summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2007-01-26 10:58:48 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2007-01-26 10:58:48 +0000
commit8008a0b76cc510a89151340b4a79b7ce4c88f53f (patch)
treeeee0f8d94ec62355a71b0dafbb688c9621b42353 /sys
parent3aa7488d4a8e9e1ce78e70c4f64262159b31d851 (diff)
When switching mode inherit the TUN_NBIO and TUN_ASYNC flags and clear
these flags on close. OK mpf@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if_tun.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c
index f10e7b4fb13..6659acbde69 100644
--- a/sys/net/if_tun.c
+++ b/sys/net/if_tun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_tun.c,v 1.81 2006/11/10 09:34:39 claudio Exp $ */
+/* $OpenBSD: if_tun.c,v 1.82 2007/01/26 10:58:47 claudio Exp $ */
/* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */
/*
@@ -274,25 +274,21 @@ tun_switch(struct tun_softc *tp, int flags)
/* tp will be removed so store unit number */
unit = tp->tun_unit;
- open = tp->tun_flags & TUN_OPEN;
+ open = tp->tun_flags & (TUN_OPEN|TUN_NBIO|TUN_ASYNC);
TUNDEBUG(("%s: switching to layer %d\n", ifp->if_xname,
flags & TUN_LAYER2 ? 2 : 3));
- /*
- * remove old device
- */
+ /* remove old device and ... */
tun_clone_destroy(ifp);
-
- /*
- * attach new interface
- */
+ /* attach new interface */
r = tun_create(&tun_cloner, unit, flags);
+
if (open && r == 0) {
/* already opened before ifconfig tunX link0 */
if ((tp = tun_lookup(unit)) == NULL)
/* this should never fail */
return (ENXIO);
- tp->tun_flags |= TUN_OPEN;
+ tp->tun_flags |= open;
TUNDEBUG(("%s: already open\n", tp->tun_if.if_xname));
}
return (r);
@@ -354,7 +350,8 @@ tunclose(dev_t dev, int flag, int mode, struct proc *p)
return (ENXIO);
ifp = &tp->tun_if;
- tp->tun_flags &= ~TUN_OPEN;
+ tp->tun_flags &= ~(TUN_OPEN|TUN_NBIO|TUN_ASYNC);
+ ifp->if_flags &= ~IFF_RUNNING;
/*
* junk all pending output