Source-Changes-HG archive

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

[src/roy]: src/external/bsd/dhcpcd/dist/src Import dhcpcd-7.0.5 with the foll...



details:   https://anonhg.NetBSD.org/src/rev/03bb8214c7fb
branches:  roy
changeset: 319525:03bb8214c7fb
user:      roy <roy%NetBSD.org@localhost>
date:      Sat Jun 02 09:42:48 2018 +0000

description:
Import dhcpcd-7.0.5 with the following changes:

  *  dhcp: Clarified some checksumming code, style and commentary
     (thanks to Maxime Villard)
  *  dhcp6: IAID is now unique per IA type rather than global
  *  ip6: if an IA callback causes a fork, exit earlier

diffstat:

 external/bsd/dhcpcd/dist/src/arp.c            |   9 ++-
 external/bsd/dhcpcd/dist/src/bpf.c            |   6 +-
 external/bsd/dhcpcd/dist/src/defs.h           |   2 +-
 external/bsd/dhcpcd/dist/src/dhcp.c           |  10 ++-
 external/bsd/dhcpcd/dist/src/dhcp6.c          |  75 +++++++++++++++++---------
 external/bsd/dhcpcd/dist/src/dhcpcd.c         |  28 +++++----
 external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in |   5 +-
 external/bsd/dhcpcd/dist/src/if-options.c     |   5 +-
 external/bsd/dhcpcd/dist/src/ipv6.c           |  23 +++++--
 9 files changed, 101 insertions(+), 62 deletions(-)

diffs (truncated from 441 to 300 lines):

diff -r 9f97d98d1a5d -r 03bb8214c7fb external/bsd/dhcpcd/dist/src/arp.c
--- a/external/bsd/dhcpcd/dist/src/arp.c        Wed May 02 22:06:41 2018 +0000
+++ b/external/bsd/dhcpcd/dist/src/arp.c        Sat Jun 02 09:42:48 2018 +0000
@@ -128,13 +128,16 @@
        /* Protocol must be IP. */
        if (ar.ar_pro != htons(ETHERTYPE_IP))
                continue;
+       /* lladdr length matches */
+       if (ar.ar_hln != ifp->hwlen)
+               continue;
+       /* Protocol length must match in_addr_t */
+       if (ar.ar_pln != sizeof(arm.sip.s_addr))
+               return;
        /* Only these types are recognised */
        if (ar.ar_op != htons(ARPOP_REPLY) &&
            ar.ar_op != htons(ARPOP_REQUEST))
                continue;
-       /* Protocol length must match in_addr_t */
-       if (ar.ar_pln != sizeof(arm.sip.s_addr))
-               return;
 #endif
 
        /* Get pointers to the hardware addresses */
diff -r 9f97d98d1a5d -r 03bb8214c7fb external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Wed May 02 22:06:41 2018 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Sat Jun 02 09:42:48 2018 +0000
@@ -108,7 +108,7 @@
        size_t buf_len;
        struct bpf_version pv;
 #ifdef BIOCIMMEDIATE
-       int flags;
+       unsigned int flags;
 #endif
 #ifndef O_CLOEXEC
        int fd_opts;
@@ -411,7 +411,7 @@
        /* Make sure the hardware length matches. */
        BPF_STMT(BPF_LD + BPF_B + BPF_IND, offsetof(struct arphdr, ar_hln)),
        BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K,
-                sizeof((struct ether_arp *)0)->arp_sha, 1, 0),
+                sizeof(((struct ether_arp *)0)->arp_sha), 1, 0),
        BPF_STMT(BPF_RET + BPF_K, 0),
 };
 #define bpf_arp_ether_len      __arraycount(bpf_arp_ether)
@@ -540,7 +540,7 @@
 #define BPF_BOOTP_ETHER_LEN    __arraycount(bpf_bootp_ether)
 
 static const struct bpf_insn bpf_bootp_filter[] = {
-       /* Make sure it's an IPv4 packet. */
+       /* Make sure it's an optionless IPv4 packet. */
        BPF_STMT(BPF_LD + BPF_B + BPF_IND, 0),
        BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0x45, 1, 0),
        BPF_STMT(BPF_RET + BPF_K, 0),
diff -r 9f97d98d1a5d -r 03bb8214c7fb external/bsd/dhcpcd/dist/src/defs.h
--- a/external/bsd/dhcpcd/dist/src/defs.h       Wed May 02 22:06:41 2018 +0000
+++ b/external/bsd/dhcpcd/dist/src/defs.h       Sat Jun 02 09:42:48 2018 +0000
@@ -28,7 +28,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "7.0.4"
+#define VERSION                        "7.0.5"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r 9f97d98d1a5d -r 03bb8214c7fb external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Wed May 02 22:06:41 2018 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Sat Jun 02 09:42:48 2018 +0000
@@ -3276,7 +3276,7 @@
        struct bootp_pkt *p;
        uint16_t bytes;
 
-       if (data_len < sizeof(p->ip) + sizeof(p->udp)) {
+       if (data_len < sizeof(p->ip)) {
                if (from)
                        from->s_addr = INADDR_ANY;
                errno = ERANGE;
@@ -3291,6 +3291,12 @@
        }
 
        bytes = ntohs(p->ip.ip_len);
+       /* Check we have a payload */
+       if (bytes <= sizeof(p->ip) + sizeof(p->udp)) {
+               errno = ERANGE;
+               return -1;
+       }
+       /* Check we don't go beyond the payload */
        if (bytes > data_len) {
                errno = ENOBUFS;
                return -1;
@@ -3334,7 +3340,7 @@
                             state->bpf_flags & RAW_PARTIALCSUM) == -1)
        {
                if (errno == EINVAL)
-                       logerrx("%s: UDP checksum failure from %s",
+                       logerrx("%s: checksum failure from %s",
                          ifp->name, inet_ntoa(from));
                else
                        logerr("%s: invalid UDP packet from %s",
diff -r 9f97d98d1a5d -r 03bb8214c7fb external/bsd/dhcpcd/dist/src/dhcp6.c
--- a/external/bsd/dhcpcd/dist/src/dhcp6.c      Wed May 02 22:06:41 2018 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp6.c      Sat Jun 02 09:42:48 2018 +0000
@@ -98,6 +98,11 @@
 };
 __CTASSERT(sizeof(struct dhcp6_ia_na) == 12);
 
+struct dhcp6_ia_ta {
+       uint8_t iaid[4];
+};
+__CTASSERT(sizeof(struct dhcp6_ia_ta) == 4);
+
 struct dhcp6_ia_addr {
        struct in6_addr addr;
        uint32_t pltime;
@@ -479,20 +484,18 @@
 
 #ifndef SMALL
 static const struct if_sla *
-dhcp6_findselfsla(struct interface *ifp, const uint8_t *iaid)
+dhcp6_findselfsla(struct interface *ifp)
 {
        size_t i, j;
+       struct if_ia *ia;
 
        for (i = 0; i < ifp->options->ia_len; i++) {
-               if (iaid == NULL ||
-                   memcmp(&ifp->options->ia[i].iaid, iaid,
-                   sizeof(ifp->options->ia[i].iaid)) == 0)
-               {
-                       for (j = 0; j < ifp->options->ia[i].sla_len; j++) {
-                               if (strcmp(ifp->options->ia[i].sla[j].ifname,
-                                   ifp->name) == 0)
-                                       return &ifp->options->ia[i].sla[j];
-                       }
+               ia = &ifp->options->ia[i];
+               if (ia->ia_type != D6_OPTION_IA_PD)
+                       continue;
+               for (j = 0; j < ia->sla_len; j++) {
+                       if (strcmp(ia->sla[j].ifname, ifp->name) == 0)
+                               return &ia->sla[j];
                }
        }
        return NULL;
@@ -629,6 +632,7 @@
        int fqdn;
        struct dhcp6_ia_na ia_na;
        uint16_t ia_na_len;
+       struct if_ia *ifia;
 #ifdef AUTH
        uint16_t auth_len;
 #endif
@@ -693,7 +697,7 @@
                                len += sizeof(o.len);
                        }
                }
-               if (dhcp6_findselfsla(ifp, NULL)) {
+               if (dhcp6_findselfsla(ifp)) {
                        n_options++;
                        len += sizeof(o.len);
                }
@@ -772,7 +776,13 @@
                }
                /* FALLTHROUGH */
        case DH6S_INIT:
-               len += ifo->ia_len * (sizeof(o) + (sizeof(uint32_t) * 3));
+               for (l = 0; l < ifo->ia_len; l++) {
+                       ifia = &ifo->ia[l];
+                       len += sizeof(o) + sizeof(uint32_t); /* IAID */
+                       /* IA_TA does not have T1 or T2 timers */
+                       if (ifo->ia[l].ia_type != D6_OPTION_IA_TA)
+                               len += sizeof(uint32_t) + sizeof(uint32_t);
+               }
                IA = 1;
                break;
        default:
@@ -899,19 +909,29 @@
                COPYIN1(D6_OPTION_RAPID_COMMIT, 0);
 
        for (l = 0; IA && l < ifo->ia_len; l++) {
+               ifia = &ifo->ia[l];
                o_lenp = NEXTLEN;
-               ia_na_len = sizeof(ia_na);
-               memcpy(ia_na.iaid, ifo->ia[l].iaid, sizeof(ia_na.iaid));
+               /* TA structure is the same as the others,
+                * it just lacks the T1 and T2 timers.
+                * These happen to be at the end of the struct,
+                * so we just don't copy them in. */
+               if (ifia->ia_type == D6_OPTION_IA_TA)
+                       ia_na_len = sizeof(struct dhcp6_ia_ta);
+               else
+                       ia_na_len = sizeof(ia_na);
+               memcpy(ia_na.iaid, ifia->iaid, sizeof(ia_na.iaid));
                ia_na.t1 = 0;
                ia_na.t2 = 0;
-               COPYIN(ifo->ia[l].ia_type, &ia_na, sizeof(ia_na));
+               COPYIN(ifia->ia_type, &ia_na, ia_na_len);
                TAILQ_FOREACH(ap, &state->addrs, next) {
                        if (ap->flags & IPV6_AF_STALE)
                                continue;
                        if (ap->prefix_vltime == 0 &&
                            !(ap->flags & IPV6_AF_REQUEST))
                                continue;
-                       if (memcmp(ifo->ia[l].iaid, ap->iaid, sizeof(uint32_t)))
+                       if (ap->ia_type != ifia->ia_type)
+                               continue;
+                       if (memcmp(ap->iaid, ifia->iaid, sizeof(ap->iaid)))
                                continue;
                        if (ap->ia_type == D6_OPTION_IA_PD) {
 #ifndef SMALL
@@ -1054,7 +1074,7 @@
                                            (o.len + sizeof(o.code));
                                }
                        }
-                       if (dhcp6_findselfsla(ifp, NULL)) {
+                       if (dhcp6_findselfsla(ifp)) {
                                o.code = htons(D6_OPTION_PD_EXCLUDE);
                                memcpy(p, &o.code, sizeof(o.code));
                                p += sizeof(o.code);
@@ -2195,6 +2215,7 @@
        uint8_t iaid[4];
        char buf[sizeof(iaid) * 3];
        struct ipv6_addr *ap;
+       struct if_ia *ifia;
 
        if (l < sizeof(*m)) {
                /* Should be impossible with guards at packet in
@@ -2248,8 +2269,9 @@
                o.len = (uint16_t)(o.len - nl);
 
                for (j = 0; j < ifo->ia_len; j++) {
-                       if (memcmp(&ifo->ia[j].iaid, ia.iaid,
-                           sizeof(ia.iaid)) == 0)
+                       ifia = &ifo->ia[j];
+                       if (ifia->ia_type == o.code &&
+                           memcmp(ifia->iaid, ia.iaid, sizeof(ia.iaid)) == 0)
                                break;
                }
                if (j == ifo->ia_len &&
@@ -2261,13 +2283,6 @@
                            buf, sizeof(buf)));
                        continue;
                }
-               if ( j < ifo->ia_len && ifo->ia[j].ia_type != o.code) {
-                       logerrx("%s: IAID %s: option type mismatch",
-                           ifp->name,
-                           hwaddr_ntoa(ia.iaid, sizeof(ia.iaid),
-                           buf, sizeof(buf)));
-                       continue;
-               }
 
                if (o.code != D6_OPTION_IA_TA) {
                        ia.t1 = ntohl(ia.t1);
@@ -2773,6 +2788,8 @@
                        }
                        for (i = 0; i < ifo->ia_len; i++) {
                                ia = &ifo->ia[i];
+                               if (ia->ia_type != D6_OPTION_IA_PD)
+                                       continue;
                                if (memcmp(ia->iaid, ap->iaid,
                                    sizeof(ia->iaid)))
                                        continue;
@@ -2869,6 +2886,8 @@
                                continue;
                        for (i = 0; i < ifo->ia_len; i++) {
                                ia = &ifo->ia[i];
+                               if (ia->ia_type != D6_OPTION_IA_PD)
+                                       continue;
                                if (memcmp(ia->iaid, ap->iaid,
                                    sizeof(ia->iaid)))
                                        continue;
@@ -3646,6 +3665,8 @@
 
        for (i = 0; i < ifp->options->ia_len; i++) {
                ia = &ifp->options->ia[i];
+               if (ia->ia_type != D6_OPTION_IA_PD)
+                       continue;
                for (j = 0; j < ia->sla_len; j++) {
                        sla = &ia->sla[j];
                        ifd = if_find(ifp->ctx->ifaces, sla->ifname);
@@ -3702,7 +3723,7 @@
 
 #ifndef SMALL
        /* Rapid commit won't work with Prefix Delegation Exclusion */
-       if (dhcp6_findselfsla(ifp, NULL))
+       if (dhcp6_findselfsla(ifp))
                del_option_mask(ifo->requestmask6, D6_OPTION_RAPID_COMMIT);
 #endif
 
diff -r 9f97d98d1a5d -r 03bb8214c7fb external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c     Wed May 02 22:06:41 2018 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c     Sat Jun 02 09:42:48 2018 +0000
@@ -770,20 +770,23 @@
 }
 
 static void
-warn_iaid_conflict(struct interface *ifp, uint8_t *iaid)
+warn_iaid_conflict(struct interface *ifp, uint16_t ia_type, uint8_t *iaid)
 {
        struct interface *ifn;
        size_t i;



Home | Main Index | Thread Index | Old Index