Changeset View
Changeset View
Standalone View
Standalone View
sys/net/if_tuntap.c
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | |||||
struct tuntap_softc { | struct tuntap_softc { | ||||
TAILQ_ENTRY(tuntap_softc) tun_list; | TAILQ_ENTRY(tuntap_softc) tun_list; | ||||
struct cdev *tun_alias; | struct cdev *tun_alias; | ||||
struct cdev *tun_dev; | struct cdev *tun_dev; | ||||
u_short tun_flags; /* misc flags */ | u_short tun_flags; /* misc flags */ | ||||
#define TUN_OPEN 0x0001 | #define TUN_OPEN 0x0001 | ||||
#define TUN_INITED 0x0002 | #define TUN_INITED 0x0002 | ||||
#define TUN_UNUSED1 0x0008 | #define TUN_UNUSED1 0x0008 | ||||
#define TUN_DSTADDR 0x0010 | #define TUN_UNUSED2 0x0010 | ||||
#define TUN_LMODE 0x0020 | #define TUN_LMODE 0x0020 | ||||
#define TUN_RWAIT 0x0040 | #define TUN_RWAIT 0x0040 | ||||
#define TUN_ASYNC 0x0080 | #define TUN_ASYNC 0x0080 | ||||
#define TUN_IFHEAD 0x0100 | #define TUN_IFHEAD 0x0100 | ||||
#define TUN_DYING 0x0200 | #define TUN_DYING 0x0200 | ||||
#define TUN_L2 0x0400 | #define TUN_L2 0x0400 | ||||
#define TUN_VMNET 0x0800 | #define TUN_VMNET 0x0800 | ||||
▲ Show 20 Lines • Show All 1,020 Lines • ▼ Show 20 Lines | tundtor(void *data) | ||||
if (ifp->if_flags & IFF_UP) { | if (ifp->if_flags & IFF_UP) { | ||||
TUN_UNLOCK(tp); | TUN_UNLOCK(tp); | ||||
if_down(ifp); | if_down(ifp); | ||||
TUN_LOCK(tp); | TUN_LOCK(tp); | ||||
} | } | ||||
/* Delete all addresses and routes which reference this interface. */ | /* Delete all addresses and routes which reference this interface. */ | ||||
if (ifp->if_drv_flags & IFF_DRV_RUNNING) { | if (ifp->if_drv_flags & IFF_DRV_RUNNING) { | ||||
struct ifaddr *ifa; | |||||
ifp->if_drv_flags &= ~IFF_DRV_RUNNING; | ifp->if_drv_flags &= ~IFF_DRV_RUNNING; | ||||
TUN_UNLOCK(tp); | TUN_UNLOCK(tp); | ||||
CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { | |||||
/* deal w/IPv4 PtP destination; unlocked read */ | |||||
if (!l2tun && ifa->ifa_addr->sa_family == AF_INET) { | |||||
rtinit(ifa, (int)RTM_DELETE, | |||||
tp->tun_flags & TUN_DSTADDR ? RTF_HOST : 0); | |||||
} else { | |||||
rtinit(ifa, (int)RTM_DELETE, 0); | |||||
} | |||||
} | |||||
if_purgeaddrs(ifp); | if_purgeaddrs(ifp); | ||||
TUN_LOCK(tp); | TUN_LOCK(tp); | ||||
} | } | ||||
out: | out: | ||||
if_link_state_change(ifp, LINK_STATE_DOWN); | if_link_state_change(ifp, LINK_STATE_DOWN); | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
funsetown(&tp->tun_sigio); | funsetown(&tp->tun_sigio); | ||||
selwakeuppri(&tp->tun_rsel, PZERO + 1); | selwakeuppri(&tp->tun_rsel, PZERO + 1); | ||||
KNOTE_LOCKED(&tp->tun_rsel.si_note, 0); | KNOTE_LOCKED(&tp->tun_rsel.si_note, 0); | ||||
TUNDEBUG (ifp, "closed\n"); | TUNDEBUG (ifp, "closed\n"); | ||||
tp->tun_flags &= ~TUN_OPEN; | tp->tun_flags &= ~TUN_OPEN; | ||||
tp->tun_pid = 0; | tp->tun_pid = 0; | ||||
tun_vnethdr_set(ifp, 0); | tun_vnethdr_set(ifp, 0); | ||||
tun_unbusy_locked(tp); | tun_unbusy_locked(tp); | ||||
TUN_UNLOCK(tp); | TUN_UNLOCK(tp); | ||||
} | } | ||||
static void | static void | ||||
tuninit(struct ifnet *ifp) | tuninit(struct ifnet *ifp) | ||||
{ | { | ||||
struct tuntap_softc *tp = ifp->if_softc; | struct tuntap_softc *tp = ifp->if_softc; | ||||
#ifdef INET | |||||
struct epoch_tracker et; | |||||
struct ifaddr *ifa; | |||||
#endif | |||||
TUNDEBUG(ifp, "tuninit\n"); | TUNDEBUG(ifp, "tuninit\n"); | ||||
TUN_LOCK(tp); | TUN_LOCK(tp); | ||||
ifp->if_drv_flags |= IFF_DRV_RUNNING; | ifp->if_drv_flags |= IFF_DRV_RUNNING; | ||||
if ((tp->tun_flags & TUN_L2) == 0) { | if ((tp->tun_flags & TUN_L2) == 0) { | ||||
ifp->if_flags |= IFF_UP; | ifp->if_flags |= IFF_UP; | ||||
getmicrotime(&ifp->if_lastchange); | getmicrotime(&ifp->if_lastchange); | ||||
#ifdef INET | |||||
NET_EPOCH_ENTER(et); | |||||
CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { | |||||
if (ifa->ifa_addr->sa_family == AF_INET) { | |||||
struct sockaddr_in *si; | |||||
si = (struct sockaddr_in *)ifa->ifa_dstaddr; | |||||
if (si && si->sin_addr.s_addr) { | |||||
tp->tun_flags |= TUN_DSTADDR; | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
NET_EPOCH_EXIT(et); | |||||
#endif | |||||
TUN_UNLOCK(tp); | TUN_UNLOCK(tp); | ||||
} else { | } else { | ||||
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | ||||
TUN_UNLOCK(tp); | TUN_UNLOCK(tp); | ||||
/* attempt to start output */ | /* attempt to start output */ | ||||
tunstart_l2(ifp); | tunstart_l2(ifp); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 808 Lines • Show Last 20 Lines |