changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: vmx: allow setting mac address of using ea:nnnnnnnnnnnn! prefix, use genrandom() to generate mac globally unique mac address

changeset 6380: 3509dbfef951
parent 6379: 449fb7d19e25
tag:tip
author: cinap_lenrek@felloff.net
date: Sun, 25 Feb 2018 21:11:41 +0100
files: sys/man/1/vmx sys/src/cmd/vmx/virtio.c sys/src/cmd/vmx/vmx.c
description: vmx: allow setting mac address of using ea:nnnnnnnnnnnn! prefix, use genrandom() to generate mac globally unique mac address
     1.1--- a/sys/man/1/vmx
     1.2+++ b/sys/man/1/vmx
     1.3@@ -100,6 +100,8 @@ Alternatively, a dial string such as \fL
     1.4 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
     1.5 .IR snoopy (8)
     1.6 format.
     1.7+The MAC address can be specified with the \fLea:\fInnnnnnnnnnnn\fL!\fR prefix,
     1.8+otherwise a random address is used.
     1.9 .PP
    1.10 A
    1.11 .B -d
     2.1--- a/sys/src/cmd/vmx/virtio.c
     2.2+++ b/sys/src/cmd/vmx/virtio.c
     2.3@@ -4,6 +4,9 @@
     2.4 #include "dat.h"
     2.5 #include "fns.h"
     2.6 
     2.7+#include <ip.h>		/* parseether() */
     2.8+#include <libsec.h>	/* genrandom() */
     2.9+
    2.10 typedef struct VIODev VIODev;
    2.11 typedef struct VIOQueue VIOQueue;
    2.12 typedef struct VIOBuf VIOBuf;
    2.13@@ -633,10 +636,11 @@ mkvionet(char *net)
    2.14 {
    2.15 	int fd, cfd;
    2.16 	VIODev *d;
    2.17-	int i;
    2.18+	char *ea;
    2.19 	int flags;
    2.20 	enum { VNETFILE = 1 };
    2.21 
    2.22+	ea = nil;
    2.23 	flags = 0;
    2.24 	for(;;){
    2.25 		if(strncmp(net, "hdr!", 4) == 0){
    2.26@@ -645,6 +649,12 @@ mkvionet(char *net)
    2.27 		}else if(strncmp(net, "file!", 5) == 0){
    2.28 			net += 5;
    2.29 			flags |= VNETFILE;
    2.30+		}else if(strncmp(net, "ea:", 3) == 0){
    2.31+			net = strchr(ea = net+3, '!');
    2.32+			if(net++ == nil){
    2.33+				werrstr("missing: !");
    2.34+				return -1;
    2.35+			}
    2.36 		}else
    2.37 			break;
    2.38 	}
    2.39@@ -665,9 +675,10 @@ mkvionet(char *net)
    2.40 	mkvioqueue(d, 1024, viowakeup);
    2.41 	mkvioqueue(d, 1024, viowakeup);
    2.42 	mkvioqueue(d, 32, vionetcmd);
    2.43-	for(i = 0; i < 6; i++)
    2.44-		d->net.mac[i] = rand();
    2.45-	d->net.mac[0] = d->net.mac[0] & ~1 | 2;
    2.46+	if(ea == nil || parseether(d->net.mac, ea)){
    2.47+		genrandom(d->net.mac, 6);
    2.48+		d->net.mac[0] = d->net.mac[0] & ~1 | 2;
    2.49+	}
    2.50 	d->net.flags = flags;
    2.51 	d->devfeat = 1<<5|1<<16|1<<17|1<<18|1<<20;
    2.52 	d->io = vionetio;
     3.1--- a/sys/src/cmd/vmx/vmx.c
     3.2+++ b/sys/src/cmd/vmx/vmx.c
     3.3@@ -87,7 +87,6 @@ vmxsetup(void)
     3.4 	rc = read(ctlfd, name, sizeof(name) - 1);
     3.5 	if(rc < 0) sysfatal("read: %r");
     3.6 	name[rc] = 0;
     3.7-	srand(atoi(name));
     3.8 	if(segname == nil){
     3.9 		segname = smprint("vm.%s", name);
    3.10 		segrclose = ORCLOSE;