Give if_tun the "almost clone" makeover.
This commit is contained in:
parent
b813f67e2a
commit
8675115e75
@ -11,7 +11,7 @@
|
||||
# device lines is present in the ./LINT configuration file. If you are
|
||||
# in doubt as to the purpose or necessity of a line, check first in LINT.
|
||||
#
|
||||
# $Id: GENERIC,v 1.34 1999/08/10 17:15:11 wpaul Exp $
|
||||
# $Id: GENERIC,v 1.35 1999/08/11 22:33:57 gallatin Exp $
|
||||
|
||||
machine alpha
|
||||
cpu EV4
|
||||
@ -127,7 +127,7 @@ pseudo-device loop
|
||||
pseudo-device ether
|
||||
pseudo-device sl 1
|
||||
pseudo-device ppp 1
|
||||
pseudo-device tun 1
|
||||
pseudo-device tun
|
||||
pseudo-device pty
|
||||
|
||||
# KTRACE enables the system-call tracing facility ktrace(2).
|
||||
|
@ -11,7 +11,7 @@
|
||||
# device lines is present in the ./LINT configuration file. If you are
|
||||
# in doubt as to the purpose or necessity of a line, check first in LINT.
|
||||
#
|
||||
# $Id: GENERIC,v 1.34 1999/08/10 17:15:11 wpaul Exp $
|
||||
# $Id: GENERIC,v 1.35 1999/08/11 22:33:57 gallatin Exp $
|
||||
|
||||
machine alpha
|
||||
cpu EV4
|
||||
@ -127,7 +127,7 @@ pseudo-device loop
|
||||
pseudo-device ether
|
||||
pseudo-device sl 1
|
||||
pseudo-device ppp 1
|
||||
pseudo-device tun 1
|
||||
pseudo-device tun
|
||||
pseudo-device pty
|
||||
|
||||
# KTRACE enables the system-call tracing facility ktrace(2).
|
||||
|
@ -11,7 +11,7 @@
|
||||
# device lines is present in the ./LINT configuration file. If you are
|
||||
# in doubt as to the purpose or necessity of a line, check first in LINT.
|
||||
#
|
||||
# $Id: SIMOS,v 1.4 1999/06/15 13:14:29 des Exp $
|
||||
# $Id: SIMOS,v 1.5 1999/08/08 19:28:56 phk Exp $
|
||||
|
||||
machine "alpha"
|
||||
cpu "EV5"
|
||||
@ -63,7 +63,7 @@ pseudo-device loop
|
||||
pseudo-device ether
|
||||
pseudo-device sl 1
|
||||
pseudo-device ppp 1
|
||||
pseudo-device tun 1
|
||||
pseudo-device tun
|
||||
pseudo-device pty
|
||||
pseudo-device gzip # Exec gzipped a.out's
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
# device lines is also present in the ./LINT configuration file. If you are
|
||||
# in doubt as to the purpose or necessity of a line, check first in LINT.
|
||||
#
|
||||
# $Id: GENERIC,v 1.180 1999/08/08 19:28:57 phk Exp $
|
||||
# $Id: GENERIC,v 1.181 1999/08/15 09:38:20 phk Exp $
|
||||
|
||||
machine i386
|
||||
cpu I386_CPU
|
||||
@ -195,7 +195,7 @@ pseudo-device loop # Network loopback
|
||||
pseudo-device ether # Ethernet support
|
||||
pseudo-device sl 1 # Kernel SLIP
|
||||
pseudo-device ppp 1 # Kernel PPP
|
||||
pseudo-device tun 1 # Packet tunnel, for ppp(1)
|
||||
pseudo-device tun # Packet tunnel, for ppp(1)
|
||||
pseudo-device pty # Pseudo-ttys (telnet etc)
|
||||
pseudo-device gzip # Exec gzipped a.out's
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# LINT -- config file for checking all the sources, tries to pull in
|
||||
# as much of the source tree as it can.
|
||||
#
|
||||
# $Id: LINT,v 1.625 1999/08/08 19:28:57 phk Exp $
|
||||
# $Id: LINT,v 1.626 1999/08/15 09:38:20 phk Exp $
|
||||
#
|
||||
# NB: You probably don't want to try running a kernel built from this
|
||||
# file. Instead, you should start from GENERIC, and add options from
|
||||
@ -404,7 +404,7 @@ pseudo-device sppp #Generic Synchronous PPP
|
||||
pseudo-device loop #Network loopback device
|
||||
pseudo-device bpf #Berkeley packet filter
|
||||
pseudo-device disc #Discard device
|
||||
pseudo-device tun 1 #Tunnel driver (ppp(8), nos-tun(8))
|
||||
pseudo-device tun #Tunnel driver (ppp(8), nos-tun(8))
|
||||
pseudo-device sl 2 #Serial Line IP
|
||||
pseudo-device ppp 2 #Point-to-point protocol
|
||||
pseudo-device streams
|
||||
|
@ -15,7 +15,7 @@
|
||||
# device lines is also present in the ./LINT configuration file. If you are
|
||||
# in doubt as to the purpose or necessity of a line, check first in LINT.
|
||||
#
|
||||
# $Id: GENERIC,v 1.180 1999/08/08 19:28:57 phk Exp $
|
||||
# $Id: GENERIC,v 1.181 1999/08/15 09:38:20 phk Exp $
|
||||
|
||||
machine i386
|
||||
cpu I386_CPU
|
||||
@ -195,7 +195,7 @@ pseudo-device loop # Network loopback
|
||||
pseudo-device ether # Ethernet support
|
||||
pseudo-device sl 1 # Kernel SLIP
|
||||
pseudo-device ppp 1 # Kernel PPP
|
||||
pseudo-device tun 1 # Packet tunnel, for ppp(1)
|
||||
pseudo-device tun # Packet tunnel, for ppp(1)
|
||||
pseudo-device pty # Pseudo-ttys (telnet etc)
|
||||
pseudo-device gzip # Exec gzipped a.out's
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# LINT -- config file for checking all the sources, tries to pull in
|
||||
# as much of the source tree as it can.
|
||||
#
|
||||
# $Id: LINT,v 1.625 1999/08/08 19:28:57 phk Exp $
|
||||
# $Id: LINT,v 1.626 1999/08/15 09:38:20 phk Exp $
|
||||
#
|
||||
# NB: You probably don't want to try running a kernel built from this
|
||||
# file. Instead, you should start from GENERIC, and add options from
|
||||
@ -404,7 +404,7 @@ pseudo-device sppp #Generic Synchronous PPP
|
||||
pseudo-device loop #Network loopback device
|
||||
pseudo-device bpf #Berkeley packet filter
|
||||
pseudo-device disc #Discard device
|
||||
pseudo-device tun 1 #Tunnel driver (ppp(8), nos-tun(8))
|
||||
pseudo-device tun #Tunnel driver (ppp(8), nos-tun(8))
|
||||
pseudo-device sl 2 #Serial Line IP
|
||||
pseudo-device ppp 2 #Point-to-point protocol
|
||||
pseudo-device streams
|
||||
|
@ -2,7 +2,7 @@
|
||||
# LINT -- config file for checking all the sources, tries to pull in
|
||||
# as much of the source tree as it can.
|
||||
#
|
||||
# $Id: LINT,v 1.625 1999/08/08 19:28:57 phk Exp $
|
||||
# $Id: LINT,v 1.626 1999/08/15 09:38:20 phk Exp $
|
||||
#
|
||||
# NB: You probably don't want to try running a kernel built from this
|
||||
# file. Instead, you should start from GENERIC, and add options from
|
||||
@ -404,7 +404,7 @@ pseudo-device sppp #Generic Synchronous PPP
|
||||
pseudo-device loop #Network loopback device
|
||||
pseudo-device bpf #Berkeley packet filter
|
||||
pseudo-device disc #Discard device
|
||||
pseudo-device tun 1 #Tunnel driver (ppp(8), nos-tun(8))
|
||||
pseudo-device tun #Tunnel driver (ppp(8), nos-tun(8))
|
||||
pseudo-device sl 2 #Serial Line IP
|
||||
pseudo-device ppp 2 #Point-to-point protocol
|
||||
pseudo-device streams
|
||||
|
@ -12,7 +12,7 @@
|
||||
# device lines is present in the ./LINT configuration file. If you are
|
||||
# in doubt as to the purpose or necessity of a line, check first in LINT.
|
||||
#
|
||||
# $Id: PCCARD,v 1.15 1999/08/08 19:28:59 phk Exp $
|
||||
# $Id: PCCARD,v 1.16 1999/08/15 09:38:20 phk Exp $
|
||||
|
||||
machine i386
|
||||
cpu I386_CPU
|
||||
@ -191,7 +191,7 @@ pseudo-device loop # Network loopback
|
||||
pseudo-device ether # Ethernet support
|
||||
pseudo-device sl 1 # Kernel SLIP
|
||||
pseudo-device ppp 1 # Kernel PPP
|
||||
pseudo-device tun 1 # Packet tunnel, for ppp(1)
|
||||
pseudo-device tun # Packet tunnel, for ppp(1)
|
||||
pseudo-device pty # Pseudo-ttys (telnet etc)
|
||||
pseudo-device gzip # Exec gzipped a.out's
|
||||
|
||||
|
126
sys/net/if_tun.c
126
sys/net/if_tun.c
@ -15,9 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "tun.h"
|
||||
#if NTUN > 0
|
||||
|
||||
#include "opt_devfs.h"
|
||||
#include "opt_inet.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -33,12 +31,10 @@
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/sysctl.h>
|
||||
#ifdef DEVFS
|
||||
#include <sys/devfsext.h>
|
||||
#endif /*DEVFS*/
|
||||
#include <sys/conf.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/netisr.h>
|
||||
@ -62,19 +58,21 @@
|
||||
#include <net/if_tunvar.h>
|
||||
#include <net/if_tun.h>
|
||||
|
||||
static MALLOC_DEFINE(M_TUN, "tun", "Tunnel Interface");
|
||||
|
||||
static void tunattach __P((void *));
|
||||
PSEUDO_SET(tunattach, if_tun);
|
||||
|
||||
static void tuncreate __P((dev_t dev));
|
||||
|
||||
#define TUNDEBUG if (tundebug) printf
|
||||
static int tundebug = 0;
|
||||
SYSCTL_INT(_debug, OID_AUTO, if_tun_debug, CTLFLAG_RW, &tundebug, 0, "");
|
||||
|
||||
static struct tun_softc tunctl[NTUN];
|
||||
|
||||
static int tunoutput __P((struct ifnet *, struct mbuf *, struct sockaddr *,
|
||||
struct rtentry *rt));
|
||||
static int tunifioctl __P((struct ifnet *, u_long, caddr_t));
|
||||
static int tuninit __P((int));
|
||||
static int tuninit __P((struct ifnet *));
|
||||
|
||||
static d_open_t tunopen;
|
||||
static d_close_t tunclose;
|
||||
@ -106,48 +104,42 @@ static struct cdevsw tun_cdevsw = {
|
||||
/* bmaj */ -1
|
||||
};
|
||||
|
||||
|
||||
static int tun_devsw_installed;
|
||||
#ifdef DEVFS
|
||||
static void *tun_devfs_token[NTUN];
|
||||
#endif
|
||||
|
||||
#define minor_val(n) ((((n) & ~0xff) << 8) | ((n) & 0xff))
|
||||
#define dev_val(n) (((n) >> 8) | ((n) & 0xff))
|
||||
|
||||
static void
|
||||
tunattach(dummy)
|
||||
void *dummy;
|
||||
{
|
||||
register int i;
|
||||
|
||||
cdevsw_add(&tun_cdevsw);
|
||||
}
|
||||
|
||||
static void
|
||||
tuncreate(dev)
|
||||
dev_t dev;
|
||||
{
|
||||
struct tun_softc *sc;
|
||||
struct ifnet *ifp;
|
||||
|
||||
if ( tun_devsw_installed )
|
||||
return;
|
||||
cdevsw_add(&tun_cdevsw);
|
||||
tun_devsw_installed = 1;
|
||||
for ( i = 0; i < NTUN; i++ ) {
|
||||
#ifdef DEVFS
|
||||
tun_devfs_token[i] = devfs_add_devswf(&tun_cdevsw, minor_val(i),
|
||||
DV_CHR, UID_UUCP,
|
||||
GID_DIALER, 0600,
|
||||
"tun%d", i);
|
||||
#endif
|
||||
tunctl[i].tun_flags = TUN_INITED;
|
||||
dev = make_dev(&tun_cdevsw, minor(dev),
|
||||
UID_UUCP, GID_DIALER, 0600, "tun%d", lminor(dev));
|
||||
|
||||
ifp = &tunctl[i].tun_if;
|
||||
ifp->if_unit = i;
|
||||
ifp->if_name = "tun";
|
||||
ifp->if_mtu = TUNMTU;
|
||||
ifp->if_ioctl = tunifioctl;
|
||||
ifp->if_output = tunoutput;
|
||||
ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
|
||||
ifp->if_snd.ifq_maxlen = ifqmaxlen;
|
||||
if_attach(ifp);
|
||||
MALLOC(sc, struct tun_softc *, sizeof(*sc), M_TUN, M_WAITOK);
|
||||
bzero(sc, sizeof *sc);
|
||||
sc->tun_flags = TUN_INITED;
|
||||
|
||||
ifp = &sc->tun_if;
|
||||
ifp->if_unit = lminor(dev);
|
||||
ifp->if_name = "tun";
|
||||
ifp->if_mtu = TUNMTU;
|
||||
ifp->if_ioctl = tunifioctl;
|
||||
ifp->if_output = tunoutput;
|
||||
ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
|
||||
ifp->if_snd.ifq_maxlen = ifqmaxlen;
|
||||
ifp->if_softc = sc;
|
||||
if_attach(ifp);
|
||||
#if NBPF > 0
|
||||
bpfattach(ifp, DLT_NULL, sizeof(u_int));
|
||||
bpfattach(ifp, DLT_NULL, sizeof(u_int));
|
||||
#endif
|
||||
}
|
||||
dev->si_drv1 = sc;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -162,15 +154,17 @@ tunopen(dev, flag, mode, p)
|
||||
{
|
||||
struct ifnet *ifp;
|
||||
struct tun_softc *tp;
|
||||
register int unit, error;
|
||||
register int error;
|
||||
|
||||
error = suser(p);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
if ((unit = dev_val(minor(dev))) >= NTUN)
|
||||
return (ENXIO);
|
||||
tp = &tunctl[unit];
|
||||
tp = dev->si_drv1;
|
||||
if (!tp) {
|
||||
tuncreate(dev);
|
||||
tp = dev->si_drv1;
|
||||
}
|
||||
if (tp->tun_flags & TUN_OPEN)
|
||||
return EBUSY;
|
||||
tp->tun_pid = p->p_pid;
|
||||
@ -191,11 +185,14 @@ tunclose(dev, foo, bar, p)
|
||||
int bar;
|
||||
struct proc *p;
|
||||
{
|
||||
register int unit = dev_val(minor(dev)), s;
|
||||
struct tun_softc *tp = &tunctl[unit];
|
||||
struct ifnet *ifp = &tp->tun_if;
|
||||
register int s;
|
||||
struct tun_softc *tp;
|
||||
struct ifnet *ifp;
|
||||
struct mbuf *m;
|
||||
|
||||
tp = dev->si_drv1;
|
||||
ifp = &tp->tun_if;
|
||||
|
||||
tp->tun_flags &= ~TUN_OPEN;
|
||||
tp->tun_pid = 0;
|
||||
|
||||
@ -238,11 +235,10 @@ tunclose(dev, foo, bar, p)
|
||||
}
|
||||
|
||||
static int
|
||||
tuninit(unit)
|
||||
int unit;
|
||||
tuninit(ifp)
|
||||
struct ifnet *ifp;
|
||||
{
|
||||
struct tun_softc *tp = &tunctl[unit];
|
||||
struct ifnet *ifp = &tp->tun_if;
|
||||
struct tun_softc *tp = ifp->if_softc;
|
||||
register struct ifaddr *ifa;
|
||||
|
||||
TUNDEBUG("%s%d: tuninit\n", ifp->if_name, ifp->if_unit);
|
||||
@ -279,7 +275,7 @@ tunifioctl(ifp, cmd, data)
|
||||
caddr_t data;
|
||||
{
|
||||
struct ifreq *ifr = (struct ifreq *)data;
|
||||
struct tun_softc *tp = &tunctl[ifp->if_unit];
|
||||
struct tun_softc *tp = ifp->if_softc;
|
||||
struct ifstat *ifs;
|
||||
int error = 0, s;
|
||||
|
||||
@ -292,12 +288,12 @@ tunifioctl(ifp, cmd, data)
|
||||
"\tOpened by PID %d\n", tp->tun_pid);
|
||||
return(0);
|
||||
case SIOCSIFADDR:
|
||||
tuninit(ifp->if_unit);
|
||||
tuninit(ifp);
|
||||
TUNDEBUG("%s%d: address set\n",
|
||||
ifp->if_name, ifp->if_unit);
|
||||
break;
|
||||
case SIOCSIFDSTADDR:
|
||||
tuninit(ifp->if_unit);
|
||||
tuninit(ifp);
|
||||
TUNDEBUG("%s%d: destination address set\n",
|
||||
ifp->if_name, ifp->if_unit);
|
||||
break;
|
||||
@ -328,7 +324,7 @@ tunoutput(ifp, m0, dst, rt)
|
||||
struct sockaddr *dst;
|
||||
struct rtentry *rt;
|
||||
{
|
||||
struct tun_softc *tp = &tunctl[ifp->if_unit];
|
||||
struct tun_softc *tp = ifp->if_softc;
|
||||
int s;
|
||||
|
||||
TUNDEBUG ("%s%d: tunoutput\n", ifp->if_name, ifp->if_unit);
|
||||
@ -428,8 +424,8 @@ tunioctl(dev, cmd, data, flag, p)
|
||||
int flag;
|
||||
struct proc *p;
|
||||
{
|
||||
int unit = dev_val(minor(dev)), s;
|
||||
struct tun_softc *tp = &tunctl[unit];
|
||||
int s;
|
||||
struct tun_softc *tp = dev->si_drv1;
|
||||
struct tuninfo *tunp;
|
||||
|
||||
switch (cmd) {
|
||||
@ -527,8 +523,7 @@ tunread(dev, uio, flag)
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
int unit = dev_val(minor(dev));
|
||||
struct tun_softc *tp = &tunctl[unit];
|
||||
struct tun_softc *tp = dev->si_drv1;
|
||||
struct ifnet *ifp = &tp->tun_if;
|
||||
struct mbuf *m, *m0;
|
||||
int error=0, len, s;
|
||||
@ -585,8 +580,8 @@ tunwrite(dev, uio, flag)
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
int unit = dev_val(minor(dev));
|
||||
struct ifnet *ifp = &tunctl[unit].tun_if;
|
||||
struct tun_softc *tp = dev->si_drv1;
|
||||
struct ifnet *ifp = &tp->tun_if;
|
||||
struct mbuf *top, **mp, *m;
|
||||
int error=0, s, tlen, mlen;
|
||||
|
||||
@ -682,8 +677,8 @@ tunpoll(dev, events, p)
|
||||
int events;
|
||||
struct proc *p;
|
||||
{
|
||||
int unit = dev_val(minor(dev)), s;
|
||||
struct tun_softc *tp = &tunctl[unit];
|
||||
int s;
|
||||
struct tun_softc *tp = dev->si_drv1;
|
||||
struct ifnet *ifp = &tp->tun_if;
|
||||
int revents = 0;
|
||||
|
||||
@ -707,6 +702,3 @@ tunpoll(dev, events, p)
|
||||
splx(s);
|
||||
return (revents);
|
||||
}
|
||||
|
||||
|
||||
#endif /* NTUN */
|
||||
|
@ -11,7 +11,7 @@
|
||||
# device lines is present in the ./LINT configuration file. If you are
|
||||
# in doubt as to the purpose or necessity of a line, check first in LINT.
|
||||
#
|
||||
# $Id: GENERIC98,v 1.82 1999/08/08 19:28:59 phk Exp $
|
||||
# $Id: GENERIC98,v 1.83 1999/08/15 09:38:21 phk Exp $
|
||||
|
||||
# GENERIC98 -- Generic PC98 machine with WD/SCSI disks
|
||||
|
||||
@ -247,7 +247,7 @@ pseudo-device loop
|
||||
pseudo-device ether
|
||||
pseudo-device sl 1
|
||||
pseudo-device ppp 1
|
||||
pseudo-device tun 1
|
||||
pseudo-device tun
|
||||
pseudo-device pty
|
||||
pseudo-device gzip # Exec gzipped a.out's
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
# device lines is present in the ./LINT configuration file. If you are
|
||||
# in doubt as to the purpose or necessity of a line, check first in LINT.
|
||||
#
|
||||
# $Id: GENERIC98,v 1.82 1999/08/08 19:28:59 phk Exp $
|
||||
# $Id: GENERIC98,v 1.83 1999/08/15 09:38:21 phk Exp $
|
||||
|
||||
# GENERIC98 -- Generic PC98 machine with WD/SCSI disks
|
||||
|
||||
@ -247,7 +247,7 @@ pseudo-device loop
|
||||
pseudo-device ether
|
||||
pseudo-device sl 1
|
||||
pseudo-device ppp 1
|
||||
pseudo-device tun 1
|
||||
pseudo-device tun
|
||||
pseudo-device pty
|
||||
pseudo-device gzip # Exec gzipped a.out's
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user