aboutsummaryrefslogtreecommitdiff
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2019-05-08 02:32:11 +0000
committerKyle Evans <kevans@FreeBSD.org>2019-05-08 02:32:11 +0000
commit251a32b5b2babf50556669b192f5820a61f6d900 (patch)
tree7fcc1f3d18e672a7f4f3c9a42fb34e649de6abf5 /sbin/ifconfig
parentd044b69950ed6ac292a3fd96323cfe5d81baf0f5 (diff)
downloadsrc-251a32b5b2babf50556669b192f5820a61f6d900.tar.gz
src-251a32b5b2babf50556669b192f5820a61f6d900.zip
tun/tap: merge and rename to `tuntap`
tun(4) and tap(4) share the same general management interface and have a lot in common. Bugs exist in tap(4) that have been fixed in tun(4), and vice-versa. Let's reduce the maintenance requirements by merging them together and using flags to differentiate between the three interface types (tun, tap, vmnet). This fixes a couple of tap(4)/vmnet(4) issues right out of the gate: - tap devices may no longer be destroyed while they're open [0] - VIMAGE issues already addressed in tun by kp [0] emaste had removed an easy-panic-button in r240938 due to devdrn blocking. A naive glance over this leads me to believe that this isn't quite complete -- destroy_devl will only block while executing d_* functions, but doesn't block the device from being destroyed while a process has it open. The latter is the intent of the condvar in tun, so this is "fixed" (for certain definitions of the word -- it wasn't really broken in tap, it just wasn't quite ideal). ifconfig(8) also grew the ability to map an interface name to a kld, so that `ifconfig {tun,tap}0` can continue to autoload the correct module, and `ifconfig vmnet0 create` will now autoload the correct module. This is a low overhead addition. (MFC commentary) This may get MFC'd if many bugs in tun(4)/tap(4) are discovered after this, and how critical they are. Changes after this are likely easily MFC'd without taking this merge, but the merge will be easier. I have no plans to do this MFC as of now. Reviewed by: bcr (manpages), tuexen (testing, syzkaller/packetdrill) Input also from: melifaro Relnotes: yes Differential Revision: https://reviews.freebsd.org/D20044
Notes
Notes: svn path=/head/; revision=347241
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/ifconfig.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index e330cc915667..1c46247b36a7 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -130,6 +130,25 @@ 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 = "tun",
+ .kldname = "if_tuntap",
+ },
+ {
+ .ifname = "tap",
+ .kldname = "if_tuntap",
+ },
+ {
+ .ifname = "vmnet",
+ .kldname = "if_tuntap",
+ },
+};
+
+
void
opt_register(struct option *p)
{
@@ -1413,9 +1432,10 @@ ifmaybeload(const char *name)
{
#define MOD_PREFIX_LEN 3 /* "if_" */
struct module_stat mstat;
- int fileid, modid;
- char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp;
+ int i, fileid, modid;
+ char ifname[IFNAMSIZ], *ifkind, *dp;
const char *cp;
+ struct module_map_entry *mme;
/* loading suppressed by the user */
if (noload)
@@ -1429,9 +1449,26 @@ 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 = NULL;
+ for (i = 0; i < nitems(module_map); ++i) {
+ mme = &module_map[i];
+ if (strcmp(mme->ifname, ifname) == 0) {
+ ifkind = strdup(mme->kldname);
+ if (ifkind == NULL)
+ err(EXIT_FAILURE, "ifmaybeload");
+ break;
+ }
+ }
+
+ /* We didn't have an alias for it... we'll guess. */
+ if (ifkind == NULL) {
+ ifkind = malloc(IFNAMSIZ + MOD_PREFIX_LEN);
+
+ /* 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);
@@ -1450,7 +1487,7 @@ ifmaybeload(const char *name)
/* already loaded? */
if (strcmp(ifname, cp) == 0 ||
strcmp(ifkind, cp) == 0)
- return;
+ goto out;
}
}
@@ -1459,6 +1496,8 @@ ifmaybeload(const char *name)
* infer the names of all drivers (eg mlx4en(4)).
*/
(void) kldload(ifkind);
+out:
+ free(ifkind);
}
static struct cmd basic_cmds[] = {