diff options
author | Marcin Siodelski <marcin@isc.org> | 2017-07-27 14:13:55 +0200 |
---|---|---|
committer | Tomek Mrugalski <tomasz@isc.org> | 2017-08-15 14:00:56 +0200 |
commit | 03e1804d39b3221a8b1a7b580665fb45fa2c3e38 (patch) | |
tree | b1da74ecb229552acbec25f6de71840cd9480787 | |
parent | [5315] Option data parser checks for runtime definitions in LibDHCP. (diff) | |
download | kea-03e1804d39b3221a8b1a7b580665fb45fa2c3e38.tar.xz kea-03e1804d39b3221a8b1a7b580665fb45fa2c3e38.zip |
[5315] Added functions that remove subnets from a configuration.
-rw-r--r-- | src/lib/dhcpsrv/cfg_subnets4.cc | 14 | ||||
-rw-r--r-- | src/lib/dhcpsrv/cfg_subnets4.h | 7 | ||||
-rw-r--r-- | src/lib/dhcpsrv/cfg_subnets6.cc | 14 | ||||
-rw-r--r-- | src/lib/dhcpsrv/cfg_subnets6.h | 7 | ||||
-rw-r--r-- | src/lib/dhcpsrv/dhcpsrv_messages.mes | 7 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc | 28 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc | 25 |
7 files changed, 102 insertions, 0 deletions
diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc index 78ca8339c3..af890d1100 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.cc +++ b/src/lib/dhcpsrv/cfg_subnets4.cc @@ -39,6 +39,20 @@ CfgSubnets4::add(const Subnet4Ptr& subnet) { subnets_.push_back(subnet); } +void +CfgSubnets4::del(const ConstSubnet4Ptr& subnet) { + auto& index = subnets_.get<SubnetIdIndexTag>(); + auto subnet_it = index.find(subnet->getID()); + if (subnet_it == index.end()) { + isc_throw(BadValue, "no subnet with ID of '" << subnet->getID() + << "' found"); + } + index.erase(subnet_it); + + LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_DEL_SUBNET4) + .arg(subnet->toText()); +} + ConstSubnet4Ptr CfgSubnets4::getBySubnetId(const SubnetID& subnet_id) const { const auto& index = subnets_.get<SubnetSubnetIdIndexTag>(); diff --git a/src/lib/dhcpsrv/cfg_subnets4.h b/src/lib/dhcpsrv/cfg_subnets4.h index ac609e3b89..16ecff5379 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.h +++ b/src/lib/dhcpsrv/cfg_subnets4.h @@ -39,6 +39,13 @@ public: /// duplicates id of an existing subnet. void add(const Subnet4Ptr& subnet); + /// @brief Removes subnet from the configuration. + /// + /// @param subnet Pointer to the subnet to be removed. + /// + /// @throw isc::BadValue if such subnet doesn't exist. + void del(const ConstSubnet4Ptr& subnet); + /// @brief Returns pointer to the collection of all IPv4 subnets. /// /// This is used in a hook (subnet4_select), where the hook is able diff --git a/src/lib/dhcpsrv/cfg_subnets6.cc b/src/lib/dhcpsrv/cfg_subnets6.cc index 468b563503..f4278a1878 100644 --- a/src/lib/dhcpsrv/cfg_subnets6.cc +++ b/src/lib/dhcpsrv/cfg_subnets6.cc @@ -38,6 +38,20 @@ CfgSubnets6::add(const Subnet6Ptr& subnet) { subnets_.push_back(subnet); } +void +CfgSubnets6::del(const ConstSubnet6Ptr& subnet) { + auto& index = subnets_.get<SubnetIdIndexTag>(); + auto subnet_it = index.find(subnet->getID()); + if (subnet_it == index.end()) { + isc_throw(BadValue, "no subnet with ID of '" << subnet->getID() + << "' found"); + } + index.erase(subnet_it); + + LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_DEL_SUBNET6) + .arg(subnet->toText()); +} + ConstSubnet6Ptr CfgSubnets6::getBySubnetId(const SubnetID& subnet_id) const { const auto& index = subnets_.get<SubnetSubnetIdIndexTag>(); diff --git a/src/lib/dhcpsrv/cfg_subnets6.h b/src/lib/dhcpsrv/cfg_subnets6.h index b8e70a9610..5e03152275 100644 --- a/src/lib/dhcpsrv/cfg_subnets6.h +++ b/src/lib/dhcpsrv/cfg_subnets6.h @@ -40,6 +40,13 @@ public: /// duplicates id of an existing subnet. void add(const Subnet6Ptr& subnet); + /// @brief Removes subnet from the configuration. + /// + /// @param subnet Pointer to the subnet to be removed. + /// + /// @throw isc::BadValue if such subnet doesn't exist. + void del(const ConstSubnet6Ptr& subnet); + /// @brief Returns pointer to the collection of all IPv6 subnets. /// /// This is used in a hook (subnet6_select), where the hook is able diff --git a/src/lib/dhcpsrv/dhcpsrv_messages.mes b/src/lib/dhcpsrv/dhcpsrv_messages.mes index 0b6b730c65..1f3961c23d 100644 --- a/src/lib/dhcpsrv/dhcpsrv_messages.mes +++ b/src/lib/dhcpsrv/dhcpsrv_messages.mes @@ -44,6 +44,13 @@ there is a good reason for it, to avoid increased number of renewals and a need for rebinding (increase of multicast traffic, which may be received by multiple servers). +% DHCPSRV_CFGMGR_DEL_SUBNET4 IPv4 subnet %1 removed +This debug message is issued when a subnet is successfully removed from the +server configuration. The argument identifies the subnet removed. + +% DHCPSRV_CFGMGR_DEL_SUBNET6 IPv6 subnet %1 removed +This debug message is issued when a subnet is successfully removed from the + % DHCPSRV_CFGMGR_NEW_SUBNET4 a new subnet has been added to configuration: %1 This is an informational message reporting that the configuration has been extended to include the specified IPv4 subnet. diff --git a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc index 78345028a9..696c477f33 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc @@ -74,6 +74,34 @@ TEST(CfgSubnets4Test, getSpecificSubnet) { EXPECT_FALSE(cfg.getByPrefix("10.20.30.0/29")); } +// This test verifies that a single subnet can be removed from the configuration. +TEST(CfgSubnets4Test, deleteSubnet) { + CfgSubnets4 cfg; + + // Create 3 subnets. + Subnet4Ptr subnet1(new Subnet4(IOAddress("192.0.2.0"), + 26, 1, 2, 3, SubnetID(5))); + Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.3.0"), + 26, 1, 2, 3, SubnetID(8))); + Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.4.0"), + 26, 1, 2, 3, SubnetID(10))); + + ASSERT_NO_THROW(cfg.add(subnet1)); + ASSERT_NO_THROW(cfg.add(subnet2)); + ASSERT_NO_THROW(cfg.add(subnet3)); + + // There should be three subnets. + ASSERT_EQ(3, cfg.getAll()->size()); + // We're going to remove the subnet #2. Let's make sure it exists before + // we remove it. + ASSERT_TRUE(cfg.getByPrefix("192.0.3.0/26")); + + // Remove the subnet and make sure it is gone. + ASSERT_NO_THROW(cfg.del(subnet2)); + ASSERT_EQ(2, cfg.getAll()->size()); + EXPECT_FALSE(cfg.getByPrefix("192.0.3.0/26")); +} + // This test verifies that it is possible to retrieve a subnet using an // IP address. TEST(CfgSubnets4Test, selectSubnetByCiaddr) { diff --git a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc index 12d1547c3e..575a0b8e90 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc @@ -83,6 +83,31 @@ TEST(CfgSubnets6Test, getSpecificSubnet) { EXPECT_FALSE(cfg.getByPrefix("3000::/16")); } +// This test verifies that a single subnet can be removed from the configuration. +TEST(CfgSubnets6Test, deleteSubnet) { + CfgSubnets6 cfg; + + // Create 3 subnets. + Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 48, 1, 2, 3, 4)); + Subnet6Ptr subnet2(new Subnet6(IOAddress("2001:db8:2::"), 48, 1, 2, 3, 4)); + Subnet6Ptr subnet3(new Subnet6(IOAddress("2001:db8:3::"), 48, 1, 2, 3, 4)); + + ASSERT_NO_THROW(cfg.add(subnet1)); + ASSERT_NO_THROW(cfg.add(subnet2)); + ASSERT_NO_THROW(cfg.add(subnet3)); + + // There should be three subnets. + ASSERT_EQ(3, cfg.getAll()->size()); + // We're going to remove the subnet #2. Let's make sure it exists before + // we remove it. + ASSERT_TRUE(cfg.getByPrefix("2001:db8:2::/48")); + + // Remove the subnet and make sure it is gone. + ASSERT_NO_THROW(cfg.del(subnet2)); + ASSERT_EQ(2, cfg.getAll()->size()); + EXPECT_FALSE(cfg.getByPrefix("2001:db8:2::/48")); +} + // This test checks that the subnet can be selected using a relay agent's // link address. TEST(CfgSubnets6Test, selectSubnetByRelayAddress) { |