-// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Fri Jun 21 2019 16:14
+// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Mon Sep 30 2019 13:41
#include <cstddef>
#include <log/message_types.h>
extern const isc::log::MessageID DHCPSRV_CFGMGR_CONFIG4_MERGED = "DHCPSRV_CFGMGR_CONFIG4_MERGED";
extern const isc::log::MessageID DHCPSRV_CFGMGR_CONFIG6_MERGED = "DHCPSRV_CFGMGR_CONFIG6_MERGED";
extern const isc::log::MessageID DHCPSRV_CFGMGR_CONFIGURE_SERVERID = "DHCPSRV_CFGMGR_CONFIGURE_SERVERID";
+extern const isc::log::MessageID DHCPSRV_CFGMGR_DDNS_PARAMETER_IGNORED = "DHCPSRV_CFGMGR_DDNS_PARAMETER_IGNORED";
+extern const isc::log::MessageID DHCPSRV_CFGMGR_DDNS_PARAMETER_MOVED = "DHCPSRV_CFGMGR_DDNS_PARAMETER_MOVED";
extern const isc::log::MessageID DHCPSRV_CFGMGR_DEL_SUBNET4 = "DHCPSRV_CFGMGR_DEL_SUBNET4";
extern const isc::log::MessageID DHCPSRV_CFGMGR_DEL_SUBNET6 = "DHCPSRV_CFGMGR_DEL_SUBNET6";
extern const isc::log::MessageID DHCPSRV_CFGMGR_NEW_SUBNET4 = "DHCPSRV_CFGMGR_NEW_SUBNET4";
"DHCPSRV_CFGMGR_CONFIG4_MERGED", "Configuration backend data has been merged.",
"DHCPSRV_CFGMGR_CONFIG6_MERGED", "Configuration backend data has been merged.",
"DHCPSRV_CFGMGR_CONFIGURE_SERVERID", "server configuration includes specification of a server identifier",
+ "DHCPSRV_CFGMGR_DDNS_PARAMETER_IGNORED", "dhpd-ddns:%1 is deprecated, using existing global:%2",
+ "DHCPSRV_CFGMGR_DDNS_PARAMETER_MOVED", "dhcp-ddns:%1 is deprecated, moving it to global:%2",
"DHCPSRV_CFGMGR_DEL_SUBNET4", "IPv4 subnet %1 removed",
"DHCPSRV_CFGMGR_DEL_SUBNET6", "IPv6 subnet %1 removed",
"DHCPSRV_CFGMGR_NEW_SUBNET4", "a new subnet has been added to configuration: %1",
#include <dhcpsrv/parsers/simple_parser4.h>
#include <dhcpsrv/srv_config.h>
#include <dhcpsrv/lease_mgr_factory.h>
+#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/cfg_hosts_util.h>
#include <process/logging_info.h>
#include <log/logger_manager.h>
return (result);
}
-DdnsParamsPtr SrvConfig::getDdnsParams(const Subnet& subnet) const {
+DdnsParamsPtr
+SrvConfig::getDdnsParams(const Subnet& subnet) const {
DdnsParamsPtr params(new DdnsParams());
params->enable_updates_ = (getD2ClientConfig()->getEnableUpdates() &&
return params;
}
+void
+SrvConfig::moveDdnsParams(isc::data::ElementPtr d2_cfg) {
+ if (!d2_cfg || (d2_cfg->getType() != Element::map)) {
+ isc_throw(BadValue, "moveDdnsParams must be given a map element");
+ }
+
+ struct Param {
+ std::string from_name;
+ std::string to_name;
+ };
+
+ std::vector<Param> params {
+ { "override-no-update", "ddns-override-no-update" },
+ { "override-client-update", "ddns-override-client-update" },
+ { "replace-client-name", "ddns-replace-client-name" },
+ { "generated-prefix", "ddns-generated-prefix" },
+ { "qualifying-suffix", "ddns-qualifying-suffix" },
+ { "hostname-char-set", "hostname-char-set" },
+ { "hostname-char-replacement", "hostname-char-replacement" }
+ };
+
+ for (auto param : params) {
+ if (d2_cfg->contains(param.from_name)) {
+ if (!configured_globals_->contains(param.to_name)) {
+ // No global value for it already, so let's add it.
+ addConfiguredGlobal(param.to_name, d2_cfg->get(param.from_name));
+ LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_DDNS_PARAMETER_MOVED)
+ .arg(param.from_name).arg(param.to_name);
+ } else {
+ // Already a global value, we'll use it and ignore this one.
+ LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_DDNS_PARAMETER_IGNORED)
+ .arg(param.from_name).arg(param.to_name);
+ }
+
+ // Now remove it from d2_data, so D2ClientCfg won't complain.
+ d2_cfg->remove(param.from_name);
+ }
+ }
}
-}
+
+} // namespace dhcp
+} // namespace isc
}
+// Verifies that parameters formerly in dhcp-ddns{} are correctly moved
+// to configured globals.
+TEST_F(SrvConfigTest, moveDdnsParamsTest) {
+ DdnsParamsPtr params;
+
+ CfgMgr::instance().setFamily(AF_INET);
+
+ struct Scenario {
+ std::string description;
+ std::string d2_input;
+ std::string d2_output;
+ std::string input_globals;
+ std::string exp_globals;
+ };
+
+ std::vector<Scenario> scenarios {
+ {
+ "scenario 1, move with no global conflicts",
+ // d2_input
+ "{\n"
+ " \"enable-updates\": true, \n"
+ " \"server-ip\" : \"192.0.2.0\",\n"
+ " \"server-port\" : 3432,\n"
+ " \"sender-ip\" : \"192.0.2.1\",\n"
+ " \"sender-port\" : 3433,\n"
+ " \"max-queue-size\" : 2048,\n"
+ " \"ncr-protocol\" : \"UDP\",\n"
+ " \"ncr-format\" : \"JSON\",\n"
+ " \"user-context\": { \"foo\": \"bar\" },\n"
+ " \"override-no-update\": true,\n"
+ " \"override-client-update\": false,\n"
+ " \"replace-client-name\": \"always\",\n"
+ " \"generated-prefix\": \"prefix\",\n"
+ " \"qualifying-suffix\": \"suffix.com.\",\n"
+ " \"hostname-char-set\": \"[^A-Z]\",\n"
+ " \"hostname-char-replacement\": \"x\"\n"
+ "}\n",
+ // d2_output
+ "{\n"
+ " \"enable-updates\": true,\n"
+ " \"server-ip\" : \"192.0.2.0\",\n"
+ " \"server-port\" : 3432,\n"
+ " \"sender-ip\" : \"192.0.2.1\",\n"
+ " \"sender-port\" : 3433,\n"
+ " \"max-queue-size\" : 2048,\n"
+ " \"ncr-protocol\" : \"UDP\",\n"
+ " \"ncr-format\" : \"JSON\",\n"
+ " \"user-context\": { \"foo\": \"bar\" }\n"
+ "}\n",
+ // input_globals - no globals to start with
+ "{\n"
+ "}\n",
+ // exp_globals
+ "{\n"
+ " \"ddns-override-no-update\": true,\n"
+ " \"ddns-override-client-update\": false,\n"
+ " \"ddns-replace-client-name\": \"always\",\n"
+ " \"ddns-generated-prefix\": \"prefix\",\n"
+ " \"ddns-qualifying-suffix\": \"suffix.com.\",\n"
+ " \"hostname-char-set\": \"[^A-Z]\",\n"
+ " \"hostname-char-replacement\": \"x\"\n"
+ "}\n"
+ },
+
+ {
+ "scenario 2, globals already exist for all movable params",
+ // d2_input
+ "{\n"
+ " \"enable-updates\": true, \n"
+ " \"override-no-update\": true,\n"
+ " \"override-client-update\": true,\n"
+ " \"replace-client-name\": \"always\",\n"
+ " \"generated-prefix\": \"prefix\",\n"
+ " \"qualifying-suffix\": \"suffix.com.\",\n"
+ " \"hostname-char-set\": \"[^A-Z]\",\n"
+ " \"hostname-char-replacement\": \"x\"\n"
+ "}\n",
+ // d2_output
+ "{\n"
+ " \"enable-updates\": true \n"
+ "}\n",
+ // input_globals
+ "{\n"
+ " \"ddns-override-no-update\": false,\n"
+ " \"ddns-override-client-update\": false,\n"
+ " \"ddns-replace-client-name\": \"when-present\",\n"
+ " \"ddns-generated-prefix\": \"org_prefix\",\n"
+ " \"ddns-qualifying-suffix\": \"org_suffix.com.\",\n"
+ " \"hostname-char-set\": \"[^a-z]\",\n"
+ " \"hostname-char-replacement\": \"y\"\n"
+ "}\n",
+ // exp_globals
+ "{\n"
+ " \"ddns-override-no-update\": false,\n"
+ " \"ddns-override-client-update\": false,\n"
+ " \"ddns-replace-client-name\": \"when-present\",\n"
+ " \"ddns-generated-prefix\": \"org_prefix\",\n"
+ " \"ddns-qualifying-suffix\": \"org_suffix.com.\",\n"
+ " \"hostname-char-set\": \"[^a-z]\",\n"
+ " \"hostname-char-replacement\": \"y\"\n"
+ "}\n"
+ },
+
+ {
+ "scenario 3, nothing to move",
+ // d2_input
+ "{\n"
+ " \"enable-updates\": true, \n"
+ " \"server-ip\" : \"192.0.2.0\",\n"
+ " \"server-port\" : 3432,\n"
+ " \"sender-ip\" : \"192.0.2.1\"\n"
+ "}\n",
+ // d2_output
+ "{\n"
+ " \"enable-updates\": true,\n"
+ " \"server-ip\" : \"192.0.2.0\",\n"
+ " \"server-port\" : 3432,\n"
+ " \"sender-ip\" : \"192.0.2.1\"\n"
+ "}\n",
+ // input_globals
+ "{\n"
+ " \"hostname-char-set\": \"[^A-Z]\",\n"
+ " \"hostname-char-replacement\": \"x\"\n"
+ "}\n",
+ // exp_globals
+ "{\n"
+ " \"hostname-char-set\": \"[^A-Z]\",\n"
+ " \"hostname-char-replacement\": \"x\"\n"
+ "}\n"
+ },
+
+ };
+
+ for (auto scenario : scenarios) {
+ SrvConfig conf(32);
+ ConstElementPtr d2_input;
+ ConstElementPtr exp_d2_output;
+ ConstElementPtr input_globals;
+ ConstElementPtr exp_globals;
+
+ {
+ SCOPED_TRACE(scenario.description);
+ ASSERT_NO_THROW(d2_input = Element::fromJSON(scenario.d2_input))
+ << "d2_input didn't parse, test is broken";
+
+ ASSERT_NO_THROW(exp_d2_output = Element::fromJSON(scenario.d2_output))
+ << "d2_output didn't parse, test is broken";
+
+ ASSERT_NO_THROW(input_globals = Element::fromJSON(scenario.input_globals))
+ << "input_globals didn't parse, test is broken";
+
+ ASSERT_NO_THROW(exp_globals = Element::fromJSON(scenario.exp_globals))
+ << "exp_globals didn't parse, test is broken";
+
+ // Create the original set of configured globals.
+ for (auto input_global : input_globals->mapValue()) {
+ conf.addConfiguredGlobal(input_global.first, input_global.second);
+ }
+
+ // We need a mutable copy of d2_input to pass into the move function.
+ ElementPtr mutable_d2 = boost::const_pointer_cast<Element>(d2_input);
+ // NOw call moveDdnsParams.
+ ASSERT_NO_THROW(conf.moveDdnsParams(mutable_d2));
+
+ // Make sure the content of mutable_d2 is correct.
+ EXPECT_TRUE(mutable_d2->equals(*exp_d2_output));
+
+ // Make sure the content of configured globals.
+ EXPECT_TRUE(conf.getConfiguredGlobals()->equals(*exp_globals));
+ }
+ }
+}
+
+// Verifies that the scoped values for DDNS parameters can be fetched
+// for a given Subnet4.
TEST_F(SrvConfigTest, getDdnsParamsTest4) {
DdnsParamsPtr params;
EXPECT_TRUE(params->enable_updates_);
}
+// Verifies that the scoped values for DDNS parameters can be fetched
+// for a given Subnet6.
TEST_F(SrvConfigTest, getDdnsParamsTest6) {
DdnsParamsPtr params;