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



details:   https://anonhg.NetBSD.org/src/rev/b642824a760a
branches:  trunk
changeset: 934665:b642824a760a
user:      roy <roy%NetBSD.org@localhost>
date:      Mon Jun 15 16:59:05 2020 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/src/bpf.c        |    8 +
 external/bsd/dhcpcd/dist/src/dhcp6.c      |   15 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c     |  303 ++++++++++++++++-------------
 external/bsd/dhcpcd/dist/src/if-bsd.c     |   96 ++++++---
 external/bsd/dhcpcd/dist/src/if-options.c |   10 +-
 external/bsd/dhcpcd/dist/src/ipv6nd.c     |    6 +-
 external/bsd/dhcpcd/dist/src/logerr.c     |    3 +
 external/bsd/dhcpcd/dist/src/privsep.c    |  200 +++++++++++++++++--
 external/bsd/dhcpcd/dist/src/script.c     |    5 +-
 9 files changed, 427 insertions(+), 219 deletions(-)

diffs (truncated from 1086 to 300 lines):

diff -r aa6ed60ce645 -r b642824a760a external/bsd/dhcpcd/dist/src/bpf.c
--- a/external/bsd/dhcpcd/dist/src/bpf.c        Mon Jun 15 16:58:01 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/bpf.c        Mon Jun 15 16:59:05 2020 +0000
@@ -703,6 +703,14 @@
                return -1;
        return 0;
 #else
+#ifdef PRIVSEP
+#if defined(__sun) /* Solaris cannot send via BPF. */
+#elif defined(BIOCSETF)
+#warning No BIOCSETWF support - a compromised BPF can be used as a raw socket
+#else
+#warning A compromised PF_PACKET socket can be used as a raw socket
+#endif
+#endif
        return bpf_bootp_rw(bpf, true);
 #endif
 }
diff -r aa6ed60ce645 -r b642824a760a external/bsd/dhcpcd/dist/src/dhcp6.c
--- a/external/bsd/dhcpcd/dist/src/dhcp6.c      Mon Jun 15 16:58:01 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp6.c      Mon Jun 15 16:59:05 2020 +0000
@@ -541,12 +541,12 @@
                state->reason = "DELEGATED6";
        }
 
-       if (sla == NULL || sla->sla_set == 0) {
+       if (sla == NULL || !sla->sla_set) {
                /* No SLA set, so make an assumption of
                 * desired SLA and prefix length. */
                asla.sla = ifp->index;
                asla.prefix_len = 0;
-               asla.sla_set = 0;
+               asla.sla_set = false;
                sla = &asla;
        } else if (sla->prefix_len == 0) {
                /* An SLA was given, but prefix length was not.
@@ -554,7 +554,7 @@
                 * potentially more than one interface. */
                asla.sla = sla->sla;
                asla.prefix_len = 0;
-               asla.sla_set = 0;
+               asla.sla_set = sla->sla_set;
                sla = &asla;
        }
 
@@ -562,16 +562,15 @@
                uint32_t sla_max;
                int bits;
 
-               if (ia->sla_max == 0) {
+               sla_max = ia->sla_max;
+               if (sla_max == 0 && (sla == NULL || !sla->sla_set)) {
                        const struct interface *ifi;
 
-                       sla_max = 0;
                        TAILQ_FOREACH(ifi, ifp->ctx->ifaces, next) {
                                if (ifi->index > sla_max)
                                        sla_max = ifi->index;
                        }
-               } else
-                       sla_max = ia->sla_max;
+               }
 
                bits = fls32(sla_max);
 
@@ -1727,6 +1726,7 @@
                if (state->old != NULL)
                        script_runreason(ifp, "EXPIRE6");
                dhcp_unlink(ifp->ctx, state->leasefile);
+               dhcp6_addrequestedaddrs(ifp);
        }
 
        if (!dhcp6_startdiscoinform(ifp)) {
@@ -2672,6 +2672,7 @@
        free(state->new);
        state->new = NULL;
        state->new_len = 0;
+       dhcp6_addrequestedaddrs(ifp);
        return bytes == 0 ? 0 : -1;
 }
 
diff -r aa6ed60ce645 -r b642824a760a external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c     Mon Jun 15 16:58:01 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c     Mon Jun 15 16:59:05 2020 +0000
@@ -943,9 +943,12 @@
                }
 
 #ifdef DHCP6
-               if (ifo->options & DHCPCD_DHCP6) {
+               /* DHCPv6 could be turned off, but the interface
+                * is still delegated to. */
+               if (ifp->active)
                        dhcp6_find_delegates(ifp);
 
+               if (ifo->options & DHCPCD_DHCP6) {
                        if (ifp->active == IF_ACTIVE_USER) {
                                enum DH6S d6_state;
 
@@ -1400,6 +1403,11 @@
        unsigned long long opts;
        int exit_code;
 
+       if (ctx->options & DHCPCD_DUMPLEASE) {
+               eloop_exit(ctx->eloop, EXIT_FAILURE);
+               return;
+       }
+
        if (sig != SIGCHLD && ctx->options & DHCPCD_FORKED) {
                pid_t pid = pidfile_read(ctx->pidfile);
                if (pid == -1) {
@@ -1462,48 +1470,6 @@
 }
 #endif
 
-static void
-dhcpcd_getinterfaces(void *arg)
-{
-       struct fd_list *fd = arg;
-       struct interface *ifp;
-       size_t len;
-
-       len = 0;
-       TAILQ_FOREACH(ifp, fd->ctx->ifaces, next) {
-               if (!ifp->active)
-                       continue;
-               len++;
-#ifdef INET
-               if (D_STATE_RUNNING(ifp))
-                       len++;
-#endif
-#ifdef IPV4LL
-               if (IPV4LL_STATE_RUNNING(ifp))
-                       len++;
-#endif
-#ifdef INET6
-               if (IPV6_STATE_RUNNING(ifp))
-                       len++;
-               if (RS_STATE_RUNNING(ifp))
-                       len++;
-#endif
-#ifdef DHCP6
-               if (D6_STATE_RUNNING(ifp))
-                       len++;
-#endif
-       }
-       if (write(fd->fd, &len, sizeof(len)) != sizeof(len))
-               return;
-       eloop_event_remove_writecb(fd->ctx->eloop, fd->fd);
-       TAILQ_FOREACH(ifp, fd->ctx->ifaces, next) {
-               if (!ifp->active)
-                       continue;
-               if (send_interface(fd, ifp, AF_UNSPEC) == -1)
-                       logerr(__func__);
-       }
-}
-
 int
 dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd,
     int argc, char **argv)
@@ -1511,23 +1477,23 @@
        struct interface *ifp;
        unsigned long long opts;
        int opt, oi, do_reboot, do_renew, af = AF_UNSPEC;
-       size_t len, l;
+       size_t len, l, nifaces;
        char *tmp, *p;
 
        /* Special commands for our control socket
         * as the other end should be blocking until it gets the
         * expected reply we should be safely able just to change the
         * write callback on the fd */
+       /* Make any change here in privsep-control.c as well. */
        if (strcmp(*argv, "--version") == 0) {
                return control_queue(fd, UNCONST(VERSION),
-                   strlen(VERSION) + 1, false);
+                   strlen(VERSION) + 1);
        } else if (strcmp(*argv, "--getconfigfile") == 0) {
                return control_queue(fd, UNCONST(fd->ctx->cffile),
-                   strlen(fd->ctx->cffile) + 1, false);
+                   strlen(fd->ctx->cffile) + 1);
        } else if (strcmp(*argv, "--getinterfaces") == 0) {
-               eloop_event_add_w(fd->ctx->eloop, fd->fd,
-                   dhcpcd_getinterfaces, fd);
-               return 0;
+               optind = argc = 0;
+               goto dumplease;
        } else if (strcmp(*argv, "--listen") == 0) {
                fd->flags |= FD_LISTEN;
                return 0;
@@ -1591,8 +1557,8 @@
 
        if (opts & DHCPCD_DUMPLEASE) {
                ctx->options |= DHCPCD_DUMPLEASE;
-               size_t nifaces = 0;
-
+dumplease:
+               nifaces = 0;
                TAILQ_FOREACH(ifp, ctx->ifaces, next) {
                        if (!ifp->active)
                                continue;
@@ -1672,68 +1638,119 @@
        return 0;
 }
 
+static void dhcpcd_readdump1(void *);
+
+static void
+dhcpcd_readdump2(void *arg)
+{
+       struct dhcpcd_ctx *ctx = arg;
+       ssize_t len;
+       int exit_code = EXIT_FAILURE;
+
+       len = read(ctx->control_fd, ctx->ctl_buf + ctx->ctl_bufpos,
+           ctx->ctl_buflen - ctx->ctl_bufpos);
+       if (len == -1) {
+               logerr(__func__);
+               goto finished;
+       } else if (len == 0)
+               goto finished;
+       if ((size_t)len + ctx->ctl_bufpos != ctx->ctl_buflen) {
+               ctx->ctl_bufpos += (size_t)len;
+               return;
+       }
+
+       if (ctx->ctl_buf[ctx->ctl_buflen - 1] != '\0') /* unlikely */
+               ctx->ctl_buf[ctx->ctl_buflen - 1] = '\0';
+       script_dump(ctx->ctl_buf, ctx->ctl_buflen);
+       fflush(stdout);
+       if (--ctx->ctl_extra != 0) {
+               putchar('\n');
+               eloop_event_add(ctx->eloop, ctx->control_fd,
+                   dhcpcd_readdump1, ctx);
+               return;
+       }
+       exit_code = EXIT_SUCCESS;
+
+finished:
+       shutdown(ctx->control_fd, SHUT_RDWR);
+       eloop_exit(ctx->eloop, exit_code);
+}
+
+static void
+dhcpcd_readdump1(void *arg)
+{
+       struct dhcpcd_ctx *ctx = arg;
+       ssize_t len;
+
+       len = read(ctx->control_fd, &ctx->ctl_buflen, sizeof(ctx->ctl_buflen));
+       if (len != sizeof(ctx->ctl_buflen)) {
+               if (len != -1)
+                       errno = EINVAL;
+               goto err;
+       }
+       if (ctx->ctl_buflen > SSIZE_MAX) {
+               errno = ENOBUFS;
+               goto err;
+       }
+
+       free(ctx->ctl_buf);
+       ctx->ctl_buf = malloc(ctx->ctl_buflen);
+       if (ctx->ctl_buf == NULL)
+               goto err;
+
+       ctx->ctl_bufpos = 0;
+       eloop_event_add(ctx->eloop, ctx->control_fd,
+           dhcpcd_readdump2, ctx);
+       return;
+
+err:
+       logerr(__func__);
+       eloop_exit(ctx->eloop, EXIT_FAILURE);
+}
+
+static void
+dhcpcd_readdump0(void *arg)
+{
+       struct dhcpcd_ctx *ctx = arg;
+       ssize_t len;
+
+       len = read(ctx->control_fd, &ctx->ctl_extra, sizeof(ctx->ctl_extra));
+       if (len != sizeof(ctx->ctl_extra)) {
+               if (len != -1)
+                       errno = EINVAL;
+               logerr(__func__);
+               eloop_exit(ctx->eloop, EXIT_FAILURE);
+               return;
+       }
+
+       if (ctx->ctl_extra == 0) {
+               eloop_exit(ctx->eloop, EXIT_SUCCESS);
+               return;
+       }
+
+       eloop_event_add(ctx->eloop, ctx->control_fd,
+           dhcpcd_readdump1, ctx);
+}
+
+static void
+dhcpcd_readdumptimeout(void *arg)



Home | Main Index | Thread Index | Old Index