Parcourir la source

[4204] OptionDef config parser updates runtime definitions in libdhcp.

Marcin Siodelski il y a 9 ans
Parent
commit
6011b53235

+ 6 - 2
src/lib/dhcpsrv/cfg_option_def.h

@@ -120,14 +120,18 @@ public:
     OptionDefinitionPtr get(const std::string& option_space,
                             const std::string& option_name) const;
 
+    /// @brief Returns reference to container holding option definitions.
+    const OptionDefSpaceContainer& getContainer() const {
+        return (option_definitions_);
+    }
+
 private:
 
     /// @brief A collection of option definitions.
     ///
     /// The option definitions stored in this container can be accessed
     /// using the option space name they belong to.
-    OptionSpaceContainer<OptionDefContainer, OptionDefinitionPtr,
-                         std::string> option_definitions_;
+    OptionDefSpaceContainer option_definitions_;
 
 };
 

+ 6 - 0
src/lib/dhcpsrv/parsers/dhcp_parsers.cc

@@ -780,6 +780,12 @@ OptionDefParser::build(ConstElementPtr option_def) {
         isc_throw(DhcpConfigError, ex.what() << " ("
                   << option_def->getPosition() << ")");
     }
+
+    // All definitions have been prepared. Put them as runtime options into
+    // the libdhcp++.
+    const OptionDefSpaceContainer& container =
+        CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->getContainer();
+    LibDHCP::setRuntimeOptionDefs(container);
 }
 
 void

+ 9 - 0
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc

@@ -495,6 +495,15 @@ TEST_F(ParseConfigTest, basicOptionDefTest) {
     EXPECT_FALSE(def->getArrayType());
     EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, def->getType());
     EXPECT_TRUE(def->getEncapsulatedSpace().empty());
+
+    // Check if libdhcp++ runtime options have been updated.
+    OptionDefinitionPtr def_libdhcp = LibDHCP::getRuntimeOptionDef("isc", 100);
+    ASSERT_TRUE(def_libdhcp);
+
+    // The LibDHCP should return a separate instance of the option definition
+    // but the values should be equal.
+    EXPECT_TRUE(def_libdhcp != def);
+    EXPECT_TRUE(*def_libdhcp == *def);
 }
 
 /// @brief Check minimal parsing of option definitions.