DragonFly BSD
DragonFly submit List (threaded) for 2003-12
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Network interface cloning (Step1: API UPDATE)


From: Max Laier <max@xxxxxxxxxxxxxx>
Date: Fri, 19 Dec 2003 19:04:08 +0100

attached patch bumps IF_CLONE... 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.

This updates all current callers of course: faith, gre, gif and vlan.

After this I'd make all pseudo devices cloning as well, slowly paving
the way to if_xname.

Comments? Hope I don't step on anyone's toe, but should not (IMO).

--
Best regards,				| max@xxxxxxxxxxxxxx
Max Laier				| ICQ #67774661
http://pf4freebsd.love2party.net/	| mlaier@EFnet #DragonFlyBSD
Index: net/if.c
===================================================================
RCS file: /root/.dfcvs/src/sys/net/if.c,v
retrieving revision 1.9
diff -u -r1.9 if.c
--- net/if.c	9 Nov 2003 02:22:36 -0000	1.9
+++ net/if.c	19 Dec 2003 16:15:20 -0000
@@ -92,6 +92,7 @@
 
 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 @@
 {
 	struct if_clone *ifc;
 	char *dp;
-	int wildcard;
+	int wildcard, bytoff, bitoff;
 	int unit;
 	int err;
 
@@ -385,12 +386,41 @@
 	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 @@
 			 */
 			panic("if_clone_create(): interface name too long");
 		}
-			
+
 	}
 
 	return (0);
@@ -418,11 +448,16 @@
 {
 	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 @@
 		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 @@
 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 @@
 {
 
 	LIST_REMOVE(ifc, ifc_list);
+	free(ifc->ifc_units, M_CLONE);
 	if_cloners_count--;
 }
 
Index: net/if.h
===================================================================
RCS file: /root/.dfcvs/src/sys/net/if.h,v
retrieving revision 1.7
diff -u -r1.7 if.h
--- net/if.h	22 Nov 2003 19:30:56 -0000	1.7
+++ net/if.h	19 Dec 2003 16:26:39 -0000
@@ -58,6 +58,7 @@
  */
 #define		IFNAMSIZ	16
 #define		IF_NAMESIZE	IFNAMSIZ
+#define		IF_MAXUNIT	0x7fff		/* if_unit is 15bits */
 
 #ifdef _KERNEL
 /*
@@ -67,13 +68,17 @@
 	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
 
 /*
Index: net/faith/if_faith.c
===================================================================
RCS file: /root/.dfcvs/src/sys/net/faith/if_faith.c,v
retrieving revision 1.5
diff -u -r1.5 if_faith.c
--- net/faith/if_faith.c	15 Sep 2003 23:38:13 -0000	1.5
+++ net/faith/if_faith.c	19 Dec 2003 16:27:55 -0000
@@ -62,7 +62,6 @@
 #include <sys/types.h>
 #include <sys/malloc.h>
 #include <machine/bus.h>	/* XXX: Shouldn't really be required! */
-#include <sys/rman.h>
 
 #include <net/if.h>
 #include <net/if_types.h>
@@ -89,11 +88,9 @@
 #include <net/net_osdep.h>
 
 #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 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 @@
 	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 @@
 			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 @@
 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,15 +188,11 @@
 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);
 }
Index: net/gif/if_gif.c
===================================================================
RCS file: /root/.dfcvs/src/sys/net/gif/if_gif.c,v
retrieving revision 1.6
diff -u -r1.6 if_gif.c
--- net/gif/if_gif.c	15 Sep 2003 23:38:13 -0000	1.6
+++ net/gif/if_gif.c	19 Dec 2003 16:52:10 -0000
@@ -48,7 +48,6 @@
 #include <sys/protosw.h>
 #include <sys/conf.h>
 #include <machine/bus.h>	/* XXX: Shouldn't really be required! */
-#include <sys/rman.h>
 #include <machine/cpu.h>
 
 #include <net/if.h>
@@ -84,18 +83,15 @@
 #include <net/net_osdep.h>
 
 #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 @@
 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 @@
 	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 @@
 	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 @@
 		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
Index: net/gre/if_gre.c
===================================================================
RCS file: /root/.dfcvs/src/sys/net/gre/if_gre.c,v
retrieving revision 1.5
diff -u -r1.5 if_gre.c
--- net/gre/if_gre.c	7 Aug 2003 21:17:24 -0000	1.5
+++ net/gre/if_gre.c	19 Dec 2003 17:18:20 -0000
@@ -58,7 +58,6 @@
 #include <sys/proc.h>
 #include <sys/protosw.h>
 #include <machine/bus.h>
-#include <sys/rman.h>
 #include <sys/socket.h>
 #include <sys/sockio.h>
 #include <sys/sysctl.h>
@@ -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 @@
 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 @@
 	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 @@
 gre_clone_destroy(ifp)
 	struct ifnet *ifp;
 {
-	int err;
 	struct gre_softc *sc = ifp->if_softc;
 
 #ifdef INET
@@ -224,9 +202,6 @@
 	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 @@
 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:
@@ -784,10 +746,6 @@
 
 		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;
 	}
Index: net/vlan/if_vlan.c
===================================================================
RCS file: /root/.dfcvs/src/sys/net/vlan/if_vlan.c,v
retrieving revision 1.4
diff -u -r1.4 if_vlan.c
--- net/vlan/if_vlan.c	7 Aug 2003 21:17:30 -0000	1.4
+++ net/vlan/if_vlan.c	19 Dec 2003 16:30:01 -0000
@@ -71,7 +71,6 @@
 #include <sys/sysctl.h>
 #include <sys/systm.h>
 #include <machine/bus.h>	/* XXX: Shouldn't really be required! */
-#include <sys/rman.h>
 
 #include <net/bpf.h>
 #include <net/ethernet.h>
@@ -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_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 @@
 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_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 @@
 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 @@
 
 	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 @@
 {
 	struct ifvlan *ifv = ifp->if_softc;
 	int s;
-	int err;
 
 	s = splnet();
 	LIST_REMOVE(ifv, ifv_list);
@@ -298,8 +254,6 @@
 
 	ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
 
-	err = rman_release_resource(ifv->r_unit);
-	KASSERT(err == 0, ("Unexpected error freeing resource"));
 	free(ifv, M_VLAN);
 }
 


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