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 Import dhcpcd-8.0.2 with the followin...



details:   https://anonhg.NetBSD.org/src/rev/f3d440123d19
branches:  ROY
changeset: 455225:f3d440123d19
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Jul 30 10:23:02 2019 +0000

description:
Import dhcpcd-8.0.2 with the following changes:

  *  NetBSD: Can be build without ARP support but listen to kernel DaD
  *  ND6: Removed NA support from SMALL builds
  *  DHCP: Avoid duplicate read of UDP socket when BPF is also open
  *  IP: Avoid adding address if already exists on OS other than Linux
  *  route: Fixed a NULL de-reference error on static routes
  *  DHCP6: Move to REQUEST if any IA has no-binding in REWNEW/REBIND
  *  IP: Accept packets with IP header options

diffstat:

 external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant |    8 +-
 external/bsd/dhcpcd/dist/src/bpf.c               |   72 ++++++++----
 external/bsd/dhcpcd/dist/src/defs.h              |    2 +-
 external/bsd/dhcpcd/dist/src/dhcp.c              |  116 +++++++++++--------
 external/bsd/dhcpcd/dist/src/dhcp6.c             |   39 +++++-
 external/bsd/dhcpcd/dist/src/dhcp6.h             |    1 +
 external/bsd/dhcpcd/dist/src/dhcpcd.8.in         |   13 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c            |    2 +-
 external/bsd/dhcpcd/dist/src/if-bsd.c            |    4 +-
 external/bsd/dhcpcd/dist/src/if-options.c        |  129 +++++++++++++---------
 external/bsd/dhcpcd/dist/src/if.h                |    3 -
 external/bsd/dhcpcd/dist/src/ipv4.c              |   35 +++++-
 external/bsd/dhcpcd/dist/src/ipv4.h              |    6 +
 external/bsd/dhcpcd/dist/src/ipv6.c              |   27 ++++-
 external/bsd/dhcpcd/dist/src/ipv6.h              |   10 +
 external/bsd/dhcpcd/dist/src/ipv6nd.c            |   12 +-
 external/bsd/dhcpcd/dist/src/route.c             |    6 +-
 external/bsd/dhcpcd/dist/src/script.c            |    7 +-
 18 files changed, 316 insertions(+), 176 deletions(-)

diffs (truncated from 1049 to 300 lines):

diff -r 46d7a633d24f -r f3d440123d19 external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant
--- a/external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant  Thu Jul 25 08:53:54 2019 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant  Tue Jul 30 10:23:02 2019 +0000
@@ -1,7 +1,9 @@
 # Start, reconfigure and stop wpa_supplicant per wireless interface.
-# This is needed because wpa_supplicant lacks hotplugging of any kind
-# and the user should not be expected to have to wire it into their system
-# if the base system doesn't do this itself.
+#
+# This is only needed when using wpa_supplicant-2.5 or older, OR
+# when wpa_supplicant has not been built with CONFIG_MATCH_IFACE, OR
+# wpa_supplicant was launched without the -M flag to activate
+# interface matching.
 
 if [ -z "$wpa_supplicant_conf" ]; then
        for x in \
diff -r 46d7a633d24f -r f3d440123d19 external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Thu Jul 25 08:53:54 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Tue Jul 30 10:23:02 2019 +0000
@@ -93,7 +93,7 @@
        }
 }
 
-static const uint8_t etherbroadcastaddr[] =
+static const uint8_t etherbcastaddr[] =
     { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
 int
@@ -104,7 +104,7 @@
        case ARPHRD_ETHER:
                return memcmp(frame +
                    offsetof(struct ether_header, ether_dhost),
-                   etherbroadcastaddr, sizeof(etherbroadcastaddr));
+                   etherbcastaddr, sizeof(etherbcastaddr));
        default:
                return -1;
        }
@@ -552,6 +552,12 @@
 }
 #endif
 
+#define        BPF_M_FHLEN     0
+#define        BPF_M_IPHLEN    1
+#define        BPF_M_IPLEN     2
+#define        BPF_M_UDP       3
+#define        BPF_M_UDPLEN    4
+
 static const struct bpf_insn bpf_bootp_ether[] = {
        /* Make sure this is an IP packet. */
        BPF_STMT(BPF_LD + BPF_H + BPF_ABS,
@@ -561,17 +567,27 @@
 
        /* Load frame header length into X. */
        BPF_STMT(BPF_LDX + BPF_W + BPF_IMM, sizeof(struct ether_header)),
-       /* Copy to M0. */
-       BPF_STMT(BPF_STX, 0),
+       /* Copy frame header length to memory */
+       BPF_STMT(BPF_STX, BPF_M_FHLEN),
 };
 #define BPF_BOOTP_ETHER_LEN    __arraycount(bpf_bootp_ether)
 
 static const struct bpf_insn bpf_bootp_filter[] = {
-       /* Make sure it's an optionless IPv4 packet. */
+       /* Make sure it's an 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_ALU + BPF_AND + BPF_K, 0xf0),
+       BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0x40, 1, 0),
        BPF_STMT(BPF_RET + BPF_K, 0),
 
+       /* Ensure IP header length is big enough and
+        * store the IP header length in memory. */
+       BPF_STMT(BPF_LD + BPF_B + BPF_IND, 0),
+       BPF_STMT(BPF_ALU + BPF_AND + BPF_K, 0x0f),
+       BPF_STMT(BPF_ALU + BPF_MUL + BPF_K, 4),
+       BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, sizeof(struct ip), 1, 0),
+       BPF_STMT(BPF_RET + BPF_K, 0),
+       BPF_STMT(BPF_ST, BPF_M_IPHLEN),
+
        /* Make sure it's a UDP packet. */
        BPF_STMT(BPF_LD + BPF_B + BPF_IND, offsetof(struct ip, ip_p)),
        BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 1, 0),
@@ -582,39 +598,42 @@
        BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 0, 1),
        BPF_STMT(BPF_RET + BPF_K, 0),
 
-       /* Store IP location in M1. */
+       /* Store IP length. */
        BPF_STMT(BPF_LD + BPF_H + BPF_IND, offsetof(struct ip, ip_len)),
-       BPF_STMT(BPF_ST, 1),
-
-       /* Store IP length in M2. */
-       BPF_STMT(BPF_LD + BPF_H + BPF_IND, offsetof(struct ip, ip_len)),
-       BPF_STMT(BPF_ST, 2),
+       BPF_STMT(BPF_ST, BPF_M_IPLEN),
 
        /* Advance to the UDP header. */
-       BPF_STMT(BPF_MISC + BPF_TXA, 0),
-       BPF_STMT(BPF_ALU + BPF_ADD + BPF_K, sizeof(struct ip)),
+       BPF_STMT(BPF_LD + BPF_MEM, BPF_M_IPHLEN),
+       BPF_STMT(BPF_ALU + BPF_ADD + BPF_X, 0),
        BPF_STMT(BPF_MISC + BPF_TAX, 0),
 
-       /* Store X in M3. */
-       BPF_STMT(BPF_STX, 3),
+       /* Store UDP location */
+       BPF_STMT(BPF_STX, BPF_M_UDP),
 
        /* Make sure it's from and to the right port. */
        BPF_STMT(BPF_LD + BPF_W + BPF_IND, 0),
        BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (BOOTPS << 16) + BOOTPC, 1, 0),
        BPF_STMT(BPF_RET + BPF_K, 0),
 
-       /* Store UDP length in X. */
+       /* Store UDP length. */
        BPF_STMT(BPF_LD + BPF_H + BPF_IND, offsetof(struct udphdr, uh_ulen)),
+       BPF_STMT(BPF_ST, BPF_M_UDPLEN),
+
+       /* Ensure that UDP length + IP header length == IP length */
+       /* Copy IP header length to X. */
+       BPF_STMT(BPF_LDX + BPF_MEM, BPF_M_IPHLEN),
+       /* Add UDP length (A) to IP header length (X). */
+       BPF_STMT(BPF_ALU + BPF_ADD + BPF_X, 0),
+       /* Store result in X. */
        BPF_STMT(BPF_MISC + BPF_TAX, 0),
-       /* Copy IP length in M2 to A. */
-       BPF_STMT(BPF_LD + BPF_MEM, 2),
-       /* Ensure IP length - IP header size == UDP length. */
-       BPF_STMT(BPF_ALU + BPF_SUB + BPF_K, sizeof(struct ip)),
+       /* Copy IP length to A. */
+       BPF_STMT(BPF_LD + BPF_MEM, BPF_M_IPLEN),
+       /* Ensure X == A. */
        BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_X, 0, 1, 0),
        BPF_STMT(BPF_RET + BPF_K, 0),
 
-       /* Advance to the BOOTP packet (UDP X is in M3). */
-       BPF_STMT(BPF_LD + BPF_MEM, 3),
+       /* Advance to the BOOTP packet. */
+       BPF_STMT(BPF_LD + BPF_MEM, BPF_M_UDP),
        BPF_STMT(BPF_ALU + BPF_ADD + BPF_K, sizeof(struct udphdr)),
        BPF_STMT(BPF_MISC + BPF_TAX, 0),
 
@@ -695,11 +714,10 @@
        }
 #endif
 
-       /* All passed, return the packet
-        * (Frame length in M0, IP length in M2). */
-       BPF_SET_STMT(bp, BPF_LD + BPF_MEM, 0);
+       /* All passed, return the packet - frame length + ip length */
+       BPF_SET_STMT(bp, BPF_LD + BPF_MEM, BPF_M_FHLEN);
        bp++;
-       BPF_SET_STMT(bp, BPF_LDX + BPF_MEM, 2);
+       BPF_SET_STMT(bp, BPF_LDX + BPF_MEM, BPF_M_IPLEN);
        bp++;
        BPF_SET_STMT(bp, BPF_ALU + BPF_ADD + BPF_X, 0);
        bp++;
diff -r 46d7a633d24f -r f3d440123d19 external/bsd/dhcpcd/dist/src/defs.h
--- a/external/bsd/dhcpcd/dist/src/defs.h       Thu Jul 25 08:53:54 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/defs.h       Tue Jul 30 10:23:02 2019 +0000
@@ -29,7 +29,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "8.0.1"
+#define VERSION                        "8.0.2"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r 46d7a633d24f -r f3d440123d19 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Thu Jul 25 08:53:54 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Tue Jul 30 10:23:02 2019 +0000
@@ -2329,7 +2329,9 @@
        return astate;
 }
 #endif
-
+#endif /* ARP */
+
+#if defined(ARP) || defined(KERNEL_RFC5227)
 static int
 dhcp_arp_address(struct interface *ifp)
 {
@@ -2417,7 +2419,7 @@
            ia ? &ia->addr : &ifo->req_addr,
            ia ? &ia->mask : &ifo->req_mask);
        if (state->offer_len)
-#ifdef ARP
+#if defined(ARP) || defined(KERNEL_RFC5227)
                dhcp_arp_bind(ifp);
 #else
                dhcp_bind(ifp);
@@ -3210,7 +3212,7 @@
        lease->frominfo = 0;
        eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
 
-#ifdef ARP
+#if defined(ARP) || defined(KERNEL_RFC5227)
        dhcp_arp_bind(ifp);
 #else
        dhcp_bind(ifp);
@@ -3218,70 +3220,80 @@
 }
 
 static void *
-get_udp_data(void *udp, size_t *len)
+get_udp_data(void *packet, size_t *len)
 {
-       struct bootp_pkt *p;
-
-       p = (struct bootp_pkt *)udp;
-       *len = (size_t)ntohs(p->ip.ip_len) - sizeof(p->ip) - sizeof(p->udp);
-       return (char *)udp + offsetof(struct bootp_pkt, bootp);
+       const struct ip *ip = packet;
+       size_t ip_hl = (size_t)ip->ip_hl * 4;
+       char *p = packet;
+
+       p += ip_hl + sizeof(struct udphdr);
+       *len = (size_t)ntohs(ip->ip_len) - sizeof(struct udphdr) - ip_hl;
+       return p;
 }
 
 static int
-valid_udp_packet(void *data, size_t data_len, struct in_addr *from,
-    int noudpcsum)
+valid_udp_packet(void *packet, size_t plen, struct in_addr *from,
+       unsigned int flags)
 {
-       struct bootp_pkt *p;
-       uint16_t bytes;
-
-       if (data_len < sizeof(p->ip)) {
-               if (from)
+       struct ip *ip = packet;
+       char ip_hlv = *(char *)ip;
+       size_t ip_hlen;
+       uint16_t ip_len, uh_sum;
+       struct udphdr *udp;
+
+       if (plen < sizeof(*ip)) {
+               if (from != NULL)
                        from->s_addr = INADDR_ANY;
                errno = ERANGE;
                return -1;
        }
-       p = (struct bootp_pkt *)data;
-       if (from)
-               from->s_addr = p->ip.ip_src.s_addr;
-       if (checksum(&p->ip, sizeof(p->ip)) != 0) {
+
+       if (from != NULL)
+               from->s_addr = ip->ip_src.s_addr;
+
+       ip_hlen = (size_t)ip->ip_hl * 4;
+       if (checksum(ip, ip_hlen) != 0) {
                errno = EINVAL;
                return -1;
        }
 
-       bytes = ntohs(p->ip.ip_len);
+       ip_len = ntohs(ip->ip_len);
        /* Check we have a payload */
-       if (bytes <= sizeof(p->ip) + sizeof(p->udp)) {
+       if (ip_len <= ip_hlen + sizeof(*udp)) {
                errno = ERANGE;
                return -1;
        }
        /* Check we don't go beyond the payload */
-       if (bytes > data_len) {
+       if (ip_len > plen) {
                errno = ENOBUFS;
                return -1;
        }
 
-       if (noudpcsum == 0) {
-               uint16_t udpsum, iplen;
-
-               /* This does scribble on the packet, but at this point
-                * we don't care to keep it. */
-               iplen = p->ip.ip_len;
-               udpsum = p->udp.uh_sum;
-               p->udp.uh_sum = 0;
-               p->ip.ip_hl = 0;
-               p->ip.ip_v = 0;
-               p->ip.ip_tos = 0;
-               p->ip.ip_len = p->udp.uh_ulen;
-               p->ip.ip_id = 0;
-               p->ip.ip_off = 0;
-               p->ip.ip_ttl = 0;
-               p->ip.ip_sum = 0;
-               if (udpsum && checksum(p, bytes) != udpsum) {
-                       errno = EINVAL;
-                       return -1;
-               }
-               p->ip.ip_len = iplen;
+       if (flags & BPF_PARTIALCSUM)
+               return 0;
+
+       udp = (struct udphdr *)((char *)ip + ip_hlen);
+       if (udp->uh_sum == 0)



Home | Main Index | Thread Index | Old Index