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/f7969c73d31f
branches:  trunk
changeset: 975781:f7969c73d31f
user:      roy <roy%NetBSD.org@localhost>
date:      Sun Sep 06 14:55:34 2020 +0000

description:
Sync

diffstat:

 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/if-options.c |   51 ++++++++-
 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/privsep.c    |   60 +++++++-----
 8 files changed, 253 insertions(+), 178 deletions(-)

diffs (truncated from 849 to 300 lines):

diff -r 995170d0f030 -r f7969c73d31f 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       Sun Sep 06 14:55:34 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 995170d0f030 -r f7969c73d31f external/bsd/dhcpcd/dist/src/dhcpcd.8.in
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.8.in  Sun Sep 06 14:54:28 2020 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.8.in  Sun Sep 06 14:55:34 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 995170d0f030 -r f7969c73d31f 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     Sun Sep 06 14:55:34 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
 
+#ifdef PRIVSEP
+       ps_init(&ctx);
+#endif
+
 #ifndef SMALL
        if (ctx.options & DHCPCD_DUMPLEASE &&
            ioctl(fileno(stdin), FIONREAD, &i, sizeof(i)) == 0 &&
            i > 0)
        {
+               ctx.options |= DHCPCD_FORKED; /* pretend child process */
+#ifdef PRIVSEP



Home | Main Index | Thread Index | Old Index