Commit 85640c19 authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[5033] - migrated D2ClientConfigParser to SimpleParser, kea-dhcp4 uses it

src/bin/dhcp4/json_config_parser.cc
    createGlobalDhcp4ConfigParser()
    - added clause to invoke new D2ClientConfigParser to
    set staging config
    - added clause to apply staged D2ClientConfig (formerly done
    by parser commit

src/bin/dhcp4/parser_context.h
src/bin/dhcp4/parser_context.cc
    aded PARSER_DHCP_DDNS context

src/bin/dhcp4/simple_parser4.h
src/bin/dhcp4/simple_parser4.cc
    defined SimpleParser4::D2_CLIENT_CONFIG_DEFAULTS
    SimpleParser4::setAllDefaults() - now sets defaults
    for D2ClientConfig

src/bin/dhcp4/tests/d2_unittest.cc
src/bin/dhcp4/tests/fqdn_unittest.cc
    Updated replace-name-mode values (true/false no longer supported)

src/lib/dhcpsrv/parsers/dhcp_parsers.h
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
    D2ClientConfig now derives from SimpleParser

src/lib/dhcpsrv/srv_config.h
src/lib/dhcpsrv/srv_config.cc
    Added a D2ClientConfigPtr member to SrvConfig.

src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
    Updated tests to set D2 client config defaults

doc/guide/dhcp4-srv.xml
    Updated, replace-client-name no longer accepts booleans
parent 6bb31a56
...@@ -2174,9 +2174,10 @@ It is merely echoed by the server ...@@ -2174,9 +2174,10 @@ It is merely echoed by the server
<note> <note>
Note that formerly, this parameter was a boolean and permitted only values Note that formerly, this parameter was a boolean and permitted only values
of <command>true</command> and <command>false</command>. Boolean values of <command>true</command> and <command>false</command>. Boolean values
will still be accepted but may eventually be deprecated. A value of have been deprecated and are no longer accepted. If you are currently using
<command>true</command> equates to <command>when-present</command>, booleans, you must replace them with the desired mode name. A value of
<command>false</command> equates to <command>never</command>. <command>true</command> maps to <command>"when-present"</command>, while
<command>false</command> maps to <command>"never"</command>.
</note> </note>
For example, To instruct kea-dhcp4 to always generate the FQDN for a For example, To instruct kea-dhcp4 to always generate the FQDN for a
......
...@@ -436,8 +436,7 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id, ...@@ -436,8 +436,7 @@ DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
parser = new HooksLibrariesParser(config_id); parser = new HooksLibrariesParser(config_id);
} else if (config_id.compare("echo-client-id") == 0) { } else if (config_id.compare("echo-client-id") == 0) {
parser = new BooleanParser(config_id, globalContext()->boolean_values_); parser = new BooleanParser(config_id, globalContext()->boolean_values_);
} else if (config_id.compare("dhcp-ddns") == 0) { // dhcp-ddns has been converted to SimpleParser.
parser = new D2ClientConfigParser(config_id);
} else if (config_id.compare("match-client-id") == 0) { } else if (config_id.compare("match-client-id") == 0) {
parser = new BooleanParser(config_id, globalContext()->boolean_values_); parser = new BooleanParser(config_id, globalContext()->boolean_values_);
} else if (config_id.compare("control-socket") == 0) { } else if (config_id.compare("control-socket") == 0) {
...@@ -637,6 +636,13 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { ...@@ -637,6 +636,13 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
continue; continue;
} }
if (config_pair.first == "dhcp-ddns") {
D2ClientConfigParser parser;
D2ClientConfigPtr cfg = parser.parse(config_pair.second);
CfgMgr::instance().getStagingCfg()->setD2ClientConfig(cfg);
continue;
}
ParserPtr parser(createGlobalDhcp4ConfigParser(config_pair.first, ParserPtr parser(createGlobalDhcp4ConfigParser(config_pair.first,
config_pair.second)); config_pair.second));
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED) LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PARSER_CREATED)
...@@ -735,6 +741,13 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { ...@@ -735,6 +741,13 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
if (hooks_parser) { if (hooks_parser) {
hooks_parser->commit(); hooks_parser->commit();
} }
{
// Used to be done by parser commit
D2ClientConfigPtr cfg;
cfg = CfgMgr::instance().getStagingCfg()->getD2ClientConfig();
CfgMgr::instance().setD2ClientConfig(cfg);
}
} }
catch (const isc::Exception& ex) { catch (const isc::Exception& ex) {
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what()); LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
......
// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -159,6 +159,8 @@ Parser4Context::contextName() ...@@ -159,6 +159,8 @@ Parser4Context::contextName()
return ("loggers"); return ("loggers");
case OUTPUT_OPTIONS: case OUTPUT_OPTIONS:
return ("output-options"); return ("output-options");
case DHCP_DDNS:
return ("dhcp-ddns");
default: default:
return ("__unknown__"); return ("__unknown__");
} }
......
// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -80,7 +80,10 @@ public: ...@@ -80,7 +80,10 @@ public:
PARSER_OPTION_DATA, PARSER_OPTION_DATA,
/// This will parse the input as hooks-library. /// This will parse the input as hooks-library.
PARSER_HOOKS_LIBRARY PARSER_HOOKS_LIBRARY,
/// This will parse the input as dhcp-ddns.
PARSER_DHCP_DDNS
} ParserType; } ParserType;
/// @brief Default constructor. /// @brief Default constructor.
...@@ -184,9 +187,6 @@ public: ...@@ -184,9 +187,6 @@ public:
///< Used while parsing content of Dhcp4. ///< Used while parsing content of Dhcp4.
DHCP4, DHCP4,
// not yet DHCP6,
// not yet DHCP_DDNS,
///< Used while parsing content of Logging ///< Used while parsing content of Logging
LOGGING, LOGGING,
...@@ -241,7 +241,10 @@ public: ...@@ -241,7 +241,10 @@ public:
LOGGERS, LOGGERS,
/// Used while parsing Logging/loggers/output_options structures. /// Used while parsing Logging/loggers/output_options structures.
OUTPUT_OPTIONS OUTPUT_OPTIONS,
/// Used while parsing Dhcp4/dhcp-ddns
DHCP_DDNS
} ParserContext; } ParserContext;
/// @brief File name /// @brief File name
......
...@@ -71,6 +71,27 @@ const ParamsList SimpleParser4::INHERIT_GLOBAL_TO_SUBNET4 = { ...@@ -71,6 +71,27 @@ const ParamsList SimpleParser4::INHERIT_GLOBAL_TO_SUBNET4 = {
"rebind-timer", "rebind-timer",
"valid-lifetime" "valid-lifetime"
}; };
/// @brief This table defines default values for D2 client configuration
///
const SimpleDefaults SimpleParser4::D2_CLIENT_CONFIG_DEFAULTS = {
{ "server-ip", Element::string, "127.0.0.1" },
{ "server-port", Element::integer, "53001" },
// default sender-ip depends on server-ip family, so we leave default blank
// parser knows to use the appropriate ZERO address based on server-ip
{ "sender-ip", Element::string, "" },
{ "sender-port", Element::integer, "0" },
{ "max-queue-size", Element::integer, "1024" },
{ "ncr-protocol", Element::string, "UDP" },
{ "ncr-format", Element::string, "JSON" },
{ "always-include-fqdn", Element::boolean, "false" },
{ "override-no-update", Element::boolean, "false" },
{ "override-client-update", Element::boolean, "false" },
{ "replace-client-name", Element::string, "NEVER" },
{ "generated-prefix", Element::string, "myhost" },
{ "qualifying-suffix", Element::string, "" }
};
/// @} /// @}
/// --------------------------------------------------------------------------- /// ---------------------------------------------------------------------------
...@@ -99,6 +120,22 @@ size_t SimpleParser4::setAllDefaults(isc::data::ElementPtr global) { ...@@ -99,6 +120,22 @@ size_t SimpleParser4::setAllDefaults(isc::data::ElementPtr global) {
} }
} }
ConstElementPtr d2_client = global->get("dhcp-ddns");
/// @todo - what if it's not in global? should we add it?
if (d2_client) {
// Because "dhcp-ddns" is a MapElement and global->get()
// returns a ConstElementPtr, then we get a map we can't
// change. So go thru gyrations to create a non-const
// map, update it with default values and then replace
// the one in global with the new one. Ick.
std::map<std::string, ConstElementPtr> d2_map;
d2_client->getValue(d2_map);
ElementPtr new_map(new MapElement());
new_map->setValue(d2_map);
cnt += SimpleParser::setDefaults(new_map, D2_CLIENT_CONFIG_DEFAULTS);
global->set("dhcp-ddns", new_map);
}
return (cnt); return (cnt);
} }
......
...@@ -33,6 +33,7 @@ public: ...@@ -33,6 +33,7 @@ public:
static const isc::data::SimpleDefaults OPTION4_DEFAULTS; static const isc::data::SimpleDefaults OPTION4_DEFAULTS;
static const isc::data::SimpleDefaults GLOBAL4_DEFAULTS; static const isc::data::SimpleDefaults GLOBAL4_DEFAULTS;
static const isc::data::ParamsList INHERIT_GLOBAL_TO_SUBNET4; static const isc::data::ParamsList INHERIT_GLOBAL_TO_SUBNET4;
static const isc::data::SimpleDefaults D2_CLIENT_CONFIG_DEFAULTS;
}; };
}; };
......
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -112,7 +112,7 @@ Dhcp4SrvD2Test::configureD2(bool enable_d2, const bool exp_result, ...@@ -112,7 +112,7 @@ Dhcp4SrvD2Test::configureD2(bool enable_d2, const bool exp_result,
" \"allow-client-update\" : true, " " \"allow-client-update\" : true, "
" \"override-no-update\" : true, " " \"override-no-update\" : true, "
" \"override-client-update\" : true, " " \"override-client-update\" : true, "
" \"replace-client-name\" : true, " " \"replace-client-name\" : \"when-present\", "
" \"generated-prefix\" : \"test.prefix\", " " \"generated-prefix\" : \"test.prefix\", "
" \"qualifying-suffix\" : \"test.suffix.\" }," " \"qualifying-suffix\" : \"test.suffix.\" },"
"\"valid-lifetime\": 4000 }"; "\"valid-lifetime\": 4000 }";
......
// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -1551,8 +1551,6 @@ TEST_F(NameDhcpv4SrvTest, emptyFqdn) { ...@@ -1551,8 +1551,6 @@ TEST_F(NameDhcpv4SrvTest, emptyFqdn) {
// the supported modes. // the supported modes.
TEST_F(NameDhcpv4SrvTest, replaceClientNameModeTest) { TEST_F(NameDhcpv4SrvTest, replaceClientNameModeTest) {
// We pass mode labels in with enclosing quotes so we can also test
// unquoted boolean literals true/false
testReplaceClientNameMode("\"never\"", testReplaceClientNameMode("\"never\"",
CLIENT_NAME_NOT_PRESENT, NAME_NOT_REPLACED); CLIENT_NAME_NOT_PRESENT, NAME_NOT_REPLACED);
testReplaceClientNameMode("\"never\"", testReplaceClientNameMode("\"never\"",
...@@ -1572,18 +1570,6 @@ TEST_F(NameDhcpv4SrvTest, replaceClientNameModeTest) { ...@@ -1572,18 +1570,6 @@ TEST_F(NameDhcpv4SrvTest, replaceClientNameModeTest) {
CLIENT_NAME_NOT_PRESENT, NAME_REPLACED); CLIENT_NAME_NOT_PRESENT, NAME_REPLACED);
testReplaceClientNameMode("\"when-not-present\"", testReplaceClientNameMode("\"when-not-present\"",
CLIENT_NAME_PRESENT, NAME_NOT_REPLACED); CLIENT_NAME_PRESENT, NAME_NOT_REPLACED);
// Verify that boolean false produces the same result as RCM_NEVER
testReplaceClientNameMode("false",
CLIENT_NAME_NOT_PRESENT, NAME_NOT_REPLACED);
testReplaceClientNameMode("false",
CLIENT_NAME_PRESENT, NAME_NOT_REPLACED);
// Verify that boolean true produces the same result as RCM_WHEN_PRESENT
testReplaceClientNameMode("true",
CLIENT_NAME_NOT_PRESENT, NAME_NOT_REPLACED);
testReplaceClientNameMode("true",
CLIENT_NAME_PRESENT, NAME_REPLACED);
} }
} // end of anonymous namespace } // end of anonymous namespace
// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -82,7 +82,17 @@ CfgMgr::isDuplicate(const Subnet6& subnet) const { ...@@ -82,7 +82,17 @@ CfgMgr::isDuplicate(const Subnet6& subnet) const {
void void
CfgMgr::setD2ClientConfig(D2ClientConfigPtr& new_config) { CfgMgr::setD2ClientConfig(D2ClientConfigPtr& new_config) {
ensureCurrentAllocated();
// Note that D2ClientMgr::setD2Config() actually attempts to apply the
// configuration by stopping its sender and opening a new one and so
// forth per the new configuration.
d2_client_mgr_.setD2ClientConfig(new_config); d2_client_mgr_.setD2ClientConfig(new_config);
// Manager will throw if the set fails, if it succeeds
// we'll update our SrvConfig, configuration_, with the D2ClientConfig
// used. This is largely bookkeeping in case we ever want to compare
// configuration_ to another SrvConfig.
configuration_->setD2ClientConfig(new_config);
} }
bool bool
......
// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -148,6 +148,11 @@ public: ...@@ -148,6 +148,11 @@ public:
/// @brief Updates the DHCP-DDNS client configuration to the given value. /// @brief Updates the DHCP-DDNS client configuration to the given value.
/// ///
/// Passes the new configuration to the D2ClientMgr instance,
/// d2_client_mgr_, which will attempt to apply the new configuration
/// by shutting down its sender and opening a new connection per the new
/// configuration (see @c D2ClientMgr::setD2ClientConfig()).
///
/// @param new_config pointer to the new client configuration. /// @param new_config pointer to the new client configuration.
/// ///
/// @throw Underlying method(s) will throw D2ClientError if given an empty /// @throw Underlying method(s) will throw D2ClientError if given an empty
......
// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // 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 // License, v. 2.0. If a copy of the MPL was not distributed with this
...@@ -1237,119 +1237,85 @@ SubnetConfigParser::getOptionalParam(const std::string& name) { ...@@ -1237,119 +1237,85 @@ SubnetConfigParser::getOptionalParam(const std::string& name) {
} }
//**************************** D2ClientConfigParser ********************** //**************************** D2ClientConfigParser **********************
D2ClientConfigParser::D2ClientConfigParser(const std::string& entry_name)
: entry_name_(entry_name), boolean_values_(new BooleanStorage()),
uint32_values_(new Uint32Storage()), string_values_(new StringStorage()),
local_client_config_() {
}
D2ClientConfigParser::~D2ClientConfigParser() {
}
void D2ClientConfigPtr
D2ClientConfigParser::build(isc::data::ConstElementPtr client_config) { D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) {
BOOST_FOREACH(ConfigPair param, client_config->mapValue()) { D2ClientConfigPtr new_config;
ParserPtr parser; bool enable_updates;
try { IOAddress server_ip(0);
parser = createConfigParser(param.first); uint32_t server_port;
} catch (std::exception& ex) { IOAddress sender_ip(0);
// Catch exception in case the configuration contains the uint32_t sender_port;
// unsupported parameter. In this case, we will need to uint32_t max_queue_size;
// append the position of this element. dhcp_ddns::NameChangeProtocol ncr_protocol;
isc_throw(DhcpConfigError, ex.what() << " (" dhcp_ddns::NameChangeFormat ncr_format;
<< param.second->getPosition() << ")"); bool always_include_fqdn;
} bool override_no_update;
bool override_client_update;
parser->build(param.second); D2ClientConfig::ReplaceClientNameMode replace_client_name_mode;
parser->commit(); std::string generated_prefix;
} std::string qualifying_suffix;
std::string current_param;
/// @todo Create configuration from the configuration parameters. Because // Get all parameters that are needed to create the D2ClientConfig.
/// the validation of the D2 configuration is atomic, there is no way to // We fetch all the parameters inside their own try clause so we
/// tell which parameter is invalid. Therefore, we catch all exceptions // spit out an error with an accurate text position. Use the
/// and append the line number of the parent element. In the future we // local, current_param, to keep track of the parameter involved.
/// may should extend D2ClientConfig code so as it returns the name of
/// the invalid parameter.
try { try {
bool enable_updates = boolean_values_->getParam("enable-updates"); current_param = "enable-updates";
enable_updates = getBoolean(client_config, current_param);
if (!enable_updates && (client_config->mapValue().size() == 1)) { if (!enable_updates && (client_config->mapValue().size() == 1)) {
// If enable-updates is the only parameter and it is false then // If enable-updates is the only parameter and it is false then
// we're done. This allows for an abbreviated configuration entry // we're done. This allows for an abbreviated configuration entry
// that only contains that flag. Use the default D2ClientConfig // that only contains that flag. Use the default D2ClientConfig
// constructor to a create a disabled instance. // constructor to a create a disabled instance.
local_client_config_.reset(new D2ClientConfig()); new_config.reset(new D2ClientConfig());
return (new_config);
}
return; current_param = "server-ip";
server_ip = IOAddress(getString(client_config, (current_param)));
current_param = "server-port";
server_port = getInteger(client_config, current_param);
current_param = "sender-ip";
std::string sender_ip_str(getString(client_config, current_param));
if (sender_ip_str.empty()) {
// The default sender IP depends on the server IP family
sender_ip = (server_ip.isV4() ? IOAddress::IPV4_ZERO_ADDRESS() :
IOAddress::IPV6_ZERO_ADDRESS());
}
else {
sender_ip = IOAddress(sender_ip_str);
} }
// Get all parameters that are needed to create the D2ClientConfig. current_param = "sender-port";
sender_port = getInteger(client_config, current_param);
// The qualifying suffix is mandatory when updates are enabled current_param = "max-queue-size";
std::string qualifying_suffix = max_queue_size = getInteger(client_config, current_param);
string_values_->getParam("qualifying-suffix");
IOAddress server_ip = current_param = "ncr-protocol";
IOAddress(string_values_->getOptionalParam("server-ip", ncr_protocol = dhcp_ddns::stringToNcrProtocol(getString(client_config,
D2ClientConfig:: current_param));
DFT_SERVER_IP)); current_param = "ncr-format";
ncr_format = dhcp_ddns::stringToNcrFormat(getString(client_config,
current_param));
uint32_t server_port = current_param = "always-include-fqdn";
uint32_values_->getOptionalParam("server-port", always_include_fqdn = getBoolean(client_config, current_param);
D2ClientConfig::DFT_SERVER_PORT);
// The default sender IP depends on the server IP family current_param = "override-no-update";
asiolink::IOAddress override_no_update = getBoolean(client_config, current_param);
sender_ip(string_values_->
getOptionalParam("sender-ip", current_param = "override-client-update";
(server_ip.isV4() ? override_client_update = getBoolean(client_config, current_param);
D2ClientConfig::DFT_V4_SENDER_IP :
D2ClientConfig::DFT_V6_SENDER_IP))); // Formerly, replace-client-name was boolean, so for now we'll support
// boolean values by mapping them to the appropriate mode
uint32_t sender_port = current_param = "replace-client-name";
uint32_values_->getOptionalParam("sender-port", std::string mode_str = getString(client_config, current_param);
D2ClientConfig::
DFT_SENDER_PORT);
uint32_t max_queue_size
= uint32_values_->getOptionalParam("max-queue-size",
D2ClientConfig::
DFT_MAX_QUEUE_SIZE);
dhcp_ddns::NameChangeProtocol ncr_protocol =
dhcp_ddns::stringToNcrProtocol(string_values_->
getOptionalParam("ncr-protocol",
D2ClientConfig::
DFT_NCR_PROTOCOL));
dhcp_ddns::NameChangeFormat ncr_format
= dhcp_ddns::stringToNcrFormat(string_values_->
getOptionalParam("ncr-format",
D2ClientConfig::
DFT_NCR_FORMAT));
std::string generated_prefix =
string_values_->getOptionalParam("generated-prefix",
D2ClientConfig::
DFT_GENERATED_PREFIX);
bool always_include_fqdn =
boolean_values_->getOptionalParam("always-include-fqdn",
D2ClientConfig::
DFT_ALWAYS_INCLUDE_FQDN);
bool override_no_update =
boolean_values_->getOptionalParam("override-no-update",
D2ClientConfig::
DFT_OVERRIDE_NO_UPDATE);
bool override_client_update =
boolean_values_->getOptionalParam("override-client-update",
D2ClientConfig::
DFT_OVERRIDE_CLIENT_UPDATE);
// Formerly, replace-client-name was boolean, so for now we'll support boolean
// values by mapping them to the appropriate mode
D2ClientConfig::ReplaceClientNameMode replace_client_name_mode;
std::string mode_str;
mode_str = string_values_->getOptionalParam("replace-client-name",
D2ClientConfig::
DFT_REPLACE_CLIENT_NAME_MODE);
if (boost::iequals(mode_str, "false")) { if (boost::iequals(mode_str, "false")) {
// @todo add a debug log // @todo add a debug log
replace_client_name_mode = D2ClientConfig::RCM_NEVER; replace_client_name_mode = D2ClientConfig::RCM_NEVER;
...@@ -1362,8 +1328,52 @@ D2ClientConfigParser::build(isc::data::ConstElementPtr client_config) { ...@@ -1362,8 +1328,52 @@ D2ClientConfigParser::build(isc::data::ConstElementPtr client_config) {
stringToReplaceClientNameMode(mode_str); stringToReplaceClientNameMode(mode_str);
} }
current_param = "generated-prefix";
generated_prefix = getString(client_config, current_param);
current_param = "qualifying-suffix";
qualifying_suffix = getString(client_config, current_param);
} catch (const std::exception& ex) {
isc_throw(D2ClientError, "D2ClientConfig error: " << ex.what()
<< " " << getPosition(current_param, client_config));
}
// Now we check for logical errors. This repeats what is done in
// D2ClientConfig::validate(), but doing it here permits us to
// emit meaningful parameter position info in the error.
if (ncr_format != dhcp_ddns::FMT_JSON) {
isc_throw(D2ClientError, "D2ClientConfig error: NCR Format: "
<< dhcp_ddns::ncrFormatToString(ncr_format)
<< " is not supported."
<< " " << getPosition("ncr-format", client_config));
}
if (ncr_protocol != dhcp_ddns::NCR_UDP) {
isc_throw(D2ClientError, "D2ClientConfig error: NCR Protocol: "
<< dhcp_ddns::ncrProtocolToString(ncr_protocol)
<< " is not supported."
<< " " << getPosition("ncr-protocol", client_config));
}
if (sender_ip.getFamily() != server_ip.getFamily()) {
isc_throw(D2ClientError, "D2ClientConfig error: address family mismatch: "
<< "server-ip: " << server_ip.toText()
<< " is: " << (server_ip.isV4() ? "IPv4" : "IPv6")
<< " while sender-ip: " << sender_ip.toText()
<< " is: " << (sender_ip.isV4() ? "IPv4" : "IPv6")
<< " " << getPosition("sender-ip", client_config));
}
if (server_ip == sender_ip && server_port == sender_port) {
isc_throw(D2ClientError, "D2ClientConfig error: server and sender cannot"
" share the exact same IP address/port: "
<< server_ip.toText() << "/" << server_port
<< " " << getPosition("sender-ip", client_config));
}
try {
// Attempt to create the new client config. // Attempt to create the new client config.
local_client_config_.reset(new D2ClientConfig(enable_updates, new_config.reset(new D2ClientConfig(enable_updates,
server_ip, server_ip,
server_port, server_port,
sender_ip,