commit b69a103ddcedfd1c4e402bc80b190a8aa7f75109
parent ee92f26347883de1a80c99b4b86ebe53ac0f541c
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date: Wed, 16 Jun 2010 07:57:02 +0200
check that mac address is not already used
Diffstat:
3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/9vx/main.c b/src/9vx/main.c
@@ -159,7 +159,7 @@ main(int argc, char **argv)
inifile = EARGF(usage());
break;
case 'm':
- setea(EARGF(usage()));
+ setmac(EARGF(usage()));
break;
case 'n':
vetap = 0;
@@ -401,7 +401,7 @@ iniopt(char *name, char *value)
else if(strcmp(name, "usetty") == 0)
usetty = 1;
else if(strcmp(name, "macaddr") == 0)
- setea(value);
+ setmac(value);
else if(strcmp(name, "netdev") == 0){
if(strncmp(value, "tap", 3) == 0) {
vetap = 1;
diff --git a/src/9vx/vether.c b/src/9vx/vether.c
@@ -31,7 +31,7 @@ extern SDifc sdloopifc;
extern SDifc sdaoeifc;
void
-setea(char *macaddr)
+setmac(char *macaddr)
{
int i;
char **nc = &macaddr;
@@ -45,31 +45,45 @@ setea(char *macaddr)
}
}
+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)
{
- static uchar ea[Eaddrlen] = {0x00, 0x00, 0x09, 0x00, 0x00, 0x00};
-
if(nve == MaxEther)
panic("too many virtual ether cards");
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]++;
nve++;
}
void links(void) {
+ static uchar ea[Eaddrlen] = {0x00, 0x00, 0x09, 0x00, 0x00, 0x00};
+
ethermediumlink();
loopbackmediumlink();
netdevmediumlink();
- for(int i=0; i<nve; i++)
+ for(int i=0; i<nve; i++){
+ if(ve[i].mac == nil){
+ while(eainuse(i, ea))
+ ea[5]++;
+ memcpy(ve[i].ea, ea, Eaddrlen);
+ }
if(ve[i].tap == 1)
ethertaplink();
else
etherpcaplink();
+ }
}
void (*ipprotoinit[])(Fs*) = {
diff --git a/src/9vx/vether.h b/src/9vx/vether.h
@@ -10,6 +10,6 @@ struct Vether
Vether ve[MaxEther+1];
int nve;
-void setea(char*);
+void setmac(char*);
void addve(char*, int);
void links();