vmx: allow setting mac address of using ea:nnnnnnnnnnnn! prefix, use genrandom() to generate mac globally unique mac address
This commit is contained in:
parent
6728a5ec23
commit
8a01033efc
3 changed files with 17 additions and 5 deletions
|
@ -100,6 +100,8 @@ Alternatively, a dial string such as \fLudp!\fIhost\fL!\fIport\fR can be used.
|
||||||
It can also be prefixed by \fLfile!\fR to interpret the argument as a file instead and it can be prefixed by \fLhdr!\fR to enable headers matching the binary
|
It can also be prefixed by \fLfile!\fR to interpret the argument as a file instead and it can be prefixed by \fLhdr!\fR to enable headers matching the binary
|
||||||
.IR snoopy (8)
|
.IR snoopy (8)
|
||||||
format.
|
format.
|
||||||
|
The MAC address can be specified with the \fLea:\fInnnnnnnnnnnn\fL!\fR prefix,
|
||||||
|
otherwise a random address is used.
|
||||||
.PP
|
.PP
|
||||||
A
|
A
|
||||||
.B -d
|
.B -d
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
#include "dat.h"
|
#include "dat.h"
|
||||||
#include "fns.h"
|
#include "fns.h"
|
||||||
|
|
||||||
|
#include <ip.h> /* parseether() */
|
||||||
|
#include <libsec.h> /* genrandom() */
|
||||||
|
|
||||||
typedef struct VIODev VIODev;
|
typedef struct VIODev VIODev;
|
||||||
typedef struct VIOQueue VIOQueue;
|
typedef struct VIOQueue VIOQueue;
|
||||||
typedef struct VIOBuf VIOBuf;
|
typedef struct VIOBuf VIOBuf;
|
||||||
|
@ -633,10 +636,11 @@ mkvionet(char *net)
|
||||||
{
|
{
|
||||||
int fd, cfd;
|
int fd, cfd;
|
||||||
VIODev *d;
|
VIODev *d;
|
||||||
int i;
|
char *ea;
|
||||||
int flags;
|
int flags;
|
||||||
enum { VNETFILE = 1 };
|
enum { VNETFILE = 1 };
|
||||||
|
|
||||||
|
ea = nil;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
for(;;){
|
for(;;){
|
||||||
if(strncmp(net, "hdr!", 4) == 0){
|
if(strncmp(net, "hdr!", 4) == 0){
|
||||||
|
@ -645,6 +649,12 @@ mkvionet(char *net)
|
||||||
}else if(strncmp(net, "file!", 5) == 0){
|
}else if(strncmp(net, "file!", 5) == 0){
|
||||||
net += 5;
|
net += 5;
|
||||||
flags |= VNETFILE;
|
flags |= VNETFILE;
|
||||||
|
}else if(strncmp(net, "ea:", 3) == 0){
|
||||||
|
net = strchr(ea = net+3, '!');
|
||||||
|
if(net++ == nil){
|
||||||
|
werrstr("missing: !");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}else
|
}else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -665,9 +675,10 @@ mkvionet(char *net)
|
||||||
mkvioqueue(d, 1024, viowakeup);
|
mkvioqueue(d, 1024, viowakeup);
|
||||||
mkvioqueue(d, 1024, viowakeup);
|
mkvioqueue(d, 1024, viowakeup);
|
||||||
mkvioqueue(d, 32, vionetcmd);
|
mkvioqueue(d, 32, vionetcmd);
|
||||||
for(i = 0; i < 6; i++)
|
if(ea == nil || parseether(d->net.mac, ea)){
|
||||||
d->net.mac[i] = rand();
|
genrandom(d->net.mac, 6);
|
||||||
d->net.mac[0] = d->net.mac[0] & ~1 | 2;
|
d->net.mac[0] = d->net.mac[0] & ~1 | 2;
|
||||||
|
}
|
||||||
d->net.flags = flags;
|
d->net.flags = flags;
|
||||||
d->devfeat = 1<<5|1<<16|1<<17|1<<18|1<<20;
|
d->devfeat = 1<<5|1<<16|1<<17|1<<18|1<<20;
|
||||||
d->io = vionetio;
|
d->io = vionetio;
|
||||||
|
|
|
@ -87,7 +87,6 @@ vmxsetup(void)
|
||||||
rc = read(ctlfd, name, sizeof(name) - 1);
|
rc = read(ctlfd, name, sizeof(name) - 1);
|
||||||
if(rc < 0) sysfatal("read: %r");
|
if(rc < 0) sysfatal("read: %r");
|
||||||
name[rc] = 0;
|
name[rc] = 0;
|
||||||
srand(atoi(name));
|
|
||||||
if(segname == nil){
|
if(segname == nil){
|
||||||
segname = smprint("vm.%s", name);
|
segname = smprint("vm.%s", name);
|
||||||
segrclose = ORCLOSE;
|
segrclose = ORCLOSE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue