public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Asias He <asias.hejun@gmail.com>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: penberg@kernel.org, gorcunov@gmail.com, kvm@vger.kernel.org
Subject: Re: [PATCH 1/2] kvm tools: Set up tun interface using ioctls
Date: Wed, 13 Apr 2011 20:39:48 +0800	[thread overview]
Message-ID: <4DA59994.4000400@gmail.com> (raw)
In-Reply-To: <1302696804-29684-1-git-send-email-levinsasha928@gmail.com>

On 04/13/2011 08:13 PM, Sasha Levin wrote:
> Use ioctls to assign IP address and bring interface up instead of using ifconfig.
> 
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
>  tools/kvm/virtio-net.c |   25 ++++++++++++++++++++++---
>  1 files changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/kvm/virtio-net.c b/tools/kvm/virtio-net.c
> index ec70d5c..5f9bf07 100644
> --- a/tools/kvm/virtio-net.c
> +++ b/tools/kvm/virtio-net.c
> @@ -14,6 +14,9 @@
>  #include <sys/ioctl.h>
>  #include <assert.h>
>  #include <fcntl.h>
> +#include <arpa/inet.h>
> +#include <sys/types.h>
> +#include <sys/socket.h>
>  
>  #define VIRTIO_NET_IRQ		14
>  #define VIRTIO_NET_QUEUE_SIZE	128
> @@ -276,7 +279,7 @@ static struct pci_device_header virtio_net_pci_device = {
>  static void virtio_net__tap_init(void)
>  {
>  	struct ifreq ifr;
> -
> +	int sock = socket(AF_INET, SOCK_STREAM, 0);
>  	net_device.tap_fd = open("/dev/net/tun", O_RDWR);
>  	if (net_device.tap_fd < 0)
>  		die("Unable to open /dev/net/tun\n");
> @@ -291,9 +294,25 @@ static void virtio_net__tap_init(void)
>  
>  	ioctl(net_device.tap_fd, TUNSETNOCSUM, 1);
>  
> +	memset(&ifr, 0, sizeof(ifr));
> +
> +	strncpy(ifr.ifr_name, net_device.tap_name, sizeof(net_device.tap_name));
> +
>  	/*FIXME: Remove this after user can specify ip address and netmask*/
> -	if (system("ifconfig tap0 192.168.33.2") < 0)
> -		warning("Can not set ip address on tap0");
> +	((struct sockaddr_in *)(&(ifr.ifr_addr)))->sin_addr.s_addr = inet_addr("192.168.33.2");
> +	ifr.ifr_addr.sa_family = AF_INET;
> +
> +	if (ioctl(sock, SIOCSIFADDR, &ifr) < 0)
> +		warning("Can not set ip address on tap device");
> +
> +	memset(&ifr, 0, sizeof(ifr));
> +	strncpy(ifr.ifr_name, net_device.tap_name, sizeof(net_device.tap_name));
> +	ioctl(sock, SIOCGIFFLAGS, &ifr);
> +	ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
> +	if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0)
> +		warning("Could not bring tap device up");
> +
> +	close(sock);
>  }
>  
>  static void virtio_net__io_thread_init(struct kvm *self)

Looks good to me.

Reviewed-by: Asias He <asias.hejun@gmail.com>

-- 
Best Regards,
Asias He

  parent reply	other threads:[~2011-04-13 12:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-13 12:13 [PATCH 1/2] kvm tools: Set up tun interface using ioctls Sasha Levin
2011-04-13 12:13 ` [PATCH 2/2] kvm tools: Make host side IP configurable Sasha Levin
2011-04-13 12:28   ` Asias He
2011-04-13 12:35     ` Pekka Enberg
2011-04-13 13:28     ` Asias He
2011-04-13 13:38       ` Sasha Levin
2011-04-13 14:07         ` Pekka Enberg
2011-04-13 14:13           ` Asias He
2011-04-13 12:39 ` Asias He [this message]
2011-04-13 13:49 ` [PATCH 1/2] kvm tools: Set up tun interface using ioctls Pekka Enberg
2011-04-13 13:59   ` Asias He
2011-04-13 14:03     ` Pekka Enberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DA59994.4000400@gmail.com \
    --to=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=penberg@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox