2 * Copyright (C) 1999-2000 by Maksim Yevmenkin <m_evmenkin@yahoo.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * -------------------------------------------------------------------------
29 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
30 * Nottingham University 1987.
34 * $FreeBSD: src/sys/net/if_tap.c,v 1.3.2.3 2002/04/14 21:41:48 luigi Exp $
35 * $DragonFly: src/sys/net/tap/if_tap.c,v 1.41 2008/09/05 17:03:15 dillon Exp $
36 * $Id: if_tap.c,v 0.21 2000/07/23 21:46:02 max Exp $
41 #include <sys/param.h>
43 #include <sys/device.h>
44 #include <sys/filedesc.h>
45 #include <sys/filio.h>
46 #include <sys/kernel.h>
47 #include <sys/malloc.h>
52 #include <sys/signalvar.h>
53 #include <sys/socket.h>
54 #include <sys/sockio.h>
55 #include <sys/sysctl.h>
56 #include <sys/systm.h>
57 #include <sys/thread2.h>
58 #include <sys/ttycom.h>
60 #include <sys/vnode.h>
61 #include <sys/serialize.h>
64 #include <net/ethernet.h>
66 #include <net/ifq_var.h>
67 #include <net/if_arp.h>
68 #include <net/if_clone.h>
69 #include <net/route.h>
70 #include <vfs/devfs/devfs.h>
72 #include <netinet/in.h>
74 #include "if_tapvar.h"
77 #define TAP_IFFLAGS (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST)
79 #define CDEV_NAME "tap"
80 #define CDEV_MAJOR 149
81 #define TAPDEBUG if (tapdebug) if_printf
85 #define VMNET_DEV_MASK 0x00010000
87 DEVFS_DECLARE_CLONE_BITMAP(tap);
90 static int tapmodevent (module_t, int, void *);
93 static cdev_t tapcreate(int);
94 static void tapdestroy(struct tap_softc *);
97 static int tap_clone_create(struct if_clone *, int);
98 static void tap_clone_destroy(struct ifnet *);
101 /* network interface */
102 static void tapifstart (struct ifnet *);
103 static int tapifioctl (struct ifnet *, u_long, caddr_t,
105 static void tapifinit (void *);
106 static void tapifstop(struct tap_softc *, int);
107 static void tapifflags(struct tap_softc *);
109 /* character device */
110 static d_open_t tapopen;
111 static d_clone_t tapclone;
112 static d_close_t tapclose;
113 static d_read_t tapread;
114 static d_write_t tapwrite;
115 static d_ioctl_t tapioctl;
116 static d_poll_t tappoll;
117 static d_kqfilter_t tapkqfilter;
119 static struct dev_ops tap_ops = {
120 { CDEV_NAME, CDEV_MAJOR, 0 },
127 .d_kqfilter = tapkqfilter
130 static int taprefcnt = 0; /* module ref. counter */
131 static int taplastunit = -1; /* max. open unit number */
132 static int tapdebug = 0; /* debug flag */
133 static int tapuopen = 0; /* all user open() */
134 static int tapuponopen = 0; /* IFF_UP */
136 MALLOC_DECLARE(M_TAP);
137 MALLOC_DEFINE(M_TAP, CDEV_NAME, "Ethernet tunnel interface");
138 struct if_clone tap_cloner = IF_CLONE_INITIALIZER("tap",
139 tap_clone_create, tap_clone_destroy,
141 static SLIST_HEAD(,tap_softc) tap_listhead =
142 SLIST_HEAD_INITIALIZER(&tap_listhead);
144 SYSCTL_INT(_debug, OID_AUTO, if_tap_debug, CTLFLAG_RW, &tapdebug, 0, "");
145 SYSCTL_DECL(_net_link);
146 SYSCTL_NODE(_net_link, OID_AUTO, tap, CTLFLAG_RW, 0,
147 "Ethernet tunnel software network interface");
148 SYSCTL_INT(_net_link_tap, OID_AUTO, user_open, CTLFLAG_RW, &tapuopen, 0,
149 "Allow user to open /dev/tap (based on node permissions)");
150 SYSCTL_INT(_net_link_tap, OID_AUTO, up_on_open, CTLFLAG_RW, &tapuponopen, 0,
151 "Bring interface up when /dev/tap is opened");
152 SYSCTL_INT(_net_link_tap, OID_AUTO, debug, CTLFLAG_RW, &tapdebug, 0, "");
154 DEV_MODULE(if_tap, tapmodevent, NULL);
159 * module event handler
162 tapmodevent(module_t mod, int type, void *data)
164 static int attached = 0;
165 struct tap_softc *tp, *ntp;
172 make_dev(&tap_ops, 0, 0, 0, 0600, "tap");
173 devfs_clone_bitmap_init(&DEVFS_CLONE_BITMAP(tap));
174 devfs_clone_handler_add("tap", tapclone);
175 SLIST_INIT(&tap_listhead);
176 if_clone_attach(&tap_cloner);
185 if_clone_detach(&tap_cloner);
187 /* Maintain tap ifs in a local list */
188 SLIST_FOREACH_MUTABLE(tp, &tap_listhead, tap_link, ntp)
193 devfs_clone_handler_del("tap");
194 dev_ops_remove_all(&tap_ops);
195 devfs_clone_bitmap_uninit(&DEVFS_CLONE_BITMAP(tap));
209 * to create interface
215 struct ifnet *ifp = NULL;
216 struct tap_softc *tp = NULL;
217 uint8_t ether_addr[ETHER_ADDR_LEN];
220 /* allocate driver storage and create device */
221 MALLOC(tp, struct tap_softc *, sizeof(*tp), M_TAP, M_WAITOK | M_ZERO);
223 /* XXX: fix lminor(dev) and so on, and unit,.... */
224 /* select device: tap or vmnet */
225 if (minor(dev) & VMNET_DEV_MASK) {
227 unit = lminor(dev) & 0xff;
228 tp->tap_flags |= TAP_VMNET;
238 tp->tap_dev = make_dev(&tap_ops, minor(dev), UID_ROOT, GID_WHEEL,
239 0600, "%s%d", name, unit);
240 tp->tap_dev->si_drv1 = dev->si_drv1 = tp;
241 reference_dev(tp->tap_dev); /* so we can destroy it later */
243 /* generate fake MAC address: 00 bd xx xx xx unit_no */
244 ether_addr[0] = 0x00;
245 ether_addr[1] = 0xbd;
246 bcopy(&ticks, ðer_addr[2], 3);
247 ether_addr[5] = (u_char)unit;
249 /* fill the rest and attach interface */
253 if_initname(ifp, name, unit);
254 if (unit > taplastunit)
257 ifp->if_init = tapifinit;
258 ifp->if_start = tapifstart;
259 ifp->if_ioctl = tapifioctl;
260 ifp->if_mtu = ETHERMTU;
261 ifp->if_flags = TAP_IFFLAGS;
262 ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
263 ifq_set_ready(&ifp->if_snd);
265 ether_ifattach(ifp, ether_addr, NULL);
267 tp->tap_flags |= TAP_INITED;
268 tp->tap_devq.ifq_maxlen = ifqmaxlen;
270 SLIST_INSERT_HEAD(&tap_listhead, tp, tap_link);
272 TAPDEBUG(ifp, "created. minor = %#x\n", minor(tp->tap_dev));
279 * Create a new tap instance.
282 tap_clone_create(struct if_clone *ifc __unused, int unit)
284 struct tap_softc *tp = NULL;
287 dev = get_dev(CDEV_MAJOR, unit);
289 dev = tapcreate(unit);
292 tp->tap_flags |= TAP_CLONE;
293 TAPDEBUG(&tp->tap_if, "clone created. minor = %#x tap_flags = 0x%x\n",
294 minor(tp->tap_dev), tp->tap_flags);
302 * to open tunnel. must be superuser
305 tapopen(struct dev_open_args *ap)
308 struct tap_softc *tp = NULL;
309 struct ifnet *ifp = NULL;
313 (error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) != 0)
317 dev = ap->a_head.a_dev;
324 ifp = &tp->arpcom.ac_if;
326 if (tp->tap_flags & TAP_OPEN) {
330 ifp = &tp->arpcom.ac_if;
332 if ((tp->tap_flags & TAP_CLONE) == 0) {
333 EVENTHANDLER_INVOKE(ifnet_attach_event, ifp);
335 /* Announce the return of the interface. */
336 rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
340 bcopy(tp->arpcom.ac_enaddr, tp->ether_addr, sizeof(tp->ether_addr));
342 if (curthread->td_proc)
343 fsetown(curthread->td_proc->p_pid, &tp->tap_sigtd);
344 tp->tap_flags |= TAP_OPEN;
347 if (tapuponopen && (ifp->if_flags & IFF_UP) == 0) {
352 ifnet_serialize_all(ifp);
354 ifnet_deserialize_all(ifp);
356 tp->tap_flags |= TAP_CLOSEDOWN;
359 TAPDEBUG(ifp, "opened. minor = %#x, refcnt = %d, taplastunit = %d\n",
360 minor(tp->tap_dev), taprefcnt, taplastunit);
367 tapclone(struct dev_clone_args *ap)
371 unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(tap), 0);
372 ap->a_dev = tapcreate(unit);
379 * close the device - mark i/f down & delete routing info
382 tapclose(struct dev_close_args *ap)
384 cdev_t dev = ap->a_head.a_dev;
385 struct tap_softc *tp = dev->si_drv1;
386 struct ifnet *ifp = &tp->tap_if;
391 /* Junk all pending output */
392 ifq_purge(&ifp->if_snd);
395 * Do not bring the interface down, and do not anything with
396 * interface, if we are in VMnet mode. just close the device.
398 * If the interface is not cloned, we always bring it down.
400 * If the interface is cloned, then we bring it down during
401 * closing only if it was brought up during opening.
403 if ((tp->tap_flags & TAP_VMNET) == 0 &&
404 ((tp->tap_flags & TAP_CLONE) == 0 ||
405 (tp->tap_flags & TAP_CLOSEDOWN))) {
406 if (ifp->if_flags & IFF_UP)
410 ifnet_serialize_all(ifp);
411 tapifstop(tp, clear_flags);
412 ifnet_deserialize_all(ifp);
414 if ((tp->tap_flags & TAP_CLONE) == 0) {
415 if_purgeaddrs_nolink(ifp);
417 EVENTHANDLER_INVOKE(ifnet_detach_event, ifp);
419 /* Announce the departure of the interface. */
420 rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
423 funsetown(tp->tap_sigio);
424 tp->tap_sigio = NULL;
425 selwakeup(&tp->tap_rsel);
427 tp->tap_flags &= ~TAP_OPEN;
428 funsetown(tp->tap_sigtd);
429 tp->tap_sigtd = NULL;
434 if_printf(ifp, "minor = %#x, refcnt = %d is out of sync. "
435 "set refcnt to 0\n", minor(tp->tap_dev), taprefcnt);
438 TAPDEBUG(ifp, "closed. minor = %#x, refcnt = %d, taplastunit = %d\n",
439 minor(tp->tap_dev), taprefcnt, taplastunit);
442 if ((tp->tap_flags & TAP_CLONE) == 0)
453 * Destroy a tap instance.
456 tapdestroy(struct tap_softc *tp)
458 struct ifnet *ifp = &tp->arpcom.ac_if;
460 TAPDEBUG(ifp, "destroyed. minor = %#x, refcnt = %d, taplastunit = %d\n",
461 minor(tp->tap_dev), taprefcnt, taplastunit);
463 ifnet_serialize_all(ifp);
465 ifnet_deserialize_all(ifp);
468 SLIST_REMOVE(&tap_listhead, tp, tap_softc, tap_link);
470 destroy_dev(tp->tap_dev);
479 * Destroy a tap instance.
482 tap_clone_destroy(struct ifnet *ifp)
484 struct tap_softc *tp = ifp->if_softc;
486 TAPDEBUG(&tp->tap_if, "clone destroyed. minor = %#x tap_flags = 0x%x\n",
487 minor(tp->tap_dev), tp->tap_flags);
488 if (tp->tap_flags & TAP_CLONE)
495 * Network interface initialization function (called with if serializer held)
502 struct tap_softc *tp = xtp;
503 struct ifnet *ifp = &tp->tap_if;
505 TAPDEBUG(ifp, "initializing, minor = %#x tap_flags = 0x%x\n",
506 minor(tp->tap_dev), tp->tap_flags);
508 ASSERT_IFNET_SERIALIZED_ALL(ifp);
512 ifp->if_flags |= IFF_RUNNING;
513 ifp->if_flags &= ~IFF_OACTIVE;
515 /* attempt to start output */
523 * Process an ioctl request on network interface (called with if serializer
529 tapifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
531 struct tap_softc *tp = (struct tap_softc *)(ifp->if_softc);
532 struct ifstat *ifs = NULL;
539 dummy = ether_ioctl(ifp, cmd, data);
546 case SIOCADDMULTI: /* XXX -- just like vmnet does */
551 ifs = (struct ifstat *)data;
552 dummy = strlen(ifs->ascii);
553 if ((tp->tap_flags & TAP_OPEN) &&
554 dummy < sizeof(ifs->ascii)) {
555 if (tp->tap_sigtd && tp->tap_sigtd->sio_proc) {
556 ksnprintf(ifs->ascii + dummy,
557 sizeof(ifs->ascii) - dummy,
558 "\tOpened by pid %d\n",
559 (int)tp->tap_sigtd->sio_proc->p_pid);
561 ksnprintf(ifs->ascii + dummy,
562 sizeof(ifs->ascii) - dummy,
563 "\tOpened by <unknown>\n");
579 * Queue packets from higher level ready to put out (called with if serializer
585 tapifstart(struct ifnet *ifp)
587 struct tap_softc *tp = ifp->if_softc;
592 TAPDEBUG(ifp, "starting, minor = %#x\n", minor(tp->tap_dev));
595 * do not junk pending output if we are in VMnet mode.
596 * XXX: can this do any harm because of queue overflow?
599 if (((tp->tap_flags & TAP_VMNET) == 0) &&
600 ((tp->tap_flags & TAP_READY) != TAP_READY)) {
601 TAPDEBUG(ifp, "not ready. minor = %#x, tap_flags = 0x%x\n",
602 minor(tp->tap_dev), tp->tap_flags);
603 ifq_purge(&ifp->if_snd);
607 ifp->if_flags |= IFF_OACTIVE;
610 while ((m = ifq_dequeue(&ifp->if_snd, NULL)) != NULL) {
623 if (tp->tap_flags & TAP_RWAIT) {
624 tp->tap_flags &= ~TAP_RWAIT;
629 KNOTE(&tp->tap_rsel.si_note, 0);
632 if ((tp->tap_flags & TAP_ASYNC) && (tp->tap_sigio != NULL)) {
634 pgsigio(tp->tap_sigio, SIGIO, 0);
639 * selwakeup is not MPSAFE. tapifstart is.
642 selwakeup(&tp->tap_rsel);
646 ifp->if_flags &= ~IFF_OACTIVE;
653 * The ops interface is now pretty minimal. Called via fileops with nothing
659 tapioctl(struct dev_ioctl_args *ap)
661 cdev_t dev = ap->a_head.a_dev;
662 caddr_t data = ap->a_data;
663 struct tap_softc *tp = dev->si_drv1;
664 struct ifnet *ifp = &tp->tap_if;
665 struct tapinfo *tapp = NULL;
670 ifnet_serialize_all(ifp);
675 tapp = (struct tapinfo *)data;
676 ifp->if_mtu = tapp->mtu;
677 ifp->if_type = tapp->type;
678 ifp->if_baudrate = tapp->baudrate;
682 tapp = (struct tapinfo *)data;
683 tapp->mtu = ifp->if_mtu;
684 tapp->type = ifp->if_type;
685 tapp->baudrate = ifp->if_baudrate;
689 tapdebug = *(int *)data;
693 *(int *)data = tapdebug;
698 tp->tap_flags |= TAP_ASYNC;
700 tp->tap_flags &= ~TAP_ASYNC;
706 /* Take a look at devq first */
707 IF_POLL(&tp->tap_devq, mb);
709 mb = ifq_poll(&ifp->if_snd);
712 for(; mb != NULL; mb = mb->m_next)
713 *(int *)data += mb->m_len;
718 error = fsetown(*(int *)data, &tp->tap_sigio);
722 *(int *)data = fgetown(tp->tap_sigio);
725 /* this is deprecated, FIOSETOWN should be used instead */
727 error = fsetown(-(*(int *)data), &tp->tap_sigio);
730 /* this is deprecated, FIOGETOWN should be used instead */
732 *(int *)data = -fgetown(tp->tap_sigio);
735 /* VMware/VMnet port ioctl's */
737 case SIOCGIFFLAGS: /* get ifnet flags */
738 bcopy(&ifp->if_flags, data, sizeof(ifp->if_flags));
741 case VMIO_SIOCSIFFLAGS: /* VMware/VMnet SIOCSIFFLAGS */
744 f &= ~IFF_CANTCHANGE;
746 ifp->if_flags = f | (ifp->if_flags & IFF_CANTCHANGE);
749 case OSIOCGIFADDR: /* get MAC address of the remote side */
751 bcopy(tp->ether_addr, data, sizeof(tp->ether_addr));
754 case SIOCSIFADDR: /* set MAC address of the remote side */
755 bcopy(data, tp->ether_addr, sizeof(tp->ether_addr));
762 ifnet_deserialize_all(ifp);
770 * The ops read interface - reads a packet at a time, or at
771 * least as much of a packet as can be read.
773 * Called from the fileops interface with nothing held.
778 tapread(struct dev_read_args *ap)
780 cdev_t dev = ap->a_head.a_dev;
781 struct uio *uio = ap->a_uio;
782 struct tap_softc *tp = dev->si_drv1;
783 struct ifnet *ifp = &tp->tap_if;
784 struct mbuf *m0 = NULL;
787 TAPDEBUG(ifp, "reading, minor = %#x\n", minor(tp->tap_dev));
789 if ((tp->tap_flags & TAP_READY) != TAP_READY) {
790 TAPDEBUG(ifp, "not ready. minor = %#x, tap_flags = 0x%x\n",
791 minor(tp->tap_dev), tp->tap_flags);
796 tp->tap_flags &= ~TAP_RWAIT;
798 /* sleep until we get a packet */
800 ifnet_serialize_all(ifp);
801 IF_DEQUEUE(&tp->tap_devq, m0);
803 if (ap->a_ioflag & IO_NDELAY) {
804 ifnet_deserialize_all(ifp);
805 return (EWOULDBLOCK);
807 tp->tap_flags |= TAP_RWAIT;
808 tsleep_interlock(tp, PCATCH);
809 ifnet_deserialize_all(ifp);
810 error = tsleep(tp, PCATCH | PINTERLOCKED, "taprd", 0);
814 ifnet_deserialize_all(ifp);
816 } while (m0 == NULL);
820 /* xfer packet to user space */
821 while ((m0 != NULL) && (uio->uio_resid > 0) && (error == 0)) {
822 len = min(uio->uio_resid, m0->m_len);
826 error = uiomove(mtod(m0, caddr_t), len, uio);
831 TAPDEBUG(ifp, "dropping mbuf, minor = %#x\n",
842 * The ops write interface - an atomic write is a packet - or else!
844 * Called from the fileops interface with nothing held.
849 tapwrite(struct dev_write_args *ap)
851 cdev_t dev = ap->a_head.a_dev;
852 struct uio *uio = ap->a_uio;
853 struct tap_softc *tp = dev->si_drv1;
854 struct ifnet *ifp = &tp->tap_if;
855 struct mbuf *top = NULL, **mp = NULL, *m = NULL;
856 int error = 0, tlen, mlen;
858 TAPDEBUG(ifp, "writing, minor = %#x\n", minor(tp->tap_dev));
860 if ((tp->tap_flags & TAP_READY) != TAP_READY) {
861 TAPDEBUG(ifp, "not ready. minor = %#x, tap_flags = 0x%x\n",
862 minor(tp->tap_dev), tp->tap_flags);
866 if (uio->uio_resid == 0)
869 if ((uio->uio_resid < 0) || (uio->uio_resid > TAPMRU)) {
870 TAPDEBUG(ifp, "invalid packet len = %d, minor = %#x\n",
871 uio->uio_resid, minor(tp->tap_dev));
875 tlen = uio->uio_resid;
877 /* get a header mbuf */
878 MGETHDR(m, MB_DONTWAIT, MT_DATA);
885 while ((error == 0) && (uio->uio_resid > 0)) {
886 m->m_len = min(mlen, uio->uio_resid);
887 error = uiomove(mtod(m, caddr_t), m->m_len, uio);
890 if (uio->uio_resid > 0) {
891 MGET(m, MB_DONTWAIT, MT_DATA);
906 top->m_pkthdr.len = tlen;
907 top->m_pkthdr.rcvif = ifp;
910 * Ethernet bridge and bpf are handled in ether_input
912 * adjust mbuf and give packet to the ether_input
914 ifnet_serialize_all(ifp);
915 ifp->if_input(ifp, top);
916 ifp->if_ipackets ++; /* ibytes are counted in ether_input */
917 ifnet_deserialize_all(ifp);
925 * The poll interface, this is only useful on reads really. The write
926 * detect always returns true, write never blocks anyway, it either
927 * accepts the packet or drops it
929 * Called from the fileops interface with nothing held.
934 tappoll(struct dev_poll_args *ap)
936 cdev_t dev = ap->a_head.a_dev;
937 struct tap_softc *tp = dev->si_drv1;
938 struct ifnet *ifp = &tp->tap_if;
941 TAPDEBUG(ifp, "polling, minor = %#x\n", minor(tp->tap_dev));
943 if (ap->a_events & (POLLIN | POLLRDNORM)) {
944 if (!IF_QEMPTY(&tp->tap_devq)) {
946 "has data in queue. minor = %#x\n",
949 revents |= (ap->a_events & (POLLIN | POLLRDNORM));
951 TAPDEBUG(ifp, "waiting for data, minor = %#x\n",
955 selrecord(curthread, &tp->tap_rsel);
960 if (ap->a_events & (POLLOUT | POLLWRNORM))
961 revents |= (ap->a_events & (POLLOUT | POLLWRNORM));
962 ap->a_events = revents;
967 * tapkqfilter - called from the fileops interface with nothing held
971 static int filt_tapread(struct knote *kn, long hint);
972 static void filt_tapdetach(struct knote *kn);
973 static struct filterops tapread_filtops =
974 { 1, NULL, filt_tapdetach, filt_tapread };
977 tapkqfilter(struct dev_kqfilter_args *ap)
979 cdev_t dev = ap->a_head.a_dev;
980 struct knote *kn = ap->a_kn;
981 struct tap_softc *tp;
990 switch(kn->kn_filter) {
992 list = &tp->tap_rsel.si_note;
993 kn->kn_fop = &tapread_filtops;
994 kn->kn_hook = (void *)tp;
1004 SLIST_INSERT_HEAD(list, kn, kn_selnext);
1011 filt_tapread(struct knote *kn, long hint)
1013 struct tap_softc *tp = (void *)kn->kn_hook;
1015 if (IF_QEMPTY(&tp->tap_devq) == 0) /* XXX serializer */
1022 filt_tapdetach(struct knote *kn)
1024 struct tap_softc *tp = (void *)kn->kn_hook;
1026 SLIST_REMOVE(&tp->tap_rsel.si_note, kn, knote, kn_selnext);
1030 tapifstop(struct tap_softc *tp, int clear_flags)
1032 struct ifnet *ifp = &tp->tap_if;
1034 ASSERT_IFNET_SERIALIZED_ALL(ifp);
1035 IF_DRAIN(&tp->tap_devq);
1036 tp->tap_flags &= ~TAP_CLOSEDOWN;
1038 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1042 tapifflags(struct tap_softc *tp)
1044 struct ifnet *ifp = &tp->arpcom.ac_if;
1046 ASSERT_IFNET_SERIALIZED_ALL(ifp);
1047 if ((tp->tap_flags & TAP_VMNET) == 0) {
1049 * Only for non-vmnet tap(4)
1051 if (ifp->if_flags & IFF_UP) {
1052 if ((ifp->if_flags & IFF_RUNNING) == 0)