[Lguest] [RFC 3/6] lguest: Set MAC address only if configured by user

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


MAC address was set to tunnet device even if no configuration was given by
the user. Fix this.

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

diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c
index 03a9598..9b262ec 100644
--- a/tools/lguest/lguest.c
+++ b/tools/lguest/lguest.c
@@ -1506,7 +1506,8 @@ static void setup_tun_net(char *arg)
 	u32 ip = INADDR_ANY;
 	bool bridging = false;
 	char tapif[IFNAMSIZ], *p;
-	struct virtio_net_config conf;
+	struct virtio_net_config virtio_conf;
+	bool has_virtio_conf = false;
 
 	net_info->tunfd = get_tun_device(tapif);
 
@@ -1535,7 +1536,8 @@ static void setup_tun_net(char *arg)
 	/* A mac address may follow the bridge name or IP address */
 	p = strchr(arg, ':');
 	if (p) {
-		str2mac(p+1, conf.mac);
+		has_virtio_conf = true;
+		str2mac(p+1, virtio_conf.mac);
 		add_feature(dev, VIRTIO_NET_F_MAC);
 		*p = '\0';
 	}
@@ -1561,7 +1563,8 @@ static void setup_tun_net(char *arg)
 	add_feature(dev, VIRTIO_NET_F_HOST_ECN);
 	/* We handle indirect ring entries */
 	add_feature(dev, VIRTIO_RING_F_INDIRECT_DESC);
-	set_config(dev, sizeof(conf), &conf);
+	if (has_virtio_conf)
+		set_config(dev, sizeof(virtio_conf), &virtio_conf);
 
 	/* We don't need the socket any more; setup is done. */
 	close(ipfd);
-- 
1.7.2.5



More information about the Lguest mailing list