FreeBSD/sys/net/if_tap.c
/*
 * tapclose
 *
 * close the device - mark i/f down & delete routing info
 */
tapclose
close the device - mark i/f down & delete routing info
tapclose close the device - mark i / f down & delete routing info
static int
tapclose(struct cdev *dev, int foo, int bar, struct thread *td)
{
	struct ifaddr		*ifa;
	struct tap_softc	*tp = dev->si_drv1;
	struct ifnet		*ifp = tp->tap_ifp;
	mtx_lock(&tp->tap_mtx);
	CURVNET_SET(ifp->if_vnet);
	IF_DRAIN(&ifp->if_snd);
	if (((tp->tap_flags & TAP_VMNET) == 0) &&
	    (ifp->if_flags & (IFF_UP | IFF_LINK0)) == IFF_UP) {
		mtx_unlock(&tp->tap_mtx);
		if_down(ifp);
		mtx_lock(&tp->tap_mtx);
		if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
			ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
			mtx_unlock(&tp->tap_mtx);
			TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
				rtinit(ifa, (int)RTM_DELETE, 0);
			}
			if_purgeaddrs(ifp);
			mtx_lock(&tp->tap_mtx);
		}
	}
	if_link_state_change(ifp, LINK_STATE_DOWN);
	CURVNET_RESTORE();
	funsetown(&tp->tap_sigio);
	selwakeuppri(&tp->tap_rsel, PZERO+1);
	KNOTE_LOCKED(&tp->tap_rsel.si_note, 0);
	tp->tap_flags &= ~TAP_OPEN;
	tp->tap_pid = 0;
	mtx_unlock(&tp->tap_mtx);
	TAPDEBUG("%s is closed. minor = %#x\n", 
		ifp->if_xname, dev2unit(dev));
	return (0);
}
static int tapclose ( struct cdev * dev , int foo , int bar , struct thread * td ) { struct ifaddr * ifa ; struct tap_softc * tp = dev -> si_drv1 ; struct ifnet * ifp = tp -> tap_ifp ; mtx_lock ( & tp -> tap_mtx ) ; CURVNET_SET ( ifp -> if_vnet ) ; IF_DRAIN ( & ifp -> if_snd ) ; if ( ( ( tp -> tap_flags & TAP_VMNET ) == 0 ) && ( ifp -> if_flags & ( IFF_UP | IFF_LINK0 ) ) == IFF_UP ) { mtx_unlock ( & tp -> tap_mtx ) ; if_down ( ifp ) ; mtx_lock ( & tp -> tap_mtx ) ; if ( ifp -> if_drv_flags & IFF_DRV_RUNNING ) { ifp -> if_drv_flags &= ~ IFF_DRV_RUNNING ; mtx_unlock ( & tp -> tap_mtx ) ; TAILQ_FOREACH ( ifa , & ifp -> if_addrhead , ifa_link ) { rtinit ( ifa , ( int ) RTM_DELETE , 0 ) ; } if_purgeaddrs ( ifp ) ; mtx_lock ( & tp -> tap_mtx ) ; } } if_link_state_change ( ifp , LINK_STATE_DOWN ) ; CURVNET_RESTORE ( ) ; funsetown ( & tp -> tap_sigio ) ; selwakeuppri ( & tp -> tap_rsel , PZERO + 1 ) ; KNOTE_LOCKED ( & tp -> tap_rsel . si_note , 0 ) ; tp -> tap_flags &= ~ TAP_OPEN ; tp -> tap_pid = 0 ; mtx_unlock ( & tp -> tap_mtx ) ; TAPDEBUG ( " \n " , ifp -> if_xname , dev2unit ( dev ) ) ; return ( 0 ) ; }
tapclose
 close the device - mark i/f down & delete routing info
tapclose close the device - mark i / f down & delete routing info
/* junk all pending output */ /*
	 * Do not bring the interface down, and do not anything with
	 * interface, if we are in VMnet mode. Just close the device.
	 */