Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/dhcpcd/dist Sync



details:   https://anonhg.NetBSD.org/src/rev/efe04b954fc1
branches:  trunk
changeset: 816851:efe04b954fc1
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Jul 29 10:07:57 2016 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/arp.c                       |   60 +-
 external/bsd/dhcpcd/dist/defs.h                      |    4 +-
 external/bsd/dhcpcd/dist/dhcp-common.c               |    4 +-
 external/bsd/dhcpcd/dist/dhcp.c                      |   77 +-
 external/bsd/dhcpcd/dist/dhcp6.c                     |   27 +-
 external/bsd/dhcpcd/dist/dhcp6.h                     |    5 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf |   11 +-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in       |    6 +-
 external/bsd/dhcpcd/dist/dhcpcd.8.in                 |   20 +-
 external/bsd/dhcpcd/dist/dhcpcd.c                    |   23 +-
 external/bsd/dhcpcd/dist/dhcpcd.conf.5.in            |   14 +-
 external/bsd/dhcpcd/dist/dhcpcd.h                    |    7 +-
 external/bsd/dhcpcd/dist/duid.c                      |    4 +-
 external/bsd/dhcpcd/dist/if-bsd.c                    |  460 +++++++++---------
 external/bsd/dhcpcd/dist/if-options.c                |   21 +-
 external/bsd/dhcpcd/dist/if-options.h                |    3 +-
 external/bsd/dhcpcd/dist/if.c                        |  144 +++--
 external/bsd/dhcpcd/dist/if.h                        |   44 +-
 external/bsd/dhcpcd/dist/ipv4.c                      |  140 +++--
 external/bsd/dhcpcd/dist/ipv4.h                      |   43 +-
 external/bsd/dhcpcd/dist/ipv4ll.c                    |   12 +-
 external/bsd/dhcpcd/dist/ipv6.c                      |  303 +++++++++---
 external/bsd/dhcpcd/dist/ipv6.h                      |   23 +-
 external/bsd/dhcpcd/dist/ipv6nd.c                    |   16 +-
 external/bsd/dhcpcd/dist/ipv6nd.h                    |    5 +-
 25 files changed, 885 insertions(+), 591 deletions(-)

diffs (truncated from 2725 to 300 lines):

diff -r 1115b5a72eda -r efe04b954fc1 external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Fri Jul 29 09:52:46 2016 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Fri Jul 29 10:07:57 2016 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: arp.c,v 1.20 2016/06/17 19:42:31 roy Exp $");
+ __RCSID("$NetBSD: arp.c,v 1.21 2016/07/29 10:07:57 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -122,32 +122,19 @@
 }
 
 static void
-arp_packet(void *arg)
+arp_packet(struct interface *ifp, uint8_t *data, size_t len)
 {
-       struct interface *ifp = arg;
        const struct interface *ifn;
-       uint8_t buf[ARP_LEN];
        struct arphdr ar;
        struct arp_msg arm;
-       ssize_t bytes;
-       struct iarp_state *state;
+       const struct iarp_state *state;
        struct arp_state *astate, *astaten;
-       unsigned char *hw_s, *hw_t;
-       int flags;
+       uint8_t *hw_s, *hw_t;
 
-       state = ARP_STATE(ifp);
-       flags = 0;
-       bytes = if_readraw(ifp, state->fd, buf, sizeof(buf), &flags);
-       if (bytes == -1) {
-               logger(ifp->ctx, LOG_ERR,
-                   "%s: arp if_readrawpacket: %m", ifp->name);
-               arp_close(ifp);
+       /* We must have a full ARP header */
+       if (len < sizeof(ar))
                return;
-       }
-       /* We must have a full ARP header */
-       if ((size_t)bytes < sizeof(ar))
-               return;
-       memcpy(&ar, buf, sizeof(ar));
+       memcpy(&ar, data, sizeof(ar));
        /* Families must match */
        if (ar.ar_hrd != htons(ifp->family))
                return;
@@ -165,10 +152,10 @@
                return;
 
        /* Get pointers to the hardware addreses */
-       hw_s = buf + sizeof(ar);
+       hw_s = data + sizeof(ar);
        hw_t = hw_s + ar.ar_hln + ar.ar_pln;
        /* Ensure we got all the data */
-       if ((hw_t + ar.ar_hln + ar.ar_pln) - buf > bytes)
+       if ((size_t)((hw_t + ar.ar_hln + ar.ar_pln) - data) > len)
                return;
        /* Ignore messages from ourself */
        TAILQ_FOREACH(ifn, ifp->ctx->ifaces, next) {
@@ -190,12 +177,39 @@
        memcpy(&arm.tip.s_addr, hw_t + ar.ar_hln, ar.ar_pln);
 
        /* Run the conflicts */
+       state = ARP_CSTATE(ifp);
        TAILQ_FOREACH_SAFE(astate, &state->arp_states, next, astaten) {
                if (astate->conflicted_cb)
                        astate->conflicted_cb(astate, &arm);
        }
 }
 
+static void
+arp_read(void *arg)
+{
+       struct interface *ifp = arg;
+       const struct iarp_state *state;
+       uint8_t buf[ARP_LEN];
+       int flags;
+       ssize_t bytes;
+
+       /* Some RAW mechanisms are generic file descriptors, not sockets.
+        * This means we have no kernel call to just get one packet,
+        * so we have to process the entire buffer. */
+       state = ARP_CSTATE(ifp);
+       flags = 0;
+       while (!(flags & RAW_EOF)) {
+               bytes = if_readraw(ifp, state->fd, buf, sizeof(buf), &flags);
+               if (bytes == -1) {
+                       logger(ifp->ctx, LOG_ERR,
+                           "%s: arp if_readrawpacket: %m", ifp->name);
+                       arp_close(ifp);
+                       return;
+               }
+               arp_packet(ifp, buf, (size_t)bytes);
+       }
+}
+
 int
 arp_open(struct interface *ifp)
 {
@@ -209,7 +223,7 @@
                            __func__, ifp->name);
                        return -1;
                }
-               eloop_event_add(ifp->ctx->eloop, state->fd, arp_packet, ifp);
+               eloop_event_add(ifp->ctx->eloop, state->fd, arp_read, ifp);
        }
        return state->fd;
 }
diff -r 1115b5a72eda -r efe04b954fc1 external/bsd/dhcpcd/dist/defs.h
--- a/external/bsd/dhcpcd/dist/defs.h   Fri Jul 29 09:52:46 2016 +0000
+++ b/external/bsd/dhcpcd/dist/defs.h   Fri Jul 29 10:07:57 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.28 2016/06/17 19:42:31 roy Exp $ */
+/* $NetBSD: defs.h,v 1.29 2016/07/29 10:07:57 roy Exp $ */
 
 /*
  * dhcpcd - DHCP client daemon
@@ -30,7 +30,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "6.11.1"
+#define VERSION                        "6.11.2"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r 1115b5a72eda -r efe04b954fc1 external/bsd/dhcpcd/dist/dhcp-common.c
--- a/external/bsd/dhcpcd/dist/dhcp-common.c    Fri Jul 29 09:52:46 2016 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp-common.c    Fri Jul 29 10:07:57 2016 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: dhcp-common.c,v 1.18 2016/06/17 19:42:31 roy Exp $");
+ __RCSID("$NetBSD: dhcp-common.c,v 1.19 2016/07/29 10:07:57 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -173,7 +173,7 @@
        char *p;
        int l;
 
-       if (uname(&utn) != 0)
+       if (uname(&utn) == -1)
                return (ssize_t)snprintf(str, len, "%s-%s",
                    PACKAGE, VERSION);
        p = str;
diff -r 1115b5a72eda -r efe04b954fc1 external/bsd/dhcpcd/dist/dhcp.c
--- a/external/bsd/dhcpcd/dist/dhcp.c   Fri Jul 29 09:52:46 2016 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp.c   Fri Jul 29 10:07:57 2016 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: dhcp.c,v 1.43 2016/06/17 19:42:31 roy Exp $");
+ __RCSID("$NetBSD: dhcp.c,v 1.44 2016/07/29 10:07:57 roy Exp $");
 
 /*
  * dhcpcd - DHCP client daemon
@@ -1101,7 +1101,7 @@
        return (ssize_t)len;
 
 toobig:
-       logger(ifp->ctx, LOG_ERR, "%s: DHCP messge too big", ifp->name);
+       logger(ifp->ctx, LOG_ERR, "%s: DHCP message too big", ifp->name);
        free(bootp);
        return -1;
 }
@@ -2728,7 +2728,7 @@
                type = 0;
        else if (ifo->options & DHCPCD_BOOTP) {
                logger(ifp->ctx, LOG_DEBUG,
-                   "%s: ignoring DHCP reply (excpecting BOOTP)",
+                   "%s: ignoring DHCP reply (expecting BOOTP)",
                    ifp->name);
                return;
        }
@@ -3096,7 +3096,7 @@
        }
 
        bytes = ntohs(p->ip.ip_len);
-       if (data_len < bytes) {
+       if (bytes > data_len) {
                errno = EINVAL;
                return -1;
        }
@@ -3128,27 +3128,15 @@
 }
 
 static void
-dhcp_handlepacket(void *arg)
+dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len, int flags)
 {
-       struct interface *ifp = arg;
-       uint8_t *bootp, buf[MTU_MAX];
-       size_t bytes;
+       uint8_t *bootp;
        struct in_addr from;
-       int i, flags;
+       int i;
+       size_t udp_len;
        const struct dhcp_state *state = D_CSTATE(ifp);
 
-       /* Need this API due to BPF */
-       flags = 0;
-       bootp = NULL;
-       bytes = (size_t)if_readraw(ifp, state->raw_fd,buf, sizeof(buf), &flags);
-       if ((ssize_t)bytes == -1) {
-               logger(ifp->ctx, LOG_ERR,
-                   "%s: dhcp if_readrawpacket: %m", ifp->name);
-               dhcp_close(ifp);
-               arp_close(ifp);
-               return;
-       }
-       if (valid_udp_packet(buf, bytes, &from, flags & RAW_PARTIALCSUM) == -1)
+       if (valid_udp_packet(data, len, &from, flags & RAW_PARTIALCSUM) == -1)
        {
                logger(ifp->ctx, LOG_ERR, "%s: invalid UDP packet from %s",
                    ifp->name, inet_ntoa(from));
@@ -3173,6 +3161,7 @@
                    "%s: server %s is not destination",
                    ifp->name, inet_ntoa(from));
        }
+
        /*
         * DHCP has a variable option area rather than a fixed vendor area.
         * Because DHCP uses the BOOTP protocol it should still send BOOTP
@@ -3180,19 +3169,47 @@
         * However some servers send a truncated vendor area.
         * dhcpcd can work fine without the vendor area being sent.
         */
-       bytes = get_udp_data(&bootp, buf);
-       if (bytes < offsetof(struct bootp, vend)) {
+       udp_len = get_udp_data(&bootp, data);
+       /* udp_len must be correct because the values are checked in
+        * valid_udp_packet(). */
+       if (udp_len < offsetof(struct bootp, vend)) {
                logger(ifp->ctx, LOG_ERR,
                    "%s: truncated packet (%zu) from %s",
-                   ifp->name, bytes, inet_ntoa(from));
+                   ifp->name, udp_len, inet_ntoa(from));
                return;
        }
-       /* But to make our IS_DHCP macro easy, ensure the vendor
+       /* To make our IS_DHCP macro easy, ensure the vendor
         * area has at least 4 octets. */
-       while (bytes < offsetof(struct bootp, vend) + 4)
-               bootp[bytes++] = '\0';
-
-       dhcp_handledhcp(ifp, (struct bootp *)bootp, bytes, &from);
+       while (udp_len < offsetof(struct bootp, vend) + 4)
+               bootp[udp_len++] = '\0';
+
+       dhcp_handledhcp(ifp, (struct bootp *)bootp, udp_len, &from);
+}
+
+static void
+dhcp_readpacket(void *arg)
+{
+       struct interface *ifp = arg;
+       uint8_t buf[MTU_MAX];
+       ssize_t bytes;
+       int flags;
+       const struct dhcp_state *state = D_CSTATE(ifp);
+
+       /* Some RAW mechanisms are generic file descriptors, not sockets.
+        * This means we have no kernel call to just get one packet,
+        * so we have to process the entire buffer. */
+       flags = 0;
+       while (!(flags & RAW_EOF)) {
+               bytes = if_readraw(ifp, state->raw_fd, buf,sizeof(buf), &flags);
+               if (bytes == -1) {
+                       logger(ifp->ctx, LOG_ERR,
+                           "%s: dhcp if_readrawpacket: %m", ifp->name);
+                       dhcp_close(ifp);
+                       arp_close(ifp);
+                       return;
+               }
+               dhcp_handlepacket(ifp, buf, (size_t)bytes, flags);
+       }
 }
 
 static void
@@ -3234,7 +3251,7 @@
                        return -1;
                }
                eloop_event_add(ifp->ctx->eloop,
-                   state->raw_fd, dhcp_handlepacket, ifp);
+                   state->raw_fd, dhcp_readpacket, ifp);
        }
        return 0;
 }
diff -r 1115b5a72eda -r efe04b954fc1 external/bsd/dhcpcd/dist/dhcp6.c
--- a/external/bsd/dhcpcd/dist/dhcp6.c  Fri Jul 29 09:52:46 2016 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp6.c  Fri Jul 29 10:07:57 2016 +0000
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
- __RCSID("$NetBSD: dhcp6.c,v 1.22 2016/06/17 19:42:31 roy Exp $");
+ __RCSID("$NetBSD: dhcp6.c,v 1.23 2016/07/29 10:07:57 roy Exp $");
 
 /*



Home | Main Index | Thread Index | Old Index