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 Sync with dhcpcd-9.4.0



details:   https://anonhg.NetBSD.org/src/rev/63e09ecf9a72
branches:  trunk
changeset: 1017458:63e09ecf9a72
user:      roy <roy%NetBSD.org@localhost>
date:      Mon Dec 28 13:57:40 2020 +0000

description:
Sync with dhcpcd-9.4.0

diffstat:

 external/bsd/dhcpcd/dist/hooks/20-resolv.conf |  23 +++++-
 external/bsd/dhcpcd/dist/src/dhcp.c           |  18 +----
 external/bsd/dhcpcd/dist/src/dhcp6.c          |   3 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c         |  93 +++++++++++++++++---------
 external/bsd/dhcpcd/dist/src/if-bsd.c         |  15 ++++
 external/bsd/dhcpcd/dist/src/if-options.c     |   4 +
 external/bsd/dhcpcd/dist/src/ipv6nd.c         |   2 -
 external/bsd/dhcpcd/dist/src/privsep.c        |   4 +-
 external/bsd/dhcpcd/dist/src/script.c         |  72 +++++++++++++-------
 9 files changed, 153 insertions(+), 81 deletions(-)

diffs (truncated from 516 to 300 lines):

diff -r a9a443664290 -r 63e09ecf9a72 external/bsd/dhcpcd/dist/hooks/20-resolv.conf
--- a/external/bsd/dhcpcd/dist/hooks/20-resolv.conf     Mon Dec 28 13:56:25 2020 +0000
+++ b/external/bsd/dhcpcd/dist/hooks/20-resolv.conf     Mon Dec 28 13:57:40 2020 +0000
@@ -7,9 +7,15 @@
 # or dnsmasq. This is important as the libc resolver isn't that powerful.
 
 resolv_conf_dir="$state_dir/resolv.conf"
+nocarrier_roaming_dir="$state_dir/roaming"
 NL="
 "
 : ${resolvconf:=resolvconf}
+if type "$resolvconf" >/dev/null 2>&1; then
+       have_resolvconf=true
+else
+       have_resolvconf=false
+fi
 
 build_resolv_conf()
 {
@@ -164,7 +170,7 @@
        for x in ${new_domain_name_servers}; do
                conf="${conf}nameserver $x$NL"
        done
-       if type "$resolvconf" >/dev/null 2>&1; then
+       if $have_resolvconf; then
                [ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
                printf %s "$conf" | "$resolvconf" -a "$ifname"
                return $?
@@ -180,7 +186,7 @@
 
 remove_resolv_conf()
 {
-       if type "$resolvconf" >/dev/null 2>&1; then
+       if $have_resolvconf; then
                "$resolvconf" -d "$ifname" -f
        else
                if [ -e "$resolv_conf_dir/$ifname" ]; then
@@ -199,7 +205,18 @@
 esac
 
 if $if_configured; then
-       if $if_up || [ "$reason" = ROUTERADVERT ]; then
+       if $have_resolvconf && [ "$reason" = NOCARRIER_ROAMING ]; then
+               # avoid calling resolvconf -c on CARRIER unless we roam
+               mkdir -p "$nocarrier_roaming_dir"
+               echo " " >"$nocarrier_roaming_dir/$interface"
+               "$resolvconf" -C "$interface.*"
+       elif $have_resolvconf && [ "$reason" = CARRIER ]; then
+               # Not all resolvconf implementations support -c
+               if [ -e "$nocarrier_roaming_dir/$interface" ]; then
+                       rm -f "$nocarrier_roaming_dir/$interface"
+                       "$resolvconf" -c "$interface.*"
+               fi
+       elif $if_up || [ "$reason" = ROUTERADVERT ]; then
                add_resolv_conf
        elif $if_down; then
                remove_resolv_conf
diff -r a9a443664290 -r 63e09ecf9a72 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Mon Dec 28 13:56:25 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Mon Dec 28 13:57:40 2020 +0000
@@ -3886,20 +3886,9 @@
        state->clientid = NULL;
 
        if (ifo->options & DHCPCD_ANONYMOUS) {
-               uint8_t duid[DUID_LEN];
-               uint8_t duid_len;
-
-               duid_len = (uint8_t)duid_make(duid, ifp, DUID_LL);
-               if (duid_len != 0) {
-                       state->clientid = malloc((size_t)duid_len + 6);
-                       if (state->clientid == NULL)
-                               goto eexit;
-                       state->clientid[0] =(uint8_t)(duid_len + 5);
-                       state->clientid[1] = 255; /* RFC 4361 */
-                       memcpy(state->clientid + 2, ifo->iaid, 4);
-                       memset(state->clientid + 2, 0, 4); /* IAID */
-                       memcpy(state->clientid + 6, duid, duid_len);
-               }
+               /* Removing the option could show that we want anonymous.
+                * As such keep it as it's already in the hwaddr field. */
+               goto make_clientid;
        } else if (*ifo->clientid) {
                state->clientid = malloc((size_t)(ifo->clientid[0] + 1));
                if (state->clientid == NULL)
@@ -3917,6 +3906,7 @@
                        memcpy(state->clientid + 6, ifp->ctx->duid,
                            ifp->ctx->duid_len);
                } else {
+make_clientid:
                        len = (uint8_t)(ifp->hwlen + 1);
                        state->clientid = malloc((size_t)len + 1);
                        if (state->clientid == NULL)
diff -r a9a443664290 -r 63e09ecf9a72 external/bsd/dhcpcd/dist/src/dhcp6.c
--- a/external/bsd/dhcpcd/dist/src/dhcp6.c      Mon Dec 28 13:56:25 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp6.c      Mon Dec 28 13:57:40 2020 +0000
@@ -2065,7 +2065,8 @@
        state->lerror = code;
        errno = 0;
 
-       if (code != 0 && ifp->ctx->options & DHCPCD_TEST)
+       /* code cannot be D6_STATUS_OK, so there is a failure */
+       if (ifp->ctx->options & DHCPCD_TEST)
                eloop_exit(ifp->ctx->eloop, EXIT_FAILURE);
 
        return (int)code;
diff -r a9a443664290 -r 63e09ecf9a72 external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c     Mon Dec 28 13:56:25 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c     Mon Dec 28 13:57:40 2020 +0000
@@ -695,36 +695,55 @@
        loginfox("%s: connected to Access Point: %s", ifp->name, pssid);
 }
 
+static void
+dhcpcd_nocarrier_roaming(struct interface *ifp)
+{
+
+       loginfox("%s: carrier lost - roaming", ifp->name);
+
+#ifdef ARP
+       arp_drop(ifp);
+#endif
+#ifdef INET
+       dhcp_abort(ifp);
+#endif
+#ifdef DHCP6
+       dhcp6_abort(ifp);
+#endif
+
+       rt_build(ifp->ctx, AF_UNSPEC);
+       script_runreason(ifp, "NOCARRIER_ROAMING");
+}
+
 void
 dhcpcd_handlecarrier(struct interface *ifp, int carrier, unsigned int flags)
 {
        bool was_link_up = if_is_link_up(ifp);
+       bool was_roaming = if_roaming(ifp);
 
        ifp->carrier = carrier;
        ifp->flags = flags;
 
        if (!if_is_link_up(ifp)) {
-               if (!was_link_up || !ifp->active)
+               if (!ifp->active || (!was_link_up && !was_roaming))
                        return;
+
+               /*
+                * If the interface is roaming (generally on wireless)
+                * then while we are not up, we are not down either.
+                * Preserve the network state until we either disconnect
+                * or re-connect.
+                */
+               if (!ifp->options->randomise_hwaddr && if_roaming(ifp)) {
+                       dhcpcd_nocarrier_roaming(ifp);
+                       return;
+               }
+
                loginfox("%s: carrier lost", ifp->name);
                script_runreason(ifp, "NOCARRIER");
-#ifdef NOCARRIER_PRESERVE_IP
-               if (ifp->flags & IFF_UP &&
-                   !(ifp->options->options & DHCPCD_ANONYMOUS))
-               {
-#ifdef ARP
-                       arp_drop(ifp);
-#endif
-#ifdef INET
-                       dhcp_abort(ifp);
-#endif
-#ifdef DHCP6
-                       dhcp6_abort(ifp);
-#endif
-               } else
-#endif
-                       dhcpcd_drop(ifp, 0);
-               if (ifp->options->options & DHCPCD_ANONYMOUS) {
+               dhcpcd_drop(ifp, 0);
+
+               if (ifp->options->randomise_hwaddr) {
                        bool is_up = ifp->flags & IFF_UP;
 
                        if (is_up)
@@ -734,6 +753,7 @@
                        if (is_up)
                                if_up(ifp);
                }
+
                return;
        }
 
@@ -774,9 +794,7 @@
                    memcmp(ifp->ssid, ossid, ifp->ssid_len)) && ifp->active)
                {
                        dhcpcd_reportssid(ifp);
-#ifdef NOCARRIER_PRESERVE_IP
                        dhcpcd_drop(ifp, 0);
-#endif
 #ifdef IPV4LL
                        ipv4ll_reset(ifp);
 #endif
@@ -788,17 +806,17 @@
 
        dhcpcd_initstate(ifp, 0);
        script_runreason(ifp, "CARRIER");
+
 #ifdef INET6
-#ifdef NOCARRIER_PRESERVE_IP
        /* Set any IPv6 Routers we remembered to expire faster than they
         * would normally as we maybe on a new network. */
        ipv6nd_startexpire(ifp);
-#endif
 #ifdef IPV6_MANAGETEMPADDR
        /* RFC4941 Section 3.5 */
        ipv6_regentempaddrs(ifp);
 #endif
 #endif
+
        dhcpcd_startinterface(ifp);
 }
 
@@ -951,22 +969,22 @@
 {
        struct interface *ifp = arg;
        struct dhcpcd_ctx *ctx = ifp->ctx;
-       bool anondown;
+       bool randmac_down;
 
        if (ifp->carrier <= LINK_DOWN &&
-           ifp->options->options & DHCPCD_ANONYMOUS &&
+           ifp->options->randomise_hwaddr &&
            ifp->flags & IFF_UP)
        {
                if_down(ifp);
-               anondown = true;
+               randmac_down = true;
        } else
-               anondown = false;
+               randmac_down = false;
 
        if ((!(ctx->options & DHCPCD_MASTER) ||
-           ifp->options->options & DHCPCD_IF_UP || anondown) &&
+           ifp->options->options & DHCPCD_IF_UP || randmac_down) &&
            !(ifp->flags & IFF_UP))
        {
-               if (ifp->options->options & DHCPCD_ANONYMOUS &&
+               if (ifp->options->randomise_hwaddr &&
                    if_randomisemac(ifp) == -1)
                        logerr(__func__);
                if (if_up(ifp) == -1)
@@ -1161,8 +1179,10 @@
 
        socklen = sizeof(rcvbuflen);
        if (getsockopt(ctx->link_fd, SOL_SOCKET,
-           SO_RCVBUF, &rcvbuflen, &socklen) == -1)
+           SO_RCVBUF, &rcvbuflen, &socklen) == -1) {
+               logerr("%s: getsockopt", __func__);
                rcvbuflen = 0;
+       }
 #ifdef __linux__
        else
                rcvbuflen /= 2;
@@ -1239,8 +1259,9 @@
        }
 
        if (ifp->hwtype != hwtype) {
-               loginfox("%s: hardware address type changed from %d to %d",
-                   ifp->name, ifp->hwtype, hwtype);
+               if (ifp->active)
+                       loginfox("%s: hardware address type changed"
+                           " from %d to %d", ifp->name, ifp->hwtype, hwtype);
                ifp->hwtype = hwtype;
        }
 
@@ -1248,8 +1269,12 @@
            (hwlen == 0 || memcmp(ifp->hwaddr, hwaddr, hwlen) == 0))
                return;
 
-       loginfox("%s: new hardware address: %s", ifp->name,
-           hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf)));
+       if (ifp->active) {
+               loginfox("%s: old hardware address: %s", ifp->name,
+                   hwaddr_ntoa(ifp->hwaddr, ifp->hwlen, buf, sizeof(buf)));
+               loginfox("%s: new hardware address: %s", ifp->name,
+                   hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf)));
+       }
        ifp->hwlen = hwlen;
        if (hwaddr != NULL)
                memcpy(ifp->hwaddr, hwaddr, hwlen);
@@ -2257,10 +2282,10 @@
        if (ctx.stdin_valid && freopen(_PATH_DEVNULL, "w", stdin) == NULL)
                logwarn("freopen stdin");
 
+#if defined(USE_SIGNALS) && !defined(THERE_IS_NO_FORK)
        if (!(ctx.options & DHCPCD_DAEMONISE))
                goto start_master;
 
-#if defined(USE_SIGNALS) && !defined(THERE_IS_NO_FORK)
        if (xsocketpair(AF_UNIX, SOCK_DGRAM | SOCK_CXNB, 0, fork_fd) == -1 ||
            (ctx.stderr_valid &&
            xsocketpair(AF_UNIX, SOCK_DGRAM | SOCK_CXNB, 0, stderr_fd) == -1))



Home | Main Index | Thread Index | Old Index