if_tun.c (111815) | if_tun.c (111888) |
---|---|
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 * | 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: head/sys/net/if_tun.c 111815 2003-03-03 12:15:54Z phk $ | 16 * $FreeBSD: head/sys/net/if_tun.c 111888 2003-03-04 23:19:55Z jlemon $ |
17 */ 18 19#include "opt_inet.h" 20#include "opt_mac.h" 21 22#include <sys/param.h> 23#include <sys/proc.h> 24#include <sys/systm.h> --- 9 unchanged lines hidden (view full) --- 34#include <sys/filedesc.h> 35#include <sys/kernel.h> 36#include <sys/sysctl.h> 37#include <sys/conf.h> 38#include <sys/uio.h> 39#include <sys/vnode.h> 40#include <sys/malloc.h> 41#include <machine/bus.h> /* XXX Shouldn't really be required ! */ | 17 */ 18 19#include "opt_inet.h" 20#include "opt_mac.h" 21 22#include <sys/param.h> 23#include <sys/proc.h> 24#include <sys/systm.h> --- 9 unchanged lines hidden (view full) --- 34#include <sys/filedesc.h> 35#include <sys/kernel.h> 36#include <sys/sysctl.h> 37#include <sys/conf.h> 38#include <sys/uio.h> 39#include <sys/vnode.h> 40#include <sys/malloc.h> 41#include <machine/bus.h> /* XXX Shouldn't really be required ! */ |
42#include <sys/random.h> |
|
42#include <sys/rman.h> 43 44#include <net/if.h> 45#include <net/if_types.h> | 43#include <sys/rman.h> 44 45#include <net/if.h> 46#include <net/if_types.h> |
47#include <net/netisr.h> |
|
46#include <net/route.h> | 48#include <net/route.h> |
47#include <net/intrq.h> | |
48#ifdef INET 49#include <netinet/in.h> 50#endif 51#include <net/bpf.h> 52#include <net/if_tunvar.h> 53#include <net/if_tun.h> 54 55#define TUNDEBUG if (tundebug) printf --- 632 unchanged lines hidden (view full) --- 688static int 689tunwrite(dev_t dev, struct uio *uio, int flag) 690{ 691 struct tun_softc *tp = dev->si_drv1; 692 struct ifnet *ifp = &tp->tun_if; 693 struct mbuf *top, **mp, *m; 694 int error=0, tlen, mlen; 695 uint32_t family; | 49#ifdef INET 50#include <netinet/in.h> 51#endif 52#include <net/bpf.h> 53#include <net/if_tunvar.h> 54#include <net/if_tun.h> 55 56#define TUNDEBUG if (tundebug) printf --- 632 unchanged lines hidden (view full) --- 689static int 690tunwrite(dev_t dev, struct uio *uio, int flag) 691{ 692 struct tun_softc *tp = dev->si_drv1; 693 struct ifnet *ifp = &tp->tun_if; 694 struct mbuf *top, **mp, *m; 695 int error=0, tlen, mlen; 696 uint32_t family; |
697 int isr; |
|
696 697 TUNDEBUG("%s%d: tunwrite\n", ifp->if_name, ifp->if_unit); 698 699 if ((ifp->if_flags & IFF_UP) != IFF_UP) 700 /* ignore silently */ 701 return (0); 702 703 if (uio->uio_resid == 0) --- 78 unchanged lines hidden (view full) --- 782 if (top->m_len < sizeof(family) && 783 (top = m_pullup(top, sizeof(family))) == NULL) 784 return (ENOBUFS); 785 family = ntohl(*mtod(top, u_int32_t *)); 786 m_adj(top, sizeof(family)); 787 } else 788 family = AF_INET; 789 | 698 699 TUNDEBUG("%s%d: tunwrite\n", ifp->if_name, ifp->if_unit); 700 701 if ((ifp->if_flags & IFF_UP) != IFF_UP) 702 /* ignore silently */ 703 return (0); 704 705 if (uio->uio_resid == 0) --- 78 unchanged lines hidden (view full) --- 784 if (top->m_len < sizeof(family) && 785 (top = m_pullup(top, sizeof(family))) == NULL) 786 return (ENOBUFS); 787 family = ntohl(*mtod(top, u_int32_t *)); 788 m_adj(top, sizeof(family)); 789 } else 790 family = AF_INET; 791 |
792 switch (family) { 793#ifdef INET 794 case AF_INET: 795 isr = NETISR_IP; 796 break; 797#endif 798#ifdef INET6 799 case AF_INET6: 800 isr = NETISR_IPV6; 801 break; 802#endif 803#ifdef IPX 804 case AF_IPX: 805 isr = NETISR_IPX; 806 break; 807#endif 808#ifdef NS 809 case AF_NS: 810 isr = NETISR_NS; 811 break; 812#endif 813#ifdef NETATALK 814 case AF_APPLETALK: 815 isr = NETISR_ATALK2; 816 break; 817#endif 818#ifdef NATM 819 case AF_NATM: 820 isr = NETISR_NATM; 821 break; 822#endif 823#ifdef ATM_CORE 824 case AF_ATM: 825 isr = NETISR_ATM; 826 break; 827#endif 828 default: 829 m_freem(m); 830 return (EAFNOSUPPORT); 831 } 832 /* First chunk of an mbuf contains good junk */ 833 if (harvest.point_to_point) 834 random_harvest(m, 16, 3, 0, RANDOM_NET); |
|
790 ifp->if_ibytes += top->m_pkthdr.len; 791 ifp->if_ipackets++; | 835 ifp->if_ibytes += top->m_pkthdr.len; 836 ifp->if_ipackets++; |
792 793 return (family_enqueue(family, top)); | 837 netisr_dispatch(isr, top); 838 return (0); |
794} 795 796/* 797 * tunpoll - the poll interface, this is only useful on reads 798 * really. The write detect always returns true, write never blocks 799 * anyway, it either accepts the packet or drops it. 800 */ 801static int --- 27 unchanged lines hidden --- | 839} 840 841/* 842 * tunpoll - the poll interface, this is only useful on reads 843 * really. The write detect always returns true, write never blocks 844 * anyway, it either accepts the packet or drops it. 845 */ 846static int --- 27 unchanged lines hidden --- |