Author: kevans
Date: Fri May 10 13:18:22 2019
New Revision: 347429
URL: https://svnweb.freebsd.org/changeset/base/347429

Log:
  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

Modified:
  head/sbin/ifconfig/ifconfig.c

Modified: head/sbin/ifconfig/ifconfig.c
==============================================================================
--- head/sbin/ifconfig/ifconfig.c       Fri May 10 12:33:42 2019        
(r347428)
+++ head/sbin/ifconfig/ifconfig.c       Fri May 10 13:18:22 2019        
(r347429)
@@ -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;
                }
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to