Skip to contentSkip to conversation

virtio-net: only output the vlan table when VIRTIO_NET_F_CTRL_VLAN is negotiated

PATCH In review Amos Kong 4 participants 7 messages Feb 17, 2014 – Feb 18, 2014

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH 1/1 virtio-net: only output the vlan table when VIRTIO_NET_F_CTRL_VLAN is negotiated

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.

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

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

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  4 ++--
 qmp-commands.hx     |  2 +-
 3 files changed, 28 insertions(+), 16 deletions(-)
hw/net/virtio-net.c +25 -13
index 3626608..0b32e6a 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);
@@ -274,18 +294,10 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
     }
     info->multicast_table = str_list;
 
-    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->has_vlan_table = true;
+        info->vlan_table = get_vlan_table(n);
     }
-    info->vlan_table = int_list;
 
     /* enable event notification after query */
     nc->rxfilter_notify_enabled = 1;
qapi-schema.json +2 -2
index 7cfb5e5..5d48fa9 100644
@@ -4034,7 +4034,7 @@
 #
 # @main-mac: the main macaddr string
 #
-# @vlan-table: a list of active vlan id
+# @vlan-table: #optional a list of active vlan id
 #
 # @unicast-table: a list of unicast macaddr string
 #
@@ -4053,7 +4053,7 @@
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
     'main-mac':           'str',
-    'vlan-table':         ['int'],
+    '*vlan-table':         ['int'],
     'unicast-table':      ['str'],
     'multicast-table':    ['str'] }}
 
qmp-commands.hx +1 -1
index cce6b81..a1c1dfa 100644
@@ -3308,7 +3308,7 @@ Each array entry contains the following:
 - "multicast-overflow": multicast table is overflowed (json-bool)
 - "unicast-overflow": unicast table is overflowed (json-bool)
 - "main-mac": main macaddr string (json-string)
-- "vlan-table": a json-array of active vlan id
+- "vlan-table": a json-array of active vlan id (optoinal)
 - "unicast-table": a json-array of unicast macaddr string
 - "multicast-table": a json-array of multicast macaddr string
 
Signature · 1 line
1.8.5.3
#1 lore raw
Quoted 5 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.

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

      ^^^^^^^^^^
       table.

One question I have from the API perspective is can we suddenly change something to be optional? If there are any users of this , wouldn't they have to change now to check the existence of this list?

Thanks
-vlad

Quoted 108 lines

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

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  4 ++--
 qmp-commands.hx     |  2 +-
 3 files changed, 28 insertions(+), 16 deletions(-)
hw/net/virtio-net.c +25 -13
index 3626608..0b32e6a 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);
@@ -274,18 +294,10 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
     }
     info->multicast_table = str_list;
 
-    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->has_vlan_table = true;
+        info->vlan_table = get_vlan_table(n);
     }
-    info->vlan_table = int_list;
 
 
     /* enable event notification after query */
     nc->rxfilter_notify_enabled = 1;
qapi-schema.json +2 -2
index 7cfb5e5..5d48fa9 100644
@@ -4034,7 +4034,7 @@
 #
 # @main-mac: the main macaddr string
 #
-# @vlan-table: a list of active vlan id
+# @vlan-table: #optional a list of active vlan id
 #
 # @unicast-table: a list of unicast macaddr string
 #
@@ -4053,7 +4053,7 @@
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
     'main-mac':           'str',
-    'vlan-table':         ['int'],
+    '*vlan-table':         ['int'],
     'unicast-table':      ['str'],
     'multicast-table':    ['str'] }}
 
qmp-commands.hx +1 -1
index cce6b81..a1c1dfa 100644
@@ -3308,7 +3308,7 @@ Each array entry contains the following:
 - "multicast-overflow": multicast table is overflowed (json-bool)
 - "unicast-overflow": unicast table is overflowed (json-bool)
 - "main-mac": main macaddr string (json-string)
-- "vlan-table": a json-array of active vlan id
+- "vlan-table": a json-array of active vlan id (optoinal)
 - "unicast-table": a json-array of unicast macaddr string
 - "multicast-table": a json-array of multicast macaddr string
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Amos Kong
Quoted 5 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.

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

s/talbe/table/

Quoted 22 lines

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

---
 hw/net/virtio-net.c | 38 +++++++++++++++++++++++++-------------
 qapi-schema.json    |  4 ++--
 qmp-commands.hx     |  2 +-
 3 files changed, 28 insertions(+), 16 deletions(-)

+++ b/qapi-schema.json

qapi-schema.json +1 -1
@@ -4034,7 +4034,7 @@
 #
 # @main-mac: the main macaddr string
 #
-# @vlan-table: a list of active vlan id
+# @vlan-table: #optional a list of active vlan id
 #
 # @unicast-table: a list of unicast macaddr string
 #

qapi-schema.json line 4056

Quoted 5 lines
qapi-schema.json +1 -1
@@ -4053,7 +4053,7 @@
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
     'main-mac':           'str',
-    'vlan-table':         ['int'],
+    '*vlan-table':         ['int'],

Indentation is now off.

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

Quoted 3 lines
qmp-commands.hx +1 -1
 - "main-mac": main macaddr string (json-string)
-- "vlan-table": a json-array of active vlan id
+- "vlan-table": a json-array of active vlan id (optoinal)

s/optoinal/optional/

Those fixes are trivial enough, so I'm okay if you correct them then add:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw
Quoted 19 lines · Eric Blake
Quoted 5 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.

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

s/talbe/table/

qapi-schema.json line 4056

Quoted 6 lines
qapi-schema.json +1 -1
@@ -4053,7 +4053,7 @@
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
     'main-mac':           'str',
-    'vlan-table':         ['int'],
+    '*vlan-table':         ['int'],

Indentation is now off.

Quoted 7 lines

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

Quoted 3 lines
qmp-commands.hx +1 -1
 - "main-mac": main macaddr string (json-string)
-- "vlan-table": a json-array of active vlan id
+- "vlan-table": a json-array of active vlan id (optoinal)

s/optoinal/optional/

Those fixes are trivial enough, so I'm okay if you correct them then add:

Scratch that. I revoke my R-b, on the following grounds:

Quoted 3 lines · Vlad Yasevich
Quoted 2 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.

Quoted 10 lines
Quoted 3 lines

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

      ^^^^^^^^^^
       table.

One question I have from the API perspective is can we suddenly change something to be optional? If there are any users of this , wouldn't they have to change now to check the existence of this list?

You are correct. Since the parameter is an output field, older clients may be depending on it existing. It is okay to generate an empty array, but you must not entirely omit the array unless you add further justification in your commit message that you are 100% positive that there are no clients of 1.6 that will be broken when the array no longer appears in the output.

Can you rework the patch to just leave the array empty in the case where the bit does not indicate it is used? Or do we need to add a new bool field to the output for new enough management to know whether to use the array?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw
Quoted 53 lines · Eric Blake
Quoted 19 lines · Eric Blake
Quoted 5 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.

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

s/talbe/table/

qapi-schema.json line 4056

Quoted 6 lines
qapi-schema.json +1 -1
@@ -4053,7 +4053,7 @@
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
     'main-mac':           'str',
-    'vlan-table':         ['int'],
+    '*vlan-table':         ['int'],

Indentation is now off.

Quoted 7 lines

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

Quoted 3 lines
qmp-commands.hx +1 -1
 - "main-mac": main macaddr string (json-string)
-- "vlan-table": a json-array of active vlan id
+- "vlan-table": a json-array of active vlan id (optoinal)

s/optoinal/optional/

Those fixes are trivial enough, so I'm okay if you correct them then add:

Scratch that. I revoke my R-b, on the following grounds:

Quoted 3 lines · Vlad Yasevich
Quoted 2 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.

Quoted 10 lines
Quoted 3 lines

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

      ^^^^^^^^^^
       table.

One question I have from the API perspective is can we suddenly change something to be optional? If there are any users of this , wouldn't they have to change now to check the existence of this list?

You are correct. Since the parameter is an output field, older clients may be depending on it existing. It is okay to generate an empty array, but you must not entirely omit the array unless you add further justification in your commit message that you are 100% positive that there are no clients of 1.6 that will be broken when the array no longer appears in the output.

Quoted 5 lines

Can you rework the patch to just leave the array empty in the case where the bit does not indicate it is used? Or do we need to add a new bool field to the output for new enough management to know whether to use the array?

I think a completely empty array should be sufficient.

-vlad

#5 lore raw
Quoted 60 lines · Vlad Yasevich
Quoted 53 lines · Eric Blake
Quoted 19 lines · Eric Blake
Quoted 5 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.

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

s/talbe/table/

qapi-schema.json line 4056

Quoted 6 lines
qapi-schema.json +1 -1
@@ -4053,7 +4053,7 @@
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
     'main-mac':           'str',
-    'vlan-table':         ['int'],
+    '*vlan-table':         ['int'],

Indentation is now off.

Quoted 7 lines

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

Quoted 3 lines
qmp-commands.hx +1 -1
 - "main-mac": main macaddr string (json-string)
-- "vlan-table": a json-array of active vlan id
+- "vlan-table": a json-array of active vlan id (optoinal)

s/optoinal/optional/

Those fixes are trivial enough, so I'm okay if you correct them then add:

Scratch that. I revoke my R-b, on the following grounds:

Quoted 3 lines · Vlad Yasevich
Quoted 2 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.

Quoted 10 lines
Quoted 3 lines

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

      ^^^^^^^^^^
       table.

One question I have from the API perspective is can we suddenly change something to be optional? If there are any users of this , wouldn't they have to change now to check the existence of this list?

You are correct. Since the parameter is an output field, older clients may be depending on it existing. It is okay to generate an empty array, but you must not entirely omit the array unless you add further justification in your commit message that you are 100% positive that there are no clients of 1.6 that will be broken when the array no longer appears in the output.

Quoted 5 lines

Can you rework the patch to just leave the array empty in the case where the bit does not indicate it is used? Or do we need to add a new bool field to the output for new enough management to know whether to use the array?

Quoted 3 lines

I think a completely empty array should be sufficient.

-vlad

An empty array could mean either no vlans allowed or all vlans allowed. Also it's nice if users can detect an old buggy qemu.

Let's just add an rx state.

#6 lore raw
Quoted 63 lines · Michael S. Tsirkin
Quoted 62 lines · Vlad Yasevich
Quoted 53 lines · Eric Blake
Quoted 19 lines · Eric Blake
Quoted 5 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.

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

s/talbe/table/

qapi-schema.json line 4056

Quoted 6 lines
qapi-schema.json +1 -1
@@ -4053,7 +4053,7 @@
     'multicast-overflow': 'bool',
     'unicast-overflow':   'bool',
     'main-mac':           'str',
-    'vlan-table':         ['int'],
+    '*vlan-table':         ['int'],

Indentation is now off.

Quoted 7 lines

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

Quoted 3 lines
qmp-commands.hx +1 -1
 - "main-mac": main macaddr string (json-string)
-- "vlan-table": a json-array of active vlan id
+- "vlan-table": a json-array of active vlan id (optoinal)

s/optoinal/optional/

Those fixes are trivial enough, so I'm okay if you correct them then add:

Scratch that. I revoke my R-b, on the following grounds:

Quoted 3 lines · Vlad Yasevich
Quoted 2 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.

Quoted 10 lines
Quoted 3 lines

We should also not send the vlan table to management, this patch makes the vlan-talbe optional.

      ^^^^^^^^^^
       table.

One question I have from the API perspective is can we suddenly change something to be optional? If there are any users of this , wouldn't they have to change now to check the existence of this list?

You are correct. Since the parameter is an output field, older clients may be depending on it existing. It is okay to generate an empty array, but you must not entirely omit the array unless you add further justification in your commit message that you are 100% positive that there are no clients of 1.6 that will be broken when the array no longer appears in the output.

Quoted 5 lines

Can you rework the patch to just leave the array empty in the case where the bit does not indicate it is used? Or do we need to add a new bool field to the output for new enough management to know whether to use the array?

I think a completely empty array should be sufficient.

Quoted 8 lines
Quoted 1 line

-vlad

An empty array could mean either no vlans allowed or all vlans allowed. Also it's nice if users can detect an old buggy qemu.

Let's just add an rx state.

Fine with me.

-vlad