summaryrefslogtreecommitdiffstats
path: root/src/if-bsd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-01-14 12:57:37 +0000
committerRoy Marples <roy@marples.name>2019-01-14 12:57:37 +0000
commit63fac97fee20c076650225c0ebeaafe9aadb1c90 (patch)
tree987dc9e1dea9dd9039ee54fe4965f36cff368218 /src/if-bsd.c
parentbe741f87312ff60299804b5bac59aa790147ad57 (diff)
downloaddhcpcd-63fac97fee20c076650225c0ebeaafe9aadb1c90.tar.xz
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.
Diffstat (limited to 'src/if-bsd.c')
-rw-r--r--src/if-bsd.c24
1 files changed, 10 insertions, 14 deletions
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);
}