Changeset View
Changeset View
Standalone View
Standalone View
sys/net/if_tuntap.c
Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | |||||
* static for the duration of a tunnel interface. | * static for the duration of a tunnel interface. | ||||
*/ | */ | ||||
struct tuntap_softc { | struct tuntap_softc { | ||||
TAILQ_ENTRY(tuntap_softc) tun_list; | TAILQ_ENTRY(tuntap_softc) tun_list; | ||||
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_RCOLL 0x0004 | #define TUN_RCOLL 0x0004 /* unused */ | ||||
markj: I would just rename to TUN_UNUSED1, or remove it outright. | |||||
kevansUnsubmitted Done Inline Actions+1 for remove it kevans: +1 for remove it | |||||
vmaffioneAuthorUnsubmitted Done Inline ActionsSounds good, I'll do. vmaffione: Sounds good, I'll do. | |||||
#define TUN_IASET 0x0008 | #define TUN_IASET 0x0008 | ||||
#define TUN_DSTADDR 0x0010 | #define TUN_DSTADDR 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 | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
SYSCTL_INT(_debug, OID_AUTO, if_tun_debug, CTLFLAG_RW, &tundebug, 0, ""); | SYSCTL_INT(_debug, OID_AUTO, if_tun_debug, CTLFLAG_RW, &tundebug, 0, ""); | ||||
static struct sx tun_ioctl_sx; | static struct sx tun_ioctl_sx; | ||||
SX_SYSINIT(tun_ioctl_sx, &tun_ioctl_sx, "tun_ioctl"); | SX_SYSINIT(tun_ioctl_sx, &tun_ioctl_sx, "tun_ioctl"); | ||||
SYSCTL_DECL(_net_link); | SYSCTL_DECL(_net_link); | ||||
/* tun */ | /* tun */ | ||||
static SYSCTL_NODE(_net_link, OID_AUTO, tun, CTLFLAG_RW, 0, | static SYSCTL_NODE(_net_link, OID_AUTO, tun, CTLFLAG_RW, 0, | ||||
"IP tunnel software network interface."); | "IP tunnel software network interface"); | ||||
SYSCTL_INT(_net_link_tun, OID_AUTO, devfs_cloning, CTLFLAG_RWTUN, &tundclone, 0, | SYSCTL_INT(_net_link_tun, OID_AUTO, devfs_cloning, CTLFLAG_RWTUN, &tundclone, 0, | ||||
"Enable legacy devfs interface creation."); | "Enable legacy devfs interface creation"); | ||||
/* tap */ | /* tap */ | ||||
static SYSCTL_NODE(_net_link, OID_AUTO, tap, CTLFLAG_RW, 0, | static SYSCTL_NODE(_net_link, OID_AUTO, tap, CTLFLAG_RW, 0, | ||||
"Ethernet tunnel software network interface"); | "Ethernet tunnel software network interface"); | ||||
SYSCTL_INT(_net_link_tap, OID_AUTO, user_open, CTLFLAG_RW, &tap_allow_uopen, 0, | SYSCTL_INT(_net_link_tap, OID_AUTO, user_open, CTLFLAG_RW, &tap_allow_uopen, 0, | ||||
"Allow user to open /dev/tap (based on node permissions)"); | "Allow user to open /dev/tap (based on node permissions)"); | ||||
SYSCTL_INT(_net_link_tap, OID_AUTO, up_on_open, CTLFLAG_RW, &tapuponopen, 0, | SYSCTL_INT(_net_link_tap, OID_AUTO, up_on_open, CTLFLAG_RW, &tapuponopen, 0, | ||||
"Bring interface up when /dev/tap is opened"); | "Bring interface up when /dev/tap is opened"); | ||||
▲ Show 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | tun_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) | ||||
if (err != 0) | if (err != 0) | ||||
return (err); | return (err); | ||||
drv = tuntap_driver_from_flags(tunflags); | drv = tuntap_driver_from_flags(tunflags); | ||||
if (drv == NULL) | if (drv == NULL) | ||||
return (ENXIO); | return (ENXIO); | ||||
if (unit != -1) { | if (unit != -1) { | ||||
/* If this unit number is still available that/s okay. */ | /* If this unit number is still available that's okay. */ | ||||
if (alloc_unr_specific(drv->unrhdr, unit) == -1) | if (alloc_unr_specific(drv->unrhdr, unit) == -1) | ||||
return (EEXIST); | return (EEXIST); | ||||
} else { | } else { | ||||
unit = alloc_unr(drv->unrhdr); | unit = alloc_unr(drv->unrhdr); | ||||
} | } | ||||
snprintf(name, IFNAMSIZ, "%s%d", drv->cdevsw.d_name, unit); | snprintf(name, IFNAMSIZ, "%s%d", drv->cdevsw.d_name, unit); | ||||
▲ Show 20 Lines • Show All 976 Lines • ▼ Show 20 Lines | tunread(struct cdev *dev, struct uio *uio, int flag) | ||||
if ((tp->tun_flags & TUN_READY) != TUN_READY) { | if ((tp->tun_flags & TUN_READY) != TUN_READY) { | ||||
TUN_UNLOCK(tp); | TUN_UNLOCK(tp); | ||||
TUNDEBUG (ifp, "not ready 0%o\n", tp->tun_flags); | TUNDEBUG (ifp, "not ready 0%o\n", tp->tun_flags); | ||||
return (EHOSTDOWN); | return (EHOSTDOWN); | ||||
} | } | ||||
tp->tun_flags &= ~TUN_RWAIT; | tp->tun_flags &= ~TUN_RWAIT; | ||||
do { | for (;;) { | ||||
IFQ_DEQUEUE(&ifp->if_snd, m); | IFQ_DEQUEUE(&ifp->if_snd, m); | ||||
if (m == NULL) { | if (m != NULL) | ||||
break; | |||||
if (flag & O_NONBLOCK) { | if (flag & O_NONBLOCK) { | ||||
TUN_UNLOCK(tp); | TUN_UNLOCK(tp); | ||||
return (EWOULDBLOCK); | return (EWOULDBLOCK); | ||||
} | } | ||||
tp->tun_flags |= TUN_RWAIT; | tp->tun_flags |= TUN_RWAIT; | ||||
error = mtx_sleep(tp, &tp->tun_mtx, PCATCH | (PZERO + 1), | error = mtx_sleep(tp, &tp->tun_mtx, PCATCH | (PZERO + 1), | ||||
"tunread", 0); | "tunread", 0); | ||||
if (error != 0) { | if (error != 0) { | ||||
TUN_UNLOCK(tp); | TUN_UNLOCK(tp); | ||||
return (error); | return (error); | ||||
} | } | ||||
} | } | ||||
} while (m == NULL); | |||||
TUN_UNLOCK(tp); | TUN_UNLOCK(tp); | ||||
if ((tp->tun_flags & TUN_L2) != 0) | if ((tp->tun_flags & TUN_L2) != 0) | ||||
BPF_MTAP(ifp, m); | BPF_MTAP(ifp, m); | ||||
while (m && uio->uio_resid > 0 && error == 0) { | while (m && uio->uio_resid > 0 && error == 0) { | ||||
len = min(uio->uio_resid, m->m_len); | len = min(uio->uio_resid, m->m_len); | ||||
if (len != 0) | if (len != 0) | ||||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | if (!IFQ_IS_EMPTY(&ifp->if_snd)) { | ||||
TUNDEBUG(ifp, "tunpoll q=%d\n", ifp->if_snd.ifq_len); | TUNDEBUG(ifp, "tunpoll q=%d\n", ifp->if_snd.ifq_len); | ||||
revents |= events & (POLLIN | POLLRDNORM); | revents |= events & (POLLIN | POLLRDNORM); | ||||
} else { | } else { | ||||
TUNDEBUG(ifp, "tunpoll waiting\n"); | TUNDEBUG(ifp, "tunpoll waiting\n"); | ||||
selrecord(td, &tp->tun_rsel); | selrecord(td, &tp->tun_rsel); | ||||
} | } | ||||
IFQ_UNLOCK(&ifp->if_snd); | IFQ_UNLOCK(&ifp->if_snd); | ||||
} | } | ||||
if (events & (POLLOUT | POLLWRNORM)) | |||||
revents |= events & (POLLOUT | POLLWRNORM); | revents |= events & (POLLOUT | POLLWRNORM); | ||||
return (revents); | return (revents); | ||||
} | } | ||||
/* | /* | ||||
* tunkqfilter - support for the kevent() system call. | * tunkqfilter - support for the kevent() system call. | ||||
*/ | */ | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
I would just rename to TUN_UNUSED1, or remove it outright.