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/33664b51782f
branches:  trunk
changeset: 360716:33664b51782f
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Mar 27 06:16:34 2018 +0000

description:
Sync

diffstat:

 external/bsd/dhcpcd/dist/src/dhcp.c   |    8 +-
 external/bsd/dhcpcd/dist/src/dhcpcd.c |  112 +++++++++++++++++++++++++++------
 2 files changed, 94 insertions(+), 26 deletions(-)

diffs (191 lines):

diff -r 7484627f3cc3 -r 33664b51782f external/bsd/dhcpcd/dist/src/dhcp.c
--- a/external/bsd/dhcpcd/dist/src/dhcp.c       Tue Mar 27 06:14:39 2018 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcp.c       Tue Mar 27 06:16:34 2018 +0000
@@ -3653,6 +3653,7 @@
 
        state = D_STATE(ifp);
        clock_gettime(CLOCK_MONOTONIC, &state->started);
+       state->interval = 0;
        free(state->offer);
        state->offer = NULL;
        state->offer_len = 0;
@@ -3891,7 +3892,7 @@
 }
 
 void
-dhcp_handleifa(int cmd, struct ipv4_addr *ia)
+dhcp_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid)
 {
        struct interface *ifp;
        struct dhcp_state *state;
@@ -3905,12 +3906,13 @@
 
        if (cmd == RTM_DELADDR) {
                if (state->addr == ia) {
-                       loginfox("%s: deleted IP address %s",
-                           ifp->name, ia->saddr);
+                       loginfox("%s: pid %d deleted IP address %s",
+                           ifp->name, pid, ia->saddr);
                        state->addr = NULL;
                        /* Don't clear the added state as we need
                         * to drop the lease. */
                        dhcp_drop(ifp, "EXPIRE");
+                       dhcp_start1(ifp);
                }
                return;
        }
diff -r 7484627f3cc3 -r 33664b51782f external/bsd/dhcpcd/dist/src/dhcpcd.c
--- a/external/bsd/dhcpcd/dist/src/dhcpcd.c     Tue Mar 27 06:14:39 2018 +0000
+++ b/external/bsd/dhcpcd/dist/src/dhcpcd.c     Tue Mar 27 06:16:34 2018 +0000
@@ -437,19 +437,15 @@
                ifo->options &=
                    ~(DHCPCD_IPV6RS | DHCPCD_DHCP6 | DHCPCD_WAITIP6);
 
-       /* We want to disable kernel interface RA as early as possible. */
+       /* We want to setup INET6 on the interface as soon as possible. */
        if (ifp->active == IF_ACTIVE_USER &&
-           !(ifp->ctx->options & DHCPCD_DUMPLEASE))
+           ifo->options & DHCPCD_IPV6 &&
+           !(ifp->ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST)))
        {
-               int ra_global, ra_iface;
-
                /* If not doing any DHCP, disable the RDNSS requirement. */
                if (!(ifo->options & (DHCPCD_DHCP | DHCPCD_DHCP6)))
                        ifo->options &= ~DHCPCD_IPV6RA_REQRDNSS;
-               ra_global = if_checkipv6(ifp->ctx, NULL);
-               ra_iface = if_checkipv6(ifp->ctx, ifp);
-               if (ra_global == -1 || ra_iface == -1)
-                       ifo->options &= ~DHCPCD_IPV6RS;
+               if_setup_inet6(ifp);
        }
 #endif
 
@@ -959,20 +955,6 @@
        }
 }
 
-static void
-dhcpcd_handlelink(void *arg)
-{
-       struct dhcpcd_ctx *ctx;
-
-       ctx = arg;
-       if (if_handlelink(ctx) == -1) {
-               logerr(__func__);
-               eloop_event_delete(ctx->eloop, ctx->link_fd);
-               close(ctx->link_fd);
-               ctx->link_fd = -1;
-       }
-}
-
 int
 dhcpcd_handleinterface(void *arg, int action, const char *ifname)
 {
@@ -1045,6 +1027,83 @@
        return 1;
 }
 
+static void
+dhcpcd_handlelink(void *arg)
+{
+       struct dhcpcd_ctx *ctx = arg;
+
+       if (if_handlelink(ctx) == -1) {
+               if (errno == ENOBUFS || errno == ENOMEM) {
+                       dhcpcd_linkoverflow(ctx);
+                       return;
+               }
+               logerr(__func__);
+       }
+}
+
+static void
+dhcpcd_checkcarrier(void *arg)
+{
+       struct interface *ifp = arg;
+
+       dhcpcd_handlecarrier(ifp->ctx, LINK_UNKNOWN, ifp->flags, ifp->name);
+}
+
+void
+dhcpcd_linkoverflow(struct dhcpcd_ctx *ctx)
+{
+       struct if_head *ifaces;
+       struct ifaddrs *ifaddrs;
+       struct interface *ifp, *ifn, *ifp1;
+
+       logerrx("route socket overflowed - learning interface state");
+
+       /* Close the existing socket and open a new one.
+        * This is easier than draining the kernel buffer of an
+        * in-determinate size. */
+       eloop_event_delete(ctx->eloop, ctx->link_fd);
+       close(ctx->link_fd);
+       if_closesockets_os(ctx);
+       if (if_opensockets_os(ctx) == -1) {
+               logerr("%s: if_opensockets", __func__);
+               eloop_exit(ctx->eloop, EXIT_FAILURE);
+               return;
+       }
+       eloop_event_add(ctx->eloop, ctx->link_fd, dhcpcd_handlelink, ctx);
+
+       /* Work out the current interfaces. */
+       ifaces = if_discover(ctx, &ifaddrs, ctx->ifc, ctx->ifv);
+
+       /* Punt departed interfaces */
+       TAILQ_FOREACH_SAFE(ifp, ctx->ifaces, next, ifn) {
+               if (if_find(ifaces, ifp->name) != NULL)
+                       continue;
+               dhcpcd_handleinterface(ctx, -1, ifp->name);
+       }
+
+       /* Add new interfaces */
+       TAILQ_FOREACH_SAFE(ifp, ifaces, next, ifn) {
+               ifp1 = if_find(ctx->ifaces, ifp->name);
+               if (ifp1 != NULL) {
+                       /* If the interface already exists,
+                        * check carrier state. */
+                       eloop_timeout_add_sec(ctx->eloop, 0,
+                           dhcpcd_checkcarrier, ifp1);
+                       continue;
+               }
+               TAILQ_REMOVE(ifaces, ifp, next);
+               TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
+               if (ifp->active)
+                       eloop_timeout_add_sec(ctx->eloop, 0,
+                           dhcpcd_prestartinterface, ifp);
+       }
+
+       /* Update address state. */
+       if_markaddrsstale(ctx->ifaces);
+       if_learnaddrs(ctx, ctx->ifaces, &ifaddrs);
+       if_deletestaleaddrs(ctx->ifaces);
+}
+
 void
 dhcpcd_handlehwaddr(struct dhcpcd_ctx *ctx, const char *ifname,
     const void *hwaddr, uint8_t hwlen)
@@ -1813,6 +1872,13 @@
        logdebugx(PACKAGE "-" VERSION " starting");
        ctx.options |= DHCPCD_STARTED;
 
+#ifdef HAVE_SETPROCTITLE
+       setproctitle("%s%s%s",
+           ctx.options & DHCPCD_MASTER ? "[master]" : argv[optind],
+           ctx.options & DHCPCD_IPV4 ? " [ip4]" : "",
+           ctx.options & DHCPCD_IPV6 ? " [ip6]" : "");
+#endif
+
        if (if_opensockets(&ctx) == -1) {
                logerr("%s: if_opensockets", __func__);
                goto exit_failure;
@@ -1858,7 +1924,7 @@
                } else
                        goto exit_failure;
                if (!(ctx.options & DHCPCD_LINK)) {
-                       logerr("aborting as link detection is disabled");
+                       logerrx("aborting as link detection is disabled");
                        goto exit_failure;
                }
        }



Home | Main Index | Thread Index | Old Index