diff options
| author | Roy Marples <roy@marples.name> | 2019-05-02 21:25:57 +0100 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2019-05-02 21:25:57 +0100 |
| commit | 6a5b0466ccae3f25169ffca928dc359c5fea4fbc (patch) | |
| tree | bd2d8c89a0c12b2d6967d3272654ec272d2671d6 /src/if-bsd.c | |
| parent | a8b066e85fbcd3543f3232bb808ef864e41c6438 (diff) | |
| download | dhcpcd-6a5b0466ccae3f25169ffca928dc359c5fea4fbc.tar.xz | |
BSD: Simplify carrier detection once more.
RTM_IFINFO messages now send the un-molested link status to
the main carrier handler which no longer polls on LINK_UNKNOWN.
Instead, we check carrier status directly, which if unsupported
we instead interface flags.
This is 2019, all interface drivers should report link status
correctly via RTM_IFINFO messages and trying to constantly work
around this is error prone and time consuming.
Diffstat (limited to 'src/if-bsd.c')
| -rw-r--r-- | src/if-bsd.c | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/src/if-bsd.c b/src/if-bsd.c index e608c8e6..cb7cce59 100644 --- a/src/if-bsd.c +++ b/src/if-bsd.c @@ -203,28 +203,19 @@ if_closesockets_os(struct dhcpcd_ctx *ctx) close(priv->pf_inet6_fd); } -static int -if_carrier_flags(struct interface *ifp, unsigned int flags) +int +if_carrier(struct interface *ifp) { struct ifmediareq ifmr = { .ifm_status = 0 }; strlcpy(ifmr.ifm_name, ifp->name, sizeof(ifmr.ifm_name)); if (ioctl(ifp->ctx->pf_inet_fd, SIOCGIFMEDIA, &ifmr) == -1 || !(ifmr.ifm_status & IFM_AVALID)) - return flags & IFF_RUNNING ? LINK_UP : LINK_UNKNOWN; + return LINK_UNKNOWN; return (ifmr.ifm_status & IFM_ACTIVE) ? LINK_UP : LINK_DOWN; } -int -if_carrier(struct interface *ifp) -{ - - if (if_getflags(ifp) == -1) - return LINK_UNKNOWN; - return if_carrier_flags(ifp, ifp->flags); -} - static void if_linkaddr(struct sockaddr_dl *sdl, const struct interface *ifp) { @@ -1009,33 +1000,24 @@ if_ifinfo(struct dhcpcd_ctx *ctx, const struct if_msghdr *ifm) { struct interface *ifp; int link_state; - unsigned int flags; if ((ifp = if_findindex(ctx->ifaces, ifm->ifm_index)) == NULL) return; - flags = (unsigned int)ifm->ifm_flags; switch (ifm->ifm_data.ifi_link_state) { case LINK_STATE_UNKNOWN: - /* In theory this is only set when an interface is first - * initiaised. - * However whilst some drivers report an active link - * via SIOCGIFMEDIA, they don't bother to announce it - * via a routing message. */ - if (ifp->wireless) /* Wireless needs to work correctly. */ - link_state = LINK_DOWN; - else - link_state = if_carrier_flags(ifp, flags); + link_state = LINK_UNKNOWN; break; case LINK_STATE_UP: - link_state = ifm->ifm_flags & IFF_UP ? LINK_UP : LINK_DOWN; + link_state = LINK_UP; break; default: link_state = LINK_DOWN; break; } - dhcpcd_handlecarrier(ctx, link_state, flags, ifp->name); + dhcpcd_handlecarrier(ctx, link_state, + (unsigned int)ifm->ifm_flags, ifp->name); } static void |
