From: Francis Dupont Date: Fri, 1 Mar 2019 14:30:58 +0000 (+0100) Subject: [492-cb-subnet-merge-vs-duplicate-subnet-prefixes] Removed conflicts by prefix too X-Git-Tag: Kea-1.6.0-beta~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38a669afd2c845872ec4bcf77855ede1d506b89c;p=thirdparty%2Fkea.git [492-cb-subnet-merge-vs-duplicate-subnet-prefixes] Removed conflicts by prefix too --- diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc index 348ed1d75e..1eb24fe70d 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.cc +++ b/src/lib/dhcpsrv/cfg_subnets4.cc @@ -87,7 +87,8 @@ CfgSubnets4::del(const SubnetID& subnet_id) { void CfgSubnets4::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks4Ptr networks, CfgSubnets4& other) { - auto& index = subnets_.get(); + auto& index_id = subnets_.get(); + auto& index_prefix = subnets_.get(); // 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.