aboutsummaryrefslogtreecommitdiff
path: root/sbin/ifconfig/ifconfig.c
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2019-05-14 02:00:12 +0000
committerKyle Evans <kevans@FreeBSD.org>2019-05-14 02:00:12 +0000
commitbbe165e404500463cc127ae280ecfb8352c731a0 (patch)
treea9a737a43f5223dec0aaa2251569ad2252bc7844 /sbin/ifconfig/ifconfig.c
parent1451ae75dbc81d84924c54dbbe7d1045bb1162bd (diff)
downloadsrc-bbe165e404500463cc127ae280ecfb8352c731a0.tar.gz
src-bbe165e404500463cc127ae280ecfb8352c731a0.zip
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.
Notes
Notes: svn path=/stable/12/; revision=347557
Diffstat (limited to 'sbin/ifconfig/ifconfig.c')
-rw-r--r--sbin/ifconfig/ifconfig.c59
1 files changed, 53 insertions, 6 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index e330cc915667..4c37ae7d89b0 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -71,6 +71,7 @@ static const char rcsid[] =
#ifdef JAIL
#include <jail.h>
#endif
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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,9 +1457,24 @@ 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);
@@ -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;
}