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
19 #include "opt_atalk.h"
21 #include "opt_inet6.h"
25 #include <sys/param.h>
28 #include <sys/systm.h>
30 #include <sys/module.h>
31 #include <sys/socket.h>
32 #include <sys/fcntl.h>
33 #include <sys/filio.h>
34 #include <sys/sockio.h>
35 #include <sys/ttycom.h>
37 #include <sys/selinfo.h>
38 #include <sys/signalvar.h>
39 #include <sys/filedesc.h>
40 #include <sys/kernel.h>
41 #include <sys/sysctl.h>
44 #include <sys/malloc.h>
45 #include <sys/random.h>
48 #include <net/if_types.h>
49 #include <net/netisr.h>
50 #include <net/route.h>
52 #include <netinet/in.h>
55 #include <net/if_tun.h>
57 #include <sys/queue.h>
59 #include <security/mac/mac_framework.h>
62 * tun_list is protected by global tunmtx. Other mutable fields are
63 * protected by tun->tun_mtx, or by their owning subsystem. tun_dev is
64 * static for the duration of a tunnel interface.
67 TAILQ_ENTRY(tun_softc) tun_list;
69 u_short tun_flags; /* misc flags */
70 #define TUN_OPEN 0x0001
71 #define TUN_INITED 0x0002
72 #define TUN_RCOLL 0x0004
73 #define TUN_IASET 0x0008
74 #define TUN_DSTADDR 0x0010
75 #define TUN_LMODE 0x0020
76 #define TUN_RWAIT 0x0040
77 #define TUN_ASYNC 0x0080
78 #define TUN_IFHEAD 0x0100
80 #define TUN_READY (TUN_OPEN | TUN_INITED)
83 * XXXRW: tun_pid is used to exclusively lock /dev/tun. Is this
84 * actually needed? Can we just return EBUSY if already open?
85 * Problem is that this involved inherent races when a tun device
86 * is handed off from one process to another, as opposed to just
87 * being slightly stale informationally.
89 pid_t tun_pid; /* owning pid */
90 struct ifnet *tun_ifp; /* the interface */
91 struct sigio *tun_sigio; /* information for async I/O */
92 struct selinfo tun_rsel; /* read select */
93 struct mtx tun_mtx; /* protect mutable softc fields */
95 #define TUN2IFP(sc) ((sc)->tun_ifp)
97 #define TUNDEBUG if (tundebug) if_printf
101 * All mutable global variables in if_tun are locked using tunmtx, with
102 * the exception of tundebug, which is used unlocked, and tunclones,
103 * which is static after setup.
105 static struct mtx tunmtx;
106 static MALLOC_DEFINE(M_TUN, TUNNAME, "Tunnel Interface");
107 static int tundebug = 0;
108 static struct clonedevs *tunclones;
109 static TAILQ_HEAD(,tun_softc) tunhead = TAILQ_HEAD_INITIALIZER(tunhead);
110 SYSCTL_INT(_debug, OID_AUTO, if_tun_debug, CTLFLAG_RW, &tundebug, 0, "");
112 static void tunclone(void *arg, struct ucred *cred, char *name,
113 int namelen, struct cdev **dev);
114 static void tuncreate(struct cdev *dev);
115 static int tunifioctl(struct ifnet *, u_long, caddr_t);
116 static int tuninit(struct ifnet *);
117 static int tunmodevent(module_t, int, void *);
118 static int tunoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
120 static void tunstart(struct ifnet *);
122 static d_open_t tunopen;
123 static d_close_t tunclose;
124 static d_read_t tunread;
125 static d_write_t tunwrite;
126 static d_ioctl_t tunioctl;
127 static d_poll_t tunpoll;
128 static d_kqfilter_t tunkqfilter;
130 static int tunkqread(struct knote *, long);
131 static int tunkqwrite(struct knote *, long);
132 static void tunkqdetach(struct knote *);
134 static struct filterops tun_read_filterops = {
137 .f_detach = tunkqdetach,
138 .f_event = tunkqread,
141 static struct filterops tun_write_filterops = {
144 .f_detach = tunkqdetach,
145 .f_event = tunkqwrite,
148 static struct cdevsw tun_cdevsw = {
149 .d_version = D_VERSION,
150 .d_flags = D_PSEUDO | D_NEEDGIANT,
157 .d_kqfilter = tunkqfilter,
162 tunclone(void *arg, struct ucred *cred, char *name, int namelen,
170 if (strcmp(name, TUNNAME) == 0) {
172 } else if (dev_stdclone(name, NULL, TUNNAME, &u) != 1)
173 return; /* Don't recognise the name */
174 if (u != -1 && u > IF_MAXUNIT)
175 return; /* Unit number too high */
177 /* find any existing device, or allocate new unit number */
178 i = clone_create(&tunclones, &tun_cdevsw, &u, dev, 0);
180 /* No preexisting struct cdev *, create one */
181 *dev = make_dev(&tun_cdevsw, unit2minor(u),
182 UID_UUCP, GID_DIALER, 0600, "tun%d", u);
185 (*dev)->si_flags |= SI_CHEAPCLONE;
191 tun_destroy(struct tun_softc *tp)
196 KASSERT((tp->tun_flags & TUN_OPEN) == 0,
197 ("tununits is out of sync - unit %d", TUN2IFP(tp)->if_dunit));
200 bpfdetach(TUN2IFP(tp));
201 if_detach(TUN2IFP(tp));
202 if_free(TUN2IFP(tp));
204 knlist_destroy(&tp->tun_rsel.si_note);
205 mtx_destroy(&tp->tun_mtx);
210 tunmodevent(module_t mod, int type, void *data)
212 static eventhandler_tag tag;
213 struct tun_softc *tp;
217 mtx_init(&tunmtx, "tunmtx", NULL, MTX_DEF);
218 clone_setup(&tunclones);
219 tag = EVENTHANDLER_REGISTER(dev_clone, tunclone, 0, 1000);
224 EVENTHANDLER_DEREGISTER(dev_clone, tag);
227 while ((tp = TAILQ_FIRST(&tunhead)) != NULL) {
228 TAILQ_REMOVE(&tunhead, tp, tun_list);
234 clone_cleanup(&tunclones);
235 mtx_destroy(&tunmtx);
243 static moduledata_t tun_mod = {
249 DECLARE_MODULE(if_tun, tun_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
252 tunstart(struct ifnet *ifp)
254 struct tun_softc *tp = ifp->if_softc;
257 TUNDEBUG(ifp,"%s starting\n", ifp->if_xname);
258 if (ALTQ_IS_ENABLED(&ifp->if_snd)) {
259 IFQ_LOCK(&ifp->if_snd);
260 IFQ_POLL_NOLOCK(&ifp->if_snd, m);
262 IFQ_UNLOCK(&ifp->if_snd);
265 IFQ_UNLOCK(&ifp->if_snd);
268 mtx_lock(&tp->tun_mtx);
269 if (tp->tun_flags & TUN_RWAIT) {
270 tp->tun_flags &= ~TUN_RWAIT;
273 if (tp->tun_flags & TUN_ASYNC && tp->tun_sigio) {
274 mtx_unlock(&tp->tun_mtx);
275 pgsigio(&tp->tun_sigio, SIGIO, 0);
277 mtx_unlock(&tp->tun_mtx);
278 selwakeuppri(&tp->tun_rsel, PZERO + 1);
279 KNOTE_UNLOCKED(&tp->tun_rsel.si_note, 0);
282 /* XXX: should return an error code so it can fail. */
284 tuncreate(struct cdev *dev)
286 struct tun_softc *sc;
289 dev->si_flags &= ~SI_CHEAPCLONE;
291 MALLOC(sc, struct tun_softc *, sizeof(*sc), M_TUN, M_WAITOK | M_ZERO);
292 mtx_init(&sc->tun_mtx, "tun_mtx", NULL, MTX_DEF);
293 sc->tun_flags = TUN_INITED;
296 TAILQ_INSERT_TAIL(&tunhead, sc, tun_list);
299 ifp = sc->tun_ifp = if_alloc(IFT_PPP);
301 panic("%s%d: failed to if_alloc() interface.\n",
302 TUNNAME, dev2unit(dev));
303 if_initname(ifp, TUNNAME, dev2unit(dev));
304 ifp->if_mtu = TUNMTU;
305 ifp->if_ioctl = tunifioctl;
306 ifp->if_output = tunoutput;
307 ifp->if_start = tunstart;
308 ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
310 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
311 ifp->if_snd.ifq_drv_maxlen = 0;
312 IFQ_SET_READY(&ifp->if_snd);
313 knlist_init(&sc->tun_rsel.si_note, NULL, NULL, NULL, NULL);
316 bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
318 TUNDEBUG(ifp, "interface %s is created, minor = %#x\n",
319 ifp->if_xname, minor(dev));
323 tunopen(struct cdev *dev, int flag, int mode, struct thread *td)
326 struct tun_softc *tp;
329 * XXXRW: Non-atomic test and set of dev->si_drv1 requires
339 * XXXRW: This use of tun_pid is subject to error due to the
340 * fact that a reference to the tunnel can live beyond the
341 * death of the process that created it. Can we replace this
342 * with a simple busy flag?
344 mtx_lock(&tp->tun_mtx);
345 if (tp->tun_pid != 0 && tp->tun_pid != td->td_proc->p_pid) {
346 mtx_unlock(&tp->tun_mtx);
349 tp->tun_pid = td->td_proc->p_pid;
351 tp->tun_flags |= TUN_OPEN;
352 mtx_unlock(&tp->tun_mtx);
354 TUNDEBUG(ifp, "open\n");
360 * tunclose - close the device - mark i/f down & delete
364 tunclose(struct cdev *dev, int foo, int bar, struct thread *td)
366 struct tun_softc *tp;
373 mtx_lock(&tp->tun_mtx);
374 tp->tun_flags &= ~TUN_OPEN;
378 * junk all pending output
381 IFQ_PURGE(&ifp->if_snd);
383 mtx_unlock(&tp->tun_mtx);
385 if (ifp->if_flags & IFF_UP) {
391 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
395 /* find internet addresses and delete routes */
396 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
397 if (ifa->ifa_addr->sa_family == AF_INET)
399 rtinit(ifa, (int)RTM_DELETE,
400 tp->tun_flags & TUN_DSTADDR ? RTF_HOST : 0);
401 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
405 funsetown(&tp->tun_sigio);
406 selwakeuppri(&tp->tun_rsel, PZERO + 1);
407 KNOTE_UNLOCKED(&tp->tun_rsel.si_note, 0);
408 TUNDEBUG (ifp, "closed\n");
413 tuninit(struct ifnet *ifp)
415 struct tun_softc *tp = ifp->if_softc;
419 TUNDEBUG(ifp, "tuninit\n");
421 ifp->if_flags |= IFF_UP;
422 ifp->if_drv_flags |= IFF_DRV_RUNNING;
423 getmicrotime(&ifp->if_lastchange);
426 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
427 if (ifa->ifa_addr->sa_family == AF_INET) {
428 struct sockaddr_in *si;
430 si = (struct sockaddr_in *)ifa->ifa_addr;
431 mtx_lock(&tp->tun_mtx);
432 if (si->sin_addr.s_addr)
433 tp->tun_flags |= TUN_IASET;
435 si = (struct sockaddr_in *)ifa->ifa_dstaddr;
436 if (si && si->sin_addr.s_addr)
437 tp->tun_flags |= TUN_DSTADDR;
438 mtx_unlock(&tp->tun_mtx);
446 * Process an ioctl request.
449 tunifioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
451 struct ifreq *ifr = (struct ifreq *)data;
452 struct tun_softc *tp = ifp->if_softc;
459 ifs = (struct ifstat *)data;
460 mtx_lock(&tp->tun_mtx);
462 sprintf(ifs->ascii + strlen(ifs->ascii),
463 "\tOpened by PID %d\n", tp->tun_pid);
464 mtx_unlock(&tp->tun_mtx);
467 error = tuninit(ifp);
468 TUNDEBUG(ifp, "address set, error=%d\n", error);
471 error = tuninit(ifp);
472 TUNDEBUG(ifp, "destination address set, error=%d\n", error);
475 ifp->if_mtu = ifr->ifr_mtu;
476 TUNDEBUG(ifp, "mtu set\n");
490 * tunoutput - queue packets from higher level ready to put out.
496 struct sockaddr *dst,
499 struct tun_softc *tp = ifp->if_softc;
500 u_short cached_tun_flags;
504 TUNDEBUG (ifp, "tunoutput\n");
507 error = mac_check_ifnet_transmit(ifp, m0);
514 /* Could be unlocked read? */
515 mtx_lock(&tp->tun_mtx);
516 cached_tun_flags = tp->tun_flags;
517 mtx_unlock(&tp->tun_mtx);
518 if ((cached_tun_flags & TUN_READY) != TUN_READY) {
519 TUNDEBUG (ifp, "not ready 0%o\n", tp->tun_flags);
524 if ((ifp->if_flags & IFF_UP) != IFF_UP) {
529 /* BPF writes need to be handled specially. */
530 if (dst->sa_family == AF_UNSPEC) {
531 bcopy(dst->sa_data, &af, sizeof(af));
535 if (bpf_peers_present(ifp->if_bpf)) {
537 bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m0);
540 /* prepend sockaddr? this may abort if the mbuf allocation fails */
541 if (cached_tun_flags & TUN_LMODE) {
542 /* allocate space for sockaddr */
543 M_PREPEND(m0, dst->sa_len, M_DONTWAIT);
545 /* if allocation failed drop packet */
551 bcopy(dst, m0->m_data, dst->sa_len);
555 if (cached_tun_flags & TUN_IFHEAD) {
556 /* Prepend the address family */
557 M_PREPEND(m0, 4, M_DONTWAIT);
559 /* if allocation failed drop packet */
565 *(u_int32_t *)m0->m_data = htonl(dst->sa_family);
568 if (dst->sa_family != AF_INET)
572 return (EAFNOSUPPORT);
576 IFQ_HANDOFF(ifp, m0, error);
578 ifp->if_collisions++;
586 * the cdevsw interface is now pretty minimal.
589 tunioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
593 struct tun_softc *tp = dev->si_drv1;
594 struct tuninfo *tunp;
598 tunp = (struct tuninfo *)data;
599 if (tunp->mtu < IF_MINMTU)
601 if (TUN2IFP(tp)->if_mtu != tunp->mtu) {
602 error = priv_check(td, PRIV_NET_SETIFMTU);
606 TUN2IFP(tp)->if_mtu = tunp->mtu;
607 TUN2IFP(tp)->if_type = tunp->type;
608 TUN2IFP(tp)->if_baudrate = tunp->baudrate;
611 tunp = (struct tuninfo *)data;
612 tunp->mtu = TUN2IFP(tp)->if_mtu;
613 tunp->type = TUN2IFP(tp)->if_type;
614 tunp->baudrate = TUN2IFP(tp)->if_baudrate;
617 tundebug = *(int *)data;
620 *(int *)data = tundebug;
623 mtx_lock(&tp->tun_mtx);
625 tp->tun_flags |= TUN_LMODE;
626 tp->tun_flags &= ~TUN_IFHEAD;
628 tp->tun_flags &= ~TUN_LMODE;
629 mtx_unlock(&tp->tun_mtx);
632 mtx_lock(&tp->tun_mtx);
634 tp->tun_flags |= TUN_IFHEAD;
635 tp->tun_flags &= ~TUN_LMODE;
637 tp->tun_flags &= ~TUN_IFHEAD;
638 mtx_unlock(&tp->tun_mtx);
641 /* Could be unlocked read? */
642 mtx_lock(&tp->tun_mtx);
643 *(int *)data = (tp->tun_flags & TUN_IFHEAD) ? 1 : 0;
644 mtx_unlock(&tp->tun_mtx);
647 /* deny this if UP */
648 if (TUN2IFP(tp)->if_flags & IFF_UP)
651 switch (*(int *)data & ~IFF_MULTICAST) {
652 case IFF_POINTOPOINT:
654 TUN2IFP(tp)->if_flags &=
655 ~(IFF_BROADCAST|IFF_POINTOPOINT|IFF_MULTICAST);
656 TUN2IFP(tp)->if_flags |= *(int *)data;
663 mtx_lock(&tp->tun_mtx);
664 tp->tun_pid = curthread->td_proc->p_pid;
665 mtx_unlock(&tp->tun_mtx);
670 mtx_lock(&tp->tun_mtx);
672 tp->tun_flags |= TUN_ASYNC;
674 tp->tun_flags &= ~TUN_ASYNC;
675 mtx_unlock(&tp->tun_mtx);
679 if (!IFQ_IS_EMPTY(&TUN2IFP(tp)->if_snd)) {
681 IFQ_LOCK(&TUN2IFP(tp)->if_snd);
682 IFQ_POLL_NOLOCK(&TUN2IFP(tp)->if_snd, mb);
683 for( *(int *)data = 0; mb != 0; mb = mb->m_next)
684 *(int *)data += mb->m_len;
685 IFQ_UNLOCK(&TUN2IFP(tp)->if_snd);
691 return (fsetown(*(int *)data, &tp->tun_sigio));
694 *(int *)data = fgetown(&tp->tun_sigio);
697 /* This is deprecated, FIOSETOWN should be used instead. */
699 return (fsetown(-(*(int *)data), &tp->tun_sigio));
701 /* This is deprecated, FIOGETOWN should be used instead. */
703 *(int *)data = -fgetown(&tp->tun_sigio);
713 * The cdevsw read interface - reads a packet at a time, or at
714 * least as much of a packet as can be read.
717 tunread(struct cdev *dev, struct uio *uio, int flag)
719 struct tun_softc *tp = dev->si_drv1;
720 struct ifnet *ifp = TUN2IFP(tp);
724 TUNDEBUG (ifp, "read\n");
725 mtx_lock(&tp->tun_mtx);
726 if ((tp->tun_flags & TUN_READY) != TUN_READY) {
727 mtx_unlock(&tp->tun_mtx);
728 TUNDEBUG (ifp, "not ready 0%o\n", tp->tun_flags);
732 tp->tun_flags &= ~TUN_RWAIT;
733 mtx_unlock(&tp->tun_mtx);
737 IFQ_DEQUEUE(&ifp->if_snd, m);
739 if (flag & O_NONBLOCK) {
741 return (EWOULDBLOCK);
743 mtx_lock(&tp->tun_mtx);
744 tp->tun_flags |= TUN_RWAIT;
745 mtx_unlock(&tp->tun_mtx);
746 if ((error = tsleep(tp, PCATCH | (PZERO + 1),
747 "tunread", 0)) != 0) {
755 while (m && uio->uio_resid > 0 && error == 0) {
756 len = min(uio->uio_resid, m->m_len);
758 error = uiomove(mtod(m, void *), len, uio);
763 TUNDEBUG(ifp, "Dropping mbuf\n");
770 * the cdevsw write interface - an atomic write is a packet - or else!
773 tunwrite(struct cdev *dev, struct uio *uio, int flag)
775 struct tun_softc *tp = dev->si_drv1;
776 struct ifnet *ifp = TUN2IFP(tp);
782 TUNDEBUG(ifp, "tunwrite\n");
784 if ((ifp->if_flags & IFF_UP) != IFF_UP)
785 /* ignore silently */
788 if (uio->uio_resid == 0)
791 if (uio->uio_resid < 0 || uio->uio_resid > TUNMRU) {
792 TUNDEBUG(ifp, "len=%d!\n", uio->uio_resid);
796 if ((m = m_uiotombuf(uio, M_DONTWAIT, 0, 0, M_PKTHDR)) == NULL) {
801 m->m_pkthdr.rcvif = ifp;
803 mac_create_mbuf_from_ifnet(ifp, m);
806 /* Could be unlocked read? */
807 mtx_lock(&tp->tun_mtx);
808 if (tp->tun_flags & TUN_IFHEAD) {
809 mtx_unlock(&tp->tun_mtx);
810 if (m->m_len < sizeof(family) &&
811 (m = m_pullup(m, sizeof(family))) == NULL)
813 family = ntohl(*mtod(m, u_int32_t *));
814 m_adj(m, sizeof(family));
816 mtx_unlock(&tp->tun_mtx);
820 BPF_MTAP2(ifp, &family, sizeof(family), m);
845 return (EAFNOSUPPORT);
847 /* First chunk of an mbuf contains good junk */
848 if (harvest.point_to_point)
849 random_harvest(m, 16, 3, 0, RANDOM_NET);
850 ifp->if_ibytes += m->m_pkthdr.len;
852 netisr_dispatch(isr, m);
857 * tunpoll - the poll interface, this is only useful on reads
858 * really. The write detect always returns true, write never blocks
859 * anyway, it either accepts the packet or drops it.
862 tunpoll(struct cdev *dev, int events, struct thread *td)
865 struct tun_softc *tp = dev->si_drv1;
866 struct ifnet *ifp = TUN2IFP(tp);
871 TUNDEBUG(ifp, "tunpoll\n");
873 if (events & (POLLIN | POLLRDNORM)) {
874 IFQ_LOCK(&ifp->if_snd);
875 IFQ_POLL_NOLOCK(&ifp->if_snd, m);
877 TUNDEBUG(ifp, "tunpoll q=%d\n", ifp->if_snd.ifq_len);
878 revents |= events & (POLLIN | POLLRDNORM);
880 TUNDEBUG(ifp, "tunpoll waiting\n");
881 selrecord(td, &tp->tun_rsel);
883 IFQ_UNLOCK(&ifp->if_snd);
885 if (events & (POLLOUT | POLLWRNORM))
886 revents |= events & (POLLOUT | POLLWRNORM);
893 * tunkqfilter - support for the kevent() system call.
896 tunkqfilter(struct cdev *dev, struct knote *kn)
899 struct tun_softc *tp = dev->si_drv1;
900 struct ifnet *ifp = TUN2IFP(tp);
903 switch(kn->kn_filter) {
905 TUNDEBUG(ifp, "%s kqfilter: EVFILT_READ, minor = %#x\n",
906 ifp->if_xname, minor(dev));
907 kn->kn_fop = &tun_read_filterops;
911 TUNDEBUG(ifp, "%s kqfilter: EVFILT_WRITE, minor = %#x\n",
912 ifp->if_xname, minor(dev));
913 kn->kn_fop = &tun_write_filterops;
917 TUNDEBUG(ifp, "%s kqfilter: invalid filter, minor = %#x\n",
918 ifp->if_xname, minor(dev));
924 kn->kn_hook = (caddr_t) dev;
925 knlist_add(&tp->tun_rsel.si_note, kn, 0);
931 * Return true of there is data in the interface queue.
934 tunkqread(struct knote *kn, long hint)
937 struct cdev *dev = (struct cdev *)(kn->kn_hook);
938 struct tun_softc *tp = dev->si_drv1;
939 struct ifnet *ifp = TUN2IFP(tp);
942 if ((kn->kn_data = ifp->if_snd.ifq_len) > 0) {
944 "%s have data in the queue. Len = %d, minor = %#x\n",
945 ifp->if_xname, ifp->if_snd.ifq_len, minor(dev));
949 "%s waiting for data, minor = %#x\n", ifp->if_xname,
959 * Always can write, always return MTU in kn->data.
962 tunkqwrite(struct knote *kn, long hint)
965 struct tun_softc *tp = ((struct cdev *)kn->kn_hook)->si_drv1;
966 struct ifnet *ifp = TUN2IFP(tp);
969 kn->kn_data = ifp->if_mtu;
976 tunkqdetach(struct knote *kn)
978 struct tun_softc *tp = ((struct cdev *)kn->kn_hook)->si_drv1;
980 knlist_remove(&tp->tun_rsel.si_note, kn, 0);