render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7a3408
From 82e798b603e50a2177f485294cb984590627c504 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <82e798b603e50a2177f485294cb984590627c504@dist-git>
7a3408
From: Martin Kletzander <mkletzan@redhat.com>
7a3408
Date: Tue, 11 Aug 2015 13:13:13 -0400
7a3408
Subject: [PATCH] conf: Don't try formating non-existing addresses
7a3408
7a3408
Commit a6f9af8292b6 added checking for address colisions between
7a3408
starting and ending addresses of forwarding addresses, but forgot that
7a3408
there might be no addresses set at all.
7a3408
7a3408
This fixes an error in the original patch for:
7a3408
7a3408
  https://bugzilla.redhat.com/show_bug.cgi?id=985653
7a3408
7a3408
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7a3408
(cherry picked from commit 1f24c1494a85d663fa36047922a7974a292a46a7)
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/conf/network_conf.c                            | 23 ++++++++++++++++---
7a3408
 .../nat-network-forward-nat-no-address.xml         | 25 +++++++++++++++++++++
7a3408
 .../nat-network-forward-nat-no-address.xml         | 26 ++++++++++++++++++++++
7a3408
 tests/networkxml2xmltest.c                         |  1 +
7a3408
 4 files changed, 72 insertions(+), 3 deletions(-)
7a3408
 create mode 100644 tests/networkxml2xmlin/nat-network-forward-nat-no-address.xml
7a3408
 create mode 100644 tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml
7a3408
7a3408
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
7a3408
index b03c2fd..e765c65 100644
7a3408
--- a/src/conf/network_conf.c
7a3408
+++ b/src/conf/network_conf.c
7a3408
@@ -1729,9 +1729,26 @@ virNetworkForwardNatDefParseXML(const char *networkName,
7a3408
         goto cleanup;
7a3408
     }
7a3408
 
7a3408
-    /* verify that start <= end */
7a3408
-    if (virSocketAddrGetRange(&def->addr.start, &def->addr.end, NULL, 0) < 0)
7a3408
-        goto cleanup;
7a3408
+    if (addrStart && addrEnd) {
7a3408
+        /* verify that start <= end */
7a3408
+        if (virSocketAddrGetRange(&def->addr.start, &def->addr.end, NULL, 0) < 0)
7a3408
+            goto cleanup;
7a3408
+    } else {
7a3408
+        if (addrStart) {
7a3408
+            virReportError(VIR_ERR_XML_ERROR,
7a3408
+                           _("Only start address '%s' specified in <nat> in "
7a3408
+                             "<forward> in network '%s'"),
7a3408
+                           addrStart, networkName);
7a3408
+            goto cleanup;
7a3408
+        }
7a3408
+        if (addrEnd) {
7a3408
+            virReportError(VIR_ERR_XML_ERROR,
7a3408
+                           _("Only end address '%s' specified in <nat> in "
7a3408
+                             "<forward> in network '%s'"),
7a3408
+                           addrEnd, networkName);
7a3408
+            goto cleanup;
7a3408
+        }
7a3408
+    }
7a3408
 
7a3408
     /* ports for SNAT and MASQUERADE */
7a3408
     nNatPorts = virXPathNodeSet("./port", ctxt, &natPortNodes);
7a3408
diff --git a/tests/networkxml2xmlin/nat-network-forward-nat-no-address.xml b/tests/networkxml2xmlin/nat-network-forward-nat-no-address.xml
7a3408
new file mode 100644
7a3408
index 0000000..97a6452
7a3408
--- /dev/null
7a3408
+++ b/tests/networkxml2xmlin/nat-network-forward-nat-no-address.xml
7a3408
@@ -0,0 +1,25 @@
7a3408
+<network>
7a3408
+  <name>default</name>
7a3408
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
7a3408
+  <bridge name="virbr0"/>
7a3408
+  <forward mode="nat" dev="eth1">
7a3408
+    <nat>
7a3408
+      <port start='60000' end='65432'/>
7a3408
+    </nat>
7a3408
+  </forward>
7a3408
+  <ip address="192.168.122.1" netmask="255.255.255.0">
7a3408
+    <dhcp>
7a3408
+      <range start="192.168.122.2" end="192.168.122.254"/>
7a3408
+      <host mac="00:16:3e:77:e2:ed" name="a.example.com" ip="192.168.122.10"/>
7a3408
+      <host mac="00:16:3e:3e:a9:1a" name="b.example.com" ip="192.168.122.11"/>
7a3408
+    </dhcp>
7a3408
+  </ip>
7a3408
+  <ip family="ipv4" address="192.168.123.1" netmask="255.255.255.0">
7a3408
+  </ip>
7a3408
+  <ip family="ipv6" address="2001:db8:ac10:fe01::1" prefix="64">
7a3408
+  </ip>
7a3408
+  <ip family="ipv6" address="2001:db8:ac10:fd01::1" prefix="64">
7a3408
+  </ip>
7a3408
+  <ip family="ipv4" address="10.24.10.1">
7a3408
+  </ip>
7a3408
+</network>
7a3408
diff --git a/tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml b/tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml
7a3408
new file mode 100644
7a3408
index 0000000..f19e34d
7a3408
--- /dev/null
7a3408
+++ b/tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml
7a3408
@@ -0,0 +1,26 @@
7a3408
+<network>
7a3408
+  <name>default</name>
7a3408
+  <uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
7a3408
+  <forward dev='eth1' mode='nat'>
7a3408
+    <nat>
7a3408
+      <port start='60000' end='65432'/>
7a3408
+    </nat>
7a3408
+    <interface dev='eth1'/>
7a3408
+  </forward>
7a3408
+  <bridge name='virbr0' stp='on' delay='0'/>
7a3408
+  <ip address='192.168.122.1' netmask='255.255.255.0'>
7a3408
+    <dhcp>
7a3408
+      <range start='192.168.122.2' end='192.168.122.254'/>
7a3408
+      <host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10'/>
7a3408
+      <host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11'/>
7a3408
+    </dhcp>
7a3408
+  </ip>
7a3408
+  <ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'>
7a3408
+  </ip>
7a3408
+  <ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'>
7a3408
+  </ip>
7a3408
+  <ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
7a3408
+  </ip>
7a3408
+  <ip family='ipv4' address='10.24.10.1'>
7a3408
+  </ip>
7a3408
+</network>
7a3408
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
7a3408
index 290336e..8d60aa8 100644
7a3408
--- a/tests/networkxml2xmltest.c
7a3408
+++ b/tests/networkxml2xmltest.c
7a3408
@@ -99,6 +99,7 @@ mymain(void)
7a3408
     DO_TEST("nat-network-dns-forward-plain");
7a3408
     DO_TEST("nat-network-dns-forwarders");
7a3408
     DO_TEST("nat-network-forward-nat-address");
7a3408
+    DO_TEST("nat-network-forward-nat-no-address");
7a3408
     DO_TEST("8021Qbh-net");
7a3408
     DO_TEST("direct-net");
7a3408
     DO_TEST("host-bridge-net");
7a3408
-- 
7a3408
2.5.0
7a3408