]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Try and track link state better, regardless of if we're using
authorRoy Marples <roy@marples.name>
Mon, 21 Sep 2020 21:24:18 +0000 (22:24 +0100)
committerRoy Marples <roy@marples.name>
Mon, 21 Sep 2020 21:24:18 +0000 (22:24 +0100)
the interface or not.

src/dhcpcd.c
src/if.c

index 0c226129a22a5e24869ce7954f841bba46441735..d573d3a96d2f90ef9a26929a04e7e847e9685414 100644 (file)
@@ -711,8 +711,7 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
 
        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 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
 
        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 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
                        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 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
                }
        } 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 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
                                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 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
 #endif
                                }
                        }
+                       if (!ifp->active)
+                               return;
                        dhcpcd_initstate(ifp, 0);
                        script_runreason(ifp, "CARRIER");
 #ifdef INET6
index cb407e19c547964658bc7e4c2c1203da74adc3f1..d3c326a92f2dd30a6530c2c286724ea16dbf4689 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -684,10 +684,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
 #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);
        }