Skip to contentSkip to conversation

virtio-net: add a field to indicate if vlan table is used

PATCH In review Amos Kong 5 participants 9 messages Feb 20, 2014 – Mar 25, 2014

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH v2 1/1 virtio-net: add a field to indicate if vlan table is used

Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.

This patch added a new field to @RxFilterInfo to indicate if management uses the vlan table.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html

---
V2: don't make vlan-table optional, add a flag to indicate
if vlan table is used by management

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  3 +++
 qmp-commands.hx     |  2 ++
 3 files changed, 30 insertions(+), 13 deletions(-)
hw/net/virtio-net.c +25 -13
index 3626608..f591f4e 100644
@@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
                             mac[1], mac[2], mac[3], mac[4], mac[5]);
 }
 
+static intList *get_vlan_table(VirtIONet *n)
+{
+    intList *list, *entry;
+    int i, j;
+
+    list = NULL;
+    for (i = 0; i < MAX_VLAN >> 5; i++) {
+        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
+            if (n->vlans[i] & (1U << j)) {
+                entry = g_malloc0(sizeof(*entry));
+                entry->value = (i << 5) + j;
+                entry->next = list;
+                list = entry;
+            }
+        }
+    }
+
+    return list;
+}
+
 static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     RxFilterInfo *info;
     strList *str_list, *entry;
-    intList *int_list, *int_entry;
-    int i, j;
+    int i;
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(nc->name);
@@ -273,19 +293,11 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
         str_list = entry;
     }
     info->multicast_table = str_list;
+    info->vlan_table = get_vlan_table(n);
 
-    int_list = NULL;
-    for (i = 0; i < MAX_VLAN >> 5; i++) {
-        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
-            if (n->vlans[i] & (1U << j)) {
-                int_entry = g_malloc0(sizeof(*int_entry));
-                int_entry->value = (i << 5) + j;
-                int_entry->next = int_list;
-                int_list = int_entry;
-            }
-        }
+    if ((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features) {
+        info->vlan = true;
     }
-    info->vlan_table = int_list;
 
     /* enable event notification after query */
     nc->rxfilter_notify_enabled = 1;
qapi-schema.json +3 -0
index 7cfb5e5..5b54e94 100644
@@ -4032,6 +4032,8 @@
 #
 # @unicast-overflow: unicast table is overflowed or not
 #
+# @vlan: whether management uses the vlan table
+#
 # @main-mac: the main macaddr string
 #
 # @vlan-table: a list of active vlan id
@@ -4052,6 +4054,7 @@
     'broadcast-allowed':  'bool',
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
+    'vlan':               'bool',
     'main-mac':           'str',
     'vlan-table':         ['int'],
     'unicast-table':      ['str'],
qmp-commands.hx +2 -0
index cce6b81..b170c79 100644
@@ -3307,6 +3307,7 @@ Each array entry contains the following:
 - "broadcast-allowed": allow to receive broadcast (json-bool)
 - "multicast-overflow": multicast table is overflowed (json-bool)
 - "unicast-overflow": unicast table is overflowed (json-bool)
+- "vlan": management uses the vlan table (json-bool)
 - "main-mac": main macaddr string (json-string)
 - "vlan-table": a json-array of active vlan id
 - "unicast-table": a json-array of unicast macaddr string
@@ -3321,6 +3322,7 @@ Example:
             "name": "vnet0",
             "main-mac": "52:54:00:12:34:56",
             "unicast": "normal",
+            "vlan": true,
             "vlan-table": [
                 4,
                 0
Signature · 1 line
1.8.5.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 15 lines · Amos Kong

Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.

This patch added a new field to @RxFilterInfo to indicate if management uses the vlan table.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html

---
V2: don't make vlan-table optional, add a flag to indicate
if vlan table is used by management

+++ b/qapi-schema.json

qapi-schema.json line 4036

Quoted 5 lines
qapi-schema.json +2 -0
@@ -4032,6 +4032,8 @@
 #
 # @unicast-overflow: unicast table is overflowed or not
 #
+# @vlan: whether management uses the vlan table
+#

Needs a '(Since 2.0)' annotation.

If that gets fixed, you can add:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Amos Kong
Quoted 67 lines · Amos Kong

Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.

This patch added a new field to @RxFilterInfo to indicate if management uses the vlan table.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html

---
V2: don't make vlan-table optional, add a flag to indicate
if vlan table is used by management

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  3 +++
 qmp-commands.hx     |  2 ++
 3 files changed, 30 insertions(+), 13 deletions(-)
hw/net/virtio-net.c +23 -5
index 3626608..f591f4e 100644
@@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
                             mac[1], mac[2], mac[3], mac[4], mac[5]);
 }
 
+static intList *get_vlan_table(VirtIONet *n)
+{
+    intList *list, *entry;
+    int i, j;
+
+    list = NULL;
+    for (i = 0; i < MAX_VLAN >> 5; i++) {
+        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
+            if (n->vlans[i] & (1U << j)) {
+                entry = g_malloc0(sizeof(*entry));
+                entry->value = (i << 5) + j;
+                entry->next = list;
+                list = entry;
+            }
+        }
+    }
+
+    return list;
+}
+
 static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     RxFilterInfo *info;
     strList *str_list, *entry;
-    intList *int_list, *int_entry;
-    int i, j;
+    int i;
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(nc->name);
@@ -273,19 +293,11 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
         str_list = entry;
     }
     info->multicast_table = str_list;
+    info->vlan_table = get_vlan_table(n);
 
-    int_list = NULL;
-    for (i = 0; i < MAX_VLAN >> 5; i++) {
-        for (j = 0; n->vlans[i] && j < 0x1f; j++) {

hw/net/virtio-net.c static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) · line 300

Quoted 10 lines
hw/net/virtio-net.c +2 -7
-            if (n->vlans[i] & (1U << j)) {
-                int_entry = g_malloc0(sizeof(*int_entry));
-                int_entry->value = (i << 5) + j;
-                int_entry->next = int_list;
-                int_list = int_entry;
-            }
-        }
+    if ((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features) {
+        info->vlan = true;
     }

So, in the case that vlan filtering is not supported in the guest we get:

             "vlan": false,
             "vlan-table": [
                 0,
                 1,
                 2,
                 ...
                 4095
            ]

since virtio_net now initializes the table to all 1s. Seems a bit awkward. We are providing a lot of data that is simply going to be ignored.

Quoted 9 lines
hw/net/virtio-net.c +0 -1
-    info->vlan_table = int_list;
 
     /* enable event notification after query */
     nc->rxfilter_notify_enabled = 1;
qapi-schema.json +0 -0
index 7cfb5e5..5b54e94 100644

qapi-schema.json line 4036

Quoted 5 lines
qapi-schema.json +2 -0
@@ -4032,6 +4032,8 @@
 #
 # @unicast-overflow: unicast table is overflowed or not
 #
+# @vlan: whether management uses the vlan table
+#

The above description seems a bit confusing to me. The value we are returning describes whether or not qemu is performing vlan filtering. I am not sure if it has any bearing on what management may be doing.

I think the idea is that management, in the future, would look at this value and make some decision about applying provided filter to the current host configuration.

qapi-schema.json line 4057

Quoted 8 lines
qapi-schema.json +1 -0
 # @main-mac: the main macaddr string
 #
 # @vlan-table: a list of active vlan id
@@ -4052,6 +4054,7 @@
     'broadcast-allowed':  'bool',
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
+    'vlan':               'bool',

Not terribly descriptive. May be call it vlan-filter?

Thanks
-vlad

Quoted 24 lines
qapi-schema.json +0 -0
     'main-mac':           'str',
     'vlan-table':         ['int'],
     'unicast-table':      ['str'],
qmp-commands.hx +2 -0
index cce6b81..b170c79 100644
@@ -3307,6 +3307,7 @@ Each array entry contains the following:
 - "broadcast-allowed": allow to receive broadcast (json-bool)
 - "multicast-overflow": multicast table is overflowed (json-bool)
 - "unicast-overflow": unicast table is overflowed (json-bool)
+- "vlan": management uses the vlan table (json-bool)
 - "main-mac": main macaddr string (json-string)
 - "vlan-table": a json-array of active vlan id
 - "unicast-table": a json-array of unicast macaddr string
@@ -3321,6 +3322,7 @@ Example:
             "name": "vnet0",
             "main-mac": "52:54:00:12:34:56",
             "unicast": "normal",
+            "vlan": true,
             "vlan-table": [
                 4,
                 0
author
#3 lore raw
Quoted 89 lines · Vlad Yasevich
Quoted 67 lines · Amos Kong

Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.

This patch added a new field to @RxFilterInfo to indicate if management uses the vlan table.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html

---
V2: don't make vlan-table optional, add a flag to indicate
if vlan table is used by management

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  3 +++
 qmp-commands.hx     |  2 ++
 3 files changed, 30 insertions(+), 13 deletions(-)
hw/net/virtio-net.c +23 -5
index 3626608..f591f4e 100644
@@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
                             mac[1], mac[2], mac[3], mac[4], mac[5]);
 }
 
+static intList *get_vlan_table(VirtIONet *n)
+{
+    intList *list, *entry;
+    int i, j;
+
+    list = NULL;
+    for (i = 0; i < MAX_VLAN >> 5; i++) {
+        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
+            if (n->vlans[i] & (1U << j)) {
+                entry = g_malloc0(sizeof(*entry));
+                entry->value = (i << 5) + j;
+                entry->next = list;
+                list = entry;
+            }
+        }
+    }
+
+    return list;
+}
+
 static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     RxFilterInfo *info;
     strList *str_list, *entry;
-    intList *int_list, *int_entry;
-    int i, j;
+    int i;
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(nc->name);
@@ -273,19 +293,11 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
         str_list = entry;
     }
     info->multicast_table = str_list;
+    info->vlan_table = get_vlan_table(n);
 
-    int_list = NULL;
-    for (i = 0; i < MAX_VLAN >> 5; i++) {
-        for (j = 0; n->vlans[i] && j < 0x1f; j++) {

hw/net/virtio-net.c static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) · line 300

Quoted 10 lines
hw/net/virtio-net.c +2 -7
-            if (n->vlans[i] & (1U << j)) {
-                int_entry = g_malloc0(sizeof(*int_entry));
-                int_entry->value = (i << 5) + j;
-                int_entry->next = int_list;
-                int_list = int_entry;
-            }
-        }
+    if ((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features) {
+        info->vlan = true;
     }

So, in the case that vlan filtering is not supported in the guest we get:

             "vlan": false,
             "vlan-table": [
                 0,
                 1,
                 2,
                 ...
                 4095
            ]
Quoted 3 lines

since virtio_net now initializes the table to all 1s. Seems a bit awkward. We are providing a lot of data that is simply going to be ignored.

In Stefan's patch [1], qemu fills all vlan ids to 1, then all the packets will come to guest.

For the host device, it also should not filter out any vlan-tagged packets when VIRTIO_NET_F_CTRL_VLAN is not negotiated. We should also fill vlan ids of host device to 1, then vlan-filter of host device will not perform.

If so, we don't need my patch, just pass [0,1,2,...4095] to management as past. The new field in RxFilterInfo isn't necessary.

[1] [PATCH] virtio-net: Do not filter VLANs without F_CTRL_VLAN

Thanks, Amos

Quoted 61 lines
Quoted 9 lines
hw/net/virtio-net.c +0 -1
-    info->vlan_table = int_list;
 
     /* enable event notification after query */
     nc->rxfilter_notify_enabled = 1;
qapi-schema.json +0 -0
index 7cfb5e5..5b54e94 100644

qapi-schema.json line 4036

Quoted 5 lines
qapi-schema.json +2 -0
@@ -4032,6 +4032,8 @@
 #
 # @unicast-overflow: unicast table is overflowed or not
 #
+# @vlan: whether management uses the vlan table
+#

The above description seems a bit confusing to me. The value we are returning describes whether or not qemu is performing vlan filtering. I am not sure if it has any bearing on what management may be doing.

I think the idea is that management, in the future, would look at this value and make some decision about applying provided filter to the current host configuration.

qapi-schema.json line 4057

Quoted 8 lines
qapi-schema.json +1 -0
 # @main-mac: the main macaddr string
 #
 # @vlan-table: a list of active vlan id
@@ -4052,6 +4054,7 @@
     'broadcast-allowed':  'bool',
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
+    'vlan':               'bool',

Not terribly descriptive. May be call it vlan-filter?

Thanks
-vlad

Quoted 24 lines
qapi-schema.json +0 -0
     'main-mac':           'str',
     'vlan-table':         ['int'],
     'unicast-table':      ['str'],
qmp-commands.hx +2 -0
index cce6b81..b170c79 100644
@@ -3307,6 +3307,7 @@ Each array entry contains the following:
 - "broadcast-allowed": allow to receive broadcast (json-bool)
 - "multicast-overflow": multicast table is overflowed (json-bool)
 - "unicast-overflow": unicast table is overflowed (json-bool)
+- "vlan": management uses the vlan table (json-bool)
 - "main-mac": main macaddr string (json-string)
 - "vlan-table": a json-array of active vlan id
 - "unicast-table": a json-array of unicast macaddr string
@@ -3321,6 +3322,7 @@ Example:
             "name": "vnet0",
             "main-mac": "52:54:00:12:34:56",
             "unicast": "normal",
+            "vlan": true,
             "vlan-table": [
                 4,
                 0
#4 lore raw
Quoted 97 lines · On Fri, 21 Feb 2014 18:01:40 +0800 Amos Kong <[email protected]> wrote:
Quoted 89 lines · Vlad Yasevich
Quoted 67 lines · Amos Kong

Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.

This patch added a new field to @RxFilterInfo to indicate if management uses the vlan table.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html

---
V2: don't make vlan-table optional, add a flag to indicate
if vlan table is used by management

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  3 +++
 qmp-commands.hx     |  2 ++
 3 files changed, 30 insertions(+), 13 deletions(-)
hw/net/virtio-net.c +23 -5
index 3626608..f591f4e 100644
@@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
                             mac[1], mac[2], mac[3], mac[4], mac[5]);
 }
 
+static intList *get_vlan_table(VirtIONet *n)
+{
+    intList *list, *entry;
+    int i, j;
+
+    list = NULL;
+    for (i = 0; i < MAX_VLAN >> 5; i++) {
+        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
+            if (n->vlans[i] & (1U << j)) {
+                entry = g_malloc0(sizeof(*entry));
+                entry->value = (i << 5) + j;
+                entry->next = list;
+                list = entry;
+            }
+        }
+    }
+
+    return list;
+}
+
 static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     RxFilterInfo *info;
     strList *str_list, *entry;
-    intList *int_list, *int_entry;
-    int i, j;
+    int i;
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(nc->name);
@@ -273,19 +293,11 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
         str_list = entry;
     }
     info->multicast_table = str_list;
+    info->vlan_table = get_vlan_table(n);
 
-    int_list = NULL;
-    for (i = 0; i < MAX_VLAN >> 5; i++) {
-        for (j = 0; n->vlans[i] && j < 0x1f; j++) {

hw/net/virtio-net.c static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) · line 300

Quoted 10 lines
hw/net/virtio-net.c +2 -7
-            if (n->vlans[i] & (1U << j)) {
-                int_entry = g_malloc0(sizeof(*int_entry));
-                int_entry->value = (i << 5) + j;
-                int_entry->next = int_list;
-                int_list = int_entry;
-            }
-        }
+    if ((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features) {
+        info->vlan = true;
     }

So, in the case that vlan filtering is not supported in the guest we get:

             "vlan": false,
             "vlan-table": [
                 0,
                 1,
                 2,
                 ...
                 4095
            ]
Quoted 3 lines

since virtio_net now initializes the table to all 1s. Seems a bit awkward. We are providing a lot of data that is simply going to be ignored.

In Stefan's patch [1], qemu fills all vlan ids to 1, then all the packets will come to guest.

Quoted 7 lines

For the host device, it also should not filter out any vlan-tagged packets when VIRTIO_NET_F_CTRL_VLAN is not negotiated. We should also fill vlan ids of host device to 1, then vlan-filter of host device will not perform.

If so, we don't need my patch, just pass [0,1,2,...4095] to management as past. The new field in RxFilterInfo isn't necessary.

What's the conclusion here?

Quoted 67 lines

[1] [PATCH] virtio-net: Do not filter VLANs without F_CTRL_VLAN

Thanks, Amos

Quoted 61 lines
Quoted 9 lines
hw/net/virtio-net.c +0 -1
-    info->vlan_table = int_list;
 
     /* enable event notification after query */
     nc->rxfilter_notify_enabled = 1;
qapi-schema.json +0 -0
index 7cfb5e5..5b54e94 100644

qapi-schema.json line 4036

Quoted 5 lines
qapi-schema.json +2 -0
@@ -4032,6 +4032,8 @@
 #
 # @unicast-overflow: unicast table is overflowed or not
 #
+# @vlan: whether management uses the vlan table
+#

The above description seems a bit confusing to me. The value we are returning describes whether or not qemu is performing vlan filtering. I am not sure if it has any bearing on what management may be doing.

I think the idea is that management, in the future, would look at this value and make some decision about applying provided filter to the current host configuration.

qapi-schema.json line 4057

Quoted 8 lines
qapi-schema.json +1 -0
 # @main-mac: the main macaddr string
 #
 # @vlan-table: a list of active vlan id
@@ -4052,6 +4054,7 @@
     'broadcast-allowed':  'bool',
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
+    'vlan':               'bool',

Not terribly descriptive. May be call it vlan-filter?

Thanks
-vlad

Quoted 24 lines
qapi-schema.json +0 -0
     'main-mac':           'str',
     'vlan-table':         ['int'],
     'unicast-table':      ['str'],
qmp-commands.hx +2 -0
index cce6b81..b170c79 100644
@@ -3307,6 +3307,7 @@ Each array entry contains the following:
 - "broadcast-allowed": allow to receive broadcast (json-bool)
 - "multicast-overflow": multicast table is overflowed (json-bool)
 - "unicast-overflow": unicast table is overflowed (json-bool)
+- "vlan": management uses the vlan table (json-bool)
 - "main-mac": main macaddr string (json-string)
 - "vlan-table": a json-array of active vlan id
 - "unicast-table": a json-array of unicast macaddr string
@@ -3321,6 +3322,7 @@ Example:
             "name": "vnet0",
             "main-mac": "52:54:00:12:34:56",
             "unicast": "normal",
+            "vlan": true,
             "vlan-table": [
                 4,
                 0
author
#5 lore raw
Quoted 105 lines · Luiz Capitulino
Quoted 102 lines · On Fri, 21 Feb 2014 18:01:40 +0800 Amos Kong <[email protected]> wrote:
Quoted 89 lines · Vlad Yasevich
Quoted 67 lines · Amos Kong

Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.

This patch added a new field to @RxFilterInfo to indicate if management uses the vlan table.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html

---
V2: don't make vlan-table optional, add a flag to indicate
if vlan table is used by management

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  3 +++
 qmp-commands.hx     |  2 ++
 3 files changed, 30 insertions(+), 13 deletions(-)
hw/net/virtio-net.c +23 -5
index 3626608..f591f4e 100644
@@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
                             mac[1], mac[2], mac[3], mac[4], mac[5]);
 }
 
+static intList *get_vlan_table(VirtIONet *n)
+{
+    intList *list, *entry;
+    int i, j;
+
+    list = NULL;
+    for (i = 0; i < MAX_VLAN >> 5; i++) {
+        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
+            if (n->vlans[i] & (1U << j)) {
+                entry = g_malloc0(sizeof(*entry));
+                entry->value = (i << 5) + j;
+                entry->next = list;
+                list = entry;
+            }
+        }
+    }
+
+    return list;
+}
+
 static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     RxFilterInfo *info;
     strList *str_list, *entry;
-    intList *int_list, *int_entry;
-    int i, j;
+    int i;
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(nc->name);
@@ -273,19 +293,11 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
         str_list = entry;
     }
     info->multicast_table = str_list;
+    info->vlan_table = get_vlan_table(n);
 
-    int_list = NULL;
-    for (i = 0; i < MAX_VLAN >> 5; i++) {
-        for (j = 0; n->vlans[i] && j < 0x1f; j++) {

hw/net/virtio-net.c static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) · line 300

Quoted 10 lines
hw/net/virtio-net.c +2 -7
-            if (n->vlans[i] & (1U << j)) {
-                int_entry = g_malloc0(sizeof(*int_entry));
-                int_entry->value = (i << 5) + j;
-                int_entry->next = int_list;
-                int_list = int_entry;
-            }
-        }
+    if ((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features) {
+        info->vlan = true;
     }

So, in the case that vlan filtering is not supported in the guest we get:

             "vlan": false,
             "vlan-table": [
                 0,
                 1,
                 2,
                 ...
                 4095
            ]
Quoted 3 lines

since virtio_net now initializes the table to all 1s. Seems a bit awkward. We are providing a lot of data that is simply going to be ignored.

In Stefan's patch [1], qemu fills all vlan ids to 1, then all the packets will come to guest.

For the host device, it also should not filter out any vlan-tagged packets when VIRTIO_NET_F_CTRL_VLAN is not negotiated. We should also fill vlan ids of host device to 1, then vlan-filter of host device will not perform.

Quoted 4 lines
Quoted 2 lines

If so, we don't need my patch, just pass [0,1,2,...4095] to management as past. The new field in RxFilterInfo isn't necessary.

What's the conclusion here?

NAK my patch, it's unnecessary.

Quoted 3 lines
Quoted 3 lines

[1] [PATCH] virtio-net: Do not filter VLANs without F_CTRL_VLAN

Thanks, Amos

#6 lore raw
Quoted 106 lines · Amos Kong
Quoted 105 lines · Luiz Capitulino
Quoted 102 lines · On Fri, 21 Feb 2014 18:01:40 +0800 Amos Kong <[email protected]> wrote:
Quoted 89 lines · Vlad Yasevich
Quoted 67 lines · Amos Kong

Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.

This patch added a new field to @RxFilterInfo to indicate if management uses the vlan table.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html

---
V2: don't make vlan-table optional, add a flag to indicate
if vlan table is used by management

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  3 +++
 qmp-commands.hx     |  2 ++
 3 files changed, 30 insertions(+), 13 deletions(-)
hw/net/virtio-net.c +23 -5
index 3626608..f591f4e 100644
@@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
                             mac[1], mac[2], mac[3], mac[4], mac[5]);
 }
 
+static intList *get_vlan_table(VirtIONet *n)
+{
+    intList *list, *entry;
+    int i, j;
+
+    list = NULL;
+    for (i = 0; i < MAX_VLAN >> 5; i++) {
+        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
+            if (n->vlans[i] & (1U << j)) {
+                entry = g_malloc0(sizeof(*entry));
+                entry->value = (i << 5) + j;
+                entry->next = list;
+                list = entry;
+            }
+        }
+    }
+
+    return list;
+}
+
 static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     RxFilterInfo *info;
     strList *str_list, *entry;
-    intList *int_list, *int_entry;
-    int i, j;
+    int i;
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(nc->name);
@@ -273,19 +293,11 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
         str_list = entry;
     }
     info->multicast_table = str_list;
+    info->vlan_table = get_vlan_table(n);
 
-    int_list = NULL;
-    for (i = 0; i < MAX_VLAN >> 5; i++) {
-        for (j = 0; n->vlans[i] && j < 0x1f; j++) {

hw/net/virtio-net.c static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) · line 300

Quoted 10 lines
hw/net/virtio-net.c +2 -7
-            if (n->vlans[i] & (1U << j)) {
-                int_entry = g_malloc0(sizeof(*int_entry));
-                int_entry->value = (i << 5) + j;
-                int_entry->next = int_list;
-                int_list = int_entry;
-            }
-        }
+    if ((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features) {
+        info->vlan = true;
     }

So, in the case that vlan filtering is not supported in the guest we get:

             "vlan": false,
             "vlan-table": [
                 0,
                 1,
                 2,
                 ...
                 4095
            ]
Quoted 3 lines

since virtio_net now initializes the table to all 1s. Seems a bit awkward. We are providing a lot of data that is simply going to be ignored.

In Stefan's patch [1], qemu fills all vlan ids to 1, then all the packets will come to guest.

For the host device, it also should not filter out any vlan-tagged packets when VIRTIO_NET_F_CTRL_VLAN is not negotiated. We should also fill vlan ids of host device to 1, then vlan-filter of host device will not perform.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

If so, we don't need my patch, just pass [0,1,2,...4095] to management as past. The new field in RxFilterInfo isn't necessary.

What's the conclusion here?

NAK my patch, it's unnecessary.

I don't agree.
libvirt does not yet look at the filter info, so let's do the job properly.
https://lists.gnu.org/archive/html/qemu-devel/2014-02/msg02604.html

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

[1] [PATCH] virtio-net: Do not filter VLANs without F_CTRL_VLAN

Thanks, Amos

#7 lore raw
In reply to Vlad Yasevich
Quoted 89 lines · Vlad Yasevich
Quoted 67 lines · Amos Kong

Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.

This patch added a new field to @RxFilterInfo to indicate if management uses the vlan table.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html

---
V2: don't make vlan-table optional, add a flag to indicate
if vlan table is used by management

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  3 +++
 qmp-commands.hx     |  2 ++
 3 files changed, 30 insertions(+), 13 deletions(-)
hw/net/virtio-net.c +23 -5
index 3626608..f591f4e 100644
@@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
                             mac[1], mac[2], mac[3], mac[4], mac[5]);
 }
 
+static intList *get_vlan_table(VirtIONet *n)
+{
+    intList *list, *entry;
+    int i, j;
+
+    list = NULL;
+    for (i = 0; i < MAX_VLAN >> 5; i++) {
+        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
+            if (n->vlans[i] & (1U << j)) {
+                entry = g_malloc0(sizeof(*entry));
+                entry->value = (i << 5) + j;
+                entry->next = list;
+                list = entry;
+            }
+        }
+    }
+
+    return list;
+}
+
 static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     RxFilterInfo *info;
     strList *str_list, *entry;
-    intList *int_list, *int_entry;
-    int i, j;
+    int i;
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(nc->name);
@@ -273,19 +293,11 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
         str_list = entry;
     }
     info->multicast_table = str_list;
+    info->vlan_table = get_vlan_table(n);
 
-    int_list = NULL;
-    for (i = 0; i < MAX_VLAN >> 5; i++) {
-        for (j = 0; n->vlans[i] && j < 0x1f; j++) {

hw/net/virtio-net.c static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) · line 300

Quoted 10 lines
hw/net/virtio-net.c +2 -7
-            if (n->vlans[i] & (1U << j)) {
-                int_entry = g_malloc0(sizeof(*int_entry));
-                int_entry->value = (i << 5) + j;
-                int_entry->next = int_list;
-                int_list = int_entry;
-            }
-        }
+    if ((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features) {
+        info->vlan = true;
     }

So, in the case that vlan filtering is not supported in the guest we get:

             "vlan": false,
             "vlan-table": [
                 0,
                 1,
                 2,
                 ...
                 4095
            ]
Quoted 3 lines

since virtio_net now initializes the table to all 1s. Seems a bit awkward. We are providing a lot of data that is simply going to be ignored.

Yes - old qemu gave an empty table anyway, so I think we should keep doing that: giving an all-vlans list would help old libvirt work better with new qemu but perpetuates the bug.

Quoted 62 lines
Quoted 9 lines
hw/net/virtio-net.c +0 -1
-    info->vlan_table = int_list;
 
     /* enable event notification after query */
     nc->rxfilter_notify_enabled = 1;
qapi-schema.json +0 -0
index 7cfb5e5..5b54e94 100644

qapi-schema.json line 4036

Quoted 5 lines
qapi-schema.json +2 -0
@@ -4032,6 +4032,8 @@
 #
 # @unicast-overflow: unicast table is overflowed or not
 #
+# @vlan: whether management uses the vlan table
+#

The above description seems a bit confusing to me. The value we are returning describes whether or not qemu is performing vlan filtering. I am not sure if it has any bearing on what management may be doing.

I think the idea is that management, in the future, would look at this value and make some decision about applying provided filter to the current host configuration.

qapi-schema.json line 4057

Quoted 8 lines
qapi-schema.json +1 -0
 # @main-mac: the main macaddr string
 #
 # @vlan-table: a list of active vlan id
@@ -4052,6 +4054,7 @@
     'broadcast-allowed':  'bool',
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
+    'vlan':               'bool',

Not terribly descriptive. May be call it vlan-filter?

Thanks
-vlad

Quoted 24 lines
qapi-schema.json +0 -0
     'main-mac':           'str',
     'vlan-table':         ['int'],
     'unicast-table':      ['str'],
qmp-commands.hx +2 -0
index cce6b81..b170c79 100644
@@ -3307,6 +3307,7 @@ Each array entry contains the following:
 - "broadcast-allowed": allow to receive broadcast (json-bool)
 - "multicast-overflow": multicast table is overflowed (json-bool)
 - "unicast-overflow": unicast table is overflowed (json-bool)
+- "vlan": management uses the vlan table (json-bool)
 - "main-mac": main macaddr string (json-string)
 - "vlan-table": a json-array of active vlan id
 - "unicast-table": a json-array of unicast macaddr string
@@ -3321,6 +3322,7 @@ Example:
             "name": "vnet0",
             "main-mac": "52:54:00:12:34:56",
             "unicast": "normal",
+            "vlan": true,
             "vlan-table": [
                 4,
                 0
#8 lore raw
In reply to Amos Kong
Quoted 95 lines · Amos Kong

Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated.

This patch added a new field to @RxFilterInfo to indicate if management uses the vlan table.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html

---
V2: don't make vlan-table optional, add a flag to indicate
if vlan table is used by management

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  3 +++
 qmp-commands.hx     |  2 ++
 3 files changed, 30 insertions(+), 13 deletions(-)
hw/net/virtio-net.c +25 -13
index 3626608..f591f4e 100644
@@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
                             mac[1], mac[2], mac[3], mac[4], mac[5]);
 }
 
+static intList *get_vlan_table(VirtIONet *n)
+{
+    intList *list, *entry;
+    int i, j;
+
+    list = NULL;
+    for (i = 0; i < MAX_VLAN >> 5; i++) {
+        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
+            if (n->vlans[i] & (1U << j)) {
+                entry = g_malloc0(sizeof(*entry));
+                entry->value = (i << 5) + j;
+                entry->next = list;
+                list = entry;
+            }
+        }
+    }
+
+    return list;
+}
+
 static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
     RxFilterInfo *info;
     strList *str_list, *entry;
-    intList *int_list, *int_entry;
-    int i, j;
+    int i;
 
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(nc->name);
@@ -273,19 +293,11 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
         str_list = entry;
     }
     info->multicast_table = str_list;
+    info->vlan_table = get_vlan_table(n);
 
-    int_list = NULL;
-    for (i = 0; i < MAX_VLAN >> 5; i++) {
-        for (j = 0; n->vlans[i] && j < 0x1f; j++) {
-            if (n->vlans[i] & (1U << j)) {
-                int_entry = g_malloc0(sizeof(*int_entry));
-                int_entry->value = (i << 5) + j;
-                int_entry->next = int_list;
-                int_list = int_entry;
-            }
-        }
+    if ((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features) {
+        info->vlan = true;
     }
-    info->vlan_table = int_list;
 
     /* enable event notification after query */
     nc->rxfilter_notify_enabled = 1;
qapi-schema.json +2 -0
index 7cfb5e5..5b54e94 100644
@@ -4032,6 +4032,8 @@
 #
 # @unicast-overflow: unicast table is overflowed or not
 #
+# @vlan: whether management uses the vlan table
+#
 # @main-mac: the main macaddr string
 #
 # @vlan-table: a list of active vlan id

qapi-schema.json line 4057

Quoted 4 lines
qapi-schema.json +1 -0
@@ -4052,6 +4054,7 @@
     'broadcast-allowed':  'bool',
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
+    'vlan':               'bool',

bool looks wrong to me.
Should be RxState

qmp-commands.hx Each array entry contains the following: · line 3310

Quoted 12 lines
qapi-schema.json +0 -0
     'main-mac':           'str',
     'vlan-table':         ['int'],
     'unicast-table':      ['str'],
qmp-commands.hx +1 -0
index cce6b81..b170c79 100644
@@ -3307,6 +3307,7 @@ Each array entry contains the following:
 - "broadcast-allowed": allow to receive broadcast (json-bool)
 - "multicast-overflow": multicast table is overflowed (json-bool)
 - "unicast-overflow": unicast table is overflowed (json-bool)
+- "vlan": management uses the vlan table (json-bool)

Nothing to do with management.
should be 'vlan receive state'

qmp-commands.hx Example: · line 3325

Quoted 8 lines
qmp-commands.hx +1 -0
 - "main-mac": main macaddr string (json-string)
 - "vlan-table": a json-array of active vlan id
 - "unicast-table": a json-array of unicast macaddr string
@@ -3321,6 +3322,7 @@ Example:
             "name": "vnet0",
             "main-mac": "52:54:00:12:34:56",
             "unicast": "normal",
+            "vlan": true,

"vlan": "normal"

qmp-commands.hx Example: · line 3328

Quoted 3 lines
qmp-commands.hx +0 -0
             "vlan-table": [
                 4,
                 0

Really vlan filtering is just like unicast filtering, except there's a smaller number of vlans so we don't (yet) have an "overflow" flag.

If you want to be proactive and add vlan_overflow in case we emulate hardware with limited # of vlans supported, that's also fine by me.

Quoted 3 lines
Signature · 1 line
1.8.5.3