506280541af56802eb6eeccc01bf17e91a4f3d51
[dragonfly.git] / sys / net / tun / if_tun.c
1 /*      $NetBSD: if_tun.c,v 1.14 1994/06/29 06:36:25 cgd Exp $  */
2
3 /*
4  * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
5  * Nottingham University 1987.
6  *
7  * This source may be freely distributed, however I would be interested
8  * in any changes that are made.
9  *
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
14  * operation though.
15  *
16  * $FreeBSD: src/sys/net/if_tun.c,v 1.74.2.8 2002/02/13 00:43:11 dillon Exp $
17  * $DragonFly: src/sys/net/tun/if_tun.c,v 1.20 2005/06/14 17:43:01 joerg Exp $
18  */
19
20 #include "opt_atalk.h"
21 #include "opt_inet.h"
22 #include "opt_inet6.h"
23 #include "opt_ipx.h"
24
25 #include <sys/param.h>
26 #include <sys/proc.h>
27 #include <sys/systm.h>
28 #include <sys/mbuf.h>
29 #include <sys/socket.h>
30 #include <sys/filio.h>
31 #include <sys/sockio.h>
32 #include <sys/ttycom.h>
33 #include <sys/poll.h>
34 #include <sys/signalvar.h>
35 #include <sys/filedesc.h>
36 #include <sys/kernel.h>
37 #include <sys/sysctl.h>
38 #include <sys/conf.h>
39 #include <sys/uio.h>
40 #include <sys/vnode.h>
41 #include <sys/malloc.h>
42
43 #include <net/if.h>
44 #include <net/if_types.h>
45 #include <net/ifq_var.h>
46 #include <net/netisr.h>
47 #include <net/route.h>
48
49 #ifdef INET
50 #include <netinet/in.h>
51 #endif
52
53 #include <net/bpf.h>
54
55 #include "if_tunvar.h"
56 #include "if_tun.h"
57
58 static MALLOC_DEFINE(M_TUN, "tun", "Tunnel Interface");
59
60 static void tunattach (void *);
61 PSEUDO_SET(tunattach, if_tun);
62
63 static void tuncreate (dev_t dev);
64
65 #define TUNDEBUG        if (tundebug) if_printf
66 static int tundebug = 0;
67 SYSCTL_INT(_debug, OID_AUTO, if_tun_debug, CTLFLAG_RW, &tundebug, 0, "");
68
69 static int tunoutput (struct ifnet *, struct mbuf *, struct sockaddr *,
70             struct rtentry *rt);
71 static int tunifioctl (struct ifnet *, u_long, caddr_t, struct ucred *);
72 static int tuninit (struct ifnet *);
73 static void tunstart(struct ifnet *);
74
75 static  d_open_t        tunopen;
76 static  d_close_t       tunclose;
77 static  d_read_t        tunread;
78 static  d_write_t       tunwrite;
79 static  d_ioctl_t       tunioctl;
80 static  d_poll_t        tunpoll;
81
82 #define CDEV_MAJOR 52
83 static struct cdevsw tun_cdevsw = {
84         /* name */      "tun",
85         /* maj */       CDEV_MAJOR,
86         /* flags */     0,
87         /* port */      NULL,
88         /* clone */     NULL,
89
90         /* open */      tunopen,
91         /* close */     tunclose,
92         /* read */      tunread,
93         /* write */     tunwrite,
94         /* ioctl */     tunioctl,
95         /* poll */      tunpoll,
96         /* mmap */      nommap,
97         /* strategy */  nostrategy,
98         /* dump */      nodump,
99         /* psize */     nopsize
100 };
101
102 static void
103 tunattach(void *dummy)
104 {
105         cdevsw_add(&tun_cdevsw, 0, 0);
106 }
107
108 static void
109 tuncreate(dev)
110         dev_t dev;
111 {
112         struct tun_softc *sc;
113         struct ifnet *ifp;
114
115         dev = make_dev(&tun_cdevsw, minor(dev),
116             UID_UUCP, GID_DIALER, 0600, "tun%d", lminor(dev));
117
118         MALLOC(sc, struct tun_softc *, sizeof(*sc), M_TUN, M_WAITOK);
119         bzero(sc, sizeof *sc);
120         sc->tun_flags = TUN_INITED;
121
122         ifp = &sc->tun_if;
123         if_initname(ifp, "tun", lminor(dev));
124         ifp->if_mtu = TUNMTU;
125         ifp->if_ioctl = tunifioctl;
126         ifp->if_output = tunoutput;
127         ifp->if_start = tunstart;
128         ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
129         ifp->if_type = IFT_PPP;
130         ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
131         ifq_set_ready(&ifp->if_snd);
132         ifp->if_softc = sc;
133         if_attach(ifp);
134         bpfattach(ifp, DLT_NULL, sizeof(u_int));
135         dev->si_drv1 = sc;
136 }
137
138 /*
139  * tunnel open - must be superuser & the device must be
140  * configured in
141  */
142 static  int
143 tunopen(dev_t dev, int flag, int mode, struct thread *td)
144 {
145         struct ifnet    *ifp;
146         struct tun_softc *tp;
147         int     error;
148
149         KKASSERT(td->td_proc);
150         if ((error = suser(td)) != NULL)
151                 return (error);
152
153         tp = dev->si_drv1;
154         if (!tp) {
155                 tuncreate(dev);
156                 tp = dev->si_drv1;
157         }
158         if (tp->tun_flags & TUN_OPEN)
159                 return EBUSY;
160         tp->tun_pid = td->td_proc->p_pid;
161         ifp = &tp->tun_if;
162         tp->tun_flags |= TUN_OPEN;
163         TUNDEBUG(ifp, "open\n");
164         return (0);
165 }
166
167 /*
168  * tunclose - close the device - mark i/f down & delete
169  * routing info
170  */
171 static  int
172 tunclose(dev_t dev, int foo, int bar, struct thread *td)
173 {
174         int     s;
175         struct tun_softc *tp;
176         struct ifnet    *ifp;
177
178         tp = dev->si_drv1;
179         ifp = &tp->tun_if;
180
181         tp->tun_flags &= ~TUN_OPEN;
182         tp->tun_pid = 0;
183
184         /* Junk all pending output. */
185         s = splimp();
186         ifq_purge(&ifp->if_snd);
187         splx(s);
188
189         if (ifp->if_flags & IFF_UP) {
190                 s = splimp();
191                 if_down(ifp);
192                 splx(s);
193         }
194
195         if (ifp->if_flags & IFF_RUNNING) {
196                 struct ifaddr *ifa;
197
198                 s = splimp();
199                 /* find internet addresses and delete routes */
200                 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
201                         if (ifa->ifa_addr->sa_family == AF_INET)
202                                 rtinit(ifa, (int)RTM_DELETE,
203                                     tp->tun_flags & TUN_DSTADDR ? RTF_HOST : 0);
204                 ifp->if_flags &= ~IFF_RUNNING;
205                 splx(s);
206         }
207
208         funsetown(tp->tun_sigio);
209         selwakeup(&tp->tun_rsel);
210
211         TUNDEBUG(ifp, "closed\n");
212         return (0);
213 }
214
215 static int
216 tuninit(ifp)
217         struct ifnet *ifp;
218 {
219         struct tun_softc *tp = ifp->if_softc;
220         struct ifaddr *ifa;
221         int error = 0;
222
223         TUNDEBUG(ifp, "tuninit\n");
224
225         ifp->if_flags |= IFF_UP | IFF_RUNNING;
226         getmicrotime(&ifp->if_lastchange);
227
228         for (ifa = TAILQ_FIRST(&ifp->if_addrhead); ifa; 
229              ifa = TAILQ_NEXT(ifa, ifa_link)) {
230                 if (ifa->ifa_addr == NULL)
231                         error = EFAULT;
232                         /* XXX: Should maybe return straight off? */
233                 else {
234 #ifdef INET
235                         if (ifa->ifa_addr->sa_family == AF_INET) {
236                             struct sockaddr_in *si;
237
238                             si = (struct sockaddr_in *)ifa->ifa_addr;
239                             if (si->sin_addr.s_addr)
240                                     tp->tun_flags |= TUN_IASET;
241
242                             si = (struct sockaddr_in *)ifa->ifa_dstaddr;
243                             if (si && si->sin_addr.s_addr)
244                                     tp->tun_flags |= TUN_DSTADDR;
245                         }
246 #endif
247                 }
248         }
249         return (error);
250 }
251
252 /*
253  * Process an ioctl request.
254  */
255 int
256 tunifioctl(ifp, cmd, data, cr)
257         struct ifnet *ifp;
258         u_long  cmd;
259         caddr_t data;
260         struct ucred *cr;
261 {
262         struct ifreq *ifr = (struct ifreq *)data;
263         struct tun_softc *tp = ifp->if_softc;
264         struct ifstat *ifs;
265         int             error = 0, s;
266
267         s = splimp();
268         switch(cmd) {
269         case SIOCGIFSTATUS:
270                 ifs = (struct ifstat *)data;
271                 if (tp->tun_pid)
272                         sprintf(ifs->ascii + strlen(ifs->ascii),
273                             "\tOpened by PID %d\n", tp->tun_pid);
274                 break;
275         case SIOCSIFADDR:
276                 error = tuninit(ifp);
277                 TUNDEBUG(ifp, "address set, error=%d\n", error);
278                 break;
279         case SIOCSIFDSTADDR:
280                 error = tuninit(ifp);
281                 TUNDEBUG(ifp, "destination address set, error=%d\n", error);
282                 break;
283         case SIOCSIFMTU:
284                 ifp->if_mtu = ifr->ifr_mtu;
285                 TUNDEBUG(ifp, "mtu set\n");
286                 break;
287         case SIOCSIFFLAGS:
288         case SIOCADDMULTI:
289         case SIOCDELMULTI:
290                 break;
291         default:
292                 error = EINVAL;
293         }
294         splx(s);
295         return (error);
296 }
297
298 /*
299  * tunoutput - queue packets from higher level ready to put out.
300  */
301 int
302 tunoutput(ifp, m0, dst, rt)
303         struct ifnet   *ifp;
304         struct mbuf    *m0;
305         struct sockaddr *dst;
306         struct rtentry *rt;
307 {
308         struct tun_softc *tp = ifp->if_softc;
309         int error, s;
310         struct altq_pktattr pktattr;
311
312         TUNDEBUG(ifp, "tunoutput\n");
313
314         if ((tp->tun_flags & TUN_READY) != TUN_READY) {
315                 TUNDEBUG(ifp, "not ready 0%o\n", tp->tun_flags);
316                 m_freem (m0);
317                 return EHOSTDOWN;
318         }
319
320         /*
321          * if the queueing discipline needs packet classification,
322          * do it before prepending link headers.
323          */
324         ifq_classify(&ifp->if_snd, m0, dst->sa_family, &pktattr);
325
326         /* BPF write needs to be handled specially */
327         if (dst->sa_family == AF_UNSPEC) {
328                 dst->sa_family = *(mtod(m0, int *));
329                 m0->m_len -= sizeof(int);
330                 m0->m_pkthdr.len -= sizeof(int);
331                 m0->m_data += sizeof(int);
332         }
333
334         if (ifp->if_bpf) {
335                 /*
336                  * We need to prepend the address family as
337                  * a four byte field.
338                  */
339                 uint32_t af = dst->sa_family;
340
341                 bpf_ptap(ifp->if_bpf, m0, &af, sizeof(af));
342         }
343
344         /* prepend sockaddr? this may abort if the mbuf allocation fails */
345         if (tp->tun_flags & TUN_LMODE) {
346                 /* allocate space for sockaddr */
347                 M_PREPEND(m0, dst->sa_len, MB_DONTWAIT);
348
349                 /* if allocation failed drop packet */
350                 if (m0 == NULL){
351                         s = splimp();   /* spl on queue manipulation */
352                         IF_DROP(&ifp->if_snd);
353                         splx(s);
354                         ifp->if_oerrors++;
355                         return (ENOBUFS);
356                 } else {
357                         bcopy(dst, m0->m_data, dst->sa_len);
358                 }
359         }
360
361         if (tp->tun_flags & TUN_IFHEAD) {
362                 /* Prepend the address family */
363                 M_PREPEND(m0, 4, MB_DONTWAIT);
364
365                 /* if allocation failed drop packet */
366                 if (m0 == NULL){
367                         s = splimp();   /* spl on queue manipulation */
368                         IF_DROP(&ifp->if_snd);
369                         splx(s);
370                         ifp->if_oerrors++;
371                         return ENOBUFS;
372                 } else
373                         *(u_int32_t *)m0->m_data = htonl(dst->sa_family);
374         } else {
375 #ifdef INET
376                 if (dst->sa_family != AF_INET)
377 #endif
378                 {
379                         m_freem(m0);
380                         return EAFNOSUPPORT;
381                 }
382         }
383
384         error = ifq_handoff(ifp, m0, &pktattr);
385         if (error)
386                 ifp->if_collisions++;
387         else
388                 ifp->if_opackets++;
389         return (error);
390 }
391
392 /*
393  * the cdevsw interface is now pretty minimal.
394  */
395 static  int
396 tunioctl(dev_t  dev, u_long cmd, caddr_t data, int flag, struct thread *td)
397 {
398         int             s;
399         struct tun_softc *tp = dev->si_drv1;
400         struct tuninfo *tunp;
401
402         switch (cmd) {
403         case TUNSIFINFO:
404                 tunp = (struct tuninfo *)data;
405                 if (tunp->mtu < IF_MINMTU)
406                         return (EINVAL);
407                 tp->tun_if.if_mtu = tunp->mtu;
408                 tp->tun_if.if_type = tunp->type;
409                 tp->tun_if.if_baudrate = tunp->baudrate;
410                 break;
411         case TUNGIFINFO:
412                 tunp = (struct tuninfo *)data;
413                 tunp->mtu = tp->tun_if.if_mtu;
414                 tunp->type = tp->tun_if.if_type;
415                 tunp->baudrate = tp->tun_if.if_baudrate;
416                 break;
417         case TUNSDEBUG:
418                 tundebug = *(int *)data;
419                 break;
420         case TUNGDEBUG:
421                 *(int *)data = tundebug;
422                 break;
423         case TUNSLMODE:
424                 if (*(int *)data) {
425                         tp->tun_flags |= TUN_LMODE;
426                         tp->tun_flags &= ~TUN_IFHEAD;
427                 } else
428                         tp->tun_flags &= ~TUN_LMODE;
429                 break;
430         case TUNSIFHEAD:
431                 if (*(int *)data) {
432                         tp->tun_flags |= TUN_IFHEAD;
433                         tp->tun_flags &= ~TUN_LMODE;
434                 } else 
435                         tp->tun_flags &= ~TUN_IFHEAD;
436                 break;
437         case TUNGIFHEAD:
438                 *(int *)data = (tp->tun_flags & TUN_IFHEAD) ? 1 : 0;
439                 break;
440         case TUNSIFMODE:
441                 /* deny this if UP */
442                 if (tp->tun_if.if_flags & IFF_UP)
443                         return(EBUSY);
444
445                 switch (*(int *)data & ~IFF_MULTICAST) {
446                 case IFF_POINTOPOINT:
447                 case IFF_BROADCAST:
448                         tp->tun_if.if_flags &= ~(IFF_BROADCAST|IFF_POINTOPOINT);
449                         tp->tun_if.if_flags |= *(int *)data;
450                         break;
451                 default:
452                         return(EINVAL);
453                 }
454                 break;
455         case TUNSIFPID:
456                 tp->tun_pid = curproc->p_pid;
457                 break;
458         case FIONBIO:
459                 break;
460         case FIOASYNC:
461                 if (*(int *)data)
462                         tp->tun_flags |= TUN_ASYNC;
463                 else
464                         tp->tun_flags &= ~TUN_ASYNC;
465                 break;
466         case FIONREAD:
467                 s = splimp();
468                 if (!ifq_is_empty(&tp->tun_if.if_snd)) {
469                         struct mbuf *mb;
470
471                         mb = ifq_poll(&tp->tun_if.if_snd);
472                         for( *(int *)data = 0; mb != 0; mb = mb->m_next) 
473                                 *(int *)data += mb->m_len;
474                 } else
475                         *(int *)data = 0;
476                 splx(s);
477                 break;
478         case FIOSETOWN:
479                 return (fsetown(*(int *)data, &tp->tun_sigio));
480
481         case FIOGETOWN:
482                 *(int *)data = fgetown(tp->tun_sigio);
483                 return (0);
484
485         /* This is deprecated, FIOSETOWN should be used instead. */
486         case TIOCSPGRP:
487                 return (fsetown(-(*(int *)data), &tp->tun_sigio));
488
489         /* This is deprecated, FIOGETOWN should be used instead. */
490         case TIOCGPGRP:
491                 *(int *)data = -fgetown(tp->tun_sigio);
492                 return (0);
493
494         default:
495                 return (ENOTTY);
496         }
497         return (0);
498 }
499
500 /*
501  * The cdevsw read interface - reads a packet at a time, or at
502  * least as much of a packet as can be read.
503  */
504 static  int
505 tunread(dev, uio, flag)
506         dev_t dev;
507         struct uio *uio;
508         int flag;
509 {
510         struct tun_softc *tp = dev->si_drv1;
511         struct ifnet    *ifp = &tp->tun_if;
512         struct mbuf     *m0;
513         int             error=0, len, s;
514
515         TUNDEBUG(ifp, "read\n");
516         if ((tp->tun_flags & TUN_READY) != TUN_READY) {
517                 TUNDEBUG(ifp, "not ready 0%o\n", tp->tun_flags);
518                 return EHOSTDOWN;
519         }
520
521         tp->tun_flags &= ~TUN_RWAIT;
522
523         s = splimp();
524         while ((m0 = ifq_dequeue(&ifp->if_snd)) == NULL) {
525                 if (flag & IO_NDELAY) {
526                         splx(s);
527                         return EWOULDBLOCK;
528                 }
529                 tp->tun_flags |= TUN_RWAIT;
530                 if ((error = tsleep(tp, PCATCH, "tunread", 0)) != 0) {
531                         splx(s);
532                         return error;
533                 }
534         }
535         splx(s);
536
537         while (m0 && uio->uio_resid > 0 && error == 0) {
538                 len = min(uio->uio_resid, m0->m_len);
539                 if (len != 0)
540                         error = uiomove(mtod(m0, caddr_t), len, uio);
541                 m0 = m_free(m0);
542         }
543
544         if (m0) {
545                 TUNDEBUG(ifp, "Dropping mbuf\n");
546                 m_freem(m0);
547         }
548         return error;
549 }
550
551 /*
552  * the cdevsw write interface - an atomic write is a packet - or else!
553  */
554 static  int
555 tunwrite(dev, uio, flag)
556         dev_t dev;
557         struct uio *uio;
558         int flag;
559 {
560         struct tun_softc *tp = dev->si_drv1;
561         struct ifnet    *ifp = &tp->tun_if;
562         struct mbuf     *top, **mp, *m;
563         int             error=0, tlen, mlen;
564         uint32_t        family;
565         int             isr;
566
567         TUNDEBUG(ifp, "tunwrite\n");
568
569         if (uio->uio_resid == 0)
570                 return 0;
571
572         if (uio->uio_resid < 0 || uio->uio_resid > TUNMRU) {
573                 TUNDEBUG(ifp, "len=%d!\n", uio->uio_resid);
574                 return EIO;
575         }
576         tlen = uio->uio_resid;
577
578         /* get a header mbuf */
579         MGETHDR(m, MB_DONTWAIT, MT_DATA);
580         if (m == NULL)
581                 return ENOBUFS;
582         mlen = MHLEN;
583
584         top = 0;
585         mp = &top;
586         while (error == 0 && uio->uio_resid > 0) {
587                 m->m_len = min(mlen, uio->uio_resid);
588                 error = uiomove(mtod (m, caddr_t), m->m_len, uio);
589                 *mp = m;
590                 mp = &m->m_next;
591                 if (uio->uio_resid > 0) {
592                         MGET (m, MB_DONTWAIT, MT_DATA);
593                         if (m == 0) {
594                                 error = ENOBUFS;
595                                 break;
596                         }
597                         mlen = MLEN;
598                 }
599         }
600         if (error) {
601                 if (top)
602                         m_freem (top);
603                 ifp->if_ierrors++;
604                 return error;
605         }
606
607         top->m_pkthdr.len = tlen;
608         top->m_pkthdr.rcvif = ifp;
609
610         if (ifp->if_bpf) {
611                 if (tp->tun_flags & TUN_IFHEAD) {
612                         /*
613                          * Conveniently, we already have a 4-byte address
614                          * family prepended to our packet !
615                          * Inconveniently, it's in the wrong byte order !
616                          */
617                         if ((top = m_pullup(top, sizeof(family))) == NULL)
618                                 return ENOBUFS;
619                         *mtod(top, u_int32_t *) =
620                             ntohl(*mtod(top, u_int32_t *));
621                         bpf_mtap(ifp->if_bpf, top);
622                         *mtod(top, u_int32_t *) =
623                             htonl(*mtod(top, u_int32_t *));
624                 } else {
625                         /*
626                          * We need to prepend the address family as
627                          * a four byte field.
628                          */
629                         static const uint32_t af = AF_INET;
630
631                         bpf_ptap(ifp->if_bpf, top, &af, sizeof(af));
632                 }
633         }
634
635         if (tp->tun_flags & TUN_IFHEAD) {
636                 if (top->m_len < sizeof(family) &&
637                     (top = m_pullup(top, sizeof(family))) == NULL)
638                                 return ENOBUFS;
639                 family = ntohl(*mtod(top, u_int32_t *));
640                 m_adj(top, sizeof(family));
641         } else
642                 family = AF_INET;
643
644         ifp->if_ibytes += top->m_pkthdr.len;
645         ifp->if_ipackets++;
646
647         switch (family) {
648 #ifdef INET
649         case AF_INET:
650                 isr = NETISR_IP;
651                 break;
652 #endif
653 #ifdef INET6
654         case AF_INET6:
655                 isr = NETISR_IPV6;
656                 break;
657 #endif
658 #ifdef IPX
659         case AF_IPX:
660                 isr = NETISR_IPX;
661                 break;
662 #endif
663 #ifdef NETATALK
664         case AF_APPLETALK:
665                 isr = NETISR_ATALK2;
666                 break;
667 #endif
668         default:
669                 m_freem(m);
670                 return (EAFNOSUPPORT);
671         }
672
673         netisr_dispatch(isr, top);
674         return (0);
675 }
676
677 /*
678  * tunpoll - the poll interface, this is only useful on reads
679  * really. The write detect always returns true, write never blocks
680  * anyway, it either accepts the packet or drops it.
681  */
682 static  int
683 tunpoll(dev_t dev, int events, struct thread *td)
684 {
685         int             s;
686         struct tun_softc *tp = dev->si_drv1;
687         struct ifnet    *ifp = &tp->tun_if;
688         int             revents = 0;
689
690         s = splimp();
691         TUNDEBUG(ifp, "tunpoll\n");
692
693         if (events & (POLLIN | POLLRDNORM)) {
694                 if (!ifq_is_empty(&ifp->if_snd)) {
695                         TUNDEBUG(ifp, "tunpoll q=%d\n", ifp->if_snd.ifq_len);
696                         revents |= events & (POLLIN | POLLRDNORM);
697                 } else {
698                         TUNDEBUG(ifp, "tunpoll waiting\n");
699                         selrecord(td, &tp->tun_rsel);
700                 }
701         }
702         if (events & (POLLOUT | POLLWRNORM))
703                 revents |= events & (POLLOUT | POLLWRNORM);
704
705         splx(s);
706         return (revents);
707 }
708
709 /*
710  * Start packet transmission on the interface.
711  * when the interface queue is rate-limited by ALTQ,
712  * if_start is needed to drain packets from the queue in order
713  * to notify readers when outgoing packets become ready.
714  */
715 static void
716 tunstart(struct ifnet *ifp)
717 {
718         struct tun_softc *tp = ifp->if_softc;
719         struct mbuf *m;
720
721         if (!ifq_is_enabled(&ifp->if_snd))
722                 return;
723
724         m = ifq_poll(&ifp->if_snd);
725         if (m != NULL) {
726                 if (tp->tun_flags & TUN_RWAIT) {
727                         tp->tun_flags &= ~TUN_RWAIT;
728                         wakeup((caddr_t)tp);
729                 }
730                 if (tp->tun_flags & TUN_ASYNC && tp->tun_sigio)
731                         pgsigio(tp->tun_sigio, SIGIO, 0);
732                 selwakeup(&tp->tun_rsel);
733         }
734 }