Deleted Added
full compact
if_tap.c (63670) if_tap.c (63803)
1/*
2 * Copyright (C) 1999-2000 by Maksim Yevmenkin <m_evmenkin@yahoo.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * BASED ON:
27 * -------------------------------------------------------------------------
28 *
29 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
30 * Nottingham University 1987.
31 */
32
33/*
1/*
2 * Copyright (C) 1999-2000 by Maksim Yevmenkin <m_evmenkin@yahoo.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * BASED ON:
27 * -------------------------------------------------------------------------
28 *
29 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
30 * Nottingham University 1987.
31 */
32
33/*
34 * $FreeBSD: head/sys/net/if_tap.c 63670 2000-07-20 17:01:10Z nsayer $
35 * $Id: if_tap.c,v 0.19 2000/07/20 02:32:27 max Exp $
34 * $FreeBSD: head/sys/net/if_tap.c 63803 2000-07-24 15:32:26Z nsayer $
35 * $Id: if_tap.c,v 0.21 2000/07/23 21:46:02 max Exp $
36 */
37
38#include "opt_inet.h"
39
40#include <sys/param.h>
41#include <sys/conf.h>
42#include <sys/filedesc.h>
43#include <sys/filio.h>

--- 114 unchanged lines hidden (view full) ---

158 (strcmp(ifp->if_name, VMNET) == 0))
159 if (ifp->if_unit == unit)
160 break;
161 splx(s);
162
163 if (ifp != NULL) {
164 struct tap_softc *tp = ifp->if_softc;
165
36 */
37
38#include "opt_inet.h"
39
40#include <sys/param.h>
41#include <sys/conf.h>
42#include <sys/filedesc.h>
43#include <sys/filio.h>

--- 114 unchanged lines hidden (view full) ---

158 (strcmp(ifp->if_name, VMNET) == 0))
159 if (ifp->if_unit == unit)
160 break;
161 splx(s);
162
163 if (ifp != NULL) {
164 struct tap_softc *tp = ifp->if_softc;
165
166 TAPDEBUG("detaching %s%d. taplastunit = %d\n",
167 ifp->if_name, unit, taplastunit);
166 TAPDEBUG("detaching %s%d. minor = %#x, " \
167 "taplastunit = %d\n",
168 ifp->if_name, unit, minor(tp->tap_dev),
169 taplastunit);
168
170
171 s = splimp();
169 ether_ifdetach(ifp, 1);
172 ether_ifdetach(ifp, 1);
173 splx(s);
170 destroy_dev(tp->tap_dev);
171 FREE(tp, M_TAP);
172 }
173 else
174 unit ++;
175 }
176
177 attached = 0;

--- 14 unchanged lines hidden (view full) ---

192 */
193static void
194tapcreate(dev)
195 dev_t dev;
196{
197 struct ifnet *ifp = NULL;
198 struct tap_softc *tp = NULL;
199 unsigned short macaddr_hi;
174 destroy_dev(tp->tap_dev);
175 FREE(tp, M_TAP);
176 }
177 else
178 unit ++;
179 }
180
181 attached = 0;

--- 14 unchanged lines hidden (view full) ---

196 */
197static void
198tapcreate(dev)
199 dev_t dev;
200{
201 struct ifnet *ifp = NULL;
202 struct tap_softc *tp = NULL;
203 unsigned short macaddr_hi;
200 int unit;
204 int unit, s;
201 char *name = NULL;
202
203 /* allocate driver storage and create device */
204 MALLOC(tp, struct tap_softc *, sizeof(*tp), M_TAP, M_WAITOK);
205 bzero(tp, sizeof(*tp));
206
207 /* select device: tap or vmnet */
208 if (minor(dev) & VMNET_DEV_MASK) {
209 name = VMNET;
210 unit = lminor(dev) & 0xff;
205 char *name = NULL;
206
207 /* allocate driver storage and create device */
208 MALLOC(tp, struct tap_softc *, sizeof(*tp), M_TAP, M_WAITOK);
209 bzero(tp, sizeof(*tp));
210
211 /* select device: tap or vmnet */
212 if (minor(dev) & VMNET_DEV_MASK) {
213 name = VMNET;
214 unit = lminor(dev) & 0xff;
215 tp->tap_flags |= TAP_VMNET;
211 }
212 else {
213 name = TAP;
214 unit = lminor(dev);
215 }
216
216 }
217 else {
218 name = TAP;
219 unit = lminor(dev);
220 }
221
217 tp->tap_dev = make_dev(&tap_cdevsw, minor(dev), UID_UUCP, GID_DIALER,
222 tp->tap_dev = make_dev(&tap_cdevsw, minor(dev), UID_ROOT, GID_WHEEL,
218 0600, "%s%d", name, unit);
219 tp->tap_dev->si_drv1 = dev->si_drv1 = tp;
220
221 /* generate fake MAC address: 00 bd xx xx xx unit_no */
222 macaddr_hi = htons(0x00bd);
223 bcopy(&macaddr_hi, &tp->arpcom.ac_enaddr[0], sizeof(short));
224 bcopy(&ticks, &tp->arpcom.ac_enaddr[2], sizeof(long));
225 tp->arpcom.ac_enaddr[5] = (u_char)unit;

--- 10 unchanged lines hidden (view full) ---

236 ifp->if_init = tapifinit;
237 ifp->if_output = ether_output;
238 ifp->if_start = tapifstart;
239 ifp->if_ioctl = tapifioctl;
240 ifp->if_mtu = ETHERMTU;
241 ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
242 ifp->if_snd.ifq_maxlen = ifqmaxlen;
243
223 0600, "%s%d", name, unit);
224 tp->tap_dev->si_drv1 = dev->si_drv1 = tp;
225
226 /* generate fake MAC address: 00 bd xx xx xx unit_no */
227 macaddr_hi = htons(0x00bd);
228 bcopy(&macaddr_hi, &tp->arpcom.ac_enaddr[0], sizeof(short));
229 bcopy(&ticks, &tp->arpcom.ac_enaddr[2], sizeof(long));
230 tp->arpcom.ac_enaddr[5] = (u_char)unit;

--- 10 unchanged lines hidden (view full) ---

241 ifp->if_init = tapifinit;
242 ifp->if_output = ether_output;
243 ifp->if_start = tapifstart;
244 ifp->if_ioctl = tapifioctl;
245 ifp->if_mtu = ETHERMTU;
246 ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
247 ifp->if_snd.ifq_maxlen = ifqmaxlen;
248
249 s = splimp();
244 ether_ifattach(ifp, 1);
250 ether_ifattach(ifp, 1);
251 splx(s);
245
252
246 tp->tap_flags = TAP_INITED;
253 tp->tap_flags |= TAP_INITED;
254
255 TAPDEBUG("interface %s%d created. minor = %#x\n",
256 ifp->if_name, ifp->if_unit, minor(tp->tap_dev));
247} /* tapcreate */
248
249
250/*
251 * tapopen
252 *
253 * to open tunnel. must be superuser
254 */

--- 18 unchanged lines hidden (view full) ---

273
274 if (tp->tap_flags & TAP_OPEN)
275 return (EBUSY);
276
277 tp->tap_pid = p->p_pid;
278 tp->tap_flags |= TAP_OPEN;
279 taprefcnt ++;
280
257} /* tapcreate */
258
259
260/*
261 * tapopen
262 *
263 * to open tunnel. must be superuser
264 */

--- 18 unchanged lines hidden (view full) ---

283
284 if (tp->tap_flags & TAP_OPEN)
285 return (EBUSY);
286
287 tp->tap_pid = p->p_pid;
288 tp->tap_flags |= TAP_OPEN;
289 taprefcnt ++;
290
281 TAPDEBUG("%s%d is open. refcnt = %d, taplastunit = %d\n",
282 tp->tap_if.if_name, tp->tap_if.if_unit, taprefcnt, taplastunit);
291 TAPDEBUG("%s%d is open. minor = %#x, refcnt = %d, taplastunit = %d\n",
292 tp->tap_if.if_name, tp->tap_if.if_unit,
293 minor(tp->tap_dev), taprefcnt, taplastunit);
283
284 return (0);
285} /* tapopen */
286
287
288/*
289 * tapclose
290 *

--- 16 unchanged lines hidden (view full) ---

307 s = splimp();
308 do {
309 IF_DEQUEUE(&ifp->if_snd, m);
310 if (m != NULL)
311 m_freem(m);
312 } while (m != NULL);
313 splx(s);
314
294
295 return (0);
296} /* tapopen */
297
298
299/*
300 * tapclose
301 *

--- 16 unchanged lines hidden (view full) ---

318 s = splimp();
319 do {
320 IF_DEQUEUE(&ifp->if_snd, m);
321 if (m != NULL)
322 m_freem(m);
323 } while (m != NULL);
324 splx(s);
325
315 if (ifp->if_flags & IFF_UP) {
326 /*
327 * do not bring the interface down, and do not anything with
328 * interface, if we are in VMnet mode. just close the device.
329 */
330
331 if (((tp->tap_flags & TAP_VMNET) == 0) && (ifp->if_flags & IFF_UP)) {
316 s = splimp();
317 if_down(ifp);
318 if (ifp->if_flags & IFF_RUNNING) {
319 /* find internet addresses and delete routes */
320 struct ifaddr *ifa = NULL;
321
332 s = splimp();
333 if_down(ifp);
334 if (ifp->if_flags & IFF_RUNNING) {
335 /* find internet addresses and delete routes */
336 struct ifaddr *ifa = NULL;
337
322 for (ifa = ifp->if_addrhead.tqh_first; ifa;
323 ifa = ifa->ifa_link.tqe_next) {
338 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
324 if (ifa->ifa_addr->sa_family == AF_INET) {
325 rtinit(ifa, (int)RTM_DELETE, 0);
326
327 /* remove address from interface */
328 bzero(ifa->ifa_addr,
329 sizeof(*(ifa->ifa_addr)));
330 bzero(ifa->ifa_dstaddr,
331 sizeof(*(ifa->ifa_dstaddr)));

--- 11 unchanged lines hidden (view full) ---

343 selwakeup(&tp->tap_rsel);
344
345 tp->tap_flags &= ~TAP_OPEN;
346 tp->tap_pid = 0;
347
348 taprefcnt --;
349 if (taprefcnt < 0) {
350 taprefcnt = 0;
339 if (ifa->ifa_addr->sa_family == AF_INET) {
340 rtinit(ifa, (int)RTM_DELETE, 0);
341
342 /* remove address from interface */
343 bzero(ifa->ifa_addr,
344 sizeof(*(ifa->ifa_addr)));
345 bzero(ifa->ifa_dstaddr,
346 sizeof(*(ifa->ifa_dstaddr)));

--- 11 unchanged lines hidden (view full) ---

358 selwakeup(&tp->tap_rsel);
359
360 tp->tap_flags &= ~TAP_OPEN;
361 tp->tap_pid = 0;
362
363 taprefcnt --;
364 if (taprefcnt < 0) {
365 taprefcnt = 0;
351 printf("%s%d refcnt = %d is out of sync. set refcnt to 0\n",
352 ifp->if_name, ifp->if_unit, taprefcnt);
366 printf("%s%d minor = %#x, refcnt = %d is out of sync. " \
367 "set refcnt to 0\n", ifp->if_name, ifp->if_unit,
368 minor(tp->tap_dev), taprefcnt);
353 }
354
369 }
370
355 TAPDEBUG("%s%d is closed. refcnt = %d, taplastunit = %d\n",
356 ifp->if_name, ifp->if_unit, taprefcnt, taplastunit);
371 TAPDEBUG("%s%d is closed. minor = %#x, refcnt = %d, taplastunit = %d\n",
372 ifp->if_name, ifp->if_unit, minor(tp->tap_dev),
373 taprefcnt, taplastunit);
357
358 return (0);
359} /* tapclose */
360
361
362/*
363 * tapifinit
364 *
365 * network interface initialization function
366 */
367static void
368tapifinit(xtp)
369 void *xtp;
370{
371 struct tap_softc *tp = (struct tap_softc *)xtp;
372 struct ifnet *ifp = &tp->tap_if;
373
374
375 return (0);
376} /* tapclose */
377
378
379/*
380 * tapifinit
381 *
382 * network interface initialization function
383 */
384static void
385tapifinit(xtp)
386 void *xtp;
387{
388 struct tap_softc *tp = (struct tap_softc *)xtp;
389 struct ifnet *ifp = &tp->tap_if;
390
374 TAPDEBUG("initializing %s%d\n", ifp->if_name, ifp->if_unit);
391 TAPDEBUG("initializing %s%d, minor = %#x\n",
392 ifp->if_name, ifp->if_unit, minor(tp->tap_dev));
375
376 ifp->if_flags |= IFF_RUNNING;
377 ifp->if_flags &= ~IFF_OACTIVE;
378
379 /* attempt to start output */
380 tapifstart(ifp);
381} /* tapifinit */
382

--- 53 unchanged lines hidden (view full) ---

436 */
437static void
438tapifstart(ifp)
439 struct ifnet *ifp;
440{
441 struct tap_softc *tp = ifp->if_softc;
442 int s;
443
393
394 ifp->if_flags |= IFF_RUNNING;
395 ifp->if_flags &= ~IFF_OACTIVE;
396
397 /* attempt to start output */
398 tapifstart(ifp);
399} /* tapifinit */
400

--- 53 unchanged lines hidden (view full) ---

454 */
455static void
456tapifstart(ifp)
457 struct ifnet *ifp;
458{
459 struct tap_softc *tp = ifp->if_softc;
460 int s;
461
444 TAPDEBUG("%s%d starting\n", ifp->if_name, ifp->if_unit);
462 TAPDEBUG("%s%d starting, minor = %#x\n",
463 ifp->if_name, ifp->if_unit, minor(tp->tap_dev));
445
464
446 if ((tp->tap_flags & TAP_READY) != TAP_READY) {
465 /*
466 * do not junk pending output if we are in VMnet mode.
467 * XXX: can this do any harm because of queue overflow?
468 */
469
470 if (((tp->tap_flags & TAP_VMNET) == 0) &&
471 ((tp->tap_flags & TAP_READY) != TAP_READY)) {
447 struct mbuf *m = NULL;
448
472 struct mbuf *m = NULL;
473
449 TAPDEBUG("%s%d not ready. tap_flags = 0x%x\n",
450 ifp->if_name, ifp->if_unit, tp->tap_flags);
474 TAPDEBUG("%s%d not ready. minor = %#x, tap_flags = 0x%x\n",
475 ifp->if_name, ifp->if_unit,
476 minor(tp->tap_dev), tp->tap_flags);
451
452 s = splimp();
453 do {
454 IF_DEQUEUE(&ifp->if_snd, m);
455 if (m != NULL)
456 m_freem(m);
457 ifp->if_oerrors ++;
458 } while (m != NULL);

--- 65 unchanged lines hidden (view full) ---

524 case TAPGDEBUG:
525 *(int *)data = tapdebug;
526 break;
527
528 case FIONBIO:
529 break;
530
531 case FIOASYNC:
477
478 s = splimp();
479 do {
480 IF_DEQUEUE(&ifp->if_snd, m);
481 if (m != NULL)
482 m_freem(m);
483 ifp->if_oerrors ++;
484 } while (m != NULL);

--- 65 unchanged lines hidden (view full) ---

550 case TAPGDEBUG:
551 *(int *)data = tapdebug;
552 break;
553
554 case FIONBIO:
555 break;
556
557 case FIOASYNC:
558 s = splimp();
532 if (*(int *)data)
533 tp->tap_flags |= TAP_ASYNC;
534 else
535 tp->tap_flags &= ~TAP_ASYNC;
559 if (*(int *)data)
560 tp->tap_flags |= TAP_ASYNC;
561 else
562 tp->tap_flags &= ~TAP_ASYNC;
563 splx(s);
536 break;
537
538 case FIONREAD:
539 s = splimp();
540 if (ifp->if_snd.ifq_head) {
541 struct mbuf *mb = ifp->if_snd.ifq_head;
542
564 break;
565
566 case FIONREAD:
567 s = splimp();
568 if (ifp->if_snd.ifq_head) {
569 struct mbuf *mb = ifp->if_snd.ifq_head;
570
543 for(*(int *)data = 0; mb != 0; mb = mb->m_next)
571 for(*(int *)data = 0;mb != NULL;mb = mb->m_next)
544 *(int *)data += mb->m_len;
545 }
546 else
547 *(int *)data = 0;
548 splx(s);
549 break;
550
551 case FIOSETOWN:

--- 60 unchanged lines hidden (view full) ---

612 struct uio *uio;
613 int flag;
614{
615 struct tap_softc *tp = dev->si_drv1;
616 struct ifnet *ifp = &tp->tap_if;
617 struct mbuf *m = NULL, *m0 = NULL;
618 int error = 0, len, s;
619
572 *(int *)data += mb->m_len;
573 }
574 else
575 *(int *)data = 0;
576 splx(s);
577 break;
578
579 case FIOSETOWN:

--- 60 unchanged lines hidden (view full) ---

640 struct uio *uio;
641 int flag;
642{
643 struct tap_softc *tp = dev->si_drv1;
644 struct ifnet *ifp = &tp->tap_if;
645 struct mbuf *m = NULL, *m0 = NULL;
646 int error = 0, len, s;
647
620 TAPDEBUG("%s%d reading\n", ifp->if_name, ifp->if_unit);
648 TAPDEBUG("%s%d reading, minor = %#x\n",
649 ifp->if_name, ifp->if_unit, minor(tp->tap_dev));
621
622 if ((tp->tap_flags & TAP_READY) != TAP_READY) {
650
651 if ((tp->tap_flags & TAP_READY) != TAP_READY) {
623 TAPDEBUG("%s%d not ready. tap_flags = 0x%x\n",
624 ifp->if_name, ifp->if_unit, tp->tap_flags);
652 TAPDEBUG("%s%d not ready. minor = %#x, tap_flags = 0x%x\n",
653 ifp->if_name, ifp->if_unit,
654 minor(tp->tap_dev), tp->tap_flags);
655
625 return (EHOSTDOWN);
626 }
627
628 tp->tap_flags &= ~TAP_RWAIT;
629
630 /* sleep until we get a packet */
631 do {
632 s = splimp();

--- 4 unchanged lines hidden (view full) ---

637 if (flag & IO_NDELAY)
638 return (EWOULDBLOCK);
639
640 tp->tap_flags |= TAP_RWAIT;
641 error = tsleep((caddr_t)tp,PCATCH|(PZERO+1),"taprd",0);
642 if (error)
643 return (error);
644 }
656 return (EHOSTDOWN);
657 }
658
659 tp->tap_flags &= ~TAP_RWAIT;
660
661 /* sleep until we get a packet */
662 do {
663 s = splimp();

--- 4 unchanged lines hidden (view full) ---

668 if (flag & IO_NDELAY)
669 return (EWOULDBLOCK);
670
671 tp->tap_flags |= TAP_RWAIT;
672 error = tsleep((caddr_t)tp,PCATCH|(PZERO+1),"taprd",0);
673 if (error)
674 return (error);
675 }
645 } while (m0 == 0);
676 } while (m0 == NULL);
646
647 /* feed packet to bpf */
648 if (ifp->if_bpf != NULL)
649 bpf_mtap(ifp, m0);
650
651 /* xfer packet to user space */
652 while ((m0 != NULL) && (uio->uio_resid > 0) && (error == 0)) {
653 len = min(uio->uio_resid, m0->m_len);
654 if (len == 0)
655 break;
656
657 error = uiomove(mtod(m0, caddr_t), len, uio);
658 MFREE(m0, m);
659 m0 = m;
660 }
661
662 if (m0 != NULL) {
677
678 /* feed packet to bpf */
679 if (ifp->if_bpf != NULL)
680 bpf_mtap(ifp, m0);
681
682 /* xfer packet to user space */
683 while ((m0 != NULL) && (uio->uio_resid > 0) && (error == 0)) {
684 len = min(uio->uio_resid, m0->m_len);
685 if (len == 0)
686 break;
687
688 error = uiomove(mtod(m0, caddr_t), len, uio);
689 MFREE(m0, m);
690 m0 = m;
691 }
692
693 if (m0 != NULL) {
663 TAPDEBUG("%s%d dropping mbuf\n", ifp->if_name, ifp->if_unit);
694 TAPDEBUG("%s%d dropping mbuf, minor = %#x\n",
695 ifp->if_name, ifp->if_unit, minor(tp->tap_dev));
664 m_freem(m0);
665 }
666
667 return (error);
668} /* tapread */
669
670
671/*

--- 8 unchanged lines hidden (view full) ---

680 int flag;
681{
682 struct tap_softc *tp = dev->si_drv1;
683 struct ifnet *ifp = &tp->tap_if;
684 struct mbuf *top = NULL, **mp = NULL, *m = NULL;
685 struct ether_header *eh = NULL;
686 int error = 0, tlen, mlen;
687
696 m_freem(m0);
697 }
698
699 return (error);
700} /* tapread */
701
702
703/*

--- 8 unchanged lines hidden (view full) ---

712 int flag;
713{
714 struct tap_softc *tp = dev->si_drv1;
715 struct ifnet *ifp = &tp->tap_if;
716 struct mbuf *top = NULL, **mp = NULL, *m = NULL;
717 struct ether_header *eh = NULL;
718 int error = 0, tlen, mlen;
719
688 TAPDEBUG("%s%d writting\n", ifp->if_name, ifp->if_unit);
720 TAPDEBUG("%s%d writting, minor = %#x\n",
721 ifp->if_name, ifp->if_unit, minor(tp->tap_dev));
689
690 if (uio->uio_resid == 0)
691 return (0);
692
693 if ((uio->uio_resid < 0) || (uio->uio_resid > TAPMRU)) {
722
723 if (uio->uio_resid == 0)
724 return (0);
725
726 if ((uio->uio_resid < 0) || (uio->uio_resid > TAPMRU)) {
694 TAPDEBUG("%s%d invalid packet len = %d\n",
695 ifp->if_name, ifp->if_unit, uio->uio_resid);
727 TAPDEBUG("%s%d invalid packet len = %d, minor = %#x\n",
728 ifp->if_name, ifp->if_unit,
729 uio->uio_resid, minor(tp->tap_dev));
730
696 return (EIO);
697 }
698 tlen = uio->uio_resid;
699
700 /* get a header mbuf */
701 MGETHDR(m, M_DONTWAIT, MT_DATA);
702 if (m == NULL)
703 return (ENOBUFS);
704 mlen = MHLEN;
705
706 top = 0;
707 mp = &top;
708 while ((error == 0) && (uio->uio_resid > 0)) {
709 m->m_len = min(mlen, uio->uio_resid);
710 error = uiomove(mtod(m, caddr_t), m->m_len, uio);
711 *mp = m;
712 mp = &m->m_next;
713 if (uio->uio_resid > 0) {
714 MGET(m, M_DONTWAIT, MT_DATA);
731 return (EIO);
732 }
733 tlen = uio->uio_resid;
734
735 /* get a header mbuf */
736 MGETHDR(m, M_DONTWAIT, MT_DATA);
737 if (m == NULL)
738 return (ENOBUFS);
739 mlen = MHLEN;
740
741 top = 0;
742 mp = &top;
743 while ((error == 0) && (uio->uio_resid > 0)) {
744 m->m_len = min(mlen, uio->uio_resid);
745 error = uiomove(mtod(m, caddr_t), m->m_len, uio);
746 *mp = m;
747 mp = &m->m_next;
748 if (uio->uio_resid > 0) {
749 MGET(m, M_DONTWAIT, MT_DATA);
715 if (m == 0) {
750 if (m == NULL) {
716 error = ENOBUFS;
717 break;
718 }
719 mlen = MLEN;
720 }
721 }
722 if (error) {
723 ifp->if_ierrors ++;

--- 32 unchanged lines hidden (view full) ---

756 dev_t dev;
757 int events;
758 struct proc *p;
759{
760 struct tap_softc *tp = dev->si_drv1;
761 struct ifnet *ifp = &tp->tap_if;
762 int s, revents = 0;
763
751 error = ENOBUFS;
752 break;
753 }
754 mlen = MLEN;
755 }
756 }
757 if (error) {
758 ifp->if_ierrors ++;

--- 32 unchanged lines hidden (view full) ---

791 dev_t dev;
792 int events;
793 struct proc *p;
794{
795 struct tap_softc *tp = dev->si_drv1;
796 struct ifnet *ifp = &tp->tap_if;
797 int s, revents = 0;
798
764 TAPDEBUG("%s%d polling\n", ifp->if_name, ifp->if_unit);
799 TAPDEBUG("%s%d polling, minor = %#x\n",
800 ifp->if_name, ifp->if_unit, minor(tp->tap_dev));
765
766 s = splimp();
767 if (events & (POLLIN | POLLRDNORM)) {
768 if (ifp->if_snd.ifq_len > 0) {
801
802 s = splimp();
803 if (events & (POLLIN | POLLRDNORM)) {
804 if (ifp->if_snd.ifq_len > 0) {
769 TAPDEBUG("%s%d have data in queue. len = %d\n",
770 ifp->if_name,ifp->if_unit, ifp->if_snd.ifq_len);
805 TAPDEBUG("%s%d have data in queue. len = %d, " \
806 "minor = %#x\n", ifp->if_name, ifp->if_unit,
807 ifp->if_snd.ifq_len, minor(tp->tap_dev));
808
771 revents |= (events & (POLLIN | POLLRDNORM));
772 }
773 else {
809 revents |= (events & (POLLIN | POLLRDNORM));
810 }
811 else {
774 TAPDEBUG("%s%d waiting for data\n",
775 ifp->if_name, ifp->if_unit);
812 TAPDEBUG("%s%d waiting for data, minor = %#x\n",
813 ifp->if_name, ifp->if_unit, minor(tp->tap_dev));
814
776 selrecord(p, &tp->tap_rsel);
777 }
778 }
779
780 if (events & (POLLOUT | POLLWRNORM))
781 revents |= (events & (POLLOUT | POLLWRNORM));
782
783 splx(s);
784 return (revents);
785} /* tappoll */
815 selrecord(p, &tp->tap_rsel);
816 }
817 }
818
819 if (events & (POLLOUT | POLLWRNORM))
820 revents |= (events & (POLLOUT | POLLWRNORM));
821
822 splx(s);
823 return (revents);
824} /* tappoll */