2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-02 06:55:16 +00:00

[#490,!284] Enable dynamic inheritance for networks in config file.

This commit is contained in:
Marcin Siodelski
2019-03-27 11:55:10 +01:00
parent 345bffe123
commit 8a21f443a6
6 changed files with 53 additions and 14 deletions

View File

@@ -532,13 +532,14 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
continue; continue;
} }
// Timers are not used in the global scope. Their values are derived // As of Kea 1.6.0 we have two ways of inheriting the global parameters.
// to specific subnets (see SimpleParser6::deriveParameters). // The old method is used in JSON configuration parsers when the global
// decline-probation-period, dhcp4o6-port, echo-client-id, // parameters are derived into the subnets and shared networks and are
// user-context are handled in global_parser.parse() which // being treated as explicitly specified. The new way used by the config
// sets global parameters. // backend is the dynamic inheritance whereby each subnet and shared
// match-client-id and authoritative are derived to subnet scope // network uses a callback function to return global parameter if it
// level. // 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") || if ( (config_pair.first == "renew-timer") ||
(config_pair.first == "rebind-timer") || (config_pair.first == "rebind-timer") ||
(config_pair.first == "valid-lifetime") || (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 == "calculate-tee-times") ||
(config_pair.first == "t1-percent") || (config_pair.first == "t1-percent") ||
(config_pair.first == "t2-percent")) { (config_pair.first == "t2-percent")) {
CfgMgr::instance().getStagingCfg()->addConfiguredGlobal(config_pair.first,
config_pair.second);
continue; continue;
} }

View File

@@ -656,11 +656,14 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
continue; continue;
} }
// Timers are not used in the global scope. Their values are derived // As of Kea 1.6.0 we have two ways of inheriting the global parameters.
// to specific subnets (see SimpleParser6::deriveParameters). // The old method is used in JSON configuration parsers when the global
// decline-probation-period, dhcp4o6-port and user-context // parameters are derived into the subnets and shared networks and are
// are handled in the global_parser.parse() which sets // being treated as explicitly specified. The new way used by the config
// global parameters. // 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") || if ( (config_pair.first == "renew-timer") ||
(config_pair.first == "rebind-timer") || (config_pair.first == "rebind-timer") ||
(config_pair.first == "preferred-lifetime") || (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 == "user-context") ||
(config_pair.first == "server-tag") || (config_pair.first == "server-tag") ||
(config_pair.first == "reservation-mode")) { (config_pair.first == "reservation-mode")) {
CfgMgr::instance().getStagingCfg()->addConfiguredGlobal(config_pair.first,
config_pair.second);
continue; continue;
} }

View File

@@ -59,7 +59,7 @@ CBControlDHCPv4::databaseConfigApply(const db::BackendSelector& backend_selector
for (auto network = networks.begin(); network != networks.end(); ++network) { for (auto network = networks.begin(); network != networks.end(); ++network) {
// In order to take advantage of the dynamic inheritance of global // In order to take advantage of the dynamic inheritance of global
// parameters to a shared network we need to set a callback function // 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 { (*network)->setFetchGlobalsFn([] () -> ConstElementPtr {
return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); 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) { for (auto subnet = subnets.begin(); subnet != subnets.end(); ++subnet) {
// In order to take advantage of the dynamic inheritance of global // In order to take advantage of the dynamic inheritance of global
// parameters to a subnet we need to set a callback function for each // 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 { (*subnet)->setFetchGlobalsFn([] () -> ConstElementPtr {
return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals()); return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
}); });

View File

@@ -615,6 +615,13 @@ SubnetConfigParser::createSubnet(ConstElementPtr params) {
subnet_->setContext(user_context); 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 ************************* //****************************** Subnet4ConfigParser *************************

View File

@@ -8,6 +8,7 @@
#include <asiolink/io_address.h> #include <asiolink/io_address.h>
#include <cc/data.h> #include <cc/data.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/cfg_option.h> #include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/parsers/dhcp_parsers.h> #include <dhcpsrv/parsers/dhcp_parsers.h>
#include <dhcpsrv/parsers/option_data_parser.h> #include <dhcpsrv/parsers/option_data_parser.h>
@@ -171,6 +172,13 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
<< shared_network_data->getPosition() << ")"); << 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); return (shared_network);
} }
@@ -270,6 +278,13 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data) {
<< shared_network_data->getPosition() << ")"); << 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); return (shared_network);
} }

View File

@@ -2371,6 +2371,8 @@ TEST_F(ParseConfigTest, defaultSubnet4) {
auto subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getSubnet(123); auto subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getSubnet(123);
ASSERT_TRUE(subnet); ASSERT_TRUE(subnet);
EXPECT_TRUE(subnet->hasFetchGlobalsFn());
EXPECT_TRUE(subnet->getIface().unspecified()); EXPECT_TRUE(subnet->getIface().unspecified());
EXPECT_TRUE(subnet->getIface().empty()); EXPECT_TRUE(subnet->getIface().empty());
@@ -2440,6 +2442,8 @@ TEST_F(ParseConfigTest, defaultSubnet6) {
auto subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->getSubnet(123); auto subnet = CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->getSubnet(123);
ASSERT_TRUE(subnet); ASSERT_TRUE(subnet);
EXPECT_TRUE(subnet->hasFetchGlobalsFn());
EXPECT_TRUE(subnet->getIface().unspecified()); EXPECT_TRUE(subnet->getIface().unspecified());
EXPECT_TRUE(subnet->getIface().empty()); EXPECT_TRUE(subnet->getIface().empty());
@@ -2492,6 +2496,8 @@ TEST_F(ParseConfigTest, defaultSharedNetwork4) {
CfgMgr::instance().getStagingCfg()->getCfgSharedNetworks4()->getByName("frog"); CfgMgr::instance().getStagingCfg()->getCfgSharedNetworks4()->getByName("frog");
ASSERT_TRUE(network); ASSERT_TRUE(network);
EXPECT_TRUE(network->hasFetchGlobalsFn());
EXPECT_TRUE(network->getIface().unspecified()); EXPECT_TRUE(network->getIface().unspecified());
EXPECT_TRUE(network->getIface().empty()); EXPECT_TRUE(network->getIface().empty());
@@ -2544,6 +2550,8 @@ TEST_F(ParseConfigTest, defaultSharedNetwork6) {
CfgMgr::instance().getStagingCfg()->getCfgSharedNetworks6()->getByName("frog"); CfgMgr::instance().getStagingCfg()->getCfgSharedNetworks6()->getByName("frog");
ASSERT_TRUE(network); ASSERT_TRUE(network);
EXPECT_TRUE(network->hasFetchGlobalsFn());
EXPECT_TRUE(network->getIface().unspecified()); EXPECT_TRUE(network->getIface().unspecified());
EXPECT_TRUE(network->getIface().empty()); EXPECT_TRUE(network->getIface().empty());