summaryrefslogtreecommitdiffstats
path: root/src/if.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-01-26 00:08:43 +0000
committerRoy Marples <roy@marples.name>2019-01-26 00:08:43 +0000
commit4f903d6ad4adf2de7712d36a921051b4dfd7210a (patch)
tree6c1b535d692ae0c96d5a4cb9a70bdb82ad23e9fa /src/if.c
parent700fd4e3d3cc65602427816f7446dada757d0538 (diff)
downloaddhcpcd-4f903d6ad4adf2de7712d36a921051b4dfd7210a.tar.xz
BSD: treat LINK_STATE_UNKNOWN as DOWN if media is invalid
On BSD, some interfaces might emit RTM_IFINFO before the link state has initialised. Mainly wireless cards. If the intial carrier call says media state change is valid, we need to treat LINK_STATE_UNKNOWN as LINK_DOWN rather than LINK_UP.
Diffstat (limited to 'src/if.c')
-rw-r--r--src/if.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/if.c b/src/if.c
index 8590e6e0..e8950d7e 100644
--- a/src/if.c
+++ b/src/if.c
@@ -155,9 +155,13 @@ if_carrier(struct interface *ifp)
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)
+ {
+ ifp->media_valid = true;
r = (ifmr.ifm_status & IFM_ACTIVE) ? LINK_UP : LINK_DOWN;
- else
+ } else {
+ ifp->media_valid = false;
r = ifr.ifr_flags & IFF_RUNNING ? LINK_UP : LINK_UNKNOWN;
+ }
#else
r = ifr.ifr_flags & IFF_RUNNING ? LINK_UP : LINK_DOWN;
#endif
@@ -592,7 +596,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
* we can work them out. */
ifp->metric = 200 + ifp->index;
if (if_getssid(ifp) != -1) {
- ifp->wireless = 1;
+ ifp->wireless = true;
ifp->metric += 100;
}
#endif