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>
27 #include <sys/systm.h>
29 #include <sys/module.h>
30 #include <sys/socket.h>
31 #include <sys/fcntl.h>
32 #include <sys/filio.h>
33 #include <sys/sockio.h>
34 #include <sys/ttycom.h>
36 #include <sys/selinfo.h>
37 #include <sys/signalvar.h>
38 #include <sys/filedesc.h>
39 #include <sys/kernel.h>
40 #include <sys/sysctl.h>
43 #include <sys/malloc.h>
44 #include <sys/random.h>
47 #include <net/if_types.h>
48 #include <net/netisr.h>
49 #include <net/route.h>
51 #include <netinet/in.h>
54 #include <net/if_tun.h>
56 #include <sys/queue.h>
58 #include <security/mac/mac_framework.h>
61 * tun_list is protected by global tunmtx. Other mutable fields are
62 * protected by tun->tun_mtx, or by their owning subsystem. tun_dev is
63 * static for the duration of a tunnel interface.
66 TAILQ_ENTRY(tun_softc) tun_list;
68 u_short tun_flags; /* misc flags */
69 #define TUN_OPEN 0x0001
70 #define TUN_INITED 0x0002
71 #define TUN_RCOLL 0x0004
72 #define TUN_IASET 0x0008
73 #define TUN_DSTADDR 0x0010
74 #define TUN_LMODE 0x0020
75 #define TUN_RWAIT 0x0040
76 #define TUN_ASYNC 0x0080
77 #define TUN_IFHEAD 0x0100
79 #define TUN_READY (TUN_OPEN | TUN_INITED)
82 * XXXRW: tun_pid is used to exclusively lock /dev/tun. Is this
83 * actually needed? Can we just return EBUSY if already open?
84 * Problem is that this involved inherent races when a tun device
85 * is handed off from one process to another, as opposed to just
86 * being slightly stale informationally.
88 pid_t tun_pid; /* owning pid */
89 struct ifnet *tun_ifp; /* the interface */
90 struct sigio *tun_sigio; /* information for async I/O */
91 struct selinfo tun_rsel; /* read select */
92 struct mtx tun_mtx; /* protect mutable softc fields */
94 #define TUN2IFP(sc) ((sc)->tun_ifp)
96 #define TUNDEBUG if (tundebug) if_printf
100 * All mutable global variables in if_tun are locked using tunmtx, with
101 * the exception of tundebug, which is used unlocked, and tunclones,
102 * which is static after setup.
104 static struct mtx tunmtx;
105 static MALLOC_DEFINE(M_TUN, TUNNAME, "Tunnel Interface");
106 static int tundebug = 0;
107 static struct clonedevs *tunclones;
108 static TAILQ_HEAD(,tun_softc) tunhead = TAILQ_HEAD_INITIALIZER(tunhead);
109 SYSCTL_INT(_debug, OID_AUTO, if_tun_debug, CTLFLAG_RW, &tundebug, 0, "");
111 static void tunclone(void *arg, struct ucred *cred, char *name,
112 int namelen, struct cdev **dev);
113 static void tuncreate(struct cdev *dev);
114 static int tunifioctl(struct ifnet *, u_long, caddr_t);
115 static int tuninit(struct ifnet *);
116 static int tunmodevent(module_t, int, void *);
117 static int tunoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
119 static void tunstart(struct ifnet *);
121 static d_open_t tunopen;
122 static d_close_t tunclose;
123 static d_read_t tunread;
124 static d_write_t tunwrite;
125 static d_ioctl_t tunioctl;
126 static d_poll_t tunpoll;
127 static d_kqfilter_t tunkqfilter;
129 static int tunkqread(struct knote *, long);
130 static int tunkqwrite(struct knote *, long);
131 static void tunkqdetach(struct knote *);
133 static struct filterops tun_read_filterops = {
136 .f_detach = tunkqdetach,
137 .f_event = tunkqread,
140 static struct filterops tun_write_filterops = {
143 .f_detach = tunkqdetach,
144 .f_event = tunkqwrite,
147 static struct cdevsw tun_cdevsw = {
148 .d_version = D_VERSION,
149 .d_flags = D_PSEUDO | D_NEEDGIANT,
156 .d_kqfilter = tunkqfilter,
161 tunclone(void *arg, struct ucred *cred, char *name, int namelen,
169 if (strcmp(name, TUNNAME) == 0) {
171 } else if (dev_stdclone(name, NULL, TUNNAME, &u) != 1)
172 return; /* Don't recognise the name */
173 if (u != -1 && u > IF_MAXUNIT)
174 return; /* Unit number too high */
176 /* find any existing device, or allocate new unit number */
177 i = clone_create(&tunclones, &tun_cdevsw, &u, dev, 0);
179 /* No preexisting struct cdev *, create one */
180 *dev = make_dev(&tun_cdevsw, unit2minor(u),
181 UID_UUCP, GID_DIALER, 0600, "tun%d", u);
184 (*dev)->si_flags |= SI_CHEAPCLONE;
190 tun_destroy(struct tun_softc *tp)
195 KASSERT((tp->tun_flags & TUN_OPEN) == 0,
196 ("tununits is out of sync - unit %d", TUN2IFP(tp)->if_dunit));
199 bpfdetach(TUN2IFP(tp));
200 if_detach(TUN2IFP(tp));
201 if_free(TUN2IFP(tp));
203 knlist_destroy(&tp->tun_rsel.si_note);
204 mtx_destroy(&tp->tun_mtx);
209 tunmodevent(module_t mod, int type, void *data)
211 static eventhandler_tag tag;
212 struct tun_softc *tp;
216 mtx_init(&tunmtx, "tunmtx", NULL, MTX_DEF);
217 clone_setup(&tunclones);
218 tag = EVENTHANDLER_REGISTER(dev_clone, tunclone, 0, 1000);
223 EVENTHANDLER_DEREGISTER(dev_clone, tag);
226 while ((tp = TAILQ_FIRST(&tunhead)) != NULL) {
227 TAILQ_REMOVE(&tunhead, tp, tun_list);
233 clone_cleanup(&tunclones);
234 mtx_destroy(&tunmtx);
242 static moduledata_t tun_mod = {
248 DECLARE_MODULE(if_tun, tun_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
251 tunstart(struct ifnet *ifp)
253 struct tun_softc *tp = ifp->if_softc;
256 TUNDEBUG(ifp,"%s starting\n", ifp->if_xname);
257 if (ALTQ_IS_ENABLED(&ifp->if_snd)) {
258 IFQ_LOCK(&ifp->if_snd);
259 IFQ_POLL_NOLOCK(&ifp->if_snd, m);
261 IFQ_UNLOCK(&ifp->if_snd);
264 IFQ_UNLOCK(&ifp->if_snd);
267 mtx_lock(&tp->tun_mtx);
268 if (tp->tun_flags & TUN_RWAIT) {
269 tp->tun_flags &= ~TUN_RWAIT;
272 if (tp->tun_flags & TUN_ASYNC && tp->tun_sigio) {
273 mtx_unlock(&tp->tun_mtx);
274 pgsigio(&tp->tun_sigio, SIGIO, 0);
276 mtx_unlock(&tp->tun_mtx);
277 selwakeuppri(&tp->tun_rsel, PZERO + 1);
278 KNOTE_UNLOCKED(&tp->tun_rsel.si_note, 0);
281 /* XXX: should return an error code so it can fail. */
283 tuncreate(struct cdev *dev)
285 struct tun_softc *sc;
288 dev->si_flags &= ~SI_CHEAPCLONE;
290 MALLOC(sc, struct tun_softc *, sizeof(*sc), M_TUN, M_WAITOK | M_ZERO);
291 mtx_init(&sc->tun_mtx, "tun_mtx", NULL, MTX_DEF);
292 sc->tun_flags = TUN_INITED;
295 TAILQ_INSERT_TAIL(&tunhead, sc, tun_list);
298 ifp = sc->tun_ifp = if_alloc(IFT_PPP);
300 panic("%s%d: failed to if_alloc() interface.\n",
301 TUNNAME, dev2unit(dev));
302 if_initname(ifp, TUNNAME, dev2unit(dev));
303 ifp->if_mtu = TUNMTU;
304 ifp->if_ioctl = tunifioctl;
305 ifp->if_output = tunoutput;
306 ifp->if_start = tunstart;
307 ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
309 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
310 ifp->if_snd.ifq_drv_maxlen = 0;
311 IFQ_SET_READY(&ifp->if_snd);
312 knlist_init(&sc->tun_rsel.si_note, NULL, NULL, NULL, NULL);
315 bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
317 TUNDEBUG(ifp, "interface %s is created, minor = %#x\n",
318 ifp->if_xname, minor(dev));
322 tunopen(struct cdev *dev, int flag, int mode, struct thread *td)
325 struct tun_softc *tp;
328 * XXXRW: Non-atomic test and set of dev->si_drv1 requires
338 * XXXRW: This use of tun_pid is subject to error due to the
339 * fact that a reference to the tunnel can live beyond the
340 * death of the process that created it. Can we replace this
341 * with a simple busy flag?
343 mtx_lock(&tp->tun_mtx);
344 if (tp->tun_pid != 0 && tp->tun_pid != td->td_proc->p_pid) {
345 mtx_unlock(&tp->tun_mtx);
348 tp->tun_pid = td->td_proc->p_pid;
350 tp->tun_flags |= TUN_OPEN;
351 mtx_unlock(&tp->tun_mtx);
353 TUNDEBUG(ifp, "open\n");
359 * tunclose - close the device - mark i/f down & delete
363 tunclose(struct cdev *dev, int foo, int bar, struct thread *td)
365 struct tun_softc *tp;
372 mtx_lock(&tp->tun_mtx);
373 tp->tun_flags &= ~TUN_OPEN;
377 * junk all pending output
380 IFQ_PURGE(&ifp->if_snd);
382 mtx_unlock(&tp->tun_mtx);
384 if (ifp->if_flags & IFF_UP) {
390 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
394 /* find internet addresses and delete routes */
395 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
396 if (ifa->ifa_addr->sa_family == AF_INET)
398 rtinit(ifa, (int)RTM_DELETE,
399 tp->tun_flags & TUN_DSTADDR ? RTF_HOST : 0);
400 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
404 funsetown(&tp->tun_sigio);
405 selwakeuppri(&tp->tun_rsel, PZERO + 1);
406 KNOTE_UNLOCKED(&tp->tun_rsel.si_note, 0);
407 TUNDEBUG (ifp, "closed\n");
412 tuninit(struct ifnet *ifp)
414 struct tun_softc *tp = ifp->if_softc;
418 TUNDEBUG(ifp, "tuninit\n");
420 ifp->if_flags |= IFF_UP;
421 ifp->if_drv_flags |= IFF_DRV_RUNNING;
422 getmicrotime(&ifp->if_lastchange);
425 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
426 if (ifa->ifa_addr->sa_family == AF_INET) {
427 struct sockaddr_in *si;
429 si = (struct sockaddr_in *)ifa->ifa_addr;
430 mtx_lock(&tp->tun_mtx);
431 if (si->sin_addr.s_addr)
432 tp->tun_flags |= TUN_IASET;
434 si = (struct sockaddr_in *)ifa->ifa_dstaddr;
435 if (si && si->sin_addr.s_addr)
436 tp->tun_flags |= TUN_DSTADDR;
437 mtx_unlock(&tp->tun_mtx);
445 * Process an ioctl request.
448 tunifioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
450 struct ifreq *ifr = (struct ifreq *)data;
451 struct tun_softc *tp = ifp->if_softc;
458 ifs = (struct ifstat *)data;
459 mtx_lock(&tp->tun_mtx);
461 sprintf(ifs->ascii + strlen(ifs->ascii),
462 "\tOpened by PID %d\n", tp->tun_pid);
463 mtx_unlock(&tp->tun_mtx);
466 error = tuninit(ifp);
467 TUNDEBUG(ifp, "address set, error=%d\n", error);
470 error = tuninit(ifp);
471 TUNDEBUG(ifp, "destination address set, error=%d\n", error);
474 ifp->if_mtu = ifr->ifr_mtu;
475 TUNDEBUG(ifp, "mtu set\n");
489 * tunoutput - queue packets from higher level ready to put out.
495 struct sockaddr *dst,
498 struct tun_softc *tp = ifp->if_softc;
499 u_short cached_tun_flags;
503 TUNDEBUG (ifp, "tunoutput\n");
506 error = mac_check_ifnet_transmit(ifp, m0);
513 /* Could be unlocked read? */
514 mtx_lock(&tp->tun_mtx);
515 cached_tun_flags = tp->tun_flags;
516 mtx_unlock(&tp->tun_mtx);
517 if ((cached_tun_flags & TUN_READY) != TUN_READY) {
518 TUNDEBUG (ifp, "not ready 0%o\n", tp->tun_flags);
523 if ((ifp->if_flags & IFF_UP) != IFF_UP) {
528 /* BPF writes need to be handled specially. */
529 if (dst->sa_family == AF_UNSPEC) {
530 bcopy(dst->sa_data, &af, sizeof(af));
534 if (bpf_peers_present(ifp->if_bpf)) {
536 bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m0);
539 /* prepend sockaddr? this may abort if the mbuf allocation fails */
540 if (cached_tun_flags & TUN_LMODE) {
541 /* allocate space for sockaddr */
542 M_PREPEND(m0, dst->sa_len, M_DONTWAIT);
544 /* if allocation failed drop packet */
550 bcopy(dst, m0->m_data, dst->sa_len);
554 if (cached_tun_flags & TUN_IFHEAD) {
555 /* Prepend the address family */
556 M_PREPEND(m0, 4, M_DONTWAIT);
558 /* if allocation failed drop packet */
564 *(u_int32_t *)m0->m_data = htonl(dst->sa_family);
567 if (dst->sa_family != AF_INET)
571 return (EAFNOSUPPORT);
575 IFQ_HANDOFF(ifp, m0, error);
577 ifp->if_collisions++;
585 * the cdevsw interface is now pretty minimal.
588 tunioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
592 struct tun_softc *tp = dev->si_drv1;
593 struct tuninfo *tunp;
597 tunp = (struct tuninfo *)data;
598 if (tunp->mtu < IF_MINMTU)
600 if (TUN2IFP(tp)->if_mtu != tunp->mtu
601 && (error = suser(td)) != 0)
603 TUN2IFP(tp)->if_mtu = tunp->mtu;
604 TUN2IFP(tp)->if_type = tunp->type;
605 TUN2IFP(tp)->if_baudrate = tunp->baudrate;
608 tunp = (struct tuninfo *)data;
609 tunp->mtu = TUN2IFP(tp)->if_mtu;
610 tunp->type = TUN2IFP(tp)->if_type;
611 tunp->baudrate = TUN2IFP(tp)->if_baudrate;
614 tundebug = *(int *)data;
617 *(int *)data = tundebug;
620 mtx_lock(&tp->tun_mtx);
622 tp->tun_flags |= TUN_LMODE;
623 tp->tun_flags &= ~TUN_IFHEAD;
625 tp->tun_flags &= ~TUN_LMODE;
626 mtx_unlock(&tp->tun_mtx);
629 mtx_lock(&tp->tun_mtx);
631 tp->tun_flags |= TUN_IFHEAD;
632 tp->tun_flags &= ~TUN_LMODE;
634 tp->tun_flags &= ~TUN_IFHEAD;
635 mtx_unlock(&tp->tun_mtx);
638 /* Could be unlocked read? */
639 mtx_lock(&tp->tun_mtx);
640 *(int *)data = (tp->tun_flags & TUN_IFHEAD) ? 1 : 0;
641 mtx_unlock(&tp->tun_mtx);
644 /* deny this if UP */
645 if (TUN2IFP(tp)->if_flags & IFF_UP)
648 switch (*(int *)data & ~IFF_MULTICAST) {
649 case IFF_POINTOPOINT:
651 TUN2IFP(tp)->if_flags &=
652 ~(IFF_BROADCAST|IFF_POINTOPOINT|IFF_MULTICAST);
653 TUN2IFP(tp)->if_flags |= *(int *)data;
660 mtx_lock(&tp->tun_mtx);
661 tp->tun_pid = curthread->td_proc->p_pid;
662 mtx_unlock(&tp->tun_mtx);
667 mtx_lock(&tp->tun_mtx);
669 tp->tun_flags |= TUN_ASYNC;
671 tp->tun_flags &= ~TUN_ASYNC;
672 mtx_unlock(&tp->tun_mtx);
676 if (!IFQ_IS_EMPTY(&TUN2IFP(tp)->if_snd)) {
678 IFQ_LOCK(&TUN2IFP(tp)->if_snd);
679 IFQ_POLL_NOLOCK(&TUN2IFP(tp)->if_snd, mb);
680 for( *(int *)data = 0; mb != 0; mb = mb->m_next)
681 *(int *)data += mb->m_len;
682 IFQ_UNLOCK(&TUN2IFP(tp)->if_snd);
688 return (fsetown(*(int *)data, &tp->tun_sigio));
691 *(int *)data = fgetown(&tp->tun_sigio);
694 /* This is deprecated, FIOSETOWN should be used instead. */
696 return (fsetown(-(*(int *)data), &tp->tun_sigio));
698 /* This is deprecated, FIOGETOWN should be used instead. */
700 *(int *)data = -fgetown(&tp->tun_sigio);
710 * The cdevsw read interface - reads a packet at a time, or at
711 * least as much of a packet as can be read.
714 tunread(struct cdev *dev, struct uio *uio, int flag)
716 struct tun_softc *tp = dev->si_drv1;
717 struct ifnet *ifp = TUN2IFP(tp);
721 TUNDEBUG (ifp, "read\n");
722 mtx_lock(&tp->tun_mtx);
723 if ((tp->tun_flags & TUN_READY) != TUN_READY) {
724 mtx_unlock(&tp->tun_mtx);
725 TUNDEBUG (ifp, "not ready 0%o\n", tp->tun_flags);
729 tp->tun_flags &= ~TUN_RWAIT;
730 mtx_unlock(&tp->tun_mtx);
734 IFQ_DEQUEUE(&ifp->if_snd, m);
736 if (flag & O_NONBLOCK) {
738 return (EWOULDBLOCK);
740 mtx_lock(&tp->tun_mtx);
741 tp->tun_flags |= TUN_RWAIT;
742 mtx_unlock(&tp->tun_mtx);
743 if ((error = tsleep(tp, PCATCH | (PZERO + 1),
744 "tunread", 0)) != 0) {
752 while (m && uio->uio_resid > 0 && error == 0) {
753 len = min(uio->uio_resid, m->m_len);
755 error = uiomove(mtod(m, void *), len, uio);
760 TUNDEBUG(ifp, "Dropping mbuf\n");
767 * the cdevsw write interface - an atomic write is a packet - or else!
770 tunwrite(struct cdev *dev, struct uio *uio, int flag)
772 struct tun_softc *tp = dev->si_drv1;
773 struct ifnet *ifp = TUN2IFP(tp);
779 TUNDEBUG(ifp, "tunwrite\n");
781 if ((ifp->if_flags & IFF_UP) != IFF_UP)
782 /* ignore silently */
785 if (uio->uio_resid == 0)
788 if (uio->uio_resid < 0 || uio->uio_resid > TUNMRU) {
789 TUNDEBUG(ifp, "len=%d!\n", uio->uio_resid);
793 if ((m = m_uiotombuf(uio, M_DONTWAIT, 0, 0)) == NULL) {
798 m->m_pkthdr.rcvif = ifp;
800 mac_create_mbuf_from_ifnet(ifp, m);
803 /* Could be unlocked read? */
804 mtx_lock(&tp->tun_mtx);
805 if (tp->tun_flags & TUN_IFHEAD) {
806 mtx_unlock(&tp->tun_mtx);
807 if (m->m_len < sizeof(family) &&
808 (m = m_pullup(m, sizeof(family))) == NULL)
810 family = ntohl(*mtod(m, u_int32_t *));
811 m_adj(m, sizeof(family));
813 mtx_unlock(&tp->tun_mtx);
817 BPF_MTAP2(ifp, &family, sizeof(family), m);
842 return (EAFNOSUPPORT);
844 /* First chunk of an mbuf contains good junk */
845 if (harvest.point_to_point)
846 random_harvest(m, 16, 3, 0, RANDOM_NET);
847 ifp->if_ibytes += m->m_pkthdr.len;
849 netisr_dispatch(isr, m);
854 * tunpoll - the poll interface, this is only useful on reads
855 * really. The write detect always returns true, write never blocks
856 * anyway, it either accepts the packet or drops it.
859 tunpoll(struct cdev *dev, int events, struct thread *td)
862 struct tun_softc *tp = dev->si_drv1;
863 struct ifnet *ifp = TUN2IFP(tp);
868 TUNDEBUG(ifp, "tunpoll\n");
870 if (events & (POLLIN | POLLRDNORM)) {
871 IFQ_LOCK(&ifp->if_snd);
872 IFQ_POLL_NOLOCK(&ifp->if_snd, m);
874 TUNDEBUG(ifp, "tunpoll q=%d\n", ifp->if_snd.ifq_len);
875 revents |= events & (POLLIN | POLLRDNORM);
877 TUNDEBUG(ifp, "tunpoll waiting\n");
878 selrecord(td, &tp->tun_rsel);
880 IFQ_UNLOCK(&ifp->if_snd);
882 if (events & (POLLOUT | POLLWRNORM))
883 revents |= events & (POLLOUT | POLLWRNORM);
890 * tunkqfilter - support for the kevent() system call.
893 tunkqfilter(struct cdev *dev, struct knote *kn)
896 struct tun_softc *tp = dev->si_drv1;
897 struct ifnet *ifp = TUN2IFP(tp);
900 switch(kn->kn_filter) {
902 TUNDEBUG(ifp, "%s kqfilter: EVFILT_READ, minor = %#x\n",
903 ifp->if_xname, minor(dev));
904 kn->kn_fop = &tun_read_filterops;
908 TUNDEBUG(ifp, "%s kqfilter: EVFILT_WRITE, minor = %#x\n",
909 ifp->if_xname, minor(dev));
910 kn->kn_fop = &tun_write_filterops;
914 TUNDEBUG(ifp, "%s kqfilter: invalid filter, minor = %#x\n",
915 ifp->if_xname, minor(dev));
921 kn->kn_hook = (caddr_t) dev;
922 knlist_add(&tp->tun_rsel.si_note, kn, 0);
928 * Return true of there is data in the interface queue.
931 tunkqread(struct knote *kn, long hint)
934 struct cdev *dev = (struct cdev *)(kn->kn_hook);
935 struct tun_softc *tp = dev->si_drv1;
936 struct ifnet *ifp = TUN2IFP(tp);
939 if ((kn->kn_data = ifp->if_snd.ifq_len) > 0) {
941 "%s have data in the queue. Len = %d, minor = %#x\n",
942 ifp->if_xname, ifp->if_snd.ifq_len, minor(dev));
946 "%s waiting for data, minor = %#x\n", ifp->if_xname,
956 * Always can write, always return MTU in kn->data.
959 tunkqwrite(struct knote *kn, long hint)
962 struct tun_softc *tp = ((struct cdev *)kn->kn_hook)->si_drv1;
963 struct ifnet *ifp = TUN2IFP(tp);
966 kn->kn_data = ifp->if_mtu;
973 tunkqdetach(struct knote *kn)
975 struct tun_softc *tp = ((struct cdev *)kn->kn_hook)->si_drv1;
977 knlist_remove(&tp->tun_rsel.si_note, kn, 0);