The --host-mac option sets up MAC address of host.

Signed-off-by: Asias He <[email protected]>
---
 tools/kvm/builtin-run.c            |   14 ++++++++++++++
 tools/kvm/include/kvm/virtio-net.h |    1 +
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 01a1de2..12cf75b 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 9ff0e15..c30deb8 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;
 };
-- 
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to