]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1790] addressed review comments
authorRazvan Becheriu <razvan@isc.org>
Thu, 25 Jan 2024 22:16:11 +0000 (00:16 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 26 Jan 2024 12:19:54 +0000 (14:19 +0200)
src/bin/dhcp4/tests/config_backend_unittest.cc
src/bin/dhcp6/tests/config_backend_unittest.cc
src/lib/cc/stamped_value.cc
src/lib/dhcpsrv/cb_ctl_dhcp.h
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/testutils/generic_backend_unittest.cc
src/share/api/remote-global-parameter4-del.json
src/share/api/remote-global-parameter4-get.json
src/share/api/remote-global-parameter6-del.json
src/share/api/remote-global-parameter6-get.json

index c71b48ee68a5cfc2ffa2d2eb8ef92a75c4cf26d3..38e467a9d420494f3ed8b50363d0382db39ee300 100644 (file)
@@ -192,8 +192,8 @@ TEST_F(Dhcp4CBTest, mergeGlobals) {
     StampedValuePtr calc_tee_times(new StampedValue("calculate-tee-times", Element::create(bool(false))));
     StampedValuePtr t2_percent(new StampedValue("t2-percent", Element::create(0.75)));
     StampedValuePtr renew_timer(new StampedValue("renew-timer", Element::create(500)));
-    StampedValuePtr mt_enabled(new StampedValue("multi-threading/enable-multi-threading", Element::create(true)));
-    StampedValuePtr mt_pool_size(new StampedValue("multi-threading/thread-pool-size", Element::create(256)));
+    StampedValuePtr mt_enabled(new StampedValue("multi-threading.enable-multi-threading", Element::create(true)));
+    StampedValuePtr mt_pool_size(new StampedValue("multi-threading.thread-pool-size", Element::create(256)));
 
     // Let's add all of the globals to the second backend.  This will verify
     // we find them there.
index 2834c5f8716aa53061d59b6eb234008aa8b7c6b9..8d4bdb8fe941cd69923e500eb37919b81426a43e 100644 (file)
@@ -192,8 +192,8 @@ TEST_F(Dhcp6CBTest, mergeGlobals) {
     StampedValuePtr server_tag(new StampedValue("server-tag", "second-server"));
     StampedValuePtr decline_period(new StampedValue("decline-probation-period", Element::create(86400)));
     StampedValuePtr renew_timer(new StampedValue("renew-timer", Element::create(500)));
-    StampedValuePtr mt_enabled(new StampedValue("multi-threading/enable-multi-threading", Element::create(true)));
-    StampedValuePtr mt_pool_size(new StampedValue("multi-threading/thread-pool-size", Element::create(256)));
+    StampedValuePtr mt_enabled(new StampedValue("multi-threading.enable-multi-threading", Element::create(true)));
+    StampedValuePtr mt_pool_size(new StampedValue("multi-threading.thread-pool-size", Element::create(256)));
 
     // Let's add all of the globals to the second backend.  This will verify
     // we find them there.
index 3fbad88626972dccdcf06d69614b58a84082b8c6..c87e6e1c1eed7df2b1838692fe9a16c5cad1d40b 100644 (file)
@@ -187,7 +187,7 @@ StampedValue::validateConstruct() const {
                 (type != Element::boolean) &&
                 (type != Element::real)) {
                 isc_throw(BadValue, "StampedValue: provided value of the '"
-                          << name_ << "/" << value_->mapValue().begin()->first
+                          << name_ << "." << value_->mapValue().begin()->first
                           << "' parameter has invalid type: "
                           << Element::typeToName(type));
             }
index 14935bb7f47029c99fd8fee259fee036ebf7b76c..309f135d96caecf2c81c687ba001a0367a6f33d2 100644 (file)
@@ -32,10 +32,34 @@ public:
         : process::CBControlBase<ConfigBackendMgrType>() {
     }
 
+    /// @brief It translates the top level map parameters from flat naming
+    /// format (e.g. param-name.sub-param-name) to the respective param-name and
+    /// sub-param-name. If the name does not contain '.', the param-name will
+    /// contain the initial name.
+    ///
+    /// @param name The name in flat format (e.g. map-name.element-name).
+    /// @param[out] param_name The resulting top level param name.
+    /// @param[out] sub_param_name The resulting sub param name inside the map.
+    ///
+    /// @return The function returns true if any conversion is done, false
+    /// otherwise.
+    static bool translateName(std::string const& name, std::string& param_name,
+                              std::string& sub_param_name) {
+        param_name = name;
+        sub_param_name = std::string();
+        auto pos = param_name.find('.');
+        if (pos != std::string::npos) {
+            sub_param_name = param_name.substr(pos + 1);
+            param_name = param_name.substr(0, pos);
+            return (true);
+        }
+        return (false);
+    }
+
 protected:
 
     /// @brief It translates the top level map parameters from flat naming
-    /// format (e.g. map-name/element-name) to proper ElementMap objects and
+    /// format (e.g. param-name.sub-param-name) to proper ElementMap objects and
     /// adds all globals fetched from config backend(s) to a SrvConfig instance
     ///
     /// Iterates over the given collection of global parameters and adds them to
@@ -54,20 +78,18 @@ protected:
                 continue;
             }
 
-            std::string name = cb_global->getName();
-            auto pos = name.find('/');
-            if (pos != std::string::npos) {
-                const std::string sub_elem(name.substr(pos + 1));
-                name = name.substr(0, pos);
-                data::ElementPtr sub_param = boost::const_pointer_cast<data::Element>(external_cfg->getConfiguredGlobal(name));
+            std::string param_name;
+            std::string sub_param_name;
+            if (translateName(cb_global->getName(), param_name, sub_param_name)) {
+                data::ElementPtr sub_param = boost::const_pointer_cast<data::Element>(external_cfg->getConfiguredGlobal(param_name));
                 if (!sub_param) {
                     sub_param = data::Element::createMap();
                 }
-                sub_param->set(sub_elem, cb_global->getElementValue());
-                external_cfg->addConfiguredGlobal(name, sub_param);
+                sub_param->set(sub_param_name, cb_global->getElementValue());
+                external_cfg->addConfiguredGlobal(param_name, sub_param);
             } else {
                 // Reuse name and value.
-                external_cfg->addConfiguredGlobal(name, cb_global->getElementValue());
+                external_cfg->addConfiguredGlobal(param_name, cb_global->getElementValue());
             }
         }
     }
index 0a77a72bf47fc8ce1a6e43a2749e9de8bbcca949..c40e2fc29ff7f7a557fc3e3b05a86dcd3fe51098 100644 (file)
@@ -1660,6 +1660,7 @@ D2ClientConfigParser::setAllDefaults(isc::data::ConstElementPtr d2_config) {
 void
 CompatibilityParser::parse(ConstElementPtr compatibility, SrvConfig& srv_cfg) {
     if (compatibility) {
+        auto family = CfgMgr::instance().getFamily();
         for (auto const& kv : compatibility->mapValue()) {
             if (!kv.second || (kv.second->getType() != Element::boolean)) {
                 isc_throw(DhcpConfigError,
@@ -1669,12 +1670,19 @@ CompatibilityParser::parse(ConstElementPtr compatibility, SrvConfig& srv_cfg) {
             }
             if (kv.first == "lenient-option-parsing") {
                 srv_cfg.setLenientOptionParsing(kv.second->boolValue());
-            } else if (kv.first == "ignore-dhcp-server-identifier") {
-                srv_cfg.setIgnoreServerIdentifier(kv.second->boolValue());
-            } else if (kv.first == "ignore-rai-link-selection") {
-                srv_cfg.setIgnoreRAILinkSelection(kv.second->boolValue());
-            } else if (kv.first == "exclude-first-last-24") {
-                srv_cfg.setExcludeFirstLast24(kv.second->boolValue());
+            } else if (family == AF_INET) {
+                if (kv.first == "ignore-dhcp-server-identifier") {
+                    srv_cfg.setIgnoreServerIdentifier(kv.second->boolValue());
+                } else if (kv.first == "ignore-rai-link-selection") {
+                    srv_cfg.setIgnoreRAILinkSelection(kv.second->boolValue());
+                } else if (kv.first == "exclude-first-last-24") {
+                    srv_cfg.setExcludeFirstLast24(kv.second->boolValue());
+                } else {
+                    isc_throw(DhcpConfigError,
+                              "unsupported compatibility parameter: "
+                              << kv.first << " (" << kv.second->getPosition()
+                              << ")");
+                }
             } else {
                 isc_throw(DhcpConfigError,
                           "unsupported compatibility parameter: "
index ff3f6914a300194f3da97c5dcaf50213b3ad12fb..3497f763130ecbf571cb915cdd93100b58947441 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <dhcp/libdhcp++.h>
 #include <dhcp/option_vendor.h>
+#include <dhcpsrv/cb_ctl_dhcp.h>
 #include <dhcpsrv/testutils/generic_backend_unittest.h>
 #include <util/buffer.h>
 #include <typeinfo>
@@ -115,22 +116,18 @@ GenericBackendTest::checkConfiguredGlobal(const SrvConfigPtr& srv_cfg,
                                           const std::string &name,
                                           ConstElementPtr exp_value) {
     ConstCfgGlobalsPtr globals = srv_cfg->getConfiguredGlobals();
-    std::string name_elem = name;
-    std::string sub_elem;
-    auto pos = name_elem.find('/');
-    if (pos != std::string::npos) {
-        sub_elem = name_elem.substr(pos + 1);
-        name_elem = name_elem.substr(0, pos);
-    }
+    std::string param_name;
+    std::string sub_param_name;
+    bool translated = CBControlDHCP<bool>::translateName(name, param_name, sub_param_name);
 
-    ConstElementPtr found_global = globals->get(name_elem);
+    ConstElementPtr found_global = globals->get(param_name);
     ASSERT_TRUE(found_global) << "expected global: "
-                              << name_elem << " not found";
+                              << param_name << " not found";
 
-    if (!sub_elem.empty()) {
+    if (translated) {
         ASSERT_EQ(Element::map, found_global->getType())
-            << "expected global: " << name_elem << " has wrong type";
-        found_global = found_global->get(sub_elem);
+            << "expected global: " << param_name << " has wrong type";
+        found_global = found_global->get(sub_param_name);
         ASSERT_TRUE(found_global) << "expected global: "
                                   << name << " not found";
     }
index 0ed6f52b2dfb48432107a0a560794a9f6e7bcb76..2cc79ffa24e6dac71da031fb1e1e27bd43a5803c 100644 (file)
@@ -5,7 +5,7 @@
         "This command deletes a global DHCPv4 parameter from the configuration database. The server uses the value specified in the configuration file, or a default value if the parameter is not specified, after deleting the parameter from the database."
     ],
     "cmd-comment": [
-        "This command carries the list including exactly one name of the parameter to be deleted. If deleting a map parameter, the ``map-name/parameter-name`` format must be used. The ``server-tags`` list is mandatory and it must contain exactly one server tag. Specifying an empty list, a value of ``null``, or multiple server tags will result in an error."
+        "This command carries the list including exactly one name of the parameter to be deleted. If deleting a map parameter, the ``map-name.parameter-name`` format must be used. The ``server-tags`` list is mandatory and it must contain exactly one server tag. Specifying an empty list, a value of ``null``, or multiple server tags will result in an error."
     ],
     "cmd-syntax": [
         "{",
index dcf63cd5485c1ce63cf68717bfc96cf547e3c21c..9fd98bbf20ff5919f212767e618da2164582706b 100644 (file)
@@ -5,7 +5,7 @@
         "This command fetches the selected global parameter for the server from the specified database."
     ],
     "cmd-comment": [
-        "This command carries a list including exactly one name of the parameter to be fetched. If retrieving a map parameter, the ``map-name/parameter-name`` format must be used. The ``server-tags`` list is mandatory and must contain exactly one server tag. Specifying an empty list, a value of ``null``, or multiple server tags will result in an error. The server tag \"all\" is allowed; it fetches the global parameter value shared by all servers."
+        "This command carries a list including exactly one name of the parameter to be fetched. If retrieving a map parameter, the ``map-name.parameter-name`` format must be used. The ``server-tags`` list is mandatory and must contain exactly one server tag. Specifying an empty list, a value of ``null``, or multiple server tags will result in an error. The server tag \"all\" is allowed; it fetches the global parameter value shared by all servers."
     ],
     "cmd-syntax": [
         "{",
index 7b4041782f61ac2bff68679c5f7561ea227822b7..6fc752947b93664bd2c7338527272aca56174288 100644 (file)
@@ -5,7 +5,7 @@
         "This command deletes a global DHCPv6 parameter from the configuration database. The server uses the value specified in the configuration file, or a default value if the parameter is not specified in the configuration file, after deleting the parameter from the database."
     ],
     "cmd-comment": [
-        "This command carries the list including exactly one name of the parameter to be deleted. If deleting a map parameter, the ``map-name/parameter-name`` format must be used. The ``server-tags`` list is mandatory and must contain exactly one server tag. Specifying an empty list, a value of ``null``, or multiple server tags will result in an error."
+        "This command carries the list including exactly one name of the parameter to be deleted. If deleting a map parameter, the ``map-name.parameter-name`` format must be used. The ``server-tags`` list is mandatory and must contain exactly one server tag. Specifying an empty list, a value of ``null``, or multiple server tags will result in an error."
     ],
     "cmd-syntax": [
         "{",
index 0950dc5174746a30f098822692339d285e872bc5..c95dceef141375cfb65ce5b627b84c89912b7642 100644 (file)
@@ -5,7 +5,7 @@
         "This command fetches the selected global parameter for the server from the specified database."
     ],
     "cmd-comment": [
-        "This command carries a list including exactly one name of the parameter to be fetched. If retrieving a map parameter, the ``map-name/parameter-name`` format must be used. The ``server-tags`` list is mandatory and must contain exactly one server tag. Specifying an empty list, a value of ``null``, or multiple server tags will result in an error. The server tag \"all\" is allowed; it fetches the global parameter value shared by all servers."
+        "This command carries a list including exactly one name of the parameter to be fetched. If retrieving a map parameter, the ``map-name.parameter-name`` format must be used. The ``server-tags`` list is mandatory and must contain exactly one server tag. Specifying an empty list, a value of ``null``, or multiple server tags will result in an error. The server tag \"all\" is allowed; it fetches the global parameter value shared by all servers."
     ],
     "cmd-syntax": [
         "{",