Add option to print MAC address and exit

- picked from https://github.com/mist64/xhyve/pull/79 and rebased

Signed-off-by: António Meireles <antonio.meireles@reformi.st>
This commit is contained in:
Dale Hamel 2015-12-06 10:16:23 -05:00 committed by António Meireles
parent fa6edefef0
commit d9681ceee8
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

@ -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 <pidfile>] [-g <gdb port>] [-l <lpc>]\n"
"Usage: %s [-behuwxMACHPWY] [-c vcpus] [-F <pidfile>] [-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"
@ -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: <slot,driver,configinfo> 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;