diff options
author | glebius <glebius@FreeBSD.org> | 2012-10-16 13:37:54 +0000 |
---|---|---|
committer | glebius <glebius@FreeBSD.org> | 2012-10-16 13:37:54 +0000 |
commit | 05f24a6b77a43334f14f31cd33a4f3e34a418ea2 (patch) | |
tree | 0f54a9446bfe2083d3c0a3f744318b2be8a0db05 /sys/net | |
parent | 745884b065065ffc8847d3ea463bf751ffcaf863 (diff) | |
download | FreeBSD-src-05f24a6b77a43334f14f31cd33a4f3e34a418ea2.zip FreeBSD-src-05f24a6b77a43334f14f31cd33a4f3e34a418ea2.tar.gz |
Make the "struct if_clone" opaque to users of the cloning API. Users
now use function calls:
if_clone_simple()
if_clone_advanced()
to initialize a cloner, instead of macros that initialize if_clone
structure.
Discussed with: brooks, bz, 1 year ago
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/if_bridge.c | 10 | ||||
-rw-r--r-- | sys/net/if_clone.c | 224 | ||||
-rw-r--r-- | sys/net/if_clone.h | 97 | ||||
-rw-r--r-- | sys/net/if_disc.c | 14 | ||||
-rw-r--r-- | sys/net/if_edsc.c | 27 | ||||
-rw-r--r-- | sys/net/if_enc.c | 9 | ||||
-rw-r--r-- | sys/net/if_epair.c | 35 | ||||
-rw-r--r-- | sys/net/if_faith.c | 16 | ||||
-rw-r--r-- | sys/net/if_gif.c | 12 | ||||
-rw-r--r-- | sys/net/if_gre.c | 16 | ||||
-rw-r--r-- | sys/net/if_lagg.c | 12 | ||||
-rw-r--r-- | sys/net/if_loop.c | 19 | ||||
-rw-r--r-- | sys/net/if_stf.c | 15 | ||||
-rw-r--r-- | sys/net/if_tap.c | 60 | ||||
-rw-r--r-- | sys/net/if_tun.c | 24 | ||||
-rw-r--r-- | sys/net/if_vlan.c | 25 |
16 files changed, 339 insertions, 276 deletions
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index 5800831..e4ce154 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -481,7 +481,8 @@ const int bridge_control_table_size = LIST_HEAD(, bridge_softc) bridge_list; -IFC_SIMPLE_DECLARE(bridge, 0); +static struct if_clone *bridge_cloner; +static const char bridge_name[] = "bridge"; static int bridge_modevent(module_t mod, int type, void *data) @@ -490,7 +491,8 @@ bridge_modevent(module_t mod, int type, void *data) switch (type) { case MOD_LOAD: mtx_init(&bridge_list_mtx, "if_bridge list", NULL, MTX_DEF); - if_clone_attach(&bridge_cloner); + bridge_cloner = if_clone_simple(bridge_name, + bridge_clone_create, bridge_clone_destroy, 0); bridge_rtnode_zone = uma_zcreate("bridge_rtnode", sizeof(struct bridge_rtnode), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); @@ -506,7 +508,7 @@ bridge_modevent(module_t mod, int type, void *data) case MOD_UNLOAD: EVENTHANDLER_DEREGISTER(ifnet_departure_event, bridge_detach_cookie); - if_clone_detach(&bridge_cloner); + if_clone_detach(bridge_cloner); uma_zdestroy(bridge_rtnode_zone); bridge_input_p = NULL; bridge_output_p = NULL; @@ -595,7 +597,7 @@ bridge_clone_create(struct if_clone *ifc, int unit, caddr_t params) LIST_INIT(&sc->sc_spanlist); ifp->if_softc = sc; - if_initname(ifp, ifc->ifc_name, unit); + if_initname(ifp, bridge_name, unit); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = bridge_ioctl; ifp->if_transmit = bridge_transmit; diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c index 3543e2f..5f68d29 100644 --- a/sys/net/if_clone.c +++ b/sys/net/if_clone.c @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2012 Gleb Smirnoff <glebius@FreeBSD.org> * Copyright (c) 1980, 1986, 1993 * The Regents of the University of California. All rights reserved. * @@ -42,19 +43,65 @@ #include <net/if.h> #include <net/if_clone.h> -#if 0 -#include <net/if_dl.h> -#endif -#include <net/if_types.h> #include <net/if_var.h> #include <net/radix.h> #include <net/route.h> #include <net/vnet.h> +/* Current IF_MAXUNIT expands maximum to 5 characters. */ +#define IFCLOSIZ (IFNAMSIZ - 5) + +/* + * Structure describing a `cloning' interface. + * + * List of locks + * (c) const until freeing + * (d) driver specific data, may need external protection. + * (e) locked by if_cloners_mtx + * (i) locked by ifc_mtx mtx + */ +struct if_clone { + char ifc_name[IFCLOSIZ]; /* (c) Name of device, e.g. `gif' */ + struct unrhdr *ifc_unrhdr; /* (c) alloc_unr(9) header */ + int ifc_maxunit; /* (c) maximum unit number */ + long ifc_refcnt; /* (i) Reference count. */ + LIST_HEAD(, ifnet) ifc_iflist; /* (i) List of cloned interfaces */ + struct mtx ifc_mtx; /* Mutex to protect members. */ + + enum { SIMPLE, ADVANCED } ifc_type; /* (c) */ + + /* (c) Driver specific cloning functions. Called with no locks held. */ + union { + struct { /* advanced cloner */ + ifc_match_t *_ifc_match; + ifc_create_t *_ifc_create; + ifc_destroy_t *_ifc_destroy; + } A; + struct { /* simple cloner */ + ifcs_create_t *_ifcs_create; + ifcs_destroy_t *_ifcs_destroy; + int _ifcs_minifs; /* minimum ifs */ + + } S; + } U; +#define ifc_match U.A._ifc_match +#define ifc_create U.A._ifc_create +#define ifc_destroy U.A._ifc_destroy +#define ifcs_create U.S._ifcs_create +#define ifcs_destroy U.S._ifcs_destroy +#define ifcs_minifs U.S._ifcs_minifs + + LIST_ENTRY(if_clone) ifc_list; /* (e) On list of cloners */ +}; + static void if_clone_free(struct if_clone *ifc); static int if_clone_createif(struct if_clone *ifc, char *name, size_t len, caddr_t params); +static int ifc_simple_match(struct if_clone *, const char *); +static int ifc_simple_create(struct if_clone *, char *, size_t, caddr_t); +static int ifc_simple_destroy(struct if_clone *, struct ifnet *); + static struct mtx if_cloners_mtx; static VNET_DEFINE(int, if_cloners_count); VNET_DEFINE(LIST_HEAD(, if_clone), if_cloners); @@ -138,18 +185,25 @@ if_clone_create(char *name, size_t len, caddr_t params) /* Try to find an applicable cloner for this request */ IF_CLONERS_LOCK(); - LIST_FOREACH(ifc, &V_if_cloners, ifc_list) { - if (ifc->ifc_match(ifc, name)) { - break; + LIST_FOREACH(ifc, &V_if_cloners, ifc_list) + if (ifc->ifc_type == SIMPLE) { + if (ifc_simple_match(ifc, name)) + break; + } else { + if (ifc->ifc_match(ifc, name)) + break; } - } #ifdef VIMAGE if (ifc == NULL && !IS_DEFAULT_VNET(curvnet)) { CURVNET_SET_QUIET(vnet0); - LIST_FOREACH(ifc, &V_if_cloners, ifc_list) { - if (ifc->ifc_match(ifc, name)) - break; - } + LIST_FOREACH(ifc, &V_if_cloners, ifc_list) + if (ifc->ifc_type == SIMPLE) { + if (ifc_simple_match(ifc, name)) + break; + } else { + if (ifc->ifc_match(ifc, name)) + break; + } CURVNET_RESTORE(); } #endif @@ -173,7 +227,10 @@ if_clone_createif(struct if_clone *ifc, char *name, size_t len, caddr_t params) if (ifunit(name) != NULL) return (EEXIST); - err = (*ifc->ifc_create)(ifc, name, len, params); + if (ifc->ifc_type == SIMPLE) + err = ifc_simple_create(ifc, name, len, params); + else + err = (*ifc->ifc_create)(ifc, name, len, params); if (!err) { ifp = ifunit(name); @@ -214,10 +271,14 @@ if_clone_destroy(const char *name) #ifdef VIMAGE if (ifc == NULL && !IS_DEFAULT_VNET(curvnet)) { CURVNET_SET_QUIET(vnet0); - LIST_FOREACH(ifc, &V_if_cloners, ifc_list) { - if (ifc->ifc_match(ifc, name)) - break; - } + LIST_FOREACH(ifc, &V_if_cloners, ifc_list) + if (ifc->type == SIMPLE) { + if (ifc_simple_match(ifc, name)) + break; + } else { + if (ifc->ifc_match(ifc, name)) + break; + } CURVNET_RESTORE(); } #endif @@ -241,7 +302,7 @@ if_clone_destroyif(struct if_clone *ifc, struct ifnet *ifp) int err; struct ifnet *ifcifp; - if (ifc->ifc_destroy == NULL) + if (ifc->ifc_type == ADVANCED && ifc->ifc_destroy == NULL) return(EOPNOTSUPP); /* @@ -266,7 +327,10 @@ if_clone_destroyif(struct if_clone *ifc, struct ifnet *ifp) if_delgroup(ifp, ifc->ifc_name); - err = (*ifc->ifc_destroy)(ifc, ifp); + if (ifc->ifc_type == SIMPLE) + err = ifc_simple_destroy(ifc, ifp); + else + err = (*ifc->ifc_destroy)(ifc, ifp); if (err != 0) { if_addgroup(ifp, ifc->ifc_name); @@ -279,21 +343,29 @@ if_clone_destroyif(struct if_clone *ifc, struct ifnet *ifp) return (err); } -/* - * Register a network interface cloner. - */ -int -if_clone_attach(struct if_clone *ifc) +static struct if_clone * +if_clone_alloc(const char *name, int maxunit) { - struct if_clone *ifc1; + struct if_clone *ifc; - KASSERT(ifc->ifc_name != NULL, ("%s: no name\n", __func__)); + KASSERT(name != NULL, ("%s: no name\n", __func__)); + ifc = malloc(sizeof(struct if_clone), M_CLONE, M_WAITOK | M_ZERO); + strncpy(ifc->ifc_name, name, IFCLOSIZ-1); IF_CLONE_LOCK_INIT(ifc); IF_CLONE_ADDREF(ifc); + ifc->ifc_maxunit = maxunit ? maxunit : IF_MAXUNIT; ifc->ifc_unrhdr = new_unrhdr(0, ifc->ifc_maxunit, &ifc->ifc_mtx); LIST_INIT(&ifc->ifc_iflist); + return (ifc); +} + +static int +if_clone_attach(struct if_clone *ifc) +{ + struct if_clone *ifc1; + IF_CLONERS_LOCK(); LIST_FOREACH(ifc1, &V_if_cloners, ifc_list) if (strcmp(ifc->ifc_name, ifc1->ifc_name) == 0) { @@ -305,11 +377,63 @@ if_clone_attach(struct if_clone *ifc) V_if_cloners_count++; IF_CLONERS_UNLOCK(); - if (ifc->ifc_attach != NULL) - (*ifc->ifc_attach)(ifc); + return (0); +} + +struct if_clone * +if_clone_advanced(const char *name, u_int maxunit, ifc_match_t match, + ifc_create_t create, ifc_destroy_t destroy) +{ + struct if_clone *ifc; + + ifc = if_clone_alloc(name, maxunit); + ifc->ifc_type = ADVANCED; + ifc->ifc_match = match; + ifc->ifc_create = create; + ifc->ifc_destroy = destroy; + + if (if_clone_attach(ifc) != 0) { + if_clone_free(ifc); + return (NULL); + } + EVENTHANDLER_INVOKE(if_clone_event, ifc); - return (0); + return (ifc); +} + +struct if_clone * +if_clone_simple(const char *name, ifcs_create_t create, ifcs_destroy_t destroy, + u_int minifs) +{ + struct if_clone *ifc; + u_int unit; + + ifc = if_clone_alloc(name, 0); + ifc->ifc_type = SIMPLE; + ifc->ifcs_create = create; + ifc->ifcs_destroy = destroy; + ifc->ifcs_minifs = minifs; + + if (if_clone_attach(ifc) != 0) { + if_clone_free(ifc); + return (NULL); + } + + for (unit = 0; unit < minifs; unit++) { + char name[IFNAMSIZ]; + int error; + + snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, unit); + error = if_clone_createif(ifc, name, IFNAMSIZ, NULL); + KASSERT(error == 0, + ("%s: failed to create required interface %s", + __func__, name)); + } + + EVENTHANDLER_INVOKE(if_clone_event, ifc); + + return (ifc); } /* @@ -318,7 +442,6 @@ if_clone_attach(struct if_clone *ifc) void if_clone_detach(struct if_clone *ifc) { - struct ifc_simple_data *ifcs = ifc->ifc_data; IF_CLONERS_LOCK(); LIST_REMOVE(ifc, ifc_list); @@ -326,8 +449,8 @@ if_clone_detach(struct if_clone *ifc) IF_CLONERS_UNLOCK(); /* Allow all simples to be destroyed */ - if (ifc->ifc_attach == ifc_simple_attach) - ifcs->ifcs_minifs = 0; + if (ifc->ifc_type == SIMPLE) + ifc->ifcs_minifs = 0; /* destroy all interfaces for this cloner */ while (!LIST_EMPTY(&ifc->ifc_iflist)) @@ -345,6 +468,7 @@ if_clone_free(struct if_clone *ifc) IF_CLONE_LOCK_DESTROY(ifc); delete_unrhdr(ifc->ifc_unrhdr); + free(ifc, M_CLONE); } /* @@ -483,29 +607,7 @@ ifc_free_unit(struct if_clone *ifc, int unit) IF_CLONE_REMREF(ifc); } -void -ifc_simple_attach(struct if_clone *ifc) -{ - int err; - int unit; - char name[IFNAMSIZ]; - struct ifc_simple_data *ifcs = ifc->ifc_data; - - KASSERT(ifcs->ifcs_minifs - 1 <= ifc->ifc_maxunit, - ("%s: %s requested more units than allowed (%d > %d)", - __func__, ifc->ifc_name, ifcs->ifcs_minifs, - ifc->ifc_maxunit + 1)); - - for (unit = 0; unit < ifcs->ifcs_minifs; unit++) { - snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, unit); - err = if_clone_createif(ifc, name, IFNAMSIZ, NULL); - KASSERT(err == 0, - ("%s: failed to create required interface %s", - __func__, name)); - } -} - -int +static int ifc_simple_match(struct if_clone *ifc, const char *name) { const char *cp; @@ -526,14 +628,13 @@ ifc_simple_match(struct if_clone *ifc, const char *name) return (1); } -int +static int ifc_simple_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) { char *dp; int wildcard; int unit; int err; - struct ifc_simple_data *ifcs = ifc->ifc_data; err = ifc_name2unit(name, &unit); if (err != 0) @@ -545,7 +646,7 @@ ifc_simple_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) if (err != 0) return (err); - err = ifcs->ifcs_create(ifc, unit, params); + err = ifc->ifcs_create(ifc, unit, params); if (err != 0) { ifc_free_unit(ifc, unit); return (err); @@ -569,18 +670,17 @@ ifc_simple_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) return (0); } -int +static int ifc_simple_destroy(struct if_clone *ifc, struct ifnet *ifp) { int unit; - struct ifc_simple_data *ifcs = ifc->ifc_data; unit = ifp->if_dunit; - if (unit < ifcs->ifcs_minifs) + if (unit < ifc->ifcs_minifs) return (EINVAL); - ifcs->ifcs_destroy(ifp); + ifc->ifcs_destroy(ifp); ifc_free_unit(ifc, unit); diff --git a/sys/net/if_clone.h b/sys/net/if_clone.h index 4278814..7159421 100644 --- a/sys/net/if_clone.h +++ b/sys/net/if_clone.h @@ -35,87 +35,42 @@ #ifdef _KERNEL -#define IFC_CLONE_INITIALIZER(name, data, maxunit, \ - attach, match, create, destroy) \ - { \ - .ifc_name = name, \ - .ifc_maxunit = maxunit, \ - .ifc_data = data, \ - .ifc_attach = attach, \ - .ifc_match = match, \ - .ifc_create = create, \ - .ifc_destroy = destroy, \ - } - -/* - * Structure describing a `cloning' interface. - * - * List of locks - * (c) const until freeing - * (d) driver specific data, may need external protection. - * (e) locked by if_cloners_mtx - * (i) locked by ifc_mtx mtx - */ -struct if_clone { - LIST_ENTRY(if_clone) ifc_list; /* (e) On list of cloners */ - const char *ifc_name; /* (c) Name of device, e.g. `gif' */ - int ifc_maxunit; /* (c) Maximum unit number */ - struct unrhdr *ifc_unrhdr; /* (c) alloc_unr(9) header */ - void *ifc_data; /* (*) Data for ifc_* functions. */ - - /* (c) Driver specific cloning functions. Called with no locks held. */ - void (*ifc_attach)(struct if_clone *); - int (*ifc_match)(struct if_clone *, const char *); - int (*ifc_create)(struct if_clone *, char *, size_t, caddr_t); - int (*ifc_destroy)(struct if_clone *, struct ifnet *); - - long ifc_refcnt; /* (i) Refrence count. */ - struct mtx ifc_mtx; /* Mutex to protect members. */ - LIST_HEAD(, ifnet) ifc_iflist; /* (i) List of cloned interfaces */ -}; - -void if_clone_init(void); -int if_clone_attach(struct if_clone *); +struct if_clone; + +/* Methods. */ +typedef int ifc_match_t(struct if_clone *, const char *); +typedef int ifc_create_t(struct if_clone *, char *, size_t, caddr_t); +typedef int ifc_destroy_t(struct if_clone *, struct ifnet *); + +typedef int ifcs_create_t(struct if_clone *, int, caddr_t); +typedef void ifcs_destroy_t(struct ifnet *); + +/* Interface cloner (de)allocating functions. */ +struct if_clone * + if_clone_advanced(const char *, u_int, ifc_match_t, ifc_create_t, + ifc_destroy_t); +struct if_clone * + if_clone_simple(const char *, ifcs_create_t, ifcs_destroy_t, u_int); void if_clone_detach(struct if_clone *); -void vnet_if_clone_init(void); - -int if_clone_create(char *, size_t, caddr_t); -int if_clone_destroy(const char *); -int if_clone_destroyif(struct if_clone *, struct ifnet *); -int if_clone_list(struct if_clonereq *); +/* Unit (de)allocating fucntions. */ int ifc_name2unit(const char *name, int *unit); int ifc_alloc_unit(struct if_clone *, int *); void ifc_free_unit(struct if_clone *, int); -/* - * The ifc_simple functions, structures, and macros implement basic - * cloning as in 5.[012]. - */ - -struct ifc_simple_data { - int ifcs_minifs; /* minimum number of interfaces */ - - int (*ifcs_create)(struct if_clone *, int, caddr_t); - void (*ifcs_destroy)(struct ifnet *); -}; - -/* interface clone event */ +/* Interface clone event. */ typedef void (*if_clone_event_handler_t)(void *, struct if_clone *); EVENTHANDLER_DECLARE(if_clone_event, if_clone_event_handler_t); -#define IFC_SIMPLE_DECLARE(name, minifs) \ -struct ifc_simple_data name##_cloner_data = \ - {minifs, name##_clone_create, name##_clone_destroy}; \ -struct if_clone name##_cloner = \ - IFC_CLONE_INITIALIZER(#name, &name##_cloner_data, IF_MAXUNIT, \ - ifc_simple_attach, ifc_simple_match, ifc_simple_create, ifc_simple_destroy) +/* The below interfaces used only by net/if.c. */ +void if_clone_init(void); +void vnet_if_clone_init(void); +int if_clone_create(char *, size_t, caddr_t); +int if_clone_destroy(const char *); +int if_clone_list(struct if_clonereq *); -void ifc_simple_attach(struct if_clone *); -int ifc_simple_match(struct if_clone *, const char *); -int ifc_simple_create(struct if_clone *, char *, size_t, caddr_t); -int ifc_simple_destroy(struct if_clone *, struct ifnet *); +/* The below interface used only by epair(4). */ +int if_clone_destroyif(struct if_clone *, struct ifnet *); #endif /* _KERNEL */ - #endif /* !_NET_IF_CLONE_H_ */ diff --git a/sys/net/if_disc.c b/sys/net/if_disc.c index ca77899..f2f902e 100644 --- a/sys/net/if_disc.c +++ b/sys/net/if_disc.c @@ -59,8 +59,6 @@ #define DSMTU 65532 #endif -#define DISCNAME "disc" - struct disc_softc { struct ifnet *sc_ifp; }; @@ -72,9 +70,10 @@ static int discioctl(struct ifnet *, u_long, caddr_t); static int disc_clone_create(struct if_clone *, int, caddr_t); static void disc_clone_destroy(struct ifnet *); -static MALLOC_DEFINE(M_DISC, DISCNAME, "Discard interface"); +static const char discname[] = "disc"; +static MALLOC_DEFINE(M_DISC, discname, "Discard interface"); -IFC_SIMPLE_DECLARE(disc, 0); +static struct if_clone *disc_cloner; static int disc_clone_create(struct if_clone *ifc, int unit, caddr_t params) @@ -90,7 +89,7 @@ disc_clone_create(struct if_clone *ifc, int unit, caddr_t params) } ifp->if_softc = sc; - if_initname(ifp, ifc->ifc_name, unit); + if_initname(ifp, discname, unit); ifp->if_mtu = DSMTU; /* * IFF_LOOPBACK should not be removed from disc's flags because @@ -135,10 +134,11 @@ disc_modevent(module_t mod, int type, void *data) switch (type) { case MOD_LOAD: - if_clone_attach(&disc_cloner); + disc_cloner = if_clone_simple(discname, disc_clone_create, + disc_clone_destroy, 0); break; case MOD_UNLOAD: - if_clone_detach(&disc_cloner); + if_clone_detach(disc_cloner); break; default: return (EOPNOTSUPP); diff --git a/sys/net/if_edsc.c b/sys/net/if_edsc.c index 82b1485..b54cfae 100644 --- a/sys/net/if_edsc.c +++ b/sys/net/if_edsc.c @@ -51,6 +51,8 @@ #include <net/if_types.h> /* IFT_ETHER and friends */ #include <net/if_var.h> /* kernel-only part of ifnet(9) */ +static const char edscname[] = "edsc"; + /* * Software configuration of an interface specific to this device type. */ @@ -64,9 +66,9 @@ struct edsc_softc { }; /* - * Simple cloning methods. - * IFC_SIMPLE_DECLARE() expects precisely these names. + * Attach to the interface cloning framework. */ +static struct if_clone *edsc_cloner; static int edsc_clone_create(struct if_clone *, int, caddr_t); static void edsc_clone_destroy(struct ifnet *); @@ -81,15 +83,7 @@ static void edsc_start(struct ifnet *ifp); /* * We'll allocate softc instances from this. */ -static MALLOC_DEFINE(M_EDSC, "edsc", "Ethernet discard interface"); - -/* - * Attach to the interface cloning framework under the name of "edsc". - * The second argument is the number of units to be created from - * the outset. It's also the minimum number of units allowed. - * We don't want any units created as soon as the driver is loaded. - */ -IFC_SIMPLE_DECLARE(edsc, 0); +static MALLOC_DEFINE(M_EDSC, edscname, "Ethernet discard interface"); /* * Create an interface instance. @@ -116,7 +110,7 @@ edsc_clone_create(struct if_clone *ifc, int unit, caddr_t params) /* * Get a name for this particular interface in its ifnet structure. */ - if_initname(ifp, ifc->ifc_name, unit); + if_initname(ifp, edscname, unit); /* * Typical Ethernet interface flags: we can do broadcast and @@ -323,8 +317,13 @@ edsc_modevent(module_t mod, int type, void *data) case MOD_LOAD: /* * Connect to the network interface cloning framework. + * The last argument is the number of units to be created + * from the outset. It's also the minimum number of units + * allowed. We don't want any units created as soon as the + * driver is loaded. */ - if_clone_attach(&edsc_cloner); + edsc_cloner = if_clone_simple(edscname, edsc_clone_create, + edsc_clone_destroy, 0); break; case MOD_UNLOAD: @@ -332,7 +331,7 @@ edsc_modevent(module_t mod, int type, void *data) * Disconnect from the cloning framework. * Existing interfaces will be disposed of properly. */ - if_clone_detach(&edsc_cloner); + if_clone_detach(edsc_cloner); break; default: diff --git a/sys/net/if_enc.c b/sys/net/if_enc.c index efd3fc7..ecc2415 100644 --- a/sys/net/if_enc.c +++ b/sys/net/if_enc.c @@ -91,8 +91,8 @@ static int enc_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct route *ro); static int enc_clone_create(struct if_clone *, int, caddr_t); static void enc_clone_destroy(struct ifnet *); - -IFC_SIMPLE_DECLARE(enc, 1); +static struct if_clone *enc_cloner; +static const char encname[] = "enc"; /* * Sysctls. @@ -143,7 +143,7 @@ enc_clone_create(struct if_clone *ifc, int unit, caddr_t params) return (ENOSPC); } - if_initname(ifp, ifc->ifc_name, unit); + if_initname(ifp, encname, unit); ifp->if_mtu = ENCMTU; ifp->if_ioctl = enc_ioctl; ifp->if_output = enc_output; @@ -167,7 +167,8 @@ enc_modevent(module_t mod, int type, void *data) switch (type) { case MOD_LOAD: mtx_init(&enc_mtx, "enc mtx", NULL, MTX_DEF); - if_clone_attach(&enc_cloner); + enc_cloner = if_clone_simple(encname, enc_clone_create, + enc_clone_destroy, 0); break; case MOD_UNLOAD: printf("enc module unload - not possible for this module\n"); diff --git a/sys/net/if_epair.c b/sys/net/if_epair.c index 2a67e18..0a2d2bc 100644 --- a/sys/net/if_epair.c +++ b/sys/net/if_epair.c @@ -72,8 +72,6 @@ __FBSDID("$FreeBSD$"); #include <net/netisr.h> #include <net/vnet.h> -#define EPAIRNAME "epair" - SYSCTL_DECL(_net_link); static SYSCTL_NODE(_net_link, OID_AUTO, epair, CTLFLAG_RW, 0, "epair sysctl"); @@ -100,9 +98,11 @@ static int epair_clone_match(struct if_clone *, const char *); static int epair_clone_create(struct if_clone *, char *, size_t, caddr_t); static int epair_clone_destroy(struct if_clone *, struct ifnet *); +static const char epairname[] = "epair"; + /* Netisr realted definitions and sysctl. */ static struct netisr_handler epair_nh = { - .nh_name = EPAIRNAME, + .nh_name = epairname, .nh_proto = NETISR_EPAIR, .nh_policy = NETISR_POLICY_CPU, .nh_handler = epair_nh_sintr, @@ -168,12 +168,10 @@ STAILQ_HEAD(eid_list, epair_ifp_drain); #define EPAIR_REFCOUNT_ASSERT(a, p) #endif -static MALLOC_DEFINE(M_EPAIR, EPAIRNAME, +static MALLOC_DEFINE(M_EPAIR, epairname, "Pair of virtual cross-over connected Ethernet-like interfaces"); -static struct if_clone epair_cloner = IFC_CLONE_INITIALIZER( - EPAIRNAME, NULL, IF_MAXUNIT, - NULL, epair_clone_match, epair_clone_create, epair_clone_destroy); +static struct if_clone *epair_cloner; /* * DPCPU area and functions. @@ -692,10 +690,10 @@ epair_clone_match(struct if_clone *ifc, const char *name) * - epair<n> * but not the epair<n>[ab] versions. */ - if (strncmp(EPAIRNAME, name, sizeof(EPAIRNAME)-1) != 0) + if (strncmp(epairname, name, sizeof(epairname)-1) != 0) return (0); - for (cp = name + sizeof(EPAIRNAME) - 1; *cp != '\0'; cp++) { + for (cp = name + sizeof(epairname) - 1; *cp != '\0'; cp++) { if (*cp < '0' || *cp > '9') return (0); } @@ -714,7 +712,7 @@ epair_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) /* * We are abusing params to create our second interface. - * Actually we already created it and called if_clone_createif() + * Actually we already created it and called if_clone_create() * for it to do the official insertion procedure the moment we knew * it cannot fail anymore. So just do attach it here. */ @@ -807,7 +805,7 @@ epair_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) ifp = sca->ifp; ifp->if_softc = sca; strlcpy(ifp->if_xname, name, IFNAMSIZ); - ifp->if_dname = ifc->ifc_name; + ifp->if_dname = epairname; ifp->if_dunit = unit; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_capabilities = IFCAP_VLAN_MTU; @@ -833,7 +831,7 @@ epair_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) ifp = scb->ifp; ifp->if_softc = scb; strlcpy(ifp->if_xname, name, IFNAMSIZ); - ifp->if_dname = ifc->ifc_name; + ifp->if_dname = epairname; ifp->if_dunit = unit; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_capabilities = IFCAP_VLAN_MTU; @@ -843,10 +841,10 @@ epair_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) ifp->if_init = epair_init; ifp->if_snd.ifq_maxlen = ifqmaxlen; /* We need to play some tricks here for the second interface. */ - strlcpy(name, EPAIRNAME, len); + strlcpy(name, epairname, len); error = if_clone_create(name, len, (caddr_t)scb); if (error) - panic("%s: if_clone_createif() for our 2nd iface failed: %d", + panic("%s: if_clone_create() for our 2nd iface failed: %d", __func__, error); scb->if_qflush = ifp->if_qflush; ifp->if_qflush = epair_qflush; @@ -958,16 +956,17 @@ epair_modevent(module_t mod, int type, void *data) if (TUNABLE_INT_FETCH("net.link.epair.netisr_maxqlen", &qlimit)) epair_nh.nh_qlimit = qlimit; netisr_register(&epair_nh); - if_clone_attach(&epair_cloner); + epair_cloner = if_clone_advanced(epairname, 0, + epair_clone_match, epair_clone_create, epair_clone_destroy); if (bootverbose) - printf("%s initialized.\n", EPAIRNAME); + printf("%s initialized.\n", epairname); break; case MOD_UNLOAD: - if_clone_detach(&epair_cloner); + if_clone_detach(epair_cloner); netisr_unregister(&epair_nh); epair_dpcpu_detach(); if (bootverbose) - printf("%s unloaded.\n", EPAIRNAME); + printf("%s unloaded.\n", epairname); break; default: return (EOPNOTSUPP); diff --git a/sys/net/if_faith.c b/sys/net/if_faith.c index db4c1d9..907dcce 100644 --- a/sys/net/if_faith.c +++ b/sys/net/if_faith.c @@ -79,8 +79,6 @@ #include <netinet6/ip6_var.h> #endif -#define FAITHNAME "faith" - struct faith_softc { struct ifnet *sc_ifp; }; @@ -95,12 +93,12 @@ static int faithprefix(struct in6_addr *); static int faithmodevent(module_t, int, void *); -static MALLOC_DEFINE(M_FAITH, FAITHNAME, "Firewall Assisted Tunnel Interface"); +static const char faithname[] = "faith"; +static MALLOC_DEFINE(M_FAITH, faithname, "Firewall Assisted Tunnel Interface"); static int faith_clone_create(struct if_clone *, int, caddr_t); static void faith_clone_destroy(struct ifnet *); - -IFC_SIMPLE_DECLARE(faith, 0); +static struct if_clone *faith_cloner; #define FAITHMTU 1500 @@ -113,8 +111,8 @@ faithmodevent(mod, type, data) switch (type) { case MOD_LOAD: - if_clone_attach(&faith_cloner); - + faith_cloner = if_clone_simple(faithname, faith_clone_create, + faith_clone_destroy, 0); #ifdef INET6 faithprefix_p = faithprefix; #endif @@ -125,7 +123,7 @@ faithmodevent(mod, type, data) faithprefix_p = NULL; #endif - if_clone_detach(&faith_cloner); + if_clone_detach(faith_cloner); break; default: return EOPNOTSUPP; @@ -159,7 +157,7 @@ faith_clone_create(ifc, unit, params) } ifp->if_softc = sc; - if_initname(sc->sc_ifp, ifc->ifc_name, unit); + if_initname(sc->sc_ifp, faithname, unit); ifp->if_mtu = FAITHMTU; /* Change to BROADCAST experimentaly to announce its prefix. */ diff --git a/sys/net/if_gif.c b/sys/net/if_gif.c index 783607b..9fef6c7 100644 --- a/sys/net/if_gif.c +++ b/sys/net/if_gif.c @@ -88,7 +88,7 @@ #include <security/mac/mac_framework.h> -#define GIFNAME "gif" +static const char gifname[] = "gif"; /* * gif_mtx protects the global gif_softc_list. @@ -106,8 +106,7 @@ void (*ng_gif_detach_p)(struct ifnet *ifp); static void gif_start(struct ifnet *); static int gif_clone_create(struct if_clone *, int, caddr_t); static void gif_clone_destroy(struct ifnet *); - -IFC_SIMPLE_DECLARE(gif, 0); +static struct if_clone *gif_cloner; static int gifmodevent(module_t, int, void *); @@ -171,7 +170,7 @@ gif_clone_create(ifc, unit, params) GIF_LOCK_INIT(sc); GIF2IFP(sc)->if_softc = sc; - if_initname(GIF2IFP(sc), ifc->ifc_name, unit); + if_initname(GIF2IFP(sc), gifname, unit); sc->encap_cookie4 = sc->encap_cookie6 = NULL; sc->gif_options = GIF_ACCEPT_REVETHIP; @@ -256,11 +255,12 @@ gifmodevent(mod, type, data) switch (type) { case MOD_LOAD: mtx_init(&gif_mtx, "gif_mtx", NULL, MTX_DEF); - if_clone_attach(&gif_cloner); + gif_cloner = if_clone_simple(gifname, gif_clone_create, + gif_clone_destroy, 0); break; case MOD_UNLOAD: - if_clone_detach(&gif_cloner); + if_clone_detach(gif_cloner); mtx_destroy(&gif_mtx); break; default: diff --git a/sys/net/if_gre.c b/sys/net/if_gre.c index 8b250d7..59e1a2a 100644 --- a/sys/net/if_gre.c +++ b/sys/net/if_gre.c @@ -90,8 +90,6 @@ */ #define GREMTU 1476 -#define GRENAME "gre" - #define MTAG_COOKIE_GRE 1307983903 #define MTAG_GRE_NESTING 1 struct mtag_gre_nesting { @@ -105,18 +103,19 @@ struct mtag_gre_nesting { * XXX: gre_softc data not protected yet. */ struct mtx gre_mtx; -static MALLOC_DEFINE(M_GRE, GRENAME, "Generic Routing Encapsulation"); +static const char grename[] = "gre"; +static MALLOC_DEFINE(M_GRE, grename, "Generic Routing Encapsulation"); struct gre_softc_head gre_softc_list; static int gre_clone_create(struct if_clone *, int, caddr_t); static void gre_clone_destroy(struct ifnet *); +static struct if_clone *gre_cloner; + static int gre_ioctl(struct ifnet *, u_long, caddr_t); static int gre_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct route *ro); -IFC_SIMPLE_DECLARE(gre, 0); - static int gre_compute_route(struct gre_softc *sc); static void greattach(void); @@ -172,7 +171,8 @@ greattach(void) mtx_init(&gre_mtx, "gre_mtx", NULL, MTX_DEF); LIST_INIT(&gre_softc_list); - if_clone_attach(&gre_cloner); + gre_cloner = if_clone_simple(grename, gre_clone_create, + gre_clone_destroy, 0); } static int @@ -192,7 +192,7 @@ gre_clone_create(ifc, unit, params) } GRE2IFP(sc)->if_softc = sc; - if_initname(GRE2IFP(sc), ifc->ifc_name, unit); + if_initname(GRE2IFP(sc), grename, unit); GRE2IFP(sc)->if_snd.ifq_maxlen = ifqmaxlen; GRE2IFP(sc)->if_addrlen = 0; @@ -961,7 +961,7 @@ gremodevent(module_t mod, int type, void *data) greattach(); break; case MOD_UNLOAD: - if_clone_detach(&gre_cloner); + if_clone_detach(gre_cloner); mtx_destroy(&gre_mtx); break; default: diff --git a/sys/net/if_lagg.c b/sys/net/if_lagg.c index e567e8e..b8fe05b 100644 --- a/sys/net/if_lagg.c +++ b/sys/net/if_lagg.c @@ -85,6 +85,9 @@ eventhandler_tag lagg_detach_cookie = NULL; static int lagg_clone_create(struct if_clone *, int, caddr_t); static void lagg_clone_destroy(struct ifnet *); +static struct if_clone *lagg_cloner; +static const char laggname[] = "lagg"; + static void lagg_lladdr(struct lagg_softc *, uint8_t *); static void lagg_capabilities(struct lagg_softc *); static void lagg_port_lladdr(struct lagg_port *, uint8_t *); @@ -118,8 +121,6 @@ static struct lagg_port *lagg_link_active(struct lagg_softc *, struct lagg_port *); static const void *lagg_gethdr(struct mbuf *, u_int, u_int, void *); -IFC_SIMPLE_DECLARE(lagg, 0); - /* Simple round robin */ static int lagg_rr_attach(struct lagg_softc *); static int lagg_rr_detach(struct lagg_softc *); @@ -187,7 +188,8 @@ lagg_modevent(module_t mod, int type, void *data) case MOD_LOAD: mtx_init(&lagg_list_mtx, "if_lagg list", NULL, MTX_DEF); SLIST_INIT(&lagg_list); - if_clone_attach(&lagg_cloner); + lagg_cloner = if_clone_simple(laggname, lagg_clone_create, + lagg_clone_destroy, 0); lagg_input_p = lagg_input; lagg_linkstate_p = lagg_port_state; lagg_detach_cookie = EVENTHANDLER_REGISTER( @@ -197,7 +199,7 @@ lagg_modevent(module_t mod, int type, void *data) case MOD_UNLOAD: EVENTHANDLER_DEREGISTER(ifnet_departure_event, lagg_detach_cookie); - if_clone_detach(&lagg_cloner); + if_clone_detach(lagg_cloner); lagg_input_p = NULL; lagg_linkstate_p = NULL; mtx_destroy(&lagg_list_mtx); @@ -311,7 +313,7 @@ lagg_clone_create(struct if_clone *ifc, int unit, caddr_t params) ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL); ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO); - if_initname(ifp, ifc->ifc_name, unit); + if_initname(ifp, laggname, unit); ifp->if_softc = sc; ifp->if_transmit = lagg_transmit; ifp->if_qflush = lagg_qflush; diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index 2850b38..acf8012 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -108,13 +108,12 @@ static void lo_clone_destroy(struct ifnet *); VNET_DEFINE(struct ifnet *, loif); /* Used externally */ #ifdef VIMAGE -static VNET_DEFINE(struct ifc_simple_data, lo_cloner_data); -static VNET_DEFINE(struct if_clone, lo_cloner); -#define V_lo_cloner_data VNET(lo_cloner_data) +static VNET_DEFINE(struct if_clone *, lo_cloner); #define V_lo_cloner VNET(lo_cloner) #endif -IFC_SIMPLE_DECLARE(lo, 1); +static struct if_clone *lo_cloner; +static const char loname[] = "lo"; static void lo_clone_destroy(struct ifnet *ifp) @@ -139,7 +138,7 @@ lo_clone_create(struct if_clone *ifc, int unit, caddr_t params) if (ifp == NULL) return (ENOSPC); - if_initname(ifp, ifc->ifc_name, unit); + if_initname(ifp, loname, unit); ifp->if_mtu = LOMTU; ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; ifp->if_ioctl = loioctl; @@ -161,12 +160,12 @@ vnet_loif_init(const void *unused __unused) { #ifdef VIMAGE + lo_cloner = if_clone_simple(loname, lo_clone_create, lo_clone_destroy, + 1); V_lo_cloner = lo_cloner; - V_lo_cloner_data = lo_cloner_data; - V_lo_cloner.ifc_data = &V_lo_cloner_data; - if_clone_attach(&V_lo_cloner); #else - if_clone_attach(&lo_cloner); + lo_cloner = if_clone_simple(loname, lo_clone_create, lo_clone_destroy, + 1); #endif } VNET_SYSINIT(vnet_loif_init, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY, @@ -177,7 +176,7 @@ static void vnet_loif_uninit(const void *unused __unused) { - if_clone_detach(&V_lo_cloner); + if_clone_detach(V_lo_cloner); V_loif = NULL; } VNET_SYSUNINIT(vnet_loif_uninit, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY, diff --git a/sys/net/if_stf.c b/sys/net/if_stf.c index b19c855..90dac40 100644 --- a/sys/net/if_stf.c +++ b/sys/net/if_stf.c @@ -127,7 +127,6 @@ static int stf_route_cache = 1; SYSCTL_INT(_net_link_stf, OID_AUTO, route_cache, CTLFLAG_RW, &stf_route_cache, 0, "Caching of IPv4 routes for 6to4 Output"); -#define STFNAME "stf" #define STFUNIT 0 #define IN6_IS_ADDR_6TO4(x) (ntohs((x)->s6_addr16[0]) == 0x2002) @@ -151,11 +150,13 @@ struct stf_softc { }; #define STF2IFP(sc) ((sc)->sc_ifp) +static const char stfname[] = "stf"; + /* * Note that mutable fields in the softc are not currently locked. * We do lock sc_ro in stf_output though. */ -static MALLOC_DEFINE(M_STF, STFNAME, "6to4 Tunnel Interface"); +static MALLOC_DEFINE(M_STF, stfname, "6to4 Tunnel Interface"); static const int ip_stf_ttl = 40; extern struct domain inetdomain; @@ -188,8 +189,7 @@ static int stf_ioctl(struct ifnet *, u_long, caddr_t); static int stf_clone_match(struct if_clone *, const char *); static int stf_clone_create(struct if_clone *, char *, size_t, caddr_t); static int stf_clone_destroy(struct if_clone *, struct ifnet *); -struct if_clone stf_cloner = IFC_CLONE_INITIALIZER(STFNAME, NULL, 0, - NULL, stf_clone_match, stf_clone_create, stf_clone_destroy); +static struct if_clone *stf_cloner; static int stf_clone_match(struct if_clone *ifc, const char *name) @@ -236,7 +236,7 @@ stf_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) * we don't conform to the default naming convention for interfaces. */ strlcpy(ifp->if_xname, name, IFNAMSIZ); - ifp->if_dname = ifc->ifc_name; + ifp->if_dname = stfname; ifp->if_dunit = IF_DUNIT_NONE; mtx_init(&(sc)->sc_ro_mtx, "stf ro", NULL, MTX_DEF); @@ -286,10 +286,11 @@ stfmodevent(mod, type, data) switch (type) { case MOD_LOAD: - if_clone_attach(&stf_cloner); + stf_cloner = if_clone_advanced(stfname, 0, stf_clone_match, + stf_clone_create, stf_clone_destroy); break; case MOD_UNLOAD: - if_clone_detach(&stf_cloner); + if_clone_detach(stf_cloner); break; default: return (EOPNOTSUPP); diff --git a/sys/net/if_tap.c b/sys/net/if_tap.c index d4ea9c5..d6cd259 100644 --- a/sys/net/if_tap.c +++ b/sys/net/if_tap.c @@ -79,8 +79,8 @@ #define CDEV_NAME "tap" #define TAPDEBUG if (tapdebug) printf -#define TAP "tap" -#define VMNET "vmnet" +static const char tapname[] = "tap"; +static const char vmnetname[] = "vmnet"; #define TAPMAXUNIT 0x7fff #define VMNET_DEV_MASK CLONE_FLAG0 @@ -99,11 +99,10 @@ static void tapifinit(void *); static int tap_clone_create(struct if_clone *, int, caddr_t); static void tap_clone_destroy(struct ifnet *); +static struct if_clone *tap_cloner; static int vmnet_clone_create(struct if_clone *, int, caddr_t); static void vmnet_clone_destroy(struct ifnet *); - -IFC_SIMPLE_DECLARE(tap, 0); -IFC_SIMPLE_DECLARE(vmnet, 0); +static struct if_clone *vmnet_cloner; /* character device */ static d_open_t tapopen; @@ -183,18 +182,12 @@ tap_clone_create(struct if_clone *ifc, int unit, caddr_t params) { struct cdev *dev; int i; - int extra; - - if (strcmp(ifc->ifc_name, VMNET) == 0) - extra = VMNET_DEV_MASK; - else - extra = 0; - /* find any existing device, or allocate new unit number */ - i = clone_create(&tapclones, &tap_cdevsw, &unit, &dev, extra); + /* Find any existing device, or allocate new unit number. */ + i = clone_create(&tapclones, &tap_cdevsw, &unit, &dev, 0); if (i) { - dev = make_dev(&tap_cdevsw, unit | extra, - UID_ROOT, GID_WHEEL, 0600, "%s%d", ifc->ifc_name, unit); + dev = make_dev(&tap_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, + "%s%d", tapname, unit); } tapcreate(dev); @@ -205,7 +198,18 @@ tap_clone_create(struct if_clone *ifc, int unit, caddr_t params) static int vmnet_clone_create(struct if_clone *ifc, int unit, caddr_t params) { - return tap_clone_create(ifc, unit, params); + struct cdev *dev; + int i; + + /* Find any existing device, or allocate new unit number. */ + i = clone_create(&tapclones, &tap_cdevsw, &unit, &dev, VMNET_DEV_MASK); + if (i) { + dev = make_dev(&tap_cdevsw, unit | VMNET_DEV_MASK, UID_ROOT, + GID_WHEEL, 0600, "%s%d", tapname, unit); + } + + tapcreate(dev); + return (0); } static void @@ -270,8 +274,10 @@ tapmodevent(module_t mod, int type, void *data) mtx_destroy(&tapmtx); return (ENOMEM); } - if_clone_attach(&tap_cloner); - if_clone_attach(&vmnet_cloner); + tap_cloner = if_clone_simple(tapname, tap_clone_create, + tap_clone_destroy, 0); + vmnet_cloner = if_clone_simple(vmnetname, vmnet_clone_create, + vmnet_clone_destroy, 0); return (0); case MOD_UNLOAD: @@ -293,8 +299,8 @@ tapmodevent(module_t mod, int type, void *data) mtx_unlock(&tapmtx); EVENTHANDLER_DEREGISTER(dev_clone, eh_tag); - if_clone_detach(&tap_cloner); - if_clone_detach(&vmnet_cloner); + if_clone_detach(tap_cloner); + if_clone_detach(vmnet_cloner); drain_dev_clone_events(); mtx_lock(&tapmtx); @@ -348,13 +354,13 @@ tapclone(void *arg, struct ucred *cred, char *name, int namelen, struct cdev **d extra = 0; /* We're interested in only tap/vmnet devices. */ - if (strcmp(name, TAP) == 0) { + if (strcmp(name, tapname) == 0) { unit = -1; - } else if (strcmp(name, VMNET) == 0) { + } else if (strcmp(name, vmnetname) == 0) { unit = -1; extra = VMNET_DEV_MASK; - } else if (dev_stdclone(name, NULL, TAP, &unit) != 1) { - if (dev_stdclone(name, NULL, VMNET, &unit) != 1) { + } else if (dev_stdclone(name, NULL, tapname, &unit) != 1) { + if (dev_stdclone(name, NULL, vmnetname, &unit) != 1) { return; } else { extra = VMNET_DEV_MASK; @@ -400,7 +406,7 @@ tapcreate(struct cdev *dev) unsigned short macaddr_hi; uint32_t macaddr_mid; int unit; - char *name = NULL; + const char *name = NULL; u_char eaddr[6]; dev->si_flags &= ~SI_CHEAPCLONE; @@ -416,10 +422,10 @@ tapcreate(struct cdev *dev) /* select device: tap or vmnet */ if (unit & VMNET_DEV_MASK) { - name = VMNET; + name = vmnetname; tp->tap_flags |= TAP_VMNET; } else - name = TAP; + name = tapname; unit &= TAPMAXUNIT; diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 74e1d22..086a3c1 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -99,7 +99,6 @@ struct tun_softc { #define TUN2IFP(sc) ((sc)->tun_ifp) #define TUNDEBUG if (tundebug) if_printf -#define TUNNAME "tun" /* * All mutable global variables in if_tun are locked using tunmtx, with @@ -107,7 +106,8 @@ struct tun_softc { * which is static after setup. */ static struct mtx tunmtx; -static MALLOC_DEFINE(M_TUN, TUNNAME, "Tunnel Interface"); +static const char tunname[] = "tun"; +static MALLOC_DEFINE(M_TUN, tunname, "Tunnel Interface"); static int tundebug = 0; static int tundclone = 1; static struct clonedevs *tunclones; @@ -134,8 +134,7 @@ static void tunstart(struct ifnet *); static int tun_clone_create(struct if_clone *, int, caddr_t); static void tun_clone_destroy(struct ifnet *); - -IFC_SIMPLE_DECLARE(tun, 0); +static struct if_clone *tun_cloner; static d_open_t tunopen; static d_close_t tunclose; @@ -173,7 +172,7 @@ static struct cdevsw tun_cdevsw = { .d_ioctl = tunioctl, .d_poll = tunpoll, .d_kqfilter = tunkqfilter, - .d_name = TUNNAME, + .d_name = tunname, }; static int @@ -187,9 +186,9 @@ tun_clone_create(struct if_clone *ifc, int unit, caddr_t params) if (i) { /* No preexisting struct cdev *, create one */ dev = make_dev(&tun_cdevsw, unit, - UID_UUCP, GID_DIALER, 0600, "%s%d", ifc->ifc_name, unit); + UID_UUCP, GID_DIALER, 0600, "%s%d", tunname, unit); } - tuncreate(ifc->ifc_name, dev); + tuncreate(tunname, dev); return (0); } @@ -211,9 +210,9 @@ tunclone(void *arg, struct ucred *cred, char *name, int namelen, if (!tundclone || priv_check_cred(cred, PRIV_NET_IFCREATE, 0) != 0) return; - if (strcmp(name, TUNNAME) == 0) { + if (strcmp(name, tunname) == 0) { u = -1; - } else if (dev_stdclone(name, NULL, TUNNAME, &u) != 1) + } else if (dev_stdclone(name, NULL, tunname, &u) != 1) return; /* Don't recognise the name */ if (u != -1 && u > IF_MAXUNIT) return; /* Unit number too high */ @@ -290,10 +289,11 @@ tunmodevent(module_t mod, int type, void *data) tag = EVENTHANDLER_REGISTER(dev_clone, tunclone, 0, 1000); if (tag == NULL) return (ENOMEM); - if_clone_attach(&tun_cloner); + tun_cloner = if_clone_simple(tunname, tun_clone_create, + tun_clone_destroy, 0); break; case MOD_UNLOAD: - if_clone_detach(&tun_cloner); + if_clone_detach(tun_cloner); EVENTHANDLER_DEREGISTER(dev_clone, tag); drain_dev_clone_events(); @@ -408,7 +408,7 @@ tunopen(struct cdev *dev, int flag, int mode, struct thread *td) */ tp = dev->si_drv1; if (!tp) { - tuncreate(TUNNAME, dev); + tuncreate(tunname, dev); tp = dev->si_drv1; } diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index 3bc3b67..379a59b 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -66,7 +66,6 @@ __FBSDID("$FreeBSD$"); #include <net/if_vlan_var.h> #include <net/vnet.h> -#define VLANNAME "vlan" #define VLAN_DEF_HWIDTH 4 #define VLAN_IFFLAGS (IFF_BROADCAST | IFF_MULTICAST) @@ -139,7 +138,8 @@ static int soft_pad = 0; SYSCTL_INT(_net_link_vlan, OID_AUTO, soft_pad, CTLFLAG_RW, &soft_pad, 0, "pad short frames before tagging"); -static MALLOC_DEFINE(M_VLAN, VLANNAME, "802.1Q Virtual LAN Interface"); +static const char vlanname[] = "vlan"; +static MALLOC_DEFINE(M_VLAN, vlanname, "802.1Q Virtual LAN Interface"); static eventhandler_tag ifdetach_tag; static eventhandler_tag iflladdr_tag; @@ -162,7 +162,7 @@ static struct sx ifv_lock; #define VLAN_LOCK_ASSERT() sx_assert(&ifv_lock, SA_LOCKED) #define VLAN_LOCK() sx_xlock(&ifv_lock) #define VLAN_UNLOCK() sx_xunlock(&ifv_lock) -#define TRUNK_LOCK_INIT(trunk) rw_init(&(trunk)->rw, VLANNAME) +#define TRUNK_LOCK_INIT(trunk) rw_init(&(trunk)->rw, vlanname) #define TRUNK_LOCK_DESTROY(trunk) rw_destroy(&(trunk)->rw) #define TRUNK_LOCK(trunk) rw_wlock(&(trunk)->rw) #define TRUNK_UNLOCK(trunk) rw_wunlock(&(trunk)->rw) @@ -207,11 +207,10 @@ static int vlan_clone_destroy(struct if_clone *, struct ifnet *); static void vlan_ifdetach(void *arg, struct ifnet *ifp); static void vlan_iflladdr(void *arg, struct ifnet *ifp); -static struct if_clone vlan_cloner = IFC_CLONE_INITIALIZER(VLANNAME, NULL, - IF_MAXUNIT, NULL, vlan_clone_match, vlan_clone_create, vlan_clone_destroy); +static struct if_clone *vlan_cloner; #ifdef VIMAGE -static VNET_DEFINE(struct if_clone, vlan_cloner); +static VNET_DEFINE(struct if_clone *, vlan_cloner); #define V_vlan_cloner VNET(vlan_cloner) #endif @@ -723,7 +722,8 @@ vlan_modevent(module_t mod, int type, void *data) vlan_tag_p = vlan_tag; vlan_devat_p = vlan_devat; #ifndef VIMAGE - if_clone_attach(&vlan_cloner); + vlan_cloner = if_clone_advanced(vlanname, 0, vlan_clone_match, + vlan_clone_create, vlan_clone_destroy); #endif if (bootverbose) printf("vlan: initialized, using " @@ -737,7 +737,7 @@ vlan_modevent(module_t mod, int type, void *data) break; case MOD_UNLOAD: #ifndef VIMAGE - if_clone_detach(&vlan_cloner); + if_clone_detach(vlan_cloner); #endif EVENTHANDLER_DEREGISTER(ifnet_departure_event, ifdetach_tag); EVENTHANDLER_DEREGISTER(iflladdr_event, iflladdr_tag); @@ -773,8 +773,9 @@ static void vnet_vlan_init(const void *unused __unused) { + vlan_cloner = if_clone_advanced(vlanname, 0, vlan_clone_match, + vlan_clone_create, vlan_clone_destroy); V_vlan_cloner = vlan_cloner; - if_clone_attach(&V_vlan_cloner); } VNET_SYSINIT(vnet_vlan_init, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY, vnet_vlan_init, NULL); @@ -783,7 +784,7 @@ static void vnet_vlan_uninit(const void *unused __unused) { - if_clone_detach(&V_vlan_cloner); + if_clone_detach(V_vlan_cloner); } VNET_SYSUNINIT(vnet_vlan_uninit, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_FIRST, vnet_vlan_uninit, NULL); @@ -835,7 +836,7 @@ vlan_clone_match(struct if_clone *ifc, const char *name) if (vlan_clone_match_ethervid(ifc, name, NULL) != NULL) return (1); - if (strncmp(VLANNAME, name, strlen(VLANNAME)) != 0) + if (strncmp(vlanname, name, strlen(vlanname)) != 0) return (0); for (cp = name + 4; *cp != '\0'; cp++) { if (*cp < '0' || *cp > '9') @@ -943,7 +944,7 @@ vlan_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) * we don't conform to the default naming convention for interfaces. */ strlcpy(ifp->if_xname, name, IFNAMSIZ); - ifp->if_dname = ifc->ifc_name; + ifp->if_dname = vlanname; ifp->if_dunit = unit; /* NB: flags are not set here */ ifp->if_linkmib = &ifv->ifv_mib; |