summaryrefslogtreecommitdiffstats
path: root/sys/net/if.c
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2002-05-25 20:17:04 +0000
committerbrooks <brooks@FreeBSD.org>2002-05-25 20:17:04 +0000
commit6cfd5a5a1d8c4a93c799f5e36a35e82908de3464 (patch)
treee660b083146de9ff5a32c2ffb3bf4b2a015c1a0b /sys/net/if.c
parentc23d71a3554dd96732f409c3956d8a2aed2ad182 (diff)
downloadFreeBSD-src-6cfd5a5a1d8c4a93c799f5e36a35e82908de3464.zip
FreeBSD-src-6cfd5a5a1d8c4a93c799f5e36a35e82908de3464.tar.gz
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)
Diffstat (limited to 'sys/net/if.c')
-rw-r--r--sys/net/if.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 8fc94e7..cf3bfc1 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -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);
+ }
}
/*
OpenPOWER on IntegriCloud