[Lguest] [RFC 2/6] lguest: Separate tunnet configuration from setting interface up

Sakari Ailus sakari.ailus at iki.fi
Sun Sep 2 02:07:44 EST 2012


Separate tunnet IP address configuration from setting the interface itself
up. Also remove a useless comment.

Signed-off-by: Sakari Ailus <sakari.ailus at iki.fi>
---
 tools/lguest/lguest.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c
index a5e01b0..03a9598 100644
--- a/tools/lguest/lguest.c
+++ b/tools/lguest/lguest.c
@@ -1420,11 +1420,6 @@ static void add_to_bridge(int fd, const char *if_name, const char *br_name)
 		err(1, "can't add %s to bridge %s", if_name, br_name);
 }
 
-/*
- * This sets up the Host end of the network device with an IP address, brings
- * it up so packets will flow, the copies the MAC address into the hwaddr
- * pointer.
- */
 static void configure_device(int fd, const char *tapif, u32 ipaddr,
 			     int prefixlen)
 {
@@ -1449,6 +1444,15 @@ static void configure_device(int fd, const char *tapif, u32 ipaddr,
 	memcpy(&ifr.ifr_netmask, &sin, sizeof(sin));
 	if (ioctl(fd, SIOCSIFNETMASK, &ifr) != 0)
 		err(1, "Setting %s interface netmask", tapif);
+}
+
+static void set_up_device(int fd, const char *tapif)
+{
+	struct ifreq ifr;
+
+	memset(&ifr, 0, sizeof(ifr));
+	strcpy(ifr.ifr_name, tapif);
+
 	ifr.ifr_flags = IFF_UP;
 	if (ioctl(fd, SIOCSIFFLAGS, &ifr) != 0)
 		err(1, "Bringing interface %s up", tapif);
@@ -1544,6 +1548,7 @@ static void setup_tun_net(char *arg)
 
 	/* Set up the tun device. */
 	configure_device(ipfd, tapif, ip, 24);
+	set_up_device(ipfd, tapif);
 
 	/* Expect Guest to handle everything except UFO */
 	add_feature(dev, VIRTIO_NET_F_CSUM);
-- 
1.7.2.5



More information about the Lguest mailing list