From: Marcin Siodelski Date: Wed, 27 Aug 2014 06:58:37 +0000 (+0200) Subject: [3512] Interface list config parser has separation of the commit and build. X-Git-Tag: trac3482_base~11^2~2^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=69c2e41c8bc8bad56c0a927871a7e7dc80dd6b73;p=thirdparty%2Fkea.git [3512] Interface list config parser has separation of the commit and build. --- diff --git a/src/lib/dhcpsrv/dhcp_parsers.cc b/src/lib/dhcpsrv/dhcp_parsers.cc index 9d856bcabe..eef68663dc 100644 --- a/src/lib/dhcpsrv/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/dhcp_parsers.cc @@ -189,12 +189,14 @@ InterfaceListConfigParser(const std::string& param_name) void InterfaceListConfigParser::build(ConstElementPtr value) { + // Copy the current interface configuration. ConfigurationPtr config = CfgMgr::instance().getConfiguration(); - config->cfg_iface_.reset(); + cfg_iface_ = config->cfg_iface_; + cfg_iface_.reset(); BOOST_FOREACH(ConstElementPtr iface, value->listValue()) { std::string iface_name = iface->stringValue(); try { - config->cfg_iface_.use(iface_name); + cfg_iface_.use(iface_name); } catch (const std::exception& ex) { isc_throw(DhcpConfigError, "Failed to select interface: " @@ -205,7 +207,8 @@ InterfaceListConfigParser::build(ConstElementPtr value) { void InterfaceListConfigParser::commit() { - // Do nothing. CfgMgr has been updated during build. + // Use the new configuration created in a build time. + CfgMgr::instance().getConfiguration()->cfg_iface_ = cfg_iface_; } bool diff --git a/src/lib/dhcpsrv/dhcp_parsers.h b/src/lib/dhcpsrv/dhcp_parsers.h index f723cb1c33..1acb3df4ac 100644 --- a/src/lib/dhcpsrv/dhcp_parsers.h +++ b/src/lib/dhcpsrv/dhcp_parsers.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -406,7 +407,9 @@ public: /// @param value pointer to the content of parsed values virtual void build(isc::data::ConstElementPtr value); - /// @brief Does nothing. + /// @brief Assignes a parsed list of interfaces to the configuration. + /// + /// This is exception safe operation. virtual void commit(); private: @@ -424,6 +427,9 @@ private: // Parsed parameter name std::string param_name_; + + /// Holds the configuration created during + CfgIface cfg_iface_; }; /// @brief Parser for hooks library list diff --git a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc index bf2d9ba572..420c882bdf 100644 --- a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc +++ b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc @@ -236,6 +236,7 @@ TEST_F(DhcpParserTest, interfaceListParserTest) { // This should parse the configuration and add eth0 and eth1 to the list // of interfaces that server should listen on. parser->build(list_element); + parser->commit(); // Use CfgMgr instance to check if eth0 and eth1 was added, and that // eth2 was not added. @@ -257,6 +258,7 @@ TEST_F(DhcpParserTest, interfaceListParserTest) { cfg->cfg_iface_.reset(); parser->build(list_element); + parser->commit(); ASSERT_NO_THROW(cfg->cfg_iface_.openSockets(10000)); EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET));