From 65a24520bd592fb38128985ab0600a6ea936f105 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Fri, 11 Jan 2008 11:59:41 +0000 Subject: [PATCH] - Split if_clone.c out of if.c, license in if.c is attached to if_clone.c - Split if_clone.h out of if.h and if_var.h, license of if_var.h is attached to if_clone.h - Staticize some variables and function in if_clone.c - if_clonereq is the only userland visible structure related to this commit; it is kept in if.h for now, so userland application won't be aware of this commit. It will be moved to net/if_clone.h No functional changes. # if_clone.c is subjected to change to support clone creation with # additional parameters. --- sys/conf/files | 3 +- sys/net/bridge/if_bridge.c | 3 +- sys/net/faith/if_faith.c | 3 +- sys/net/gif/if_gif.c | 3 +- sys/net/gre/if_gre.c | 3 +- sys/net/if.c | 252 +-------------------------------------- sys/net/if.h | 25 +--- sys/net/if_clone.c | 289 +++++++++++++++++++++++++++++++++++++++++++++ sys/net/if_clone.h | 81 +++++++++++++ sys/net/if_var.h | 11 +- sys/net/pf/pfvar.h | 3 +- sys/net/vlan/if_vlan.c | 3 +- sys/netinet/ip_carp.c | 3 +- 13 files changed, 392 insertions(+), 290 deletions(-) create mode 100644 sys/net/if_clone.c create mode 100644 sys/net/if_clone.h diff --git a/sys/conf/files b/sys/conf/files index 9370d5108a..19a5dc3d03 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,5 +1,5 @@ # $FreeBSD: src/sys/conf/files,v 1.340.2.137 2003/06/04 17:10:30 sam Exp $ -# $DragonFly: src/sys/conf/files,v 1.197 2007/12/29 13:40:28 swildner Exp $ +# $DragonFly: src/sys/conf/files,v 1.198 2008/01/11 11:59:40 sephe Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -698,6 +698,7 @@ net/bridge/if_bridge.c optional bridge net/bridge/bridgestp.c optional bridge net/bsd_comp.c optional ppp_bsdcomp net/if.c standard +net/if_clone.c standard net/if_atmsubr.c optional atm net/disc/if_disc.c optional disc net/ef/if_ef.c optional ef diff --git a/sys/net/bridge/if_bridge.c b/sys/net/bridge/if_bridge.c index 229719f367..5811e7a891 100644 --- a/sys/net/bridge/if_bridge.c +++ b/sys/net/bridge/if_bridge.c @@ -66,7 +66,7 @@ * $OpenBSD: if_bridge.c,v 1.60 2001/06/15 03:38:33 itojun Exp $ * $NetBSD: if_bridge.c,v 1.31 2005/06/01 19:45:34 jdc Exp $ * $FreeBSD: src/sys/net/if_bridge.c,v 1.26 2005/10/13 23:05:55 thompsa Exp $ - * $DragonFly: src/sys/net/bridge/if_bridge.c,v 1.27 2008/01/06 16:55:52 swildner Exp $ + * $DragonFly: src/sys/net/bridge/if_bridge.c,v 1.28 2008/01/11 11:59:40 sephe Exp $ */ /* @@ -111,6 +111,7 @@ #include #include #include +#include #include /* for struct arpcom */ #include diff --git a/sys/net/faith/if_faith.c b/sys/net/faith/if_faith.c index fda9cae22c..1fe2f28295 100644 --- a/sys/net/faith/if_faith.c +++ b/sys/net/faith/if_faith.c @@ -33,7 +33,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_faith.c,v 1.3.2.6 2002/04/28 05:40:25 suz Exp $ - * $DragonFly: src/sys/net/faith/if_faith.c,v 1.17 2008/01/05 14:02:38 swildner Exp $ + * $DragonFly: src/sys/net/faith/if_faith.c,v 1.18 2008/01/11 11:59:40 sephe Exp $ */ /* * derived from @@ -68,6 +68,7 @@ #include #include #include +#include #ifdef INET #include diff --git a/sys/net/gif/if_gif.c b/sys/net/gif/if_gif.c index 13c1dec50f..77225df756 100644 --- a/sys/net/gif/if_gif.c +++ b/sys/net/gif/if_gif.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_gif.c,v 1.4.2.15 2002/11/08 16:57:13 ume Exp $ - * $DragonFly: src/sys/net/gif/if_gif.c,v 1.19 2008/01/05 14:02:38 swildner Exp $ + * $DragonFly: src/sys/net/gif/if_gif.c,v 1.20 2008/01/11 11:59:41 sephe Exp $ * $KAME: if_gif.c,v 1.87 2001/10/19 08:50:27 itojun Exp $ */ @@ -57,6 +57,7 @@ #include #include #include +#include #include #include diff --git a/sys/net/gre/if_gre.c b/sys/net/gre/if_gre.c index f8b64e41b8..2405d2eefc 100644 --- a/sys/net/gre/if_gre.c +++ b/sys/net/gre/if_gre.c @@ -1,6 +1,6 @@ /* $NetBSD: if_gre.c,v 1.42 2002/08/14 00:23:27 itojun Exp $ */ /* $FreeBSD: src/sys/net/if_gre.c,v 1.9.2.3 2003/01/23 21:06:44 sam Exp $ */ -/* $DragonFly: src/sys/net/gre/if_gre.c,v 1.19 2006/12/22 23:44:55 swildner Exp $ */ +/* $DragonFly: src/sys/net/gre/if_gre.c,v 1.20 2008/01/11 11:59:41 sephe Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -68,6 +68,7 @@ #include #include #include +#include #ifdef INET #include diff --git a/sys/net/if.c b/sys/net/if.c index 0b629ee3f5..d830ddf281 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -32,7 +32,7 @@ * * @(#)if.c 8.3 (Berkeley) 1/4/94 * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $ - * $DragonFly: src/sys/net/if.c,v 1.59 2007/12/31 04:58:53 sephe Exp $ + * $DragonFly: src/sys/net/if.c,v 1.60 2008/01/11 11:59:40 sephe Exp $ */ #include "opt_compat.h" @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -66,10 +67,9 @@ #include #include #include +#include #include -#include - #if defined(INET) || defined(INET6) /*XXX*/ #include @@ -113,9 +113,6 @@ static int if_rtdel(struct radix_node *, void *); extern void nd6_setmtu(struct ifnet *); #endif -struct if_clone *if_clone_lookup(const char *, int *); -int if_clone_list(struct if_clonereq *); - SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); @@ -123,14 +120,10 @@ SYSINIT(interfaces, SI_SUB_PROTO_IF, SI_ORDER_FIRST, ifinit, NULL) 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"); int ifqmaxlen = IFQ_MAXLEN; struct ifnethead ifnet = TAILQ_HEAD_INITIALIZER(ifnet); -LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners); -int if_cloners_count; - struct callout if_slowtimo_timer; int if_index = 0; @@ -486,245 +479,6 @@ if_rtdel(struct radix_node *rn, void *arg) } /* - * 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 = if_clone_lookup(name, &unit); - if (ifc == NULL) - return (EINVAL); - - if (ifunit(name) != NULL) - return (EEXIST); - - bytoff = bitoff = 0; - wildcard = (unit < 0); - /* - * Find a free unit if none was given. - */ - if (wildcard) { - while (bytoff < ifc->ifc_bmlen && - ifc->ifc_units[bytoff] == 0xff) - bytoff++; - if (bytoff >= ifc->ifc_bmlen) - return (ENOSPC); - while ((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0) - bitoff++; - unit = (bytoff << 3) + bitoff; - } - - if (unit > ifc->ifc_maxunit) - return (ENXIO); - - err = (*ifc->ifc_create)(ifc, unit); - if (err != 0) - return (err); - - if (!wildcard) { - bytoff = unit >> 3; - bitoff = unit - (bytoff << 3); - } - - /* - * Allocate the unit in the bitmap. - */ - KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) == 0, - ("%s: bit is already set", __func__)); - ifc->ifc_units[bytoff] |= (1 << bitoff); - - /* In the wildcard case, we need to update the name. */ - if (wildcard) { - for (dp = name; *dp != '\0'; dp++); - if (ksnprintf(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"); - } - - } - - EVENTHANDLER_INVOKE(if_clone_event, ifc); - - 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; - - 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); - - if (ifc->ifc_destroy == NULL) - return (EOPNOTSUPP); - - (*ifc->ifc_destroy)(ifp); - - /* - * Compute offset in the bitmap and deallocate the unit. - */ - bytoff = unit >> 3; - bitoff = unit - (bytoff << 3); - KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0, - ("%s: bit is already cleared", __func__)); - ifc->ifc_units[bytoff] &= ~(1 << bitoff); - return (0); -} - -/* - * Look up a network interface cloner. - */ -struct if_clone * -if_clone_lookup(const char *name, int *unitp) -{ - struct if_clone *ifc; - const char *cp; - int i; - - for (ifc = LIST_FIRST(&if_cloners); ifc != NULL;) { - for (cp = name, i = 0; i < ifc->ifc_namelen; i++, cp++) { - if (ifc->ifc_name[i] != *cp) - goto next_ifc; - } - goto found_name; - next_ifc: - ifc = LIST_NEXT(ifc, ifc_list); - } - - /* No match. */ - return ((struct if_clone *)NULL); - - found_name: - if (*cp == '\0') { - i = -1; - } else { - for (i = 0; *cp != '\0'; cp++) { - if (*cp < '0' || *cp > '9') { - /* Bogus unit number. */ - return (NULL); - } - i = (i * 10) + (*cp - '0'); - } - } - - if (unitp != NULL) - *unitp = 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 <= 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 = ifc->ifc_maxunit + 1; - len = maxclone >> 3; - if ((len << 3) < maxclone) - len++; - ifc->ifc_units = kmalloc(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); - } -} - -/* - * Unregister a network interface cloner. - */ -void -if_clone_detach(struct if_clone *ifc) -{ - - LIST_REMOVE(ifc, ifc_list); - kfree(ifc->ifc_units, M_CLONE); - if_cloners_count--; -} - -/* - * 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, error = 0; - - ifcr->ifcr_total = if_cloners_count; - if ((dst = ifcr->ifcr_buffer) == NULL) { - /* Just asking how many there are. */ - return (0); - } - - if (ifcr->ifcr_count < 0) - return (EINVAL); - - count = (if_cloners_count < ifcr->ifcr_count) ? - if_cloners_count : ifcr->ifcr_count; - - for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0; - ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) { - strlcpy(outbuf, ifc->ifc_name, IFNAMSIZ); - error = copyout(outbuf, dst, IFNAMSIZ); - if (error) - break; - } - - return (error); -} - -/* * Locate an interface based on a complete address. */ struct ifaddr * diff --git a/sys/net/if.h b/sys/net/if.h index 2e0ab180b2..971c14f53d 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -32,7 +32,7 @@ * * @(#)if.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if.h,v 1.58.2.9 2002/08/30 14:23:38 sobomax Exp $ - * $DragonFly: src/sys/net/if.h,v 1.19 2007/09/30 04:37:27 sephe Exp $ + * $DragonFly: src/sys/net/if.h,v 1.20 2008/01/11 11:59:40 sephe Exp $ */ #ifndef _NET_IF_H_ @@ -73,31 +73,10 @@ struct ifnet; #define IF_NAMESIZE IFNAMSIZ #define IF_MAXUNIT 0x7fff /* if_unit is 15bits */ -#ifdef _KERNEL -/* - * Structure describing a `cloning' interface. - */ -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); - void (*ifc_destroy)(struct ifnet *); -}; - -#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) \ - { { 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy } -#endif - /* * Structure used to query names of interface cloners. + * XXX should be moved to net/if_clone.h */ - struct if_clonereq { int ifcr_total; /* total cloners (out) */ int ifcr_count; /* room for this many in user buffer */ diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c new file mode 100644 index 0000000000..79f746844a --- /dev/null +++ b/sys/net/if_clone.c @@ -0,0 +1,289 @@ +/* + * 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 PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * 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, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if.c 8.3 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $ + * $DragonFly: src/sys/net/if_clone.c,v 1.1 2008/01/11 11:59:40 sephe Exp $ + */ + +#include +#include +#include + +#include +#include + +static LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners); +static int if_cloners_count; + +MALLOC_DEFINE(M_CLONE, "clone", "interface cloning framework"); + +static struct if_clone *if_clone_lookup(const char *, int *); + +/* + * 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 = if_clone_lookup(name, &unit); + if (ifc == NULL) + return (EINVAL); + + if (ifunit(name) != NULL) + return (EEXIST); + + bytoff = bitoff = 0; + wildcard = (unit < 0); + /* + * Find a free unit if none was given. + */ + if (wildcard) { + while (bytoff < ifc->ifc_bmlen && + ifc->ifc_units[bytoff] == 0xff) + bytoff++; + if (bytoff >= ifc->ifc_bmlen) + return (ENOSPC); + while ((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0) + bitoff++; + unit = (bytoff << 3) + bitoff; + } + + if (unit > ifc->ifc_maxunit) + return (ENXIO); + + err = (*ifc->ifc_create)(ifc, unit); + if (err != 0) + return (err); + + if (!wildcard) { + bytoff = unit >> 3; + bitoff = unit - (bytoff << 3); + } + + /* + * Allocate the unit in the bitmap. + */ + KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) == 0, + ("%s: bit is already set", __func__)); + ifc->ifc_units[bytoff] |= (1 << bitoff); + + /* In the wildcard case, we need to update the name. */ + if (wildcard) { + for (dp = name; *dp != '\0'; dp++); + if (ksnprintf(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"); + } + + } + + EVENTHANDLER_INVOKE(if_clone_event, ifc); + + 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; + + 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); + + if (ifc->ifc_destroy == NULL) + return (EOPNOTSUPP); + + (*ifc->ifc_destroy)(ifp); + + /* + * Compute offset in the bitmap and deallocate the unit. + */ + bytoff = unit >> 3; + bitoff = unit - (bytoff << 3); + KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0, + ("%s: bit is already cleared", __func__)); + ifc->ifc_units[bytoff] &= ~(1 << bitoff); + return (0); +} + +/* + * 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 <= 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 = ifc->ifc_maxunit + 1; + len = maxclone >> 3; + if ((len << 3) < maxclone) + len++; + ifc->ifc_units = kmalloc(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); + } +} + +/* + * Unregister a network interface cloner. + */ +void +if_clone_detach(struct if_clone *ifc) +{ + + LIST_REMOVE(ifc, ifc_list); + kfree(ifc->ifc_units, M_CLONE); + if_cloners_count--; +} + +/* + * 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, error = 0; + + ifcr->ifcr_total = if_cloners_count; + if ((dst = ifcr->ifcr_buffer) == NULL) { + /* Just asking how many there are. */ + return (0); + } + + if (ifcr->ifcr_count < 0) + return (EINVAL); + + count = (if_cloners_count < ifcr->ifcr_count) ? + if_cloners_count : ifcr->ifcr_count; + + for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0; + ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) { + strlcpy(outbuf, ifc->ifc_name, IFNAMSIZ); + error = copyout(outbuf, dst, IFNAMSIZ); + if (error) + break; + } + + return (error); +} + +/* + * 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 = LIST_FIRST(&if_cloners); ifc != NULL;) { + for (cp = name, i = 0; i < ifc->ifc_namelen; i++, cp++) { + if (ifc->ifc_name[i] != *cp) + goto next_ifc; + } + goto found_name; + next_ifc: + ifc = LIST_NEXT(ifc, ifc_list); + } + + /* No match. */ + return ((struct if_clone *)NULL); + + found_name: + if (*cp == '\0') { + i = -1; + } else { + for (i = 0; *cp != '\0'; cp++) { + if (*cp < '0' || *cp > '9') { + /* Bogus unit number. */ + return (NULL); + } + i = (i * 10) + (*cp - '0'); + } + } + + if (unitp != NULL) + *unitp = i; + return (ifc); +} diff --git a/sys/net/if_clone.h b/sys/net/if_clone.h new file mode 100644 index 0000000000..ee4d19eece --- /dev/null +++ b/sys/net/if_clone.h @@ -0,0 +1,81 @@ +/* + * 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 PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * 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, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * 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: src/sys/net/if_var.h,v 1.18.2.16 2003/04/15 18:11:19 fjoe Exp $ + * $FreeBSD: src/sys/net/if.h,v 1.58.2.9 2002/08/30 14:23:38 sobomax Exp $ + * $DragonFly: src/sys/net/if_clone.h,v 1.1 2008/01/11 11:59:40 sephe Exp $ + */ + +#ifndef _NET_IF_CLONE_H_ +#define _NET_IF_CLONE_H_ + +#ifdef _KERNEL + +#ifndef _SYS_QUEUE_H_ +#include +#endif + +/* + * Structure describing a `cloning' interface. + */ +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); + void (*ifc_destroy)(struct ifnet *); +}; + +#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) \ +{ { 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy } + +/* interface clone event */ +typedef void (*if_clone_event_handler_t)(void *, struct if_clone *); +EVENTHANDLER_DECLARE(if_clone_event, if_clone_event_handler_t); + +struct if_clonereq; /* XXX, should move definition from net/if.h */ + +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 *); +int if_clone_list(struct if_clonereq *); + +#endif /* _KERNEL */ + +#endif /* !_NET_IF_CLONE_H_ */ diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 5efe27a8bd..4413d7d84a 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -32,7 +32,7 @@ * * From: @(#)if.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.16 2003/04/15 18:11:19 fjoe Exp $ - * $DragonFly: src/sys/net/if_var.h,v 1.43 2007/12/31 04:58:53 sephe Exp $ + * $DragonFly: src/sys/net/if_var.h,v 1.44 2008/01/11 11:59:40 sephe Exp $ */ #ifndef _NET_IF_VAR_H_ @@ -421,9 +421,6 @@ EVENTHANDLER_DECLARE(ifnet_attach_event, ifnet_attach_event_handler_t); /* interface detach event */ typedef void (*ifnet_detach_event_handler_t)(void *, struct ifnet *); EVENTHANDLER_DECLARE(ifnet_detach_event, ifnet_detach_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); static __inline void IFAREF(struct ifaddr *_ifa) @@ -492,12 +489,6 @@ struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *); 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 *); - #define IF_LLSOCKADDR(ifp) \ ((struct sockaddr_dl *)(ifp)->if_lladdr->ifa_addr) #define IF_LLADDR(ifp) LLADDR(IF_LLSOCKADDR(ifp)) diff --git a/sys/net/pf/pfvar.h b/sys/net/pf/pfvar.h index 8d9c3a1358..4c2a335104 100644 --- a/sys/net/pf/pfvar.h +++ b/sys/net/pf/pfvar.h @@ -1,7 +1,7 @@ /* $FreeBSD: src/sys/contrib/pf/net/pfvar.h,v 1.8 2004/08/12 13:59:44 mlaier Exp $ */ /* $OpenBSD: pfvar.h,v 1.187 2004/03/22 04:54:18 mcbride Exp $ */ /* add $OpenBSD: pfvar.h,v 1.194 2004/05/11 07:34:11 dhartmei Exp $ */ -/* $DragonFly: src/sys/net/pf/pfvar.h,v 1.3 2005/06/15 16:32:58 joerg Exp $ */ +/* $DragonFly: src/sys/net/pf/pfvar.h,v 1.4 2008/01/11 11:59:41 sephe Exp $ */ /* * Copyright (c) 2004 The DragonFly Project. All rights reserved. @@ -43,6 +43,7 @@ #include #include +#include #include #ifdef _KERNEL diff --git a/sys/net/vlan/if_vlan.c b/sys/net/vlan/if_vlan.c index 154b1f576e..530f38db87 100644 --- a/sys/net/vlan/if_vlan.c +++ b/sys/net/vlan/if_vlan.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_vlan.c,v 1.15.2.13 2003/02/14 22:25:58 fenner Exp $ - * $DragonFly: src/sys/net/vlan/if_vlan.c,v 1.25 2007/10/13 09:43:19 sephe Exp $ + * $DragonFly: src/sys/net/vlan/if_vlan.c,v 1.26 2008/01/11 11:59:41 sephe Exp $ */ /* @@ -80,6 +80,7 @@ #include #include #include +#include #include "if_vlan_var.h" #ifdef INET diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index e3806763cd..fb471956bd 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -25,7 +25,7 @@ */ /* * $FreeBSD: src/sys/netinet/ip_carp.c,v 1.48 2007/02/02 09:39:09 glebius Exp $ - * $DragonFly: src/sys/netinet/ip_carp.c,v 1.5 2008/01/06 16:55:52 swildner Exp $ + * $DragonFly: src/sys/netinet/ip_carp.c,v 1.6 2008/01/11 11:59:40 sephe Exp $ */ #include "opt_carp.h" @@ -61,6 +61,7 @@ #include #include #include +#include #ifdef INET #include -- 2.11.4.GIT