FreeBSD/sys/net/if_tap.c
/*
 * tapopen
 *
 * to open tunnel. must be superuser
 */
tapopen
to open tunnel. must be superuser
tapopen to open tunnel . must be superuser
static int
tapopen(struct cdev *dev, int flag, int mode, struct thread *td)
{
	struct tap_softc	*tp = NULL;
	struct ifnet		*ifp = NULL;
	int			 error;
	if (tapuopen == 0) {
		error = priv_check(td, PRIV_NET_TAP);
		if (error)
			return (error);
	}
	if ((dev2unit(dev) & CLONE_UNITMASK) > TAPMAXUNIT)
		return (ENXIO);
	tp = dev->si_drv1;
	mtx_lock(&tp->tap_mtx);
	if (tp->tap_flags & TAP_OPEN) {
		mtx_unlock(&tp->tap_mtx);
		return (EBUSY);
	}
	bcopy(IF_LLADDR(tp->tap_ifp), tp->ether_addr, sizeof(tp->ether_addr));
	tp->tap_pid = td->td_proc->p_pid;
	tp->tap_flags |= TAP_OPEN;
	ifp = tp->tap_ifp;
	ifp->if_drv_flags |= IFF_DRV_RUNNING;
	ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
	if (tapuponopen)
		ifp->if_flags |= IFF_UP;
	if_link_state_change(ifp, LINK_STATE_UP);
	mtx_unlock(&tp->tap_mtx);
	TAPDEBUG("%s is open. minor = %#x\n", ifp->if_xname, dev2unit(dev));
	return (0);
}
static int tapopen ( struct cdev * dev , int flag , int mode , struct thread * td ) { struct tap_softc * tp = NULL ; struct ifnet * ifp = NULL ; int error ; if ( tapuopen == 0 ) { error = priv_check ( td , PRIV_NET_TAP ) ; if ( error ) return ( error ) ; } if ( ( dev2unit ( dev ) & CLONE_UNITMASK ) > TAPMAXUNIT ) return ( ENXIO ) ; tp = dev -> si_drv1 ; mtx_lock ( & tp -> tap_mtx ) ; if ( tp -> tap_flags & TAP_OPEN ) { mtx_unlock ( & tp -> tap_mtx ) ; return ( EBUSY ) ; } bcopy ( IF_LLADDR ( tp -> tap_ifp ) , tp -> ether_addr , sizeof ( tp -> ether_addr ) ) ; tp -> tap_pid = td -> td_proc -> p_pid ; tp -> tap_flags |= TAP_OPEN ; ifp = tp -> tap_ifp ; ifp -> if_drv_flags |= IFF_DRV_RUNNING ; ifp -> if_drv_flags &= ~ IFF_DRV_OACTIVE ; if ( tapuponopen ) ifp -> if_flags |= IFF_UP ; if_link_state_change ( ifp , LINK_STATE_UP ) ; mtx_unlock ( & tp -> tap_mtx ) ; TAPDEBUG ( " \n " , ifp -> if_xname , dev2unit ( dev ) ) ; return ( 0 ) ; }
tapopen
 to open tunnel.
tapopen to open tunnel .