changeset 2476:2d2f728a69dc draft

Always send a carrier as it's no longer encapsulated in the IPv4 stack. When stopping and not departed, run with the STOPPED reason but do not process it in hooks.
author Roy Marples <roy@marples.name>
date Tue, 06 May 2014 14:42:24 +0000
parents 023d080fb9aa
children 0cb34a762c93
files dhcpcd-run-hooks.in dhcpcd.c script.c
diffstat 3 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/dhcpcd-run-hooks.in	Tue May 06 14:39:31 2014 +0000
+++ b/dhcpcd-run-hooks.in	Tue May 06 14:42:24 2014 +0000
@@ -7,6 +7,8 @@
 		ifsuffix=":ra";;
 	INFORM6|BOUND6|RENEW6|REBIND6|REBOOT6|EXPIRE6|RELEASE6|STOP6)
 		ifsuffix=":dhcp6";;
+	STOPPED) # This reason should never be processed
+		exit 0;;
 	*)
 		ifsuffix=;;
 esac
--- a/dhcpcd.c	Tue May 06 14:39:31 2014 +0000
+++ b/dhcpcd.c	Tue May 06 14:42:24 2014 +0000
@@ -309,6 +309,8 @@
 	eloop_timeout_delete(ctx->eloop, NULL, ifp);
 	if (ifp->options->options & DHCPCD_DEPARTED)
 		script_runreason(ifp, "DEPARTED");
+	else
+		script_runreason(ifp, "STOPPED");
 	if_free(ifp);
 	if (!(ctx->options & (DHCPCD_MASTER | DHCPCD_TEST)))
 		eloop_exit(ctx->eloop, EXIT_FAILURE);
@@ -993,6 +995,8 @@
 			if (argc == 1) {
 				TAILQ_FOREACH(ifp, ctx->ifaces, next) {
 					len++;
+					if (D_STATE(ifp))
+						len++;
 					if (D6_STATE_RUNNING(ifp))
 						len++;
 					if (ipv6nd_has_ra(ifp))
@@ -1014,6 +1018,8 @@
 				TAILQ_FOREACH(ifp, ctx->ifaces, next) {
 					if (strcmp(argv[opt], ifp->name) == 0) {
 						len++;
+						if (D_STATE(ifp))
+							len++;
 						if (D6_STATE_RUNNING(ifp))
 							len++;
 						if (ipv6nd_has_ra(ifp))
--- a/script.c	Tue May 06 14:39:31 2014 +0000
+++ b/script.c	Tue May 06 14:42:24 2014 +0000
@@ -523,7 +523,6 @@
 {
 	const char *reason;
 	int retval = 0;
-	int onestate = 0;
 #ifdef INET
 	const struct dhcp_state *d = D_CSTATE(ifp);
 #endif
@@ -531,42 +530,36 @@
 	const struct dhcp6_state *d6 = D6_CSTATE(ifp);
 #endif
 
+	switch (ifp->carrier) {
+	case LINK_UP:
+		reason = "CARRIER";
+		break;
+	case LINK_DOWN:
+		reason = "NOCARRIER";
+		break;
+	default:
+		reason = "UNKNOWN";
+		break;
+	}
+	if (send_interface1(fd, ifp, reason) == -1)
+			retval = -1;
 #ifdef INET
-	if (d) {
-		onestate = 1;
+	if (d)
 		if (send_interface1(fd, ifp, d->reason) == -1)
 			retval = -1;
-	}
 #endif
 
 #ifdef INET6
 	if (ipv6nd_has_ra(ifp)) {
-		onestate = 1;
 		if (send_interface1(fd, ifp, "ROUTERADVERT") == -1)
 			retval = -1;
 	}
 	if (D6_STATE_RUNNING(ifp)) {
-		onestate = 1;
 		if (send_interface1(fd, ifp, d6->reason) == -1)
 			retval = -1;
 	}
 #endif
 
-	if (!onestate) {
-		switch (ifp->carrier) {
-		case LINK_UP:
-			reason = "CARRIER";
-			break;
-		case LINK_DOWN:
-			reason = "NOCARRIER";
-			break;
-		default:
-			reason = "UNKNOWN";
-			break;
-		}
-		if (send_interface1(fd, ifp, reason) == -1)
-			retval = -1;
-	}
 	return retval;
 }