165a24520SSepherosa Ziehau /*
265a24520SSepherosa Ziehau * Copyright (c) 1980, 1986, 1993
365a24520SSepherosa Ziehau * The Regents of the University of California. All rights reserved.
465a24520SSepherosa Ziehau *
565a24520SSepherosa Ziehau * Redistribution and use in source and binary forms, with or without
665a24520SSepherosa Ziehau * modification, are permitted provided that the following conditions
765a24520SSepherosa Ziehau * are met:
865a24520SSepherosa Ziehau * 1. Redistributions of source code must retain the above copyright
965a24520SSepherosa Ziehau * notice, this list of conditions and the following disclaimer.
1065a24520SSepherosa Ziehau * 2. Redistributions in binary form must reproduce the above copyright
1165a24520SSepherosa Ziehau * notice, this list of conditions and the following disclaimer in the
1265a24520SSepherosa Ziehau * documentation and/or other materials provided with the distribution.
13dc71b7abSJustin C. Sherrill * 3. Neither the name of the University nor the names of its contributors
1465a24520SSepherosa Ziehau * may be used to endorse or promote products derived from this software
1565a24520SSepherosa Ziehau * without specific prior written permission.
1665a24520SSepherosa Ziehau *
1765a24520SSepherosa Ziehau * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1865a24520SSepherosa Ziehau * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1965a24520SSepherosa Ziehau * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2065a24520SSepherosa Ziehau * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2165a24520SSepherosa Ziehau * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2265a24520SSepherosa Ziehau * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2365a24520SSepherosa Ziehau * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2465a24520SSepherosa Ziehau * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2565a24520SSepherosa Ziehau * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2665a24520SSepherosa Ziehau * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2765a24520SSepherosa Ziehau * SUCH DAMAGE.
2865a24520SSepherosa Ziehau *
2965a24520SSepherosa Ziehau * @(#)if.c 8.3 (Berkeley) 1/4/94
3065a24520SSepherosa Ziehau * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $
3165a24520SSepherosa Ziehau */
3265a24520SSepherosa Ziehau
3365a24520SSepherosa Ziehau #include <sys/param.h>
3465a24520SSepherosa Ziehau #include <sys/kernel.h>
3565a24520SSepherosa Ziehau #include <sys/malloc.h>
365a57776aSAaron LI #include <sys/eventhandler.h>
372010725fSAaron LI #include <sys/limits.h>
3865a24520SSepherosa Ziehau
3965a24520SSepherosa Ziehau #include <net/if.h>
40bff82488SAaron LI #include <net/if_var.h>
4165a24520SSepherosa Ziehau #include <net/if_clone.h>
4265a24520SSepherosa Ziehau
4365a24520SSepherosa Ziehau static LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners);
4465a24520SSepherosa Ziehau static int if_cloners_count;
4565a24520SSepherosa Ziehau
4665a24520SSepherosa Ziehau MALLOC_DEFINE(M_CLONE, "clone", "interface cloning framework");
4765a24520SSepherosa Ziehau
482010725fSAaron LI static int if_name2unit(const char *, int *);
492010725fSAaron LI static bool if_clone_match(struct if_clone *, const char *);
502010725fSAaron LI static struct if_clone *if_clone_lookup(const char *);
519ad42ca2SAaron LI static int if_clone_alloc_unit(struct if_clone *, int *);
529ad42ca2SAaron LI static void if_clone_free_unit(struct if_clone *, int);
53bb54c3a2SAaron LI static int if_clone_createif(struct if_clone *, int, caddr_t, caddr_t);
5465a24520SSepherosa Ziehau
5565a24520SSepherosa Ziehau /*
561047b69eSAaron LI * Lookup the cloner and create a clone network interface.
5765a24520SSepherosa Ziehau */
5865a24520SSepherosa Ziehau int
if_clone_create(char * name,int len,caddr_t params,caddr_t data)59bb54c3a2SAaron LI if_clone_create(char *name, int len, caddr_t params, caddr_t data)
6065a24520SSepherosa Ziehau {
6165a24520SSepherosa Ziehau struct if_clone *ifc;
6284cb91c3SAaron LI char ifname[IFNAMSIZ];
632010725fSAaron LI bool wildcard;
6465a24520SSepherosa Ziehau int unit;
6565a24520SSepherosa Ziehau int err;
6665a24520SSepherosa Ziehau
679ad42ca2SAaron LI if ((ifc = if_clone_lookup(name)) == NULL)
689ad42ca2SAaron LI return (EINVAL);
699ad42ca2SAaron LI if ((err = if_name2unit(name, &unit)) != 0)
709ad42ca2SAaron LI return (err);
7165a24520SSepherosa Ziehau
729ad42ca2SAaron LI wildcard = (unit < 0);
739ad42ca2SAaron LI
74*98a21ddaSMatthew Dillon ifnet_lock();
75*98a21ddaSMatthew Dillon if ((err = if_clone_alloc_unit(ifc, &unit)) != 0) {
76*98a21ddaSMatthew Dillon ifnet_unlock();
779ad42ca2SAaron LI return (err);
78*98a21ddaSMatthew Dillon }
7965a24520SSepherosa Ziehau
8084cb91c3SAaron LI ksnprintf(ifname, IFNAMSIZ, "%s%d", ifc->ifc_name, unit);
8184cb91c3SAaron LI
8284cb91c3SAaron LI /*
8384cb91c3SAaron LI * Update the name with the allocated unit for the caller,
8484cb91c3SAaron LI * who must preserve enough space.
8584cb91c3SAaron LI */
86f835013fSAaron LI if (wildcard && strlcpy(name, ifname, len) >= len) {
87f835013fSAaron LI if_clone_free_unit(ifc, unit);
88*98a21ddaSMatthew Dillon ifnet_unlock();
8984cb91c3SAaron LI return (ENOSPC);
90f835013fSAaron LI }
9184cb91c3SAaron LI
92*98a21ddaSMatthew Dillon err = if_clone_createif(ifc, unit, params, data);
93*98a21ddaSMatthew Dillon if (err)
949ad42ca2SAaron LI if_clone_free_unit(ifc, unit);
95*98a21ddaSMatthew Dillon ifnet_unlock();
9665a24520SSepherosa Ziehau
97*98a21ddaSMatthew Dillon return (err);
9865a24520SSepherosa Ziehau }
9965a24520SSepherosa Ziehau
10065a24520SSepherosa Ziehau /*
1011047b69eSAaron LI * Lookup the cloner and destroy a clone network interface.
10265a24520SSepherosa Ziehau */
10365a24520SSepherosa Ziehau int
if_clone_destroy(const char * name)10465a24520SSepherosa Ziehau if_clone_destroy(const char *name)
10565a24520SSepherosa Ziehau {
10665a24520SSepherosa Ziehau struct if_clone *ifc;
10765a24520SSepherosa Ziehau struct ifnet *ifp;
108a7e9152eSSepherosa Ziehau int unit, error;
10965a24520SSepherosa Ziehau
1103b1300daSAaron LI ifnet_lock();
1113b1300daSAaron LI ifp = ifunit(name);
1123b1300daSAaron LI ifnet_unlock();
1133b1300daSAaron LI if (ifp == NULL)
1143b1300daSAaron LI return (ENXIO);
1153b1300daSAaron LI
1163b1300daSAaron LI if ((ifc = if_clone_lookup(ifp->if_dname)) == NULL)
11765a24520SSepherosa Ziehau return (EINVAL);
11865a24520SSepherosa Ziehau
1193b1300daSAaron LI unit = ifp->if_dunit;
12065a24520SSepherosa Ziehau if (unit < ifc->ifc_minifs)
12165a24520SSepherosa Ziehau return (EINVAL);
12265a24520SSepherosa Ziehau
1233b1300daSAaron LI if (ifc->ifc_destroy == NULL)
12465a24520SSepherosa Ziehau return (EOPNOTSUPP);
12565a24520SSepherosa Ziehau
1263b1300daSAaron LI ifnet_lock();
1279ad42ca2SAaron LI if_clone_free_unit(ifc, unit);
128*98a21ddaSMatthew Dillon error = ifc->ifc_destroy(ifp);
129*98a21ddaSMatthew Dillon if (error)
130*98a21ddaSMatthew Dillon if_clone_alloc_unit(ifc, &unit);
131*98a21ddaSMatthew Dillon /* else ifc structure is dead */
132*98a21ddaSMatthew Dillon ifnet_unlock();
1333b1300daSAaron LI
134*98a21ddaSMatthew Dillon return (error);
13565a24520SSepherosa Ziehau }
13665a24520SSepherosa Ziehau
13765a24520SSepherosa Ziehau /*
13865a24520SSepherosa Ziehau * Register a network interface cloner.
13965a24520SSepherosa Ziehau */
140595dc8f1SAaron LI int
if_clone_attach(struct if_clone * ifc)14165a24520SSepherosa Ziehau if_clone_attach(struct if_clone *ifc)
14265a24520SSepherosa Ziehau {
1439ad42ca2SAaron LI struct if_clone *ifct;
14465a24520SSepherosa Ziehau int len, maxclone;
14565a24520SSepherosa Ziehau int unit;
14651edabe8SMarkus Pfeiffer
14751edabe8SMarkus Pfeiffer LIST_FOREACH(ifct, &if_cloners, ifc_list) {
148595dc8f1SAaron LI if (strcmp(ifct->ifc_name, ifc->ifc_name) == 0)
149595dc8f1SAaron LI return (EEXIST);
15051edabe8SMarkus Pfeiffer }
15165a24520SSepherosa Ziehau
15265a24520SSepherosa Ziehau KASSERT(ifc->ifc_minifs - 1 <= ifc->ifc_maxunit,
15365a24520SSepherosa Ziehau ("%s: %s requested more units then allowed (%d > %d)",
15465a24520SSepherosa Ziehau __func__, ifc->ifc_name, ifc->ifc_minifs,
15565a24520SSepherosa Ziehau ifc->ifc_maxunit + 1));
15665a24520SSepherosa Ziehau /*
15765a24520SSepherosa Ziehau * Compute bitmap size and allocate it.
15865a24520SSepherosa Ziehau */
15965a24520SSepherosa Ziehau maxclone = ifc->ifc_maxunit + 1;
16065a24520SSepherosa Ziehau len = maxclone >> 3;
16165a24520SSepherosa Ziehau if ((len << 3) < maxclone)
16265a24520SSepherosa Ziehau len++;
16365a24520SSepherosa Ziehau ifc->ifc_units = kmalloc(len, M_CLONE, M_WAITOK | M_ZERO);
16465a24520SSepherosa Ziehau ifc->ifc_bmlen = len;
16565a24520SSepherosa Ziehau
16665a24520SSepherosa Ziehau LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list);
16765a24520SSepherosa Ziehau if_cloners_count++;
16865a24520SSepherosa Ziehau
169*98a21ddaSMatthew Dillon ifnet_lock();
17065a24520SSepherosa Ziehau for (unit = 0; unit < ifc->ifc_minifs; unit++) {
1719ad42ca2SAaron LI if_clone_alloc_unit(ifc, &unit);
172bb54c3a2SAaron LI if (if_clone_createif(ifc, unit, NULL, NULL) != 0) {
173*98a21ddaSMatthew Dillon ifnet_unlock();
1741047b69eSAaron LI panic("%s: failed to create required interface %s%d",
1751047b69eSAaron LI __func__, ifc->ifc_name, unit);
1761047b69eSAaron LI }
17765a24520SSepherosa Ziehau }
178*98a21ddaSMatthew Dillon ifnet_unlock();
1790de0168fSAaron LI
1800de0168fSAaron LI EVENTHANDLER_INVOKE(if_clone_event, ifc);
181595dc8f1SAaron LI
182595dc8f1SAaron LI return (0);
18365a24520SSepherosa Ziehau }
18465a24520SSepherosa Ziehau
18565a24520SSepherosa Ziehau /*
18665a24520SSepherosa Ziehau * Unregister a network interface cloner.
18765a24520SSepherosa Ziehau */
18865a24520SSepherosa Ziehau void
if_clone_detach(struct if_clone * ifc)18965a24520SSepherosa Ziehau if_clone_detach(struct if_clone *ifc)
19065a24520SSepherosa Ziehau {
19165a24520SSepherosa Ziehau
19265a24520SSepherosa Ziehau LIST_REMOVE(ifc, ifc_list);
19365a24520SSepherosa Ziehau kfree(ifc->ifc_units, M_CLONE);
19465a24520SSepherosa Ziehau if_cloners_count--;
19565a24520SSepherosa Ziehau }
19665a24520SSepherosa Ziehau
19765a24520SSepherosa Ziehau /*
19865a24520SSepherosa Ziehau * Provide list of interface cloners to userspace.
19965a24520SSepherosa Ziehau */
20065a24520SSepherosa Ziehau int
if_clone_list(struct if_clonereq * ifcr)20165a24520SSepherosa Ziehau if_clone_list(struct if_clonereq *ifcr)
20265a24520SSepherosa Ziehau {
20365a24520SSepherosa Ziehau char outbuf[IFNAMSIZ], *dst;
20465a24520SSepherosa Ziehau struct if_clone *ifc;
20565a24520SSepherosa Ziehau int count, error = 0;
20665a24520SSepherosa Ziehau
20765a24520SSepherosa Ziehau ifcr->ifcr_total = if_cloners_count;
20865a24520SSepherosa Ziehau if ((dst = ifcr->ifcr_buffer) == NULL) {
20965a24520SSepherosa Ziehau /* Just asking how many there are. */
21065a24520SSepherosa Ziehau return (0);
21165a24520SSepherosa Ziehau }
21265a24520SSepherosa Ziehau
21365a24520SSepherosa Ziehau if (ifcr->ifcr_count < 0)
21465a24520SSepherosa Ziehau return (EINVAL);
21565a24520SSepherosa Ziehau
21665a24520SSepherosa Ziehau count = (if_cloners_count < ifcr->ifcr_count) ?
21765a24520SSepherosa Ziehau if_cloners_count : ifcr->ifcr_count;
21865a24520SSepherosa Ziehau
2191047b69eSAaron LI for (ifc = LIST_FIRST(&if_cloners);
2201047b69eSAaron LI ifc != NULL && count != 0;
22165a24520SSepherosa Ziehau ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) {
222b8b9f56eSMatthew Dillon bzero(outbuf, IFNAMSIZ); /* sanitize */
22365a24520SSepherosa Ziehau strlcpy(outbuf, ifc->ifc_name, IFNAMSIZ);
22465a24520SSepherosa Ziehau error = copyout(outbuf, dst, IFNAMSIZ);
22565a24520SSepherosa Ziehau if (error)
22665a24520SSepherosa Ziehau break;
22765a24520SSepherosa Ziehau }
22865a24520SSepherosa Ziehau
22965a24520SSepherosa Ziehau return (error);
23065a24520SSepherosa Ziehau }
23165a24520SSepherosa Ziehau
23265a24520SSepherosa Ziehau /*
2332010725fSAaron LI * Extract the unit number from interface name of the form "name###".
2342010725fSAaron LI * A unit of -1 is stored if the given name doesn't have a unit.
2352010725fSAaron LI *
2362010725fSAaron LI * Returns 0 on success and an error on failure.
23765a24520SSepherosa Ziehau */
2382010725fSAaron LI static int
if_name2unit(const char * name,int * unit)2392010725fSAaron LI if_name2unit(const char *name, int *unit)
24065a24520SSepherosa Ziehau {
2412010725fSAaron LI const char *cp;
2422010725fSAaron LI int cutoff = INT_MAX / 10;
2432010725fSAaron LI int cutlim = INT_MAX % 10;
2442010725fSAaron LI
2452010725fSAaron LI for (cp = name; *cp != '\0' && (*cp < '0' || *cp > '9'); cp++)
2462010725fSAaron LI ;
2472010725fSAaron LI if (*cp == '\0') {
2482010725fSAaron LI *unit = -1;
2492010725fSAaron LI } else if (cp[0] == '0' && cp[1] != '\0') {
2502010725fSAaron LI /* Disallow leading zeroes. */
2512010725fSAaron LI return (EINVAL);
2522010725fSAaron LI } else {
2532010725fSAaron LI for (*unit = 0; *cp != '\0'; cp++) {
2542010725fSAaron LI if (*cp < '0' || *cp > '9') {
2552010725fSAaron LI /* Bogus unit number. */
2562010725fSAaron LI return (EINVAL);
2572010725fSAaron LI }
2582010725fSAaron LI if (*unit > cutoff ||
2592010725fSAaron LI (*unit == cutoff && *cp - '0' > cutlim))
2602010725fSAaron LI return (EINVAL);
2612010725fSAaron LI *unit = (*unit * 10) + (*cp - '0');
2622010725fSAaron LI }
2632010725fSAaron LI }
2642010725fSAaron LI
2652010725fSAaron LI return (0);
2662010725fSAaron LI }
2672010725fSAaron LI
2682010725fSAaron LI /*
2692010725fSAaron LI * Check whether the interface cloner matches the name.
2702010725fSAaron LI */
2712010725fSAaron LI static bool
if_clone_match(struct if_clone * ifc,const char * name)2722010725fSAaron LI if_clone_match(struct if_clone *ifc, const char *name)
2732010725fSAaron LI {
27465a24520SSepherosa Ziehau const char *cp;
27565a24520SSepherosa Ziehau int i;
27665a24520SSepherosa Ziehau
2772010725fSAaron LI /* Match the name */
278e224e5e7SAaron LI for (cp = name, i = 0; i < strlen(ifc->ifc_name); i++, cp++) {
27965a24520SSepherosa Ziehau if (ifc->ifc_name[i] != *cp)
2802010725fSAaron LI return (false);
28165a24520SSepherosa Ziehau }
2822010725fSAaron LI
2832010725fSAaron LI /* Make sure there's a unit number or nothing after the name */
2842010725fSAaron LI for ( ; *cp != '\0'; cp++) {
2852010725fSAaron LI if (*cp < '0' || *cp > '9')
2862010725fSAaron LI return (false);
2872010725fSAaron LI }
2882010725fSAaron LI
2892010725fSAaron LI return (true);
2902010725fSAaron LI }
2912010725fSAaron LI
2922010725fSAaron LI /*
2932010725fSAaron LI * Look up a network interface cloner.
2942010725fSAaron LI */
2952010725fSAaron LI static struct if_clone *
if_clone_lookup(const char * name)2962010725fSAaron LI if_clone_lookup(const char *name)
2972010725fSAaron LI {
2982010725fSAaron LI struct if_clone *ifc;
2992010725fSAaron LI
3002010725fSAaron LI LIST_FOREACH(ifc, &if_cloners, ifc_list) {
3012010725fSAaron LI if (if_clone_match(ifc, name))
3022010725fSAaron LI return ifc;
30365a24520SSepherosa Ziehau }
30465a24520SSepherosa Ziehau
3052038fb68SSascha Wildner return (NULL);
30665a24520SSepherosa Ziehau }
3079ad42ca2SAaron LI
3089ad42ca2SAaron LI /*
3099ad42ca2SAaron LI * Allocate a unit number.
3109ad42ca2SAaron LI *
311*98a21ddaSMatthew Dillon * ifnet must be locked.
312*98a21ddaSMatthew Dillon *
3139ad42ca2SAaron LI * Returns 0 on success and an error on failure.
3149ad42ca2SAaron LI */
3159ad42ca2SAaron LI static int
if_clone_alloc_unit(struct if_clone * ifc,int * unit)3169ad42ca2SAaron LI if_clone_alloc_unit(struct if_clone *ifc, int *unit)
3179ad42ca2SAaron LI {
3189ad42ca2SAaron LI int bytoff, bitoff;
3199ad42ca2SAaron LI
3209ad42ca2SAaron LI if (*unit < 0) {
3219ad42ca2SAaron LI /*
3229ad42ca2SAaron LI * Wildcard mode: find a free unit.
3239ad42ca2SAaron LI */
3249ad42ca2SAaron LI bytoff = bitoff = 0;
3259ad42ca2SAaron LI while (bytoff < ifc->ifc_bmlen &&
3269ad42ca2SAaron LI ifc->ifc_units[bytoff] == 0xff)
3279ad42ca2SAaron LI bytoff++;
3289ad42ca2SAaron LI if (bytoff >= ifc->ifc_bmlen)
3299ad42ca2SAaron LI return (ENOSPC);
3309ad42ca2SAaron LI while ((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0)
3319ad42ca2SAaron LI bitoff++;
3329ad42ca2SAaron LI *unit = (bytoff << 3) + bitoff;
3339ad42ca2SAaron LI } else {
3349ad42ca2SAaron LI bytoff = *unit >> 3;
3359ad42ca2SAaron LI bitoff = *unit - (bytoff << 3);
3369ad42ca2SAaron LI }
3379ad42ca2SAaron LI
3389ad42ca2SAaron LI if (*unit > ifc->ifc_maxunit)
3399ad42ca2SAaron LI return (ENXIO);
3409ad42ca2SAaron LI
3419ad42ca2SAaron LI /*
3429ad42ca2SAaron LI * Allocate the unit in the bitmap.
3439ad42ca2SAaron LI */
344*98a21ddaSMatthew Dillon #if 0
3459ad42ca2SAaron LI KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) == 0,
3469ad42ca2SAaron LI ("%s: bit is already set", __func__));
347*98a21ddaSMatthew Dillon #endif
348*98a21ddaSMatthew Dillon if (ifc->ifc_units[bytoff] & (1 << bitoff))
349*98a21ddaSMatthew Dillon return (EEXIST);
3509ad42ca2SAaron LI ifc->ifc_units[bytoff] |= (1 << bitoff);
3519ad42ca2SAaron LI
3529ad42ca2SAaron LI return (0);
3539ad42ca2SAaron LI }
3549ad42ca2SAaron LI
3559ad42ca2SAaron LI /*
3569ad42ca2SAaron LI * Free an allocated unit number.
357*98a21ddaSMatthew Dillon *
358*98a21ddaSMatthew Dillon * ifnet must be locked.
3599ad42ca2SAaron LI */
3609ad42ca2SAaron LI static void
if_clone_free_unit(struct if_clone * ifc,int unit)3619ad42ca2SAaron LI if_clone_free_unit(struct if_clone *ifc, int unit)
3629ad42ca2SAaron LI {
3639ad42ca2SAaron LI int bytoff, bitoff;
3649ad42ca2SAaron LI
3659ad42ca2SAaron LI bytoff = unit >> 3;
3669ad42ca2SAaron LI bitoff = unit - (bytoff << 3);
3679ad42ca2SAaron LI KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0,
3689ad42ca2SAaron LI ("%s: bit is already cleared", __func__));
3699ad42ca2SAaron LI ifc->ifc_units[bytoff] &= ~(1 << bitoff);
3709ad42ca2SAaron LI }
3711047b69eSAaron LI
3721047b69eSAaron LI /*
3731047b69eSAaron LI * Create a clone network interface.
374*98a21ddaSMatthew Dillon *
375*98a21ddaSMatthew Dillon * ifnet must be locked
3761047b69eSAaron LI */
3771047b69eSAaron LI static int
if_clone_createif(struct if_clone * ifc,int unit,caddr_t params,caddr_t data)378bb54c3a2SAaron LI if_clone_createif(struct if_clone *ifc, int unit, caddr_t params, caddr_t data)
3791047b69eSAaron LI {
3801047b69eSAaron LI struct ifnet *ifp;
3811047b69eSAaron LI char ifname[IFNAMSIZ];
3821047b69eSAaron LI int err;
3831047b69eSAaron LI
3841047b69eSAaron LI ksnprintf(ifname, IFNAMSIZ, "%s%d", ifc->ifc_name, unit);
3851047b69eSAaron LI
3861047b69eSAaron LI ifp = ifunit(ifname);
3871047b69eSAaron LI if (ifp != NULL)
3881047b69eSAaron LI return (EEXIST);
3891047b69eSAaron LI
390*98a21ddaSMatthew Dillon /*ifnet_unlock();*/
391bb54c3a2SAaron LI err = (*ifc->ifc_create)(ifc, unit, params, data);
392*98a21ddaSMatthew Dillon /*ifnet_lock();*/
3931047b69eSAaron LI if (err != 0)
3941047b69eSAaron LI return (err);
3951047b69eSAaron LI
3965e983a2eSAaron LI ifp = ifunit(ifname);
3975e983a2eSAaron LI if (ifp == NULL)
3985e983a2eSAaron LI return (ENXIO);
3995e983a2eSAaron LI
4005e983a2eSAaron LI err = if_addgroup(ifp, ifc->ifc_name);
4015e983a2eSAaron LI if (err != 0)
4025e983a2eSAaron LI return (err);
4035e983a2eSAaron LI
4041047b69eSAaron LI return (0);
4051047b69eSAaron LI }
406