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 with dhcpcd-9.3.0



details:   https://anonhg.NetBSD.org/src/rev/63f19233ac59
branches:  trunk
changeset: 944643:63f19233ac59
user:      roy <roy%NetBSD.org@localhost>
date:      Mon Oct 05 16:02:15 2020 +0000

description:
Sync with dhcpcd-9.3.0

diffstat:

 external/bsd/dhcpcd/dist/src/bpf.c        |    7 +-
 external/bsd/dhcpcd/dist/src/dhcp.c       |   18 +-
 external/bsd/dhcpcd/dist/src/dhcp6.c      |   10 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c     |  216 +++++++++++++++--------------
 external/bsd/dhcpcd/dist/src/if-bsd.c     |   96 ++++++------
 external/bsd/dhcpcd/dist/src/if-options.c |   52 +++---
 external/bsd/dhcpcd/dist/src/ipv6nd.c     |    2 +-
 external/bsd/dhcpcd/dist/src/logerr.c     |    2 +-
 external/bsd/dhcpcd/dist/src/privsep.c    |  109 ++++++++++++---
 external/bsd/dhcpcd/dist/src/script.c     |    2 +-
 10 files changed, 299 insertions(+), 215 deletions(-)

diffs (truncated from 1096 to 300 lines):

diff -r 25e6c9082fe9 -r 63f19233ac59 external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Mon Oct 05 16:01:13 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Mon Oct 05 16:02:15 2020 +0000
@@ -70,14 +70,14 @@
        (insn)->jt = 0;                                         \
        (insn)->jf = 0;                                         \
        (insn)->k = (uint32_t)(v);                              \
-};
+}
 
 #define        BPF_SET_JUMP(insn, c, v, t, f) {                        \
        (insn)->code = (c);                                     \
        (insn)->jt = (t);                                       \
        (insn)->jf = (f);                                       \
        (insn)->k = (uint32_t)(v);                              \
-};
+}
 
 size_t
 bpf_frame_header_len(const struct interface *ifp)
@@ -585,9 +585,6 @@
 };
 #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_base[] = {
        /* Make sure it's an IPv4 packet. */
        BPF_STMT(BPF_LD + BPF_B + BPF_IND, 0),
diff -r 25e6c9082fe9 -r 63f19233ac59 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Mon Oct 05 16:01:13 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Mon Oct 05 16:02:15 2020 +0000
@@ -1164,7 +1164,7 @@
                logdebugx("reading standard input");
                sbytes = read(fileno(stdin), buf.buf, sizeof(buf.buf));
        } else {
-               logdebugx("%s: reading lease `%s'",
+               logdebugx("%s: reading lease: %s",
                    ifp->name, state->leasefile);
                sbytes = dhcp_readfile(ifp->ctx, state->leasefile,
                    buf.buf, sizeof(buf.buf));
@@ -2314,7 +2314,7 @@
        state->state = DHS_BOUND;
        if (!state->lease.frominfo &&
            !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))) {
-               logdebugx("%s: writing lease `%s'",
+               logdebugx("%s: writing lease: %s",
                    ifp->name, state->leasefile);
                if (dhcp_writefile(ifp->ctx, state->leasefile, 0640,
                    state->new, state->new_len) == -1)
@@ -2865,10 +2865,10 @@
                print_string(sname, sizeof(sname), OT_STRING | OT_DOMAIN,
                    bootp->sname, sizeof(bootp->sname));
                if (a == NULL)
-                       logmessage(loglevel, "%s: %s %s %s `%s'",
+                       logmessage(loglevel, "%s: %s %s %s %s",
                            ifp->name, msg, tfrom, inet_ntoa(addr), sname);
                else
-                       logmessage(loglevel, "%s: %s %s %s %s `%s'",
+                       logmessage(loglevel, "%s: %s %s %s %s %s",
                            ifp->name, msg, a, tfrom, inet_ntoa(addr), sname);
        } else {
                if (r != 0) {
@@ -3477,6 +3477,16 @@
 #ifdef PRIVSEP
        const struct dhcp_state *state = D_CSTATE(ifp);
 
+       /* It's possible that an interface departs and arrives in short
+        * order to receive a BPF frame out of order.
+        * There is a similar check in ARP, but much lower down the stack.
+        * It's not needed for other inet protocols because we send the
+        * message as a whole and select the interface off that and then
+        * check state. BPF on the other hand is very interface
+        * specific and we do need this check. */
+       if (state == NULL)
+               return;
+
        /* Ignore double reads */
        if (IN_PRIVSEP(ifp->ctx)) {
                switch (state->state) {
diff -r 25e6c9082fe9 -r 63f19233ac59 external/bsd/dhcpcd/dist/src/dhcp6.c
--- a/external/bsd/dhcpcd/dist/src/dhcp6.c      Mon Oct 05 16:01:13 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp6.c      Mon Oct 05 16:02:15 2020 +0000
@@ -147,7 +147,7 @@
        uint16_t dhcp6_opt;
 };
 
-const struct dhcp_compat dhcp_compats[] = {
+static const struct dhcp_compat dhcp_compats[] = {
        { DHO_DNSSERVER,        D6_OPTION_DNS_SERVERS },
        { DHO_HOSTNAME,         D6_OPTION_FQDN },
        { DHO_DNSDOMAIN,        D6_OPTION_FQDN },
@@ -2588,7 +2588,7 @@
                logdebugx("reading standard input");
                bytes = read(fileno(stdin), buf.buf, sizeof(buf.buf));
        } else {
-               logdebugx("%s: reading lease `%s'",
+               logdebugx("%s: reading lease: %s",
                    ifp->name, state->leasefile);
                bytes = dhcp_readfile(ifp->ctx, state->leasefile,
                    buf.buf, sizeof(buf.buf));
@@ -3218,7 +3218,7 @@
                            ifp->name, state->expire);
                rt_build(ifp->ctx, AF_INET6);
                if (!confirmed && !timedout) {
-                       logdebugx("%s: writing lease `%s'",
+                       logdebugx("%s: writing lease: %s",
                            ifp->name, state->leasefile);
                        if (dhcp_writefile(ifp->ctx, state->leasefile, 0640,
                            state->new, state->new_len) == -1)
@@ -3657,12 +3657,12 @@
            "/tmp/dhcp6.reply%d.raw", replyn++);
        fd = open(fname, O_RDONLY, 0);
        if (fd == -1) {
-               logerr("%s: open `%s'", __func__, fname);
+               logerr("%s: open: %s", __func__, fname);
                return;
        }
        tlen = read(fd, tbuf, sizeof(tbuf));
        if (tlen == -1)
-               logerr("%s: read `%s'", __func__, fname);
+               logerr("%s: read: %s", __func__, fname);
        close(fd);
 
        /* Copy across ServerID so we can work with our own server. */
diff -r 25e6c9082fe9 -r 63f19233ac59 external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c     Mon Oct 05 16:01:13 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c     Mon Oct 05 16:02:15 2020 +0000
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-const char dhcpcd_copyright[] = "Copyright (c) 2006-2020 Roy Marples";
+static const char dhcpcd_copyright[] = "Copyright (c) 2006-2020 Roy Marples";
 
 #include <sys/file.h>
 #include <sys/ioctl.h>
@@ -360,7 +360,7 @@
                return;
 
        /* Don't use loginfo because this makes no sense in a log. */
-       if (!(logopts & LOGERR_QUIET))
+       if (!(logopts & LOGERR_QUIET) && ctx->stderr_valid)
                (void)fprintf(stderr,
                    "forked to background, child pid %d\n", getpid());
        i = EXIT_SUCCESS;
@@ -432,8 +432,6 @@
        /* De-activate the interface */
        ifp->active = IF_INACTIVE;
        ifp->options->options &= ~DHCPCD_STOPPING;
-       /* Set the link state to unknown as we're no longer tracking it. */
-       ifp->carrier = LINK_UNKNOWN;
 
        if (!(ctx->options & (DHCPCD_MASTER | DHCPCD_TEST)))
                eloop_exit(ctx->eloop, EXIT_FAILURE);
@@ -700,43 +698,36 @@
                return;
        }
 
-       loginfox("%s: connected to Access Point `%s'", ifp->name, pssid);
+       loginfox("%s: connected to Access Point: %s", ifp->name, pssid);
 }
 
 void
-dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
-    const char *ifname)
+dhcpcd_handlecarrier(struct interface *ifp, int carrier, unsigned int flags)
 {
-       struct interface *ifp;
-
-       ifp = if_find(ctx->ifaces, ifname);
-       if (ifp == NULL ||
-           ifp->options == NULL || !(ifp->options->options & DHCPCD_LINK) ||
-           !ifp->active)
-               return;
+       bool nolink = ifp->options == NULL ||
+           !(ifp->options->options & DHCPCD_LINK);
 
+       ifp->flags = flags;
        if (carrier == LINK_UNKNOWN) {
-               if (ifp->wireless) {
+               if (ifp->wireless)
                        carrier = LINK_DOWN;
-                       ifp->flags = flags;
-               } else
-                       carrier = if_carrier(ifp);
-       } else
-               ifp->flags = flags;
-       if (carrier == LINK_UNKNOWN)
-               carrier = IF_UPANDRUNNING(ifp) ? LINK_UP : LINK_DOWN;
+               else
+                       carrier = IF_UPANDRUNNING(ifp) ? LINK_UP : LINK_DOWN;
+       }
 
        if (carrier == LINK_DOWN || (ifp->flags & IFF_UP) == 0) {
                if (ifp->carrier != LINK_DOWN) {
-                       if (ifp->carrier == LINK_UP)
-                               loginfox("%s: carrier lost", ifp->name);
 #ifdef NOCARRIER_PRESERVE_IP
                        if (ifp->flags & IFF_UP &&
-                           !(ifp->options->options & DHCPCD_ANONYMOUS))
+                           (ifp->options == NULL ||
+                           !(ifp->options->options & DHCPCD_ANONYMOUS)))
                                ifp->carrier = LINK_DOWN_IFFUP;
                        else
 #endif
                                ifp->carrier = LINK_DOWN;
+                       if (!ifp->active || nolink)
+                               return;
+                       loginfox("%s: carrier lost", ifp->name);
                        script_runreason(ifp, "NOCARRIER");
 #ifdef NOCARRIER_PRESERVE_IP
                        if (ifp->flags & IFF_UP &&
@@ -767,13 +758,14 @@
                }
        } else if (carrier == LINK_UP && ifp->flags & IFF_UP) {
                if (ifp->carrier != LINK_UP) {
-                       loginfox("%s: carrier acquired", ifp->name);
                        ifp->carrier = LINK_UP;
+                       if (ifp->active)
+                               loginfox("%s: carrier acquired", ifp->name);
 #if !defined(__linux__) && !defined(__NetBSD__)
                        /* BSD does not emit RTM_NEWADDR or RTM_CHGADDR when the
                         * hardware address changes so we have to go
                         * through the disovery process to work it out. */
-                       dhcpcd_handleinterface(ctx, 0, ifp->name);
+                       dhcpcd_handleinterface(ifp->ctx, 0, ifp->name);
 #endif
                        if (ifp->wireless) {
                                uint8_t ossid[IF_SSIDLEN];
@@ -784,8 +776,9 @@
                                if_getssid(ifp);
 
                                /* If we changed SSID network, drop leases */
-                               if (ifp->ssid_len != olen ||
-                                   memcmp(ifp->ssid, ossid, ifp->ssid_len))
+                               if ((ifp->ssid_len != olen ||
+                                   memcmp(ifp->ssid, ossid, ifp->ssid_len)) &&
+                                   ifp->active)
                                {
                                        dhcpcd_reportssid(ifp);
 #ifdef NOCARRIER_PRESERVE_IP
@@ -796,6 +789,8 @@
 #endif
                                }
                        }
+                       if (!ifp->active || nolink)
+                               return;
                        dhcpcd_initstate(ifp, 0);
                        script_runreason(ifp, "CARRIER");
 #ifdef INET6
@@ -871,20 +866,11 @@
        struct interface *ifp = arg;
        struct if_options *ifo = ifp->options;
 
-       if (ifo->options & DHCPCD_LINK) {
-               switch (ifp->carrier) {
-               case LINK_UP:
-                       break;
-               case LINK_DOWN:
-                       loginfox("%s: waiting for carrier", ifp->name);
-                       return;
-               case LINK_UNKNOWN:
-                       /* No media state available.
-                        * Loop until both IFF_UP and IFF_RUNNING are set */
-                       if (ifo->poll == 0)
-                               if_pollinit(ifp);
-                       return;
-               }
+       if (ifo->options & DHCPCD_LINK && (ifp->carrier == LINK_DOWN ||
+           (ifp->carrier == LINK_UNKNOWN && !IF_UPANDRUNNING(ifp))))
+       {
+               loginfox("%s: waiting for carrier", ifp->name);
+               return;
        }
 
        if (ifo->options & (DHCPCD_DUID | DHCPCD_IPV6) &&
@@ -993,9 +979,6 @@
                        logerr(__func__);
        }
 
-       if (ifp->options->poll != 0)
-               if_pollinit(ifp);
-
        dhcpcd_startinterface(ifp);
 }
 
@@ -1034,14 +1017,13 @@
 int
 dhcpcd_handleinterface(void *arg, int action, const char *ifname)
 {
-       struct dhcpcd_ctx *ctx;
+       struct dhcpcd_ctx *ctx = arg;
        struct ifaddrs *ifaddrs;
        struct if_head *ifs;
        struct interface *ifp, *iff;
        const char * const argv[] = { ifname };
        int e;
 



Home | Main Index | Thread Index | Old Index