]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[492-cb-subnet-merge-vs-duplicate-subnet-prefixes] Removed conflicts by prefix too
authorFrancis Dupont <fdupont@isc.org>
Fri, 1 Mar 2019 14:30:58 +0000 (15:30 +0100)
committerMarcin Siodelski <marcin@isc.org>
Fri, 24 May 2019 16:30:00 +0000 (12:30 -0400)
src/lib/dhcpsrv/cfg_subnets4.cc

index 348ed1d75ef6118ce00b8d3cb1a0ef0a2a1b12a9..1eb24fe70dbb21ae9efc5d29d36405e923767226 100644 (file)
@@ -87,7 +87,8 @@ CfgSubnets4::del(const SubnetID& subnet_id) {
 void
 CfgSubnets4::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks4Ptr networks,
                    CfgSubnets4& other) {
-    auto& index = subnets_.get<SubnetSubnetIdIndexTag>();
+    auto& index_id = subnets_.get<SubnetSubnetIdIndexTag>();
+    auto& index_prefix = subnets_.get<SubnetPrefixIndexTag>();
 
     // Iterate over the subnets to be merged. They will replace the existing
     // subnets with the same id. All new subnets will be inserted into the
@@ -98,11 +99,37 @@ CfgSubnets4::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks4Ptr networks,
          ++other_subnet) {
 
         // Check if there is a subnet with the same ID.
-        auto subnet_it = index.find((*other_subnet)->getID());
-        if (subnet_it != index.end()) {
+        auto subnet_id_it = index_id.find((*other_subnet)->getID());
+        if (subnet_id_it != index_id.end()) {
+
+            // Subnet found.
+            auto existing_subnet = *subnet_id_it;
+
+            // If the existing subnet and other subnet
+            // are the same instance skip it.
+            if (existing_subnet == *other_subnet) {
+                continue;
+            }
+
+            // We're going to replace the existing subnet with the other
+            // version. If it belongs to a shared network, we need
+            // remove it from that network.
+            SharedNetwork4Ptr network;
+            existing_subnet->getSharedNetwork(network);
+            if (network) {
+                network->del(existing_subnet->getID());
+            }
+
+            // Now we remove the existing subnet.
+            index_id.erase(subnet_id_it);
+        }
+
+        // Check if there is a subnet with the same prefix.
+        auto subnet_prefix_it = index_prefix.find((*other_subnet)->toText());
+        if (subnet_prefix_it != index_prefix.end()) {
 
             // Subnet found.
-            auto existing_subnet = *subnet_it;
+            auto existing_subnet = *subnet_prefix_it;
 
             // If the existing subnet and other subnet
             // are the same instance skip it.
@@ -120,7 +147,7 @@ CfgSubnets4::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks4Ptr networks,
             }
 
             // Now we remove the existing subnet.
-            index.erase(subnet_it);
+            index_prefix.erase(subnet_prefix_it);
         }
 
         // Create the subnet's options based on the given definitions.