From: Thomas Markwalder Date: Wed, 11 Jan 2017 20:22:30 +0000 (-0500) Subject: [5033] - kea-dhcp6 now uses new D2ClientConfigParser X-Git-Tag: trac5112_base~6^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b20235ebf98aca3669d622260b510a622e8b2d4;p=thirdparty%2Fkea.git [5033] - kea-dhcp6 now uses new D2ClientConfigParser src/bin/dhcp6/json_config_parser.cc createGlobalDhcp6ConfigParser() - added clause to invoke new D2ClientConfigParser to set staging config - added clause to apply staged D2ClientConfig (formerly done by parser commit src/bin/dhcp6/parser_context.h src/bin/dhcp6/parser_context.cc aded PARSER_DHCP_DDNS context src/bin/dhcp4/simple_parser6.h src/bin/dhcp4/simple_parser6.cc defined SimpleParser6::D2_CLIENT_CONFIG_DEFAULTS SimpleParser6::setAllDefaults() - now sets defaults for D2ClientConfig src/bin/dhcp6/tests/d2_unittest.cc src/bin/dhcp6/tests/fqdn_unittest.cc Updated replace-name-mode values and tests (true/false no longer supported) doc/guide/dhcp6-srv.xml Updated, replace-client-name no longer accepts booleans --- diff --git a/doc/guide/dhcp6-srv.xml b/doc/guide/dhcp6-srv.xml index 27fe542a90..befae1cdbe 100644 --- a/doc/guide/dhcp6-srv.xml +++ b/doc/guide/dhcp6-srv.xml @@ -2372,9 +2372,10 @@ should include options from the isc option space: Note that formerly, this parameter was a boolean and permitted only values of true and false. Boolean values - will still be accepted but may eventually be deprecated. A value of - true equates to when-present, - false equates to never. + have been deprecated and are no longer accepted. If you are currently using + booleans, you must replace them with the desired mode name. A value of + true maps to "when-present", while + false maps to "never". For example, To instruct kea-dhcp6 to always generate the FQDN for a diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index dc8ec9e709..c8dc4f5c2a 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -742,12 +742,10 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { hooks_parser->commit(); } - { - // Used to be done by parser commit - D2ClientConfigPtr cfg; - cfg = CfgMgr::instance().getStagingCfg()->getD2ClientConfig(); - CfgMgr::instance().setD2ClientConfig(cfg); - } + // Apply the staged D2ClientConfig, used to be done by parser commit + D2ClientConfigPtr cfg; + cfg = CfgMgr::instance().getStagingCfg()->getD2ClientConfig(); + CfgMgr::instance().setD2ClientConfig(cfg); } catch (const isc::Exception& ex) { LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what()); diff --git a/src/bin/dhcp4/tests/fqdn_unittest.cc b/src/bin/dhcp4/tests/fqdn_unittest.cc index 41ef4ba788..179c2ae2fa 100644 --- a/src/bin/dhcp4/tests/fqdn_unittest.cc +++ b/src/bin/dhcp4/tests/fqdn_unittest.cc @@ -427,10 +427,7 @@ public: // in a client request correctly, according to the replace-client-name // mode configuration parameter. // - // @param mode - value to use client-name-replacment parameter - for - // mode labels such as NEVER and ALWAYS must incluce enclosing quotes: - // "\"NEVER\"". This allows us to also pass in boolean literals which - // are unquoted. + // @param mode - value to use for replace-client-name // @param client_name_flag - specifies whether or not the client request // should contain a hostname option // @param exp_replacement_flag - specifies whether or not the server is @@ -452,7 +449,7 @@ public: "\"dhcp-ddns\": {" "\"enable-updates\": true," "\"qualifying-suffix\": \"fake-suffix.isc.org.\"," - "\"replace-client-name\": %s" + "\"replace-client-name\": \"%s\"" "}}"; // Create the configuration and configure the server @@ -1551,24 +1548,24 @@ TEST_F(NameDhcpv4SrvTest, emptyFqdn) { // the supported modes. TEST_F(NameDhcpv4SrvTest, replaceClientNameModeTest) { - testReplaceClientNameMode("\"never\"", + testReplaceClientNameMode("never", CLIENT_NAME_NOT_PRESENT, NAME_NOT_REPLACED); - testReplaceClientNameMode("\"never\"", + testReplaceClientNameMode("never", CLIENT_NAME_PRESENT, NAME_NOT_REPLACED); - testReplaceClientNameMode("\"always\"", + testReplaceClientNameMode("always", CLIENT_NAME_NOT_PRESENT, NAME_REPLACED); - testReplaceClientNameMode("\"always\"", + testReplaceClientNameMode("always", CLIENT_NAME_PRESENT, NAME_REPLACED); - testReplaceClientNameMode("\"when-present\"", + testReplaceClientNameMode("when-present", CLIENT_NAME_NOT_PRESENT, NAME_NOT_REPLACED); - testReplaceClientNameMode("\"when-present\"", + testReplaceClientNameMode("when-present", CLIENT_NAME_PRESENT, NAME_REPLACED); - testReplaceClientNameMode("\"when-not-present\"", + testReplaceClientNameMode("when-not-present", CLIENT_NAME_NOT_PRESENT, NAME_REPLACED); - testReplaceClientNameMode("\"when-not-present\"", + testReplaceClientNameMode("when-not-present", CLIENT_NAME_PRESENT, NAME_NOT_REPLACED); } diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 04e1e0fcf0..9512eba44e 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -716,8 +716,7 @@ DhcpConfigParser* createGlobal6DhcpConfigParser(const std::string& config_id, parser = new DbAccessParser(config_id, DbAccessParser::HOSTS_DB); } else if (config_id.compare("hooks-libraries") == 0) { parser = new HooksLibrariesParser(config_id); - } else if (config_id.compare("dhcp-ddns") == 0) { - parser = new D2ClientConfigParser(config_id); + // dhcp-ddns has been converted to SimpleParser } else if (config_id.compare("mac-sources") == 0) { parser = new MACSourcesListConfigParser(config_id, globalContext()); @@ -911,6 +910,13 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { continue; } + if (config_pair.first == "dhcp-ddns") { + D2ClientConfigParser parser; + D2ClientConfigPtr cfg = parser.parse(config_pair.second); + CfgMgr::instance().getStagingCfg()->setD2ClientConfig(cfg); + continue; + } + ParserPtr parser(createGlobal6DhcpConfigParser(config_pair.first, config_pair.second)); LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PARSER_CREATED) @@ -1012,6 +1018,11 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { if (hooks_parser) { hooks_parser->commit(); } + + // Apply staged D2ClientConfig, used to be done by parser commit + D2ClientConfigPtr cfg; + cfg = CfgMgr::instance().getStagingCfg()->getD2ClientConfig(); + CfgMgr::instance().setD2ClientConfig(cfg); } catch (const isc::Exception& ex) { LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_FAIL).arg(ex.what()); diff --git a/src/bin/dhcp6/parser_context.cc b/src/bin/dhcp6/parser_context.cc index 6293f91bee..cd90fefc76 100644 --- a/src/bin/dhcp6/parser_context.cc +++ b/src/bin/dhcp6/parser_context.cc @@ -1,4 +1,4 @@ -// 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 // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -163,6 +163,8 @@ Parser6Context::contextName() return ("loggers"); case OUTPUT_OPTIONS: return ("output-options"); + case DHCP_DDNS: + return ("dhcp-ddns"); default: return ("__unknown__"); } diff --git a/src/bin/dhcp6/parser_context.h b/src/bin/dhcp6/parser_context.h index 077bb6e639..ea260d398c 100644 --- a/src/bin/dhcp6/parser_context.h +++ b/src/bin/dhcp6/parser_context.h @@ -1,4 +1,4 @@ -// 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 // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -83,7 +83,10 @@ public: PARSER_OPTION_DATA, /// This will parse the input as hooks-library. - PARSER_HOOKS_LIBRARY + PARSER_HOOKS_LIBRARY, + + /// This will parse the input as dhcp-ddns. (D2 client config) + PARSER_DHCP_DDNS } ParserType; /// @brief Default constructor. @@ -250,7 +253,10 @@ public: LOGGERS, /// Used while parsing Logging/loggers/output_options structures. - OUTPUT_OPTIONS + OUTPUT_OPTIONS, + + /// Used while parsing Dhcp6/dhcp-ddns + DHCP_DDNS } ParserContext; /// @brief File name diff --git a/src/bin/dhcp6/simple_parser6.cc b/src/bin/dhcp6/simple_parser6.cc index aa2844d939..f2cba8deef 100644 --- a/src/bin/dhcp6/simple_parser6.cc +++ b/src/bin/dhcp6/simple_parser6.cc @@ -1,4 +1,4 @@ -// 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 // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -73,6 +73,27 @@ const ParamsList SimpleParser6::INHERIT_GLOBAL_TO_SUBNET6 = { "preferred-lifetime", "valid-lifetime" }; + +/// @brief This table defines default values for D2 client configuration +/// +const SimpleDefaults SimpleParser6::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, "" } +}; + /// @} /// --------------------------------------------------------------------------- @@ -101,6 +122,22 @@ size_t SimpleParser6::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 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); } diff --git a/src/bin/dhcp6/simple_parser6.h b/src/bin/dhcp6/simple_parser6.h index 6093afc28e..0fa456c659 100644 --- a/src/bin/dhcp6/simple_parser6.h +++ b/src/bin/dhcp6/simple_parser6.h @@ -34,6 +34,7 @@ public: static const isc::data::SimpleDefaults OPTION6_DEFAULTS; static const isc::data::SimpleDefaults GLOBAL6_DEFAULTS; static const isc::data::ParamsList INHERIT_GLOBAL_TO_SUBNET6; + static const isc::data::SimpleDefaults D2_CLIENT_CONFIG_DEFAULTS; }; }; diff --git a/src/bin/dhcp6/tests/d2_unittest.cc b/src/bin/dhcp6/tests/d2_unittest.cc index 09d0528928..5112ff4fc3 100644 --- a/src/bin/dhcp6/tests/d2_unittest.cc +++ b/src/bin/dhcp6/tests/d2_unittest.cc @@ -1,4 +1,4 @@ -// 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 // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -117,7 +117,7 @@ Dhcp6SrvD2Test::configureD2(bool enable_d2, const bool exp_result, " \"allow-client-update\" : true, " " \"override-no-update\" : true, " " \"override-client-update\" : true, " - " \"replace-client-name\" : true, " + " \"replace-client-name\" : \"when-present\", " " \"generated-prefix\" : \"test.prefix\", " " \"qualifying-suffix\" : \"test.suffix.\" }," "\"valid-lifetime\": 4000 }"; diff --git a/src/bin/dhcp6/tests/fqdn_unittest.cc b/src/bin/dhcp6/tests/fqdn_unittest.cc index d645995f9d..b7702bcb01 100644 --- a/src/bin/dhcp6/tests/fqdn_unittest.cc +++ b/src/bin/dhcp6/tests/fqdn_unittest.cc @@ -1,4 +1,4 @@ -// 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 // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -391,10 +391,8 @@ public: // in a client request correctly, according to the replace-client-name // mode configuration parameter. // - // @param mode - value to use client-name-replacment parameter - for - // mode labels such as NEVER and ALWAYS must incluce enclosing quotes: - // "\"NEVER\"". This allows us to also pass in boolean literals which - // are unquoted. + // @param mode - value to use for replace-client-name mode + // // @param client_name_flag - specifies whether or not the client request // should contain a hostname option // @param exp_replacement_flag - specifies whether or not the server is @@ -420,7 +418,7 @@ public: "\"dhcp-ddns\": { \n" "\"enable-updates\": true, \n" "\"qualifying-suffix\": \"fake-suffix.isc.org.\", \n" - "\"replace-client-name\": %s \n" + "\"replace-client-name\": \"%s\" \n" "}} \n"; // Create the configuration and configure the server @@ -1494,39 +1492,25 @@ TEST_F(FqdnDhcpv6SrvTest, hostnameReservationDdnsDisabled) { TEST_F(FqdnDhcpv6SrvTest, replaceClientNameModeTest) { isc::dhcp::test::IfaceMgrTestConfig test_config(true); - // 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); - testReplaceClientNameMode("\"never\"", + testReplaceClientNameMode("never", CLIENT_NAME_PRESENT, NAME_NOT_REPLACED); - testReplaceClientNameMode("\"always\"", + testReplaceClientNameMode("always", CLIENT_NAME_NOT_PRESENT, NAME_REPLACED); - testReplaceClientNameMode("\"always\"", + testReplaceClientNameMode("always", CLIENT_NAME_PRESENT, NAME_REPLACED); - testReplaceClientNameMode("\"when-present\"", + testReplaceClientNameMode("when-present", CLIENT_NAME_NOT_PRESENT, NAME_NOT_REPLACED); - testReplaceClientNameMode("\"when-present\"", + testReplaceClientNameMode("when-present", CLIENT_NAME_PRESENT, NAME_REPLACED); - testReplaceClientNameMode("\"when-not-present\"", + testReplaceClientNameMode("when-not-present", CLIENT_NAME_NOT_PRESENT, NAME_REPLACED); - testReplaceClientNameMode("\"when-not-present\"", - 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", + testReplaceClientNameMode("when-not-present", 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