From: Roy Marples Date: Mon, 17 Jul 2023 22:48:18 +0000 (+0100) Subject: linux: consider IFF_LOWER_UP and !IFF_DORMANT for LINK_UP X-Git-Tag: v10.0.2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f5c4999b690a0a95bcbf0c1bb5c12dd3618308f;p=thirdparty%2Fdhcpcd.git linux: consider IFF_LOWER_UP and !IFF_DORMANT for LINK_UP --- diff --git a/src/if-linux.c b/src/if-linux.c index 8c560b52..5e033a16 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -60,6 +60,9 @@ #include #endif +/* Inlcude this *after* net/if.h so we get IFF_DORMANT */ +#include + #include #include #include @@ -525,11 +528,25 @@ if_setmac(struct interface *ifp, void *mac, uint8_t maclen) return if_ioctl(ifp->ctx, SIOCSIFHWADDR, &ifr, sizeof(ifr)); } +static int if_carrier_from_flags(unsigned int flags) +{ + +#ifdef IFF_LOWER_UP + return ((flags & (IFF_LOWER_UP | IFF_RUNNING)) == + (IFF_LOWER_UP | IFF_RUNNING)) +#ifdef IFF_DORMANT + && !(flags & IFF_DORMANT) +#endif + ? LINK_UP : LINK_DOWN; +#else + return flags & IFF_RUNNING ? LINK_UP : LINK_DOWN; +#endif +} + int if_carrier(struct interface *ifp, __unused const void *ifadata) { - - return ifp->flags & IFF_RUNNING ? LINK_UP : LINK_DOWN; + return if_carrier_from_flags(ifp->flags); } bool @@ -1047,7 +1064,7 @@ link_netlink(struct dhcpcd_ctx *ctx, void *arg, struct nlmsghdr *nlm) } dhcpcd_handlecarrier(ifp, - ifi->ifi_flags & IFF_RUNNING ? LINK_UP : LINK_DOWN, + if_carrier_from_flags(ifi->ifi_flags), ifi->ifi_flags); return 0; }