diff mbox

[15/16] kvm tools: Initialize MAC address for virtio net properly

Message ID 1310893024-21615-16-git-send-email-asias.hejun@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Asias He July 17, 2011, 8:57 a.m. UTC
- Drop static initialization

- Move the initializtion out of tap init

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 tools/kvm/virtio/net.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index f4ba79a..af9b740 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -82,7 +82,6 @@  static struct net_dev ndev = {
 	.mutex	= PTHREAD_MUTEX_INITIALIZER,
 
 	.config = {
-		.mac			= {0x00, 0x15, 0x15, 0x15, 0x15, 0x15},
 		.status			= VIRTIO_NET_S_LINK_UP,
 	},
 	.host_features			= 1UL << VIRTIO_NET_F_MAC
@@ -318,13 +317,10 @@  static struct ioport_operations virtio_net_io_ops = {
 static bool virtio_net__tap_init(const struct virtio_net_parameters *params)
 {
 	int sock = socket(AF_INET, SOCK_STREAM, 0);
-	int i, pid, status, offload, hdr_len;
+	int pid, status, offload, hdr_len;
 	struct sockaddr_in sin = {0};
 	struct ifreq ifr;
 
-	for (i = 0 ; i < 6 ; i++)
-		ndev.config.mac[i] = params->guest_mac[i];
-
 	ndev.tap_fd = open("/dev/net/tun", O_RDWR);
 	if (ndev.tap_fd < 0) {
 		pr_warning("Unable to open /dev/net/tun");
@@ -459,6 +455,9 @@  void virtio_net__init(const struct virtio_net_parameters *params)
 	ndev.base_addr	    = net_base_addr;
 	pci__register(&pci_header, dev);
 
+	for (i = 0 ; i < 6 ; i++)
+		ndev.config.mac[i] = params->guest_mac[i];
+
 	ndev.mode = params->mode;
 	if (ndev.mode == NET_MODE_TAP) {
 		virtio_net__tap_init(params);