From: Roy Marples Date: Wed, 9 Oct 2019 11:47:06 +0000 (+0100) Subject: if: Ignore TAP interfaces by default X-Git-Tag: v8.1.0~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2af48e581d28f72ca918d87ace8a8af31854499;p=thirdparty%2Fdhcpcd.git if: Ignore TAP interfaces by default 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. --- diff --git a/src/if-bsd.c b/src/if-bsd.c index 89013b11..476a3fe2 100644 --- a/src/if-bsd.c +++ b/src/if-bsd.c @@ -101,6 +101,12 @@ #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) { diff --git a/src/if-linux.c b/src/if-linux.c index 57e6030e..061b1fa8 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -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) diff --git a/src/if-sun.c b/src/if-sun.c index 687a6ad0..4008698f 100644 --- a/src/if-sun.c +++ b/src/if-sun.c @@ -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) { diff --git a/src/if.c b/src/if.c index c483f046..b9cf63ed 100644 --- 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" diff --git a/src/if.h b/src/if.h index 4126fd33..0800c102 100644 --- 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 *);