From: Roy Marples Date: Wed, 9 Oct 2019 12:34:34 +0000 (+0100) Subject: BSD: Ignore interface groups as we would the interface name X-Git-Tag: v8.1.0~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f2803c8a8695bd6fbcda1c958b30226dee2d4217;p=thirdparty%2Fdhcpcd.git BSD: Ignore interface groups as we would the interface name Incase someone renames tap0 to foo4. --- diff --git a/src/if-bsd.c b/src/if-bsd.c index 476a3fe2..5de892e3 100644 --- a/src/if-bsd.c +++ b/src/if-bsd.c @@ -214,8 +214,8 @@ if_closesockets_os(struct dhcpcd_ctx *ctx) close(priv->pf_inet6_fd); } -bool -if_ignore(const char *drvname) +static bool +if_ignore1(const char *drvname) { const char * const *p; @@ -226,6 +226,45 @@ if_ignore(const char *drvname) return false; } +bool +if_ignore(struct dhcpcd_ctx *ctx, const char *ifname) +{ + struct if_spec spec; + + if (if_nametospec(ifname, &spec) != 0) + return false; + + if (if_ignore1(spec.drvname)) + return true; + +#ifdef SIOCGIFGROUP + struct ifgroupreq ifgr = { .ifgr_len = 0 }; + struct ifg_req *ifg; + size_t ifg_len; + + strlcpy(ifgr.ifgr_name, ifname, sizeof(ifgr.ifgr_name)); + if (ioctl(ctx->pf_inet_fd, SIOCGIFGROUP, &ifgr) == -1 || + (ifgr.ifgr_groups = malloc(ifgr.ifgr_len)) == NULL || + ioctl(ctx->pf_inet_fd, SIOCGIFGROUP, &ifgr) == -1) + { + logerr(__func__); + return false; + } + + for (ifg = ifgr.ifgr_groups, ifg_len = ifgr.ifgr_len; + ifg && ifg_len >= sizeof(*ifg); + ifg++, ifg_len -= sizeof(*ifg)) + { + if (if_ignore1(ifg->ifgrq_group)) + return true; + } +#else + UNUSED(ctx); +#endif + + return false; +} + int if_carrier(struct interface *ifp) { diff --git a/src/if-linux.c b/src/if-linux.c index 061b1fa8..f421b011 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -254,7 +254,7 @@ if_conf(struct interface *ifp) /* XXX work out TAP interfaces? */ bool -if_ignore(__unused const char *drvname) +if_ignore(__unused struct dhcpcd_ctx *ctx, __unused const char *ifname) { return false; diff --git a/src/if-sun.c b/src/if-sun.c index 4008698f..39e217c2 100644 --- a/src/if-sun.c +++ b/src/if-sun.c @@ -258,7 +258,7 @@ if_getssid(__unused struct interface *ifp) /* XXX work out TAP interfaces? */ bool -if_ignore(__unused const char *drvname) +if_ignore(__unused struct dhcpcd_ctx *ctx, __unused const char *ifname) { return false; diff --git a/src/if.c b/src/if.c index b9cf63ed..c6e1d190 100644 --- a/src/if.c +++ b/src/if.c @@ -419,7 +419,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, * Don't allow some reserved interface names unless explicit. */ if (IF_NOCONF) { if (ifa->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT) || - if_ignore(spec.drvname)) + if_ignore(ctx, spec.devname)) active = IF_INACTIVE; } diff --git a/src/if.h b/src/if.h index 0800c102..19b6b2fe 100644 --- a/src/if.h +++ b/src/if.h @@ -152,7 +152,7 @@ int if_nametospec(const char *, struct if_spec *); int if_conf(struct interface *); int if_init(struct interface *); int if_getssid(struct interface *); -bool if_ignore(const char *); +bool if_ignore(struct dhcpcd_ctx *, const char *); int if_vimaster(const struct dhcpcd_ctx *ctx, const char *); unsigned short if_vlanid(const struct interface *); int if_opensockets(struct dhcpcd_ctx *);