Skip to contentSkip to conversation

virtio-net: revert mac on reset

PATCH In review Michael S. Tsirkin 3 participants 3 messages Jan 16, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-net: revert mac on reset

Once guest overrides virtio net primary mac, it retains the value set until qemu exit. This is inconsistent with standard nic behaviour. To fix, revert the mac to the original value on reset.

---
 hw/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/virtio-net.c +1 -0
index 3bb01b1..4d80a25 100644
@@ -199,6 +199,7 @@ static void virtio_net_reset(VirtIODevice *vdev)
     n->mac_table.multi_overflow = 0;
     n->mac_table.uni_overflow = 0;
     memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
+    memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac));
     memset(n->vlans, 0, MAX_VLAN >> 3);
 }
 
Signature · 1 line
MST
Reviewed-by on v1 1/1
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 15 lines · Michael S. Tsirkin

Once guest overrides virtio net primary mac, it retains the value set until qemu exit. This is inconsistent with standard nic behaviour. To fix, revert the mac to the original value on reset.

---
 hw/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/virtio-net.c +0 -0
index 3bb01b1..4d80a25 100644

hw/virtio-net.c static void virtio_net_reset(VirtIODevice *vdev) · line 205

Quoted 7 lines
hw/virtio-net.c +1 -0
@@ -199,6 +199,7 @@ static void virtio_net_reset(VirtIODevice *vdev)
     n->mac_table.multi_overflow = 0;
     n->mac_table.uni_overflow = 0;
     memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
+    memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac));
     memset(n->vlans, 0, MAX_VLAN >> 3);
 }