From patchwork Sun Jul 17 08:57:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 983012 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6H8xkO0024047 for ; Sun, 17 Jul 2011 08:59:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754342Ab1GQI7o (ORCPT ); Sun, 17 Jul 2011 04:59:44 -0400 Received: from mail-iw0-f174.google.com ([209.85.214.174]:63499 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754276Ab1GQI7n (ORCPT ); Sun, 17 Jul 2011 04:59:43 -0400 Received: by mail-iw0-f174.google.com with SMTP id 6so2294615iwn.19 for ; Sun, 17 Jul 2011 01:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=W6PijLdzeecQMA7UXK/9W71sxCDOZVZXKXnePVAsVbA=; b=JiAs8pOhtRPN5DclG0YRm63RgMvab8DihF5vbL3bgWIr2M/EEKX9zaLc7Kegt+u5qQ dzj1/WqnVRChMIddwAKDkphTWTr+jNBb9KmvRtZcdzheVaT5EqqHCMtUNfH+pSSPFEty 1bNt4YZ0VEYo+eB9yL+aT0ja2xYbQmQ3mwrSE= Received: by 10.42.155.73 with SMTP id t9mr5426266icw.216.1310893182905; Sun, 17 Jul 2011 01:59:42 -0700 (PDT) Received: from localhost.localdomain ([219.224.169.130]) by mx.google.com with ESMTPS id us2sm3593680icb.19.2011.07.17.01.59.39 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Jul 2011 01:59:42 -0700 (PDT) From: Asias He To: Pekka Enberg Cc: Cyrill Gorcunov , Ingo Molnar , Sasha Levin , Prasad Joshi , kvm@vger.kernel.org, Asias He Subject: [PATCH 13/16] kvm tools: Introduce --host-mac option Date: Sun, 17 Jul 2011 16:57:01 +0800 Message-Id: <1310893024-21615-14-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1310893024-21615-1-git-send-email-asias.hejun@gmail.com> References: <1310893024-21615-1-git-send-email-asias.hejun@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sun, 17 Jul 2011 08:59:46 +0000 (UTC) The --host-mac option sets up MAC address of host. Signed-off-by: Asias He --- 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; };