From baa59dbe5b46cf3a2811c74955374415727dfdc3 Mon Sep 17 00:00:00 2001 From: Asias He Date: Sun, 17 Jul 2011 16:57:03 +0800 Subject: [PATCH] kvm tools: Initialize MAC address for virtio net properly - Drop static initialization - Move the initializtion out of tap init Signed-off-by: Asias He Signed-off-by: Pekka Enberg --- tools/kvm/virtio/net.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index f4ba79af001b..af9b7409f6ba 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); -- 2.39.5