Yanqiu Zhang reported [1] that when a vlan is defined with a single
vlan id and native mode set to tagged, the vlan was not setup correctly
using the standard Linux bridge functionality. This is due a conflict
between the XML validation and the bridge functionality.

The XML validation will allow a single vlan id to be configured with
native mode set to tagged without setting the vlan mode to trunked. If
the vlan is explicitly set to "trunk='no'" then the validation will
correctly reject the configuration.

Rather than force the user to specify "trunk='yes'", update the code to
infer trunk='yes' if a single vlan id is configured with native mode set
to a non-default value. It already infers trunk='yes' if more than one
vlan id is specified.

Reported-by: Yanqiu Zhang <yanqz...@redhat.com>
Closes: https://gitlab.com/libvirt/libvirt/-/issues/767 [1]
Signed-off-by: Leigh Brown <le...@solinno.co.uk>
---
 src/conf/netdev_vlan_conf.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/conf/netdev_vlan_conf.c b/src/conf/netdev_vlan_conf.c
index 1ac66aec54..300d0d8e86 100644
--- a/src/conf/netdev_vlan_conf.c
+++ b/src/conf/netdev_vlan_conf.c
@@ -87,12 +87,13 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr 
ctxt, virNetDevVlan *def)
 
     def->nTags = nTags;
 
-    /* now that we know how many tags there are, look for an explicit
-     * trunk setting.
+    /* In case the trunk attribute is not specified, infer it from
+     * the number of tags or use of native vlan mode.
      */
-    if (nTags > 1)
+    if (nTags > 1 || def->nativeMode != 0)
         def->trunk = true;
 
+    /* Look for and validate an explicit trunk setting. */
     ctxt->node = node;
     if ((trunk = virXPathString("string(./@trunk)", ctxt)) != NULL) {
         def->trunk = STRCASEEQ(trunk, "yes");
-- 
2.49.0

Reply via email to