From owner-svn-src-stable-12@freebsd.org Tue May 14 02:00:14 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 465D015A10EF; Tue, 14 May 2019 02:00:14 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E078176F16; Tue, 14 May 2019 02:00:13 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BABF61A628; Tue, 14 May 2019 02:00:13 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x4E20DrO083827; Tue, 14 May 2019 02:00:13 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4E20DTV083826; Tue, 14 May 2019 02:00:13 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201905140200.x4E20DTV083826@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 14 May 2019 02:00:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r347557 - in stable: 11/sbin/ifconfig 12/sbin/ifconfig X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/sbin/ifconfig 12/sbin/ifconfig X-SVN-Commit-Revision: 347557 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E078176F16 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.97)[-0.972,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 May 2019 02:00:14 -0000 Author: kevans Date: Tue May 14 02:00:12 2019 New Revision: 347557 URL: https://svnweb.freebsd.org/changeset/base/347557 Log: MFC r347241 (partial), r347392, r347429: ifconfig(8) ifname <-> kld mapping MFC r347241 (partial): Initial mechanism for mapping ifname <-> kld if_tun/if_tap mappings have been removed and the vmnet mapping has been updated to the if_tap module. MFC r347392: ifconfig(8): Partial revert of r347241 r347241 introduced an ifname <-> kld mapping table, mostly so tun/tap/vmnet can autoload the correct module on use. It also inadvertently made bogus some previously valid uses of sizeof(). Revert back to ifkind on the stack for simplicity sake. This reduces the diff from the previous version of ifmaybeload for easiser auditing. MFC r347429: ifconfig(8): Add kld mappings for ipsec/enc Additionally, providing mappings makes the comparison for already loaded modules a little more strict. This should have been done at initial introduction, but there was no real reason- however, it proves necessary for enc which has a standard enc -> if_enc mapping but there also exists an 'enc' module that's actually CAM. The mapping lets us unambiguously determine the correct module. Modified: stable/12/sbin/ifconfig/ifconfig.c Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/sbin/ifconfig/ifconfig.c Directory Properties: stable/11/ (props changed) Modified: stable/12/sbin/ifconfig/ifconfig.c ============================================================================== --- stable/12/sbin/ifconfig/ifconfig.c Tue May 14 00:34:08 2019 (r347556) +++ stable/12/sbin/ifconfig/ifconfig.c Tue May 14 02:00:12 2019 (r347557) @@ -71,6 +71,7 @@ static const char rcsid[] = #ifdef JAIL #include #endif +#include #include #include #include @@ -130,6 +131,31 @@ struct ifa_order_elt { TAILQ_HEAD(ifa_queue, ifa_order_elt); +static struct module_map_entry { + const char *ifname; + const char *kldname; +} module_map[] = { + { + .ifname = "vmnet", + .kldname = "if_tap", + }, + { + .ifname = "ipsec", + .kldname = "ipsec", + }, + { + /* + * This mapping exists because there is a conflicting enc module + * in CAM. ifconfig's guessing behavior will attempt to match + * the ifname to a module as well as if_${ifname} and clash with + * CAM enc. This is an assertion of the correct module to load. + */ + .ifname = "enc", + .kldname = "if_enc", + }, +}; + + void opt_register(struct option *p) { @@ -1413,9 +1439,11 @@ ifmaybeload(const char *name) { #define MOD_PREFIX_LEN 3 /* "if_" */ struct module_stat mstat; - int fileid, modid; + int i, fileid, modid; char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp; const char *cp; + struct module_map_entry *mme; + bool found; /* loading suppressed by the user */ if (noload) @@ -1429,10 +1457,25 @@ ifmaybeload(const char *name) break; } - /* turn interface and unit into module name */ - strlcpy(ifkind, "if_", sizeof(ifkind)); - strlcat(ifkind, ifname, sizeof(ifkind)); + /* Either derive it from the map or guess otherwise */ + *ifkind = '\0'; + found = false; + for (i = 0; i < nitems(module_map); ++i) { + mme = &module_map[i]; + if (strcmp(mme->ifname, ifname) == 0) { + strlcpy(ifkind, mme->kldname, sizeof(ifkind)); + found = true; + break; + } + } + /* We didn't have an alias for it... we'll guess. */ + if (!found) { + /* turn interface and unit into module name */ + strlcpy(ifkind, "if_", sizeof(ifkind)); + strlcat(ifkind, ifname, sizeof(ifkind)); + } + /* scan files in kernel */ mstat.version = sizeof(struct module_stat); for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { @@ -1447,8 +1490,12 @@ ifmaybeload(const char *name) } else { cp = mstat.name; } - /* already loaded? */ - if (strcmp(ifname, cp) == 0 || + /* + * Is it already loaded? Don't compare with ifname if + * we were specifically told which kld to use. Doing + * so could lead to conflicts not trivially solved. + */ + if ((!found && strcmp(ifname, cp) == 0) || strcmp(ifkind, cp) == 0) return; }