| 614 | } |
| 615 | |
| 616 | static void |
| 617 | tun_destroy(struct tuntap_softc *tp) |
| 618 | { |
| 619 | |
| 620 | TUN_LOCK(tp); |
| 621 | tp->tun_flags |= TUN_DYING; |
| 622 | if (tp->tun_busy != 0) |
| 623 | cv_wait_unlock(&tp->tun_cv, &tp->tun_mtx); |
| 624 | else |
| 625 | TUN_UNLOCK(tp); |
| 626 | |
| 627 | CURVNET_SET(TUN2IFP(tp)->if_vnet); |
| 628 | |
| 629 | /* destroy_dev will take care of any alias. */ |
| 630 | destroy_dev(tp->tun_dev); |
| 631 | seldrain(&tp->tun_rsel); |
| 632 | knlist_clear(&tp->tun_rsel.si_note, 0); |
| 633 | knlist_destroy(&tp->tun_rsel.si_note); |
| 634 | if ((tp->tun_flags & TUN_L2) != 0) { |
| 635 | ether_ifdetach(TUN2IFP(tp)); |
| 636 | } else { |
| 637 | bpfdetach(TUN2IFP(tp)); |
| 638 | if_detach(TUN2IFP(tp)); |
| 639 | } |
| 640 | sx_xlock(&tun_ioctl_sx); |
| 641 | TUN2IFP(tp)->if_softc = NULL; |
| 642 | sx_xunlock(&tun_ioctl_sx); |
| 643 | free_unr(tp->tun_drv->unrhdr, TUN2IFP(tp)->if_dunit); |
| 644 | if_free(TUN2IFP(tp)); |
| 645 | mtx_destroy(&tp->tun_mtx); |
| 646 | cv_destroy(&tp->tun_cv); |
| 647 | free(tp, M_TUN); |
| 648 | CURVNET_RESTORE(); |
| 649 | } |
| 650 | |
| 651 | static int |
| 652 | tun_clone_destroy(struct if_clone *ifc __unused, struct ifnet *ifp) |
no test coverage detected