Deleted Added
full compact
if_tap.c (105228) if_tap.c (106939)
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 105228 2002-10-16 10:45:53Z phk $
34 * $FreeBSD: head/sys/net/if_tap.c 106939 2002-11-15 00:00:15Z sam $
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>

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

215
216 KASSERT(!(tp->tap_flags & TAP_OPEN),
217 ("%s%d flags is out of sync", ifp->if_name,
218 ifp->if_unit));
219
220 /* XXX makedev check? nah.. not right now :) */
221
222 s = splimp();
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>

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

215
216 KASSERT(!(tp->tap_flags & TAP_OPEN),
217 ("%s%d flags is out of sync", ifp->if_name,
218 ifp->if_unit));
219
220 /* XXX makedev check? nah.. not right now :) */
221
222 s = splimp();
223 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
223 ether_ifdetach(ifp);
224 splx(s);
225
226 free(tp, M_TAP);
227 }
228
229 if (tapbasedev != NOUDEV)
230 destroy_dev(udev2dev(tapbasedev, 0));
231

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

358 tp->arpcom.ac_enaddr[5] = (u_char)unit;
359
360 /* fill the rest and attach interface */
361 ifp = &tp->tap_if;
362 ifp->if_softc = tp;
363 ifp->if_unit = unit;
364 ifp->if_name = name;
365 ifp->if_init = tapifinit;
224 splx(s);
225
226 free(tp, M_TAP);
227 }
228
229 if (tapbasedev != NOUDEV)
230 destroy_dev(udev2dev(tapbasedev, 0));
231

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

358 tp->arpcom.ac_enaddr[5] = (u_char)unit;
359
360 /* fill the rest and attach interface */
361 ifp = &tp->tap_if;
362 ifp->if_softc = tp;
363 ifp->if_unit = unit;
364 ifp->if_name = name;
365 ifp->if_init = tapifinit;
366 ifp->if_output = ether_output;
367 ifp->if_start = tapifstart;
368 ifp->if_ioctl = tapifioctl;
369 ifp->if_mtu = ETHERMTU;
370 ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
371 ifp->if_snd.ifq_maxlen = ifqmaxlen;
372
373 dev->si_drv1 = tp;
374
375 s = splimp();
366 ifp->if_start = tapifstart;
367 ifp->if_ioctl = tapifioctl;
368 ifp->if_mtu = ETHERMTU;
369 ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
370 ifp->if_snd.ifq_maxlen = ifqmaxlen;
371
372 dev->si_drv1 = tp;
373
374 s = splimp();
376 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
375 ether_ifattach(ifp, tp->arpcom.ac_enaddr);
377 splx(s);
378
379 tp->tap_flags |= TAP_INITED;
380
381 TAPDEBUG("interface %s%d is created. minor = %#x\n",
382 ifp->if_name, ifp->if_unit, minor(dev));
383} /* tapcreate */
384

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

541 u_long cmd;
542 caddr_t data;
543{
544 struct tap_softc *tp = (struct tap_softc *)(ifp->if_softc);
545 struct ifstat *ifs = NULL;
546 int s, dummy;
547
548 switch (cmd) {
376 splx(s);
377
378 tp->tap_flags |= TAP_INITED;
379
380 TAPDEBUG("interface %s%d is created. minor = %#x\n",
381 ifp->if_name, ifp->if_unit, minor(dev));
382} /* tapcreate */
383

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

540 u_long cmd;
541 caddr_t data;
542{
543 struct tap_softc *tp = (struct tap_softc *)(ifp->if_softc);
544 struct ifstat *ifs = NULL;
545 int s, dummy;
546
547 switch (cmd) {
549 case SIOCSIFADDR:
550 case SIOCGIFADDR:
551 case SIOCSIFMTU:
552 s = splimp();
553 dummy = ether_ioctl(ifp, cmd, data);
554 splx(s);
555 return (dummy);
556
557 case SIOCSIFFLAGS: /* XXX -- just like vmnet does */
558 case SIOCADDMULTI:
559 case SIOCDELMULTI:
560 break;
561
562 case SIOCGIFSTATUS:
563 s = splimp();
564 ifs = (struct ifstat *)data;
565 dummy = strlen(ifs->ascii);
566 if (tp->tap_pid != 0 && dummy < sizeof(ifs->ascii))
567 snprintf(ifs->ascii + dummy,
568 sizeof(ifs->ascii) - dummy,
569 "\tOpened by PID %d\n", tp->tap_pid);
570 splx(s);
571 break;
572
573 default:
548 case SIOCSIFFLAGS: /* XXX -- just like vmnet does */
549 case SIOCADDMULTI:
550 case SIOCDELMULTI:
551 break;
552
553 case SIOCGIFSTATUS:
554 s = splimp();
555 ifs = (struct ifstat *)data;
556 dummy = strlen(ifs->ascii);
557 if (tp->tap_pid != 0 && dummy < sizeof(ifs->ascii))
558 snprintf(ifs->ascii + dummy,
559 sizeof(ifs->ascii) - dummy,
560 "\tOpened by PID %d\n", tp->tap_pid);
561 splx(s);
562 break;
563
564 default:
574 return (EINVAL);
565 s = splimp();
566 dummy = ether_ioctl(ifp, cmd, data);
567 splx(s);
568 return (dummy);
575 }
576
577 return (0);
578} /* tapifioctl */
579
580
581/*
582 * tapifstart

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

796 tp->tap_flags |= TAP_RWAIT;
797 error = tsleep((caddr_t)tp,PCATCH|(PZERO+1),"taprd",0);
798 if (error)
799 return (error);
800 }
801 } while (m == NULL);
802
803 /* feed packet to bpf */
569 }
570
571 return (0);
572} /* tapifioctl */
573
574
575/*
576 * tapifstart

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

790 tp->tap_flags |= TAP_RWAIT;
791 error = tsleep((caddr_t)tp,PCATCH|(PZERO+1),"taprd",0);
792 if (error)
793 return (error);
794 }
795 } while (m == NULL);
796
797 /* feed packet to bpf */
804 if (ifp->if_bpf != NULL)
805 bpf_mtap(ifp, m);
798 BPF_MTAP(ifp, m);
806
807 /* xfer packet to user space */
808 while ((m != NULL) && (uio->uio_resid > 0) && (error == 0)) {
809 len = min(uio->uio_resid, m->m_len);
810 if (len == 0)
811 break;
812
813 error = uiomove(mtod(m, caddr_t), len, uio);

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

833tapwrite(dev, uio, flag)
834 dev_t dev;
835 struct uio *uio;
836 int flag;
837{
838 struct tap_softc *tp = dev->si_drv1;
839 struct ifnet *ifp = &tp->tap_if;
840 struct mbuf *top = NULL, **mp = NULL, *m = NULL;
799
800 /* xfer packet to user space */
801 while ((m != NULL) && (uio->uio_resid > 0) && (error == 0)) {
802 len = min(uio->uio_resid, m->m_len);
803 if (len == 0)
804 break;
805
806 error = uiomove(mtod(m, caddr_t), len, uio);

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

826tapwrite(dev, uio, flag)
827 dev_t dev;
828 struct uio *uio;
829 int flag;
830{
831 struct tap_softc *tp = dev->si_drv1;
832 struct ifnet *ifp = &tp->tap_if;
833 struct mbuf *top = NULL, **mp = NULL, *m = NULL;
841 struct ether_header *eh = NULL;
842 int error = 0, tlen, mlen;
843
844 TAPDEBUG("%s%d writting, minor = %#x\n",
845 ifp->if_name, ifp->if_unit, minor(dev));
846
847 if (uio->uio_resid == 0)
848 return (0);
849

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

882 if (top)
883 m_freem(top);
884 return (error);
885 }
886
887 top->m_pkthdr.len = tlen;
888 top->m_pkthdr.rcvif = ifp;
889
834 int error = 0, tlen, mlen;
835
836 TAPDEBUG("%s%d writting, minor = %#x\n",
837 ifp->if_name, ifp->if_unit, minor(dev));
838
839 if (uio->uio_resid == 0)
840 return (0);
841

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

874 if (top)
875 m_freem(top);
876 return (error);
877 }
878
879 top->m_pkthdr.len = tlen;
880 top->m_pkthdr.rcvif = ifp;
881
890 /*
891 * Ethernet bridge and bpf are handled in ether_input
892 *
893 * adjust mbuf and give packet to the ether_input
894 */
882 /* Pass packet up to parent. */
883 (*ifp->if_input)(ifp, top);
884 ifp->if_ipackets ++; /* ibytes are counted in parent */
895
885
896 eh = mtod(top, struct ether_header *);
897 m_adj(top, sizeof(struct ether_header));
898 ether_input(ifp, eh, top);
899 ifp->if_ipackets ++; /* ibytes are counted in ether_input */
900
901 return (0);
902} /* tapwrite */
903
904
905/*
906 * tappoll
907 *
908 * the poll interface, this is only useful on reads

--- 38 unchanged lines hidden ---
886 return (0);
887} /* tapwrite */
888
889
890/*
891 * tappoll
892 *
893 * the poll interface, this is only useful on reads

--- 38 unchanged lines hidden ---