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/src Update to dhcpcd-9.2.0 with the f...



details:   https://anonhg.NetBSD.org/src/rev/a00fa22b4bc9
branches:  roy
changeset: 938316:a00fa22b4bc9
user:      roy <roy%NetBSD.org@localhost>
date:      Sun Sep 06 14:54:28 2020 +0000

description:
Update to dhcpcd-9.2.0 with the following changes:

 * route: ensure IPv4LL routes come last in priority
 * DHCP: fix many issues with extending the last lease
 * privsep: don't read control group from config in privsep
 * privsep: only the master process responds to signals
 * privsep: use a socketpair for stderr/stdin rather than dupping /dev/null
 * privsep: right limit stdin/stderr/stdout
 * privsep: dumping a lease is now run in a sandbox
 * options: check if kernel supports INET or INET6 before enabling default
 * options: let clientid override a prior duid
 * options: allow -1 to represent infinity for requested lease time
 * dhcpcd: fix a crash initing a new interface after route overflow

diffstat:

 external/bsd/dhcpcd/dist/src/defs.h           |    2 +-
 external/bsd/dhcpcd/dist/src/dhcp.c           |   82 +++++++------
 external/bsd/dhcpcd/dist/src/dhcpcd.8.in      |    6 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c         |  150 ++++++++++++++++++-------
 external/bsd/dhcpcd/dist/src/dhcpcd.conf.5.in |   10 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.h         |    6 +-
 external/bsd/dhcpcd/dist/src/eloop.c          |    5 +-
 external/bsd/dhcpcd/dist/src/if-options.c     |   51 +++++++-
 external/bsd/dhcpcd/dist/src/if.c             |   47 ++++++++
 external/bsd/dhcpcd/dist/src/if.h             |    3 +-
 external/bsd/dhcpcd/dist/src/ipv4.c           |    9 +-
 external/bsd/dhcpcd/dist/src/ipv4.h           |    1 +
 external/bsd/dhcpcd/dist/src/ipv4ll.c         |    5 +
 external/bsd/dhcpcd/dist/src/ipv6.c           |   33 ++---
 external/bsd/dhcpcd/dist/src/ipv6nd.c         |    4 +-
 external/bsd/dhcpcd/dist/src/logerr.c         |   45 +------
 external/bsd/dhcpcd/dist/src/logerr.h         |    2 -
 external/bsd/dhcpcd/dist/src/route.c          |    8 +
 external/bsd/dhcpcd/dist/src/route.h          |    5 +-
 19 files changed, 304 insertions(+), 170 deletions(-)

diffs (truncated from 960 to 300 lines):

diff -r bde9549e05d8 -r a00fa22b4bc9 external/bsd/dhcpcd/dist/src/defs.h
--- a/external/bsd/dhcpcd/dist/src/defs.h       Wed Jul 22 13:18:01 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/defs.h       Sun Sep 06 14:54:28 2020 +0000
@@ -29,7 +29,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "9.1.4"
+#define VERSION                        "9.2.0"
 
 #ifndef PRIVSEP_USER
 # define PRIVSEP_USER          "_" PACKAGE
diff -r bde9549e05d8 -r a00fa22b4bc9 external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Wed Jul 22 13:18:01 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Sun Sep 06 14:54:28 2020 +0000
@@ -777,7 +777,7 @@
            (type == DHCP_REQUEST &&
            state->addr->mask.s_addr == lease->mask.s_addr &&
            (state->new == NULL || IS_DHCP(state->new)) &&
-           !(state->added & STATE_FAKE))))
+           !(state->added & (STATE_FAKE | STATE_EXPIRED)))))
                bootp->ciaddr = state->addr->addr.s_addr;
 
        bootp->op = BOOTREQUEST;
@@ -836,7 +836,7 @@
                if (type == DHCP_DECLINE ||
                    (type == DHCP_REQUEST &&
                    (state->addr == NULL ||
-                   state->added & STATE_FAKE ||
+                   state->added & (STATE_FAKE | STATE_EXPIRED) ||
                    lease->addr.s_addr != state->addr->addr.s_addr)))
                {
                        putip = true;
@@ -1745,7 +1745,7 @@
                goto fail;
        len = (size_t)r;
 
-       if (!(state->added & STATE_FAKE) &&
+       if (!(state->added & (STATE_FAKE | STATE_EXPIRED)) &&
            state->addr != NULL &&
            ipv4_iffindaddr(ifp, &state->lease.addr, NULL) != NULL)
                from.s_addr = state->lease.addr.s_addr;
@@ -1869,14 +1869,16 @@
        state->state = DHS_DISCOVER;
        dhcp_new_xid(ifp);
        eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
-       if (ifo->fallback)
-               eloop_timeout_add_sec(ifp->ctx->eloop,
-                   ifo->reboot, dhcp_fallback, ifp);
+       if (!(state->added & STATE_EXPIRED)) {
+               if (ifo->fallback)
+                       eloop_timeout_add_sec(ifp->ctx->eloop,
+                           ifo->reboot, dhcp_fallback, ifp);
 #ifdef IPV4LL
-       else if (ifo->options & DHCPCD_IPV4LL)
-               eloop_timeout_add_sec(ifp->ctx->eloop,
-                   ifo->reboot, ipv4ll_start, ifp);
+               else if (ifo->options & DHCPCD_IPV4LL)
+                       eloop_timeout_add_sec(ifp->ctx->eloop,
+                           ifo->reboot, ipv4ll_start, ifp);
 #endif
+       }
        if (ifo->options & DHCPCD_REQUEST)
                loginfox("%s: soliciting a DHCP lease (requesting %s)",
                    ifp->name, inet_ntoa(ifo->req_addr));
@@ -1897,30 +1899,21 @@
 }
 
 static void
-dhcp_expire1(struct interface *ifp)
-{
-       struct dhcp_state *state = D_STATE(ifp);
-
-       eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
-       dhcp_drop(ifp, "EXPIRE");
-       dhcp_unlink(ifp->ctx, state->leasefile);
-       state->interval = 0;
-       if (!(ifp->options->options & DHCPCD_LINK) || ifp->carrier > LINK_DOWN)
-               dhcp_discover(ifp);
-}
-
-static void
 dhcp_expire(void *arg)
 {
        struct interface *ifp = arg;
+       struct dhcp_state *state = D_STATE(ifp);
 
        if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) {
                logwarnx("%s: DHCP lease expired, extending lease", ifp->name);
-               return;
+               state->added |= STATE_EXPIRED;
+       } else {
+               logerrx("%s: DHCP lease expired", ifp->name);
+               dhcp_drop(ifp, "EXPIRE");
+               dhcp_unlink(ifp->ctx, state->leasefile);
        }
-
-       logerrx("%s: DHCP lease expired", ifp->name);
-       dhcp_expire1(ifp);
+       state->interval = 0;
+       dhcp_discover(ifp);
 }
 
 #if defined(ARP) || defined(IN_IFF_DUPLICATED)
@@ -2291,7 +2284,9 @@
                return;
        }
        if (state->reason == NULL) {
-               if (state->old && !(state->added & STATE_FAKE)) {
+               if (state->old &&
+                   !(state->added & (STATE_FAKE | STATE_EXPIRED)))
+               {
                        if (state->old->yiaddr == state->new->yiaddr &&
                            lease->server.s_addr &&
                            state->state != DHS_REBIND)
@@ -2364,19 +2359,6 @@
        eloop_event_add(ctx->eloop, state->udp_rfd, dhcp_handleifudp, ifp);
 }
 
-static void
-dhcp_lastlease(void *arg)
-{
-       struct interface *ifp = arg;
-       struct dhcp_state *state = D_STATE(ifp);
-
-       loginfox("%s: timed out contacting a DHCP server, using last lease",
-           ifp->name);
-       dhcp_bind(ifp);
-       state->interval = 0;
-       dhcp_discover(ifp);
-}
-
 static size_t
 dhcp_message_new(struct bootp **bootp,
     const struct in_addr *addr, const struct in_addr *mask)
@@ -2476,6 +2458,26 @@
 #endif
 
 static void
+dhcp_lastlease(void *arg)
+{
+       struct interface *ifp = arg;
+       struct dhcp_state *state = D_STATE(ifp);
+
+       loginfox("%s: timed out contacting a DHCP server, using last lease",
+           ifp->name);
+#if defined(ARP) || defined(KERNEL_RFC5227)
+       dhcp_arp_bind(ifp);
+#else
+       dhcp_bind(ifp);
+#endif
+       /* Set expired here because dhcp_bind() -> ipv4_addaddr() will reset
+        * state */
+       state->added |= STATE_EXPIRED;
+       state->interval = 0;
+       dhcp_discover(ifp);
+}
+
+static void
 dhcp_static(struct interface *ifp)
 {
        struct if_options *ifo;
diff -r bde9549e05d8 -r a00fa22b4bc9 external/bsd/dhcpcd/dist/src/dhcpcd.8.in
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.8.in  Wed Jul 22 13:18:01 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.8.in  Sun Sep 06 14:54:28 2020 +0000
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd May 31, 2020
+.Dd September 2, 2020
 .Dt DHCPCD 8
 .Os
 .Sh NAME
@@ -385,8 +385,10 @@
 .Nm
 will exit.
 .It Fl l , Fl Fl leasetime Ar seconds
-Request a specific lease time in
+Request a lease time of
 .Ar seconds .
+.Ar -1
+represents an infinite lease time.
 By default
 .Nm
 does not request any lease time and leaves it in the hands of the
diff -r bde9549e05d8 -r a00fa22b4bc9 external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c     Wed Jul 22 13:18:01 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c     Sun Sep 06 14:54:28 2020 +0000
@@ -336,7 +336,7 @@
 #ifdef THERE_IS_NO_FORK
        eloop_timeout_delete(ctx->eloop, handle_exit_timeout, ctx);
        errno = ENOSYS;
-       return 0;
+       return;
 #else
        int i;
        unsigned int logopts = loggetopts();
@@ -361,8 +361,8 @@
 
        /* Don't use loginfo because this makes no sense in a log. */
        if (!(logopts & LOGERR_QUIET))
-               (void)fprintf(stderr, "forked to background, child pid %d\n",
-                   getpid());
+               (void)fprintf(stderr,
+                   "forked to background, child pid %d\n", getpid());
        i = EXIT_SUCCESS;
        if (write(ctx->fork_fd, &i, sizeof(i)) == -1)
                logerr("write");
@@ -371,11 +371,18 @@
        close(ctx->fork_fd);
        ctx->fork_fd = -1;
 
-       if (isatty(loggeterrfd())) {
-               logopts &= ~LOGERR_ERR;
-               logsetopts(logopts);
-               logseterrfd(-1);
-       }
+       /*
+        * Stop writing to stderr.
+        * On the happy path, only the master process writes to stderr,
+        * so this just stops wasting fprintf calls to nowhere.
+        * All other calls - ie errors in privsep processes or script output,
+        * will error when printing.
+        * If we *really* want to fix that, then we need to suck
+        * stderr/stdout in the master process and either disacrd it or pass
+        * it to the launcher process and then to stderr.
+        */
+       logopts &= ~LOGERR_ERR;
+       logsetopts(logopts);
 #endif
 }
 
@@ -1153,6 +1160,15 @@
 }
 #endif
 
+static void
+dhcpcd_runprestartinterface(void *arg)
+{
+       struct interface *ifp = arg;
+
+       run_preinit(ifp);
+       dhcpcd_prestartinterface(ifp);
+}
+
 void
 dhcpcd_linkoverflow(struct dhcpcd_ctx *ctx)
 {
@@ -1215,9 +1231,11 @@
                        continue;
                }
                TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
-               if (ifp->active)
+               if (ifp->active) {
+                       dhcpcd_initstate(ifp, 0);
                        eloop_timeout_add_sec(ctx->eloop, 0,
-                           dhcpcd_prestartinterface, ifp);
+                           dhcpcd_runprestartinterface, ifp);
+               }
        }
        free(ifaces);
 
@@ -1765,6 +1783,24 @@
        eloop_exit(ctx->eloop, exit_code);
 }
 
+static void
+dhcpcd_stderr_cb(void *arg)
+{
+       struct dhcpcd_ctx *ctx = arg;
+       char log[BUFSIZ];
+       ssize_t len;
+
+       len = read(ctx->stderr_fd, log, sizeof(log));
+       if (len == -1) {
+               if (errno != ECONNRESET)
+                       logerr(__func__);
+               return;
+       }
+
+       log[len] = '\0';
+       fprintf(stderr, "%s", log);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -1778,7 +1814,7 @@
        ssize_t len;
 #if defined(USE_SIGNALS) || !defined(THERE_IS_NO_FORK)
        pid_t pid;
-       int sigpipe[2];
+       int fork_fd[2], stderr_fd[2];
 #endif
 #ifdef USE_SIGNALS
        int sig = 0;
@@ -2100,11 +2136,20 @@
        }
 #endif



Home | Main Index | Thread Index | Old Index