]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#490,!284] Enable inheritance of globals upon config merge.
authorMarcin Siodelski <marcin@isc.org>
Wed, 27 Mar 2019 09:08:23 +0000 (10:08 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 27 Mar 2019 19:44:25 +0000 (20:44 +0100)
src/lib/dhcpsrv/cb_ctl_dhcp4.cc
src/lib/dhcpsrv/network.h
src/lib/dhcpsrv/tests/cb_ctl_dhcp_unittest.cc

index e9e7e83677107934315d497f03508b0f193dc616..2ca78b4a239412c2beaf6a2dedf0bef864fdd0a4 100644 (file)
@@ -57,6 +57,12 @@ CBControlDHCPv4::databaseConfigApply(const db::BackendSelector& backend_selector
             getMgr().getPool()->getModifiedSharedNetworks4(backend_selector, server_selector,
                                                            lb_modification_time);
         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.
+            (*network)->setFetchGlobalsFn([] () -> ConstElementPtr {
+                return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
+            });
             external_cfg->getCfgSharedNetworks4()->add((*network));
         }
     }
@@ -67,6 +73,12 @@ CBControlDHCPv4::databaseConfigApply(const db::BackendSelector& backend_selector
                                                                             server_selector,
                                                                             lb_modification_time);
         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)->setFetchGlobalsFn([] () -> ConstElementPtr {
+                return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
+            });
             external_cfg->getCfgSubnets4()->add((*subnet));
         }
     }
index b2760681a9bccea599a5ff1a5d3ebaa5d96923ed..1682263ee8be86925a6a8c5d8611a9da9984b57e 100644 (file)
@@ -220,6 +220,14 @@ public:
         fetch_globals_fn_ = fetch_globals_fn;
     }
 
+    /// @brief Checks if the network is associated with a function used to
+    /// fetch globally configured parameters.
+    ///
+    /// @return true if it is associated, false otherwise.
+    bool hasFetchGlobalsFn() const {
+        return (static_cast<bool>(fetch_globals_fn_));
+    }
+
     /// @brief Sets local name of the interface for which this network is
     /// selected.
     ///
index d64c4b584e0760a5c3a757f53e597ddf2ef92426..f38a2aecbc8e121ad18a10afc2e779d026803c77 100644 (file)
@@ -295,6 +295,7 @@ public:
         if (fetchConfigElement("dhcp4_shared_network") &&
             (network->getModificationTime() > lb_modification_time)) {
             EXPECT_TRUE(found_network);
+            EXPECT_TRUE(found_network->hasFetchGlobalsFn());
 
         } else {
             EXPECT_FALSE(found_network);
@@ -306,7 +307,8 @@ public:
         auto found_subnet = subnets->getSubnet(1);
         if (fetchConfigElement("dhcp4_subnet") &&
             (subnet->getModificationTime() > lb_modification_time)) {
-            EXPECT_TRUE(found_subnet);
+            ASSERT_TRUE(found_subnet);
+            EXPECT_TRUE(found_subnet->hasFetchGlobalsFn());
 
         } else {
             EXPECT_FALSE(found_subnet);