vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

commit 276b9e1da20f8ceed000776eef0868b95cf01e8f
parent 6826d61737fa8943adbfd7c60be0b19fbf37a4be
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date:   Sat,  5 Jun 2010 15:50:44 +0200

ugly option to use the tap device

Diffstat:
src/9vx/Makefrag | 1+
src/9vx/devtabve.c | 7++++++-
src/9vx/ethertap.c | 34++++++++++++++++------------------
src/9vx/main.c | 12++++++++++--
4 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/src/9vx/Makefrag b/src/9vx/Makefrag @@ -115,6 +115,7 @@ PLAN9_IP_OBJS = \ devip.o \ devip-posix.o \ devtabve.o \ + ethertap.o \ etherve.o \ ) \ $(addprefix 9vx/a/,\ diff --git a/src/9vx/devtabve.c b/src/9vx/devtabve.c @@ -57,6 +57,8 @@ Dev *devtab[] = { 0 }; +extern int nettap; +extern void ethertaplink(void); extern void ethervelink(void); extern void ethermediumlink(void); extern void loopbackmediumlink(void); @@ -65,7 +67,10 @@ void links(void) { ethermediumlink(); loopbackmediumlink(); netdevmediumlink(); - ethervelink(); + if(nettap) + ethertaplink(); + else + ethervelink(); } extern void ilinit(Fs*); diff --git a/src/9vx/ethertap.c b/src/9vx/ethertap.c @@ -24,7 +24,6 @@ #include "a/etherif.h" -extern char *vxhostdev; static uchar anyea[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff,}; typedef struct Ctlr Ctlr; @@ -40,7 +39,6 @@ setup(char *dev) { int fd; struct ifreq ifr; - struct sockaddr_ll sa; if((fd = open("/dev/net/tun", O_RDWR)) < 0) return -1; @@ -58,7 +56,7 @@ setup(char *dev) } Block* -rspkt(Ctlr *c) +tappkt(Ctlr *c) { int n; Block *b; @@ -79,19 +77,19 @@ rspkt(Ctlr *c) } static void -rsrecvkproc(void *v) +taprecvkproc(void *v) { Block *b; Ether *e; e = v; - while(b = rspkt(e->ctlr)) + while((b = tappkt(e->ctlr))) etheriq(e, b, 1); pexit("read fail", 1); } static void -rstransmit(Ether* e) +taptransmit(Ether* e) { Block *b, *h; Ctlr *c; @@ -113,7 +111,7 @@ rstransmit(Ether* e) } static long -rsifstat(Ether *e, void *a, long n, ulong offset) +tapifstat(Ether *e, void *a, long n, ulong offset) { char buf[128]; Ctlr *c; @@ -124,21 +122,21 @@ rsifstat(Ether *e, void *a, long n, ulong offset) } static void -rsattach(Ether* e) +tapattach(Ether* e) { - kproc("rsrecv", rsrecvkproc, e); + kproc("taprecv", taprecvkproc, e); } static uchar eatab[] = { 0x00, 0x48, 0x01, 0x23, 0x45, 0x60, }; -static char *rsdevtab[] = { +static char *tapdevtab[] = { "tap0", }; static int -rspnp(Ether* e) +tappnp(Ether* e) { uchar *ea; Ctlr c; @@ -148,26 +146,26 @@ rspnp(Ether* e) return -1; ea = eatab + Eaddrlen*nctlr; memset(&c, 0, sizeof c); - c.fd = setup(rsdevtab[nctlr++]); + c.fd = setup(tapdevtab[nctlr++]); memcpy(c.ea, ea, Eaddrlen); if(c.fd== -1){ - print("rs: failed to initialize\n"); + print("tap: failed to initialize\n"); return -1; } e->ctlr = malloc(sizeof c); memcpy(e->ctlr, &c, sizeof c); e->tbdf = BUSUNKNOWN; memcpy(e->ea, ea, Eaddrlen); - e->attach = rsattach; - e->transmit = rstransmit; - e->ifstat = rsifstat; + e->attach = tapattach; + e->transmit = taptransmit; + e->ifstat = tapifstat; e->ni.arg = e; e->ni.link = 1; return 0; } void -ethervelink(void) +ethertaplink(void) { - addethercard("rs", rspnp); + addethercard("tap", tappnp); } diff --git a/src/9vx/main.c b/src/9vx/main.c @@ -49,6 +49,7 @@ char* argv0; char* conffile = "9vx"; char* macaddr; char* netdev; +int nettap; Conf conf; static char* inifile; @@ -83,7 +84,7 @@ void usage(void) { // TODO(yy): add debug and other options by ron - fprint(2, "usage: 9vx [-p file.ini] [-bgit] [-n [netdev]] [-m macaddr] [-r root] [-u user]\n"); + fprint(2, "usage: 9vx [-p file.ini] [-bgit] [-n [tap] [netdev]] [-m macaddr] [-r root] [-u user]\n"); exit(1); } @@ -157,6 +158,10 @@ main(int argc, char **argv) case 'n': vether = 1; netdev = ARGF(); + if(strcmp(netdev, "tap") == 0){ + nettap = 1; + netdev = ARGF(); + } break; case 'm': vether = 1; @@ -233,8 +238,11 @@ main(int argc, char **argv) initrc ? "i " : "", usetty ? "t " : ""); if(vether) print("-n "); - if(netdev) + if(netdev){ + if(nettap) + print("tap "); print("%s ", netdev); + } if(macaddr) print("-m %s ", macaddr); print("-r %s -u %s\n", localroot, username);