ini: ether values - vx32 - Local 9vx git repository for patches.
 (HTM) git clone git://r-36.net/vx32
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit 63886a0f0e4e2e423f7b544275543cf6bbef5a55
 (DIR) parent 91f17a2007af56e7a849bc5ea5f6f2d06c9f5185
 (HTM) Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
       Date:   Mon, 27 Sep 2010 23:15:31 +0200
       
       ini: ether values
       
       Diffstat:
         M src/9vx/Makefrag                    |       2 +-
         M src/9vx/conf.c                      |      55 +++++++++++++++++++++++++++----
         M src/9vx/main.c                      |      37 +++++++++++++++----------------
         M src/9vx/vether.c                    |      63 ++-----------------------------
         M src/9vx/vether.h                    |       3 ---
       
       5 files changed, 71 insertions(+), 89 deletions(-)
       ---
 (DIR) diff --git a/src/9vx/Makefrag b/src/9vx/Makefrag
       @@ -26,7 +26,7 @@ endif
        #PLAN9GUI=nogui
        
        # Virtual ethernet devices
       -#PLAN9PCAP=etherpcap
       +PLAN9PCAP=etherpcap
        #PLAN9PCAP=nopcap
        #PLAN9TAP=ethertap
        #PLAN9TAP=notap
 (DIR) diff --git a/src/9vx/conf.c b/src/9vx/conf.c
       @@ -14,6 +14,48 @@
        
        char        filebuf[BOOTARGSLEN];
        
       +static void
       +addether(char *name, char *value)
       +{
       +        char *p;
       +        int ctlrno;
       +
       +        ctlrno = atoi(&name[5]);
       +        if(ctlrno > MaxEther)
       +                return;
       +        p = value;
       +        while(*p){
       +                while(*p == ' ' || *p == '\t')
       +                        p++;
       +                if(*p == '\0')
       +                        break;
       +                if(strncmp(p, "type=", 5) == 0){
       +                        p += 5;
       +                        if(strncmp(p, "tap", 3) == 0)
       +                                ve[ctlrno].tap = 1;
       +                        else if(strncmp(p, "pcap", 4) == 0)
       +                                ve[ctlrno].tap = 0;
       +                        else
       +                                return;
       +                }
       +                else if(strncmp(p, "dev=", 4) == 0){
       +                        p += 4;
       +                        ve[ctlrno].dev = p;
       +                        while(*p && *p != ' ' && *p != '\t')
       +                                p++;
       +                        *p++ = '\0';
       +                        continue;
       +                }
       +                else if(strncmp(p, "ea=", 3) == 0){
       +                        if(parseether(ve[ctlrno].ea, p+3) == -1)
       +                                memset(ve[ctlrno].ea, 0, 6);
       +                }
       +                while(*p && *p != ' ' && *p != '\t')
       +                        p++;
       +        }
       +        nve++;
       +}
       +
        void
        setinioptions()
        {
       @@ -36,15 +78,15 @@ setinioptions()
                                memsize = atoi(value);
                        else if(strcmp(name, "canopenfiles") == 0)
                                canopen = value;
       -                else if(strcmp(name, "ether") == 0)
       -                        //addether(name, value);
       -                        value = value;
       +                else if(strncmp(name, "ether", 5) == 0)
       +                        addether(name, value);
                        else if(strcmp(name, "initarg") == 0)
                                initarg = value;
                        else if(strcmp(name, "localroot") == 0)
                                localroot = value;
                        else if(strcmp(name, "user") == 0)
                                username = value;
       +                /* Restore '=' for setinienv and printconfig */
                        *(--value) = '=';
                }
        }
       @@ -108,8 +150,6 @@ addini(char *buf)
                        if(!incomment)
                                *p++ = *q;        
                }
       -        if(p > buf && p[-1] != '\n')
       -                *p++ = '\n';
                *p++ = 0;
        
                n += gettokens(buf, &inifield[n], MAXCONF-n, "\n");
       @@ -154,7 +194,9 @@ fullpath(char *root) {
                return root;
        }
        
       -/* poor man's quotestrdup to avoid needing quote.c */
       +/*
       + * Poor man's quotestrdup to avoid needing quote.c
       + */
        char*
        quoted(char *in) {
                char *out, *p;
       @@ -217,6 +259,7 @@ printconfig(char *argv0){
                print(argv0);
                if(usetty)
                        print(" -%c", nogui ? 'g' : 't');
       +        print(" \n");
                for(i = 0; i < MAXCONF; i++){
                        if(!inifield[i])
                                break;
 (DIR) diff --git a/src/9vx/main.c b/src/9vx/main.c
       @@ -82,7 +82,6 @@ nop(void)
        int
        main(int argc, char **argv)
        {
       -        int vetap;
                char *file;
        
                /* Minimal set up to make print work. */
       @@ -101,6 +100,7 @@ main(int argc, char **argv)
                nofork = 0;
                nve = 0;
                usetty = 0;
       +readargs:
                ARGBEGIN{
                /* debugging options */
                case '1':
       @@ -145,21 +145,8 @@ main(int argc, char **argv)
                case 't':
                        usetty = 1;
                        break;
       -        default:
       -                goto iniargs;
       -        }ARGEND
       -
       -iniargs:
       -        while(argc > 0 && argv[0][0] != '-'){
       -                addini(strdup(argv[0]));
       -                argc--; argv++;
       -        }
       -        /*
       -         * ARGBEGIN will do: argv++; argc--;
       -         * but argv[0] is not argv0 now
       -         */
       -        argc++; argv--;
       -        ARGBEGIN{
       +        
       +        /* ini values */
                case 'f':
                        file = EARGF(usage());
                        if(addinifile(file) < 0)
       @@ -167,7 +154,7 @@ iniargs:
                        break;
                case 'i':
                        /*
       -                 * Pass additional flag after -i is to init 
       +                 * Pass additional flag after -i to init 
                         * This is convenient for -ic and -im
                         */
                        if(_args[0] != 0){
       @@ -183,11 +170,23 @@ iniargs:
                case 'u':
                        username = EARGF(usage());
                        break;
       +
                default:
                        usage();
                }ARGEND
       -        if(argc > 0)
       -                goto iniargs;
       +
       +        while(argc > 0){
       +                if(argv[0][0] == '-'){
       +                        /*
       +                         * ARGBEGIN will do: argv++; argc--;
       +                         * to skip argv0, but argv[0] is not argv0 now
       +                         */
       +                        argc++; argv--;
       +                        goto readargs;
       +                }
       +                addini(strdup(argv[0]));
       +                argc--; argv++;
       +        }
        
                if(username == nil && (username = getuser()) == nil)
                        username = "tor";
 (DIR) diff --git a/src/9vx/vether.c b/src/9vx/vether.c
       @@ -30,55 +30,13 @@ extern void espinit(Fs*);
        extern SDifc sdloopifc;
        extern SDifc sdaoeifc;
        
       -void
       -setmac(char *macaddr)
       -{
       -        int i;
       -        char **nc = &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;
       -        }
       -}
       -
       -static int
       -eainuse(int n, uchar ea[Eaddrlen])
       -{
       -        int i;
       -
       -        for(i = 0; i < nve; i++)
       -                if((i<n || ve[i].mac != nil) && memcmp(ea, ve[i].ea, Eaddrlen) == 0)
       -                        return -1;
       -        return 0;
       -}
       -
       -void
       -addve(char *dev, int tap)
       -{
       -        if(nve == MaxEther)
       -                panic("too many virtual ether cards");
       -        ve[nve].tap = tap;
       -        ve[nve].dev = dev;
       -        ve[nve].mac = nil;
       -        nve++;
       -}
       -
        void links(void) {
       -        static uchar ea[Eaddrlen] = {0x00, 0x00, 0x09, 0x00, 0x00, 0x00};
       -
                ethermediumlink();
                loopbackmediumlink();
                netdevmediumlink();
       -        for(int i=0; i<nve; i++){
       -                if(ve[i].mac == nil){
       -                        while(eainuse(i, ea))
       -                                ea[5]++;
       -                        memcpy(ve[i].ea, ea, Eaddrlen);
       -                }
       +        for(int i=0; i<MaxEther; i++){
       +                if(ve[i].dev == nil)
       +                        continue;
                        if(ve[i].tap == 1)
                                ethertaplink();
                        else
       @@ -99,21 +57,6 @@ void (*ipprotoinit[])(Fs*) = {
                nil,
        };
        
       -int
       -eafrom(char *ma, uchar ea[6])
       -{
       -        int i;
       -        char **nc = &ma;
       -
       -        for(i = 0; i < 6; i++){
       -                if(!ma)
       -                        return -1;
       -                ea[i] = (uchar)strtoul(ma, nc, 16);
       -                ma = *nc+1;
       -        }
       -        return 0;
       -}
       -
        SDifc *sdifc[] =
        {
                &sdloopifc,
 (DIR) diff --git a/src/9vx/vether.h b/src/9vx/vether.h
       @@ -3,13 +3,10 @@ struct Vether
        {
                int        tap;
                char        *dev;
       -        char        *mac;
                uchar ea[Eaddrlen];
        };
        
        Vether ve[MaxEther+1];
        int nve;
        
       -void        setmac(char*);
       -void        addve(char*, int);
        void        links();