1 /* $NetBSD: if_tun.c,v 1.14 1994/06/29 06:36:25 cgd Exp $ */
4 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
5 * Nottingham University 1987.
7 * This source may be freely distributed, however I would be interested
8 * in any changes that are made.
10 * This driver takes packets off the IP i/f and hands them up to a
11 * user process to have its wicked way with. This driver has it's
12 * roots in a similar driver written by Phil Cockcroft (formerly) at
13 * UCL. This driver is based much more on read/write/poll mode of
16 * $FreeBSD: src/sys/net/if_tun.c,v 1.74.2.8 2002/02/13 00:43:11 dillon Exp $
21 #include "opt_inet6.h"
23 #include <sys/param.h>
26 #include <sys/systm.h>
28 #include <sys/socket.h>
30 #include <sys/device.h>
31 #include <sys/filio.h>
32 #include <sys/sockio.h>
33 #include <sys/thread2.h>
34 #include <sys/ttycom.h>
35 #include <sys/signalvar.h>
36 #include <sys/filedesc.h>
37 #include <sys/kernel.h>
38 #include <sys/sysctl.h>
40 #include <sys/vnode.h>
41 #include <sys/malloc.h>
42 #include <sys/mplock2.h>
43 #include <sys/devfs.h>
44 #include <sys/queue.h>
48 #include <net/if_types.h>
49 #include <net/if_clone.h>
50 #include <net/ifq_var.h>
51 #include <net/netisr.h>
52 #include <net/route.h>
55 #include <netinet/in.h>
58 #include "if_tunvar.h"
62 #define TUN_PREALLOCATED_UNITS 4
64 #define TUN_PREALLOCATED_UNITS NTUN
68 #define TUNDEBUG if (tundebug) if_printf
71 static int tunmodevent(module_t, int, void *);
74 static struct tun_softc *tuncreate(cdev_t, int);
75 static void tundestroy(struct tun_softc *sc);
78 static int tun_clone_create(struct if_clone *, int, caddr_t);
79 static int tun_clone_destroy(struct ifnet *);
81 /* network interface */
82 static int tunifinit(struct ifnet *);
83 static void tunifstart(struct ifnet *, struct ifaltq_subque *);
84 static int tunifoutput(struct ifnet *, struct mbuf *,
85 struct sockaddr *, struct rtentry *rt);
86 static int tunifioctl(struct ifnet *, u_long,
87 caddr_t, struct ucred *);
89 /* character device */
90 static d_open_t tunopen;
91 static d_close_t tunclose;
92 static d_read_t tunread;
93 static d_write_t tunwrite;
94 static d_ioctl_t tunioctl;
95 static d_kqfilter_t tunkqfilter;
96 static d_clone_t tunclone;
98 static struct dev_ops tun_ops = {
105 .d_kqfilter = tunkqfilter
109 static void tun_filter_detach(struct knote *);
110 static int tun_filter_read(struct knote *, long);
111 static int tun_filter_write(struct knote *, long);
113 static struct filterops tun_read_filtops = {
119 static struct filterops tun_write_filtops = {
126 static int tundebug = 0; /* debug flag */
127 static int tunrefcnt = 0; /* module reference counter */
129 static MALLOC_DEFINE(M_TUN, TUN, "Tunnel Interface");
131 static DEVFS_DEFINE_CLONE_BITMAP(tun);
133 struct if_clone tun_cloner = IF_CLONE_INITIALIZER(
134 TUN, tun_clone_create, tun_clone_destroy, 0, IF_MAXUNIT);
136 static SLIST_HEAD(,tun_softc) tun_listhead =
137 SLIST_HEAD_INITIALIZER(&tun_listhead);
139 SYSCTL_INT(_debug, OID_AUTO, if_tun_debug, CTLFLAG_RW, &tundebug, 0,
140 "Enable debug output");
141 SYSCTL_DECL(_net_link);
142 SYSCTL_NODE(_net_link, OID_AUTO, tun, CTLFLAG_RW, 0,
143 "IP tunnel software network interface");
144 SYSCTL_INT(_net_link_tun, OID_AUTO, debug, CTLFLAG_RW, &tundebug, 0,
145 "Enable debug output");
146 SYSCTL_INT(_net_link_tun, OID_AUTO, refcnt, CTLFLAG_RD, &tunrefcnt, 0,
147 "Number of opened devices");
149 DEV_MODULE(if_tun, tunmodevent, NULL);
152 * tunmodevent - module event handler
155 tunmodevent(module_t mod, int type, void *data)
157 static cdev_t dev = NULL;
158 struct tun_softc *sc, *sc_tmp;
163 dev = make_autoclone_dev(&tun_ops, &DEVFS_CLONE_BITMAP(tun),
164 tunclone, UID_UUCP, GID_DIALER,
167 SLIST_INIT(&tun_listhead);
168 if_clone_attach(&tun_cloner);
170 for (i = 0; i < TUN_PREALLOCATED_UNITS; ++i) {
171 make_dev(&tun_ops, i, UID_UUCP, GID_DIALER,
172 0600, "%s%d", TUN, i);
173 devfs_clone_bitmap_set(&DEVFS_CLONE_BITMAP(tun), i);
181 if_clone_detach(&tun_cloner);
183 SLIST_FOREACH_MUTABLE(sc, &tun_listhead, tun_link, sc_tmp)
186 dev_ops_remove_all(&tun_ops);
187 destroy_autoclone_dev(dev, &DEVFS_CLONE_BITMAP(tun));
198 tunclone(struct dev_clone_args *ap)
202 unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(tun), 0);
203 ap->a_dev = make_only_dev(&tun_ops, unit, UID_UUCP, GID_DIALER,
204 0600, "%s%d", TUN, unit);
206 if (tuncreate(ap->a_dev, 0) == NULL)
212 static struct tun_softc *
213 tuncreate(cdev_t dev, int flags)
215 struct tun_softc *sc;
217 int unit = minor(dev);
219 sc = kmalloc(sizeof(*sc), M_TUN, M_WAITOK | M_ZERO);
222 sc->tun_flags = TUN_INITED;
223 sc->tun_flags |= flags;
225 reference_dev(dev); /* device association */
227 ifp = sc->tun_ifp = if_alloc(IFT_PPP);
229 kprintf("%s: failed to if_alloc() interface for %s%d",
230 __func__, TUN, unit);
234 if_initname(ifp, TUN, unit);
235 ifp->if_mtu = TUNMTU;
236 ifp->if_ioctl = tunifioctl;
237 ifp->if_output = tunifoutput;
238 ifp->if_start = tunifstart;
239 ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
240 ifp->if_type = IFT_PPP;
242 ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
243 ifq_set_ready(&ifp->if_snd);
245 if_attach(ifp, NULL);
246 bpfattach(ifp, DLT_NULL, sizeof(u_int));
248 SLIST_INSERT_HEAD(&tun_listhead, sc, tun_link);
249 TUNDEBUG(ifp, "created, minor = %#x, flags = 0x%x\n",
250 unit, sc->tun_flags);
255 tundestroy(struct tun_softc *sc)
257 cdev_t dev = sc->tun_dev;
258 struct ifnet *ifp = sc->tun_ifp;
259 int unit = minor(dev);
261 TUNDEBUG(ifp, "destroyed, minor = %#x. Module refcnt = %d\n",
270 release_dev(dev); /* device disassociation */
272 /* Also destroy the cloned device */
273 if (unit >= TUN_PREALLOCATED_UNITS) {
275 devfs_clone_bitmap_put(&DEVFS_CLONE_BITMAP(tun), unit);
278 SLIST_REMOVE(&tun_listhead, sc, tun_softc, tun_link);
283 * tunnel open - must be superuser & the device must be configured in
286 tunopen(struct dev_open_args *ap)
288 cdev_t dev = ap->a_head.a_dev;
290 struct tun_softc *sc;
293 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) != 0)
297 if (sc == NULL && (sc = tuncreate(dev, TUN_MANUALMAKE)) == NULL)
299 if (sc->tun_flags & TUN_OPEN)
303 if ((sc->tun_flags & TUN_CLONE) == 0) {
304 EVENTHANDLER_INVOKE(ifnet_attach_event, ifp);
306 /* Announce the return of the interface. */
307 rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
310 sc->tun_pid = curproc->p_pid;
311 sc->tun_flags |= TUN_OPEN;
314 TUNDEBUG(ifp, "opened, minor = %#x. Module refcnt = %d\n",
315 minor(dev), tunrefcnt);
320 * close the device - mark interface down & delete routing info
323 tunclose(struct dev_close_args *ap)
325 cdev_t dev = ap->a_head.a_dev;
326 struct tun_softc *sc = dev->si_drv1;
327 struct ifnet *ifp = sc->tun_ifp;
328 int unit = minor(dev);
330 sc->tun_flags &= ~TUN_OPEN;
333 /* Junk all pending output. */
334 ifq_purge_all(&ifp->if_snd);
336 if (ifp->if_flags & IFF_UP)
338 ifp->if_flags &= ~IFF_RUNNING;
340 if ((sc->tun_flags & TUN_CLONE) == 0) {
341 if_purgeaddrs_nolink(ifp);
343 EVENTHANDLER_INVOKE(ifnet_detach_event, ifp);
345 /* Announce the departure of the interface. */
346 rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
349 funsetown(&sc->tun_sigio);
350 KNOTE(&sc->tun_rkq.ki_note, 0);
355 if_printf(ifp, ". Module refcnt = %d is out of sync! "
356 "Force refcnt to be 0.\n", tunrefcnt);
359 TUNDEBUG(ifp, "closed, minor = %#x. Module refcnt = %d\n",
362 /* Only auto-destroy if the interface was not manually created. */
363 if ((sc->tun_flags & TUN_MANUALMAKE) == 0 &&
364 unit >= TUN_PREALLOCATED_UNITS) {
374 * Interface clone support
376 * Create and destroy tun device/interface via ifconfig(8).
379 static struct tun_softc *
382 struct tun_softc *sc;
384 SLIST_FOREACH(sc, &tun_listhead, tun_link) {
385 if (minor(sc->tun_dev) == unit)
392 tun_clone_create(struct if_clone *ifc __unused, int unit,
393 caddr_t param __unused)
395 struct tun_softc *sc;
400 if (!devfs_clone_bitmap_chk(&DEVFS_CLONE_BITMAP(tun), unit)) {
401 devfs_clone_bitmap_set(&DEVFS_CLONE_BITMAP(tun), unit);
402 dev = make_dev(&tun_ops, unit, UID_UUCP, GID_DIALER,
403 0600, "%s%d", TUN, unit);
405 dev = devfs_find_device_by_name("%s%d", TUN, unit);
410 if ((sc = tuncreate(dev, TUN_MANUALMAKE)) == NULL)
414 sc->tun_flags |= TUN_CLONE;
415 TUNDEBUG(sc->tun_ifp, "clone created, minor = %#x, flags = 0x%x\n",
416 minor(sc->tun_dev), sc->tun_flags);
422 tun_clone_destroy(struct ifnet * ifp)
424 struct tun_softc *sc = ifp->if_softc;
426 if ((sc->tun_flags & TUN_CLONE) == 0)
429 TUNDEBUG(ifp, "clone destroyed, minor = %#x, flags = 0x%x\n",
430 minor(sc->tun_dev), sc->tun_flags);
438 * Network interface functions
442 tunifinit(struct ifnet *ifp)
445 struct tun_softc *sc = ifp->if_softc;
447 struct ifaddr_container *ifac;
450 TUNDEBUG(ifp, "initialize\n");
452 ifp->if_flags |= IFF_UP | IFF_RUNNING;
453 getmicrotime(&ifp->if_lastchange);
455 TAILQ_FOREACH(ifac, &ifp->if_addrheads[mycpuid], ifa_link) {
456 struct ifaddr *ifa = ifac->ifa;
458 if (ifa->ifa_addr == NULL) {
460 /* XXX: Should maybe return straight off? */
463 if (ifa->ifa_addr->sa_family == AF_INET) {
464 struct sockaddr_in *si;
466 si = (struct sockaddr_in *)ifa->ifa_addr;
467 if (si->sin_addr.s_addr)
468 sc->tun_flags |= TUN_IASET;
477 * Process an ioctl request.
482 tunifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr)
484 struct ifreq *ifr = (struct ifreq *)data;
485 struct tun_softc *sc = ifp->if_softc;
491 ifs = (struct ifstat *)data;
493 ksprintf(ifs->ascii + strlen(ifs->ascii),
494 "\tOpened by PID %d\n", sc->tun_pid);
497 error = tunifinit(ifp);
498 TUNDEBUG(ifp, "address set, error=%d\n", error);
501 error = tunifinit(ifp);
502 TUNDEBUG(ifp, "destination address set, error=%d\n", error);
505 ifp->if_mtu = ifr->ifr_mtu;
506 TUNDEBUG(ifp, "mtu set\n");
519 * Start packet transmission on the interface.
520 * when the interface queue is rate-limited by ALTQ,
521 * if_start is needed to drain packets from the queue in order
522 * to notify readers when outgoing packets become ready.
525 tunifstart(struct ifnet *ifp, struct ifaltq_subque *ifsq)
527 struct tun_softc *sc = ifp->if_softc;
530 ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq);
532 if (!ifq_is_enabled(&ifp->if_snd))
537 if (sc->tun_flags & TUN_RWAIT) {
538 sc->tun_flags &= ~TUN_RWAIT;
541 if (sc->tun_flags & TUN_ASYNC && sc->tun_sigio)
542 pgsigio(sc->tun_sigio, SIGIO, 0);
543 ifsq_deserialize_hw(ifsq);
544 KNOTE(&sc->tun_rkq.ki_note, 0);
545 ifsq_serialize_hw(ifsq);
550 * tunifoutput - queue packets from higher level ready to put out.
555 tunifoutput_serialized(struct ifnet *ifp, struct mbuf *m0,
556 struct sockaddr *dst, struct rtentry *rt)
558 struct tun_softc *sc = ifp->if_softc;
560 struct altq_pktattr pktattr;
562 TUNDEBUG(ifp, "output\n");
564 if ((sc->tun_flags & TUN_READY) != TUN_READY) {
565 TUNDEBUG(ifp, "not ready, flags = 0x%x\n", sc->tun_flags);
571 * if the queueing discipline needs packet classification,
572 * do it before prepending link headers.
574 ifq_classify(&ifp->if_snd, m0, dst->sa_family, &pktattr);
576 /* BPF write needs to be handled specially */
577 if (dst->sa_family == AF_UNSPEC) {
578 dst->sa_family = *(mtod(m0, int *));
579 m0->m_len -= sizeof(int);
580 m0->m_pkthdr.len -= sizeof(int);
581 m0->m_data += sizeof(int);
588 * We need to prepend the address family as
591 uint32_t af = dst->sa_family;
593 bpf_ptap(ifp->if_bpf, m0, &af, sizeof(af));
598 /* prepend sockaddr? this may abort if the mbuf allocation fails */
599 if (sc->tun_flags & TUN_LMODE) {
600 /* allocate space for sockaddr */
601 M_PREPEND(m0, dst->sa_len, M_NOWAIT);
603 /* if allocation failed drop packet */
605 IFNET_STAT_INC(ifp, oerrors, 1);
608 bcopy(dst, m0->m_data, dst->sa_len);
612 if (sc->tun_flags & TUN_IFHEAD) {
613 /* Prepend the address family */
614 M_PREPEND(m0, 4, M_NOWAIT);
616 /* if allocation failed drop packet */
618 IFNET_STAT_INC(ifp, oerrors, 1);
621 *(u_int32_t *)m0->m_data = htonl(dst->sa_family);
625 if (dst->sa_family != AF_INET)
629 return (EAFNOSUPPORT);
633 error = ifq_handoff(ifp, m0, &pktattr);
635 IFNET_STAT_INC(ifp, collisions, 1);
637 IFNET_STAT_INC(ifp, opackets, 1);
638 if (sc->tun_flags & TUN_RWAIT) {
639 sc->tun_flags &= ~TUN_RWAIT;
643 if (sc->tun_flags & TUN_ASYNC && sc->tun_sigio)
644 pgsigio(sc->tun_sigio, SIGIO, 0);
646 ifnet_deserialize_all(ifp);
647 KNOTE(&sc->tun_rkq.ki_note, 0);
648 ifnet_serialize_all(ifp);
654 tunifoutput(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst,
659 ifnet_serialize_all(ifp);
660 error = tunifoutput_serialized(ifp, m0, dst, rt);
661 ifnet_deserialize_all(ifp);
668 * the ops interface is now pretty minimal.
671 tunioctl(struct dev_ioctl_args *ap)
673 cdev_t dev = ap->a_head.a_dev;
674 caddr_t data = ap->a_data;
675 struct tun_softc *sc = dev->si_drv1;
676 struct ifnet *ifp = sc->tun_ifp;
678 struct tuninfo *tunp;
683 tunp = (struct tuninfo *)data;
684 if (ifp->if_type != tunp->type)
686 if (tunp->mtu < IF_MINMTU)
688 ifp->if_mtu = tunp->mtu;
689 ifp->if_baudrate = tunp->baudrate;
693 tunp = (struct tuninfo *)data;
694 tunp->mtu = ifp->if_mtu;
695 tunp->type = ifp->if_type;
696 tunp->baudrate = ifp->if_baudrate;
700 ifr = (struct ifreq *)data;
701 strlcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
705 tundebug = *(int *)data;
709 *(int *)data = tundebug;
714 sc->tun_flags |= TUN_LMODE;
715 sc->tun_flags &= ~TUN_IFHEAD;
717 sc->tun_flags &= ~TUN_LMODE;
723 sc->tun_flags |= TUN_IFHEAD;
724 sc->tun_flags &= ~TUN_LMODE;
726 sc->tun_flags &= ~TUN_IFHEAD;
731 *(int *)data = (sc->tun_flags & TUN_IFHEAD) ? 1 : 0;
735 /* deny this if UP */
736 if (ifp->if_flags & IFF_UP)
739 switch (*(int *)data & ~IFF_MULTICAST) {
740 case IFF_POINTOPOINT:
742 ifp->if_flags &= ~(IFF_BROADCAST | IFF_POINTOPOINT);
743 ifp->if_flags |= *(int *)data;
751 sc->tun_pid = curproc->p_pid;
756 sc->tun_flags |= TUN_ASYNC;
758 sc->tun_flags &= ~TUN_ASYNC;
762 *(int *)data = ifsq_poll_pktlen(
763 ifq_get_subq_default(&ifp->if_snd));
767 error = fsetown(*(int *)data, &sc->tun_sigio);
771 *(int *)data = fgetown(&sc->tun_sigio);
774 /* This is deprecated, FIOSETOWN should be used instead. */
776 error = fsetown(-(*(int *)data), &sc->tun_sigio);
779 /* This is deprecated, FIOGETOWN should be used instead. */
781 *(int *)data = -fgetown(&sc->tun_sigio);
793 * The ops read interface - reads a packet at a time, or at
794 * least as much of a packet as can be read.
797 tunread(struct dev_read_args *ap)
799 cdev_t dev = ap->a_head.a_dev;
800 struct uio *uio = ap->a_uio;
801 struct tun_softc *sc = dev->si_drv1;
802 struct ifnet *ifp = sc->tun_ifp;
803 struct ifaltq_subque *ifsq = ifq_get_subq_default(&ifp->if_snd);
807 TUNDEBUG(ifp, "read\n");
808 if ((sc->tun_flags & TUN_READY) != TUN_READY) {
809 TUNDEBUG(ifp, "not ready, flags = 0x%x\n", sc->tun_flags);
813 sc->tun_flags &= ~TUN_RWAIT;
815 ifnet_serialize_all(ifp);
817 while ((m0 = ifsq_dequeue(ifsq)) == NULL) {
818 if (ap->a_ioflag & IO_NDELAY) {
819 ifnet_deserialize_all(ifp);
820 return (EWOULDBLOCK);
822 sc->tun_flags |= TUN_RWAIT;
823 ifnet_deserialize_all(ifp);
824 if ((error = tsleep(sc, PCATCH, "tunread", 0)) != 0)
826 ifnet_serialize_all(ifp);
829 ifnet_deserialize_all(ifp);
831 while (m0 && uio->uio_resid > 0 && error == 0) {
832 len = (int)szmin(uio->uio_resid, m0->m_len);
834 error = uiomove(mtod(m0, caddr_t), (size_t)len, uio);
839 TUNDEBUG(ifp, "dropping mbuf\n");
846 * the ops write interface - an atomic write is a packet - or else!
849 tunwrite(struct dev_write_args *ap)
851 cdev_t dev = ap->a_head.a_dev;
852 struct uio *uio = ap->a_uio;
853 struct tun_softc *sc = dev->si_drv1;
854 struct ifnet *ifp = sc->tun_ifp;
855 struct mbuf *top, **mp, *m;
857 uint32_t family, mru;
861 TUNDEBUG(ifp, "tunwrite\n");
863 if (uio->uio_resid == 0)
867 if (sc->tun_flags & TUN_IFHEAD)
868 mru += sizeof(family);
869 if (uio->uio_resid > mru) {
870 TUNDEBUG(ifp, "len = %zd!\n", uio->uio_resid);
874 /* get a header mbuf */
875 MGETHDR(m, M_WAITOK, MT_DATA);
879 tlen = uio->uio_resid;
882 while (error == 0 && uio->uio_resid > 0) {
883 m->m_len = (int)szmin(MHLEN, uio->uio_resid);
884 error = uiomove(mtod(m, caddr_t), (size_t)m->m_len, uio);
887 if (uio->uio_resid > 0) {
888 MGET(m, M_WAITOK, MT_DATA);
898 IFNET_STAT_INC(ifp, ierrors, 1);
902 top->m_pkthdr.len = (int)tlen;
903 top->m_pkthdr.rcvif = ifp;
909 if (sc->tun_flags & TUN_IFHEAD) {
911 * Conveniently, we already have a 4-byte
912 * address family prepended to our packet !
913 * Inconveniently, it's in the wrong byte
916 if ((top = m_pullup(top, sizeof(family)))
921 *mtod(top, u_int32_t *) =
922 ntohl(*mtod(top, u_int32_t *));
923 bpf_mtap(ifp->if_bpf, top);
924 *mtod(top, u_int32_t *) =
925 htonl(*mtod(top, u_int32_t *));
928 * We need to prepend the address family as
931 static const uint32_t af = AF_INET;
933 bpf_ptap(ifp->if_bpf, top, &af, sizeof(af));
940 if (sc->tun_flags & TUN_IFHEAD) {
941 if (top->m_len < sizeof(family) &&
942 (top = m_pullup(top, sizeof(family))) == NULL)
944 family = ntohl(*mtod(top, u_int32_t *));
945 m_adj(top, sizeof(family));
950 IFNET_STAT_INC(ifp, ibytes, top->m_pkthdr.len);
951 IFNET_STAT_INC(ifp, ipackets, 1);
966 return (EAFNOSUPPORT);
969 netisr_queue(isr, top);
975 * tunkqfilter - support for the kevent() system call.
978 tunkqfilter(struct dev_kqfilter_args *ap)
980 cdev_t dev = ap->a_head.a_dev;
981 struct tun_softc *sc = dev->si_drv1;
982 struct ifnet *ifp = sc->tun_ifp;
983 struct knote *kn = ap->a_kn;
987 ifnet_serialize_all(ifp);
989 switch (kn->kn_filter) {
991 kn->kn_fop = &tun_read_filtops;
992 kn->kn_hook = (caddr_t)sc;
995 kn->kn_fop = &tun_write_filtops;
996 kn->kn_hook = (caddr_t)sc;
999 ifnet_deserialize_all(ifp);
1000 ap->a_result = EOPNOTSUPP;
1004 klist = &sc->tun_rkq.ki_note;
1005 knote_insert(klist, kn);
1006 ifnet_deserialize_all(ifp);
1012 tun_filter_detach(struct knote *kn)
1014 struct tun_softc *sc = (struct tun_softc *)kn->kn_hook;
1015 struct klist *klist = &sc->tun_rkq.ki_note;
1017 knote_remove(klist, kn);
1021 tun_filter_write(struct knote *kn, long hint)
1023 /* Always ready for a write */
1028 tun_filter_read(struct knote *kn, long hint)
1030 struct tun_softc *sc = (struct tun_softc *)kn->kn_hook;
1031 struct ifnet *ifp = sc->tun_ifp;
1034 ifnet_serialize_all(ifp);
1035 if (!ifsq_is_empty(ifq_get_subq_default(&ifp->if_snd)))
1037 ifnet_deserialize_all(ifp);