From b7b982e2fe2a281ccbae6b6469160e979a6a59e8 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 30 Dec 2003 03:56:04 +0000 Subject: [PATCH] Bump the network interface cloning API to what is in 5.x with the following nice additions: 1) All if_unit allocations are handled in the cloner common case removing a lot of (repetitive) code from callers as well as the rman.h dependency. 2) Initial device instances are created when the cloner is attached. Submitted-by: Max Laier Testing-by: David Rhodus --- sys/net/faith/if_faith.c | 61 +++------------------------- sys/net/gif/if_gif.c | 53 +++---------------------- sys/net/gre/if_gre.c | 54 +++---------------------- sys/net/if.c | 85 +++++++++++++++++++++++++++++++++++++--- sys/net/if.h | 13 ++++-- sys/net/vlan/if_vlan.c | 58 +++------------------------ 6 files changed, 113 insertions(+), 211 deletions(-) diff --git a/sys/net/faith/if_faith.c b/sys/net/faith/if_faith.c index b637a339a9..3fc88a3eef 100644 --- a/sys/net/faith/if_faith.c +++ b/sys/net/faith/if_faith.c @@ -33,7 +33,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_faith.c,v 1.3.2.6 2002/04/28 05:40:25 suz Exp $ - * $DragonFly: src/sys/net/faith/if_faith.c,v 1.5 2003/09/15 23:38:13 hsu Exp $ + * $DragonFly: src/sys/net/faith/if_faith.c,v 1.6 2003/12/30 03:56:01 dillon Exp $ */ /* * derived from @@ -62,7 +62,6 @@ #include #include #include /* XXX: Shouldn't really be required! */ -#include #include #include @@ -89,11 +88,9 @@ #include #define FAITHNAME "faith" -#define FAITH_MAXUNIT 0x7fff /* ifp->if_unit is only 15 bits */ struct faith_softc { struct ifnet sc_if; /* must be first */ - struct resource *r_unit; LIST_ENTRY(faith_softc) sc_list; }; @@ -106,14 +103,13 @@ static int faithprefix (struct in6_addr *); static int faithmodevent (module_t, int, void *); static MALLOC_DEFINE(M_FAITH, FAITHNAME, "Firewall Assisted Tunnel Interface"); -static struct rman faithunits[1]; LIST_HEAD(, faith_softc) faith_softc_list; -int faith_clone_create (struct if_clone *, int *); +int faith_clone_create (struct if_clone *, int); void faith_clone_destroy (struct ifnet *); -struct if_clone faith_cloner = - IF_CLONE_INITIALIZER(FAITHNAME, faith_clone_create, faith_clone_destroy); +struct if_clone faith_cloner = IF_CLONE_INITIALIZER(FAITHNAME, + faith_clone_create, faith_clone_destroy, NFAITH, IF_MAXUNIT); #define FAITHMTU 1500 @@ -123,30 +119,11 @@ faithmodevent(mod, type, data) int type; void *data; { - int i; - int err; switch (type) { case MOD_LOAD: - faithunits->rm_type = RMAN_ARRAY; - faithunits->rm_descr = "configurable if_faith units"; - err = rman_init(faithunits); - if (err != 0) - return (err); - err = rman_manage_region(faithunits, 0, FAITH_MAXUNIT); - if (err != 0) { - printf("%s: faithunits: rman_manage_region: " - "Failed %d\n", FAITHNAME, err); - rman_fini(faithunits); - return (err); - } LIST_INIT(&faith_softc_list); if_clone_attach(&faith_cloner); - for(i = 0; i < NFAITH; i ++) { - err = faith_clone_create(&faith_cloner, &i); - KASSERT(err == 0, - ("Error creating initial faith interfaces")); - } #ifdef INET6 faithprefix_p = faithprefix; @@ -164,10 +141,6 @@ faithmodevent(mod, type, data) faith_clone_destroy( &LIST_FIRST(&faith_softc_list)->sc_if); - err = rman_fini(faithunits); - if (err != 0) - return (err); - break; } return 0; @@ -185,34 +158,16 @@ MODULE_VERSION(if_faith, 1); int faith_clone_create(ifc, unit) struct if_clone *ifc; - int *unit; + int unit; { - struct resource *r; struct faith_softc *sc; - if (*unit > FAITH_MAXUNIT) - return (ENXIO); - - if (*unit < 0) { - r = rman_reserve_resource(faithunits, 0, FAITH_MAXUNIT, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (ENOSPC); - *unit = rman_get_start(r); - } else { - r = rman_reserve_resource(faithunits, *unit, *unit, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (ENOSPC); - } - sc = malloc(sizeof(struct faith_softc), M_FAITH, M_WAITOK); bzero(sc, sizeof(struct faith_softc)); sc->sc_if.if_softc = sc; sc->sc_if.if_name = FAITHNAME; - sc->sc_if.if_unit = *unit; - sc->r_unit = r; + sc->sc_if.if_unit = unit; sc->sc_if.if_mtu = FAITHMTU; /* Change to BROADCAST experimentaly to announce its prefix. */ @@ -233,16 +188,12 @@ void faith_clone_destroy(ifp) struct ifnet *ifp; { - int err; struct faith_softc *sc = (void *) ifp; LIST_REMOVE(sc, sc_list); bpfdetach(ifp); if_detach(ifp); - err = rman_release_resource(sc->r_unit); - KASSERT(err == 0, ("Unexpected error freeing resource")); - free(sc, M_FAITH); } diff --git a/sys/net/gif/if_gif.c b/sys/net/gif/if_gif.c index 47d4410ccc..dc4a6d990f 100644 --- a/sys/net/gif/if_gif.c +++ b/sys/net/gif/if_gif.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/net/if_gif.c,v 1.4.2.15 2002/11/08 16:57:13 ume Exp $ */ -/* $DragonFly: src/sys/net/gif/if_gif.c,v 1.6 2003/09/15 23:38:13 hsu Exp $ */ +/* $DragonFly: src/sys/net/gif/if_gif.c,v 1.7 2003/12/30 03:56:02 dillon Exp $ */ /* $KAME: if_gif.c,v 1.87 2001/10/19 08:50:27 itojun Exp $ */ /* @@ -48,7 +48,6 @@ #include #include #include /* XXX: Shouldn't really be required! */ -#include #include #include @@ -84,18 +83,15 @@ #include #define GIFNAME "gif" -#define GIFDEV "if_gif" -#define GIF_MAXUNIT 0x7fff /* ifp->if_unit is only 15 bits */ static MALLOC_DEFINE(M_GIF, "gif", "Generic Tunnel Interface"); -static struct rman gifunits[1]; LIST_HEAD(, gif_softc) gif_softc_list; -int gif_clone_create (struct if_clone *, int *); +int gif_clone_create (struct if_clone *, int); void gif_clone_destroy (struct ifnet *); -struct if_clone gif_cloner = - IF_CLONE_INITIALIZER("gif", gif_clone_create, gif_clone_destroy); +struct if_clone gif_cloner = IF_CLONE_INITIALIZER("gif", gif_clone_create, + gif_clone_destroy, 0, IF_MAXUNIT); static int gifmodevent (module_t, int, void *); @@ -133,34 +129,16 @@ SYSCTL_INT(_net_link_gif, OID_AUTO, parallel_tunnels, CTLFLAG_RW, int gif_clone_create(ifc, unit) struct if_clone *ifc; - int *unit; + int unit; { - struct resource *r; struct gif_softc *sc; - - if (*unit > GIF_MAXUNIT) - return (ENXIO); - - if (*unit < 0) { - r = rman_reserve_resource(gifunits, 0, GIF_MAXUNIT, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (ENOSPC); - *unit = rman_get_start(r); - } else { - r = rman_reserve_resource(gifunits, *unit, *unit, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (EEXIST); - } sc = malloc (sizeof(struct gif_softc), M_GIF, M_WAITOK); bzero(sc, sizeof(struct gif_softc)); sc->gif_if.if_softc = sc; sc->gif_if.if_name = GIFNAME; - sc->gif_if.if_unit = *unit; - sc->r_unit = r; + sc->gif_if.if_unit = unit; gifattach0(sc); @@ -215,9 +193,6 @@ gif_clone_destroy(ifp) bpfdetach(ifp); if_detach(ifp); - err = rman_release_resource(sc->r_unit); - KASSERT(err == 0, ("Unexpected error freeing resource")); - free(sc, M_GIF); } @@ -227,22 +202,9 @@ gifmodevent(mod, type, data) int type; void *data; { - int err; switch (type) { case MOD_LOAD: - gifunits->rm_type = RMAN_ARRAY; - gifunits->rm_descr = "configurable if_gif units"; - err = rman_init(gifunits); - if (err != 0) - return (err); - err = rman_manage_region(gifunits, 0, GIF_MAXUNIT); - if (err != 0) { - printf("%s: gifunits: rman_manage_region: Failed %d\n", - GIFNAME, err); - rman_fini(gifunits); - return (err); - } LIST_INIT(&gif_softc_list); if_clone_attach(&gif_cloner); @@ -257,9 +219,6 @@ gifmodevent(mod, type, data) while (!LIST_EMPTY(&gif_softc_list)) gif_clone_destroy(&LIST_FIRST(&gif_softc_list)->gif_if); - err = rman_fini(gifunits); - if (err != 0) - return (err); #ifdef INET6 ip6_gif_hlim = 0; #endif diff --git a/sys/net/gre/if_gre.c b/sys/net/gre/if_gre.c index 43bc808647..6a38acc8cd 100644 --- a/sys/net/gre/if_gre.c +++ b/sys/net/gre/if_gre.c @@ -1,6 +1,6 @@ /* $NetBSD: if_gre.c,v 1.42 2002/08/14 00:23:27 itojun Exp $ */ /* $FreeBSD: src/sys/net/if_gre.c,v 1.9.2.3 2003/01/23 21:06:44 sam Exp $ */ -/* $DragonFly: src/sys/net/gre/if_gre.c,v 1.5 2003/08/07 21:17:24 dillon Exp $ */ +/* $DragonFly: src/sys/net/gre/if_gre.c,v 1.6 2003/12/30 03:56:03 dillon Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -58,7 +58,6 @@ #include #include #include -#include #include #include #include @@ -94,21 +93,19 @@ #define GREMTU 1476 #define GRENAME "gre" -#define GRE_MAXUNIT 0x7fff static MALLOC_DEFINE(M_GRE, GRENAME, "Generic Routing Encapsulation"); -static struct rman greunits[1]; struct gre_softc_head gre_softc_list; -static int gre_clone_create(struct if_clone *, int *); +static int gre_clone_create(struct if_clone *, int); static void gre_clone_destroy(struct ifnet *); static int gre_ioctl(struct ifnet *, u_long, caddr_t); static int gre_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *rt); -static struct if_clone gre_cloner = - IF_CLONE_INITIALIZER("gre", gre_clone_create, gre_clone_destroy); +static struct if_clone gre_cloner = IF_CLONE_INITIALIZER("gre", + gre_clone_create, gre_clone_destroy, 0, IF_MAXUNIT); static int gre_compute_route(struct gre_softc *sc); @@ -162,33 +159,16 @@ greattach(void) static int gre_clone_create(ifc, unit) struct if_clone *ifc; - int *unit; + int unit; { - struct resource *r; struct gre_softc *sc; - if (*unit > GRE_MAXUNIT) - return (ENXIO); - - if (*unit < 0) { - r = rman_reserve_resource(greunits, 0, GRE_MAXUNIT, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (ENOSPC); - *unit = rman_get_start(r); - } else { - r = rman_reserve_resource(greunits, *unit, *unit, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (EEXIST); - } - sc = malloc(sizeof(struct gre_softc), M_GRE, M_WAITOK); memset(sc, 0, sizeof(struct gre_softc)); sc->sc_if.if_name = GRENAME; sc->sc_if.if_softc = sc; - sc->sc_if.if_unit = *unit; + sc->sc_if.if_unit = unit; sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN; sc->sc_if.if_type = IFT_OTHER; sc->sc_if.if_addrlen = 0; @@ -202,7 +182,6 @@ gre_clone_create(ifc, unit) sc->sc_if.if_flags |= IFF_LINK0; sc->encap = NULL; sc->called = 0; - sc->r_unit = r; if_attach(&sc->sc_if); bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t)); LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list); @@ -213,7 +192,6 @@ static void gre_clone_destroy(ifp) struct ifnet *ifp; { - int err; struct gre_softc *sc = ifp->if_softc; #ifdef INET @@ -224,9 +202,6 @@ gre_clone_destroy(ifp) bpfdetach(ifp); if_detach(ifp); - err = rman_release_resource(sc->r_unit); - KASSERT(err == 0, ("Unexpected error freeing resource")); - free(sc, M_GRE); } @@ -761,22 +736,9 @@ gre_in_cksum(u_short *p, u_int len) static int gremodevent(module_t mod, int type, void *data) { - int err; switch (type) { case MOD_LOAD: - greunits->rm_type = RMAN_ARRAY; - greunits->rm_descr = "configurable if_gre units"; - err = rman_init(greunits); - if (err != 0) - return (err); - err = rman_manage_region(greunits, 0, GRE_MAXUNIT); - if (err != 0) { - printf("%s: greunits: rman_manage_region: Failed %d\n", - GRENAME, err); - rman_fini(greunits); - return (err); - } greattach(); break; case MOD_UNLOAD: @@ -785,10 +747,6 @@ gremodevent(module_t mod, int type, void *data) while (!LIST_EMPTY(&gre_softc_list)) gre_clone_destroy(&LIST_FIRST(&gre_softc_list)->sc_if); - err = rman_fini(greunits); - if (err != 0) - return (err); - break; } return 0; diff --git a/sys/net/if.c b/sys/net/if.c index 0ca8c32ee4..4d717e3f3f 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -32,7 +32,7 @@ * * @(#)if.c 8.3 (Berkeley) 1/4/94 * $FreeBSD: src/sys/net/if.c,v 1.85.2.23 2003/04/15 18:11:19 fjoe Exp $ - * $DragonFly: src/sys/net/if.c,v 1.10 2003/12/30 01:01:48 dillon Exp $ + * $DragonFly: src/sys/net/if.c,v 1.11 2003/12/30 03:56:00 dillon Exp $ */ #include "opt_compat.h" @@ -92,6 +92,7 @@ SYSINIT(interfaces, SI_SUB_PROTO_IF, SI_ORDER_FIRST, ifinit, NULL) MALLOC_DEFINE(M_IFADDR, "ifaddr", "interface address"); MALLOC_DEFINE(M_IFMADDR, "ether_multi", "link-level multicast address"); +MALLOC_DEFINE(M_CLONE, "clone", "interface cloning framework"); int ifqmaxlen = IFQ_MAXLEN; struct ifnethead ifnet; /* depend on static init XXX */ @@ -374,7 +375,7 @@ if_clone_create(name, len) { struct if_clone *ifc; char *dp; - int wildcard; + int wildcard, bytoff, bitoff; int unit; int err; @@ -385,12 +386,41 @@ if_clone_create(name, len) if (ifunit(name) != NULL) return (EEXIST); + bytoff = bitoff = 0; wildcard = (unit < 0); + /* + * Find a free unit if none was given. + */ + if (wildcard) { + while ((bytoff < ifc->ifc_bmlen) + && (ifc->ifc_units[bytoff] == 0xff)) + bytoff++; + if (bytoff >= ifc->ifc_bmlen) + return (ENOSPC); + while ((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0) + bitoff++; + unit = (bytoff << 3) + bitoff; + } - err = (*ifc->ifc_create)(ifc, &unit); + if (unit > ifc->ifc_maxunit) + return (ENXIO); + + err = (*ifc->ifc_create)(ifc, unit); if (err != 0) return (err); + if (!wildcard) { + bytoff = unit >> 3; + bitoff = unit - (bytoff << 3); + } + + /* + * Allocate the unit in the bitmap. + */ + KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) == 0, + ("%s: bit is already set", __func__)); + ifc->ifc_units[bytoff] |= (1 << bitoff); + /* In the wildcard case, we need to update the name. */ if (wildcard) { for (dp = name; *dp != '\0'; dp++); @@ -403,7 +433,7 @@ if_clone_create(name, len) */ panic("if_clone_create(): interface name too long"); } - + } return (0); @@ -418,11 +448,16 @@ if_clone_destroy(name) { struct if_clone *ifc; struct ifnet *ifp; + int bytoff, bitoff; + int unit; - ifc = if_clone_lookup(name, NULL); + ifc = if_clone_lookup(name, &unit); if (ifc == NULL) return (EINVAL); + if (unit < ifc->ifc_minifs) + return (EINVAL); + ifp = ifunit(name); if (ifp == NULL) return (ENXIO); @@ -431,6 +466,15 @@ if_clone_destroy(name) return (EOPNOTSUPP); (*ifc->ifc_destroy)(ifp); + + /* + * Compute offset in the bitmap and deallocate the unit. + */ + bytoff = unit >> 3; + bitoff = unit - (bytoff << 3); + KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0, + ("%s: bit is already cleared", __func__)); + ifc->ifc_units[bytoff] &= ~(1 << bitoff); return (0); } @@ -484,9 +528,39 @@ void if_clone_attach(ifc) struct if_clone *ifc; { + int bytoff, bitoff; + int err; + int len, maxclone; + int unit; + + KASSERT(ifc->ifc_minifs - 1 <= ifc->ifc_maxunit, + ("%s: %s requested more units then allowed (%d > %d)", + __func__, ifc->ifc_name, ifc->ifc_minifs, + ifc->ifc_maxunit + 1)); + /* + * Compute bitmap size and allocate it. + */ + maxclone = ifc->ifc_maxunit + 1; + len = maxclone >> 3; + if ((len << 3) < maxclone) + len++; + ifc->ifc_units = malloc(len, M_CLONE, M_WAITOK | M_ZERO); + ifc->ifc_bmlen = len; LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list); if_cloners_count++; + + for (unit = 0; unit < ifc->ifc_minifs; unit++) { + err = (*ifc->ifc_create)(ifc, unit); + KASSERT(err == 0, + ("%s: failed to create required interface %s%d", + __func__, ifc->ifc_name, unit)); + + /* Allocate the unit in the bitmap. */ + bytoff = unit >> 3; + bitoff = unit - (bytoff << 3); + ifc->ifc_units[bytoff] |= (1 << bitoff); + } } /* @@ -498,6 +572,7 @@ if_clone_detach(ifc) { LIST_REMOVE(ifc, ifc_list); + free(ifc->ifc_units, M_CLONE); if_cloners_count--; } diff --git a/sys/net/if.h b/sys/net/if.h index af0dfe65bd..571a938c13 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -32,7 +32,7 @@ * * @(#)if.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if.h,v 1.58.2.9 2002/08/30 14:23:38 sobomax Exp $ - * $DragonFly: src/sys/net/if.h,v 1.7 2003/11/22 19:30:56 asmodai Exp $ + * $DragonFly: src/sys/net/if.h,v 1.8 2003/12/30 03:56:00 dillon Exp $ */ #ifndef _NET_IF_H_ @@ -58,6 +58,7 @@ struct ifnet; */ #define IFNAMSIZ 16 #define IF_NAMESIZE IFNAMSIZ +#define IF_MAXUNIT 0x7fff /* if_unit is 15bits */ #ifdef _KERNEL /* @@ -67,13 +68,17 @@ struct if_clone { LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */ const char *ifc_name; /* name of device, e.g. `gif' */ size_t ifc_namelen; /* length of name */ + int ifc_minifs; /* minimum number of interfaces */ + int ifc_maxunit; /* maximum unit number */ + unsigned char *ifc_units; /* bitmap to handle units */ + int ifc_bmlen; /* bitmap length */ - int (*ifc_create)(struct if_clone *, int *); + int (*ifc_create)(struct if_clone *, int); void (*ifc_destroy)(struct ifnet *); }; -#define IF_CLONE_INITIALIZER(name, create, destroy) \ - { { 0 }, name, sizeof(name) - 1, create, destroy } +#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) \ + { { 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy } #endif /* diff --git a/sys/net/vlan/if_vlan.c b/sys/net/vlan/if_vlan.c index 56c51bbba2..05e49361e0 100644 --- a/sys/net/vlan/if_vlan.c +++ b/sys/net/vlan/if_vlan.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_vlan.c,v 1.15.2.13 2003/02/14 22:25:58 fenner Exp $ - * $DragonFly: src/sys/net/vlan/if_vlan.c,v 1.4 2003/08/07 21:17:30 dillon Exp $ + * $DragonFly: src/sys/net/vlan/if_vlan.c,v 1.5 2003/12/30 03:56:04 dillon Exp $ */ /* @@ -71,7 +71,6 @@ #include #include #include /* XXX: Shouldn't really be required! */ -#include #include #include @@ -87,17 +86,15 @@ #endif #define VLANNAME "vlan" -#define VLAN_MAXUNIT 0x7fff /* ifp->if_unit is only 15 bits */ SYSCTL_DECL(_net_link); SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN"); SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency"); static MALLOC_DEFINE(M_VLAN, "vlan", "802.1Q Virtual LAN Interface"); -static struct rman vlanunits[1]; static LIST_HEAD(, ifvlan) ifv_list; -static int vlan_clone_create(struct if_clone *, int *); +static int vlan_clone_create(struct if_clone *, int); static void vlan_clone_destroy(struct ifnet *); static void vlan_start(struct ifnet *ifp); static void vlan_ifinit(void *foo); @@ -109,8 +106,8 @@ static int vlan_setmulti(struct ifnet *ifp); static int vlan_unconfig(struct ifnet *ifp); static int vlan_config(struct ifvlan *ifv, struct ifnet *p); -struct if_clone vlan_cloner = - IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy); +struct if_clone vlan_cloner = IF_CLONE_INITIALIZER("vlan", vlan_clone_create, + vlan_clone_destroy, NVLAN, IF_MAXUNIT); /* * Program our multicast filter. What we're actually doing is @@ -180,32 +177,13 @@ vlan_setmulti(struct ifnet *ifp) static int vlan_modevent(module_t mod, int type, void *data) { - int i; - int err; switch (type) { case MOD_LOAD: - vlanunits->rm_type = RMAN_ARRAY; - vlanunits->rm_descr = "configurable if_vlan units"; - err = rman_init(vlanunits); - if (err != 0) - return (err); - err = rman_manage_region(vlanunits, 0, VLAN_MAXUNIT); - if (err != 0) { - printf("%s: vlanunits: rman_manage_region: Failed %d\n", - VLANNAME, err); - rman_fini(vlanunits); - return (err); - } LIST_INIT(&ifv_list); vlan_input_p = vlan_input; vlan_input_tag_p = vlan_input_tag; if_clone_attach(&vlan_cloner); - for(i = 0; i < NVLAN; i ++) { - err = vlan_clone_create(&vlan_cloner, &i); - KASSERT(err == 0, - ("Unexpected error creating initial VLANs")); - } break; case MOD_UNLOAD: if_clone_detach(&vlan_cloner); @@ -213,9 +191,6 @@ vlan_modevent(module_t mod, int type, void *data) vlan_input_tag_p = NULL; while (!LIST_EMPTY(&ifv_list)) vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if); - err = rman_fini(vlanunits); - if (err != 0) - return (err); break; } return 0; @@ -230,29 +205,12 @@ static moduledata_t vlan_mod = { DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); static int -vlan_clone_create(struct if_clone *ifc, int *unit) +vlan_clone_create(struct if_clone *ifc, int unit) { - struct resource *r; struct ifvlan *ifv; struct ifnet *ifp; int s; - if (*unit > VLAN_MAXUNIT) - return (ENXIO); - - if (*unit < 0) { - r = rman_reserve_resource(vlanunits, 0, VLAN_MAXUNIT, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (ENOSPC); - *unit = rman_get_start(r); - } else { - r = rman_reserve_resource(vlanunits, *unit, *unit, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (EEXIST); - } - ifv = malloc(sizeof(struct ifvlan), M_VLAN, M_WAITOK); memset(ifv, 0, sizeof(struct ifvlan)); ifp = &ifv->ifv_if; @@ -264,8 +222,7 @@ vlan_clone_create(struct if_clone *ifc, int *unit) ifp->if_softc = ifv; ifp->if_name = "vlan"; - ifp->if_unit = *unit; - ifv->r_unit = r; + ifp->if_unit = unit; /* NB: flags are not set here */ ifp->if_linkmib = &ifv->ifv_mib; ifp->if_linkmiblen = sizeof ifv->ifv_mib; @@ -289,7 +246,6 @@ vlan_clone_destroy(struct ifnet *ifp) { struct ifvlan *ifv = ifp->if_softc; int s; - int err; s = splnet(); LIST_REMOVE(ifv, ifv_list); @@ -298,8 +254,6 @@ vlan_clone_destroy(struct ifnet *ifp) ether_ifdetach(ifp, ETHER_BPF_SUPPORTED); - err = rman_release_resource(ifv->r_unit); - KASSERT(err == 0, ("Unexpected error freeing resource")); free(ifv, M_VLAN); } -- 2.41.0