vx32

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

commit 22f9c849f452516af8e9af87ef48461002501fc3
parent 7792c92a37520a1624fcbc3c715ecc92a8f8859f
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date:   Tue, 15 Jun 2010 20:31:40 +0200

parse multiple netdev options

Diffstat:
src/9vx/main.c | 66++++++++++++++++++++++++++++++++++++------------------------------
src/9vx/vether.c | 6+++---
src/9vx/vether.h | 9+++++++--
3 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/src/9vx/main.c b/src/9vx/main.c @@ -27,6 +27,10 @@ #include "fs.h" +#include "netif.h" +#include "etherif.h" +#include "vether.h" + #define Image IMAGE #include "draw.h" #include "memdraw.h" @@ -59,7 +63,6 @@ static int bootboot; /* run /boot/boot instead of bootscript */ static int initrc; /* run rc instead of init */ static int nogui; /* do not start the gui */ static int usetty; /* use tty for input/output */ -static int vether; /* use virtual ethernet device */ static char* username; static Mach mach0; @@ -97,6 +100,8 @@ int main(int argc, char **argv) { int nofork; + int vetap; + char *vedev; char buf[1024]; /* Minimal set up to make print work. */ @@ -107,6 +112,7 @@ main(int argc, char **argv) nogui = 0; nofork = 0; usetty = 0; + nve = 0; localroot = nil; ARGBEGIN{ /* debugging options */ @@ -155,22 +161,22 @@ main(int argc, char **argv) case 'p': inifile = EARGF(usage()); break; + case 'm': + setea(EARGF(usage())); + break; case 'n': - vether = 1; - netdev = ARGF(); - if(strcmp(netdev, "tap") == 0){ - nettap = 1; - netdev = ARGF(); + vetap = 0; + vedev = ARGF(); + if(vedev != nil && strcmp(vedev, "tap") == 0){ + vetap = 1; + vedev = ARGF(); } - if(netdev != 0 && netdev[0] == '-'){ - netdev = nil; + if(vedev != nil && vedev[0] == '-'){ + vedev = nil; argc++; *argv--; } - break; - case 'm': - vether = 1; - macaddr = EARGF(usage()); + addve(vedev, vetap); break; case 'r': localroot = EARGF(usage()); @@ -241,28 +247,27 @@ main(int argc, char **argv) if(bootboot | nogui | initrc | usetty) print("-%s%s%s%s ", bootboot ? "b" : "", nogui ? "g" : "", initrc ? "i " : "", usetty ? "t " : ""); - if(vether) - print("-n "); - if(nettap) - print("tap "); - if(netdev) - print("%s ", netdev); - if(macaddr) - print("-m %s ", macaddr); + for(int i=0; i<nve; i++){ + print("-n %s", ve[i].tap ? "tap ": ""); + if(ve[i].dev != nil) + print("%s ", ve[i].dev); + if(ve[i].mac != nil) + print("-m %s ", ve[i].mac); + } print("-r %s -u %s\n", localroot, username); - if(!vether) + if(nve == 0) ipdevtab = pipdevtab; printinit(); procinit0(); initseg(); - if(vether) + if(nve > 0) links(); chandevreset(); if(!singlethread){ - if(!netdev) + if(nve == 0) makekprocdev(&ipdevtab); makekprocdev(&fsdevtab); makekprocdev(&drawdevtab); @@ -381,6 +386,9 @@ inifields(void (*fp)(char*, char*)) void iniopt(char *name, char *value) { + char *vedev; + int vetap; + if(*name == '*') name++; if(strcmp(name, "bootboot") == 0) @@ -393,17 +401,15 @@ iniopt(char *name, char *value) username = value; else if(strcmp(name, "usetty") == 0) usetty = 1; + else if(strcmp(name, "macaddr") == 0 && !macaddr) + setea(value); else if(strcmp(name, "netdev") == 0 && !netdev){ - vether = 1; if(strncmp(value, "tap", 3) == 0) { - nettap = 1; + vetap = 1; value += 4; } - netdev = value; - } - else if(strcmp(name, "macaddr") == 0 && !macaddr){ - vether = 1; - macaddr = value; + vedev = value; + addve(vedev, vetap); } else if(strcmp(name, "nogui") == 0){ nogui = 1; diff --git a/src/9vx/vether.c b/src/9vx/vether.c @@ -38,6 +38,7 @@ setea(char *macaddr) if(nve == 0) return; + ve[nve-1].mac = macaddr; for(i = 0; i < Eaddrlen; i++){ ve[nve-1].ea[i] = (uchar)strtoul(macaddr, nc, 16); macaddr = *nc+1; @@ -47,14 +48,13 @@ setea(char *macaddr) void addve(char *dev, int tap) { - int i; - static uchar ea[Eaddrlen] = {0x00, 0x00, 0x09, 0x00, 0x00, 0x00}; if(nve == MaxEther) panic("too many virtual ether cards"); - ve[nve].dev = dev; ve[nve].tap = tap; + ve[nve].dev = dev; + ve[nve].mac = nil; /* This ea could conflict with one given by the user */ memcpy(ve[nve].ea, ea, Eaddrlen); ea[5]++; diff --git a/src/9vx/vether.h b/src/9vx/vether.h @@ -3,8 +3,13 @@ struct Vether { int tap; char *dev; + char *mac; uchar ea[Eaddrlen]; }; -static Vether ve[MaxEther+1]; -static int nve = 0; +Vether ve[MaxEther+1]; +int nve; + +void setea(char*); +void addve(char*, int); +void links();