summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_subnets4.cc
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2019-03-01 15:30:58 +0100
committerMarcin Siodelski <marcin@isc.org>2019-05-24 18:30:00 +0200
commit38a669afd2c845872ec4bcf77855ede1d506b89c (patch)
treef11c564a376aa1f16597746976c5eda67fcd0478 /src/lib/dhcpsrv/cfg_subnets4.cc
parent[#539,!330] Updated ChangeLog entry (diff)
downloadkea-38a669afd2c845872ec4bcf77855ede1d506b89c.tar.xz
kea-38a669afd2c845872ec4bcf77855ede1d506b89c.zip
[492-cb-subnet-merge-vs-duplicate-subnet-prefixes] Removed conflicts by prefix too
Diffstat (limited to 'src/lib/dhcpsrv/cfg_subnets4.cc')
-rw-r--r--src/lib/dhcpsrv/cfg_subnets4.cc37
1 files changed, 32 insertions, 5 deletions
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<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.