From: Roy Marples Date: Mon, 20 Apr 2020 13:11:00 +0000 (+0100) Subject: if: ensure interface flags persist when setting a flag X-Git-Tag: v9.0.2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19065b4a37ea8c4d7584d98a9fe056183ae91f82;p=thirdparty%2Fdhcpcd.git if: ensure interface flags persist when setting a flag Otherwise we stupidly drop IFF_MULTICAST on Linux. --- diff --git a/src/if.c b/src/if.c index 51e05571..f73dfc7e 100644 --- a/src/if.c +++ b/src/if.c @@ -161,19 +161,17 @@ int if_setflag(struct interface *ifp, short setflag, short unsetflag) { struct ifreq ifr = { .ifr_flags = 0 }; - short f; + short oflags; - if (if_getflags(ifp) == -1) + strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name)); + if (ioctl(ifp->ctx->pf_inet_fd, SIOCGIFFLAGS, &ifr) == -1) return -1; - f = (short)ifp->flags; - if ((f & setflag) == setflag && (f & unsetflag) == 0) - return 0; - - strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name)); + oflags = ifr.ifr_flags; ifr.ifr_flags |= setflag; ifr.ifr_flags &= (short)~unsetflag; - if (if_ioctl(ifp->ctx, SIOCSIFFLAGS, &ifr, sizeof(ifr)) == -1) + if (ifr.ifr_flags != oflags && + if_ioctl(ifp->ctx, SIOCSIFFLAGS, &ifr, sizeof(ifr)) == -1) return -1; ifp->flags = (unsigned int)ifr.ifr_flags;