[RESEND PATCH] network: don't allow multiple dhcp sections

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

 



This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=907779

A <dhcp> element can exist in only one IPv4 address and one IPv6
address per network.  This patch enforces that in virNetworkUpdate.
---
Rebased to latest master, hopefully this works better.
My original message:
https://www.redhat.com/archives/libvir-list/2014-November/msg00989.html

 src/conf/network_conf.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 97719ed..92aa9d5 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -3480,6 +3480,31 @@ virNetworkIpDefByIndex(virNetworkDefPtr def, int
parentIndex) }

 static int
+virNetworkDefUpdateCheckMultiDHCP(virNetworkDefPtr def,
+                                  virNetworkIpDefPtr ipdef)
+{
+    int family = VIR_SOCKET_ADDR_FAMILY(&ipdef->address);
+    size_t i;
+    virNetworkIpDefPtr ip;
+
+    for (i = 0;
+         (ip = virNetworkDefGetIpByIndex(def, family, i));
+         i++) {
+        if (ip != ipdef) {
+            if (ip->nranges || ip->nhosts) {
+                virReportError(VIR_ERR_OPERATION_INVALID,
+                               _("dhcp is supported only for a "
+                                 "single %s address on each network"),
+                               (family == AF_INET) ? "IPv4" : "IPv6");
+                return -1;
+            }
+        }
+    }
+
+    return 0;
+}
+
+static int
 virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr def,
                               unsigned int command,
                               int parentIndex,
@@ -3544,6 +3569,9 @@ virNetworkDefUpdateIPDHCPHost(virNetworkDefPtr
 def, } else if ((command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST) ||
                (command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST)) {

+        if (virNetworkDefUpdateCheckMultiDHCP(def, ipdef) < 0)
+            goto cleanup;
+
         /* log error if an entry with same name/address/ip already
  exists */ for (i = 0; i < ipdef->nhosts; i++) {
             if ((host.mac &&
@@ -3651,6 +3679,9 @@ virNetworkDefUpdateIPDHCPRange(virNetworkDefPtr
  def, if ((command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST) ||
         (command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST)) {

+        if (virNetworkDefUpdateCheckMultiDHCP(def, ipdef) < 0)
+            goto cleanup;
+
         if (i < ipdef->nranges) {
             char *startip = virSocketAddrFormat(&range.start);
             char *endip = virSocketAddrFormat(&range.end);
-- 
2.1.0

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