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>
51 #include <sys/signalvar.h>
52 #include <sys/socket.h>
53 #include <sys/sockio.h>
54 #include <sys/sysctl.h>
55 #include <sys/systm.h>
56 #include <sys/ttycom.h>
58 #include <sys/vnode.h>
59 #include <sys/serialize.h>
61 #include <sys/thread2.h>
62 #include <sys/mplock2.h>
65 #include <net/ethernet.h>
67 #include <net/ifq_var.h>
68 #include <net/if_arp.h>
69 #include <net/if_clone.h>
70 #include <net/route.h>
71 #include <sys/devfs.h>
73 #include <netinet/in.h>
75 #include "if_tapvar.h"
78 #define TAP_IFFLAGS (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST)
80 #define TAP_PREALLOCATED_UNITS 4
82 #define CDEV_NAME "tap"
83 #define CDEV_MAJOR 149
84 #define TAPDEBUG if (tapdebug) if_printf
88 #define VMNET_DEV_MASK 0x00010000
90 DEVFS_DECLARE_CLONE_BITMAP(tap);
93 static int tapmodevent (module_t, int, void *);
96 static struct tap_softc *tapcreate(int, cdev_t);
97 static void tapdestroy(struct tap_softc *);
100 static int tap_clone_create(struct if_clone *, int, caddr_t);
101 static void tap_clone_destroy(struct ifnet *);
104 /* network interface */
105 static void tapifstart (struct ifnet *);
106 static int tapifioctl (struct ifnet *, u_long, caddr_t,
108 static void tapifinit (void *);
109 static void tapifstop(struct tap_softc *, int);
110 static void tapifflags(struct tap_softc *);
112 /* character device */
113 static d_open_t tapopen;
114 static d_clone_t tapclone;
115 static d_close_t tapclose;
116 static d_read_t tapread;
117 static d_write_t tapwrite;
118 static d_ioctl_t tapioctl;
119 static d_kqfilter_t tapkqfilter;
121 static struct dev_ops tap_ops = {
122 { CDEV_NAME, CDEV_MAJOR, 0 },
128 .d_kqfilter = tapkqfilter
131 static int taprefcnt = 0; /* module ref. counter */
132 static int taplastunit = -1; /* max. open unit number */
133 static int tapdebug = 0; /* debug flag */
134 static int tapuopen = 0; /* all user open() */
135 static int tapuponopen = 0; /* IFF_UP */
137 MALLOC_DECLARE(M_TAP);
138 MALLOC_DEFINE(M_TAP, CDEV_NAME, "Ethernet tunnel interface");
139 struct if_clone tap_cloner = IF_CLONE_INITIALIZER("tap",
140 tap_clone_create, tap_clone_destroy,
142 static SLIST_HEAD(,tap_softc) tap_listhead =
143 SLIST_HEAD_INITIALIZER(&tap_listhead);
145 SYSCTL_INT(_debug, OID_AUTO, if_tap_debug, CTLFLAG_RW, &tapdebug, 0, "");
146 SYSCTL_DECL(_net_link);
147 SYSCTL_NODE(_net_link, OID_AUTO, tap, CTLFLAG_RW, 0,
148 "Ethernet tunnel software network interface");
149 SYSCTL_INT(_net_link_tap, OID_AUTO, user_open, CTLFLAG_RW, &tapuopen, 0,
150 "Allow user to open /dev/tap (based on node permissions)");
151 SYSCTL_INT(_net_link_tap, OID_AUTO, up_on_open, CTLFLAG_RW, &tapuponopen, 0,
152 "Bring interface up when /dev/tap is opened");
153 SYSCTL_INT(_net_link_tap, OID_AUTO, debug, CTLFLAG_RW, &tapdebug, 0, "");
155 DEV_MODULE(if_tap, tapmodevent, NULL);
160 * module event handler
163 tapmodevent(module_t mod, int type, void *data)
165 static int attached = 0;
166 struct tap_softc *tp, *ntp;
174 make_autoclone_dev(&tap_ops, &DEVFS_CLONE_BITMAP(tap), tapclone,
175 UID_ROOT, GID_WHEEL, 0600, "tap");
176 SLIST_INIT(&tap_listhead);
177 if_clone_attach(&tap_cloner);
179 for (i = 0; i < TAP_PREALLOCATED_UNITS; ++i) {
180 make_dev(&tap_ops, i, UID_ROOT, GID_WHEEL,
182 devfs_clone_bitmap_set(&DEVFS_CLONE_BITMAP(tap), i);
192 if_clone_detach(&tap_cloner);
194 /* Maintain tap ifs in a local list */
195 SLIST_FOREACH_MUTABLE(tp, &tap_listhead, tap_link, ntp)
200 devfs_clone_handler_del("tap");
201 dev_ops_remove_all(&tap_ops);
202 devfs_clone_bitmap_uninit(&DEVFS_CLONE_BITMAP(tap));
214 * tapcreate - create or clone an interface
216 static struct tap_softc *
217 tapcreate(int unit, cdev_t dev)
219 const char *name = TAP;
221 struct tap_softc *tp;
222 uint8_t ether_addr[ETHER_ADDR_LEN];
224 tp = kmalloc(sizeof(*tp), M_TAP, M_WAITOK | M_ZERO);
229 reference_dev(dev); /* tp association */
231 /* generate fake MAC address: 00 bd xx xx xx unit_no */
232 ether_addr[0] = 0x00;
233 ether_addr[1] = 0xbd;
234 bcopy(&ticks, ðer_addr[2], 3);
235 ether_addr[5] = (u_char)unit;
237 /* fill the rest and attach interface */
241 if_initname(ifp, name, unit);
242 if (unit > taplastunit)
245 ifp->if_init = tapifinit;
246 ifp->if_start = tapifstart;
247 ifp->if_ioctl = tapifioctl;
248 ifp->if_mtu = ETHERMTU;
249 ifp->if_flags = TAP_IFFLAGS;
250 ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
251 ifq_set_ready(&ifp->if_snd);
253 ether_ifattach(ifp, ether_addr, NULL);
255 tp->tap_flags |= TAP_INITED;
256 tp->tap_devq.ifq_maxlen = ifqmaxlen;
258 SLIST_INSERT_HEAD(&tap_listhead, tp, tap_link);
260 TAPDEBUG(ifp, "created. minor = %#x\n", minor(dev));
268 struct tap_softc *tp;
270 SLIST_FOREACH(tp, &tap_listhead, tap_link) {
271 if (tp->tap_unit == unit)
280 * Create a new tap instance via ifconfig.
283 tap_clone_create(struct if_clone *ifc __unused, int unit,
284 caddr_t param __unused)
286 struct tap_softc *tp;
291 if (!devfs_clone_bitmap_chk(&DEVFS_CLONE_BITMAP(tap), unit)) {
292 devfs_clone_bitmap_set(&DEVFS_CLONE_BITMAP(tap), unit);
293 dev = make_dev(&tap_ops, unit, UID_ROOT, GID_WHEEL,
294 0600, "%s%d", TAP, unit);
296 dev = devfs_find_device_by_name("%s%d", TAP, unit);
299 KKASSERT(dev != NULL);
300 tp = tapcreate(unit, dev);
302 tp->tap_flags |= TAP_CLONE;
303 TAPDEBUG(&tp->tap_if, "clone created. minor = %#x tap_flags = 0x%x\n",
304 minor(tp->tap_dev), tp->tap_flags);
312 * to open tunnel. must be superuser
315 tapopen(struct dev_open_args *ap)
318 struct tap_softc *tp = NULL;
319 struct ifnet *ifp = NULL;
323 (error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) != 0)
327 dev = ap->a_head.a_dev;
330 tp = tapcreate(minor(dev), dev);
331 if (tp->tap_flags & TAP_OPEN) {
335 ifp = &tp->arpcom.ac_if;
337 if ((tp->tap_flags & TAP_CLONE) == 0) {
338 EVENTHANDLER_INVOKE(ifnet_attach_event, ifp);
340 /* Announce the return of the interface. */
341 rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
344 bcopy(tp->arpcom.ac_enaddr, tp->ether_addr, sizeof(tp->ether_addr));
346 if (curthread->td_proc)
347 fsetown(curthread->td_proc->p_pid, &tp->tap_sigtd);
348 tp->tap_flags |= TAP_OPEN;
351 if (tapuponopen && (ifp->if_flags & IFF_UP) == 0) {
356 ifnet_serialize_all(ifp);
358 ifnet_deserialize_all(ifp);
360 tp->tap_flags |= TAP_CLOSEDOWN;
363 TAPDEBUG(ifp, "opened. minor = %#x, refcnt = %d, taplastunit = %d\n",
364 minor(tp->tap_dev), taprefcnt, taplastunit);
371 tapclone(struct dev_clone_args *ap)
375 unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(tap), 0);
376 ap->a_dev = make_only_dev(&tap_ops, unit, UID_ROOT, GID_WHEEL,
377 0600, "%s%d", TAP, unit);
378 tapcreate(unit, ap->a_dev);
385 * close the device - mark i/f down & delete routing info
388 tapclose(struct dev_close_args *ap)
390 cdev_t dev = ap->a_head.a_dev;
391 struct tap_softc *tp = dev->si_drv1;
392 struct ifnet *ifp = &tp->tap_if;
397 /* Junk all pending output */
398 ifq_purge(&ifp->if_snd);
401 * Do not bring the interface down, and do not anything with
402 * interface, if we are in VMnet mode. just close the device.
404 * If the interface is not cloned, we always bring it down.
406 * If the interface is cloned, then we bring it down during
407 * closing only if it was brought up during opening.
409 if ((tp->tap_flags & TAP_VMNET) == 0 &&
410 ((tp->tap_flags & TAP_CLONE) == 0 ||
411 (tp->tap_flags & TAP_CLOSEDOWN))) {
412 if (ifp->if_flags & IFF_UP)
416 ifnet_serialize_all(ifp);
417 tapifstop(tp, clear_flags);
418 ifnet_deserialize_all(ifp);
420 if ((tp->tap_flags & TAP_CLONE) == 0) {
421 if_purgeaddrs_nolink(ifp);
423 EVENTHANDLER_INVOKE(ifnet_detach_event, ifp);
425 /* Announce the departure of the interface. */
426 rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
429 funsetown(tp->tap_sigio);
430 tp->tap_sigio = NULL;
431 KNOTE(&tp->tap_rsel.si_note, 0);
433 tp->tap_flags &= ~TAP_OPEN;
434 funsetown(tp->tap_sigtd);
435 tp->tap_sigtd = NULL;
440 if_printf(ifp, "minor = %#x, refcnt = %d is out of sync. "
441 "set refcnt to 0\n", minor(tp->tap_dev), taprefcnt);
444 TAPDEBUG(ifp, "closed. minor = %#x, refcnt = %d, taplastunit = %d\n",
445 minor(tp->tap_dev), taprefcnt, taplastunit);
447 if (tp->tap_unit >= TAP_PREALLOCATED_UNITS)
457 * Destroy a tap instance.
460 tapdestroy(struct tap_softc *tp)
462 struct ifnet *ifp = &tp->arpcom.ac_if;
465 TAPDEBUG(ifp, "destroyed. minor = %#x, refcnt = %d, taplastunit = %d\n",
466 minor(tp->tap_dev), taprefcnt, taplastunit);
468 ifnet_serialize_all(ifp);
470 ifnet_deserialize_all(ifp);
473 SLIST_REMOVE(&tap_listhead, tp, tap_softc, tap_link);
479 release_dev(dev); /* tp association */
482 * Also destroy the cloned device
484 if (tp->tap_unit >= TAP_PREALLOCATED_UNITS) {
486 devfs_clone_bitmap_put(&DEVFS_CLONE_BITMAP(tap), tp->tap_unit);
497 * Destroy a tap instance.
500 tap_clone_destroy(struct ifnet *ifp)
502 struct tap_softc *tp = ifp->if_softc;
504 TAPDEBUG(&tp->tap_if, "clone destroyed. minor = %#x tap_flags = 0x%x\n",
505 minor(tp->tap_dev), tp->tap_flags);
506 if (tp->tap_flags & TAP_CLONE)
513 * Network interface initialization function (called with if serializer held)
520 struct tap_softc *tp = xtp;
521 struct ifnet *ifp = &tp->tap_if;
523 TAPDEBUG(ifp, "initializing, minor = %#x tap_flags = 0x%x\n",
524 minor(tp->tap_dev), tp->tap_flags);
526 ASSERT_IFNET_SERIALIZED_ALL(ifp);
530 ifp->if_flags |= IFF_RUNNING;
531 ifp->if_flags &= ~IFF_OACTIVE;
533 /* attempt to start output */
541 * Process an ioctl request on network interface (called with if serializer
547 tapifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
549 struct tap_softc *tp = (struct tap_softc *)(ifp->if_softc);
550 struct ifstat *ifs = NULL;
557 dummy = ether_ioctl(ifp, cmd, data);
564 case SIOCADDMULTI: /* XXX -- just like vmnet does */
569 ifs = (struct ifstat *)data;
570 dummy = strlen(ifs->ascii);
571 if ((tp->tap_flags & TAP_OPEN) &&
572 dummy < sizeof(ifs->ascii)) {
573 if (tp->tap_sigtd && tp->tap_sigtd->sio_proc) {
574 ksnprintf(ifs->ascii + dummy,
575 sizeof(ifs->ascii) - dummy,
576 "\tOpened by pid %d\n",
577 (int)tp->tap_sigtd->sio_proc->p_pid);
579 ksnprintf(ifs->ascii + dummy,
580 sizeof(ifs->ascii) - dummy,
581 "\tOpened by <unknown>\n");
597 * Queue packets from higher level ready to put out (called with if serializer
603 tapifstart(struct ifnet *ifp)
605 struct tap_softc *tp = ifp->if_softc;
610 TAPDEBUG(ifp, "starting, minor = %#x\n", minor(tp->tap_dev));
613 * do not junk pending output if we are in VMnet mode.
614 * XXX: can this do any harm because of queue overflow?
617 if (((tp->tap_flags & TAP_VMNET) == 0) &&
618 ((tp->tap_flags & TAP_READY) != TAP_READY)) {
619 TAPDEBUG(ifp, "not ready. minor = %#x, tap_flags = 0x%x\n",
620 minor(tp->tap_dev), tp->tap_flags);
621 ifq_purge(&ifp->if_snd);
625 ifp->if_flags |= IFF_OACTIVE;
628 while ((m = ifq_dequeue(&ifp->if_snd, NULL)) != NULL) {
641 if (tp->tap_flags & TAP_RWAIT) {
642 tp->tap_flags &= ~TAP_RWAIT;
647 KNOTE(&tp->tap_rsel.si_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 { 1, NULL, filt_tapdetach, filt_tapread };
944 static struct filterops tapwrite_filtops =
945 { 1, 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;
958 list = &tp->tap_rsel.si_note;
962 switch(kn->kn_filter) {
964 kn->kn_fop = &tapread_filtops;
965 kn->kn_hook = (void *)tp;
968 kn->kn_fop = &tapwrite_filtops;
969 kn->kn_hook = (void *)tp;
972 ap->a_result = EOPNOTSUPP;
977 SLIST_INSERT_HEAD(list, kn, kn_selnext);
984 filt_tapread(struct knote *kn, long hint)
986 struct tap_softc *tp = (void *)kn->kn_hook;
988 if (IF_QEMPTY(&tp->tap_devq) == 0) /* XXX serializer */
995 filt_tapwrite(struct knote *kn, long hint)
997 /* Always ready for a write */
1002 filt_tapdetach(struct knote *kn)
1004 struct tap_softc *tp = (void *)kn->kn_hook;
1006 SLIST_REMOVE(&tp->tap_rsel.si_note, kn, knote, kn_selnext);
1010 tapifstop(struct tap_softc *tp, int clear_flags)
1012 struct ifnet *ifp = &tp->tap_if;
1014 ASSERT_IFNET_SERIALIZED_ALL(ifp);
1015 IF_DRAIN(&tp->tap_devq);
1016 tp->tap_flags &= ~TAP_CLOSEDOWN;
1018 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1022 tapifflags(struct tap_softc *tp)
1024 struct ifnet *ifp = &tp->arpcom.ac_if;
1026 ASSERT_IFNET_SERIALIZED_ALL(ifp);
1027 if ((tp->tap_flags & TAP_VMNET) == 0) {
1029 * Only for non-vmnet tap(4)
1031 if (ifp->if_flags & IFF_UP) {
1032 if ((ifp->if_flags & IFF_RUNNING) == 0)