From 127ead92a07efd5708211fd440a4d8117a2ba75e Mon Sep 17 00:00:00 2001 From: bms Date: Sun, 1 Apr 2007 22:02:30 +0000 Subject: [PATCH] MFC: Add a sysctl net.link.tap.up_on_open which defaults to zero; when it is non-zero, tap(4) instances will be marked IFF_UP on attach. 1.71 +6 -1 src/sys/net/if_tap.c 1.19 +8 -1 src/share/man/man4/tap.4 PR: 110383 Requested by: Frank Behrens --- share/man/man4/tap.4 | 9 ++++++++- sys/net/if_tap.c | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/share/man/man4/tap.4 b/share/man/man4/tap.4 index 98861d85b66d..86c880e4fde0 100644 --- a/share/man/man4/tap.4 +++ b/share/man/man4/tap.4 @@ -1,7 +1,7 @@ .\" $FreeBSD$ .\" Based on PR#2411 .\" -.Dd February 4, 2007 +.Dd March 19, 2007 .Os .Dt TAP 4 .Sh NAME @@ -117,6 +117,13 @@ and is restricted to the super-user, unless the variable .Va net.link.tap.user_open is non-zero. +If the +.Xr sysctl 8 +variable +.Va net.link.tap.up_on_open +is non-zero, the tunnel device will be marked +.Dq up +when the control device is opened. A .Fn read call will return an error diff --git a/sys/net/if_tap.c b/sys/net/if_tap.c index 5b8390553664..5f55d2487ff3 100644 --- a/sys/net/if_tap.c +++ b/sys/net/if_tap.c @@ -149,7 +149,8 @@ static struct cdevsw tap_cdevsw = { */ static struct mtx tapmtx; static int tapdebug = 0; /* debug flag */ -static int tapuopen = 0; /* allow user open() */ +static int tapuopen = 0; /* allow user open() */ +static int tapuponopen = 0; /* IFF_UP on open() */ static int tapdclone = 1; /* enable devfs cloning */ static SLIST_HEAD(, tap_softc) taphead; /* first device */ static struct clonedevs *tapclones; @@ -163,6 +164,8 @@ SYSCTL_NODE(_net_link, OID_AUTO, tap, CTLFLAG_RW, 0, "Ethernet tunnel software network interface"); SYSCTL_INT(_net_link_tap, OID_AUTO, user_open, CTLFLAG_RW, &tapuopen, 0, "Allow user to open /dev/tap (based on node permissions)"); +SYSCTL_INT(_net_link_tap, OID_AUTO, up_on_open, CTLFLAG_RW, &tapuponopen, 0, + "Bring interface up when /dev/tap is opened"); SYSCTL_INT(_net_link_tap, OID_AUTO, devfs_cloning, CTLFLAG_RW, &tapdclone, 0, "Enably legacy devfs interface creation"); SYSCTL_INT(_net_link_tap, OID_AUTO, debug, CTLFLAG_RW, &tapdebug, 0, ""); @@ -501,6 +504,8 @@ tapopen(struct cdev *dev, int flag, int mode, struct thread *td) s = splimp(); ifp->if_drv_flags |= IFF_DRV_RUNNING; ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + if (tapuponopen) + ifp->if_flags |= IFF_UP; splx(s); TAPDEBUG("%s is open. minor = %#x\n", ifp->if_xname, minor(dev));