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 Update to dhcpcd-9.3.0 with the follo...



details:   https://anonhg.NetBSD.org/src/rev/d3ceb9732912
branches:  ROY
changeset: 940197:d3ceb9732912
user:      roy <roy%NetBSD.org@localhost>
date:      Mon Oct 05 16:01:13 2020 +0000

description:
Update to dhcpcd-9.3.0 with the following changes:
 * dhcpcd: Backticks have been removed from quoting filenames
 * dhcpcd: Only manipulate stdin, stdout and stderr if they are valid
 * duid: Adjust option so the type can be specified
 * logerr: Don't leak logfile fd to scripts
 * privsep: Run the launcher process in the sandbox
 * BSD: Use `ifi_link_state` as the single source of truth about carrier
 * BSD: Ignore vether(4) devices by default

diffstat:

 external/bsd/dhcpcd/dist/README.md             |    5 -
 external/bsd/dhcpcd/dist/src/bpf.c             |    7 +-
 external/bsd/dhcpcd/dist/src/defs.h            |    2 +-
 external/bsd/dhcpcd/dist/src/dev.h             |    4 +-
 external/bsd/dhcpcd/dist/src/dhcp-common.c     |    2 +-
 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/dhcpcd.conf.5.in  |   19 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.h          |    8 +-
 external/bsd/dhcpcd/dist/src/duid.c            |   14 +-
 external/bsd/dhcpcd/dist/src/duid.h            |    1 +
 external/bsd/dhcpcd/dist/src/if-bsd.c          |   96 +++++-----
 external/bsd/dhcpcd/dist/src/if-options.c      |   52 +++--
 external/bsd/dhcpcd/dist/src/if-options.h      |    2 -
 external/bsd/dhcpcd/dist/src/if.c              |   49 +---
 external/bsd/dhcpcd/dist/src/if.h              |    5 +-
 external/bsd/dhcpcd/dist/src/ipv6nd.c          |    2 +-
 external/bsd/dhcpcd/dist/src/logerr.c          |    2 +-
 external/bsd/dhcpcd/dist/src/privsep-bpf.c     |   31 +--
 external/bsd/dhcpcd/dist/src/privsep-bsd.c     |   13 +-
 external/bsd/dhcpcd/dist/src/privsep-control.c |   13 +-
 external/bsd/dhcpcd/dist/src/privsep-inet.c    |   23 +--
 external/bsd/dhcpcd/dist/src/privsep-root.c    |   62 ++++--
 external/bsd/dhcpcd/dist/src/privsep-root.h    |    2 +-
 external/bsd/dhcpcd/dist/src/privsep.c         |  109 ++++++++++--
 external/bsd/dhcpcd/dist/src/privsep.h         |   18 +-
 external/bsd/dhcpcd/dist/src/script.c          |    2 +-
 28 files changed, 426 insertions(+), 361 deletions(-)

diffs (truncated from 1842 to 300 lines):

diff -r e0887f0bbbcc -r d3ceb9732912 external/bsd/dhcpcd/dist/README.md
--- a/external/bsd/dhcpcd/dist/README.md        Sun Sep 06 14:54:28 2020 +0000
+++ b/external/bsd/dhcpcd/dist/README.md        Mon Oct 05 16:01:13 2020 +0000
@@ -89,11 +89,6 @@
 dhcpcd-7 defaults the database directory to `/var/db/dhcpcd` instead of
 `/var/db` and now stores dhcpcd.duid and dhcpcd.secret in there instead of
 in /etc.
-dhcpcd-9 requires this directory and contents to be writeable by the
-unprivileged user (default _dhcpcd, _dhcp or dhcpcd).
-
-Of course this won't work if dhcpcd is packaged up, so packagers will need to
-install similar logic into their dhcpcd package.
 
 dhcpcd-9 defaults the run directory to `/var/run/dhcpcd` instead of
 `/var/run` and the prefix of dhcpcd has been removed from the files.
diff -r e0887f0bbbcc -r d3ceb9732912 external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Sun Sep 06 14:54:28 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Mon Oct 05 16:01:13 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 e0887f0bbbcc -r d3ceb9732912 external/bsd/dhcpcd/dist/src/defs.h
--- a/external/bsd/dhcpcd/dist/src/defs.h       Sun Sep 06 14:54:28 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/defs.h       Mon Oct 05 16:01:13 2020 +0000
@@ -29,7 +29,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "9.2.0"
+#define VERSION                        "9.3.0"
 
 #ifndef PRIVSEP_USER
 # define PRIVSEP_USER          "_" PACKAGE
diff -r e0887f0bbbcc -r d3ceb9732912 external/bsd/dhcpcd/dist/src/dev.h
--- a/external/bsd/dhcpcd/dist/src/dev.h        Sun Sep 06 14:54:28 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dev.h        Mon Oct 05 16:01:13 2020 +0000
@@ -31,7 +31,7 @@
 // dev plugin setup
 struct dev {
        const char *name;
-       int (*initialized)(const char *);
+       int (*initialised)(const char *);
        int (*listening)(void);
        int (*handle_device)(void *);
        int (*start)(void);
@@ -47,7 +47,7 @@
 // hooks for dhcpcd
 #ifdef PLUGIN_DEV
 #include "dhcpcd.h"
-int dev_initialized(struct dhcpcd_ctx *, const char *);
+int dev_initialised(struct dhcpcd_ctx *, const char *);
 int dev_listening(struct dhcpcd_ctx *);
 int dev_start(struct dhcpcd_ctx *, int (*)(void *, int, const char *));
 void dev_stop(struct dhcpcd_ctx *);
diff -r e0887f0bbbcc -r d3ceb9732912 external/bsd/dhcpcd/dist/src/dhcp-common.c
--- a/external/bsd/dhcpcd/dist/src/dhcp-common.c        Sun Sep 06 14:54:28 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp-common.c        Mon Oct 05 16:01:13 2020 +0000
@@ -615,7 +615,7 @@
        }
 
        /* Trim any extra data.
-        * Maybe we need a settng to reject DHCP options with extra data? */
+        * Maybe we need a setting to reject DHCP options with extra data? */
        if (opt->type & OT_ARRAY)
                return (ssize_t)(dl - (dl % sz));
        return (ssize_t)sz;
diff -r e0887f0bbbcc -r d3ceb9732912 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Sun Sep 06 14:54:28 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Mon Oct 05 16:01:13 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 e0887f0bbbcc -r d3ceb9732912 external/bsd/dhcpcd/dist/src/dhcp6.c
--- a/external/bsd/dhcpcd/dist/src/dhcp6.c      Sun Sep 06 14:54:28 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp6.c      Mon Oct 05 16:01:13 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 e0887f0bbbcc -r d3ceb9732912 external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c     Sun Sep 06 14:54:28 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c     Mon Oct 05 16:01:13 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)



Home | Main Index | Thread Index | Old Index