]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Introduce --host-mac option
authorAsias He <asias.hejun@gmail.com>
Sun, 17 Jul 2011 08:57:01 +0000 (16:57 +0800)
committerPekka Enberg <penberg@kernel.org>
Mon, 18 Jul 2011 10:17:18 +0000 (13:17 +0300)
The --host-mac option sets up MAC address of host.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-run.c
tools/kvm/include/kvm/virtio-net.h

index 01a1de27b45bf7d550615b1912cfe3f83877dd9a..12cf75bcc6a3ab5d0404aea04914f8aa229a114e 100644 (file)
@@ -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;
index 9ff0e153f8e9d2e06edcb5bb06a518288a0b68a1..c30deb8cdac4188c75c55ee10e28c23cfda0830c 100644 (file)
@@ -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;
 };