Module Name:    src
Committed By:   roy
Date:           Tue Mar 27 06:16:34 UTC 2018

Modified Files:
        src/external/bsd/dhcpcd/dist/src: dhcp.c dhcpcd.c

Log Message:
Sync


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/external/bsd/dhcpcd/dist/src/dhcp.c \
    src/external/bsd/dhcpcd/dist/src/dhcpcd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/dhcpcd/dist/src/dhcp.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcp.c:1.8 src/external/bsd/dhcpcd/dist/src/dhcp.c:1.9
--- src/external/bsd/dhcpcd/dist/src/dhcp.c:1.8	Mon Jan 29 11:13:06 2018
+++ src/external/bsd/dhcpcd/dist/src/dhcp.c	Tue Mar 27 06:16:34 2018
@@ -3653,6 +3653,7 @@ dhcp_start1(void *arg)
 
 	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 @@ dhcp_abort(struct interface *ifp)
 }
 
 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 @@ dhcp_handleifa(int cmd, struct ipv4_addr
 
 	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;
 	}
Index: src/external/bsd/dhcpcd/dist/src/dhcpcd.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.8 src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.9
--- src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.8	Mon Jan 29 11:13:06 2018
+++ src/external/bsd/dhcpcd/dist/src/dhcpcd.c	Tue Mar 27 06:16:34 2018
@@ -437,19 +437,15 @@ configure_interface1(struct interface *i
 		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 @@ dhcpcd_activateinterface(struct interfac
 	}
 }
 
-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 @@ dhcpcd_handleinterface(void *arg, int ac
 	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 @@ printpidfile:
 	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 @@ printpidfile:
 		} 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;
 		}
 	}

Reply via email to