]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#103,!289] Added function to delete subnet by ID from the configuration.
authorMarcin Siodelski <marcin@isc.org>
Thu, 4 Apr 2019 08:21:48 +0000 (10:21 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 10 Apr 2019 14:57:43 +0000 (16:57 +0200)
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/cfg_subnets4.h
src/lib/dhcpsrv/cfg_subnets6.cc
src/lib/dhcpsrv/cfg_subnets6.h
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc

index fd86f6dd76fbfaa356058e92801e492e3ffa490e..f7a96efb1f0be87d1a5ff6683f21c64b0db39c6e 100644 (file)
@@ -43,12 +43,20 @@ CfgSubnets4::add(const Subnet4Ptr& subnet) {
 
 void
 CfgSubnets4::del(const ConstSubnet4Ptr& subnet) {
+    del(subnet->getID());
+}
+
+void
+CfgSubnets4::del(const SubnetID& subnet_id) {
     auto& index = subnets_.get<SubnetSubnetIdIndexTag>();
-    auto subnet_it = index.find(subnet->getID());
+    auto subnet_it = index.find(subnet_id);
     if (subnet_it == index.end()) {
-        isc_throw(BadValue, "no subnet with ID of '" << subnet->getID()
+        isc_throw(BadValue, "no subnet with ID of '" << subnet_id
                   << "' found");
     }
+
+    Subnet4Ptr subnet = *subnet_it;
+
     index.erase(subnet_it);
 
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_DEL_SUBNET4)
index 27890f6a28864b9a9b0f684b8f875c40ba453364..aab236e97b255deb30012f514ad9cb23b2e4dace 100644 (file)
@@ -48,6 +48,13 @@ public:
     /// @throw isc::BadValue if such subnet doesn't exist.
     void del(const ConstSubnet4Ptr& subnet);
 
+    /// @brief Removes subnet from the configuration.
+    ///
+    /// @param subnet_id Identifier of the subnet to be removed.
+    ///
+    /// @throw isc::BadValue if such subnet doesn't exist.
+    void del(const SubnetID& subnet_id);
+
     /// @brief Merges specified subnet configuration into this configuration.
     ///
     /// This method merges subnets from the @c other configuration into this
index 0370f8fd685143403fc00948695bc79452c21a20..b087ef4f59723baa3e719c2edbf3db449b8d9a2d 100644 (file)
@@ -43,12 +43,20 @@ CfgSubnets6::add(const Subnet6Ptr& subnet) {
 
 void
 CfgSubnets6::del(const ConstSubnet6Ptr& subnet) {
+    del(subnet->getID());
+}
+
+void
+CfgSubnets6::del(const SubnetID& subnet_id) {
     auto& index = subnets_.get<SubnetSubnetIdIndexTag>();
-    auto subnet_it = index.find(subnet->getID());
+    auto subnet_it = index.find(subnet_id);
     if (subnet_it == index.end()) {
-        isc_throw(BadValue, "no subnet with ID of '" << subnet->getID()
+        isc_throw(BadValue, "no subnet with ID of '" << subnet_id
                   << "' found");
     }
+
+    Subnet6Ptr subnet = *subnet_it;
+
     index.erase(subnet_it);
 
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_DEL_SUBNET6)
index 3899fd283777006933ee2a3804562e729ba085ee..ce3e1dd9f402f7c38074f147a7397bafc99f507d 100644 (file)
@@ -48,6 +48,13 @@ public:
     /// @throw isc::BadValue if such subnet doesn't exist.
     void del(const ConstSubnet6Ptr& subnet);
 
+    /// @brief Removes subnet from the configuration.
+    ///
+    /// @param subnet_id Identifier of the subnet to be removed.
+    ///
+    /// @throw isc::BadValue if such subnet doesn't exist.
+    void del(const SubnetID& subnet_id);
+
     /// @brief Returns pointer to the collection of all IPv6 subnets.
     ///
     /// This is used in a hook (subnet6_select), where the hook is able
index f883e0a9a0703ae0594a2770d2bff6f740ddd550..e21b9bb33a02010dffa3f1325cac94fe51c6cedc 100644 (file)
@@ -136,6 +136,11 @@ TEST(CfgSubnets4Test, deleteSubnet) {
     ASSERT_NO_THROW(cfg.del(subnet2));
     ASSERT_EQ(2, cfg.getAll()->size());
     EXPECT_FALSE(cfg.getByPrefix("192.0.3.0/26"));
+
+    // Remove another subnet by ID.
+    ASSERT_NO_THROW(cfg.del(subnet1->getID()));
+    ASSERT_EQ(1, cfg.getAll()->size());
+    EXPECT_FALSE(cfg.getByPrefix("192.0.2.0/26"));
 }
 
 // This test verifies that subnets configuration is properly merged.
index 4707aac6488ad2a5e94f4d3183ef2db637bc5f09..c411abf1d00b6c3c2e4b71ca2c7350df499ad61a 100644 (file)
@@ -106,6 +106,11 @@ TEST(CfgSubnets6Test, deleteSubnet) {
     ASSERT_NO_THROW(cfg.del(subnet2));
     ASSERT_EQ(2, cfg.getAll()->size());
     EXPECT_FALSE(cfg.getByPrefix("2001:db8:2::/48"));
+
+    // Remove another subnet by ID.
+    ASSERT_NO_THROW(cfg.del(subnet1->getID()));
+    ASSERT_EQ(1, cfg.getAll()->size());
+    EXPECT_FALSE(cfg.getByPrefix("2001:db8:1::/48"));
 }
 
 // This test checks that the subnet can be selected using a relay agent's