summaryrefslogtreecommitdiffstats
path: root/sys/net/if_tun.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2012-10-16 13:37:54 +0000
committerglebius <glebius@FreeBSD.org>2012-10-16 13:37:54 +0000
commit05f24a6b77a43334f14f31cd33a4f3e34a418ea2 (patch)
tree0f54a9446bfe2083d3c0a3f744318b2be8a0db05 /sys/net/if_tun.c
parent745884b065065ffc8847d3ea463bf751ffcaf863 (diff)
downloadFreeBSD-src-05f24a6b77a43334f14f31cd33a4f3e34a418ea2.zip
FreeBSD-src-05f24a6b77a43334f14f31cd33a4f3e34a418ea2.tar.gz
Make the "struct if_clone" opaque to users of the cloning API. Users
now use function calls: if_clone_simple() if_clone_advanced() to initialize a cloner, instead of macros that initialize if_clone structure. Discussed with: brooks, bz, 1 year ago
Diffstat (limited to 'sys/net/if_tun.c')
-rw-r--r--sys/net/if_tun.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c
index 74e1d22..086a3c1 100644
--- a/sys/net/if_tun.c
+++ b/sys/net/if_tun.c
@@ -99,7 +99,6 @@ struct tun_softc {
#define TUN2IFP(sc) ((sc)->tun_ifp)
#define TUNDEBUG if (tundebug) if_printf
-#define TUNNAME "tun"
/*
* All mutable global variables in if_tun are locked using tunmtx, with
@@ -107,7 +106,8 @@ struct tun_softc {
* which is static after setup.
*/
static struct mtx tunmtx;
-static MALLOC_DEFINE(M_TUN, TUNNAME, "Tunnel Interface");
+static const char tunname[] = "tun";
+static MALLOC_DEFINE(M_TUN, tunname, "Tunnel Interface");
static int tundebug = 0;
static int tundclone = 1;
static struct clonedevs *tunclones;
@@ -134,8 +134,7 @@ static void tunstart(struct ifnet *);
static int tun_clone_create(struct if_clone *, int, caddr_t);
static void tun_clone_destroy(struct ifnet *);
-
-IFC_SIMPLE_DECLARE(tun, 0);
+static struct if_clone *tun_cloner;
static d_open_t tunopen;
static d_close_t tunclose;
@@ -173,7 +172,7 @@ static struct cdevsw tun_cdevsw = {
.d_ioctl = tunioctl,
.d_poll = tunpoll,
.d_kqfilter = tunkqfilter,
- .d_name = TUNNAME,
+ .d_name = tunname,
};
static int
@@ -187,9 +186,9 @@ tun_clone_create(struct if_clone *ifc, int unit, caddr_t params)
if (i) {
/* No preexisting struct cdev *, create one */
dev = make_dev(&tun_cdevsw, unit,
- UID_UUCP, GID_DIALER, 0600, "%s%d", ifc->ifc_name, unit);
+ UID_UUCP, GID_DIALER, 0600, "%s%d", tunname, unit);
}
- tuncreate(ifc->ifc_name, dev);
+ tuncreate(tunname, dev);
return (0);
}
@@ -211,9 +210,9 @@ tunclone(void *arg, struct ucred *cred, char *name, int namelen,
if (!tundclone || priv_check_cred(cred, PRIV_NET_IFCREATE, 0) != 0)
return;
- if (strcmp(name, TUNNAME) == 0) {
+ if (strcmp(name, tunname) == 0) {
u = -1;
- } else if (dev_stdclone(name, NULL, TUNNAME, &u) != 1)
+ } else if (dev_stdclone(name, NULL, tunname, &u) != 1)
return; /* Don't recognise the name */
if (u != -1 && u > IF_MAXUNIT)
return; /* Unit number too high */
@@ -290,10 +289,11 @@ tunmodevent(module_t mod, int type, void *data)
tag = EVENTHANDLER_REGISTER(dev_clone, tunclone, 0, 1000);
if (tag == NULL)
return (ENOMEM);
- if_clone_attach(&tun_cloner);
+ tun_cloner = if_clone_simple(tunname, tun_clone_create,
+ tun_clone_destroy, 0);
break;
case MOD_UNLOAD:
- if_clone_detach(&tun_cloner);
+ if_clone_detach(tun_cloner);
EVENTHANDLER_DEREGISTER(dev_clone, tag);
drain_dev_clone_events();
@@ -408,7 +408,7 @@ tunopen(struct cdev *dev, int flag, int mode, struct thread *td)
*/
tp = dev->si_drv1;
if (!tp) {
- tuncreate(TUNNAME, dev);
+ tuncreate(tunname, dev);
tp = dev->si_drv1;
}
OpenPOWER on IntegriCloud