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/src Sync



details:   https://anonhg.NetBSD.org/src/rev/124733af0c1d
branches:  trunk
changeset: 453660:124733af0c1d
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Aug 21 17:12:19 2019 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/src/bpf.c        |  15 +++++
 external/bsd/dhcpcd/dist/src/dhcp.c       |  79 +++++++++++++-----------------
 external/bsd/dhcpcd/dist/src/dhcpcd.c     |   9 +-
 external/bsd/dhcpcd/dist/src/if-bsd.c     |  37 ++++++++------
 external/bsd/dhcpcd/dist/src/if-options.c |   4 +-
 external/bsd/dhcpcd/dist/src/ipv6.h       |  10 ++-
 6 files changed, 84 insertions(+), 70 deletions(-)

diffs (truncated from 364 to 300 lines):

diff -r 5b3b46894a65 -r 124733af0c1d external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Wed Aug 21 17:10:29 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Wed Aug 21 17:12:19 2019 +0000
@@ -558,6 +558,15 @@
 #define        BPF_M_UDP       3
 #define        BPF_M_UDPLEN    4
 
+#ifdef ARPHRD_NONE
+static const struct bpf_insn bpf_bootp_none[] = {
+       /* Set the frame header length to zero. */
+       BPF_STMT(BPF_LD + BPF_IMM, 0),
+       BPF_STMT(BPF_ST, BPF_M_FHLEN),
+};
+#define BPF_BOOTP_NONE_LEN     __arraycount(bpf_bootp_none)
+#endif
+
 static const struct bpf_insn bpf_bootp_ether[] = {
        /* Make sure this is an IP packet. */
        BPF_STMT(BPF_LD + BPF_H + BPF_ABS,
@@ -665,6 +674,12 @@
        bp = bpf;
        /* Check frame header. */
        switch(ifp->family) {
+#ifdef ARPHRD_NONE
+       case ARPHRD_NONE:
+               memcpy(bp, bpf_bootp_none, sizeof(bpf_bootp_none));
+               bp += BPF_BOOTP_NONE_LEN;
+               break;
+#endif
        case ARPHRD_ETHER:
                memcpy(bp, bpf_bootp_ether, sizeof(bpf_bootp_ether));
                bp += BPF_BOOTP_ETHER_LEN;
diff -r 5b3b46894a65 -r 124733af0c1d external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Wed Aug 21 17:10:29 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Wed Aug 21 17:12:19 2019 +0000
@@ -1584,24 +1584,24 @@
 }
 
 static uint16_t
-checksum(const void *data, size_t len)
+in_cksum(void *data, size_t len, uint32_t *isum)
 {
-       const uint8_t *addr = data;
-       uint32_t sum = 0;
-
-       while (len > 1) {
-               sum += (uint32_t)(addr[0] * 256 + addr[1]);
-               addr += 2;
-               len -= 2;
-       }
+       const uint16_t *word = data;
+       uint32_t sum = isum != NULL ? *isum : 0;
+
+       for (; len > 1; len -= sizeof(*word))
+               sum += *word++;
 
        if (len == 1)
-               sum += (uint32_t)(*addr * 256);
+               sum += *(const uint8_t *)word;
+
+       if (isum != NULL)
+               *isum = sum;
 
        sum = (sum >> 16) + (sum & 0xffff);
        sum += (sum >> 16);
 
-       return (uint16_t)~htons((uint16_t)sum);
+       return (uint16_t)~sum;
 }
 
 static struct bootp_pkt *
@@ -1639,14 +1639,16 @@
        udp->uh_dport = htons(BOOTPS);
        udp->uh_ulen = htons((uint16_t)(sizeof(*udp) + length));
        ip->ip_len = udp->uh_ulen;
-       udp->uh_sum = checksum(udpp, sizeof(*ip) +  sizeof(*udp) + length);
+       udp->uh_sum = in_cksum(udpp, sizeof(*ip) + sizeof(*udp) + length, NULL);
 
        ip->ip_v = IPVERSION;
        ip->ip_hl = sizeof(*ip) >> 2;
        ip->ip_id = (uint16_t)arc4random_uniform(UINT16_MAX);
        ip->ip_ttl = IPDEFTTL;
        ip->ip_len = htons((uint16_t)(sizeof(*ip) + sizeof(*udp) + length));
-       ip->ip_sum = checksum(ip, sizeof(*ip));
+       ip->ip_sum = in_cksum(ip, sizeof(*ip), NULL);
+       if (ip->ip_sum == 0)
+               ip->ip_sum = 0xffff; /* RFC 768 */
 
        *sz = sizeof(*ip) + sizeof(*udp) + length;
        return udpp;
@@ -2363,7 +2365,10 @@
                return 0;
        }
 #else
-       if (ifp->options->options & DHCPCD_ARP && ia == NULL) {
+       if (!(ifp->flags & IFF_NOARP) &&
+           ifp->options->options & DHCPCD_ARP &&
+           ia == NULL)
+       {
                struct arp_state *astate;
                struct dhcp_lease l;
 
@@ -3236,10 +3241,15 @@
        unsigned int flags)
 {
        struct ip *ip = packet;
-       char ip_hlv = *(char *)ip;
+       struct ip pseudo_ip = {
+               .ip_p = IPPROTO_UDP,
+               .ip_src = ip->ip_src,
+               .ip_dst = ip->ip_dst
+       };
        size_t ip_hlen;
        uint16_t ip_len, uh_sum;
        struct udphdr *udp;
+       uint32_t csum;
 
        if (plen < sizeof(*ip)) {
                if (from != NULL)
@@ -3252,13 +3262,13 @@
                from->s_addr = ip->ip_src.s_addr;
 
        ip_hlen = (size_t)ip->ip_hl * 4;
-       if (checksum(ip, ip_hlen) != 0) {
+       if (in_cksum(ip, ip_hlen, NULL) != 0) {
                errno = EINVAL;
                return -1;
        }
 
+       /* Check we have a payload */
        ip_len = ntohs(ip->ip_len);
-       /* Check we have a payload */
        if (ip_len <= ip_hlen + sizeof(*udp)) {
                errno = ERANGE;
                return -1;
@@ -3272,28 +3282,21 @@
        if (flags & BPF_PARTIALCSUM)
                return 0;
 
-       udp = (struct udphdr *)((char *)ip + ip_hlen);
+       /* UDP checksum is based on a pseudo IP header alongside
+        * the UDP header and payload. */
+       udp = (struct udphdr *)(void *)((char *)ip + ip_hlen);
        if (udp->uh_sum == 0)
                return 0;
+
        uh_sum = udp->uh_sum;
-
-       /* This does scribble on the packet, but at this point
-        * we don't care to keep it. */
        udp->uh_sum = 0;
-       ip->ip_hl = 0;
-       ip->ip_v = 0;
-       ip->ip_tos = 0;
-       ip->ip_len = udp->uh_ulen;
-       ip->ip_id = 0;
-       ip->ip_off = 0;
-       ip->ip_ttl = 0;
-       ip->ip_sum = 0;
-       if (checksum(packet, ip_len) != uh_sum) {
+       pseudo_ip.ip_len = udp->uh_ulen;
+       csum = 0;
+       in_cksum(&pseudo_ip, sizeof(pseudo_ip), &csum);
+       if (in_cksum(udp, ntohs(udp->uh_ulen), &csum) != uh_sum) {
                errno = EINVAL;
                return -1;
        }
-       *(char *)ip = ip_hlv;
-       ip->ip_len = htons(ip_len);
 
        return 0;
 }
@@ -3339,12 +3342,6 @@
                          ifp->name, inet_ntoa(from));
                return;
        }
-       if (ifp->flags & IFF_POINTOPOINT &&
-           (state->addr == NULL || state->addr->brd.s_addr != from.s_addr))
-       {
-               logwarnx("%s: server %s is not destination",
-                   ifp->name, inet_ntoa(from));
-       }
 
        /*
         * DHCP has a variable option area rather than a fixed vendor area.
@@ -3721,12 +3718,6 @@
                return;
        }
 
-       if (ifp->hwlen == 0 && ifo->clientid[0] == '\0') {
-               logwarnx("%s: needs a clientid to configure", ifp->name);
-               dhcp_drop(ifp, "FAIL");
-               eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
-               return;
-       }
        /* We don't want to read the old lease if we NAK an old test */
        nolease = state->offer && ifp->ctx->options & DHCPCD_TEST;
        if (!nolease && ifo->options & DHCPCD_DHCP) {
diff -r 5b3b46894a65 -r 124733af0c1d external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c     Wed Aug 21 17:10:29 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c     Wed Aug 21 17:12:19 2019 +0000
@@ -458,11 +458,10 @@
                ifo->options &= ~DHCPCD_ARP;
                if (!(ifp->flags & IFF_MULTICAST))
                        ifo->options &= ~DHCPCD_IPV6RS;
-               if (!(ifo->options & DHCPCD_INFORM))
+               if (!(ifo->options & (DHCPCD_INFORM | DHCPCD_WANTDHCP)))
                        ifo->options |= DHCPCD_STATIC;
        }
-       if (ifp->flags & IFF_NOARP ||
-           !(ifo->options & DHCPCD_ARP) ||
+       if (!(ifo->options & DHCPCD_ARP) ||
            ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))
                ifo->options &= ~DHCPCD_IPV4LL;
 
@@ -1440,10 +1439,10 @@
         * write callback on the fd */
        if (strcmp(*argv, "--version") == 0) {
                return control_queue(fd, UNCONST(VERSION),
-                   strlen(VERSION) + 1, 0);
+                   strlen(VERSION) + 1, false);
        } else if (strcmp(*argv, "--getconfigfile") == 0) {
                return control_queue(fd, UNCONST(fd->ctx->cffile),
-                   strlen(fd->ctx->cffile) + 1, 0);
+                   strlen(fd->ctx->cffile) + 1, false);
        } else if (strcmp(*argv, "--getinterfaces") == 0) {
                eloop_event_add_w(fd->ctx->eloop, fd->fd,
                    dhcpcd_getinterfaces, fd);
diff -r 5b3b46894a65 -r 124733af0c1d external/bsd/dhcpcd/dist/src/if-bsd.c
--- a/external/bsd/dhcpcd/dist/src/if-bsd.c     Wed Aug 21 17:10:29 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/if-bsd.c     Wed Aug 21 17:12:19 2019 +0000
@@ -191,6 +191,8 @@
        if (setsockopt(ctx->link_fd, PF_ROUTE, ROUTE_MSGFILTER,
            &msgfilter_mask, sizeof(msgfilter_mask)) == -1)
                logerr(__func__);
+#else
+#warning kernel does not support route message filtering
 #endif
 
        return 0;
@@ -660,11 +662,8 @@
        }
 #endif
 
-       /* We have already checked that at least one address must be
-        * present after the rtm structure. */
-       /* coverity[ptr_arith] */
-       if (get_addrs(rtm->rtm_addrs, rtm + 1,
-                     rtm->rtm_msglen - sizeof(*rtm), rti_info) == -1)
+       if (get_addrs(rtm->rtm_addrs, (const char *)rtm + sizeof(*rtm),
+                     rtm->rtm_msglen - sizeof(*rtm), rti_info) == -1)
                return -1;
        memset(rt, 0, sizeof(*rt));
 
@@ -1115,10 +1114,7 @@
        if ((ifp = if_findindex(ctx->ifaces, ifam->ifam_index)) == NULL)
                return 0;
 
-       /* We have already checked that at least one address must be
-        * present after the ifam structure. */
-       /* coverity[ptr_arith] */
-       if (get_addrs(ifam->ifam_addrs, ifam + 1,
+       if (get_addrs(ifam->ifam_addrs, (const char *)ifam + sizeof(*ifam),
                      ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
                return -1;
 
@@ -1314,32 +1310,41 @@
 #ifdef RTM_DESYNC
        case RTM_DESYNC:
                dhcpcd_linkoverflow(ctx);
+#elif !defined(SO_RERROR)
+#warning cannot detect route socket overflow within kernel
 #endif
        }
 
        return 0;
 }
 
+__CTASSERT(offsetof(struct rt_msghdr, rtm_msglen) == 0);
 int
 if_handlelink(struct dhcpcd_ctx *ctx)
 {
        struct rtm rtm;
-       struct iovec iov = { .iov_base = &rtm, .iov_len = sizeof(rtm) };
-       struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1 };
        ssize_t len;
 
-       len = recvmsg(ctx->link_fd, &msg, 0);
+       len = read(ctx->link_fd, &rtm, sizeof(rtm));
        if (len == -1)
                return -1;
        if (len == 0)
                return 0;
-       if (len < rtm.hdr.rtm_msglen) {
+       if ((size_t)len < sizeof(rtm.hdr.rtm_msglen) ||
+           len != rtm.hdr.rtm_msglen)
+       {
                errno = EINVAL;
                return -1;
        }



Home | Main Index | Thread Index | Old Index