From: Francis Dupont Date: Mon, 16 Aug 2021 11:39:09 +0000 (+0200) Subject: [#2011] Checkpoint: updated examples X-Git-Tag: Kea-2.0.0~163 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0d44d1882d68b988bf9a8bc07dda3738c8cde461;p=thirdparty%2Fkea.git [#2011] Checkpoint: updated examples --- diff --git a/doc/Makefile.am b/doc/Makefile.am index 2a4b872c41..03f492b52e 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -5,6 +5,8 @@ EXTRA_DIST = images/kea-logo-100x70.png nobase_dist_doc_DATA = examples/agent/comments.json nobase_dist_doc_DATA += examples/agent/https.json nobase_dist_doc_DATA += examples/agent/simple.json +nobase_dist_doc_DATA += examples/ddns/all-keys.json +nobase_dist_doc_DATA += examples/ddns/all-keys-netconf.json nobase_dist_doc_DATA += examples/ddns/comments.json nobase_dist_doc_DATA += examples/ddns/gss-tsig.json nobase_dist_doc_DATA += examples/ddns/sample1.json diff --git a/doc/examples/ddns/all-keys-netconf.json b/doc/examples/ddns/all-keys-netconf.json new file mode 100644 index 0000000000..765a20f13a --- /dev/null +++ b/doc/examples/ddns/all-keys-netconf.json @@ -0,0 +1,174 @@ +// WARNING: This example configuration is not meant for production use. +// The Kea Kea's DHCP-DDNS server can refuse this configuration because +// it may contain mutually exclusive configuration parameters. +// +// The primary purpose of the example file is to provide a comprehensive +// list of parameters supported by Kea DHCP-DDNS server along with the +// brief description of each parameter. +// +// This stable version is used for YANG as we do not want to update code +// and models each time a keyword is added to the syntax. +{ + // Kea DHCP-DDNS server configuration begins here. + "DhcpDdns": { + + // Global Parameters + + // IP address D2 will listen for update requests at. + // Default is 127.0.0.1 + "ip-address": "127.0.0.1", + + // Port D2 will listen for update requests on. + // Default is 53001. + "port": 53001, + + // Maximum time to we will wait for a DNS server to respond to us. + // Unit is the millisecond, default is 100ms. + "dns-server-timeout" : 100, + + // Protocol to use for Name Change Requests from a Kea DHCP server. + // Currently only 'UDP' is supported. + "ncr-protocol": "UDP", + + // Format to use for Name Change Requests from a Kea DHCP server. + // Currently only 'JSON' is supported. + "ncr-format": "JSON", + + // Command control socket configuration parameters for Kea DHCP-DDNS server. + "control-socket": { + + // Location of the unix domain socket file the DHCP-DDNS server uses + // to receive control commands from the Kea Control Agent or the + // local server administrator. + "socket-name": "/tmp/kea-ddns-ctrl-socket", + + // Control socket type used by the Kea DHCP-DDNS server. + // The 'unix' socket is currently the only supported type. + "socket-type": "unix" + }, + + // List of hooks libraries and their specific configuration parameters + // to be loaded by Kea DHCP-DDNS server. + "hooks-libraries": [ + { + // Location of the hooks library to be loaded. + "library": "/opt/local/ddns-server-commands.so", + + // Hook library specific configuration parameters. + "parameters": { } + } + ], + + // Forward DDNS (Dynamic DNS). + "forward-ddns": { + + // List of DDNS domains. + "ddns-domains": [ + { + // Name of the zone (required). + "name": "example.com.", + + // Name of the TSIG key used to protect DNS updates. + "key-name": "d2.md5.key", + + // List of DNS servers where to send DNS updates. + "dns-servers": [ + { + // DNS server IP address (required). + "ip-address": "2001:db8:1::10", + + // DNS server UDP port. Default is 53 (DNS service). + "port": 7802 + } + ] + } + ] + }, + + // Reverse DDNS (Dynamic DNS). + "reverse-ddns": { + + // List of DDNS domains. + "ddns-domains": [ + { + // Name of the zone (required). + "name": "2.0.192.in-addr.arpa.", + + // Name of the TSIG key used to protect DNS updates. + "key-name": "d2.sha1.key", + + // List of DNS servers where to send DNS updates. + "dns-servers": [ + { + // DNS server IP address (required). + "ip-address": "172.16.1.1", + + // DNS server UDP port. Default is 53 (DNS service). + "port": 5301 + } + ] + } + ] + }, + + // List of TSIG keys used to protect DNS updates. + "tsig-keys": [ + { + // Name of the TSIG key (required). + "name": "d2.md5.key", + + // Algorithm of the TSIG key (required). + // The value must be a valid algorithm name e.g. + // HMAC-MD5, HMAC-SHA1, HMAC-SHA224, ... + "algorithm": "HMAC-MD5", + + // Number of bits in the digest. Default is 0 which means + // to use all bits provided by the algorithm. Too short values + // (depending on the algorithm) are rejected. + "digest-bits": 0, + + // Secret of the TSIG key (required) in base-64. + "secret": "LSWXnfkKZjdPJI5QxlpnfQ==" + } + ], + + // List of loggers used by the servers using this configuration file. + "loggers": [ + { + // Debug level, a value between 0..99. The greater the value + // the more detailed debug log. + "debuglevel": 99, + + // Name of the logger. + "name": "kea-dhcp-ddns", + + // Configures how the log should be output. + "output_options": [ + { + // Determines whether the log should flushed to a file. + "flush": true, + + // Specifies maximum filesize before the file is being rotated. + "maxsize": 10240000, + + // Specifies the maximum number of rotated files being kept. + "maxver": 1, + + // Specifies logging destination. + "output": "stdout", + + // Specifies log entry content + "pattern": "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i] %m\n" + } + ], + + // Specifies logging severity, i.e. "ERROR", "WARN", "INFO", "DEBUG". + "severity": "INFO" + } + ], + + // Look at sample1 example for the use of user-contexts. + "user-context": { } +} + +} diff --git a/doc/examples/ddns/all-keys.json b/doc/examples/ddns/all-keys.json new file mode 100644 index 0000000000..7de1703e32 --- /dev/null +++ b/doc/examples/ddns/all-keys.json @@ -0,0 +1,183 @@ +// WARNING: This example configuration is not meant for production use. +// The Kea Kea's DHCP-DDNS server can refuse this configuration because +// it may contain mutually exclusive configuration parameters. +// +// The primary purpose of the example file is to provide a comprehensive +// list of parameters supported by Kea DHCP-DDNS server along with the +// brief description of each parameter. +// +// This current version should be up to date, i.e. new keywords should be +// added in this file at the same time than in the syntax. +{ + // Kea DHCP-DDNS server configuration begins here. + "DhcpDdns": { + + // Global Parameters + + // IP address D2 will listen for update requests at. + // Default is 127.0.0.1 + "ip-address": "127.0.0.1", + + // Port D2 will listen for update requests on. + // Default is 53001. + "port": 53001, + + // Maximum time to we will wait for a DNS server to respond to us. + // Unit is the millisecond, default is 100ms. + "dns-server-timeout" : 100, + + // Protocol to use for Name Change Requests from a Kea DHCP server. + // Currently only 'UDP' is supported. + "ncr-protocol": "UDP", + + // Format to use for Name Change Requests from a Kea DHCP server. + // Currently only 'JSON' is supported. + "ncr-format": "JSON", + + // Command control socket configuration parameters for Kea DHCP-DDNS server. + "control-socket": { + + // Location of the unix domain socket file the DHCP-DDNS server uses + // to receive control commands from the Kea Control Agent or the + // local server administrator. + "socket-name": "/tmp/kea-ddns-ctrl-socket", + + // Control socket type used by the Kea DHCP-DDNS server. + // The 'unix' socket is currently the only supported type. + "socket-type": "unix" + }, + + // List of hooks libraries and their specific configuration parameters + // to be loaded by Kea DHCP-DDNS server. + "hooks-libraries": [ + { + // Location of the hooks library to be loaded. + "library": "/opt/local/ddns-server-commands.so", + + // Hook library specific configuration parameters. + "parameters": { } + } + ], + + // Forward DDNS (Dynamic DNS). + "forward-ddns": { + + // List of DDNS domains. + "ddns-domains": [ + { + // Name of the zone (required). + "name": "example.com.", + + // Name of the TSIG key used to protect DNS updates for + // names in the domain. + "key-name": "d2.md5.key", + + // List of DNS servers where to send DNS updates. + "dns-servers": [ + { + // DNS server IP address (required). + "ip-address": "2001:db8:1::10", + + // DNS server UDP port. Default is 53 (DNS service). + "port": 7802, + + // Name of the TSIG key used to protect DNS updates + // sent to the DNS server. + "key-name": "d2.sha1.key" + } + ] + } + ] + }, + + // Reverse DDNS (Dynamic DNS). + "reverse-ddns": { + + // List of DDNS domains. + "ddns-domains": [ + { + // Name of the zone (required). + "name": "2.0.192.in-addr.arpa.", + + // Name of the TSIG key used to protect DNS updates for + // names in the domain. + "key-name": "d2.sha1.key", + + // List of DNS servers where to send DNS updates. + "dns-servers": [ + { + // DNS server IP address (required). + "ip-address": "172.16.1.1", + + // DNS server UDP port. Default is 53 (DNS service). + "port": 5301, + + // Name of the TSIG key used to protect DNS updates + "key-name": "d2.md5.key" + } + ] + } + ] + }, + + // List of TSIG keys used to protect DNS updates. + "tsig-keys": [ + { + // Name of the TSIG key (required). + "name": "d2.md5.key", + + // Algorithm of the TSIG key (required). + // The value must be a valid algorithm name e.g. + // HMAC-MD5, HMAC-SHA1, HMAC-SHA224, ... + "algorithm": "HMAC-MD5", + + // Number of bits in the digest. Default is 0 which means + // to use all bits provided by the algorithm. Too short values + // (depending on the algorithm) are rejected. + "digest-bits": 0, + + // Secret of the TSIG key (required) in base-64. + "secret": "LSWXnfkKZjdPJI5QxlpnfQ==" + } + ], + + // List of loggers used by the servers using this configuration file. + "loggers": [ + { + // Debug level, a value between 0..99. The greater the value + // the more detailed debug log. + "debuglevel": 99, + + // Name of the logger. + "name": "kea-dhcp-ddns", + + // Configures how the log should be output. + "output_options": [ + { + // Determines whether the log should flushed to a file. + "flush": true, + + // Specifies maximum filesize before the file is being rotated. + "maxsize": 10240000, + + // Specifies the maximum number of rotated files being kept. + "maxver": 1, + + // Specifies logging destination. + "output": "stdout", + + // Specifies log entry content + "pattern": "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i] %m\n" + } + ], + + // Specifies logging severity, i.e. "ERROR", "WARN", "INFO", "DEBUG". + "severity": "INFO" + } + ], + + // Look at sample1 example for the use of user-contexts. + "user-context": { } +} + +} diff --git a/src/bin/d2/tests/parser_unittest.cc b/src/bin/d2/tests/parser_unittest.cc index 53220130e7..ff3a6b4d12 100644 --- a/src/bin/d2/tests/parser_unittest.cc +++ b/src/bin/d2/tests/parser_unittest.cc @@ -246,7 +246,7 @@ void testFile(const std::string& fname) { cout << "Parsing file " << fname << " (" << decommented << ")" << endl; - EXPECT_NO_THROW(json = Element::fromJSONFile(decommented, true)); + ASSERT_NO_THROW(json = Element::fromJSONFile(decommented, true)); reference_json = moveComments(json); // remove the temporary file @@ -272,6 +272,8 @@ void testFile(const std::string& fname) { // the second time with D2Parser. Both JSON trees are then compared. TEST(ParserTest, file) { vector configs; + configs.push_back("all-keys.json"); + configs.push_back("all-keys-netconf.json"); configs.push_back("comments.json"); configs.push_back("gss-tsig.json"); configs.push_back("sample1.json"); @@ -701,12 +703,15 @@ TEST(ParserTest, mapEntries) { } syntax_file.close(); - // Get keywords from the sample file - string sample_dir(D2_TEST_DATA_DIR); + // Get keywords from the exsample files + string sample_dir(CFG_EXAMPLES); sample_dir += "/"; ElementPtr sample_json = Element::createList(); - loadFile(sample_dir + "get_config.json", sample_json); - KeywordSet sample_keys; + loadFile(sample_dir + "all-keys.json", sample_json); + loadFile(sample_dir + "all-keys-netconf.json", sample_json); + KeywordSet sample_keys = { + "hostname" + }; // Recursively extract keywords. static void (*extract)(ConstElementPtr, KeywordSet&) = [] (ConstElementPtr json, KeywordSet& set) { @@ -755,8 +760,8 @@ void testDuplicate(ConstElementPtr json) { // This test checks that duplicate entries make parsing to fail. TEST(ParserTest, duplicateMapEntries) { // Get the config to work with from the sample file. - string sample_fname(D2_TEST_DATA_DIR); - sample_fname += "/get_config.json"; + string sample_fname(CFG_EXAMPLES); + sample_fname += "/all-keys.json"; D2ParserContext ctx; ElementPtr sample_json; EXPECT_NO_THROW(sample_json = diff --git a/src/lib/d2srv/d2_simple_parser.cc b/src/lib/d2srv/d2_simple_parser.cc index e6e8594551..81bab9c0ce 100644 --- a/src/lib/d2srv/d2_simple_parser.cc +++ b/src/lib/d2srv/d2_simple_parser.cc @@ -82,7 +82,7 @@ namespace d2 { const SimpleDefaults D2SimpleParser::D2_GLOBAL_DEFAULTS = { { "ip-address", Element::string, "127.0.0.1" }, { "port", Element::integer, "53001" }, - { "dns-server-timeout", Element::integer, "100" }, // in seconds + { "dns-server-timeout", Element::integer, "100" }, // in milliseconds { "ncr-protocol", Element::string, "UDP" }, { "ncr-format", Element::string, "JSON" } };