]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
network: Allow adding DNS entries sharing hostname for multiple addreses
authorPeter Krempa <pkrempa@redhat.com>
Wed, 14 Jul 2021 10:58:12 +0000 (12:58 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 16 Jul 2021 12:50:57 +0000 (14:50 +0200)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/network_conf.c
tests/networkxml2xmlin/nat-network-dns-hosts.xml
tests/networkxml2xmlout/nat-network-dns-hosts.xml
tests/networkxml2xmlupdateout/nat-network-dns-more-hosts.xml
tests/networkxml2xmlupdateout/nat-network-no-hosts.xml

index b10ff5c7a8f17d86c9f7896da3d2e40103daaa0f..fe9919d4ceba86c596b92f816850b9d2e1954eaa 100644 (file)
@@ -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;
index 58608f6959c88e0525e5552841846d76ef44d727..c28ebd8c4bdb02e28f2b1649ad687e615c4e476c 100644 (file)
@@ -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>
index 7c561aad2a31b63a4fa59735884361eed8f80f24..86832af5186e00e22c69969cfc6223f49ee17b08 100644 (file)
@@ -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>
index dfc12eb2f904830367b5dd8d914e6b30da8b6b86..7b8a451b67511ce8908425b2f320b0d46f50e416 100644 (file)
@@ -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>
index 7cff9edc093be6a29dd2d68a1335fedf12e6c33a..679575973c31914be60329a7e3a958902cc189d8 100644 (file)
@@ -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>