--- if_tun.c.orig 2008-06-20 16:45:07.000000000 -0700 +++ if_tun.c 2008-09-19 15:47:55.000000000 -0700 @@ -129,6 +129,7 @@ struct rtentry *rt); static void tunstart(struct ifnet *); +static int tun_clone_lookup(struct cdev **); static int tun_clone_create(struct if_clone *, int, caddr_t); static void tun_clone_destroy(struct ifnet *); @@ -174,6 +175,28 @@ }; static int +tun_clone_lookup(struct cdev **dev) +{ + struct tun_softc *tp; + + mtx_lock(&tunmtx); + TAILQ_FOREACH(tp, &tunhead, tun_list) { + mtx_lock(&tp->tun_mtx); + if ((tp->tun_flags & TUN_OPEN) == 0) { + *dev = tp->tun_dev; + mtx_unlock(&tp->tun_mtx); + mtx_unlock(&tunmtx); + + return (1); + } + mtx_unlock(&tp->tun_mtx); + } + mtx_unlock(&tunmtx); + + return (0); +} + +static int tun_clone_create(struct if_clone *ifc, int unit, caddr_t params) { struct cdev *dev; @@ -213,6 +236,11 @@ return; if (strcmp(name, TUNNAME) == 0) { + if (tun_clone_lookup(dev)) { + dev_ref(*dev); + return; + } + u = -1; } else if (dev_stdclone(name, NULL, TUNNAME, &u) != 1) return; /* Don't recognise the name */