]> xenbits.xensource.com Git - libvirt.git/commitdiff
network: don't allow multiple dhcp sections
authorKyle DeFrancia <kdef@linux.vnet.ibm.com>
Thu, 4 Dec 2014 21:07:36 +0000 (13:07 -0800)
committerLaine Stump <laine@laine.org>
Mon, 8 Dec 2014 20:41:09 +0000 (15:41 -0500)
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.

src/conf/network_conf.c

index 0d09deff7ff95a97af889ce778c7c7ddc1fccb26..ddb5c077b50099a8928e09c18c3967dbe8f2aaba 100644 (file)
@@ -3508,6 +3508,30 @@ virNetworkIpDefByIndex(virNetworkDefPtr def, int parentIndex)
     return ipdef;
 }
 
+
+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,
@@ -3573,6 +3597,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 &&
@@ -3680,6 +3707,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);