changeset 2552:8238b7cd09d7 draft

Improve startup with regards to carrier checking and adding a link-local IPv6 address.
author Roy Marples <roy@marples.name>
date Mon, 30 Jun 2014 15:43:58 +0000
parents 65869393ad06
children 9a21dc3880d9
files dhcpcd.c if.c
diffstat 2 files changed, 31 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/dhcpcd.c	Mon Jun 30 12:08:00 2014 +0000
+++ b/dhcpcd.c	Mon Jun 30 15:43:58 2014 +0000
@@ -339,7 +339,7 @@
 		ifo->options &= ~(DHCPCD_ARP | DHCPCD_IPV4LL);
 	if (!(ifp->flags & (IFF_POINTOPOINT | IFF_LOOPBACK | IFF_MULTICAST)))
 		ifo->options &= ~DHCPCD_IPV6RS;
-	if (ifo->options & DHCPCD_LINK && if_carrier(ifp) == LINK_UNKNOWN)
+	if (ifo->options & DHCPCD_LINK && ifp->carrier == LINK_UNKNOWN)
 		ifo->options &= ~DHCPCD_LINK;
 
 	if (ifo->metric != -1)
@@ -561,6 +561,24 @@
 		    ifp->name, ifn->name);
 }
 
+static void
+pre_start(struct interface *ifp)
+{
+
+	/* Add our link-local address before upping the interface
+	 * so our RFC7217 address beats the hwaddr based one.
+	 * This is also a safety check incase it was ripped out
+	 * from under us. */
+	if (ifp->options->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) {
+		syslog(LOG_ERR, "%s: ipv6_start: %m", ifp->name);
+		ifp->options->options &= DHCPCD_IPV6;
+	}
+
+	if (!(ifp->flags & IFF_UP) && if_up(ifp) == -1)
+		syslog(LOG_ERR, "%s: if_up: %m", ifp->name);
+}
+
+
 void
 dhcpcd_startinterface(void *arg)
 {
@@ -569,24 +587,9 @@
 	size_t i;
 	char buf[DUID_LEN * 3];
 
-	/* Add our link-local address before upping the interface
-	 * so our RFC7217 address beats the hwaddr based one.
-	 * This is also a safety check incase it was ripped out
-	 * from under us. */
-	if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) {
-		syslog(LOG_ERR, "%s: ipv6_start: %m", ifp->name);
-		ifo->options &= DHCPCD_IPV6;
-	}
+	pre_start(ifp);
 
-	if (!(ifp->flags & IFF_UP) && if_carrier(ifp) != LINK_UNKNOWN) {
-		if (if_up(ifp) == -1)
-			syslog(LOG_ERR, "%s: if_up: %m",
-			    ifp->name);
-	}
-
-	if (ifp->carrier == LINK_UNKNOWN)
-		dhcpcd_handlecarrier(ifp->ctx, LINK_UNKNOWN, 0, ifp->name);
-	if (ifp->carrier == LINK_DOWN) {
+	if (ifp->carrier == LINK_DOWN && ifo->options & DHCPCD_LINK) {
 		syslog(LOG_INFO, "%s: waiting for carrier", ifp->name);
 		return;
 	}
@@ -700,31 +703,17 @@
 static void
 run_preinit(struct interface *ifp)
 {
-	const char *reason;
+
+	pre_start(ifp);
+	if (ifp->ctx->options & DHCPCD_TEST)
+		return;
 
-	reason = NULL; /* appease gcc */
-	if (ifp->options->options & DHCPCD_LINK) {
-		switch (if_carrier(ifp)) {
-		case LINK_DOWN:
-			ifp->carrier = LINK_DOWN;
-			reason = "NOCARRIER";
-			break;
-		case LINK_UP:
-			ifp->carrier = LINK_UP;
-			reason = "CARRIER";
-			break;
-		default:
-			ifp->carrier = LINK_UNKNOWN;
-			return;
-		}
-	} else
-		ifp->carrier = LINK_UNKNOWN;
+	script_runreason(ifp, "PREINIT");
 
-	if (!(ifp->ctx->options & DHCPCD_TEST))
-		script_runreason(ifp, "PREINIT");
-
-	if (ifp->carrier != LINK_UNKNOWN && !(ifp->ctx->options & DHCPCD_TEST))
-		script_runreason(ifp, reason);
+	if (ifp->carrier != LINK_UNKNOWN &&
+	    ifp->options->options & DHCPCD_LINK)
+		script_runreason(ifp,
+		    ifp->carrier == LINK_UP ? "CARRIER" : "NOCARRIER");
 }
 
 int
--- a/if.c	Mon Jun 30 12:08:00 2014 +0000
+++ b/if.c	Mon Jun 30 15:43:58 2014 +0000
@@ -295,6 +295,7 @@
 		ifp->ctx = ctx;
 		strlcpy(ifp->name, p, sizeof(ifp->name));
 		ifp->flags = ifa->ifa_flags;
+		ifp->carrier = if_carrier(ifp);
 
 		sdl_type = 0;
 		/* Don't allow loopback unless explicit */