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.

Discussed with:	ae
MFC after:	4 days
This commit is contained in:
Kyle Evans 2019-05-10 13:18:22 +00:00
parent ef68f03ec2
commit 6a68e95de8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=347429

View File

@ -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>
@ -146,6 +147,20 @@ static struct module_map_entry {
.ifname = "vmnet",
.kldname = "if_tuntap",
},
{
.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",
},
};
@ -1436,6 +1451,7 @@ ifmaybeload(const char *name)
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)
@ -1451,16 +1467,18 @@ ifmaybeload(const char *name)
/* 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 (*ifkind == '\0') {
if (!found) {
/* turn interface and unit into module name */
strlcpy(ifkind, "if_", sizeof(ifkind));
strlcat(ifkind, ifname, sizeof(ifkind));
@ -1480,8 +1498,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;
}