diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2018-02-25 21:11:41 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2018-02-25 21:11:41 +0100 |
commit | 8a01033efcdc72f8b63b5a7afcc699ca20edfdc0 (patch) | |
tree | adfd852667a975d673c149c7c48197ed455ccd81 | |
parent | 6728a5ec2351cac7cc27333e0d984c5c2b029b87 (diff) | |
download | plan9front-8a01033efcdc72f8b63b5a7afcc699ca20edfdc0.tar.xz |
vmx: allow setting mac address of using ea:nnnnnnnnnnnn! prefix, use genrandom() to generate mac globally unique mac address
-rw-r--r-- | sys/man/1/vmx | 2 | ||||
-rw-r--r-- | sys/src/cmd/vmx/virtio.c | 19 | ||||
-rw-r--r-- | sys/src/cmd/vmx/vmx.c | 1 |
3 files changed, 17 insertions, 5 deletions
diff --git a/sys/man/1/vmx b/sys/man/1/vmx index 9f8b8ac57..656a114cf 100644 --- a/sys/man/1/vmx +++ b/sys/man/1/vmx @@ -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 .IR snoopy (8) format. +The MAC address can be specified with the \fLea:\fInnnnnnnnnnnn\fL!\fR prefix, +otherwise a random address is used. .PP A .B -d diff --git a/sys/src/cmd/vmx/virtio.c b/sys/src/cmd/vmx/virtio.c index 1dd1b5537..4e18fa7bd 100644 --- a/sys/src/cmd/vmx/virtio.c +++ b/sys/src/cmd/vmx/virtio.c @@ -4,6 +4,9 @@ #include "dat.h" #include "fns.h" +#include <ip.h> /* parseether() */ +#include <libsec.h> /* genrandom() */ + typedef struct VIODev VIODev; typedef struct VIOQueue VIOQueue; typedef struct VIOBuf VIOBuf; @@ -633,10 +636,11 @@ mkvionet(char *net) { int fd, cfd; VIODev *d; - int i; + char *ea; int flags; enum { VNETFILE = 1 }; + ea = nil; flags = 0; for(;;){ if(strncmp(net, "hdr!", 4) == 0){ @@ -645,6 +649,12 @@ mkvionet(char *net) }else if(strncmp(net, "file!", 5) == 0){ net += 5; flags |= VNETFILE; + }else if(strncmp(net, "ea:", 3) == 0){ + net = strchr(ea = net+3, '!'); + if(net++ == nil){ + werrstr("missing: !"); + return -1; + } }else break; } @@ -665,9 +675,10 @@ mkvionet(char *net) mkvioqueue(d, 1024, viowakeup); mkvioqueue(d, 1024, viowakeup); mkvioqueue(d, 32, vionetcmd); - for(i = 0; i < 6; i++) - d->net.mac[i] = rand(); - d->net.mac[0] = d->net.mac[0] & ~1 | 2; + if(ea == nil || parseether(d->net.mac, ea)){ + genrandom(d->net.mac, 6); + d->net.mac[0] = d->net.mac[0] & ~1 | 2; + } d->net.flags = flags; d->devfeat = 1<<5|1<<16|1<<17|1<<18|1<<20; d->io = vionetio; diff --git a/sys/src/cmd/vmx/vmx.c b/sys/src/cmd/vmx/vmx.c index aeeeb9676..c4484966e 100644 --- a/sys/src/cmd/vmx/vmx.c +++ b/sys/src/cmd/vmx/vmx.c @@ -87,7 +87,6 @@ vmxsetup(void) rc = read(ctlfd, name, sizeof(name) - 1); if(rc < 0) sysfatal("read: %r"); name[rc] = 0; - srand(atoi(name)); if(segname == nil){ segname = smprint("vm.%s", name); segrclose = ORCLOSE; |