aboutsummaryrefslogtreecommitdiff
path: root/sys/net/if_stf.c
diff options
context:
space:
mode:
authorBrooks Davis <brooks@FreeBSD.org>2004-06-22 20:13:25 +0000
committerBrooks Davis <brooks@FreeBSD.org>2004-06-22 20:13:25 +0000
commitf889d2ef8da175657081833cd39f04f0c12b1827 (patch)
treebebe9375487f298832806df2423be9c48dba04e6 /sys/net/if_stf.c
parent9eb31321cf596446b95d4432d82efef21454ac09 (diff)
downloadsrc-f889d2ef8da175657081833cd39f04f0c12b1827.tar.gz
src-f889d2ef8da175657081833cd39f04f0c12b1827.zip
Major overhaul of pseudo-interface cloning. Highlights include:
- Split the code out into if_clone.[ch]. - Locked struct if_clone. [1] - Add a per-cloner match function rather then simply matching names of the form <name><unit> and <name>. - Use the match function to allow creation of <interface>.<tag> 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 visible 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 implementation 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 incompatible IFC_CLONE_INITIALIZER and ifc_simple consumers use IFC_SIMPLE_DECLARE instead. Submitted by: Maurycy Pawlowski-Wieronski <maurycy at fouk.org> [1] Reviewed by: andre, mlaier Discussed on: net
Notes
Notes: svn path=/head/; revision=130933
Diffstat (limited to 'sys/net/if_stf.c')
-rw-r--r--sys/net/if_stf.c58
1 files changed, 46 insertions, 12 deletions
diff --git a/sys/net/if_stf.c b/sys/net/if_stf.c
index 08445508d5df..2f9eb0271c6d 100644
--- a/sys/net/if_stf.c
+++ b/sys/net/if_stf.c
@@ -94,6 +94,7 @@
#include <sys/malloc.h>
#include <net/if.h>
+#include <net/if_clone.h>
#include <net/route.h>
#include <net/netisr.h>
#include <net/if_types.h>
@@ -119,6 +120,7 @@
#include <net/bpf.h>
#define STFNAME "stf"
+#define STFUNIT 0
#define IN6_IS_ADDR_6TO4(x) (ntohs((x)->s6_addr16[0]) == 0x2002)
@@ -160,6 +162,8 @@ struct protosw in_stf_protosw =
&rip_usrreqs
};
+static char *stfnames[] = {"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 *);
@@ -173,30 +177,58 @@ static int stf_checkaddr6(struct stf_softc *, struct in6_addr *,
static void stf_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
static int stf_ioctl(struct ifnet *, u_long, caddr_t);
-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 = IFC_CLONE_INITIALIZER(STFNAME, NULL, 0,
+ NULL, stf_clone_match, stf_clone_create, stf_clone_destroy);
-/* only one clone is currently allowed */
-struct if_clone stf_cloner =
- IF_CLONE_INITIALIZER(STFNAME, stf_clone_create, stf_clone_destroy, 0, 0);
+static int
+stf_clone_match(struct if_clone *ifc, const char *name)
+{
+ int i;
+
+ for(i = 0; stfnames[i] != NULL; i++) {
+ if (strcmp(stfnames[i], name) == 0)
+ return (1);
+ }
+
+ return (0);
+}
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;
+ /*
+ * We can only have one unit, but since unit allocation is
+ * already locked, we use it to keep from allocating extra
+ * interfaces.
+ */
+ unit = STFUNIT;
+ err = ifc_alloc_unit(ifc, &unit);
+ if (err != 0)
+ return (err);
+
sc = malloc(sizeof(struct stf_softc), M_STF, M_WAITOK | M_ZERO);
ifp = &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 = ifc->ifc_name;
+ ifp->if_dunit = IF_DUNIT_NONE;
sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6,
stf_encapcheck, &in_stf_protosw, sc);
if (sc->encap_cookie == NULL) {
if_printf(ifp, "attach failed\n");
free(sc, M_STF);
+ ifc_free_unit(ifc, unit);
return (ENOMEM);
}
@@ -226,9 +258,8 @@ stf_destroy(struct stf_softc *sc)
free(sc, M_STF);
}
-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 = (void *) ifp;
@@ -237,6 +268,9 @@ stf_clone_destroy(ifp)
mtx_unlock(&stf_mtx);
stf_destroy(sc);
+ ifc_free_unit(ifc, STFUNIT);
+
+ return (0);
}
static int