From: Asias He Date: Sun, 17 Jul 2011 08:57:01 +0000 (+0800) Subject: kvm tools: Introduce --host-mac option X-Git-Tag: next-20110824~3^2~94 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=275fb3543dede4b929d8d8708b8da465e15f1239;p=karo-tx-linux.git kvm tools: Introduce --host-mac option The --host-mac option sets up MAC address of host. Signed-off-by: Asias He Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 01a1de27b45b..12cf75bcc6a3 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -47,6 +47,7 @@ #define DEFAULT_HOST_ADDR "192.168.33.1" #define DEFAULT_GUEST_ADDR "192.168.33.15" #define DEFAULT_GUEST_MAC "00:15:15:15:15:15" +#define DEFAULT_HOST_MAC "00:01:01:01:01:01" #define DEFAULT_SCRIPT "none" #define MB_SHIFT (20) @@ -71,6 +72,7 @@ static const char *network; static const char *host_ip_addr; static const char *guest_ip; static const char *guest_mac; +static const char *host_mac; static const char *script; static const char *guest_name; static bool single_step; @@ -168,6 +170,8 @@ static const struct option options[] = { "Assign this address to the host side networking"), OPT_STRING('\0', "guest-ip", &guest_ip, "a.b.c.d", "Assign this address to the guest side networking"), + OPT_STRING('\0', "host-mac", &host_mac, "aa:bb:cc:dd:ee:ff", + "Assign this address to the host side NIC"), OPT_STRING('\0', "guest-mac", &guest_mac, "aa:bb:cc:dd:ee:ff", "Assign this address to the guest side NIC"), OPT_STRING('\0', "tapscript", &script, "Script path", @@ -552,6 +556,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) if (!guest_mac) guest_mac = DEFAULT_GUEST_MAC; + if (!host_mac) + host_mac = DEFAULT_HOST_MAC; + if (!script) script = DEFAULT_SCRIPT; @@ -664,6 +671,13 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) net_params.guest_mac+3, net_params.guest_mac+4, net_params.guest_mac+5); + sscanf(host_mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", + net_params.host_mac, + net_params.host_mac+1, + net_params.host_mac+2, + net_params.host_mac+3, + net_params.host_mac+4, + net_params.host_mac+5); if (!strncmp(network, "user", 4)) net_params.mode = NET_MODE_USER; diff --git a/tools/kvm/include/kvm/virtio-net.h b/tools/kvm/include/kvm/virtio-net.h index 9ff0e153f8e9..c30deb8cdac4 100644 --- a/tools/kvm/include/kvm/virtio-net.h +++ b/tools/kvm/include/kvm/virtio-net.h @@ -8,6 +8,7 @@ struct virtio_net_parameters { const char *host_ip; const char *script; char guest_mac[6]; + char host_mac[6]; struct kvm *kvm; int mode; };