diff options
author | mux <mux@FreeBSD.org> | 2002-03-11 09:26:07 +0000 |
---|---|---|
committer | mux <mux@FreeBSD.org> | 2002-03-11 09:26:07 +0000 |
commit | 9a5e4c88a3c8f122fd226c41249210b7d9a95ab7 (patch) | |
tree | ead93d76aaa7a11f5c58953041c77a386e18fc64 /sys/net/if_stf.c | |
parent | 352806ecf32064d3f84e690dc624e0a0aac0507b (diff) | |
download | FreeBSD-src-9a5e4c88a3c8f122fd226c41249210b7d9a95ab7.zip FreeBSD-src-9a5e4c88a3c8f122fd226c41249210b7d9a95ab7.tar.gz |
Simplify the interface cloning framework by handling unit
unit allocation with a bitmap in the generic layer. This
allows us to get rid of the duplicated rman code in every
clonable interface.
Reviewed by: brooks
Approved by: phk
Diffstat (limited to 'sys/net/if_stf.c')
-rw-r--r-- | sys/net/if_stf.c | 52 |
1 files changed, 5 insertions, 47 deletions
diff --git a/sys/net/if_stf.c b/sys/net/if_stf.c index ee14ece..3aaae46 100644 --- a/sys/net/if_stf.c +++ b/sys/net/if_stf.c @@ -86,8 +86,6 @@ #include <sys/kernel.h> #include <sys/protosw.h> #include <sys/queue.h> -#include <machine/bus.h> /* XXX: Shouldn't really be required! */ -#include <sys/rman.h> #include <machine/cpu.h> #include <sys/malloc.h> @@ -118,7 +116,6 @@ #include <net/bpf.h> #define STFNAME "stf" -#define STF_MAXUNIT 0 /* only one is currently allowed */ #define IN6_IS_ADDR_6TO4(x) (ntohs((x)->s6_addr16[0]) == 0x2002) #define GET_V4(x) ((struct in_addr *)(&(x)->s6_addr16[1])) @@ -131,14 +128,12 @@ struct stf_softc { } __sc_ro46; #define sc_ro __sc_ro46.__sc_ro4 const struct encaptab *encap_cookie; - struct resource *r_unit; /* resource allocated for this unit */ LIST_ENTRY(stf_softc) sc_list; /* all stf's are linked */ }; static LIST_HEAD(, stf_softc) stf_softc_list; static MALLOC_DEFINE(M_STF, STFNAME, "6to4 Tunnel Interface"); -static struct rman stfunits[1]; static int ip_stf_ttl = 40; extern struct domain inetdomain; @@ -162,40 +157,23 @@ static int stf_checkaddr6 __P((struct stf_softc *, struct in6_addr *, static void stf_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *)); static int stf_ioctl __P((struct ifnet *, u_long, caddr_t)); -int stf_clone_create __P((struct if_clone *, int *)); +int stf_clone_create __P((struct if_clone *, int)); int stf_clone_destroy __P((struct ifnet *)); +/* only one clone is currently allowed */ struct if_clone stf_cloner = - IF_CLONE_INITIALIZER(STFNAME, stf_clone_create, stf_clone_destroy); + IF_CLONE_INITIALIZER(STFNAME, stf_clone_create, stf_clone_destroy, 0); int stf_clone_create(ifc, unit) struct if_clone *ifc; - int *unit; + int unit; { - struct resource *r; struct stf_softc *sc; - if (*unit > STF_MAXUNIT) - return (ENXIO); - - if (*unit < 0) { - r = rman_reserve_resource(stfunits, 0, STF_MAXUNIT, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (ENOSPC); - *unit = rman_get_start(r); - } else { - r = rman_reserve_resource(stfunits, *unit, *unit, 1, - RF_ALLOCATED | RF_ACTIVE, NULL); - if (r == NULL) - return (EEXIST); - } - sc = malloc(sizeof(struct stf_softc), M_STF, M_WAITOK | M_ZERO); sc->sc_if.if_name = STFNAME; - sc->sc_if.if_unit = *unit; - sc->r_unit = r; + sc->sc_if.if_unit = unit; sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6, stf_encapcheck, &in_stf_protosw, sc); @@ -229,9 +207,6 @@ stf_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_STF); return (0); } @@ -242,22 +217,9 @@ stfmodevent(mod, type, data) int type; void *data; { - int err; switch (type) { case MOD_LOAD: - stfunits->rm_type = RMAN_ARRAY; - stfunits->rm_descr = "configurable if_stf units"; - err = rman_init(stfunits); - if (err != 0) - return (err); - err = rman_manage_region(stfunits, 0, STF_MAXUNIT); - if (err != 0) { - printf("%s: stfunits: rman_manage_region: Failed %d\n", - STFNAME, err); - rman_fini(stfunits); - return (err); - } LIST_INIT(&stf_softc_list); if_clone_attach(&stf_cloner); @@ -267,10 +229,6 @@ stfmodevent(mod, type, data) while (!LIST_EMPTY(&stf_softc_list)) stf_clone_destroy(&LIST_FIRST(&stf_softc_list)->sc_if); - - err = rman_fini(stfunits); - KASSERT(err == 0, ("Unexpected error freeing resource")); - break; } |