From owner-freebsd-net@FreeBSD.ORG Tue Apr 20 21:24:54 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 08FF116A4CE for ; Tue, 20 Apr 2004 21:24:54 -0700 (PDT) Received: from odin.ac.hmc.edu (Odin.AC.HMC.Edu [134.173.32.75]) by mx1.FreeBSD.org (Postfix) with ESMTP id AB9F543D4C for ; Tue, 20 Apr 2004 21:24:53 -0700 (PDT) (envelope-from brdavis@odin.ac.hmc.edu) Received: from odin.ac.hmc.edu (IDENT:brdavis@localhost.localdomain [127.0.0.1]) by odin.ac.hmc.edu (8.12.10/8.12.3) with ESMTP id i3L4OrjU011807 for ; Tue, 20 Apr 2004 21:24:53 -0700 Received: (from brdavis@localhost) by odin.ac.hmc.edu (8.12.10/8.12.3/Submit) id i3L4Or3L011806 for net@freebsd.org; Tue, 20 Apr 2004 21:24:53 -0700 Date: Tue, 20 Apr 2004 21:24:53 -0700 From: Brooks Davis To: net@freebsd.org Message-ID: <20040421042453.GA8866@Odin.AC.HMC.Edu> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="opJtzjQTFsWo+cga" Content-Disposition: inline User-Agent: Mutt/1.5.4i Subject: RFC: if_clone overhaul X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Apr 2004 04:24:54 -0000 --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Please test/review the following patch to the network interface cloneing code. This code is a major overhaul of the cloning infrastructure. The significant include: - Split the code out into if_clone.[ch]. - Locked struct if_clone. Derived from work by Maurycy Pawlowski-Wieronski - Add a per-cloner match function rather then simply matching names of the form and . - Use the match function to allow creation of . vlan interfaces. The old way is preserved unchanged! - Also the match function to allow creation of stf(4) interfaces named stf0, stf, or 6to4. This is the only major user visiable change in that "ifconfig stf" creates the interface stf rather then stf0 and does not print "stf0" to stdout. - Allow destroy functions to fail so they can refuse to delete interfaces. Currently, we forbid the deletion of interfaces which were created in the init function, particularly lo0, pflog0, and pfsync0. In the case of lo0 this was a panic implemenation so it does not count as a user visiable change. :-) - Since most interfaces do not need the new functionality, an family of wrapper functions, ifc_simple_*(), were created to wrap old style cloner functions. - The IF_CLONE_INITIALIZER macro is replaced with a new incompatable IFC_CLONE_INITALIZER and ifc_simple consumers use IFC_SIMPLE_DECLARE instead. TODO: - Integrate vlan changes into /etc/rc* (add support for interfaces with '.' in their name). - Document new vlan syntax in vlan(4). Patch also available at: http://people.freebsd.org/~brooks/patches/ifclone.diff -- Brooks Changed files: sys/conf/files sys/net/if_var.h sys/net/if.c sys/net/if_disc.c sys/net/if_faith.c sys/net/if_gif.c sys/net/if_gre.c sys/net/if_loop.c sys/net/if_ppp.c sys/net/if_stf.c sys/net/if_vlan.c sys/contrib/pf/net/if_pflog.c sys/contrib/pf/net/if_pfsync.c Added files: sys/net/if_clone.h sys/net/if_clone.c --- ../cleanup/sys/conf/files Tue Apr 20 19:16:42 2004 +++ sys/conf/files Tue Apr 20 19:21:52 2004 @@ -1200,6 +1200,7 @@ net/if.c standard net/if_arcsubr.c optional arcnet net/if_atmsubr.c optional atm +net/if_clone.c standard net/if_disc.c optional disc net/if_ef.c optional ef net/if_ethersubr.c optional ether --- ../cleanup/sys/net/if_var.h Sun Apr 18 17:26:34 2004 +++ sys/net/if_var.h Sun Apr 18 17:30:02 2004 @@ -299,9 +299,6 @@ /* interface departure event */ typedef void (*ifnet_departure_event_handler_t)(void *, struct ifnet *); EVENTHANDLER_DECLARE(ifnet_departure_event, ifnet_departure_event_handler_= t); -/* interface clone event */ -typedef void (*if_clone_event_handler_t)(void *, struct if_clone *); -EVENTHANDLER_DECLARE(if_clone_event, if_clone_event_handler_t); =20 #define IF_AFDATA_LOCK_INIT(ifp) \ mtx_init(&(ifp)->if_afdata_mtx, "if_afdata", NULL, MTX_DEF) @@ -486,12 +483,6 @@ =20 struct ifmultiaddr *ifmaof_ifpforaddr(struct sockaddr *, struct ifnet *); int if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen); - -void if_clone_attach(struct if_clone *); -void if_clone_detach(struct if_clone *); - -int if_clone_create(char *, int); -int if_clone_destroy(const char *); =20 #define IF_LLADDR(ifp) \ LLADDR((struct sockaddr_dl *) ifaddr_byindex((ifp)->if_index)->ifa_add= r) --- ../cleanup/sys/net/if.c Tue Apr 20 19:16:42 2004 +++ sys/net/if.c Tue Apr 20 19:21:53 2004 @@ -56,6 +56,7 @@ =20 #include #include +#include #include #include #include @@ -88,8 +89,6 @@ static void if_unroute(struct ifnet *, int flag, int fam); static void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *); static int if_rtdel(struct radix_node *, void *); -static struct if_clone *if_clone_lookup(const char *, int *); -static int if_clone_list(struct if_clonereq *); static int ifhwioctl(u_long, struct ifnet *, caddr_t, struct thread *); #ifdef INET6 /* @@ -104,8 +103,6 @@ int ifqmaxlen =3D IFQ_MAXLEN; struct ifnethead ifnet; /* depend on static init XXX */ struct mtx ifnet_lock; -static int if_cloners_count; -LIST_HEAD(, if_clone) if_cloners =3D LIST_HEAD_INITIALIZER(if_cloners); =20 static int if_indexlim =3D 8; static struct klist ifklist; @@ -124,7 +121,6 @@ =20 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"); =20 static d_open_t netopen; static d_close_t netclose; @@ -261,6 +257,7 @@ if_grow(); /* create initial table */ ifdev_byindex(0) =3D make_dev(&net_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "network"); + if_clone_init(); } =20 static void @@ -653,243 +650,6 @@ } =20 return (0); -} - -/* - * Create a clone network interface. - */ -int -if_clone_create(char *name, int len) -{ - struct if_clone *ifc; - char *dp; - int wildcard, bytoff, bitoff; - int unit; - int err; - - ifc =3D if_clone_lookup(name, &unit); - if (ifc =3D=3D NULL) - return (EINVAL); - - if (ifunit(name) !=3D NULL) - return (EEXIST); - - bytoff =3D bitoff =3D 0; - wildcard =3D (unit < 0); - /* - * Find a free unit if none was given. - */ - if (wildcard) { - while ((bytoff < ifc->ifc_bmlen) - && (ifc->ifc_units[bytoff] =3D=3D 0xff)) - bytoff++; - if (bytoff >=3D ifc->ifc_bmlen) - return (ENOSPC); - while ((ifc->ifc_units[bytoff] & (1 << bitoff)) !=3D 0) - bitoff++; - unit =3D (bytoff << 3) + bitoff; - } - - if (unit > ifc->ifc_maxunit) - return (ENXIO); - - err =3D (*ifc->ifc_create)(ifc, unit); - if (err !=3D 0) - return (err); - - if (!wildcard) { - bytoff =3D unit >> 3; - bitoff =3D unit - (bytoff << 3); - } - - /* - * Allocate the unit in the bitmap. - */ - KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) =3D=3D 0, - ("%s: bit is already set", __func__)); - ifc->ifc_units[bytoff] |=3D (1 << bitoff); - - /* In the wildcard case, we need to update the name. */ - if (wildcard) { - for (dp =3D name; *dp !=3D '\0'; dp++); - if (snprintf(dp, len - (dp-name), "%d", unit) > - len - (dp-name) - 1) { - /* - * This can only be a programmer error and - * there's no straightforward way to recover if - * it happens. - */ - panic("if_clone_create(): interface name too long"); - } - - } - - return (0); -} - -/* - * Destroy a clone network interface. - */ -int -if_clone_destroy(const char *name) -{ - struct if_clone *ifc; - struct ifnet *ifp; - int bytoff, bitoff; - int unit; - - ifp =3D ifunit(name); - if (ifp =3D=3D NULL) - return (ENXIO); - - unit =3D ifp->if_dunit; - - ifc =3D if_clone_lookup(ifp->if_dname, NULL); - if (ifc =3D=3D NULL) - return (EINVAL); - - if (ifc->ifc_destroy =3D=3D NULL) - return (EOPNOTSUPP); - - (*ifc->ifc_destroy)(ifp); - - /* - * Compute offset in the bitmap and deallocate the unit. - */ - bytoff =3D unit >> 3; - bitoff =3D unit - (bytoff << 3); - KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) !=3D 0, - ("%s: bit is already cleared", __func__)); - ifc->ifc_units[bytoff] &=3D ~(1 << bitoff); - return (0); -} - -/* - * Look up a network interface cloner. - */ -static struct if_clone * -if_clone_lookup(const char *name, int *unitp) -{ - struct if_clone *ifc; - const char *cp; - int i; - - for (ifc =3D LIST_FIRST(&if_cloners); ifc !=3D NULL;) { - for (cp =3D name, i =3D 0; i < ifc->ifc_namelen; i++, cp++) { - if (ifc->ifc_name[i] !=3D *cp) - goto next_ifc; - } - goto found_name; - next_ifc: - ifc =3D LIST_NEXT(ifc, ifc_list); - } - - /* No match. */ - return ((struct if_clone *)NULL); - - found_name: - if (*cp =3D=3D '\0') { - i =3D -1; - } else { - for (i =3D 0; *cp !=3D '\0'; cp++) { - if (*cp < '0' || *cp > '9') { - /* Bogus unit number. */ - return (NULL); - } - i =3D (i * 10) + (*cp - '0'); - } - } - - if (unitp !=3D NULL) - *unitp =3D i; - return (ifc); -} - -/* - * Register a network interface cloner. - */ -void -if_clone_attach(struct if_clone *ifc) -{ - int bytoff, bitoff; - int err; - int len, maxclone; - int unit; - - KASSERT(ifc->ifc_minifs - 1 <=3D 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 =3D ifc->ifc_maxunit + 1; - len =3D maxclone >> 3; - if ((len << 3) < maxclone) - len++; - ifc->ifc_units =3D malloc(len, M_CLONE, M_WAITOK | M_ZERO); - ifc->ifc_bmlen =3D len; - - LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list); - if_cloners_count++; - - for (unit =3D 0; unit < ifc->ifc_minifs; unit++) { - err =3D (*ifc->ifc_create)(ifc, unit); - KASSERT(err =3D=3D 0, - ("%s: failed to create required interface %s%d", - __func__, ifc->ifc_name, unit)); - - /* Allocate the unit in the bitmap. */ - bytoff =3D unit >> 3; - bitoff =3D unit - (bytoff << 3); - ifc->ifc_units[bytoff] |=3D (1 << bitoff); - } - EVENTHANDLER_INVOKE(if_clone_event, ifc); -} - -/* - * Unregister a network interface cloner. - */ -void -if_clone_detach(struct if_clone *ifc) -{ - - LIST_REMOVE(ifc, ifc_list); - free(ifc->ifc_units, M_CLONE); - if_cloners_count--; -} - -/* - * Provide list of interface cloners to userspace. - */ -static int -if_clone_list(struct if_clonereq *ifcr) -{ - char outbuf[IFNAMSIZ], *dst; - struct if_clone *ifc; - int count, error =3D 0; - - ifcr->ifcr_total =3D if_cloners_count; - if ((dst =3D ifcr->ifcr_buffer) =3D=3D NULL) { - /* Just asking how many there are. */ - return (0); - } - - if (ifcr->ifcr_count < 0) - return (EINVAL); - - count =3D (if_cloners_count < ifcr->ifcr_count) ? - if_cloners_count : ifcr->ifcr_count; - - for (ifc =3D LIST_FIRST(&if_cloners); ifc !=3D NULL && count !=3D 0; - ifc =3D LIST_NEXT(ifc, ifc_list), count--, dst +=3D IFNAMSIZ) { - strlcpy(outbuf, ifc->ifc_name, IFNAMSIZ); - error =3D copyout(outbuf, dst, IFNAMSIZ); - if (error) - break; - } - - return (error); } =20 #define equal(a1, a2) (bcmp((a1), (a2), ((a1))->sa_len) =3D=3D 0) --- /dev/null Tue Apr 20 21:00:01 2004 +++ sys/net/if_clone.h Mon Apr 19 14:27:11 2004 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * From: @(#)if.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD$ + */ + +#ifndef _NET_IF_CLONE_H_ +#define _NET_IF_CLONE_H_ + +#ifdef _KERNEL + +#define IFC_CLONE_INITIALIZER(name, data, maxunit, \ + attach, match, create, destroy) \ + { { 0 }, name, maxunit, NULL, 0, data, attach, match, create, destroy } + +/* + * Structure describing a `cloning' interface. + * + * List of locks + * (c) const until freeing + * (d) driver specific data, may need external protection. + * (e) locked by if_cloners_mtx + * (i) locked by ifc_mtx mtx + */ +struct if_clone { + LIST_ENTRY(if_clone) ifc_list; /* (e) On list of cloners */ + const char *ifc_name; /* (c) Name of device, e.g. `gif' */ + int ifc_maxunit; /* (c) Maximum unit number */ + unsigned char *ifc_units; /* (i) Bitmap to handle units. */ + /* Considered private, access */ + /* via ifc_(alloc|free)_unit(). */ + int ifc_bmlen; /* (c) Bitmap length. */ + void *ifc_data; /* (*) Data for ifc_* functions. */ + long ifc_refcnt; /* (i) Refrence count. */ + struct mtx ifc_mtx; /* Muted to protect members. */ + + /* (c) Driver specific cloning functions. Called with no locks held. */ + void (*ifc_attach)(struct if_clone *); + int (*ifc_match)(struct if_clone *, const char *); + int (*ifc_create)(struct if_clone *, char *, size_t); + int (*ifc_destroy)(struct if_clone *, struct ifnet *); +}; + +void if_clone_init(void); +void if_clone_attach(struct if_clone *); +void if_clone_detach(struct if_clone *); + +int if_clone_create(char *, size_t); +int if_clone_destroy(const char *); +int if_clone_list(struct if_clonereq *); + +int ifc_name2unit(const char *name, int *unit); +int ifc_alloc_unit(struct if_clone *, int *); +void ifc_free_unit(struct if_clone *, int); + +/* + * The ifc_simple functions, structures, and macros implement basic + * cloning as in 5.[012]. + */ + +struct ifc_simple_data { + int ifcs_minifs; /* minimum number of interfaces */ + + int (*ifcs_create)(struct if_clone *, int); + void (*ifcs_destroy)(struct ifnet *); +}; + +/* interface clone event */ +typedef void (*if_clone_event_handler_t)(void *, struct if_clone *); +EVENTHANDLER_DECLARE(if_clone_event, if_clone_event_handler_t); + +#define IFC_SIMPLE_DECLARE(name, minifs) \ +struct ifc_simple_data name##_cloner_data =3D \ + {minifs, name##_clone_create, name##_clone_destroy}; \ +struct if_clone name##_cloner =3D \ + IFC_CLONE_INITIALIZER(#name, &name##_cloner_data, IF_MAXUNIT, \ + ifc_simple_attach, ifc_simple_match, ifc_simple_create, ifc_simple_des= troy) + +void ifc_simple_attach(struct if_clone *); +int ifc_simple_match(struct if_clone *, const char *); +int ifc_simple_create(struct if_clone *, char *, size_t); +int ifc_simple_destroy(struct if_clone *, struct ifnet *); + +#endif /* _KERNEL */ + +#endif /* !_NET_IF_CLONE_H_ */ --- /dev/null Tue Apr 20 21:00:01 2004 +++ sys/net/if_clone.c Mon Apr 19 13:30:17 2004 @@ -0,0 +1,474 @@ +/* + * Copyright (c) 1980, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if.c 8.5 (Berkeley) 1/9/95 + * $FreeBSD$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#if 0 +#include +#endif +#include +#include +#include +#include + +static void if_clone_free(struct if_clone *ifc); + +static struct mtx if_cloners_mtx; +static int if_cloners_count; +LIST_HEAD(, if_clone) if_cloners =3D LIST_HEAD_INITIALIZER(if_cloners); + +#define IF_CLONERS_LOCK_INIT() \ + mtx_init(&if_cloners_mtx, "if_cloners lock", NULL, MTX_DEF) +#define IF_CLONERS_LOCK_ASSERT() mtx_assert(&if_cloners_mtx, MA_OWNED) +#define IF_CLONERS_LOCK() mtx_lock(&if_cloners_mtx) +#define IF_CLONERS_UNLOCK() mtx_unlock(&if_cloners_mtx) + +#define IF_CLONE_LOCK_INIT(ifc) \ + mtx_init(&(ifc)->ifc_mtx, "if_clone lock", NULL, MTX_DEF) +#define IF_CLONE_LOCK_DESTROY(ifc) mtx_destroy(&(ifc)->ifc_mtx) +#define IF_CLONE_LOCK_ASSERT(ifc) mtx_assert(&(ifc)->ifc_mtx, MA_OWNED) +#define IF_CLONE_LOCK(ifc) mtx_lock(&(ifc)->ifc_mtx) +#define IF_CLONE_UNLOCK(ifc) mtx_unlock(&(ifc)->ifc_mtx) + +#define IF_CLONE_ADDREF(ifc) \ + do { \ + IF_CLONE_LOCK(ifc); \ + IF_CLONE_ADDREF_LOCKED(ifc); \ + IF_CLONE_UNLOCK(ifc); \ + } while (0) +#define IF_CLONE_ADDREF_LOCKED(ifc) \ + do { \ + IF_CLONE_LOCK_ASSERT(ifc); \ + KASSERT((ifc)->ifc_refcnt >=3D 0, \ + ("negative refcnt %ld", (ifc)->ifc_refcnt)); \ + (ifc)->ifc_refcnt++; \ + } while (0) +#define IF_CLONE_REMREF(ifc) \ + do { \ + IF_CLONE_LOCK(ifc); \ + IF_CLONE_REMREF_LOCKED(ifc); \ + } while (0) +#define IF_CLONE_REMREF_LOCKED(ifc) \ + do { \ + IF_CLONE_LOCK_ASSERT(ifc); \ + KASSERT((ifc)->ifc_refcnt > 0, \ + ("bogus refcnt %ld", (ifc)->ifc_refcnt)); \ + if (--(ifc)->ifc_refcnt =3D=3D 0) { \ + IF_CLONE_UNLOCK(ifc); \ + if_clone_free(ifc); \ + } \ + /* silently free the lock */ \ + IF_CLONE_UNLOCK(ifc); \ + } while (0) + +MALLOC_DEFINE(M_CLONE, "clone", "interface cloning framework"); + +void +if_clone_init(void) +{ + IF_CLONERS_LOCK_INIT(); +} + +/* + * Create a clone network interface. + */ +int +if_clone_create(char *name, size_t len) +{ + int err; + struct if_clone *ifc; + + if (ifunit(name) !=3D NULL) + return (EEXIST); + + /* Try to find an applicable cloner for this request */ + IF_CLONERS_LOCK(); + LIST_FOREACH(ifc, &if_cloners, ifc_list) { + if (ifc->ifc_match(ifc, name)) { + IF_CLONE_ADDREF(ifc); + break; + } + } + IF_CLONERS_UNLOCK(); + + if (ifc =3D=3D NULL) + return (EINVAL); + + err =3D (*ifc->ifc_create)(ifc, name, len); + IF_CLONE_REMREF(ifc); + return (err); +} + +/* + * Destroy a clone network interface. + */ +int +if_clone_destroy(const char *name) +{ + int err; + struct if_clone *ifc; + struct ifnet *ifp; + + ifp =3D ifunit(name); + if (ifp =3D=3D NULL) + return (ENXIO); + + /* Find the cloner for this interface */ + IF_CLONERS_LOCK(); + LIST_FOREACH(ifc, &if_cloners, ifc_list) { + if (strcmp(ifc->ifc_name, ifp->if_dname) =3D=3D 0) { + IF_CLONE_ADDREF(ifc); + break; + } + } + IF_CLONERS_UNLOCK(); + if (ifc =3D=3D NULL) + return (EINVAL); + + if (ifc->ifc_destroy =3D=3D NULL) { + err =3D EOPNOTSUPP; + goto done; + } + + err =3D (*ifc->ifc_destroy)(ifc, ifp); + +done: + IF_CLONE_REMREF(ifc); + return (err); +} + +/* + * Register a network interface cloner. + */ +void +if_clone_attach(struct if_clone *ifc) +{ + int len, maxclone; + + /* + * Compute bitmap size and allocate it. + */ + maxclone =3D ifc->ifc_maxunit + 1; + len =3D maxclone >> 3; + if ((len << 3) < maxclone) + len++; + ifc->ifc_units =3D malloc(len, M_CLONE, M_WAITOK | M_ZERO); + ifc->ifc_bmlen =3D len; + IF_CLONE_LOCK_INIT(ifc); + IF_CLONE_ADDREF(ifc); + + IF_CLONERS_LOCK(); + LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list); + if_cloners_count++; + IF_CLONERS_UNLOCK(); + + if (ifc->ifc_attach !=3D NULL) + (*ifc->ifc_attach)(ifc); + EVENTHANDLER_INVOKE(if_clone_event, ifc); +} + +/* + * Unregister a network interface cloner. + */ +void +if_clone_detach(struct if_clone *ifc) +{ + + IF_CLONERS_LOCK(); + LIST_REMOVE(ifc, ifc_list); + if_cloners_count--; + IF_CLONERS_UNLOCK(); + + IF_CLONE_REMREF(ifc); +} + +static void +if_clone_free(struct if_clone *ifc) +{ + + IF_CLONE_LOCK_DESTROY(ifc); + free(ifc->ifc_units, M_CLONE); +} + +/* + * Provide list of interface cloners to userspace. + */ +int +if_clone_list(struct if_clonereq *ifcr) +{ + char outbuf[IFNAMSIZ], *dst; + struct if_clone *ifc; + int count, err =3D 0; + + IF_CLONERS_LOCK(); + + ifcr->ifcr_total =3D if_cloners_count; + if ((dst =3D ifcr->ifcr_buffer) =3D=3D NULL) { + /* Just asking how many there are. */ + goto done; + } + + if (ifcr->ifcr_count < 0) { + err =3D EINVAL; + goto done; + } + + count =3D (if_cloners_count < ifcr->ifcr_count) ? + if_cloners_count : ifcr->ifcr_count; + + for (ifc =3D LIST_FIRST(&if_cloners); ifc !=3D NULL && count !=3D 0; + ifc =3D LIST_NEXT(ifc, ifc_list), count--, dst +=3D IFNAMSIZ) { + strlcpy(outbuf, ifc->ifc_name, IFNAMSIZ); + err =3D copyout(outbuf, dst, IFNAMSIZ); + if (err) + break; + } + +done: + IF_CLONERS_UNLOCK(); + return (err); +} + +/* + * A utility function to extract unit numbers from interface names of + * the form name###. + * + * Returns 0 on success and an error on failure. + */ +int +ifc_name2unit(const char *name, int *unit) +{ + const char *cp; + + for (cp =3D name; *cp !=3D '\0' && (*cp < '0' || *cp > '9'); cp++); + if (*cp =3D=3D '\0') { + *unit =3D -1; + } else { + for (*unit =3D 0; *cp !=3D '\0'; cp++) { + if (*cp < '0' || *cp > '9') { + /* Bogus unit number. */ + return (EINVAL); + } + *unit =3D (*unit * 10) + (*cp - '0'); + } + } + + return (0); +} + +int +ifc_alloc_unit(struct if_clone *ifc, int *unit) +{ + int wildcard, bytoff, bitoff; + int err =3D 0; + + IF_CLONE_LOCK(ifc); + + bytoff =3D bitoff =3D 0; + wildcard =3D (*unit < 0); + /* + * Find a free unit if none was given. + */ + if (wildcard) { + while ((bytoff < ifc->ifc_bmlen) + && (ifc->ifc_units[bytoff] =3D=3D 0xff)) + bytoff++; + if (bytoff >=3D ifc->ifc_bmlen) { + err =3D ENOSPC; + goto done; + } + while ((ifc->ifc_units[bytoff] & (1 << bitoff)) !=3D 0) + bitoff++; + *unit =3D (bytoff << 3) + bitoff; + } + + if (*unit > ifc->ifc_maxunit) { + err =3D ENOSPC; + goto done; + } + + if (!wildcard) { + bytoff =3D *unit >> 3; + bitoff =3D *unit - (bytoff << 3); + } + + if((ifc->ifc_units[bytoff] & (1 << bitoff)) !=3D 0) { + err =3D EEXIST; + goto done; + } + /* + * Allocate the unit in the bitmap. + */ + ifc->ifc_units[bytoff] |=3D (1 << bitoff); + +done: + IF_CLONE_UNLOCK(ifc); + return (err); +} + +void +ifc_free_unit(struct if_clone *ifc, int unit) +{ + int bytoff, bitoff; + + + /* + * Compute offset in the bitmap and deallocate the unit. + */ + bytoff =3D unit >> 3; + bitoff =3D unit - (bytoff << 3); + + IF_CLONE_LOCK(ifc); + KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) !=3D 0, + ("%s: bit is already cleared", __func__)); + ifc->ifc_units[bytoff] &=3D ~(1 << bitoff); + IF_CLONE_UNLOCK(ifc); +} + +void +ifc_simple_attach(struct if_clone *ifc) +{ + int err; + int unit; + char name[IFNAMSIZ]; + struct ifc_simple_data *ifcs =3D ifc->ifc_data; + + KASSERT(ifcs->ifcs_minifs - 1 <=3D ifc->ifc_maxunit, + ("%s: %s requested more units then allowed (%d > %d)", + __func__, ifc->ifc_name, ifcs->ifcs_minifs, + ifc->ifc_maxunit + 1)); + + for (unit =3D 0; unit < ifcs->ifcs_minifs; unit++) { + snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, unit); + err =3D (*ifc->ifc_create)(ifc, name, IFNAMSIZ); + KASSERT(err =3D=3D 0, + ("%s: failed to create required interface %s", + __func__, name)); + } +} + +int +ifc_simple_match(struct if_clone *ifc, const char *name) +{ + const char *cp; + int i; +=09 + IF_CLONE_LOCK_ASSERT(ifc); + + /* Match the name */ + for (cp =3D name, i =3D 0; i < strlen(ifc->ifc_name); i++, cp++) { + if (ifc->ifc_name[i] !=3D *cp) + return (0); + } + + /* Make sure there's a unit number or nothing after the name */ + for (; *cp !=3D '\0'; cp++) { + if (*cp < '0' || *cp > '9') + return (0); + } + + return (1); +} + +int +ifc_simple_create(struct if_clone *ifc, char *name, size_t len) +{ + char *dp; + int wildcard; + int unit; + int err; + struct ifc_simple_data *ifcs =3D ifc->ifc_data; + + err =3D ifc_name2unit(name, &unit); + if (err !=3D 0) + return (err); + + wildcard =3D (unit < 0); + + err =3D ifc_alloc_unit(ifc, &unit); + if (err !=3D 0) + return (err); + + err =3D ifcs->ifcs_create(ifc, unit); + if (err !=3D 0) { + ifc_free_unit(ifc, unit); + return (err); + } + + /* In the wildcard case, we need to update the name. */ + if (wildcard) { + for (dp =3D name; *dp !=3D '\0'; dp++); + if (snprintf(dp, len - (dp-name), "%d", unit) > + len - (dp-name) - 1) { + /* + * This can only be a programmer error and + * there's no straightforward way to recover if + * it happens. + */ + panic("if_clone_create(): interface name too long"); + } + + } + + return (0); +} + +int +ifc_simple_destroy(struct if_clone *ifc, struct ifnet *ifp) +{ + int unit; + struct ifc_simple_data *ifcs =3D ifc->ifc_data; + + unit =3D ifp->if_dunit; + + if (unit < ifcs->ifcs_minifs)=20 + return (EINVAL); + + ifcs->ifcs_destroy(ifp); + + ifc_free_unit(ifc, unit); + + return (0); +} --- ../cleanup/sys/net/if_disc.c Fri Apr 9 13:38:47 2004 +++ sys/net/if_disc.c Mon Apr 19 13:00:37 2004 @@ -45,6 +45,7 @@ #include =20 #include +#include #include #include #include @@ -75,8 +76,8 @@ static struct mtx disc_mtx; static MALLOC_DEFINE(M_DISC, DISCNAME, "Discard interface"); static LIST_HEAD(, disc_softc) disc_softc_list; -static struct if_clone disc_cloner =3D IF_CLONE_INITIALIZER(DISCNAME, - disc_clone_create, disc_clone_destroy, 0, IF_MAXUNIT); + +IFC_SIMPLE_DECLARE(disc, 0); =20 static int disc_clone_create(struct if_clone *ifc, int unit) --- ../cleanup/sys/net/if_faith.c Tue Apr 13 18:44:01 2004 +++ sys/net/if_faith.c Mon Apr 19 13:00:37 2004 @@ -55,6 +55,7 @@ #include =20 #include +#include #include #include #include @@ -103,8 +104,7 @@ static void faith_clone_destroy(struct ifnet *); static void faith_destroy(struct faith_softc *); =20 -struct if_clone faith_cloner =3D IF_CLONE_INITIALIZER(FAITHNAME, - faith_clone_create, faith_clone_destroy, 0, IF_MAXUNIT); +IFC_SIMPLE_DECLARE(faith, 0); =20 #define FAITHMTU 1500 =20 --- ../cleanup/sys/net/if_gif.c Tue Apr 13 18:44:01 2004 +++ sys/net/if_gif.c Mon Apr 19 13:00:37 2004 @@ -51,6 +51,7 @@ #include =20 #include +#include #include #include #include @@ -99,8 +100,7 @@ static int gif_clone_create(struct if_clone *, int); static void gif_clone_destroy(struct ifnet *); =20 -struct if_clone gif_cloner =3D IF_CLONE_INITIALIZER("gif", - gif_clone_create, gif_clone_destroy, 0, IF_MAXUNIT); +IFC_SIMPLE_DECLARE(gif, 0); =20 static int gifmodevent(module_t, int, void *); =20 --- ../cleanup/sys/net/if_gre.c Tue Mar 23 15:48:13 2004 +++ sys/net/if_gre.c Mon Apr 19 13:00:37 2004 @@ -62,6 +62,7 @@ =20 #include #include +#include #include #include =20 @@ -106,8 +107,7 @@ static int gre_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *rt); =20 -static struct if_clone gre_cloner =3D - IF_CLONE_INITIALIZER("gre", gre_clone_create, gre_clone_destroy, 0, IF= _MAXUNIT); +IFC_SIMPLE_DECLARE(gre, 0); =20 static int gre_compute_route(struct gre_softc *sc); =20 --- ../cleanup/sys/net/if_loop.c Tue Apr 13 18:44:01 2004 +++ sys/net/if_loop.c Mon Apr 19 13:00:37 2004 @@ -54,6 +54,7 @@ #include =20 #include +#include #include #include #include @@ -112,8 +113,7 @@ static struct mtx lo_mtx; static LIST_HEAD(lo_list, lo_softc) lo_list; =20 -struct if_clone lo_cloner =3D IF_CLONE_INITIALIZER(LONAME, - lo_clone_create, lo_clone_destroy, 1, IF_MAXUNIT); +IFC_SIMPLE_DECLARE(lo, 1); =20 static void lo_clone_destroy(ifp) --- ../cleanup/sys/net/if_ppp.c Sun Apr 18 22:18:25 2004 +++ sys/net/if_ppp.c Mon Apr 19 13:00:37 2004 @@ -97,6 +97,7 @@ #include =20 #include +#include #include #include #include @@ -157,8 +158,7 @@ static int ppp_clone_create(struct if_clone *, int); static void ppp_clone_destroy(struct ifnet *); =20 -static struct if_clone ppp_cloner =3D IF_CLONE_INITIALIZER(PPPNAME, - ppp_clone_create, ppp_clone_destroy, 0, IF_MAXUNIT); +IFC_SIMPLE_DECLARE(ppp, 0); =20 /* * Some useful mbuf macros not in mbuf.h. --- ../cleanup/sys/net/if_stf.c Sun Apr 18 22:18:25 2004 +++ sys/net/if_stf.c Sun Apr 18 22:19:33 2004 @@ -93,6 +93,7 @@ #include =20 #include +#include #include #include #include @@ -118,6 +119,7 @@ #include =20 #define STFNAME "stf" +#define STFUNIT 0 =20 #define IN6_IS_ADDR_6TO4(x) (ntohs((x)->s6_addr16[0]) =3D=3D 0x2002) =20 @@ -159,6 +161,8 @@ &rip_usrreqs }; =20 +static char *stfnames[] =3D {"stf0", "stf", "6to4", NULL}; + static int stfmodevent(module_t, int, void *); static int stf_encapcheck(const struct mbuf *, int, int, void *); static struct in6_ifaddr *stf_getsrcifa6(struct ifnet *); @@ -172,30 +176,58 @@ static void stf_rtrequest(int, struct rtentry *, struct rt_addrinfo *); static int stf_ioctl(struct ifnet *, u_long, caddr_t); =20 -static int stf_clone_create(struct if_clone *, int); -static void stf_clone_destroy(struct ifnet *); +static int stf_clone_match(struct if_clone *, const char *); +static int stf_clone_create(struct if_clone *, char *, size_t); +static int stf_clone_destroy(struct if_clone *, struct ifnet *); +struct if_clone stf_cloner =3D IFC_CLONE_INITIALIZER(STFNAME, NULL, 0, + NULL, stf_clone_match, stf_clone_create, stf_clone_destroy); + +static int +stf_clone_match(struct if_clone *ifc, const char *name) +{ + int i; =20 -/* only one clone is currently allowed */ -struct if_clone stf_cloner =3D - IF_CLONE_INITIALIZER(STFNAME, stf_clone_create, stf_clone_destroy, 0, = 0); + for(i =3D 0; stfnames[i] !=3D NULL; i++) { + if (strcmp(stfnames[i], name) =3D=3D 0) + return (1); + } + + return (0); +} =20 static int -stf_clone_create(ifc, unit) - struct if_clone *ifc; - int unit; +stf_clone_create(struct if_clone *ifc, char *name, size_t len) { + int err, unit; struct stf_softc *sc; struct ifnet *ifp; =20 + /* + * We can only have one unit, but since unit allocation is + * already locked, we use it to keep from allocating extra + * interfaces. + */ + unit =3D STFUNIT; + err =3D ifc_alloc_unit(ifc, &unit); + if (err !=3D 0) + return (err); + sc =3D malloc(sizeof(struct stf_softc), M_STF, M_WAITOK | M_ZERO); ifp =3D &sc->sc_if; - if_initname(ifp, ifc->ifc_name, unit); + /* + * Set the name manually rather then using if_initname because + * we don't conform to the default naming convention for interfaces. + */ + strlcpy(ifp->if_xname, name, IFNAMSIZ); + ifp->if_dname =3D ifc->ifc_name; + ifp->if_dunit =3D IF_DUNIT_NONE; =20 sc->encap_cookie =3D encap_attach_func(AF_INET, IPPROTO_IPV6, stf_encapcheck, &in_stf_protosw, sc); if (sc->encap_cookie =3D=3D NULL) { if_printf(ifp, "attach failed\n"); free(sc, M_STF); + ifc_free_unit(ifc, unit); return (ENOMEM); } =20 @@ -225,9 +257,8 @@ free(sc, M_STF); } =20 -static void -stf_clone_destroy(ifp) - struct ifnet *ifp; +static int +stf_clone_destroy(struct if_clone *ifc, struct ifnet *ifp) { struct stf_softc *sc =3D (void *) ifp; =20 @@ -236,6 +267,9 @@ mtx_unlock(&stf_mtx); =20 stf_destroy(sc); + ifc_free_unit(ifc, STFUNIT); + + return (0); } =20 static int --- ../cleanup/sys/net/if_vlan.c Fri Jan 23 10:08:55 2004 +++ sys/net/if_vlan.c Tue Apr 13 18:27:20 2004 @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -116,8 +117,6 @@ #define VLAN_LOCK() mtx_lock(&ifv_mtx) #define VLAN_UNLOCK() mtx_unlock(&ifv_mtx) =20 -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); static void vlan_input(struct ifnet *ifp, struct mbuf *m); @@ -125,9 +124,16 @@ static int vlan_setmulti(struct ifnet *ifp); static int vlan_unconfig(struct ifnet *ifp); static int vlan_config(struct ifvlan *ifv, struct ifnet *p); +static int vlan_set_promisc(struct ifnet *ifp); =20 -struct if_clone vlan_cloner =3D IF_CLONE_INITIALIZER(VLANNAME, - vlan_clone_create, vlan_clone_destroy, 0, IF_MAXUNIT); +static struct ifnet *vlan_clone_match_ethertag(struct if_clone *, + const char *, int *); +static int vlan_clone_match(struct if_clone *, const char *); +static int vlan_clone_create(struct if_clone *, char *, size_t); +static int vlan_clone_destroy(struct if_clone *, struct ifnet *); + +struct if_clone vlan_cloner =3D IFC_CLONE_INITIALIZER(VLANNAME, NULL, IF_M= AXUNIT, + NULL, vlan_clone_match, vlan_clone_create, vlan_clone_destroy); =20 /* * Program our multicast filter. What we're actually doing is @@ -224,7 +230,8 @@ if_clone_detach(&vlan_cloner); vlan_input_p =3D NULL; while (!LIST_EMPTY(&ifv_list)) - vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if); + vlan_clone_destroy(&vlan_cloner, + &LIST_FIRST(&ifv_list)->ifv_if); VLAN_LOCK_DESTROY(); break; }=20 @@ -239,18 +246,117 @@ =20 DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); =20 +static struct ifnet * +vlan_clone_match_ethertag(struct if_clone *ifc, const char *name, int *tag) +{ + int t; + const char *cp; + struct ifnet *ifp; + + t =3D 0; + + /* Check for . style interface names. */ + IFNET_RLOCK(); + TAILQ_FOREACH(ifp, &ifnet, if_link) { + if (ifp->if_type !=3D IFT_ETHER) + continue; + if (strncmp(ifp->if_xname, name, strlen(ifp->if_xname)) !=3D 0) + continue; + cp =3D name + strlen(ifp->if_xname); + if (*cp !=3D '.') + continue; + for(; *cp !=3D '\0'; cp++) { + if (*cp < '0' || *cp > '9') + continue; + t =3D (t * 10) + (*cp - '0'); + } + if (tag !=3D NULL) + *tag =3D t; + break; + } + IFNET_RUNLOCK(); + + return ifp; +} + +static int +vlan_clone_match(struct if_clone *ifc, const char *name) +{ + const char *cp; + + if (vlan_clone_match_ethertag(ifc, name, NULL) !=3D NULL) + return (1); + + if (strncmp(VLANNAME, name, strlen(VLANNAME)) !=3D 0) + return (0); + for (cp =3D name + 4; *cp !=3D '\0'; cp++) { + if (*cp < '0' || *cp > '9') + return (0); + } + + return (1); +} + static int -vlan_clone_create(struct if_clone *ifc, int unit) +vlan_clone_create(struct if_clone *ifc, char *name, size_t len) { + char *dp; + int wildcard; + int unit; + int error; + int tag; + int ethertag; struct ifvlan *ifv; struct ifnet *ifp; + struct ifnet *p; + + if ((p =3D vlan_clone_match_ethertag(ifc, name, &tag)) !=3D NULL) { + ethertag =3D 1; + unit =3D -1; + wildcard =3D 0; + + /* + * Don't let the caller set up a VLAN tag with + * anything except VLID bits. + */ + if (tag & ~EVL_VLID_MASK) { + return (EINVAL); + } + } else { + ethertag =3D 0; + + error =3D ifc_name2unit(name, &unit); + if (error !=3D 0) + return (error); + + wildcard =3D (unit < 0); + } + + error =3D ifc_alloc_unit(ifc, &unit); + if (error !=3D 0) + return (error); + + /* In the wildcard case, we need to update the name. */ + if (wildcard) { + for (dp =3D name; *dp !=3D '\0'; dp++); + if (snprintf(dp, len - (dp-name), "%d", unit) > + len - (dp-name) - 1) { + panic("%s: interface name too long", __func__); + } + } =20 ifv =3D malloc(sizeof(struct ifvlan), M_VLAN, M_WAITOK | M_ZERO); ifp =3D &ifv->ifv_if; SLIST_INIT(&ifv->vlan_mc_listhead); =20 ifp->if_softc =3D ifv; - if_initname(ifp, ifc->ifc_name, unit); + /* + * Set the name manually rather then using if_initname because + * we don't conform to the default naming convention for interfaces. + */ + strlcpy(ifp->if_xname, name, IFNAMSIZ); + ifp->if_dname =3D ifc->ifc_name; + ifp->if_dunit =3D unit; /* NB: flags are not set here */ ifp->if_linkmib =3D &ifv->ifv_mib; ifp->if_linkmiblen =3D sizeof ifv->ifv_mib; @@ -270,11 +376,36 @@ LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list); VLAN_UNLOCK(); =20 + if (ethertag) { + VLAN_LOCK(); + error =3D vlan_config(ifv, p); + if (error !=3D 0) { + /* + * Since we've partialy failed, we need to back + * out all the way, otherwise userland could get + * confused. Thus, we destroy the interface. + */ + LIST_REMOVE(ifv, ifv_list); + vlan_unconfig(ifp); + VLAN_UNLOCK(); + ether_ifdetach(ifp); + free(ifv, M_VLAN); + + return (error); + } + ifv->ifv_tag =3D tag; + ifp->if_flags |=3D IFF_RUNNING; + VLAN_UNLOCK(); + + /* Update promiscuous mode, if necessary. */ + vlan_set_promisc(ifp); + } + return (0); } =20 -static void -vlan_clone_destroy(struct ifnet *ifp) +static int +vlan_clone_destroy(struct if_clone *ifc, struct ifnet *ifp) { struct ifvlan *ifv =3D ifp->if_softc; =20 @@ -286,6 +417,8 @@ ether_ifdetach(ifp); =20 free(ifv, M_VLAN); + + return (0); } =20 static void --- ../cleanup/sys/contrib/pf/net/if_pflog.c Tue Apr 13 18:44:01 2004 +++ sys/contrib/pf/net/if_pflog.c Mon Apr 19 13:00:37 2004 @@ -62,6 +62,9 @@ #endif =20 #include +#if defined(__FreeBSD__) +#include +#endif #include #include #include @@ -122,8 +125,7 @@ #ifdef __FreeBSD__ static MALLOC_DEFINE(M_PFLOG, PFLOGNAME, "Packet Filter Logging Interface"= ); static LIST_HEAD(pflog_list, pflog_softc) pflog_list; -struct if_clone pflog_cloner =3D IF_CLONE_INITIALIZER(PFLOGNAME, - pflog_clone_create, pflog_clone_destroy, 1, IF_MAXUNIT); +IFC_SIMPLE_DECLARE(pflog, 1); =20 static void pflog_clone_destroy(struct ifnet *ifp) --- ../cleanup/sys/contrib/pf/net/if_pfsync.c Tue Apr 13 18:44:01 2004 +++ sys/contrib/pf/net/if_pfsync.c Mon Apr 19 13:00:37 2004 @@ -57,6 +57,9 @@ #endif =20 #include +#if defined(__FreeBSD__) +#include +#endif #include #include #include @@ -117,8 +120,7 @@ #ifdef __FreeBSD__ static MALLOC_DEFINE(M_PFSYNC, PFSYNCNAME, "Packet Filter State Sync. Inte= rface"); static LIST_HEAD(pfsync_list, pfsync_softc) pfsync_list; -struct if_clone pfsync_cloner =3D IF_CLONE_INITIALIZER(PFSYNCNAME, - pfsync_clone_create, pfsync_clone_destroy, 1, IF_MAXUNIT); +IFC_SIMPLE_DECLARE(pfsync, 1); =20 static void pfsync_clone_destroy(struct ifnet *ifp) --=20 Any statement of the form "X is the one, true Y" is FALSE. PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4 --opJtzjQTFsWo+cga Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFAhfeUXY6L6fI4GtQRAkcpAJ41Nm5lHIdtnuMhefv2sYs+z4814QCgz6up VfL/NGiVaXjDe+44jrSzrMY= =UEwl -----END PGP SIGNATURE----- --opJtzjQTFsWo+cga--