From: Roy Marples Date: Mon, 14 Jan 2019 12:57:37 +0000 (+0000) Subject: BSD: Fix UP/DOWN for interfaces which dont' report media changes X-Git-Tag: v7.1.0~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=751efa515f8c1000f2bda9023bff7a8f80761db3;p=thirdparty%2Fdhcpcd.git BSD: Fix UP/DOWN for interfaces which dont' report media changes Carrier UP/DOWN state is handled by media change events on BSD. When the carrier state changes, it's always to LINK_STATE_DOWN or LINK_STATE_UP. If we receive LINK_STATE_UNKNOWN from RTM_IFINFO it means the interface doesn't change media change events and as such won't report carrier state changes. In this instance, we can only rely on IFF_UP being set, which is the same condition dhcpcd needs for LINK_STATE_UP. --- diff --git a/src/if-bsd.c b/src/if-bsd.c index 7e4b6774..facc945c 100644 --- a/src/if-bsd.c +++ b/src/if-bsd.c @@ -960,22 +960,18 @@ if_ifinfo(struct dhcpcd_ctx *ctx, const struct if_msghdr *ifm) if ((ifp = if_findindex(ctx->ifaces, ifm->ifm_index)) == NULL) return; - switch (ifm->ifm_data.ifi_link_state) { - case LINK_STATE_DOWN: + + /* If we get LINK_STATE_UNKNOWN here, it means the interface + * doesn't support reporting carrier state. + * As such, we need to rely on IFF_UP. + * Even if LINK_STATE_UP is reported, we also need IFF_UP as well + * so for dhcpcd they are equivalent and we only need to check + * LINK_STATE_DOWN. */ + if (ifm->ifm_data.ifi_link_state == LINK_STATE_DOWN) link_state = LINK_DOWN; - break; - case LINK_STATE_UP: - /* dhcpcd considers the link down if IFF_UP is not set. */ + else link_state = ifm->ifm_flags & IFF_UP ? LINK_UP : LINK_DOWN; - break; - default: - /* handle_carrier will re-load the interface flags and check for - * IFF_RUNNING as some drivers that don't handle link state also - * don't set IFF_RUNNING when this routing message is generated. - * As such, it is a race ...*/ - link_state = LINK_UNKNOWN; - break; - } + dhcpcd_handlecarrier(ctx, link_state, (unsigned int)ifm->ifm_flags, ifp->name); }