Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net allow cloners as modules.



details:   https://anonhg.NetBSD.org/src/rev/0dc6563249f3
branches:  trunk
changeset: 785356:0dc6563249f3
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 10 19:46:12 2013 +0000

description:
allow cloners as modules.

diffstat:

 sys/net/if.c |  28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diffs (67 lines):

diff -r 8a6787dc2fe5 -r 0dc6563249f3 sys/net/if.c
--- a/sys/net/if.c      Sun Mar 10 19:32:29 2013 +0000
+++ b/sys/net/if.c      Sun Mar 10 19:46:12 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.261 2012/11/01 06:36:30 msaitoh Exp $ */
+/*     $NetBSD: if.c,v 1.262 2013/03/10 19:46:12 christos Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.261 2012/11/01 06:36:30 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.262 2013/03/10 19:46:12 christos Exp $");
 
 #include "opt_inet.h"
 
@@ -124,6 +124,7 @@
 #include <net/radix.h>
 #include <net/route.h>
 #include <net/netisr.h>
+#include <sys/module.h>
 #ifdef NETATALK
 #include <netatalk/at_extern.h>
 #include <netatalk/at.h>
@@ -984,25 +985,32 @@
 {
        struct if_clone *ifc;
        const char *cp;
+       char *dp, ifname[IFNAMSIZ + 3];
        int unit;
 
+       strcpy(ifname, "if_");
        /* separate interface name from unit */
-       for (cp = name;
-           cp - name < IFNAMSIZ && *cp && (*cp < '0' || *cp > '9');
-           cp++)
-               continue;
+       for (dp = ifname + 3, cp = name; cp - name < IFNAMSIZ &&
+           *cp && (*cp < '0' || *cp > '9');)
+               *dp++ = *cp++;
 
        if (cp == name || cp - name == IFNAMSIZ || !*cp)
                return NULL;    /* No name or unit number */
+       *dp++ = '\0';
 
+again:
        LIST_FOREACH(ifc, &if_cloners, ifc_list) {
-               if (strlen(ifc->ifc_name) == cp - name &&
-                   strncmp(name, ifc->ifc_name, cp - name) == 0)
+               if (strcmp(ifname + 3, ifc->ifc_name) == 0)
                        break;
        }
 
-       if (ifc == NULL)
-               return NULL;
+       if (ifc == NULL) {
+               if (*ifname == '\0' ||
+                   module_autoload(ifname, MODULE_CLASS_DRIVER))
+                       return NULL;
+               *ifname = '\0';
+               goto again;
+       }
 
        unit = 0;
        while (cp - name < IFNAMSIZ && *cp) {



Home | Main Index | Thread Index | Old Index