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 * $Id: if_tap.c,v 0.21 2000/07/23 21:46:02 max Exp $
40 #include <sys/param.h>
42 #include <sys/device.h>
43 #include <sys/filedesc.h>
44 #include <sys/filio.h>
45 #include <sys/kernel.h>
46 #include <sys/malloc.h>
50 #include <sys/signalvar.h>
51 #include <sys/socket.h>
52 #include <sys/sockio.h>
53 #include <sys/sysctl.h>
54 #include <sys/systm.h>
55 #include <sys/ttycom.h>
57 #include <sys/vnode.h>
58 #include <sys/serialize.h>
60 #include <sys/thread2.h>
61 #include <sys/mplock2.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 <sys/devfs.h>
72 #include <netinet/in.h>
74 #include "if_tapvar.h"
77 #define TAP_IFFLAGS (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST)
79 #define TAP_PREALLOCATED_UNITS 4
81 #define CDEV_NAME "tap"
82 #define TAPDEBUG if (tapdebug) if_printf
86 #define VMNET_DEV_MASK 0x00010000
88 DEVFS_DECLARE_CLONE_BITMAP(tap);
91 static int tapmodevent (module_t, int, void *);
94 static struct tap_softc *tapcreate(int, cdev_t);
95 static void tapdestroy(struct tap_softc *);
98 static int tap_clone_create(struct if_clone *, int, caddr_t);
99 static int tap_clone_destroy(struct ifnet *);
102 /* network interface */
103 static void tapifstart (struct ifnet *);
104 static int tapifioctl (struct ifnet *, u_long, caddr_t,
106 static void tapifinit (void *);
107 static void tapifstop(struct tap_softc *, int);
108 static void tapifflags(struct tap_softc *);
110 /* character device */
111 static d_open_t tapopen;
112 static d_clone_t tapclone;
113 static d_close_t tapclose;
114 static d_read_t tapread;
115 static d_write_t tapwrite;
116 static d_ioctl_t tapioctl;
117 static d_kqfilter_t tapkqfilter;
119 static struct dev_ops tap_ops = {
126 .d_kqfilter = tapkqfilter
129 static int taprefcnt = 0; /* module ref. counter */
130 static int taplastunit = -1; /* max. open unit number */
131 static int tapdebug = 0; /* debug flag */
132 static int tapuopen = 0; /* all user open() */
133 static int tapuponopen = 0; /* IFF_UP */
135 MALLOC_DECLARE(M_TAP);
136 MALLOC_DEFINE(M_TAP, CDEV_NAME, "Ethernet tunnel interface");
137 struct if_clone tap_cloner = IF_CLONE_INITIALIZER("tap",
138 tap_clone_create, tap_clone_destroy,
140 static SLIST_HEAD(,tap_softc) tap_listhead =
141 SLIST_HEAD_INITIALIZER(&tap_listhead);
143 SYSCTL_INT(_debug, OID_AUTO, if_tap_debug, CTLFLAG_RW, &tapdebug, 0, "");
144 SYSCTL_DECL(_net_link);
145 SYSCTL_NODE(_net_link, OID_AUTO, tap, CTLFLAG_RW, 0,
146 "Ethernet tunnel software network interface");
147 SYSCTL_INT(_net_link_tap, OID_AUTO, user_open, CTLFLAG_RW, &tapuopen, 0,
148 "Allow user to open /dev/tap (based on node permissions)");
149 SYSCTL_INT(_net_link_tap, OID_AUTO, up_on_open, CTLFLAG_RW, &tapuponopen, 0,
150 "Bring interface up when /dev/tap is opened");
151 SYSCTL_INT(_net_link_tap, OID_AUTO, debug, CTLFLAG_RW, &tapdebug, 0, "");
153 DEV_MODULE(if_tap, tapmodevent, NULL);
158 * module event handler
161 tapmodevent(module_t mod, int type, void *data)
163 static int attached = 0;
164 struct tap_softc *tp, *ntp;
172 make_autoclone_dev(&tap_ops, &DEVFS_CLONE_BITMAP(tap), tapclone,
173 UID_ROOT, GID_WHEEL, 0600, "tap");
174 SLIST_INIT(&tap_listhead);
175 if_clone_attach(&tap_cloner);
177 for (i = 0; i < TAP_PREALLOCATED_UNITS; ++i) {
178 make_dev(&tap_ops, i, UID_ROOT, GID_WHEEL,
180 devfs_clone_bitmap_set(&DEVFS_CLONE_BITMAP(tap), i);
190 if_clone_detach(&tap_cloner);
192 /* Maintain tap ifs in a local list */
193 SLIST_FOREACH_MUTABLE(tp, &tap_listhead, tap_link, ntp)
198 devfs_clone_handler_del("tap");
199 dev_ops_remove_all(&tap_ops);
200 devfs_clone_bitmap_uninit(&DEVFS_CLONE_BITMAP(tap));
212 * tapcreate - create or clone an interface
214 static struct tap_softc *
215 tapcreate(int unit, cdev_t dev)
217 const char *name = TAP;
219 struct tap_softc *tp;
220 uint8_t ether_addr[ETHER_ADDR_LEN];
222 tp = kmalloc(sizeof(*tp), M_TAP, M_WAITOK | M_ZERO);
227 reference_dev(dev); /* tp association */
229 /* generate fake MAC address: 00 bd xx xx xx unit_no */
230 ether_addr[0] = 0x00;
231 ether_addr[1] = 0xbd;
232 bcopy(&ticks, ðer_addr[2], 3);
233 ether_addr[5] = (u_char)unit;
235 /* fill the rest and attach interface */
239 if_initname(ifp, name, unit);
240 if (unit > taplastunit)
243 ifp->if_init = tapifinit;
244 ifp->if_start = tapifstart;
245 ifp->if_ioctl = tapifioctl;
246 ifp->if_mtu = ETHERMTU;
247 ifp->if_flags = TAP_IFFLAGS;
248 ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
249 ifq_set_ready(&ifp->if_snd);
251 ether_ifattach(ifp, ether_addr, NULL);
253 tp->tap_flags |= TAP_INITED;
254 tp->tap_devq.ifq_maxlen = ifqmaxlen;
256 SLIST_INSERT_HEAD(&tap_listhead, tp, tap_link);
258 TAPDEBUG(ifp, "created. minor = %#x\n", minor(dev));
266 struct tap_softc *tp;
268 SLIST_FOREACH(tp, &tap_listhead, tap_link) {
269 if (tp->tap_unit == unit)
278 * Create a new tap instance via ifconfig.
281 tap_clone_create(struct if_clone *ifc __unused, int unit,
282 caddr_t param __unused)
284 struct tap_softc *tp;
289 if (!devfs_clone_bitmap_chk(&DEVFS_CLONE_BITMAP(tap), unit)) {
290 devfs_clone_bitmap_set(&DEVFS_CLONE_BITMAP(tap), unit);
291 dev = make_dev(&tap_ops, unit, UID_ROOT, GID_WHEEL,
292 0600, "%s%d", TAP, unit);
294 dev = devfs_find_device_by_name("%s%d", TAP, unit);
297 KKASSERT(dev != NULL);
298 tp = tapcreate(unit, dev);
300 tp->tap_flags |= TAP_CLONE;
301 TAPDEBUG(&tp->tap_if, "clone created. minor = %#x tap_flags = 0x%x\n",
302 minor(tp->tap_dev), tp->tap_flags);
310 * to open tunnel. must be superuser
313 tapopen(struct dev_open_args *ap)
316 struct tap_softc *tp = NULL;
317 struct ifnet *ifp = NULL;
321 (error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) != 0)
325 dev = ap->a_head.a_dev;
328 tp = tapcreate(minor(dev), dev);
329 if (tp->tap_flags & TAP_OPEN) {
333 ifp = &tp->arpcom.ac_if;
335 if ((tp->tap_flags & TAP_CLONE) == 0) {
336 EVENTHANDLER_INVOKE(ifnet_attach_event, ifp);
338 /* Announce the return of the interface. */
339 rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
342 bcopy(tp->arpcom.ac_enaddr, tp->ether_addr, sizeof(tp->ether_addr));
344 if (curthread->td_proc)
345 fsetown(curthread->td_proc->p_pid, &tp->tap_sigtd);
346 tp->tap_flags |= TAP_OPEN;
349 if (tapuponopen && (ifp->if_flags & IFF_UP) == 0) {
354 ifnet_serialize_all(ifp);
356 ifnet_deserialize_all(ifp);
358 tp->tap_flags |= TAP_CLOSEDOWN;
361 TAPDEBUG(ifp, "opened. minor = %#x, refcnt = %d, taplastunit = %d\n",
362 minor(tp->tap_dev), taprefcnt, taplastunit);
369 tapclone(struct dev_clone_args *ap)
373 unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(tap), 0);
374 ap->a_dev = make_only_dev(&tap_ops, unit, UID_ROOT, GID_WHEEL,
375 0600, "%s%d", TAP, unit);
376 tapcreate(unit, ap->a_dev);
383 * close the device - mark i/f down & delete routing info
386 tapclose(struct dev_close_args *ap)
388 cdev_t dev = ap->a_head.a_dev;
389 struct tap_softc *tp = dev->si_drv1;
390 struct ifnet *ifp = &tp->tap_if;
395 /* Junk all pending output */
396 ifq_purge(&ifp->if_snd);
399 * Do not bring the interface down, and do not anything with
400 * interface, if we are in VMnet mode. just close the device.
402 * If the interface is not cloned, we always bring it down.
404 * If the interface is cloned, then we bring it down during
405 * closing only if it was brought up during opening.
407 if ((tp->tap_flags & TAP_VMNET) == 0 &&
408 ((tp->tap_flags & TAP_CLONE) == 0 ||
409 (tp->tap_flags & TAP_CLOSEDOWN))) {
410 if (ifp->if_flags & IFF_UP)
414 ifnet_serialize_all(ifp);
415 tapifstop(tp, clear_flags);
416 ifnet_deserialize_all(ifp);
418 if ((tp->tap_flags & TAP_CLONE) == 0) {
419 if_purgeaddrs_nolink(ifp);
421 EVENTHANDLER_INVOKE(ifnet_detach_event, ifp);
423 /* Announce the departure of the interface. */
424 rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
427 funsetown(tp->tap_sigio);
428 tp->tap_sigio = NULL;
429 KNOTE(&tp->tap_rkq.ki_note, 0);
431 tp->tap_flags &= ~TAP_OPEN;
432 funsetown(tp->tap_sigtd);
433 tp->tap_sigtd = NULL;
438 if_printf(ifp, "minor = %#x, refcnt = %d is out of sync. "
439 "set refcnt to 0\n", minor(tp->tap_dev), taprefcnt);
442 TAPDEBUG(ifp, "closed. minor = %#x, refcnt = %d, taplastunit = %d\n",
443 minor(tp->tap_dev), taprefcnt, taplastunit);
445 if (tp->tap_unit >= TAP_PREALLOCATED_UNITS)
455 * Destroy a tap instance.
458 tapdestroy(struct tap_softc *tp)
460 struct ifnet *ifp = &tp->arpcom.ac_if;
463 TAPDEBUG(ifp, "destroyed. minor = %#x, refcnt = %d, taplastunit = %d\n",
464 minor(tp->tap_dev), taprefcnt, taplastunit);
466 ifnet_serialize_all(ifp);
468 ifnet_deserialize_all(ifp);
471 SLIST_REMOVE(&tap_listhead, tp, tap_softc, tap_link);
477 release_dev(dev); /* tp association */
480 * Also destroy the cloned device
482 if (tp->tap_unit >= TAP_PREALLOCATED_UNITS) {
484 devfs_clone_bitmap_put(&DEVFS_CLONE_BITMAP(tap), tp->tap_unit);
495 * Destroy a tap instance.
498 tap_clone_destroy(struct ifnet *ifp)
500 struct tap_softc *tp = ifp->if_softc;
502 if ((tp->tap_flags & TAP_CLONE) == 0)
505 TAPDEBUG(&tp->tap_if, "clone destroyed. minor = %#x tap_flags = 0x%x\n",
506 minor(tp->tap_dev), tp->tap_flags);
515 * Network interface initialization function (called with if serializer held)
522 struct tap_softc *tp = xtp;
523 struct ifnet *ifp = &tp->tap_if;
525 TAPDEBUG(ifp, "initializing, minor = %#x tap_flags = 0x%x\n",
526 minor(tp->tap_dev), tp->tap_flags);
528 ASSERT_IFNET_SERIALIZED_ALL(ifp);
532 ifp->if_flags |= IFF_RUNNING;
533 ifp->if_flags &= ~IFF_OACTIVE;
535 /* attempt to start output */
543 * Process an ioctl request on network interface (called with if serializer
549 tapifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
551 struct tap_softc *tp = (struct tap_softc *)(ifp->if_softc);
552 struct ifstat *ifs = NULL;
559 dummy = ether_ioctl(ifp, cmd, data);
566 case SIOCADDMULTI: /* XXX -- just like vmnet does */
571 ifs = (struct ifstat *)data;
572 dummy = strlen(ifs->ascii);
573 if ((tp->tap_flags & TAP_OPEN) &&
574 dummy < sizeof(ifs->ascii)) {
575 if (tp->tap_sigtd && tp->tap_sigtd->sio_proc) {
576 ksnprintf(ifs->ascii + dummy,
577 sizeof(ifs->ascii) - dummy,
578 "\tOpened by pid %d\n",
579 (int)tp->tap_sigtd->sio_proc->p_pid);
581 ksnprintf(ifs->ascii + dummy,
582 sizeof(ifs->ascii) - dummy,
583 "\tOpened by <unknown>\n");
599 * Queue packets from higher level ready to put out (called with if serializer
605 tapifstart(struct ifnet *ifp)
607 struct tap_softc *tp = ifp->if_softc;
612 TAPDEBUG(ifp, "starting, minor = %#x\n", minor(tp->tap_dev));
615 * do not junk pending output if we are in VMnet mode.
616 * XXX: can this do any harm because of queue overflow?
619 if (((tp->tap_flags & TAP_VMNET) == 0) &&
620 ((tp->tap_flags & TAP_READY) != TAP_READY)) {
621 TAPDEBUG(ifp, "not ready. minor = %#x, tap_flags = 0x%x\n",
622 minor(tp->tap_dev), tp->tap_flags);
623 ifq_purge(&ifp->if_snd);
627 ifp->if_flags |= IFF_OACTIVE;
630 while ((m = ifq_dequeue(&ifp->if_snd, NULL)) != NULL) {
643 if (tp->tap_flags & TAP_RWAIT) {
644 tp->tap_flags &= ~TAP_RWAIT;
648 KNOTE(&tp->tap_rkq.ki_note, 0);
650 if ((tp->tap_flags & TAP_ASYNC) && (tp->tap_sigio != NULL)) {
652 pgsigio(tp->tap_sigio, SIGIO, 0);
657 ifp->if_flags &= ~IFF_OACTIVE;
664 * The ops interface is now pretty minimal. Called via fileops with nothing
670 tapioctl(struct dev_ioctl_args *ap)
672 cdev_t dev = ap->a_head.a_dev;
673 caddr_t data = ap->a_data;
674 struct tap_softc *tp = dev->si_drv1;
675 struct ifnet *ifp = &tp->tap_if;
676 struct tapinfo *tapp = NULL;
681 ifnet_serialize_all(ifp);
686 tapp = (struct tapinfo *)data;
687 ifp->if_mtu = tapp->mtu;
688 ifp->if_type = tapp->type;
689 ifp->if_baudrate = tapp->baudrate;
693 tapp = (struct tapinfo *)data;
694 tapp->mtu = ifp->if_mtu;
695 tapp->type = ifp->if_type;
696 tapp->baudrate = ifp->if_baudrate;
700 tapdebug = *(int *)data;
704 *(int *)data = tapdebug;
709 tp->tap_flags |= TAP_ASYNC;
711 tp->tap_flags &= ~TAP_ASYNC;
717 /* Take a look at devq first */
718 IF_POLL(&tp->tap_devq, mb);
720 mb = ifq_poll(&ifp->if_snd);
723 for(; mb != NULL; mb = mb->m_next)
724 *(int *)data += mb->m_len;
729 error = fsetown(*(int *)data, &tp->tap_sigio);
733 *(int *)data = fgetown(&tp->tap_sigio);
736 /* this is deprecated, FIOSETOWN should be used instead */
738 error = fsetown(-(*(int *)data), &tp->tap_sigio);
741 /* this is deprecated, FIOGETOWN should be used instead */
743 *(int *)data = -fgetown(&tp->tap_sigio);
746 /* VMware/VMnet port ioctl's */
748 case SIOCGIFFLAGS: /* get ifnet flags */
749 bcopy(&ifp->if_flags, data, sizeof(ifp->if_flags));
752 case VMIO_SIOCSIFFLAGS: /* VMware/VMnet SIOCSIFFLAGS */
755 f &= ~IFF_CANTCHANGE;
757 ifp->if_flags = f | (ifp->if_flags & IFF_CANTCHANGE);
760 case OSIOCGIFADDR: /* get MAC address of the remote side */
762 bcopy(tp->ether_addr, data, sizeof(tp->ether_addr));
765 case SIOCSIFADDR: /* set MAC address of the remote side */
766 bcopy(data, tp->ether_addr, sizeof(tp->ether_addr));
773 ifnet_deserialize_all(ifp);
781 * The ops read interface - reads a packet at a time, or at
782 * least as much of a packet as can be read.
784 * Called from the fileops interface with nothing held.
789 tapread(struct dev_read_args *ap)
791 cdev_t dev = ap->a_head.a_dev;
792 struct uio *uio = ap->a_uio;
793 struct tap_softc *tp = dev->si_drv1;
794 struct ifnet *ifp = &tp->tap_if;
795 struct mbuf *m0 = NULL;
798 TAPDEBUG(ifp, "reading, minor = %#x\n", minor(tp->tap_dev));
800 if ((tp->tap_flags & TAP_READY) != TAP_READY) {
801 TAPDEBUG(ifp, "not ready. minor = %#x, tap_flags = 0x%x\n",
802 minor(tp->tap_dev), tp->tap_flags);
807 tp->tap_flags &= ~TAP_RWAIT;
809 /* sleep until we get a packet */
811 ifnet_serialize_all(ifp);
812 IF_DEQUEUE(&tp->tap_devq, m0);
814 if (ap->a_ioflag & IO_NDELAY) {
815 ifnet_deserialize_all(ifp);
816 return (EWOULDBLOCK);
818 tp->tap_flags |= TAP_RWAIT;
819 tsleep_interlock(tp, PCATCH);
820 ifnet_deserialize_all(ifp);
821 error = tsleep(tp, PCATCH | PINTERLOCKED, "taprd", 0);
825 ifnet_deserialize_all(ifp);
827 } while (m0 == NULL);
831 /* xfer packet to user space */
832 while ((m0 != NULL) && (uio->uio_resid > 0) && (error == 0)) {
833 len = (int)szmin(uio->uio_resid, m0->m_len);
837 error = uiomove(mtod(m0, caddr_t), (size_t)len, uio);
842 TAPDEBUG(ifp, "dropping mbuf, minor = %#x\n",
853 * The ops write interface - an atomic write is a packet - or else!
855 * Called from the fileops interface with nothing held.
860 tapwrite(struct dev_write_args *ap)
862 cdev_t dev = ap->a_head.a_dev;
863 struct uio *uio = ap->a_uio;
864 struct tap_softc *tp = dev->si_drv1;
865 struct ifnet *ifp = &tp->tap_if;
866 struct mbuf *top = NULL, **mp = NULL, *m = NULL;
870 TAPDEBUG(ifp, "writing, minor = %#x\n", minor(tp->tap_dev));
872 if ((tp->tap_flags & TAP_READY) != TAP_READY) {
873 TAPDEBUG(ifp, "not ready. minor = %#x, tap_flags = 0x%x\n",
874 minor(tp->tap_dev), tp->tap_flags);
878 if (uio->uio_resid == 0)
881 if (uio->uio_resid > TAPMRU) {
882 TAPDEBUG(ifp, "invalid packet len = %zu, minor = %#x\n",
883 uio->uio_resid, minor(tp->tap_dev));
887 tlen = uio->uio_resid;
889 /* get a header mbuf */
890 MGETHDR(m, MB_DONTWAIT, MT_DATA);
897 while ((error == 0) && (uio->uio_resid > 0)) {
898 m->m_len = (int)szmin(mlen, uio->uio_resid);
899 error = uiomove(mtod(m, caddr_t), (size_t)m->m_len, uio);
902 if (uio->uio_resid > 0) {
903 MGET(m, MB_DONTWAIT, MT_DATA);
918 top->m_pkthdr.len = (int)tlen;
919 top->m_pkthdr.rcvif = ifp;
922 * Ethernet bridge and bpf are handled in ether_input
924 * adjust mbuf and give packet to the ether_input
926 ifnet_serialize_all(ifp);
927 ifp->if_input(ifp, top);
928 ifp->if_ipackets ++; /* ibytes are counted in ether_input */
929 ifnet_deserialize_all(ifp);
935 * tapkqfilter - called from the fileops interface with nothing held
939 static int filt_tapread(struct knote *kn, long hint);
940 static int filt_tapwrite(struct knote *kn, long hint);
941 static void filt_tapdetach(struct knote *kn);
942 static struct filterops tapread_filtops =
943 { FILTEROP_ISFD, NULL, filt_tapdetach, filt_tapread };
944 static struct filterops tapwrite_filtops =
945 { FILTEROP_ISFD, NULL, filt_tapdetach, filt_tapwrite };
948 tapkqfilter(struct dev_kqfilter_args *ap)
950 cdev_t dev = ap->a_head.a_dev;
951 struct knote *kn = ap->a_kn;
952 struct tap_softc *tp;
957 list = &tp->tap_rkq.ki_note;
961 switch(kn->kn_filter) {
963 kn->kn_fop = &tapread_filtops;
964 kn->kn_hook = (void *)tp;
967 kn->kn_fop = &tapwrite_filtops;
968 kn->kn_hook = (void *)tp;
971 ap->a_result = EOPNOTSUPP;
976 knote_insert(list, kn);
981 filt_tapread(struct knote *kn, long hint)
983 struct tap_softc *tp = (void *)kn->kn_hook;
985 if (IF_QEMPTY(&tp->tap_devq) == 0) /* XXX serializer */
992 filt_tapwrite(struct knote *kn, long hint)
994 /* Always ready for a write */
999 filt_tapdetach(struct knote *kn)
1001 struct tap_softc *tp = (void *)kn->kn_hook;
1003 knote_remove(&tp->tap_rkq.ki_note, kn);
1007 tapifstop(struct tap_softc *tp, int clear_flags)
1009 struct ifnet *ifp = &tp->tap_if;
1011 ASSERT_IFNET_SERIALIZED_ALL(ifp);
1012 IF_DRAIN(&tp->tap_devq);
1013 tp->tap_flags &= ~TAP_CLOSEDOWN;
1015 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1019 tapifflags(struct tap_softc *tp)
1021 struct ifnet *ifp = &tp->arpcom.ac_if;
1023 ASSERT_IFNET_SERIALIZED_ALL(ifp);
1024 if ((tp->tap_flags & TAP_VMNET) == 0) {
1026 * Only for non-vmnet tap(4)
1028 if (ifp->if_flags & IFF_UP) {
1029 if ((ifp->if_flags & IFF_RUNNING) == 0)