Blame SOURCES/kvm-virtio-net-add-vlan-receive-state-to-RxFilterInfo.patch

2382db
From 2bfc8b6bf5e03e3b8c0c7dc1743f719cc4273784 Mon Sep 17 00:00:00 2001
2382db
From: Amos Kong <akong@redhat.com>
2382db
Date: Mon, 4 Aug 2014 04:12:08 +0200
2382db
Subject: [PATCH 09/10] virtio-net: add vlan receive state to RxFilterInfo
2382db
2382db
Message-id: <1407125528-27862-3-git-send-email-akong@redhat.com>
2382db
Patchwork-id: 60416
2382db
O-Subject: [RHEL-7.1/7.0.z qemu-kvm PATCH 2/2] virtio-net: add vlan receive state to RxFilterInfo
2382db
Bugzilla: 1130149
2382db
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
2382db
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
2382db
RH-Acked-by: Vlad Yasevich <vyasevic@redhat.com>
2382db
2382db
Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't
2382db
filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.
2382db
2382db
This patch added a new field to @RxFilterInfo to indicate vlan receive
2382db
state ('normal', 'none', 'all'). If VIRTIO_NET_F_CTRL_VLAN isn't
2382db
negotiated, vlan receive state will be 'all', then all VLAN-tagged packets
2382db
will be received by guest.
2382db
2382db
This patch also fixed a boundary issue in visiting vlan table.
2382db
2382db
[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html
2382db
2382db
Signed-off-by: Amos Kong <akong@redhat.com>
2382db
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
2382db
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2382db
Reviewed-by: Eric Blake <eblake@redhat.com>
2382db
(backport from commit f7bc8ef8091229a4bec0e2a40af90abb8dcb3834)
2382db
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
2382db
---
2382db
 hw/net/virtio-net.c |   42 +++++++++++++++++++++++++++++-------------
2382db
 qapi-schema.json    |    3 +++
2382db
 qmp-commands.hx     |    2 ++
2382db
 3 files changed, 34 insertions(+), 13 deletions(-)
2382db
2382db
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
2382db
index 8e58139..4a50869 100644
2382db
--- a/hw/net/virtio-net.c
2382db
+++ b/hw/net/virtio-net.c
2382db
@@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
2382db
                             mac[1], mac[2], mac[3], mac[4], mac[5]);
2382db
 }
2382db
 
2382db
+static intList *get_vlan_table(VirtIONet *n)
2382db
+{
2382db
+    intList *list, *entry;
2382db
+    int i, j;
2382db
+
2382db
+    list = NULL;
2382db
+    for (i = 0; i < MAX_VLAN >> 5; i++) {
2382db
+        for (j = 0; n->vlans[i] && j <= 0x1f; j++) {
2382db
+            if (n->vlans[i] & (1U << j)) {
2382db
+                entry = g_malloc0(sizeof(*entry));
2382db
+                entry->value = (i << 5) + j;
2382db
+                entry->next = list;
2382db
+                list = entry;
2382db
+            }
2382db
+        }
2382db
+    }
2382db
+
2382db
+    return list;
2382db
+}
2382db
+
2382db
 static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
2382db
 {
2382db
     VirtIONet *n = qemu_get_nic_opaque(nc);
2382db
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
2382db
     RxFilterInfo *info;
2382db
     strList *str_list, *entry;
2382db
-    intList *int_list, *int_entry;
2382db
-    int i, j;
2382db
+    int i;
2382db
 
2382db
     info = g_malloc0(sizeof(*info));
2382db
     info->name = g_strdup(nc->name);
2382db
@@ -273,19 +293,15 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
2382db
         str_list = entry;
2382db
     }
2382db
     info->multicast_table = str_list;
2382db
+    info->vlan_table = get_vlan_table(n);
2382db
 
2382db
-    int_list = NULL;
2382db
-    for (i = 0; i < MAX_VLAN >> 5; i++) {
2382db
-        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
2382db
-            if (n->vlans[i] & (1U << j)) {
2382db
-                int_entry = g_malloc0(sizeof(*int_entry));
2382db
-                int_entry->value = (i << 5) + j;
2382db
-                int_entry->next = int_list;
2382db
-                int_list = int_entry;
2382db
-            }
2382db
-        }
2382db
+    if (!((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features)) {
2382db
+        info->vlan = RX_STATE_ALL;
2382db
+    } else if (!info->vlan_table) {
2382db
+        info->vlan = RX_STATE_NONE;
2382db
+    } else {
2382db
+        info->vlan = RX_STATE_NORMAL;
2382db
     }
2382db
-    info->vlan_table = int_list;
2382db
 
2382db
     /* enable event notification after query */
2382db
     nc->rxfilter_notify_enabled = 1;
2382db
diff --git a/qapi-schema.json b/qapi-schema.json
2382db
index 017b3b7..aaa86f5 100644
2382db
--- a/qapi-schema.json
2382db
+++ b/qapi-schema.json
2382db
@@ -4044,6 +4044,8 @@
2382db
 #
2382db
 # @unicast: unicast receive state
2382db
 #
2382db
+# @vlan: vlan receive state (Since 2.0)
2382db
+#
2382db
 # @broadcast-allowed: whether to receive broadcast
2382db
 #
2382db
 # @multicast-overflow: multicast table is overflowed or not
2382db
@@ -4067,6 +4069,7 @@
2382db
     'promiscuous':        'bool',
2382db
     'multicast':          'RxState',
2382db
     'unicast':            'RxState',
2382db
+    'vlan':               'RxState',
2382db
     'broadcast-allowed':  'bool',
2382db
     'multicast-overflow': 'bool',
2382db
     'unicast-overflow':   'bool',
2382db
diff --git a/qmp-commands.hx b/qmp-commands.hx
2382db
index 08a01ee..1d4be84 100644
2382db
--- a/qmp-commands.hx
2382db
+++ b/qmp-commands.hx
2382db
@@ -3230,6 +3230,7 @@ Each array entry contains the following:
2382db
 - "promiscuous": promiscuous mode is enabled (json-bool)
2382db
 - "multicast": multicast receive state (one of 'normal', 'none', 'all')
2382db
 - "unicast": unicast receive state  (one of 'normal', 'none', 'all')
2382db
+- "vlan": vlan receive state (one of 'normal', 'none', 'all') (Since 2.0)
2382db
 - "broadcast-allowed": allow to receive broadcast (json-bool)
2382db
 - "multicast-overflow": multicast table is overflowed (json-bool)
2382db
 - "unicast-overflow": unicast table is overflowed (json-bool)
2382db
@@ -3247,6 +3248,7 @@ Example:
2382db
             "name": "vnet0",
2382db
             "main-mac": "52:54:00:12:34:56",
2382db
             "unicast": "normal",
2382db
+            "vlan": "normal",
2382db
             "vlan-table": [
2382db
                 4,
2382db
                 0
2382db
-- 
2382db
1.7.1
2382db