[PATCH 2/2] network: Allow adding DNS entries sharing hostname for multiple addreses

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

 



Having multiple addresses having same hostname is a common config either
to have IPv4 and IPv6 address for the same hostname or even for DNS
round robin. The validation in the network update code didn't allow
adding such entries despite the fact that it is possible to define a
network with them.

Don't check hostname duplicity when adding a DNS entry.

The update of the test case adds another entry for the 'pudding'
hostname which is added in one of the networkxml2xmlupdate test cases.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/network_conf.c                             | 13 +++++++++----
 tests/networkxml2xmlin/nat-network-dns-hosts.xml    |  3 +++
 tests/networkxml2xmlout/nat-network-dns-hosts.xml   |  3 +++
 .../nat-network-dns-more-hosts.xml                  |  3 +++
 .../nat-network-no-hosts.xml                        |  3 +++
 5 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index b10ff5c7a8..fe9919d4ce 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -3404,12 +3404,17 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def,
         if (virSocketAddrEqual(&host.ip, &dns->hosts[i].ip))
             foundThisTime = true;

-        for (j = 0; j < host.nnames && !foundThisTime; j++) {
-            for (k = 0; k < dns->hosts[i].nnames && !foundThisTime; k++) {
-                if (STREQ(host.names[j], dns->hosts[i].names[k]))
-                    foundThisTime = true;
+        /* when adding we want to only check duplicates of address since having
+         * multiple addresses with the same hostname is a legitimate configuration */
+        if (!isAdd) {
+            for (j = 0; j < host.nnames && !foundThisTime; j++) {
+                for (k = 0; k < dns->hosts[i].nnames && !foundThisTime; k++) {
+                    if (STREQ(host.names[j], dns->hosts[i].names[k]))
+                        foundThisTime = true;
+                }
             }
         }
+
         if (foundThisTime) {
             foundCt++;
             foundIdx = i;
diff --git a/tests/networkxml2xmlin/nat-network-dns-hosts.xml b/tests/networkxml2xmlin/nat-network-dns-hosts.xml
index 58608f6959..c28ebd8c4b 100644
--- a/tests/networkxml2xmlin/nat-network-dns-hosts.xml
+++ b/tests/networkxml2xmlin/nat-network-dns-hosts.xml
@@ -4,6 +4,9 @@
   <forward dev='eth0' mode='nat'/>
   <bridge name='virbr0' stp='on' delay='0'/>
   <dns forwardPlainNames='no'>
+    <host ip='192.168.122.122'>
+      <hostname>pudding</hostname>
+    </host>
     <host ip='192.168.122.1'>
       <hostname>host</hostname>
       <hostname>gateway</hostname>
diff --git a/tests/networkxml2xmlout/nat-network-dns-hosts.xml b/tests/networkxml2xmlout/nat-network-dns-hosts.xml
index 7c561aad2a..86832af518 100644
--- a/tests/networkxml2xmlout/nat-network-dns-hosts.xml
+++ b/tests/networkxml2xmlout/nat-network-dns-hosts.xml
@@ -6,6 +6,9 @@
   </forward>
   <bridge name='virbr0' stp='on' delay='0'/>
   <dns forwardPlainNames='no'>
+    <host ip='192.168.122.122'>
+      <hostname>pudding</hostname>
+    </host>
     <host ip='192.168.122.1'>
       <hostname>host</hostname>
       <hostname>gateway</hostname>
diff --git a/tests/networkxml2xmlupdateout/nat-network-dns-more-hosts.xml b/tests/networkxml2xmlupdateout/nat-network-dns-more-hosts.xml
index dfc12eb2f9..7b8a451b67 100644
--- a/tests/networkxml2xmlupdateout/nat-network-dns-more-hosts.xml
+++ b/tests/networkxml2xmlupdateout/nat-network-dns-more-hosts.xml
@@ -9,6 +9,9 @@
     <host ip='f0:d::f0:d'>
       <hostname>pudding</hostname>
     </host>
+    <host ip='192.168.122.122'>
+      <hostname>pudding</hostname>
+    </host>
     <host ip='192.168.122.1'>
       <hostname>host</hostname>
       <hostname>gateway</hostname>
diff --git a/tests/networkxml2xmlupdateout/nat-network-no-hosts.xml b/tests/networkxml2xmlupdateout/nat-network-no-hosts.xml
index 7cff9edc09..679575973c 100644
--- a/tests/networkxml2xmlupdateout/nat-network-no-hosts.xml
+++ b/tests/networkxml2xmlupdateout/nat-network-no-hosts.xml
@@ -6,6 +6,9 @@
   </forward>
   <bridge name='virbr0' stp='on' delay='0'/>
   <dns forwardPlainNames='no'>
+    <host ip='192.168.122.122'>
+      <hostname>pudding</hostname>
+    </host>
     <host ip='192.168.122.2'>
       <hostname>shared</hostname>
       <hostname>names</hostname>
-- 
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