changeset 5473:475c5872e821 draft

Try and track link state better, regardless of if we're using the interface or not.
author Roy Marples <roy@marples.name>
date Mon, 21 Sep 2020 22:24:18 +0100
parents 578cd75c91e8
children b95f6db91afa
files src/dhcpcd.c src/if.c
diffstat 2 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcpcd.c	Mon Sep 21 17:40:28 2020 +0100
+++ b/src/dhcpcd.c	Mon Sep 21 22:24:18 2020 +0100
@@ -711,8 +711,7 @@
 
 	ifp = if_find(ctx->ifaces, ifname);
 	if (ifp == NULL ||
-	    ifp->options == NULL || !(ifp->options->options & DHCPCD_LINK) ||
-	    !ifp->active)
+	    ifp->options == NULL || !(ifp->options->options & DHCPCD_LINK))
 		return;
 
 	if (carrier == LINK_UNKNOWN) {
@@ -728,8 +727,6 @@
 
 	if (carrier == LINK_DOWN || (ifp->flags & IFF_UP) == 0) {
 		if (ifp->carrier != LINK_DOWN) {
-			if (ifp->carrier == LINK_UP)
-				loginfox("%s: carrier lost", ifp->name);
 #ifdef NOCARRIER_PRESERVE_IP
 			if (ifp->flags & IFF_UP &&
 			    !(ifp->options->options & DHCPCD_ANONYMOUS))
@@ -737,6 +734,10 @@
 			else
 #endif
 				ifp->carrier = LINK_DOWN;
+			if (!ifp->active)
+				return;
+			if (ifp->carrier == LINK_UP)
+				loginfox("%s: carrier lost", ifp->name);
 			script_runreason(ifp, "NOCARRIER");
 #ifdef NOCARRIER_PRESERVE_IP
 			if (ifp->flags & IFF_UP &&
@@ -767,8 +768,9 @@
 		}
 	} else if (carrier == LINK_UP && ifp->flags & IFF_UP) {
 		if (ifp->carrier != LINK_UP) {
-			loginfox("%s: carrier acquired", ifp->name);
 			ifp->carrier = LINK_UP;
+			if (ifp->active)
+				loginfox("%s: carrier acquired", ifp->name);
 #if !defined(__linux__) && !defined(__NetBSD__)
 			/* BSD does not emit RTM_NEWADDR or RTM_CHGADDR when the
 			 * hardware address changes so we have to go
@@ -784,8 +786,9 @@
 				if_getssid(ifp);
 
 				/* If we changed SSID network, drop leases */
-				if (ifp->ssid_len != olen ||
-				    memcmp(ifp->ssid, ossid, ifp->ssid_len))
+				if ((ifp->ssid_len != olen ||
+				    memcmp(ifp->ssid, ossid, ifp->ssid_len)) &&
+				    ifp->active)
 				{
 					dhcpcd_reportssid(ifp);
 #ifdef NOCARRIER_PRESERVE_IP
@@ -796,6 +799,8 @@
 #endif
 				}
 			}
+			if (!ifp->active)
+				return;
 			dhcpcd_initstate(ifp, 0);
 			script_runreason(ifp, "CARRIER");
 #ifdef INET6
--- a/src/if.c	Mon Sep 21 17:40:28 2020 +0100
+++ b/src/if.c	Mon Sep 21 22:24:18 2020 +0100
@@ -684,10 +684,7 @@
 #endif
 
 		ifp->active = active;
-		if (ifp->active)
-			ifp->carrier = if_carrier(ifp);
-		else
-			ifp->carrier = LINK_UNKNOWN;
+		ifp->carrier = if_carrier(ifp);
 		TAILQ_INSERT_TAIL(ifs, ifp, next);
 	}