From c6bf5fcad6bbb2bb9023180199a771752bde64ff Mon Sep 17 00:00:00 2001 From: Dale Hamel Date: Sun, 6 Dec 2015 10:16:23 -0500 Subject: [PATCH] Add option to print MAC address and exit --- include/xhyve/xhyve.h | 1 + src/pci_virtio_net_vmnet.c | 8 ++++++++ src/xhyve.c | 10 ++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/xhyve/xhyve.h b/include/xhyve/xhyve.h index 4f85664..5464b2e 100644 --- a/include/xhyve/xhyve.h +++ b/include/xhyve/xhyve.h @@ -41,6 +41,7 @@ #define VMEXIT_ABORT (-1) extern int guest_ncpus; +extern int print_mac; extern char *guest_uuid_str; extern char *vmname; diff --git a/src/pci_virtio_net_vmnet.c b/src/pci_virtio_net_vmnet.c index a309cb1..b2620d7 100644 --- a/src/pci_virtio_net_vmnet.c +++ b/src/pci_virtio_net_vmnet.c @@ -722,6 +722,14 @@ pci_vtnet_init(struct pci_devinst *pi, UNUSED char *opts) return (-1); } + if (print_mac == 1) + { + printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", + sc->vms->mac[0], sc->vms->mac[1], sc->vms->mac[2], + sc->vms->mac[3], sc->vms->mac[4], sc->vms->mac[5]); + exit(0); + } + sc->vsc_config.mac[0] = sc->vms->mac[0]; sc->vsc_config.mac[1] = sc->vms->mac[1]; sc->vsc_config.mac[2] = sc->vms->mac[2]; diff --git a/src/xhyve.c b/src/xhyve.c index 97fd41f..d49a6a3 100644 --- a/src/xhyve.c +++ b/src/xhyve.c @@ -78,6 +78,7 @@ extern int vmexit_task_switch(struct vm_exit *, int *vcpu); char *vmname = "vm"; int guest_ncpus; +int print_mac; char *guest_uuid_str; static int guest_vmexit_on_hlt, guest_vmexit_on_pause; @@ -124,7 +125,7 @@ usage(int code) { fprintf(stderr, - "Usage: %s [-behuwxACHPWY] [-c vcpus] [-g ] [-l ]\n" + "Usage: %s [-behuwxMACHPWY] [-c vcpus] [-g ] [-l ]\n" " %*s [-m mem] [-p vcpu:hostcpu] [-s ] [-U uuid] -f \n" " -A: create ACPI tables\n" " -c: # cpus (default 1)\n" @@ -136,6 +137,7 @@ usage(int code) " -H: vmexit from the guest on hlt\n" " -l: LPC device configuration\n" " -m: memory size in MB\n" + " -M: print MAC address and exit if using vmnet\n" " -p: pin 'vcpu' to 'hostcpu'\n" " -P: vmexit from the guest on pause\n" " -s: PCI slot config\n" @@ -787,12 +789,13 @@ main(int argc, char *argv[]) progname = basename(argv[0]); gdb_port = 0; guest_ncpus = 1; + print_mac = 0; memsize = 256 * MB; mptgen = 1; rtc_localtime = 1; fw = 0; - while ((c = getopt(argc, argv, "behvuwxACHPWY:f:g:c:s:m:l:U:")) != -1) { + while ((c = getopt(argc, argv, "behvuwxMACHPWY:f:g:c:s:m:l:U:")) != -1) { switch (c) { case 'A': acpi = 1; @@ -832,6 +835,9 @@ main(int argc, char *argv[]) if (error) errx(EX_USAGE, "invalid memsize '%s'", optarg); break; + case 'M': + print_mac = 1; + break; case 'H': guest_vmexit_on_hlt = 1; break;