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 df3c885..7e25097 100644 --- a/src/xhyve.c +++ b/src/xhyve.c @@ -79,6 +79,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 char *pidfile; @@ -126,7 +127,7 @@ usage(int code) { fprintf(stderr, - "Usage: %s [-behuwxACHPWY] [-c vcpus] [-F ] [-g ] [-l ]\n" + "Usage: %s [-behuwxMACHPWY] [-c vcpus] [-F ] [-g ] [-l ]\n" " %*s [-m mem] [-p vcpu:hostcpu] [-s ] [-U uuid] -f \n" " -A: create ACPI tables\n" " -c: # cpus (default 1)\n" @@ -139,6 +140,7 @@ usage(int code) " -H: vmexit from the guest on hlt\n" " -l: LPC device configuration. Ex: -l com1,stdio -l com2,autopty -l com2,/dev/myownpty\n" " -m: memory size in MB, may be suffixed with one of K, M, G or T\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" @@ -845,12 +847,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:F:g:c:s:m:l:U:")) != -1) { + while ((c = getopt(argc, argv, "behvuwxMACHPWY:f:F:g:c:s:m:l:U:")) != -1) { switch (c) { case 'A': acpi = 1; @@ -893,6 +896,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;