From patchwork Wed Apr 13 12:13:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 703651 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3DCDcYT029211 for ; Wed, 13 Apr 2011 12:13:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755223Ab1DMMNf (ORCPT ); Wed, 13 Apr 2011 08:13:35 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:33937 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755089Ab1DMMNf (ORCPT ); Wed, 13 Apr 2011 08:13:35 -0400 Received: by wya21 with SMTP id 21so431810wya.19 for ; Wed, 13 Apr 2011 05:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=sueJvpX2X8Rg51z8Nzio2LxcH9+WZ4K6mDVNKfUYvd4=; b=XXL4OdnZTGibW7GxHteoYGZGJzkyy1LAybvk7m5QMk48pwAgf5yFITgXExM5JlCYur iWwh0el2yLh1LSKnuzUGsoepZam604r0huJk77nSQeTsFtRDLa39RlDOQX4wGZtfOuFa YCwZl0Z2tlqbb9sUcO8Cm0FEqzoUc+iOnPJas= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=T80+hcrTNqtuJwikjZfz9ZWe09FEDTOnUoPNR4kdMAygpfa3W68qROx8Xf7qk0XupM /TRZ60WA3BsfHN8LXJj6b0knFwl/ijDjHl0DAX34OVT9jkBtuWwNXLN05pdSCF2BIGl0 gECP42dPL8FnCmlfskANU3WhGy7wLc7e5tJSE= Received: by 10.216.182.20 with SMTP id n20mr7300431wem.113.1302696814067; Wed, 13 Apr 2011 05:13:34 -0700 (PDT) Received: from localhost.localdomain ([94.230.81.151]) by mx.google.com with ESMTPS id s40sm235855weq.28.2011.04.13.05.13.32 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 13 Apr 2011 05:13:33 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org, gorcunov@gmail.com, asias.hejun@gmail.com Cc: kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 2/2] kvm tools: Make host side IP configurable Date: Wed, 13 Apr 2011 15:13:24 +0300 Message-Id: <1302696804-29684-2-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc1 In-Reply-To: <1302696804-29684-1-git-send-email-levinsasha928@gmail.com> References: <1302696804-29684-1-git-send-email-levinsasha928@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 (demeter1.kernel.org [140.211.167.41]); Wed, 13 Apr 2011 12:13:39 +0000 (UTC) Add --host-ip-addr parameter to allow changing the host-side IP address. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/virtio-net.h | 2 +- tools/kvm/kvm-run.c | 9 ++++++++- tools/kvm/virtio-net.c | 9 ++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/kvm/include/kvm/virtio-net.h b/tools/kvm/include/kvm/virtio-net.h index a1cab15..03eb623 100644 --- a/tools/kvm/include/kvm/virtio-net.h +++ b/tools/kvm/include/kvm/virtio-net.h @@ -2,6 +2,6 @@ #define KVM__VIRTIO_NET_H struct kvm; -void virtio_net__init(struct kvm *self); +void virtio_net__init(struct kvm *self, const char* host_ip_addr); #endif /* KVM__VIRTIO_NET_H */ diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 6046a0a..910a8d8 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -31,6 +31,7 @@ #define DEFAULT_KVM_DEV "/dev/kvm" #define DEFAULT_CONSOLE "serial" #define DEFAULT_NETWORK "none" +#define DEFAULT_HOST_ADDR "192.168.33.2" #define MB_SHIFT (20) #define MIN_RAM_SIZE_MB (64ULL) @@ -66,6 +67,7 @@ static const char *image_filename; static const char *console; static const char *kvm_dev; static const char *network; +static const char *host_ip_addr; static bool single_step; static bool readonly_image; extern bool ioport_debug; @@ -89,6 +91,8 @@ static const struct option options[] = { "Console to use"), OPT_STRING('n', "network", &network, "virtio", "Network to use"), + OPT_STRING('\0', "host-ip-addr", &host_ip_addr, "a.b.c.d", + "Assign this address to the host side networking"), OPT_GROUP("Kernel options:"), OPT_STRING('k', "kernel", &kernel_filename, "kernel", @@ -218,6 +222,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) else active_console = CONSOLE_8250; + if (!host_ip_addr) + host_ip_addr = DEFAULT_HOST_ADDR; + term_init(); kvm = kvm__init(kvm_dev, ram_size); @@ -259,7 +266,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) network = DEFAULT_NETWORK; if (!strncmp(network, "virtio", 6)) - virtio_net__init(kvm); + virtio_net__init(kvm, host_ip_addr); kvm__start_timer(kvm); diff --git a/tools/kvm/virtio-net.c b/tools/kvm/virtio-net.c index 5f9bf07..ec65779 100644 --- a/tools/kvm/virtio-net.c +++ b/tools/kvm/virtio-net.c @@ -276,7 +276,7 @@ static struct pci_device_header virtio_net_pci_device = { .irq_line = VIRTIO_NET_IRQ, }; -static void virtio_net__tap_init(void) +static void virtio_net__tap_init(const char *host_ip_addr) { struct ifreq ifr; int sock = socket(AF_INET, SOCK_STREAM, 0); @@ -298,8 +298,7 @@ static void virtio_net__tap_init(void) strncpy(ifr.ifr_name, net_device.tap_name, sizeof(net_device.tap_name)); - /*FIXME: Remove this after user can specify ip address and netmask*/ - ((struct sockaddr_in *)(&(ifr.ifr_addr)))->sin_addr.s_addr = inet_addr("192.168.33.2"); + ((struct sockaddr_in *)(&(ifr.ifr_addr)))->sin_addr.s_addr = inet_addr(host_ip_addr); ifr.ifr_addr.sa_family = AF_INET; if (ioctl(sock, SIOCSIFADDR, &ifr) < 0) @@ -327,11 +326,11 @@ static void virtio_net__io_thread_init(struct kvm *self) pthread_create(&net_device.io_tx_thread, NULL, virtio_net_tx_thread, (void *)self); } -void virtio_net__init(struct kvm *self) +void virtio_net__init(struct kvm *self, const char* host_ip_addr) { pci__register(&virtio_net_pci_device, PCI_VIRTIO_NET_DEVNUM); ioport__register(IOPORT_VIRTIO_NET, &virtio_net_io_ops, IOPORT_VIRTIO_NET_SIZE); - virtio_net__tap_init(); + virtio_net__tap_init(host_ip_addr); virtio_net__io_thread_init(self); }