]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
link: introduce LINK_DOWN_IFFUP
authorRoy Marples <roy@marples.name>
Wed, 30 Jan 2019 22:40:12 +0000 (22:40 +0000)
committerRoy Marples <roy@marples.name>
Wed, 30 Jan 2019 22:40:12 +0000 (22:40 +0000)
Set this state so when we preserve config on carrier loss.
This allows us to remove config if the interface is then brought down.

src/dhcp.c
src/dhcp6.c
src/dhcpcd.c
src/dhcpcd.h
src/ipv6nd.c
src/script.c

index 181603484e75f5e29822e39d890f83b1fea64a92..d9a2872bf80e5fc2a560703b396b0c3035e0d173 100644 (file)
@@ -1764,7 +1764,7 @@ send_message(struct interface *ifp, uint8_t type,
 
        if (!callback) {
                /* No carrier? Don't bother sending the packet. */
-               if (ifp->carrier == LINK_DOWN)
+               if (ifp->carrier <= LINK_DOWN)
                        return;
                logdebugx("%s: sending %s with xid 0x%x",
                    ifp->name,
@@ -1784,7 +1784,7 @@ send_message(struct interface *ifp, uint8_t type,
                timespecnorm(&tv);
                /* No carrier? Don't bother sending the packet.
                 * However, we do need to advance the timeout. */
-               if (ifp->carrier == LINK_DOWN)
+               if (ifp->carrier <= LINK_DOWN)
                        goto fail;
                logdebugx("%s: sending %s (xid 0x%x), next in %0.1f seconds",
                    ifp->name,
@@ -1965,7 +1965,7 @@ dhcp_expire1(struct interface *ifp)
        dhcp_drop(ifp, "EXPIRE");
        unlink(state->leasefile);
        state->interval = 0;
-       if (!(ifp->options->options & DHCPCD_LINK) || ifp->carrier != LINK_DOWN)
+       if (!(ifp->options->options & DHCPCD_LINK) || ifp->carrier > LINK_DOWN)
                dhcp_discover(ifp);
 }
 
@@ -2601,7 +2601,7 @@ dhcp_reboot(struct interface *ifp)
        state->state = DHS_REBOOT;
        state->interval = 0;
 
-       if (ifo->options & DHCPCD_LINK && ifp->carrier == LINK_DOWN) {
+       if (ifo->options & DHCPCD_LINK && ifp->carrier <= LINK_DOWN) {
                loginfox("%s: waiting for carrier", ifp->name);
                return;
        }
@@ -2691,7 +2691,7 @@ dhcp_drop(struct interface *ifp, const char *reason)
                state->state = DHS_RELEASE;
 
                unlink(state->leasefile);
-               if (ifp->carrier != LINK_DOWN &&
+               if (ifp->carrier > LINK_DOWN &&
                    state->new != NULL &&
                    state->lease.server.s_addr != INADDR_ANY)
                {
index 6fef9899ea3515eb95fa0981064a50842909a502..da82c6ae247578afa5473ce0e16e3560ac54eeab 100644 (file)
@@ -1169,7 +1169,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
        struct ipv6_addr *lla;
        int s;
 
-       if (!callback && ifp->carrier == LINK_DOWN)
+       if (!callback && ifp->carrier <= LINK_DOWN)
                return 0;
 
        memset(&dst, 0, sizeof(dst));
@@ -1262,7 +1262,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
                }
 
 logsend:
-               if (ifp->carrier != LINK_DOWN)
+               if (ifp->carrier > LINK_DOWN)
                        logdebugx("%s: %s %s (xid 0x%02x%02x%02x),"
                            " next in %0.1f seconds",
                            ifp->name,
@@ -1286,7 +1286,7 @@ logsend:
                }
        }
 
-       if (ifp->carrier == LINK_DOWN)
+       if (ifp->carrier <= LINK_DOWN)
                return 0;
 
        /* Update the elapsed time */
index 72bfe5e702d11faa897f1273ac9c2665f721a811..a2cd04e254a1efe6ef9fac3ed1833eef0eb6cefc 100644 (file)
@@ -755,24 +755,30 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
                if (ifp->carrier != LINK_DOWN) {
                        if (ifp->carrier == LINK_UP)
                                loginfox("%s: carrier lost", ifp->name);
-                       ifp->carrier = LINK_DOWN;
+#ifdef NOCARRIER_PRESERVE_IP
+                       if (ifp->flags & IFF_UP)
+                               ifp->carrier = LINK_DOWN_IFFUP;
+                       else
+#endif
+                               ifp->carrier = LINK_DOWN;
                        script_runreason(ifp, "NOCARRIER");
 #ifdef NOCARRIER_PRESERVE_IP
+                       if (ifp->flags & IFF_UP) {
 #ifdef ARP
-                       arp_drop(ifp);
+                               arp_drop(ifp);
 #endif
 #ifdef INET
-                       dhcp_abort(ifp);
+                               dhcp_abort(ifp);
 #endif
 #ifdef INET6
-                       ipv6nd_expire(ifp, 0);
+                               ipv6nd_expire(ifp, 0);
 #endif
 #ifdef DHCP6
-                       dhcp6_abort(ifp);
+                               dhcp6_abort(ifp);
 #endif
-#else
-                       dhcpcd_drop(ifp, 0);
+                       } else
 #endif
+                               dhcpcd_drop(ifp, 0);
                }
        } else if (carrier == LINK_UP && ifp->flags & IFF_UP) {
                if (ifp->carrier != LINK_UP) {
index cbd958331c1c73d9930141aebf9e3d3d06fcb65e..3957700655b18beaa3b9d3d9cd1ef9ae4fe43b4a 100644 (file)
 #define IF_ACTIVE      1
 #define IF_ACTIVE_USER 2
 
-#define LINK_UP                1
-#define LINK_UNKNOWN   0
-#define LINK_DOWN      -1
+#define        LINK_UP         1
+#define        LINK_UNKNOWN    0
+#define        LINK_DOWN       -1
+#define        LINK_DOWN_IFFUP -2
 
 #define IF_DATA_IPV4   0
 #define IF_DATA_ARP    1
index b524a9e86775060238101d0f5b590aa1ed1b0206..5a248486c9ce0dc323fdb2fa6c22990160ca3476 100644 (file)
@@ -346,7 +346,7 @@ ipv6nd_sendadvertisement(void *arg)
        struct in6_pktinfo pi;
        const struct rs_state *state = RS_CSTATE(ifp);
 
-       if (state == NULL || ifp->carrier == LINK_DOWN)
+       if (state == NULL || ifp->carrier <= LINK_DOWN)
                goto freeit;
 
        memset(&dst, 0, sizeof(dst));
@@ -408,7 +408,7 @@ ipv6nd_advertise(struct ipv6_addr *ia)
        iaf = NULL;
        TAILQ_FOREACH(ifp, ctx->ifaces, next) {
                state = IPV6_STATE(ifp);
-               if (state == NULL || ifp->carrier == LINK_DOWN)
+               if (state == NULL || ifp->carrier <= LINK_DOWN)
                        continue;
 
                TAILQ_FOREACH(iap, &state->addrs, next) {
index 96104b10eea2a4289ecc65a7686437cffd590131..ba4ce03b2936052e6d37fe0620fb55d5925f1f65 100644 (file)
@@ -649,6 +649,7 @@ send_interface(struct fd_list *fd, const struct interface *ifp)
                reason = "CARRIER";
                break;
        case LINK_DOWN:
+       case LINK_DOWN_IFFUP:
                reason = "NOCARRIER";
                break;
        default: