]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
if: Ignore TAP interfaces by default
authorRoy Marples <roy@marples.name>
Wed, 9 Oct 2019 11:47:06 +0000 (12:47 +0100)
committerRoy Marples <roy@marples.name>
Wed, 9 Oct 2019 11:47:06 +0000 (12:47 +0100)
TAP interfaces are virtual ethernet and not really distinguishable
from real interfaces other than the interface name.

On BSD the interfaces are always called tapN.

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

index 89013b1120f52055cad7f98a5b6d04b1222f2b0f..476a3fe27f8153cdb9c30f6185b393ca646a422c 100644 (file)
 #define RT_ADVANCE(x, n) (x += RT_ROUNDUP((n)->sa_len))
 #endif
 
+/* Ignore these interface names which look like ethernet but are virtual. */
+static const char * const ifnames_ignore[] = {
+       "tap",
+       NULL
+};
+
 #ifdef INET6
 static void ifa_setscope(struct sockaddr_in6 *, unsigned int);
 static unsigned int ifa_getscope(const struct sockaddr_in6 *);
@@ -208,6 +214,18 @@ if_closesockets_os(struct dhcpcd_ctx *ctx)
                close(priv->pf_inet6_fd);
 }
 
+bool
+if_ignore(const char *drvname)
+{
+       const char * const *p;
+
+       for (p = ifnames_ignore; *p; p++) {
+               if (strcmp(*p, drvname) == 0)
+                       return true;
+       }
+       return false;
+}
+
 int
 if_carrier(struct interface *ifp)
 {
index 57e6030e52e897ea4a6cb63aef6363612632ec8d..061b1fa89a33a9f0eaeafe4f89954bffc060ff3e 100644 (file)
@@ -252,6 +252,14 @@ if_conf(struct interface *ifp)
        return 0;
 }
 
+/* XXX work out TAP interfaces? */
+bool
+if_ignore(__unused const char *drvname)
+{
+
+       return false;
+}
+
 /* XXX work out Virtal Interface Masters */
 int
 if_vimaster(__unused const struct dhcpcd_ctx *ctx, __unused const char *ifname)
index 687a6ad093d7bb1625d999cdc5a671b8950370a4..4008698f86d72df2828b357ea13909c28aee8e10 100644 (file)
@@ -249,14 +249,21 @@ if_mtu_os(const struct interface *ifp)
 }
 
 int
-if_getssid(struct interface *ifp)
+if_getssid(__unused struct interface *ifp)
 {
 
-       UNUSED(ifp);
        errno = ENOTSUP;
        return -1;
 }
 
+/* XXX work out TAP interfaces? */
+bool
+if_ignore(__unused const char *drvname)
+{
+
+       return false;
+}
+
 unsigned short
 if_vlanid(__unused const struct interface *ifp)
 {
index c483f046ff2e62feb9c1dc890de3e3171d4bda4c..b9cf63edd011f6f21278517d8c28410e05a9d8e0 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -405,13 +405,6 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
                        continue;
 #endif
 
-               /* Don't allow loopback or pointopoint unless explicit */
-               if (ifa->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) {
-                       if ((argc == 0 || argc == -1) &&
-                           ctx->ifac == 0 && !if_hasconf(ctx, spec.devname))
-                               active = IF_INACTIVE;
-               }
-
                if (if_vimaster(ctx, spec.devname) == 1) {
                        logfunc_t *logfunc = argc != 0 ? logerrx : logdebugx;
                        logfunc("%s: is a Virtual Interface Master, skipping",
@@ -419,6 +412,17 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
                        continue;
                }
 
+#define        IF_NOCONF       ((argc == 0 || argc == -1) && ctx->ifac == 0 && \
+                        !if_hasconf(ctx, spec.devname))
+
+               /* Don't allow loopback or pointopoint unless explicit.
+                * Don't allow some reserved interface names unless explicit. */
+               if (IF_NOCONF) {
+                       if (ifa->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT) ||
+                           if_ignore(spec.drvname))
+                               active = IF_INACTIVE;
+               }
+
                ifp = calloc(1, sizeof(*ifp));
                if (ifp == NULL) {
                        logerr(__func__);
@@ -495,9 +499,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
 #endif
                        default:
                                /* Don't allow unless explicit */
-                               if ((argc == 0 || argc == -1) &&
-                                   ctx->ifac == 0 &&
-                                   !if_hasconf(ctx, ifp->name))
+                               if (IF_NOCONF)
                                        active = IF_INACTIVE;
                                if (active)
                                        logwarnx("%s: unsupported"
index 4126fd33e4c49e705a21d57d5d52889752177d6f..0800c102a3298079b0a5cd521bb8e0ac287ebfaa 100644 (file)
--- a/src/if.h
+++ b/src/if.h
@@ -152,6 +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 *);
 int if_vimaster(const struct dhcpcd_ctx *ctx, const char *);
 unsigned short if_vlanid(const struct interface *);
 int if_opensockets(struct dhcpcd_ctx *);