]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
BSD: Ignore interface groups as we would the interface name
authorRoy Marples <roy@marples.name>
Wed, 9 Oct 2019 12:34:34 +0000 (13:34 +0100)
committerRoy Marples <roy@marples.name>
Wed, 9 Oct 2019 12:34:34 +0000 (13:34 +0100)
Incase someone renames tap0 to foo4.

src/if-bsd.c
src/if-linux.c
src/if-sun.c
src/if.c
src/if.h

index 476a3fe27f8153cdb9c30f6185b393ca646a422c..5de892e3eee77cd089dd561211ba63df53dfb202 100644 (file)
@@ -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)
 {
index 061b1fa89a33a9f0eaeafe4f89954bffc060ff3e..f421b011bf048e33b2a24539d204b1443e7d26c5 100644 (file)
@@ -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;
index 4008698f86d72df2828b357ea13909c28aee8e10..39e217c2e186015da01a980feba0e6af74ac54b1 100644 (file)
@@ -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;
index b9cf63edd011f6f21278517d8c28410e05a9d8e0..c6e1d1902c256d19090be8fc20a19dcef4d52b18 100644 (file)
--- 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;
                }
 
index 0800c102a3298079b0a5cd521bb8e0ac287ebfaa..19b6b2fe1b9780b59afff4a23a53cb2d3d4bbd0a 100644 (file)
--- 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 *);