diff --git a/sys/net/if_tuntap.c b/sys/net/if_tuntap.c --- a/sys/net/if_tuntap.c +++ b/sys/net/if_tuntap.c @@ -623,7 +623,8 @@ tun_destroy(struct tuntap_softc *tp) { - TUN_LOCK(tp); + TUN_LOCK_ASSERT(tp); + tp->tun_flags |= TUN_DYING; if (tp->tun_busy != 0) cv_wait_unlock(&tp->tun_cv, &tp->tun_mtx); @@ -659,6 +660,12 @@ { struct tuntap_softc *tp = ifp->if_softc; + TUN_LOCK(tp); + if (tp->tun_pid == curproc->p_pid) { + TUN_UNLOCK(tp); + return (EBUSY); + } + mtx_lock(&tunmtx); TAILQ_REMOVE(&tunhead, tp, tun_list); mtx_unlock(&tunmtx); @@ -721,6 +728,7 @@ while ((tp = TAILQ_FIRST(&tunhead)) != NULL) { TAILQ_REMOVE(&tunhead, tp, tun_list); mtx_unlock(&tunmtx); + TUN_LOCK(tp); tun_destroy(tp); mtx_lock(&tunmtx); }