Patchwork [RFC,3/4] virtio-net: Limit the num of uni/multicast mac addresses

login
register
mail settings
Submitter Jason Wang
Date Sept. 27, 2010, 12:51 p.m.
Message ID <20100927125109.12060.19145.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com>
Download mbox | patch
Permalink /patch/65842/
State New
Headers show

Comments

Jason Wang - Sept. 27, 2010, 12:51 p.m.
In order to send gratuitous packet for each mac address, we need to keep
track every macaddress after migration which is obviously conflicted with the
overload policy currently used in qemu which just forward all packets to guest
when it can't record all the macaddress. So we need to limit the num of
uni/multicast mac addresses in qemu.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/virtio-net.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

Patch

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 0a9cae2..79afb65 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -291,7 +291,9 @@  static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
                mac_data.entries * ETH_ALEN);
         n->mac_table.in_use += mac_data.entries;
     } else {
-        n->mac_table.uni_overflow = 1;
+        /* Gratuitous packet could not be built properly in overflow mode, so we
+         * never allow uni_overflow here. */
+        return VIRTIO_NET_ERR;
     }
 
     n->mac_table.first_multi = n->mac_table.in_use;
@@ -309,7 +311,9 @@  static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
                    mac_data.entries * ETH_ALEN);
             n->mac_table.in_use += mac_data.entries;
         } else {
-            n->mac_table.multi_overflow = 1;
+            /* Gratuitous packet could not be built properly in overflow mode,
+             * so we never allow multi_overflow here. */
+            return VIRTIO_NET_ERR;
         }
     }
 
@@ -844,9 +848,8 @@  static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
             qemu_get_buffer(f, n->mac_table.macs,
                             n->mac_table.in_use * ETH_ALEN);
         } else if (n->mac_table.in_use) {
-            qemu_fseek(f, n->mac_table.in_use * ETH_ALEN, SEEK_CUR);
-            n->mac_table.multi_overflow = n->mac_table.uni_overflow = 1;
-            n->mac_table.in_use = 0;
+            error_report("virtio-net: Overflow was not permitted.");
+            return -EINVAL;
         }
     }
  
@@ -873,6 +876,10 @@  static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
     if (version_id >= 9) {
         n->mac_table.multi_overflow = qemu_get_byte(f);
         n->mac_table.uni_overflow = qemu_get_byte(f);
+        if (n->mac_table.multi_overflow || n->mac_table.uni_overflow) {
+            error_report("virtio-net: Overflow was not permitted");
+            return -EINVAL;
+        }
     }
 
     if (version_id >= 10) {