]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1082] Checkpoint: use new code, built but some tests must be updated
authorFrancis Dupont <fdupont@isc.org>
Fri, 18 Dec 2020 22:55:26 +0000 (23:55 +0100)
committerRazvan Becheriu <razvan@isc.org>
Thu, 6 Jan 2022 12:48:45 +0000 (14:48 +0200)
17 files changed:
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp6/json_config_parser.cc
src/lib/dhcpsrv/cb_ctl_dhcp4.cc
src/lib/dhcpsrv/cb_ctl_dhcp6.cc
src/lib/dhcpsrv/cfg_globals.cc
src/lib/dhcpsrv/cfg_globals.h
src/lib/dhcpsrv/d2_client_cfg.h
src/lib/dhcpsrv/network.cc
src/lib/dhcpsrv/network.h
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/shared_network_parser.cc
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.h
src/lib/dhcpsrv/tests/network_unittest.cc
src/lib/dhcpsrv/tests/srv_config_unittest.cc
src/lib/dhcpsrv/testutils/generic_backend_unittest.cc

index 80a15703b4f6c983aa2abb20fbff5463c127b5de..9c171e0ac6398903f5695ef146b6249c48d10e0b 100644 (file)
@@ -617,6 +617,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
                 (config_pair.first == "shared-networks") ||
                 (config_pair.first == "reservations") ||
                 (config_pair.first == "config-control") ||
+                (config_pair.first == "loggers") ||
                 (config_pair.first == "compatibility")) {
                 continue;
             }
@@ -654,7 +655,6 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
                  (config_pair.first == "t2-percent") ||
                  (config_pair.first == "cache-threshold") ||
                  (config_pair.first == "cache-max-age") ||
-                 (config_pair.first == "loggers") ||
                  (config_pair.first == "hostname-char-set") ||
                  (config_pair.first == "hostname-char-replacement") ||
                  (config_pair.first == "ddns-send-updates") ||
index 65b96676aaac480b2eaa7861513f0cedc066e71e..e915c538ecbac0a20fcb89be50461f0f1cc91279 100644 (file)
@@ -1452,7 +1452,7 @@ TEST_F(Dhcp4ParserTest, nextServerGlobal) {
         getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"));
     ASSERT_TRUE(subnet);
     // Reset the fetch global function to staging (vs current) config.
-    subnet->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_EQ("1.2.3.4", subnet->getSiaddr().get().toText());
@@ -1719,7 +1719,7 @@ TEST_F(Dhcp4ParserTest, matchClientIdNoGlobal) {
     Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
     ASSERT_TRUE(subnet1);
     // Reset the fetch global function to staging (vs current) config.
-    subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_TRUE(subnet1->getMatchClientId());
@@ -1727,7 +1727,7 @@ TEST_F(Dhcp4ParserTest, matchClientIdNoGlobal) {
     Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
     ASSERT_TRUE(subnet2);
     // Reset the fetch global function to staging (vs current) config.
-    subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_FALSE(subnet2->getMatchClientId());
@@ -1765,7 +1765,7 @@ TEST_F(Dhcp4ParserTest, matchClientIdGlobal) {
     Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
     ASSERT_TRUE(subnet1);
     // Reset the fetch global function to staging (vs current) config.
-    subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_FALSE(subnet1->getMatchClientId());
@@ -1773,7 +1773,7 @@ TEST_F(Dhcp4ParserTest, matchClientIdGlobal) {
     Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
     ASSERT_TRUE(subnet2);
     // Reset the fetch global function to staging (vs current) config.
-    subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_TRUE(subnet2->getMatchClientId());
@@ -1810,7 +1810,7 @@ TEST_F(Dhcp4ParserTest, authoritativeNoGlobal) {
     Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
     ASSERT_TRUE(subnet1);
     // Reset the fetch global function to staging (vs current) config.
-    subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_TRUE(subnet1->getAuthoritative());
@@ -1818,7 +1818,7 @@ TEST_F(Dhcp4ParserTest, authoritativeNoGlobal) {
     Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
     ASSERT_TRUE(subnet2);
     // Reset the fetch global function to staging (vs current) config.
-    subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_FALSE(subnet2->getAuthoritative());
@@ -1856,7 +1856,7 @@ TEST_F(Dhcp4ParserTest, authoritativeGlobal) {
     Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
     ASSERT_TRUE(subnet1);
     // Reset the fetch global function to staging (vs current) config.
-    subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_FALSE(subnet1->getAuthoritative());
@@ -1864,7 +1864,7 @@ TEST_F(Dhcp4ParserTest, authoritativeGlobal) {
     Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
     ASSERT_TRUE(subnet2);
     // Reset the fetch global function to staging (vs current) config.
-    subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_TRUE(subnet2->getAuthoritative());
@@ -5531,7 +5531,7 @@ TEST_F(Dhcp4ParserTest, hostReservationGlobal) {
     subnet = subnets->selectSubnet(IOAddress("192.0.2.1"));
     ASSERT_TRUE(subnet);
     // Reset the fetch global function to staging (vs current) config.
-    subnet->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_FALSE(subnet->getReservationsGlobal());
@@ -5542,7 +5542,7 @@ TEST_F(Dhcp4ParserTest, hostReservationGlobal) {
     subnet = subnets->selectSubnet(IOAddress("192.0.3.1"));
     ASSERT_TRUE(subnet);
     // Reset the fetch global function to staging (vs current) config.
-    subnet->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_FALSE(subnet->getReservationsGlobal());
@@ -7380,7 +7380,7 @@ TEST_F(Dhcp4ParserTest, storeExtendedInfoNoGlobal) {
     Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
     ASSERT_TRUE(subnet1);
     // Reset the fetch global function to staging (vs current) config.
-    subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_TRUE(subnet1->getStoreExtendedInfo());
@@ -7388,7 +7388,7 @@ TEST_F(Dhcp4ParserTest, storeExtendedInfoNoGlobal) {
     Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
     ASSERT_TRUE(subnet2);
     // Reset the fetch global function to staging (vs current) config.
-    subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_FALSE(subnet2->getStoreExtendedInfo());
@@ -7426,7 +7426,7 @@ TEST_F(Dhcp4ParserTest, storeExtendedInfoGlobal) {
     Subnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1"));
     ASSERT_TRUE(subnet1);
     // Reset the fetch global function to staging (vs current) config.
-    subnet1->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_FALSE(subnet1->getStoreExtendedInfo());
@@ -7434,7 +7434,7 @@ TEST_F(Dhcp4ParserTest, storeExtendedInfoGlobal) {
     Subnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1"));
     ASSERT_TRUE(subnet2);
     // Reset the fetch global function to staging (vs current) config.
-    subnet2->setFetchGlobalsFn([]() -> ConstElementPtr {
+    subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
     });
     EXPECT_TRUE(subnet2->getStoreExtendedInfo());
index 7a8b1c73a6926bcdab709abc58384a91f2614935..5244f7d201cbb095e5515be8f3c1f8b5129151a7 100644 (file)
@@ -754,6 +754,7 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
                 (config_pair.first == "reservations") ||
                 (config_pair.first == "config-control") ||
                 (config_pair.first == "relay-supplied-options") ||
+                (config_pair.first == "loggers") ||
                 (config_pair.first == "compatibility")) {
                 continue;
             }
@@ -788,7 +789,6 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
                  (config_pair.first == "t2-percent") ||
                  (config_pair.first == "cache-threshold") ||
                  (config_pair.first == "cache-max-age") ||
-                 (config_pair.first == "loggers") ||
                  (config_pair.first == "hostname-char-set") ||
                  (config_pair.first == "hostname-char-replacement") ||
                  (config_pair.first == "ddns-send-updates") ||
index 3c53d0522331863061cb5a0b973dd061fcd6a333..da6c1968b1470b8383db489a162539099d97c7ba 100644 (file)
@@ -224,7 +224,7 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector,
             // 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 to allow for fetching global parameters.
-            (*network)->setFetchGlobalsFn([] () -> ConstElementPtr {
+            (*network)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr {
                 return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
             });
             external_cfg->getCfgSharedNetworks4()->add((*network));
@@ -246,7 +246,7 @@ CBControlDHCPv4::databaseConfigApply(const BackendSelector& backend_selector,
             // 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 {
+            (*subnet)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr {
                 return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
             });
             external_cfg->getCfgSubnets4()->add((*subnet));
index 2713db2201f3609d662138291c45fe6472188125..65e6266fdc258e448ff7df724556cc5d27646833 100644 (file)
@@ -223,7 +223,7 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector
             // 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 to allow for fetching global parameters.
-            (*network)->setFetchGlobalsFn([] () -> ConstElementPtr {
+            (*network)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr {
                 return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
             });
             external_cfg->getCfgSharedNetworks6()->add((*network));
@@ -245,7 +245,7 @@ CBControlDHCPv6::databaseConfigApply(const db::BackendSelector& backend_selector
             // 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 {
+            (*subnet)->setFetchGlobalsFn([] () -> ConstCfgGlobalsPtr {
                 return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
             });
             external_cfg->getCfgSubnets6()->add((*subnet));
index e40c8655401169cfa2ead49c77f9e6b57794ae5e..541e654564ac0e35f3712ba62c6a37f9428f0f53 100644 (file)
@@ -21,26 +21,8 @@ CfgGlobals::nameToIndex = {
     { "renew-timer", RENEW_TIMER },
     { "rebind-timer", REBIND_TIMER },
     { "decline-probation-period", DECLINE_PROBATION_PERIOD },
-    { "shared-networks", SHARED_NETWORKS },
-    { "interfaces-config", INTERFACES_CONFIG },
-    { "lease-database", LEASE_DATABASE },
-    { "hosts-database", HOSTS_DATABASE },
-    { "hosts-databases", HOSTS_DATABASES },
-    { "host-reservation-identifiers", HOST_RESERVATION_IDENTIFIERS },
-    { "client-classes", CLIENT_CLASSES },
-    { "option-def", OPTION_DEF },
-    { "option-data", OPTION_DATA },
-    { "hooks-libraries", HOOKS_LIBRARIES },
-    { "expired-leases-processing", EXPIRED_LEASES_PROCESSING },
     { "dhcp4o6-port", DHCP4O6_PORT },
-    { "control-socket", CONTROL_SOCKET },
-    { "dhcp-queue-control", DHCP_QUEUE_CONTROL },
-    { "dhcp-ddns", DHCP_DDNS },
-    { "user-context", USER_CONTEXT },
     { "comment", COMMENT },
-    { "sanity-checks", SANITY_CHECKS },
-    { "reservations", RESERVATIONS },
-    { "config-control", CONFIG_CONTROL },
     { "server-tag", SERVER_TAG },
     { "reservation-mode", RESERVATION_MODE },
     { "reservations-global", RESERVATIONS_GLOBAL },
@@ -49,7 +31,6 @@ CfgGlobals::nameToIndex = {
     { "calculate-tee-times", CALCULATE_TEE_TIMES },
     { "t1-percent", T1_PERCENT },
     { "t2-percent", T2_PERCENT },
-    { "loggers", LOGGERS },
     { "hostname-char-set", HOSTNAME_CHAR_SET },
     { "hostname-char-replacement", HOSTNAME_CHAR_REPLACEMENT },
     { "ddns-send-updates", DDNS_SEND_UPDATES },
@@ -61,7 +42,6 @@ CfgGlobals::nameToIndex = {
     { "store-extended-info", STORE_EXTENDED_INFO },
     { "statistic-default-sample-count", STATISTIC_DEFAULT_SAMPLE_COUNT },
     { "statistic-default-sample-age", STATISTIC_DEFAULT_SAMPLE_AGE },
-    { "multi-threading", MULTI_THREADING },
     { "cache-threshold", CACHE_THRESHOLD },
     { "cache-max-age", CACHE_MAX_AGE },
     { "ip-reservations-unique", IP_RESERVATIONS_UNIQUE },
@@ -69,7 +49,6 @@ CfgGlobals::nameToIndex = {
     { "ddns-use-conflict-resolution", DDNS_USE_CONFLICT_RESOLUTION },
 
     // DHCPv4 specific parameters.
-    { "subnet4", SUBNET4 },
     { "echo-client-id", ECHO_CLIENT_ID },
     { "match-client-id", MATCH_CLIENT_ID },
     { "authoritative", AUTHORITATIVE },
@@ -81,11 +60,7 @@ CfgGlobals::nameToIndex = {
     { "data-directory", DATA_DIRECTORY },
     { "preferred-lifetime", PREFERRED_LIFETIME },
     { "min-preferred-lifetime", MIN_PREFERRED_LIFETIME },
-    { "max-preferred-lifetime", MAX_PREFERRED_LIFETIME },
-    { "subnet6", SUBNET6 },
-    { "mac-sources", MAC_SOURCES },
-    { "relay-supplied-options", RELAY_SUPPLIED_OPTIONS },
-    { "server-id", SERVER_ID }
+    { "max-preferred-lifetime", MAX_PREFERRED_LIFETIME }
 };
 
 // Load time sanity check.
@@ -174,6 +149,19 @@ CfgGlobals::clear() {
     }
 }
 
+const CfgGlobals::MapType
+CfgGlobals::valuesMap() const {
+    MapType map;
+    for (auto it = nameToIndex.cbegin(); it != nameToIndex.cend(); ++it) {
+        int idx = it->second;
+        ConstElementPtr value = values_[idx];
+        if (value) {
+            map.insert(make_pair(it->first, value));
+        }
+    }
+    return (map);
+}
+
 ElementPtr
 CfgGlobals::toElement() const {
     ElementPtr result = Element::createMap();
index 7c9d8aa7fb8af83af1b5755e1d31eeed9f7e53fd..354269bab4ea910d6004365f8dd631ecd3f3a5d0 100644 (file)
@@ -44,26 +44,8 @@ public:
         RENEW_TIMER,
         REBIND_TIMER,
         DECLINE_PROBATION_PERIOD,
-        SHARED_NETWORKS,
-        INTERFACES_CONFIG,
-        LEASE_DATABASE,
-        HOSTS_DATABASE,
-        HOSTS_DATABASES,
-        HOST_RESERVATION_IDENTIFIERS,
-        CLIENT_CLASSES,
-        OPTION_DEF,
-        OPTION_DATA,
-        HOOKS_LIBRARIES,
-        EXPIRED_LEASES_PROCESSING,
         DHCP4O6_PORT,
-        CONTROL_SOCKET,
-        DHCP_QUEUE_CONTROL,
-        DHCP_DDNS,
-        USER_CONTEXT,
         COMMENT,
-        SANITY_CHECKS,
-        RESERVATIONS,
-        CONFIG_CONTROL,
         SERVER_TAG,
         RESERVATION_MODE,
         RESERVATIONS_GLOBAL,
@@ -72,7 +54,6 @@ public:
         CALCULATE_TEE_TIMES,
         T1_PERCENT,
         T2_PERCENT,
-        LOGGERS,
         HOSTNAME_CHAR_SET,
         HOSTNAME_CHAR_REPLACEMENT,
         DDNS_SEND_UPDATES,
@@ -84,7 +65,6 @@ public:
         STORE_EXTENDED_INFO,
         STATISTIC_DEFAULT_SAMPLE_COUNT,
         STATISTIC_DEFAULT_SAMPLE_AGE,
-        MULTI_THREADING,
         CACHE_THRESHOLD,
         CACHE_MAX_AGE,
         IP_RESERVATIONS_UNIQUE,
@@ -92,7 +72,6 @@ public:
         DDNS_USE_CONFLICT_RESOLUTION,
 
         // DHCPv4 specific parameters.
-        SUBNET4,
         ECHO_CLIENT_ID,
         MATCH_CLIENT_ID,
         AUTHORITATIVE,
@@ -104,17 +83,13 @@ public:
         DATA_DIRECTORY,
         PREFERRED_LIFETIME,
         MIN_PREFERRED_LIFETIME,
-        MAX_PREFERRED_LIFETIME,
-        SUBNET6,
-        MAC_SOURCES,
-        RELAY_SUPPLIED_OPTIONS,
-        SERVER_ID
+        MAX_PREFERRED_LIFETIME
     };
 
     /// @brief Last index.
     ///
     /// @note: please update when a new element is appended to the Index enum.
-    static const int MAX_INDEX = SERVER_ID;
+    static const int MAX_INDEX = MAX_PREFERRED_LIFETIME;
 
     /// @brief Size of configured global objects.
     static const size_t SIZE = MAX_INDEX + 1;
@@ -160,9 +135,18 @@ public:
     /// @brief Clear configured parameter values.
     void clear();
 
-    /// @brief Unparse configured globals.
+    /// @brief Type of name and value map.
+    typedef std::map<std::string, isc::data::ConstElementPtr> MapType;
+
+    /// @brief Returns configured parameters as a map.
+    ///
+    /// @note: the map includes only set global parameters i.e.
+    /// ConstElementPtr values are never null.
+    const MapType valuesMap() const;
+
+    /// @brief Unparse configured global parameters.
     ///
-    /// @return a pointer to unparsed globals.
+    /// @return a pointer to unparsed global parameters.
     isc::data::ElementPtr toElement() const;
 
 protected:
@@ -170,9 +154,12 @@ protected:
     std::vector<isc::data::ConstElementPtr> values_;
 };
 
-/// @brief Shared pointer to a CfgGlobals instance.
+/// @brief Non-const shared pointer to a CfgGlobals instance.
 typedef boost::shared_ptr<CfgGlobals> CfgGlobalsPtr;
 
+/// @brief Const shared pointer to a CfgGlobals instance.
+typedef boost::shared_ptr<const CfgGlobals> ConstCfgGlobalsPtr;
+
 } // namespace isc::dhcp
 } // namespace isc
 
index 98c77a515e09e936737ca7251c71fbdfd5aa5219..b51f1f2d3a4be9baedaffd16200a8c2e3166d400 100644 (file)
@@ -16,6 +16,7 @@
 #include <cc/cfg_to_element.h>
 #include <cc/user_context.h>
 #include <dhcp_ddns/ncr_io.h>
+#include <dhcpsrv/cfg_globals.h>
 #include <exceptions/exceptions.h>
 #include <util/optional.h>
 
@@ -44,7 +45,7 @@ public:
 
 /// @brief Callback function for @c D2ClientConfig that retrieves globally
 /// configured parameters.
-typedef std::function<data::ConstElementPtr()> FetchNetworkGlobalsFn;
+typedef std::function<ConstCfgGlobalsPtr()> FetchNetworkGlobalsFn;
 
 
 /// @brief Acts as a storage vault for D2 client configuration
index 5fc4f86c66e2cff265bf1c551aed6283bb5bab97..c7675d5d2cc4d7337b806908b30f57ac6cbed385 100644 (file)
@@ -105,8 +105,8 @@ Network::getGlobalProperty(Optional<IOAddress> property,
                            const std::string& /*min_name*/,
                            const std::string& /*max_name*/) const {
     if (!global_name.empty() && fetch_globals_fn_) {
-        ConstElementPtr globals = fetch_globals_fn_();
-        if (globals && (globals->getType() == Element::map)) {
+        ConstCfgGlobalsPtr globals = fetch_globals_fn_();
+        if (globals) {
             ConstElementPtr global_param = globals->get(global_name);
             if (global_param) {
                 std::string global_str = global_param->stringValue();
index 5521afacabbb408dbb7f0bbb9911e66024b7c4e3..9c5b2c9b241212ffcfc65e46496d5b2ef0b4fdb0 100644 (file)
@@ -14,6 +14,7 @@
 #include <cc/user_context.h>
 #include <dhcp/classify.h>
 #include <dhcp/option.h>
+#include <dhcpsrv/cfg_globals.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/cfg_4o6.h>
 #include <dhcpsrv/d2_client_cfg.h>
@@ -47,7 +48,7 @@ typedef boost::weak_ptr<Network> WeakNetworkPtr;
 
 /// @brief Callback function for @c Network that retrieves globally
 /// configured parameters.
-typedef std::function<data::ConstElementPtr()> FetchNetworkGlobalsFn;
+typedef std::function<ConstCfgGlobalsPtr()> FetchNetworkGlobalsFn;
 
 /// @brief Common interface representing a network to which the DHCP clients
 /// are connected.
@@ -785,8 +786,8 @@ protected:
                                  const std::string& max_name = "") const {
         unused(min_name, max_name);
         if (!global_name.empty() && fetch_globals_fn_) {
-            data::ConstElementPtr globals = fetch_globals_fn_();
-            if (globals && (globals->getType() == data::Element::map)) {
+            ConstCfgGlobalsPtr globals = fetch_globals_fn_();
+            if (globals) {
                 data::ConstElementPtr global_param = globals->get(global_name);
                 if (global_param) {
                     // If there is a global parameter, convert it to the
@@ -823,8 +824,8 @@ protected:
                                        const std::string& max_name = "") const {
 
         if (!global_name.empty() && fetch_globals_fn_) {
-            data::ConstElementPtr globals = fetch_globals_fn_();
-            if (globals && (globals->getType() == data::Element::map)) {
+            ConstCfgGlobalsPtr globals = fetch_globals_fn_();
+            if (globals) {
                 data::ConstElementPtr param = globals->get(global_name);
                 if (param) {
                     NumType def_value = static_cast<NumType>(param->intValue());
index 46c4e2eeb4a01723a30bb1e0ebbcbaade5971f1e..f3d7b24d3ec1ccd8fa56e834e306ffe7112b4be6 100644 (file)
@@ -655,7 +655,7 @@ SubnetConfigParser::createSubnet(ConstElementPtr params) {
     // 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 {
+    subnet_->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
     });
 }
index 98c136f9d8c998f09d27833170e9d099744e21ee..c3438bb542fb364821d754a9776e92efbf4f8387 100644 (file)
@@ -208,7 +208,7 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
     // 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 {
+     shared_network->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
     });
 
@@ -385,7 +385,7 @@ SharedNetwork6Parser::parse(const data::ConstElementPtr& shared_network_data) {
     // 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 {
+     shared_network->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr {
         return (CfgMgr::instance().getCurrentCfg()->getConfiguredGlobals());
     });
 
index e1db1083be783156266cb664d9b8cd92bca8594b..b8fd09fa634d5a5dc83badc9b16e7b624e37e89b 100644 (file)
@@ -46,7 +46,7 @@ SrvConfig::SrvConfig()
       class_dictionary_(new ClientClassDictionary()),
       decline_timer_(0), echo_v4_client_id_(true), dhcp4o6_port_(0),
       d2_client_config_(new D2ClientConfig()),
-      configured_globals_(Element::createMap()),
+      configured_globals_(new CfgGlobals()),
       cfg_consist_(new CfgConsistency()),
       lenient_option_parsing_(false) {
 }
@@ -65,7 +65,7 @@ SrvConfig::SrvConfig(const uint32_t sequence)
       class_dictionary_(new ClientClassDictionary()),
       decline_timer_(0), echo_v4_client_id_(true), dhcp4o6_port_(0),
       d2_client_config_(new D2ClientConfig()),
-      configured_globals_(Element::createMap()),
+      configured_globals_(new CfgGlobals()),
       cfg_consist_(new CfgConsistency()),
       lenient_option_parsing_(false) {
 }
@@ -243,7 +243,7 @@ SrvConfig::mergeGlobals(SrvConfig& other) {
     }
     // Iterate over the "other" globals, adding/overwriting them into
     // this config's list of globals.
-    for (auto other_global : other.getConfiguredGlobals()->mapValue()) {
+    for (auto other_global : other.getConfiguredGlobals()->valuesMap()) {
         addConfiguredGlobal(other_global.first, other_global.second);
     }
 
@@ -251,8 +251,8 @@ SrvConfig::mergeGlobals(SrvConfig& other) {
     BaseNetworkParser::moveReservationMode(mutable_cfg);
 
     // A handful of values are stored as members in SrvConfig. So we'll
-    // iterate over the merged globals, setting appropriate members.
-    for (auto merged_global : config_set->mapValue()) {
+    // iterate over the merged globals, setting approprate members.
+    for (auto merged_global : getConfiguredGlobals()->valuesMap()) {
         std::string name = merged_global.first;
         ConstElementPtr element = merged_global.second;
         try {
@@ -322,21 +322,6 @@ SrvConfig::updateStatistics() {
     }
 }
 
-isc::data::ConstElementPtr
-SrvConfig::getConfiguredGlobal(std::string name) const {
-    isc::data::ConstElementPtr global;
-    if (configured_globals_->contains(name)) {
-        global = configured_globals_->get(name);
-    }
-
-    return (global);
-}
-
-void
-SrvConfig::clearConfiguredGlobals() {
-    configured_globals_ = isc::data::Element::createMap();
-}
-
 void
 SrvConfig::applyDefaultsConfiguredGlobals(const SimpleDefaults& defaults) {
     // Code from SimpleParser::setDefaults
@@ -344,14 +329,13 @@ SrvConfig::applyDefaultsConfiguredGlobals(const SimpleDefaults& defaults) {
     // we're inserting here are not present in whatever the config file
     // came from, we need to make sure it's clearly labeled as default.
     const Element::Position pos("<default-value>", 0, 0);
-    ConstElementPtr globals = getConfiguredGlobals();
 
     // Let's go over all parameters we have defaults for.
     for (auto def_value : defaults) {
 
         // Try if such a parameter is there. If it is, let's
         // skip it, because user knows best *cough*.
-        ConstElementPtr x = globals->get(def_value.name_);
+        ConstElementPtr x = getConfiguredGlobal(def_value.name_);
         if (x) {
             // There is such a value already, skip it.
             continue;
@@ -619,11 +603,9 @@ SrvConfig::toElement() const {
 
     // Get family for the configuration manager
     uint16_t family = CfgMgr::instance().getFamily();
-    // DhcpX global map
-    ElementPtr dhcp = ConfigBase::toElement();
 
-    // Add in explicitly configured globals.
-    dhcp->setValue(configured_globals_->mapValue());
+    // DhcpX global map initialiazed from configured globals
+    ElementPtr dhcp = configured_globals_->toElement();
 
     // Set user-context
     contextToElement(dhcp);
index b755039626cd2f6d4c3d56c361c9b2323a14534d..d419c5b03d921ee7f77031a3acf5bc0eb42dded8 100644 (file)
@@ -11,6 +11,7 @@
 #include <dhcpsrv/cfg_db_access.h>
 #include <dhcpsrv/cfg_duid.h>
 #include <dhcpsrv/cfg_expiration.h>
+#include <dhcpsrv/cfg_globals.h>
 #include <dhcpsrv/cfg_host_operations.h>
 #include <dhcpsrv/cfg_hosts.h>
 #include <dhcpsrv/cfg_iface.h>
@@ -769,23 +770,50 @@ public:
         d2_client_config_ = d2_client_config;
     }
 
-    /// @brief Returns pointer to configured global parameters
-    isc::data::ConstElementPtr getConfiguredGlobals() const {
-        return (isc::data::ConstElementPtr(configured_globals_));
+    /// @brief Returns non-const pointer to configured global parameters.
+    ///
+    /// This function returns a non-const pointer to the configured
+    /// global parameters.
+    ///
+    /// @return Object representing configured global parameters.
+    CfgGlobalsPtr  getConfiguredGlobals() {
+        return (configured_globals_);
+    }
+
+    /// @brief Returns const pointer to configured global parameters.
+    ///
+    /// This function returns a onst pointer to the configured
+    /// global parameters.
+    ///
+    /// @return Object representing configured global parameters.
+    ConstCfgGlobalsPtr getConfiguredGlobals() const {
+        return (configured_globals_);
     }
 
     /// @brief Returns pointer to a given configured global parameter
     /// @param name name of the parameter to fetch
     /// @return Pointer to the parameter if it exists, otherwise an
     /// empty pointer.
-    isc::data::ConstElementPtr getConfiguredGlobal(std::string name) const;
+    isc::data::ConstElementPtr getConfiguredGlobal(std::string name) const {
+        return (configured_globals_->get(name));
+    }
+
+    /// @brief Returns pointer to a given configured global parameter
+    /// @param index index of the parameter to fetch
+    /// @return Pointer to the parameter if it exists, otherwise an
+    /// empty pointer.
+    isc::data::ConstElementPtr getConfiguredGlobal(int index) const {
+        return (configured_globals_->get(index));
+    }
 
     /// @brief Removes all configured global parameters.
     /// @note This removes the default values too so either
     /// @c applyDefaultsConfiguredGlobals and @c mergeGlobals,
     /// or @c isc::data::SimpleParser::setDefaults and
     /// @c extractConfiguredGlobals should be called after.
-    void clearConfiguredGlobals();
+    void clearConfiguredGlobals() {
+        configured_globals_->clear();
+    }
 
     /// @brief Applies defaults to global parameters.
     /// @param defaults vector of (name, type, value) defaults to apply.
@@ -1026,7 +1054,7 @@ private:
     D2ClientConfigPtr d2_client_config_;
 
     /// @brief Stores the global parameters specified via configuration
-    isc::data::ElementPtr configured_globals_;
+    CfgGlobalsPtr configured_globals_;
 
     /// @brief Pointer to the configuration consistency settings
     CfgConsistencyPtr cfg_consist_;
index a92884c1b23c9aa4a95bdd9fad52424757d5fce5..7c0612603fe11f49df6b1ad0b0822572badfc26c 100644 (file)
@@ -57,8 +57,7 @@ class NetworkTest : public ::testing::Test {
 public:
 
     /// @brief Constructor.
-    NetworkTest()
-        : globals_(Element::createMap()) {
+    NetworkTest() : globals_(new CfgGlobals()) {
     }
 
     /// @brief Returns pointer to the function which returns configured
@@ -68,7 +67,7 @@ public:
     }
 
     /// @brief Returns configured global parameters.
-    ConstElementPtr fetchGlobalsFn() {
+    ConstCfgGlobalsPtr fetchGlobalsFn() {
         return (globals_);
     }
 
@@ -146,7 +145,7 @@ public:
     }
 
     /// @brief Holds the collection of configured globals.
-    ElementPtr globals_;
+    CfgGlobalsPtr globals_;
 };
 
 // This test verifies that the inheritance is supported for certain
index b9390c1785a6e4864c8b8e663ab309508b9a6b35..51dc377e8036bf93f4b7cda259d91b65f24ac892 100644 (file)
@@ -460,10 +460,9 @@ TEST_F(SrvConfigTest, configuredGlobals) {
     SrvConfig conf(32);
 
     // The map of configured globals should be empty.
-    ConstElementPtr srv_globals = conf.getConfiguredGlobals();
+    ConstCfgGlobalsPtr srv_globals = conf.getConfiguredGlobals();
     ASSERT_TRUE(srv_globals);
-    ASSERT_EQ(Element::map, srv_globals->getType());
-    ASSERT_TRUE(srv_globals->mapValue().empty());
+    ASSERT_TRUE(srv_globals->valuesMap().empty());
 
     // Attempting to extract globals from a non-map should throw.
     ASSERT_THROW(conf.extractConfiguredGlobals(Element::create(777)), isc::BadValue);
@@ -487,12 +486,10 @@ TEST_F(SrvConfigTest, configuredGlobals) {
 
     // Now see if the extract was correct.
     srv_globals = conf.getConfiguredGlobals();
-    ASSERT_TRUE(srv_globals);
-    ASSERT_EQ(Element::map, srv_globals->getType());
-    ASSERT_FALSE(srv_globals->mapValue().empty());
+    ASSERT_FALSE(srv_globals->valuesMap().empty());
 
     // Maps and lists should be excluded.
-    auto globals = srv_globals->mapValue();
+    auto globals = srv_globals->valuesMap();
     for (auto global = globals.begin(); global != globals.end(); ++global) {
         if (global->first == "astring") {
             ASSERT_EQ(Element::string, global->second->getType());
@@ -1073,8 +1070,8 @@ TEST_F(SrvConfigTest, mergeGlobals4) {
     ASSERT_NO_THROW(expected_globals = Element::fromJSON(exp_globals))
                     << "exp_globals didn't parse, test is broken";
 
-    EXPECT_TRUE(isEquivalent(expected_globals, cfg_to.getConfiguredGlobals()));
-
+    EXPECT_TRUE(isEquivalent(expected_globals,
+                            cfg_to.getConfiguredGlobals()->toElement()));
 }
 
 // This test verifies that globals from one SrvConfig
@@ -1146,7 +1143,8 @@ TEST_F(SrvConfigTest, mergeGlobals6) {
     ASSERT_NO_THROW(expected_globals = Element::fromJSON(exp_globals))
                     << "exp_globals didn't parse, test is broken";
 
-    EXPECT_TRUE(isEquivalent(expected_globals, cfg_to.getConfiguredGlobals()));
+    EXPECT_TRUE(isEquivalent(expected_globals,
+                            cfg_to.getConfiguredGlobals()->toElement()));
 
 }
 
@@ -1374,7 +1372,7 @@ TEST_F(SrvConfigTest, getDdnsParamsTest4) {
     // 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.
-    subnet1->setFetchGlobalsFn([conf]() -> ConstElementPtr {
+    subnet1->setFetchGlobalsFn([conf]() -> ConstCfgGlobalsPtr {
         return (conf.getConfiguredGlobals());
     });
 
@@ -1391,7 +1389,7 @@ TEST_F(SrvConfigTest, getDdnsParamsTest4) {
     // 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.
-    subnet2->setFetchGlobalsFn([conf]() -> ConstElementPtr {
+    subnet2->setFetchGlobalsFn([conf]() -> ConstCfgGlobalsPtr {
         return (conf.getConfiguredGlobals());
     });
 
@@ -1534,7 +1532,7 @@ TEST_F(SrvConfigTest, getDdnsParamsTest6) {
     // 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.
-    subnet1->setFetchGlobalsFn([conf]() -> ConstElementPtr {
+    subnet1->setFetchGlobalsFn([conf]() -> ConstCfgGlobalsPtr {
         return (conf.getConfiguredGlobals());
     });
 
@@ -1551,7 +1549,7 @@ TEST_F(SrvConfigTest, getDdnsParamsTest6) {
     // 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.
-    subnet2->setFetchGlobalsFn([conf]() -> ConstElementPtr {
+    subnet2->setFetchGlobalsFn([conf]() -> ConstCfgGlobalsPtr {
         return (conf.getConfiguredGlobals());
     });
 
index da6dc67d0f75c8e2d5e1cee8df9482d89c5d095a..34468959e41aa6fd533d988efbc45bb0790a0914 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -105,7 +105,7 @@ void
 GenericBackendTest::checkConfiguredGlobal(const SrvConfigPtr& srv_cfg,
                                           const std::string &name,
                                           ConstElementPtr exp_value) {
-    ConstElementPtr globals = srv_cfg->getConfiguredGlobals();
+    ConstCfgGlobalsPtr globals = srv_cfg->getConfiguredGlobals();
     ConstElementPtr found_global = globals->get(name);
     ASSERT_TRUE(found_global) << "expected global: "
                               << name << " not found";
@@ -123,7 +123,6 @@ GenericBackendTest::checkConfiguredGlobal(const SrvConfigPtr& srv_cfg,
     checkConfiguredGlobal(srv_cfg, exp_global->getName(), exp_global->getElementValue());
 }
 
-
 } // end of namespace isc::dhcp::test
 } // end of namespace isc::dhcp
 } // end of namespace isc