From: Roy Marples Date: Wed, 30 Jan 2019 22:40:12 +0000 (+0000) Subject: link: introduce LINK_DOWN_IFFUP X-Git-Tag: v7.1.1~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3458df6129a28ada2a6d613c4054136430f99f4c;p=thirdparty%2Fdhcpcd.git link: introduce LINK_DOWN_IFFUP Set this state so when we preserve config on carrier loss. This allows us to remove config if the interface is then brought down. --- diff --git a/src/dhcp.c b/src/dhcp.c index 18160348..d9a2872b 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -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) { diff --git a/src/dhcp6.c b/src/dhcp6.c index 6fef9899..da82c6ae 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -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 */ diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 72bfe5e7..a2cd04e2 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -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) { diff --git a/src/dhcpcd.h b/src/dhcpcd.h index cbd95833..39577006 100644 --- a/src/dhcpcd.h +++ b/src/dhcpcd.h @@ -49,9 +49,10 @@ #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 diff --git a/src/ipv6nd.c b/src/ipv6nd.c index b524a9e8..5a248486 100644 --- a/src/ipv6nd.c +++ b/src/ipv6nd.c @@ -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) { diff --git a/src/script.c b/src/script.c index 96104b10..ba4ce03b 100644 --- a/src/script.c +++ b/src/script.c @@ -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: