[PATCH 36/37] virDomainNetDefParseXML: Parse attributes of <mac> only when present

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Access the 'mac_node' variable only when it was filled.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 48 +++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2a266ac6c9..d3755547c7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9321,37 +9321,37 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
     if ((tap = virXPathString("string(./backend/@tap)", ctxt)))
         def->backend.tap = virFileSanitizePath(tap);

-    mac_node = virXPathNode("./mac", ctxt);
+    if ((mac_node = virXPathNode("./mac", ctxt))) {
+        if ((macaddr = virXMLPropString(mac_node, "address"))) {
+            if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("unable to parse mac address '%s'"),
+                               (const char *)macaddr);
+                return NULL;
+            }
+            if (virMacAddrIsMulticast(&def->mac)) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("expected unicast mac address, found multicast '%s'"),
+                               (const char *)macaddr);
+                return NULL;
+            }
+        }

-    if ((macaddr = virXMLPropString(mac_node, "address"))) {
-        if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("unable to parse mac address '%s'"),
-                           (const char *)macaddr);
+        if (virXMLPropEnum(mac_node, "type",
+                           virDomainNetMacTypeTypeFromString,
+                           VIR_XML_PROP_NONZERO, &def->mac_type) < 0)
             return NULL;
-        }
-        if (virMacAddrIsMulticast(&def->mac)) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("expected unicast mac address, found multicast '%s'"),
-                           (const char *)macaddr);
+
+        if (virXMLPropTristateBool(mac_node, "check", VIR_XML_PROP_NONE,
+                                   &def->mac_check) < 0)
             return NULL;
-        }
-    } else {
+    }
+
+    if (!macaddr) {
         virDomainNetGenerateMAC(xmlopt, &def->mac);
         def->mac_generated = true;
     }

-    if (virXMLPropEnum(mac_node, "type",
-                       virDomainNetMacTypeTypeFromString,
-                       VIR_XML_PROP_NONZERO,
-                       &def->mac_type) < 0)
-        return NULL;
-
-    if (virXMLPropTristateBool(mac_node, "check",
-                               VIR_XML_PROP_NONE,
-                               &def->mac_check) < 0)
-        return NULL;
-
     if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info,
                                     flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT
                                     | VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) < 0) {
-- 
2.37.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux