]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#490,!284] Enable dynamic inheritance for networks in config file.
authorMarcin Siodelski <marcin@isc.org>
Wed, 27 Mar 2019 10:55:10 +0000 (11:55 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 27 Mar 2019 19:44:25 +0000 (20:44 +0100)
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
src/lib/dhcpsrv/cb_ctl_dhcp4.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/shared_network_parser.cc
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc

index 01cf46d096d1f8aeb252c34ad6d4087a528ba3c3..a6c7dbc7540deda49ab84781b2563ed958b200be 100644 (file)
@@ -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;
             }
 
index eb359592019a830b35e0dbcdb84a6695e9246ee0..645f5c0f270ddc7ace701e020a86c1b501251906 100644 (file)
@@ -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;
             }
 
index 2ca78b4a239412c2beaf6a2dedf0bef864fdd0a4..02ea3d54f8426286f6caa2e088b7934f89278d90 100644 (file)
@@ -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());
             });
index 048064ecf2039ee3dddc004fe157199b8c781190..392aab545d7a43b7025b5b5a216b6c3f5873c63d 100644 (file)
@@ -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 *************************
index 712c2f570d91d2db9bd979c629664118f23e056a..0482dc3d106eed35deb036609bc9f2674cf0062f 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <asiolink/io_address.h>
 #include <cc/data.h>
+#include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/parsers/dhcp_parsers.h>
 #include <dhcpsrv/parsers/option_data_parser.h>
@@ -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);
 }
 
index 5a6725f9a7fbbf6d38318f8a66dd2e7566849b92..2c5b57bbedb582206060c83d80e1244b833217a7 100644 (file)
@@ -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());