|
@@ -302,9 +302,6 @@ public:
|
|
|
return (answer);
|
|
|
}
|
|
|
|
|
|
- // option parsing must be done last, so save it if we hit if first
|
|
|
- ParserPtr option_parser;
|
|
|
-
|
|
|
ConfigPair config_pair;
|
|
|
try {
|
|
|
// Iterate over the config elements.
|
|
@@ -334,14 +331,8 @@ public:
|
|
|
|
|
|
// Create the parser based on element name.
|
|
|
ParserPtr parser(createConfigParser(config_pair.first));
|
|
|
- // Options must be parsed last
|
|
|
- if (config_pair.first == "option-data") {
|
|
|
- option_parser = parser;
|
|
|
- } else {
|
|
|
- // Anything else we can call build straight away.
|
|
|
- parser->build(config_pair.second);
|
|
|
- parser->commit();
|
|
|
- }
|
|
|
+ parser->build(config_pair.second);
|
|
|
+ parser->commit();
|
|
|
}
|
|
|
|
|
|
int family = parser_context_->universe_ == Option::V4
|
|
@@ -434,8 +425,7 @@ public:
|
|
|
size_t setAllDefaults(isc::data::ElementPtr global,
|
|
|
const SimpleDefaults& global_defaults,
|
|
|
const SimpleDefaults& option_defaults,
|
|
|
- const SimpleDefaults& option_def_defaults,
|
|
|
- const SimpleDefaults& d2_client_defaults) {
|
|
|
+ const SimpleDefaults& option_def_defaults) {
|
|
|
size_t cnt = 0;
|
|
|
// Set global defaults first.
|
|
|
cnt = SimpleParser::setDefaults(global, global_defaults);
|
|
@@ -455,16 +445,6 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ConstElementPtr d2_client = global->get("dhcp-ddns");
|
|
|
- /// @todo - what if it's not in global? should we add it?
|
|
|
- if (d2_client) {
|
|
|
- // Get the mutable form of d2 client config
|
|
|
- ElementPtr mutable_d2 =
|
|
|
- boost::const_pointer_cast<Element>(d2_client);
|
|
|
- cnt += SimpleParser::setDefaults(mutable_d2, d2_client_defaults);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
return (cnt);
|
|
|
}
|
|
|
|
|
@@ -521,31 +501,19 @@ public:
|
|
|
{ "valid-lifetime", Element::integer, "7200" }
|
|
|
};
|
|
|
|
|
|
- /// @brief This table defines default values for D2 client configuration
|
|
|
- const SimpleDefaults D2_CLIENT_CFG_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, "" }
|
|
|
- };
|
|
|
-
|
|
|
if (v6) {
|
|
|
setAllDefaults(config, GLOBAL6_DEFAULTS, OPTION6_DEFAULTS,
|
|
|
- OPTION6_DEF_DEFAULTS, D2_CLIENT_CFG_DEFAULTS);
|
|
|
+ OPTION6_DEF_DEFAULTS);
|
|
|
} else {
|
|
|
setAllDefaults(config, GLOBAL6_DEFAULTS, OPTION4_DEFAULTS,
|
|
|
- OPTION4_DEF_DEFAULTS, D2_CLIENT_CFG_DEFAULTS);
|
|
|
+ OPTION4_DEF_DEFAULTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// D2 client configuration code is in this library
|
|
|
+ ConstElementPtr d2_client = config->get("dhcp-ddns");
|
|
|
+ if (d2_client &&
|
|
|
+ !D2ClientConfigParser::isShortCutDisabled(d2_client)) {
|
|
|
+ D2ClientConfigParser::setAllDefaults(d2_client);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1868,7 +1836,38 @@ TEST_F(ParseConfigTest, parserDefaultsD2Config) {
|
|
|
|
|
|
/// @brief Check various invalid D2 client configurations.
|
|
|
TEST_F(ParseConfigTest, invalidD2Config) {
|
|
|
+ std::string invalid_shortcuts[] = {
|
|
|
+ // Must supply at least enable-updates
|
|
|
+ "{ \"dhcp-ddns\" :"
|
|
|
+ " {"
|
|
|
+ " }"
|
|
|
+ "}",
|
|
|
+ // Enable-updates must be a boolean
|
|
|
+ "{ \"dhcp-ddns\" :"
|
|
|
+ " {"
|
|
|
+ " \"enable-updates\" : 0"
|
|
|
+ " }"
|
|
|
+ "}",
|
|
|
+ // stop
|
|
|
+ ""
|
|
|
+ };
|
|
|
+ int i = 0;
|
|
|
+ while (!invalid_shortcuts[i].empty()) {
|
|
|
+ // Verify that the configuration string parsing throws
|
|
|
+ EXPECT_THROW(parseConfiguration(invalid_shortcuts[i]),
|
|
|
+ DhcpConfigError);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+
|
|
|
std::string invalid_configs[] = {
|
|
|
+#if simple_parser_get_position_got_fixed
|
|
|
+ // Must supply qualifying-suffix when updates are enabled
|
|
|
+ "{ \"dhcp-ddns\" :"
|
|
|
+ " {"
|
|
|
+ " \"enable-updates\" : true"
|
|
|
+ " }"
|
|
|
+ "}",
|
|
|
+#endif
|
|
|
// Invalid server ip value
|
|
|
"{ \"dhcp-ddns\" :"
|
|
|
" {"
|
|
@@ -2017,7 +2016,7 @@ TEST_F(ParseConfigTest, invalidD2Config) {
|
|
|
// Iterate through the invalid configuration strings, attempting to
|
|
|
// parse each one. They should fail to parse, but fail gracefully.
|
|
|
D2ClientConfigPtr current_config;
|
|
|
- int i = 0;
|
|
|
+ i = 0;
|
|
|
while (!invalid_configs[i].empty()) {
|
|
|
// Verify that the configuration string parses without throwing.
|
|
|
int rcode = parseConfiguration(invalid_configs[i]);
|