Skip to content

Commit 7d3fb3d

Browse files
author
Razvan Becheriu
committed
[#1790] addressed review comments
1 parent 48a4661 commit 7d3fb3d

File tree

10 files changed

+64
-37
lines changed

10 files changed

+64
-37
lines changed

src/bin/dhcp4/tests/config_backend_unittest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ TEST_F(Dhcp4CBTest, mergeGlobals) {
192192
StampedValuePtr calc_tee_times(new StampedValue("calculate-tee-times", Element::create(bool(false))));
193193
StampedValuePtr t2_percent(new StampedValue("t2-percent", Element::create(0.75)));
194194
StampedValuePtr renew_timer(new StampedValue("renew-timer", Element::create(500)));
195-
StampedValuePtr mt_enabled(new StampedValue("multi-threading/enable-multi-threading", Element::create(true)));
196-
StampedValuePtr mt_pool_size(new StampedValue("multi-threading/thread-pool-size", Element::create(256)));
195+
StampedValuePtr mt_enabled(new StampedValue("multi-threading.enable-multi-threading", Element::create(true)));
196+
StampedValuePtr mt_pool_size(new StampedValue("multi-threading.thread-pool-size", Element::create(256)));
197197

198198
// Let's add all of the globals to the second backend. This will verify
199199
// we find them there.

src/bin/dhcp6/tests/config_backend_unittest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ TEST_F(Dhcp6CBTest, mergeGlobals) {
192192
StampedValuePtr server_tag(new StampedValue("server-tag", "second-server"));
193193
StampedValuePtr decline_period(new StampedValue("decline-probation-period", Element::create(86400)));
194194
StampedValuePtr renew_timer(new StampedValue("renew-timer", Element::create(500)));
195-
StampedValuePtr mt_enabled(new StampedValue("multi-threading/enable-multi-threading", Element::create(true)));
196-
StampedValuePtr mt_pool_size(new StampedValue("multi-threading/thread-pool-size", Element::create(256)));
195+
StampedValuePtr mt_enabled(new StampedValue("multi-threading.enable-multi-threading", Element::create(true)));
196+
StampedValuePtr mt_pool_size(new StampedValue("multi-threading.thread-pool-size", Element::create(256)));
197197

198198
// Let's add all of the globals to the second backend. This will verify
199199
// we find them there.

src/lib/cc/stamped_value.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ StampedValue::validateConstruct() const {
187187
(type != Element::boolean) &&
188188
(type != Element::real)) {
189189
isc_throw(BadValue, "StampedValue: provided value of the '"
190-
<< name_ << "/" << value_->mapValue().begin()->first
190+
<< name_ << "." << value_->mapValue().begin()->first
191191
<< "' parameter has invalid type: "
192192
<< Element::typeToName(type));
193193
}

src/lib/dhcpsrv/cb_ctl_dhcp.h

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,34 @@ class CBControlDHCP : public process::CBControlBase<ConfigBackendMgrType> {
3232
: process::CBControlBase<ConfigBackendMgrType>() {
3333
}
3434

35+
/// @brief It translates the top level map parameters from flat naming
36+
/// format (e.g. param-name.sub-param-name) to the respective param-name and
37+
/// sub-param-name. If the name does not contain '.', the param-name will
38+
/// contain the initial name.
39+
///
40+
/// @param name The name in flat format (e.g. map-name.element-name).
41+
/// @param[out] param_name The resulting top level param name.
42+
/// @param[out] sub_param_name The resulting sub param name inside the map.
43+
///
44+
/// @return The function returns true if any conversion is done, false
45+
/// otherwise.
46+
static bool translateName(std::string const& name, std::string& param_name,
47+
std::string& sub_param_name) {
48+
param_name = name;
49+
sub_param_name = std::string();
50+
auto pos = param_name.find('.');
51+
if (pos != std::string::npos) {
52+
sub_param_name = param_name.substr(pos + 1);
53+
param_name = param_name.substr(0, pos);
54+
return (true);
55+
}
56+
return (false);
57+
}
58+
3559
protected:
3660

3761
/// @brief It translates the top level map parameters from flat naming
38-
/// format (e.g. map-name/element-name) to proper ElementMap objects and
62+
/// format (e.g. param-name.sub-param-name) to proper ElementMap objects and
3963
/// adds all globals fetched from config backend(s) to a SrvConfig instance
4064
///
4165
/// Iterates over the given collection of global parameters and adds them to
@@ -54,20 +78,18 @@ class CBControlDHCP : public process::CBControlBase<ConfigBackendMgrType> {
5478
continue;
5579
}
5680

57-
std::string name = cb_global->getName();
58-
auto pos = name.find('/');
59-
if (pos != std::string::npos) {
60-
const std::string sub_elem(name.substr(pos + 1));
61-
name = name.substr(0, pos);
62-
data::ElementPtr sub_param = boost::const_pointer_cast<data::Element>(external_cfg->getConfiguredGlobal(name));
81+
std::string param_name;
82+
std::string sub_param_name;
83+
if (translateName(cb_global->getName(), param_name, sub_param_name)) {
84+
data::ElementPtr sub_param = boost::const_pointer_cast<data::Element>(external_cfg->getConfiguredGlobal(param_name));
6385
if (!sub_param) {
6486
sub_param = data::Element::createMap();
6587
}
66-
sub_param->set(sub_elem, cb_global->getElementValue());
67-
external_cfg->addConfiguredGlobal(name, sub_param);
88+
sub_param->set(sub_param_name, cb_global->getElementValue());
89+
external_cfg->addConfiguredGlobal(param_name, sub_param);
6890
} else {
6991
// Reuse name and value.
70-
external_cfg->addConfiguredGlobal(name, cb_global->getElementValue());
92+
external_cfg->addConfiguredGlobal(param_name, cb_global->getElementValue());
7193
}
7294
}
7395
}

src/lib/dhcpsrv/parsers/dhcp_parsers.cc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,7 @@ D2ClientConfigParser::setAllDefaults(isc::data::ConstElementPtr d2_config) {
16601660
void
16611661
CompatibilityParser::parse(ConstElementPtr compatibility, SrvConfig& srv_cfg) {
16621662
if (compatibility) {
1663+
auto family = CfgMgr::instance().getFamily();
16631664
for (auto const& kv : compatibility->mapValue()) {
16641665
if (!kv.second || (kv.second->getType() != Element::boolean)) {
16651666
isc_throw(DhcpConfigError,
@@ -1669,12 +1670,19 @@ CompatibilityParser::parse(ConstElementPtr compatibility, SrvConfig& srv_cfg) {
16691670
}
16701671
if (kv.first == "lenient-option-parsing") {
16711672
srv_cfg.setLenientOptionParsing(kv.second->boolValue());
1672-
} else if (kv.first == "ignore-dhcp-server-identifier") {
1673-
srv_cfg.setIgnoreServerIdentifier(kv.second->boolValue());
1674-
} else if (kv.first == "ignore-rai-link-selection") {
1675-
srv_cfg.setIgnoreRAILinkSelection(kv.second->boolValue());
1676-
} else if (kv.first == "exclude-first-last-24") {
1677-
srv_cfg.setExcludeFirstLast24(kv.second->boolValue());
1673+
} else if (family == AF_INET) {
1674+
if (kv.first == "ignore-dhcp-server-identifier") {
1675+
srv_cfg.setIgnoreServerIdentifier(kv.second->boolValue());
1676+
} else if (kv.first == "ignore-rai-link-selection") {
1677+
srv_cfg.setIgnoreRAILinkSelection(kv.second->boolValue());
1678+
} else if (kv.first == "exclude-first-last-24") {
1679+
srv_cfg.setExcludeFirstLast24(kv.second->boolValue());
1680+
} else {
1681+
isc_throw(DhcpConfigError,
1682+
"unsupported compatibility parameter: "
1683+
<< kv.first << " (" << kv.second->getPosition()
1684+
<< ")");
1685+
}
16781686
} else {
16791687
isc_throw(DhcpConfigError,
16801688
"unsupported compatibility parameter: "

src/lib/dhcpsrv/testutils/generic_backend_unittest.cc

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <dhcp/libdhcp++.h>
1010
#include <dhcp/option_vendor.h>
11+
#include <dhcpsrv/cb_ctl_dhcp.h>
1112
#include <dhcpsrv/testutils/generic_backend_unittest.h>
1213
#include <util/buffer.h>
1314
#include <typeinfo>
@@ -115,22 +116,18 @@ GenericBackendTest::checkConfiguredGlobal(const SrvConfigPtr& srv_cfg,
115116
const std::string &name,
116117
ConstElementPtr exp_value) {
117118
ConstCfgGlobalsPtr globals = srv_cfg->getConfiguredGlobals();
118-
std::string name_elem = name;
119-
std::string sub_elem;
120-
auto pos = name_elem.find('/');
121-
if (pos != std::string::npos) {
122-
sub_elem = name_elem.substr(pos + 1);
123-
name_elem = name_elem.substr(0, pos);
124-
}
119+
std::string param_name;
120+
std::string sub_param_name;
121+
bool translated = CBControlDHCP<bool>::translateName(name, param_name, sub_param_name);
125122

126-
ConstElementPtr found_global = globals->get(name_elem);
123+
ConstElementPtr found_global = globals->get(param_name);
127124
ASSERT_TRUE(found_global) << "expected global: "
128-
<< name_elem << " not found";
125+
<< param_name << " not found";
129126

130-
if (!sub_elem.empty()) {
127+
if (translated) {
131128
ASSERT_EQ(Element::map, found_global->getType())
132-
<< "expected global: " << name_elem << " has wrong type";
133-
found_global = found_global->get(sub_elem);
129+
<< "expected global: " << param_name << " has wrong type";
130+
found_global = found_global->get(sub_param_name);
134131
ASSERT_TRUE(found_global) << "expected global: "
135132
<< name << " not found";
136133
}

src/share/api/remote-global-parameter4-del.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"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."
66
],
77
"cmd-comment": [
8-
"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."
8+
"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."
99
],
1010
"cmd-syntax": [
1111
"{",

src/share/api/remote-global-parameter4-get.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"This command fetches the selected global parameter for the server from the specified database."
66
],
77
"cmd-comment": [
8-
"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."
8+
"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."
99
],
1010
"cmd-syntax": [
1111
"{",

src/share/api/remote-global-parameter6-del.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"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."
66
],
77
"cmd-comment": [
8-
"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."
8+
"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."
99
],
1010
"cmd-syntax": [
1111
"{",

src/share/api/remote-global-parameter6-get.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"This command fetches the selected global parameter for the server from the specified database."
66
],
77
"cmd-comment": [
8-
"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."
8+
"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."
99
],
1010
"cmd-syntax": [
1111
"{",

0 commit comments

Comments
 (0)