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.0 with the followin...



details:   https://anonhg.NetBSD.org/src/rev/634f42e171a0
branches:  ROY
changeset: 455223:634f42e171a0
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Jul 24 09:54:49 2019 +0000

description:
Import dhcpcd-8.0.0 with the following changes:

  *  ARP now supports many requests
  *  Routing tables now use Red-Black Trees
  *  Script variables are no longer allocated manually

diffstat:

 external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant |    2 +-
 external/bsd/dhcpcd/dist/hooks/20-resolv.conf    |   39 +-
 external/bsd/dhcpcd/dist/hooks/50-ntp.conf       |    1 +
 external/bsd/dhcpcd/dist/src/arp.c               |  269 +++++----
 external/bsd/dhcpcd/dist/src/arp.h               |   18 +-
 external/bsd/dhcpcd/dist/src/auth.c              |    2 +
 external/bsd/dhcpcd/dist/src/auth.h              |    1 +
 external/bsd/dhcpcd/dist/src/bpf.c               |   28 +-
 external/bsd/dhcpcd/dist/src/bpf.h               |    3 +
 external/bsd/dhcpcd/dist/src/common.c            |   49 +-
 external/bsd/dhcpcd/dist/src/common.h            |   34 +-
 external/bsd/dhcpcd/dist/src/control.c           |    1 +
 external/bsd/dhcpcd/dist/src/control.h           |    1 +
 external/bsd/dhcpcd/dist/src/defs.h              |    3 +-
 external/bsd/dhcpcd/dist/src/dev.h               |    1 +
 external/bsd/dhcpcd/dist/src/dhcp-common.c       |  355 ++++---------
 external/bsd/dhcpcd/dist/src/dhcp-common.h       |   14 +-
 external/bsd/dhcpcd/dist/src/dhcp.c              |  534 ++++++++------------
 external/bsd/dhcpcd/dist/src/dhcp.h              |   15 +-
 external/bsd/dhcpcd/dist/src/dhcp6.c             |  123 +---
 external/bsd/dhcpcd/dist/src/dhcp6.h             |    3 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.8.in         |    6 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c            |   58 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in    |    8 +
 external/bsd/dhcpcd/dist/src/dhcpcd.h            |   20 +-
 external/bsd/dhcpcd/dist/src/duid.c              |    1 +
 external/bsd/dhcpcd/dist/src/duid.h              |    1 +
 external/bsd/dhcpcd/dist/src/eloop.c             |    1 +
 external/bsd/dhcpcd/dist/src/eloop.h             |    1 +
 external/bsd/dhcpcd/dist/src/if-bsd.c            |   30 +-
 external/bsd/dhcpcd/dist/src/if-options.c        |   39 +-
 external/bsd/dhcpcd/dist/src/if-options.h        |    3 +-
 external/bsd/dhcpcd/dist/src/if.c                |   83 +---
 external/bsd/dhcpcd/dist/src/if.h                |    4 +-
 external/bsd/dhcpcd/dist/src/ipv4.c              |  135 ++--
 external/bsd/dhcpcd/dist/src/ipv4.h              |   11 +-
 external/bsd/dhcpcd/dist/src/ipv4ll.c            |  432 ++++++++-------
 external/bsd/dhcpcd/dist/src/ipv4ll.h            |   13 +-
 external/bsd/dhcpcd/dist/src/ipv6.c              |   87 +--
 external/bsd/dhcpcd/dist/src/ipv6.h              |    5 +-
 external/bsd/dhcpcd/dist/src/ipv6nd.c            |  242 +++++---
 external/bsd/dhcpcd/dist/src/ipv6nd.h            |    5 +-
 external/bsd/dhcpcd/dist/src/logerr.c            |   61 +-
 external/bsd/dhcpcd/dist/src/logerr.h            |    1 +
 external/bsd/dhcpcd/dist/src/route.c             |  412 +++++++++++----
 external/bsd/dhcpcd/dist/src/route.h             |   34 +-
 external/bsd/dhcpcd/dist/src/sa.c                |   33 +
 external/bsd/dhcpcd/dist/src/sa.h                |    7 +
 external/bsd/dhcpcd/dist/src/script.c            |  592 ++++++++--------------
 external/bsd/dhcpcd/dist/src/script.h            |    2 +
 50 files changed, 1894 insertions(+), 1929 deletions(-)

diffs (truncated from 6683 to 300 lines):

diff -r 6bef39fb830b -r 634f42e171a0 external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant
--- a/external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant  Wed Jul 17 18:24:23 2019 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/10-wpa_supplicant  Wed Jul 24 09:54:49 2019 +0000
@@ -93,7 +93,7 @@
        err=$(wpa_cli -i"$interface" terminate 2>&1)
        errn=$?
        if [ $errn != 0 ]; then
-               syslog err "failed to start wpa_supplicant"
+               syslog err "failed to stop wpa_supplicant"
                syslog err "$err"
        fi
        return $errn
diff -r 6bef39fb830b -r 634f42e171a0 external/bsd/dhcpcd/dist/hooks/20-resolv.conf
--- a/external/bsd/dhcpcd/dist/hooks/20-resolv.conf     Wed Jul 17 18:24:23 2019 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/20-resolv.conf     Wed Jul 24 09:54:49 2019 +0000
@@ -19,6 +19,7 @@
        interfaces=$(list_interfaces "$resolv_conf_dir")
 
        # Build the resolv.conf
+       header=
        if [ -n "$interfaces" ]; then
                # Build the header
                for x in ${interfaces}; do
@@ -69,30 +70,26 @@
 }
 
 # Extract any ND DNS options from the RA
-# For now, we ignore the lifetime of the DNS options unless they
-# are absent or zero.
-# In this case they are removed from consideration.
-# See draft-gont-6man-slaac-dns-config-issues-01 for issues
-# regarding DNS option lifetime in ND messages.
+# Obey the lifetimes
 eval_nd_dns()
 {
-       eval ltime=\$nd${i}_rdnss${j}_lifetime
-       if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
-               rdnss=
-       else
+
+       eval rdnsstime=\$nd${i}_rdnss${j}_lifetime
+       [ -z "$rdnsstime" ] && return 1
+       ltime=$(($rdnsstime - $offset))
+       if [ "$ltime" -gt 0 ]; then
                eval rdnss=\$nd${i}_rdnss${j}_servers
-       fi
-       eval ltime=\$nd${i}_dnssl${j}_lifetime
-       if [ -z "$ltime" ] || [ "$ltime" = 0 ]; then
-               dnssl=
-       else
-               eval dnssl=\$nd${i}_dnssl${j}_search
+               [ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
        fi
 
-       [ -z "${rdnss}${dnssl}" ] && return 1
+       eval dnssltime=\$nd${i}_dnssl${j}_lifetime
+       [ -z "$dnssltime" ] && return 1
+       ltime=$(($dnssltime - $offset))
+       if [ "$ltime" -gt 0 ]; then
+               eval dnssl=\$nd${i}_dnssl${j}_search
+               [ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
+       fi
 
-       [ -n "$rdnss" ] && new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
-       [ -n "$dnssl" ] && new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
        j=$(($j + 1))
        return 0
 }
@@ -106,12 +103,16 @@
        i=1
        j=1
        while true; do
+               eval acquired=\$nd${i}_acquired
+               [ -z "$acquired" ] && break
+               eval now=\$nd${i}_now
+               [ -z "$now" ] && break
+               offset=$(($now - $acquired))
                while true; do
                        eval_nd_dns || break
                done
                i=$(($i + 1))
                j=1
-               eval_nd_dns || break
        done
        [ -n "$new_rdnss" ] && \
            new_domain_name_servers="$new_domain_name_servers${new_domain_name_servers:+ }$new_rdnss"
diff -r 6bef39fb830b -r 634f42e171a0 external/bsd/dhcpcd/dist/hooks/50-ntp.conf
--- a/external/bsd/dhcpcd/dist/hooks/50-ntp.conf        Wed Jul 17 18:24:23 2019 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/50-ntp.conf        Wed Jul 24 09:54:49 2019 +0000
@@ -62,6 +62,7 @@
        # Build a list of interfaces
        interfaces=$(list_interfaces "$ntp_conf_dir")
 
+       header=
        servers=
        if [ -n "$interfaces" ]; then
                # Build the header
diff -r 6bef39fb830b -r 634f42e171a0 external/bsd/dhcpcd/dist/src/arp.c
--- a/external/bsd/dhcpcd/dist/src/arp.c        Wed Jul 17 18:24:23 2019 +0000
+++ b/external/bsd/dhcpcd/dist/src/arp.c        Wed Jul 24 09:54:49 2019 +0000
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
 /*
  * dhcpcd - ARP handler
  * Copyright (c) 2006-2019 Roy Marples <roy%marples.name@localhost>
@@ -36,6 +37,7 @@
 
 #include <errno.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -62,8 +64,9 @@
 /* Assert the correct structure size for on wire */
 __CTASSERT(sizeof(struct arphdr) == 8);
 
-ssize_t
-arp_request(const struct interface *ifp, in_addr_t sip, in_addr_t tip)
+static ssize_t
+arp_request(const struct interface *ifp,
+    const struct in_addr *sip, const struct in_addr *tip)
 {
        uint8_t arp_buffer[ARP_LEN];
        struct arphdr ar;
@@ -74,7 +77,7 @@
        ar.ar_hrd = htons(ifp->family);
        ar.ar_pro = htons(ETHERTYPE_IP);
        ar.ar_hln = ifp->hwlen;
-       ar.ar_pln = sizeof(sip);
+       ar.ar_pln = sizeof(tip->s_addr);
        ar.ar_op = htons(ARPOP_REQUEST);
 
        p = arp_buffer;
@@ -93,9 +96,12 @@
 
        APPEND(&ar, sizeof(ar));
        APPEND(ifp->hwaddr, ifp->hwlen);
-       APPEND(&sip, sizeof(sip));
+       if (sip != NULL)
+               APPEND(&sip->s_addr, sizeof(sip->s_addr));
+       else
+               ZERO(sizeof(tip->s_addr));
        ZERO(ifp->hwlen);
-       APPEND(&tip, sizeof(tip));
+       APPEND(&tip->s_addr, sizeof(tip->s_addr));
 
        state = ARP_CSTATE(ifp);
        return bpf_send(ifp, state->bpf_fd, ETHERTYPE_ARP, arp_buffer, len);
@@ -106,6 +112,77 @@
 }
 
 static void
+arp_report_conflicted(const struct arp_state *astate,
+    const struct arp_msg *amsg)
+{
+       char buf[HWADDR_LEN * 3];
+
+       if (amsg == NULL) {
+               logerrx("%s: DAD detected %s",
+                   astate->iface->name, inet_ntoa(astate->addr));
+               return;
+       }
+
+       logerrx("%s: hardware address %s claims %s",
+           astate->iface->name,
+           hwaddr_ntoa(amsg->sha, astate->iface->hwlen, buf, sizeof(buf)),
+           inet_ntoa(astate->addr));
+}
+
+
+static void
+arp_found(struct arp_state *astate, const struct arp_msg *amsg)
+{
+       struct interface *ifp;
+       struct ivp4_addr *ia;
+#ifndef KERNEL_RFC5227
+       struct timespec now, defend;
+#endif
+
+       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);
+               return;
+       }
+
+#ifndef KERNEL_RFC5227
+       /* RFC 3927 Section 2.5 says a defence should
+        * broadcast an ARP announcement.
+        * Because the kernel will also unicast a reply to the
+        * hardware address which requested the IP address
+        * the other IPv4LL client will receieve two ARP
+        * messages.
+        * If another conflict happens within DEFEND_INTERVAL
+        * then we must drop our address and negotiate a new one. */
+       defend.tv_sec = astate->defend.tv_sec + DEFEND_INTERVAL;
+       defend.tv_nsec = astate->defend.tv_nsec;
+       clock_gettime(CLOCK_MONOTONIC, &now);
+       if (timespeccmp(&defend, &now, >))
+               logwarnx("%s: %d second defence failed for %s",
+                   ifp->name, DEFEND_INTERVAL, inet_ntoa(astate->addr));
+       else if (arp_request(ifp, &astate->addr, &astate->addr) == -1)
+               logerr(__func__);
+       else {
+               logdebugx("%s: defended address %s",
+                   ifp->name, inet_ntoa(astate->addr));
+               astate->defend = now;
+               return;
+       }
+#endif
+
+       if (astate->defend_failed_cb != NULL)
+               astate->defend_failed_cb(astate);
+}
+
+static void
 arp_packet(struct interface *ifp, uint8_t *data, size_t len)
 {
        const struct interface *ifn;
@@ -164,14 +241,15 @@
        memcpy(&arm.tha, hw_t, ar.ar_hln);
        memcpy(&arm.tip.s_addr, hw_t + ar.ar_hln, ar.ar_pln);
 
-       /* Run the conflicts */
+       /* Match the ARP probe to our states.
+        * Ignore Unicast Poll, RFC1122. */
        state = ARP_CSTATE(ifp);
        TAILQ_FOREACH_SAFE(astate, &state->arp_states, next, astaten) {
-               if (arm.sip.s_addr != astate->addr.s_addr &&
-                   arm.tip.s_addr != astate->addr.s_addr)
-                       continue;
-               if (astate->conflicted_cb)
-                       astate->conflicted_cb(astate, &arm);
+               if (IN_ARE_ADDR_EQUAL(&arm.sip, &astate->addr) ||
+                   (IN_IS_ADDR_UNSPECIFIED(&arm.sip) &&
+                   IN_ARE_ADDR_EQUAL(&arm.tip, &astate->addr) &&
+                   state->bpf_flags & BPF_BCAST))
+                       arp_found(astate, &arm);
        }
 }
 
@@ -243,7 +321,7 @@
        }
 }
 
-int
+static int
 arp_open(struct interface *ifp)
 {
        struct iarp_state *state;
@@ -265,7 +343,8 @@
 {
        struct arp_state *astate = arg;
 
-       astate->probed_cb(astate);
+       timespecclear(&astate->defend);
+       astate->not_found_cb(astate);
 }
 
 static void
@@ -290,7 +369,7 @@
            ifp->name, inet_ntoa(astate->addr),
            astate->probes ? astate->probes : PROBE_NUM, PROBE_NUM,
            timespec_to_double(&tv));
-       if (arp_request(ifp, 0, astate->addr.s_addr) == -1)
+       if (arp_request(ifp, NULL, &astate->addr) == -1)
                logerr(__func__);
 }
 
@@ -314,6 +393,23 @@
 }
 #endif /* ARP */
 
+static struct arp_state *
+arp_find(struct interface *ifp, const struct in_addr *addr)
+{
+       struct iarp_state *state;
+       struct arp_state *astate;
+
+       if ((state = ARP_STATE(ifp)) == NULL)
+               goto out;
+       TAILQ_FOREACH(astate, &state->arp_states, next) {
+               if (astate->addr.s_addr == addr->s_addr && astate->iface == ifp)
+                       return astate;
+       }
+out:
+       errno = ESRCH;
+       return NULL;
+}
+
 static void
 arp_announced(void *arg)



Home | Main Index | Thread Index | Old Index