[PATCH 3/5] bridge_driver: make the dnsmasq comand line more exact

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

 



bridge_driver.c: Only the service and potocol are mandatory argument.
If domain or target is not supplied in xml, we should not include the period
and comma in command line, so we don't provide them in dnsmasq
command line and leave the work to dnsmasq.

<srv service='kerberos' protocol='tcp'/>
before:
 --srv-host=kerberos.tcp..,,,
It will report error in this case

after:
 --srv-host=_kerberos._tcp

network_conf.c: Because we initialized these three values, we should
dumpxml their values anytime.
---
 src/conf/network_conf.c     |   31 +++++++++++++++--------------
 src/network/bridge_driver.c |   44 ++++++++++++++++++++++++++++++------------
 2 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index f6694ed..99c6fc1 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -755,8 +755,10 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
     char *value = NULL;
     virNetworkDNSDefPtr def = NULL;
 
-    if (VIR_ALLOC(def) < 0)
-        goto no_memory;
+    if (VIR_ALLOC(def) < 0) {
+        virReportOOMError();
+        goto error;
+    }
 
     if ((n = virXPathNodeSet("./dns/srv", ctxt, &nodes)) < 0) {
         virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
@@ -764,8 +766,10 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
         goto error;
     }
 
-    if (n && VIR_REALLOC_N(def->srvrecords, def->nsrvrecords + n) < 0)
-        goto no_memory;
+    if (n && VIR_REALLOC_N(def->srvrecords, def->nsrvrecords + n) < 0) {
+        virReportOOMError();
+        goto error;
+    }
     for (i = 0; i < n; i++) {
         virNetworkDNSSrvRecordsDefPtr srv;
 
@@ -798,8 +802,10 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
                 goto error;
             }
 
-            if (VIR_REALLOC_N(def->txtrecords, def->ntxtrecords + 1) < 0)
-                goto no_memory;
+            if (VIR_REALLOC_N(def->txtrecords, def->ntxtrecords + 1) < 0) {
+                virReportOOMError();
+                goto error;
+            }
 
             def->txtrecords[def->ntxtrecords].name = name;
             def->txtrecords[def->ntxtrecords].value = value;
@@ -817,9 +823,6 @@ virNetworkDNSDefParseXML(virNetworkDNSDefPtr *dnsdef,
     }
 
     ret = 0;
-no_memory:
-    virReportOOMError();
-
 error:
     if (ret < 0) {
         VIR_FREE(name);
@@ -1412,12 +1415,10 @@ virNetworkDNSDefFormat(virBufferPtr buf,
                 virBufferAsprintf(buf, " domain='%s'", def->srvrecords[i]->domain);
             if (def->srvrecords[i]->target)
                 virBufferAsprintf(buf, " target='%s'", def->srvrecords[i]->target);
-            if (def->srvrecords[i]->port)
-                virBufferAsprintf(buf, " port='%d'", def->srvrecords[i]->port);
-            if (def->srvrecords[i]->priority)
-                virBufferAsprintf(buf, " priority='%d'", def->srvrecords[i]->priority);
-            if (def->srvrecords[i]->weight)
-                virBufferAsprintf(buf, " weight='%d'", def->srvrecords[i]->weight);
+
+            virBufferAsprintf(buf, " port='%d'", def->srvrecords[i]->port);
+            virBufferAsprintf(buf, " priority='%d'", def->srvrecords[i]->priority);
+            virBufferAsprintf(buf, " weight='%d'", def->srvrecords[i]->weight);
 
             virBufferAsprintf(buf, "/>\n");
         }
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index df999b9..95a9b96 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -459,6 +459,8 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
     int r, ret = -1;
     int nbleases = 0;
     int ii;
+    char *domain = NULL;
+    char *target = NULL;
     char *record = NULL;
     char *recordPort = NULL;
     char *recordWeight = NULL;
@@ -527,38 +529,52 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
 
         for (i = 0; i < dns->nsrvrecords; i++) {
             if (dns->srvrecords[i]->service && dns->srvrecords[i]->protocol) {
-                if (dns->srvrecords[i]->port) {
-                    if (virAsprintf(&recordPort, "%d", dns->srvrecords[i]->port) < 0) {
+                if (dns->srvrecords[i]->domain) {
+                    if (virAsprintf(&domain, ".%s",
+                                    dns->srvrecords[i]->domain) < 0) {
                         virReportOOMError();
                         goto cleanup;
                     }
                 }
-                if (dns->srvrecords[i]->priority) {
-                    if (virAsprintf(&recordPriority, "%d", dns->srvrecords[i]->priority) < 0) {
+
+                if (dns->srvrecords[i]->target) {
+                    if (virAsprintf(&target, ",%s",
+                                    dns->srvrecords[i]->target) < 0) {
                         virReportOOMError();
                         goto cleanup;
                     }
-                }
-                if (dns->srvrecords[i]->weight) {
-                    if (virAsprintf(&recordWeight, "%d", dns->srvrecords[i]->weight) < 0) {
+                    if (virAsprintf(&recordPort, ",%d",
+                                    dns->srvrecords[i]->port) < 0) {
+                        virReportOOMError();
+                        goto cleanup;
+                    }
+                    if (virAsprintf(&recordPriority, ",%d",
+                                    dns->srvrecords[i]->priority) < 0) {
+                        virReportOOMError();
+                        goto cleanup;
+                    }
+                    if (virAsprintf(&recordWeight, ",%d",
+                                    dns->srvrecords[i]->weight) < 0) {
                         virReportOOMError();
                         goto cleanup;
                     }
                 }
 
-                if (virAsprintf(&record, "%s.%s.%s,%s,%s,%s,%s",
+                if (virAsprintf(&record, "%s.%s%s%s%s%s%s",
                                 dns->srvrecords[i]->service,
                                 dns->srvrecords[i]->protocol,
-                                dns->srvrecords[i]->domain   ? dns->srvrecords[i]->domain : "",
-                                dns->srvrecords[i]->target   ? dns->srvrecords[i]->target : "",
-                                recordPort                  ? recordPort                : "",
-                                recordPriority              ? recordPriority            : "",
-                                recordWeight                ? recordWeight              : "") < 0) {
+                                domain            ? domain         : "",
+                                target            ? target         : "",
+                                recordPort        ? recordPort     : "",
+                                recordPriority    ? recordPriority : "",
+                                recordWeight      ? recordWeight   : "") < 0) {
                     virReportOOMError();
                     goto cleanup;
                 }
 
                 virCommandAddArgPair(cmd, "--srv-host", record);
+                VIR_FREE(domain);
+                VIR_FREE(target);
                 VIR_FREE(record);
                 VIR_FREE(recordPort);
                 VIR_FREE(recordWeight);
@@ -666,6 +682,8 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
 
     ret = 0;
 cleanup:
+    VIR_FREE(domain);
+    VIR_FREE(target);
     VIR_FREE(record);
     VIR_FREE(recordPort);
     VIR_FREE(recordWeight);
-- 
1.7.7.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]