Move all unit number management cloned interfaces into the cloning

code.  The reverts the API change which made the <if>_clone_destory()
functions return an int instead of void bringing us into closer
alignment with NetBSD.

Reviewed by:	net (a long time ago)
This commit is contained in:
Brooks Davis 2002-05-25 20:17:04 +00:00
parent ddf4e2a272
commit ae5a19be8e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97289
7 changed files with 47 additions and 39 deletions

View File

@ -656,12 +656,15 @@ if_clone_destroy(name)
struct if_clone *ifc;
struct ifnet *ifp;
int bytoff, bitoff;
int err, unit;
int unit;
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);
@ -669,9 +672,7 @@ if_clone_destroy(name)
if (ifc->ifc_destroy == NULL)
return (EOPNOTSUPP);
err = (*ifc->ifc_destroy)(ifp);
if (err != 0)
return (err);
(*ifc->ifc_destroy)(ifp);
/*
* Compute offset in the bitmap and deallocate the unit.
@ -734,8 +735,15 @@ 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.
*/
@ -745,8 +753,21 @@ if_clone_attach(ifc)
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);
}
}
/*

View File

@ -67,16 +67,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_destroy)(struct ifnet *);
void (*ifc_destroy)(struct ifnet *);
};
#define IF_CLONE_INITIALIZER(name, create, destroy, maxunit) \
{ { 0 }, name, sizeof(name) - 1, maxunit, NULL, 0, create, destroy }
#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) \
{ { 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy }
#endif
/*

View File

@ -103,10 +103,10 @@ static MALLOC_DEFINE(M_FAITH, FAITHNAME, "Firewall Assisted Tunnel Interface");
static LIST_HEAD(, faith_softc) faith_softc_list;
int faith_clone_create(struct if_clone *, int);
int faith_clone_destroy(struct ifnet *);
void faith_clone_destroy(struct ifnet *);
struct if_clone faith_cloner = IF_CLONE_INITIALIZER(FAITHNAME,
faith_clone_create, faith_clone_destroy, IF_MAXUNIT);
faith_clone_create, faith_clone_destroy, 0, IF_MAXUNIT);
#define FAITHMTU 1500
@ -181,7 +181,7 @@ faith_clone_create(ifc, unit)
return (0);
}
int
void
faith_clone_destroy(ifp)
struct ifnet *ifp;
{
@ -192,7 +192,6 @@ faith_clone_destroy(ifp)
if_detach(ifp);
free(sc, M_FAITH);
return (0);
}
int

View File

@ -90,10 +90,10 @@ void (*ng_gif_attach_p)(struct ifnet *ifp);
void (*ng_gif_detach_p)(struct ifnet *ifp);
int gif_clone_create(struct if_clone *, int);
int gif_clone_destroy(struct ifnet *);
void gif_clone_destroy(struct ifnet *);
struct if_clone gif_cloner = IF_CLONE_INITIALIZER("gif",
gif_clone_create, gif_clone_destroy, IF_MAXUNIT);
gif_clone_create, gif_clone_destroy, 0, IF_MAXUNIT);
static int gifmodevent(module_t, int, void *);
void gif_delete_tunnel(struct gif_softc *);
@ -207,7 +207,7 @@ gif_clone_create(ifc, unit)
return (0);
}
int
void
gif_clone_destroy(ifp)
struct ifnet *ifp;
{
@ -231,7 +231,6 @@ gif_clone_destroy(ifp)
if_detach(ifp);
free(sc, M_GIF);
return (0);
}
static int

View File

@ -110,7 +110,7 @@ static void lortrequest(int, struct rtentry *, struct rt_addrinfo *);
int looutput(struct ifnet *ifp, struct mbuf *m,
struct sockaddr *dst, struct rtentry *rt);
int lo_clone_create(struct if_clone *, int);
int lo_clone_destroy(struct ifnet *);
void lo_clone_destroy(struct ifnet *);
struct ifnet *loif = NULL; /* Used externally */
@ -118,10 +118,10 @@ static MALLOC_DEFINE(M_LO, LONAME, "Loopback Interface");
static LIST_HEAD(lo_list, lo_softc) lo_list;
struct if_clone lo_cloner =
IF_CLONE_INITIALIZER(LONAME, lo_clone_create, lo_clone_destroy, IF_MAXUNIT);
struct if_clone lo_cloner = IF_CLONE_INITIALIZER(LONAME,
lo_clone_create, lo_clone_destroy, 1, IF_MAXUNIT);
int
void
lo_clone_destroy(ifp)
struct ifnet *ifp;
{
@ -129,17 +129,13 @@ lo_clone_destroy(ifp)
sc = ifp->if_softc;
/*
* Prevent lo0 from being destroyed.
*/
if (loif == ifp)
return (EINVAL);
/* XXX: destroying lo0 will lead to panics. */
KASSERT(loif != ifp, ("%s: destroying lo0", __func__));
bpfdetach(ifp);
if_detach(ifp);
LIST_REMOVE(sc, sc_next);
free(sc, M_LO);
return (0);
}
int
@ -172,16 +168,10 @@ lo_clone_create(ifc, unit)
static int
loop_modevent(module_t mod, int type, void *data)
{
int err;
switch (type) {
case MOD_LOAD:
LIST_INIT(&lo_list);
if_clone_attach(&lo_cloner);
/* Create lo0 */
err = if_clone_create("lo0", sizeof ("lo0"));
KASSERT(err == 0, ("%s: can't create lo0", __func__));
break;
case MOD_UNLOAD:
printf("loop module unload - not possible for this module type\n");

View File

@ -158,11 +158,11 @@ static void stf_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
static int stf_ioctl(struct ifnet *, u_long, caddr_t);
int stf_clone_create(struct if_clone *, int);
int stf_clone_destroy(struct ifnet *);
void stf_clone_destroy(struct ifnet *);
/* only one clone is currently allowed */
struct if_clone stf_cloner =
IF_CLONE_INITIALIZER(STFNAME, stf_clone_create, stf_clone_destroy, 0);
IF_CLONE_INITIALIZER(STFNAME, stf_clone_create, stf_clone_destroy, 0, 0);
int
stf_clone_create(ifc, unit)
@ -194,7 +194,7 @@ stf_clone_create(ifc, unit)
return (0);
}
int
void
stf_clone_destroy(ifp)
struct ifnet *ifp;
{
@ -208,7 +208,6 @@ stf_clone_destroy(ifp)
if_detach(ifp);
free(sc, M_STF);
return (0);
}
static int

View File

@ -90,7 +90,7 @@ static MALLOC_DEFINE(M_VLAN, "vlan", "802.1Q Virtual LAN Interface");
static LIST_HEAD(, ifvlan) ifv_list;
static int vlan_clone_create(struct if_clone *, int);
static int vlan_clone_destroy(struct ifnet *);
static void vlan_clone_destroy(struct ifnet *);
static void vlan_start(struct ifnet *ifp);
static void vlan_ifinit(void *foo);
static int vlan_input(struct ether_header *eh, struct mbuf *m);
@ -102,7 +102,7 @@ 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, IF_MAXUNIT);
vlan_clone_create, vlan_clone_destroy, 0, IF_MAXUNIT);
/*
* Program our multicast filter. What we're actually doing is
@ -236,7 +236,7 @@ vlan_clone_create(struct if_clone *ifc, int unit)
return (0);
}
static int
static void
vlan_clone_destroy(struct ifnet *ifp)
{
struct ifvlan *ifv = ifp->if_softc;
@ -250,7 +250,6 @@ vlan_clone_destroy(struct ifnet *ifp)
ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
free(ifv, M_VLAN);
return (0);
}
static void