From: Marcin Siodelski Date: Wed, 27 Mar 2019 10:55:10 +0000 (+0100) Subject: [#490,!284] Enable dynamic inheritance for networks in config file. X-Git-Tag: Kea-1.6.0-beta~300 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a21f443a64e3a5ffaeec44d9c651b624d66dbf6;p=thirdparty%2Fkea.git [#490,!284] Enable dynamic inheritance for networks in config file. --- diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index 01cf46d096..a6c7dbc754 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -532,13 +532,14 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set, continue; } - // Timers are not used in the global scope. Their values are derived - // to specific subnets (see SimpleParser6::deriveParameters). - // decline-probation-period, dhcp4o6-port, echo-client-id, - // user-context are handled in global_parser.parse() which - // sets global parameters. - // match-client-id and authoritative are derived to subnet scope - // level. + // As of Kea 1.6.0 we have two ways of inheriting the global parameters. + // The old method is used in JSON configuration parsers when the global + // parameters are derived into the subnets and shared networks and are + // being treated as explicitly specified. The new way used by the config + // backend is the dynamic inheritance whereby each subnet and shared + // network uses a callback function to return global parameter if it + // is not specified at lower level. This callback uses configured globals. + // Let's store all globals there so as they can be accessed. if ( (config_pair.first == "renew-timer") || (config_pair.first == "rebind-timer") || (config_pair.first == "valid-lifetime") || @@ -556,6 +557,9 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set, (config_pair.first == "calculate-tee-times") || (config_pair.first == "t1-percent") || (config_pair.first == "t2-percent")) { + + CfgMgr::instance().getStagingCfg()->addConfiguredGlobal(config_pair.first, + config_pair.second); continue; } diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index eb35959201..645f5c0f27 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -656,11 +656,14 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set, continue; } - // Timers are not used in the global scope. Their values are derived - // to specific subnets (see SimpleParser6::deriveParameters). - // decline-probation-period, dhcp4o6-port and user-context - // are handled in the global_parser.parse() which sets - // global parameters. + // As of Kea 1.6.0 we have two ways of inheriting the global parameters. + // The old method is used in JSON configuration parsers when the global + // parameters are derived into the subnets and shared networks and are + // being treated as explicitly specified. The new way used by the config + // backend is the dynamic inheritance whereby each subnet and shared + // network uses a callback function to return global parameter if it + // is not specified at lower level. This callback uses configured globals. + // Let's store all globals there so as they can be accessed. if ( (config_pair.first == "renew-timer") || (config_pair.first == "rebind-timer") || (config_pair.first == "preferred-lifetime") || @@ -670,6 +673,8 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set, (config_pair.first == "user-context") || (config_pair.first == "server-tag") || (config_pair.first == "reservation-mode")) { + CfgMgr::instance().getStagingCfg()->addConfiguredGlobal(config_pair.first, + config_pair.second); continue; } diff --git a/src/lib/dhcpsrv/cb_ctl_dhcp4.cc b/src/lib/dhcpsrv/cb_ctl_dhcp4.cc index 2ca78b4a23..02ea3d54f8 100644 --- a/src/lib/dhcpsrv/cb_ctl_dhcp4.cc +++ b/src/lib/dhcpsrv/cb_ctl_dhcp4.cc @@ -59,7 +59,7 @@ CBControlDHCPv4::databaseConfigApply(const db::BackendSelector& backend_selector for (auto network = networks.begin(); network != networks.end(); ++network) { // In order to take advantage of the dynamic inheritance of global // parameters to a shared network we need to set a callback function - // for each network which can be used to fetch global parameters. + // for each network to allow for fetching global parameters. (*network)->setFetchGlobalsFn([] () -> ConstElementPtr { return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); }); @@ -75,7 +75,7 @@ CBControlDHCPv4::databaseConfigApply(const db::BackendSelector& backend_selector for (auto subnet = subnets.begin(); subnet != subnets.end(); ++subnet) { // In order to take advantage of the dynamic inheritance of global // parameters to a subnet we need to set a callback function for each - // subnet which can be used to fetch global parameters. + // subnet to allow for fetching global parameters. (*subnet)->setFetchGlobalsFn([] () -> ConstElementPtr { return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); }); diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index 048064ecf2..392aab545d 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -615,6 +615,13 @@ SubnetConfigParser::createSubnet(ConstElementPtr params) { subnet_->setContext(user_context); } + // In order to take advantage of the dynamic inheritance of global + // parameters to a subnet we need to set a callback function for each + // subnet to allow for fetching global parameters. + subnet_->setFetchGlobalsFn([]() -> ConstElementPtr { + return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); + }); + } //****************************** Subnet4ConfigParser ************************* diff --git a/src/lib/dhcpsrv/parsers/shared_network_parser.cc b/src/lib/dhcpsrv/parsers/shared_network_parser.cc index 712c2f570d..0482dc3d10 100644 --- a/src/lib/dhcpsrv/parsers/shared_network_parser.cc +++ b/src/lib/dhcpsrv/parsers/shared_network_parser.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -171,6 +172,13 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) { << shared_network_data->getPosition() << ")"); } + // In order to take advantage of the dynamic inheritance of global + // parameters to a shared network we need to set a callback function + // for each shared network to allow for fetching global parameters. + shared_network->setFetchGlobalsFn([]() -> ConstElementPtr { + return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); + }); + return (shared_network); } @@ -270,6 +278,13 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data) { << shared_network_data->getPosition() << ")"); } + // In order to take advantage of the dynamic inheritance of global + // parameters to a shared network we need to set a callback function + // for each shared network which can be used to fetch global parameters. + shared_network->setFetchGlobalsFn([]() -> ConstElementPtr { + return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); + }); + return (shared_network); } diff --git a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc index 5a6725f9a7..2c5b57bbed 100644 --- a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc +++ b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc @@ -2371,6 +2371,8 @@ TEST_F(ParseConfigTest, defaultSubnet4) { auto subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getSubnet(123); ASSERT_TRUE(subnet); + EXPECT_TRUE(subnet->hasFetchGlobalsFn()); + EXPECT_TRUE(subnet->getIface().unspecified()); EXPECT_TRUE(subnet->getIface().empty()); @@ -2440,6 +2442,8 @@ TEST_F(ParseConfigTest, defaultSubnet6) { auto subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->getSubnet(123); ASSERT_TRUE(subnet); + EXPECT_TRUE(subnet->hasFetchGlobalsFn()); + EXPECT_TRUE(subnet->getIface().unspecified()); EXPECT_TRUE(subnet->getIface().empty()); @@ -2492,6 +2496,8 @@ TEST_F(ParseConfigTest, defaultSharedNetwork4) { CfgMgr::instance().getStagingCfg()->getCfgSharedNetworks4()->getByName("frog"); ASSERT_TRUE(network); + EXPECT_TRUE(network->hasFetchGlobalsFn()); + EXPECT_TRUE(network->getIface().unspecified()); EXPECT_TRUE(network->getIface().empty()); @@ -2544,6 +2550,8 @@ TEST_F(ParseConfigTest, defaultSharedNetwork6) { CfgMgr::instance().getStagingCfg()->getCfgSharedNetworks6()->getByName("frog"); ASSERT_TRUE(network); + EXPECT_TRUE(network->hasFetchGlobalsFn()); + EXPECT_TRUE(network->getIface().unspecified()); EXPECT_TRUE(network->getIface().empty());