]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#99,!176] Added deletion of vendor options from the configuration.
authorMarcin Siodelski <marcin@isc.org>
Wed, 19 Dec 2018 20:26:24 +0000 (21:26 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 20 Dec 2018 19:47:42 +0000 (14:47 -0500)
src/lib/dhcpsrv/cfg_option.cc
src/lib/dhcpsrv/cfg_option.h
src/lib/dhcpsrv/tests/cfg_option_unittest.cc

index 0125709a68a65a54a43e34858b85564b96ad4aee..71a4d5a66de8fc72f48b4aa85b8e80f6fb9e7a95 100644 (file)
@@ -226,6 +226,19 @@ CfgOption::del(const std::string& option_space, const uint16_t option_code) {
     return (idx.erase(option_code));
 }
 
+size_t
+CfgOption::del(const uint32_t vendor_id, const uint16_t option_code) {
+    // Check for presence of options.
+    OptionContainerPtr vendor_options = getAll(vendor_id);
+    if (!vendor_options || vendor_options->empty()) {
+        // There are no options, so there is nothing to do.
+        return (0);
+    }
+
+    auto& idx = vendor_options->get<1>();
+    return (idx.erase(option_code));
+}
+
 ElementPtr
 CfgOption::toElement() const {
     // option-data value is a list of maps
index a618076c6d40a4c85cc871cdb459c0ad3fcda62d..92a6c4ee92e0c9cbb650dd9da551a722c44ff177 100644 (file)
@@ -420,11 +420,19 @@ public:
     /// it is also deleted from all option instances encapsulating this
     /// option space.
     ///
-    /// @param key Option space name or vendor identifier.
+    /// @param option_space Option space name.
     /// @param option_code Code of the option to be returned.
     ///
     /// @return Number of deleted options.
-    size_t del(const std::string& key, const uint16_t option_code);
+    size_t del(const std::string& option_space, const uint16_t option_code);
+
+    /// @brief Delets vendor option for the specified vendor id.
+    ///
+    /// @param vendor_id Vendor identifier.
+    /// @param option_code Option code.
+    ///
+    /// @return Number of deleted options.
+    size_t del(const uint32_t vendor_id, const uint16_t option_code);
 
     /// @brief Returns a list of configured option space names.
     ///
index 0a619d2931f461b63cabdd8659b1ae6e9947eeb7..563928286dd4f651840e0d376f9110ca1a951878 100644 (file)
@@ -400,7 +400,7 @@ TEST_F(CfgOptionTest, encapsulate) {
 }
 
 // This test verifies that an option can be deleted from the configuration.
-TEST_F(CfgOptionTest, del) {
+TEST_F(CfgOptionTest, delFromOptionSpace) {
     CfgOption cfg;
 
     generateEncapsulatedOptions(cfg);
@@ -438,9 +438,36 @@ TEST_F(CfgOptionTest, del) {
         ASSERT_NO_THROW(top_level_option = cfg.get(DHCP6_OPTION_SPACE, code));
         ASSERT_TRUE(top_level_option.option_);
         EXPECT_FALSE(top_level_option.option_->getOption(5));
+        // Other options should remain.
+        EXPECT_TRUE(top_level_option.option_->getOption(1));
     }
 }
 
+// This test verifies that a vendor option can be deleted from the configuration.
+TEST_F(CfgOptionTest, delVendorOption) {
+    CfgOption cfg;
+
+    // Create multiple vendor options for vendor id 123.
+    for (uint16_t code = 100; code < 110; ++code) {
+        OptionPtr option(new Option(Option::V6, code, OptionBuffer(1, 0xFF)));
+        ASSERT_NO_THROW(cfg.add(option, false, "vendor-123"));
+    }
+
+    // Make sure that the option we're trying to delete is there.
+    ASSERT_TRUE(cfg.get(123, 105).option_);
+
+    // Delete the option.
+    uint64_t deleted_num;
+    ASSERT_NO_THROW(deleted_num = cfg.del(123, 105));
+    EXPECT_EQ(1, deleted_num);
+
+    // Make sure the option is gone.
+    EXPECT_FALSE(cfg.get(123, 105).option_);
+
+    // Other options, like 107, shouldn't be gone.
+    EXPECT_TRUE(cfg.get(123, 107).option_);
+}
+
 // This test verifies that single option can be retrieved from the configuration
 // using option code and option space.
 TEST_F(CfgOptionTest, get) {