[libvirt PATCH 09/14] virInterfaceDefParseDhcp: Simplify and cleanup

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

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/conf/interface_conf.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index 0b3e5716f3..bfeb69e664 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -226,24 +226,18 @@ virInterfaceDefParseBondArpValid(xmlXPathContextPtr ctxt)
 
 static int
 virInterfaceDefParseDhcp(virInterfaceProtocolDef *def,
-                         xmlNodePtr dhcp, xmlXPathContextPtr ctxt)
+                         xmlNodePtr dhcp)
 {
-    VIR_XPATH_NODE_AUTORESTORE(ctxt)
-    g_autofree char *tmp = NULL;
+    virTristateBool peerdns;
 
     def->dhcp = 1;
-    ctxt->node = dhcp;
     def->peerdns = -1;
-    /* Not much to do in the current version */
-    tmp = virXPathString("string(./@peerdns)", ctxt);
-    if (tmp) {
-        bool state = false;
-        if (virStringParseYesNo(tmp, &state) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("unknown dhcp peerdns value %s"), tmp);
-            return -1;
-        }
-        def->peerdns = state ? 1 : 0;
+
+    if (virXMLPropTristateBool(dhcp, "peerdns", VIR_XML_PROP_NONZERO, &peerdns) < 0)
+        return -1;
+
+    if (peerdns != VIR_TRISTATE_BOOL_ABSENT) {
+        def->peerdns = peerdns == VIR_TRISTATE_BOOL_YES ? 1 : 0;
     }
 
     return 0;
@@ -279,7 +273,7 @@ virInterfaceDefParseProtoIPv4(virInterfaceProtocolDef *def,
 
     dhcp = virXPathNode("./dhcp", ctxt);
     if (dhcp != NULL) {
-        if (virInterfaceDefParseDhcp(def, dhcp, ctxt) < 0)
+        if (virInterfaceDefParseDhcp(def, dhcp) < 0)
             return -1;
     }
 
@@ -328,7 +322,7 @@ virInterfaceDefParseProtoIPv6(virInterfaceProtocolDef *def,
 
     dhcp = virXPathNode("./dhcp", ctxt);
     if (dhcp != NULL) {
-        if (virInterfaceDefParseDhcp(def, dhcp, ctxt) < 0)
+        if (virInterfaceDefParseDhcp(def, dhcp) < 0)
             return -1;
     }
 
-- 
2.31.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