Add option to print MAC address and exit

This commit is contained in:
Dale Hamel 2015-12-06 10:16:23 -05:00
parent cd782515ff
commit c6bf5fcad6
3 changed files with 17 additions and 2 deletions

View file

@ -41,6 +41,7 @@
#define VMEXIT_ABORT (-1)
extern int guest_ncpus;
extern int print_mac;
extern char *guest_uuid_str;
extern char *vmname;

View file

@ -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];

View file

@ -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 <gdb port>] [-l <lpc>]\n"
"Usage: %s [-behuwxMACHPWY] [-c vcpus] [-g <gdb port>] [-l <lpc>]\n"
" %*s [-m mem] [-p vcpu:hostcpu] [-s <pci>] [-U uuid] -f <fw>\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: <slot,driver,configinfo> 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;