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-8.1.0 with the foll...



details:   https://anonhg.NetBSD.org/src/rev/172d4006803d
branches:  roy
changeset: 455232:172d4006803d
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Oct 11 11:00:49 2019 +0000

description:
Import dhcpcd-8.1.0 with the following changes:

 * Fix carrier status after a route socket overflow
 * Allow domain spaced options
 * DHCP: Allow not sending Force Renew Nonce or Reconf Accept
 * IPv4LL: Now passes Apple Bonjour test versions 1.4 and 1.5
 * ARP: Fix a typo and remove pragma (thus working with old gcc)
 * DHCP6: Fix a cosmetic issue with infinite leases
 * DHCP6: SLA 0 and Prefix Len 0 will now add a delegatd /64 address
 * Ignore some virtual interfaces such as Tap and Bridge by default
 * BPF: Move validation logic out of BPF and back into dhcpcd

diffstat:

 external/bsd/dhcpcd/dist/src/arp.c         |   95 ++++++----
 external/bsd/dhcpcd/dist/src/bpf.c         |   81 +--------
 external/bsd/dhcpcd/dist/src/bpf.h         |   19 ++
 external/bsd/dhcpcd/dist/src/control.h     |    2 +
 external/bsd/dhcpcd/dist/src/defs.h        |    2 +-
 external/bsd/dhcpcd/dist/src/dhcp-common.c |    4 +
 external/bsd/dhcpcd/dist/src/dhcp-common.h |    5 +
 external/bsd/dhcpcd/dist/src/dhcp.c        |  243 ++++++++++++++++------------
 external/bsd/dhcpcd/dist/src/dhcp.h        |    2 +-
 external/bsd/dhcpcd/dist/src/dhcp6.c       |   76 +++-----
 external/bsd/dhcpcd/dist/src/dhcpcd.8.in   |   11 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c      |    7 +-
 external/bsd/dhcpcd/dist/src/if-bsd.c      |   63 +++++++
 external/bsd/dhcpcd/dist/src/if-options.c  |   17 +-
 external/bsd/dhcpcd/dist/src/if.c          |   45 ++--
 external/bsd/dhcpcd/dist/src/if.h          |    1 +
 external/bsd/dhcpcd/dist/src/ipv4.c        |   23 +-
 external/bsd/dhcpcd/dist/src/ipv4.h        |    1 +
 external/bsd/dhcpcd/dist/src/ipv4ll.c      |   45 +++-
 external/bsd/dhcpcd/dist/src/ipv4ll.h      |    2 +-
 external/bsd/dhcpcd/dist/src/route.c       |    4 +-
 21 files changed, 425 insertions(+), 323 deletions(-)

diffs (truncated from 1558 to 300 lines):

diff -r 8de19138a912 -r 172d4006803d external/bsd/dhcpcd/dist/src/arp.c
--- a/external/bsd/dhcpcd/dist/src/arp.c        Fri Sep 13 11:52:31 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/arp.c        Fri Oct 11 11:00:49 2019 +0000
@@ -129,12 +129,11 @@
            inet_ntoa(astate->addr));
 }
 
-
 static void
 arp_found(struct arp_state *astate, const struct arp_msg *amsg)
 {
        struct interface *ifp;
-       struct ivp4_addr *ia;
+       struct ipv4_addr *ia;
 #ifndef KERNEL_RFC5227
        struct timespec now, defend;
 #endif
@@ -142,11 +141,8 @@
        arp_report_conflicted(astate, amsg);
        ifp = astate->iface;
 
-#pragma GCC diagnostic push /* GCC is clearly wrong about this warning. */
-#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
        /* If we haven't added the address we're doing a probe. */
        ia = ipv4_iffindaddr(ifp, &astate->addr, NULL);
-#pragma GCC diagnostic pop
        if (ia == NULL) {
                if (astate->found_cb != NULL)
                        astate->found_cb(astate, amsg);
@@ -182,6 +178,35 @@
                astate->defend_failed_cb(astate);
 }
 
+static bool
+arp_validate(const struct interface *ifp, struct arphdr *arp)
+{
+
+       /* Families must match */
+       if (arp->ar_hrd != htons(ifp->family))
+               return false;
+
+       /* Protocol must be IP. */
+       if (arp->ar_pro != htons(ETHERTYPE_IP))
+               return false;
+
+       /* lladdr length matches */
+       if (arp->ar_hln != ifp->hwlen)
+               return false;
+
+       /* Protocol length must match in_addr_t */
+       if (arp->ar_pln != sizeof(in_addr_t))
+               return false;
+
+       /* Only these types are recognised */
+       if (arp->ar_op != htons(ARPOP_REPLY) &&
+           arp->ar_op != htons(ARPOP_REQUEST))
+               return false;
+
+       return true;
+}
+
+
 static void
 arp_packet(struct interface *ifp, uint8_t *data, size_t len)
 {
@@ -197,25 +222,12 @@
                return;
        memcpy(&ar, data, sizeof(ar));
 
-       /* These checks are enforced in the BPF filter. */
-#if 0
-       /* Families must match */
-       if (ar.ar_hrd != htons(ifp->family))
+       if (!arp_validate(ifp, &ar)) {
+#ifdef BPF_DEBUG
+               logerrx("%s: ARP BPF validation failure", ifp->name);
+#endif
                return;
-       /* 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;
-#endif
+       }
 
        /* Get pointers to the hardware addresses */
        hw_s = data + sizeof(ar);
@@ -329,10 +341,8 @@
        state = ARP_STATE(ifp);
        if (state->bpf_fd == -1) {
                state->bpf_fd = bpf_open(ifp, bpf_arp);
-               if (state->bpf_fd == -1) {
-                       logerr("%s: %s", __func__, ifp->name);
+               if (state->bpf_fd == -1)
                        return -1;
-               }
                eloop_event_add(ifp->ctx->eloop, state->bpf_fd, arp_read, ifp);
        }
        return state->bpf_fd;
@@ -428,6 +438,7 @@
 {
        struct arp_state *astate = arg;
        struct interface *ifp = astate->iface;
+       struct ipv4_addr *ia;
 
        if (++astate->claims < ANNOUNCE_NUM)
                logdebugx("%s: ARP announcing %s (%d of %d), "
@@ -438,24 +449,31 @@
                logdebugx("%s: ARP announcing %s (%d of %d)",
                    ifp->name, inet_ntoa(astate->addr),
                    astate->claims, ANNOUNCE_NUM);
+
+       /* The kernel will send a Gratuitous ARP for newly added addresses.
+        * So we can avoid sending the same.
+        * Linux is special and doesn't send one. */
+       ia = ipv4_iffindaddr(ifp, &astate->addr, NULL);
+#ifndef __linux__
+       if (astate->claims == 1 && ia != NULL && ia->flags & IPV4_AF_NEW)
+               goto skip_request;
+#endif
+
        if (arp_request(ifp, &astate->addr, &astate->addr) == -1)
                logerr(__func__);
+
+#ifndef __linux__
+skip_request:
+#endif
+       /* No longer a new address. */
+       if (ia != NULL)
+               ia->flags |= ~IPV4_AF_NEW;
+
        eloop_timeout_add_sec(ifp->ctx->eloop, ANNOUNCE_WAIT,
            astate->claims < ANNOUNCE_NUM ? arp_announce1 : arp_announced,
            astate);
 }
 
-/*
- * XXX FIXME
- * Kernels supporting RFC5227 will announce the address when it's
- * added.
- * dhcpcd should not announce when this happens, nor need to open
- * a BPF socket for it.
- * Also, an address might be added to a non preferred inteface when
- * the same address exists on a preferred one so we need to instruct
- * the kernel not to announce the address somehow.
- */
-
 void
 arp_announce(struct arp_state *astate)
 {
@@ -501,6 +519,9 @@
 {
        struct arp_state *astate;
 
+       if (ifp->flags & IFF_NOARP)
+               return;
+
        astate = arp_find(ifp, ia);
        if (astate == NULL) {
                astate = arp_new(ifp, ia);
diff -r 8de19138a912 -r 172d4006803d external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Fri Sep 13 11:52:31 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Fri Oct 11 11:00:49 2019 +0000
@@ -410,13 +410,7 @@
 #endif
 
 #ifdef ARP
-
 static const struct bpf_insn bpf_arp_ether [] = {
-       /* Ensure packet is at least correct size. */
-       BPF_STMT(BPF_LD + BPF_W + BPF_LEN, 0),
-       BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, sizeof(struct ether_arp), 1, 0),
-       BPF_STMT(BPF_RET + BPF_K, 0),
-
        /* Check this is an ARP packet. */
        BPF_STMT(BPF_LD + BPF_H + BPF_ABS,
                 offsetof(struct ether_header, ether_type)),
@@ -552,17 +546,8 @@
 }
 #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
-
 #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
@@ -574,13 +559,14 @@
        BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 1, 0),
        BPF_STMT(BPF_RET + BPF_K, 0),
 
-       /* Load frame header length into X. */
-       BPF_STMT(BPF_LDX + BPF_W + BPF_IMM, sizeof(struct ether_header)),
-       /* Copy frame header length to memory */
-       BPF_STMT(BPF_STX, BPF_M_FHLEN),
+       /* Advance to the IP header. */
+       BPF_STMT(BPF_LDX + BPF_K, sizeof(struct ether_header)),
 };
 #define BPF_BOOTP_ETHER_LEN    __arraycount(bpf_bootp_ether)
 
+#define BOOTP_MIN_SIZE         sizeof(struct ip) + sizeof(struct udphdr) + \
+                               sizeof(struct bootp)
+
 static const struct bpf_insn bpf_bootp_filter[] = {
        /* Make sure it's an IPv4 packet. */
        BPF_STMT(BPF_LD + BPF_B + BPF_IND, 0),
@@ -588,15 +574,6 @@
        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),
@@ -607,49 +584,17 @@
        BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 0, 1),
        BPF_STMT(BPF_RET + BPF_K, 0),
 
-       /* Store IP length. */
-       BPF_STMT(BPF_LD + BPF_H + BPF_IND, offsetof(struct ip, ip_len)),
-       BPF_STMT(BPF_ST, BPF_M_IPLEN),
-
        /* Advance to the UDP header. */
-       BPF_STMT(BPF_LD + BPF_MEM, BPF_M_IPHLEN),
+       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_STMT(BPF_ALU + BPF_ADD + BPF_X, 0),
        BPF_STMT(BPF_MISC + BPF_TAX, 0),
 
-       /* 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. */
-       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 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. */
-       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),
-
-       /* Make sure it's BOOTREPLY. */
-       BPF_STMT(BPF_LD + BPF_B + BPF_IND, offsetof(struct bootp, op)),
-       BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, BOOTREPLY, 1, 0),
-       BPF_STMT(BPF_RET + BPF_K, 0),
 };
 
 #define BPF_BOOTP_FILTER_LEN   __arraycount(bpf_bootp_filter)
@@ -729,14 +674,8 @@
        }
 #endif
 
-       /* 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, BPF_M_IPLEN);



Home | Main Index | Thread Index | Old Index