Kea 1.9.11
simple_parser6.cc
Go to the documentation of this file.
1// Copyright (C) 2016-2021 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <cc/data.h>
11
12#include <boost/foreach.hpp>
13
14using namespace isc::data;
15
16namespace isc {
17namespace dhcp {
32
39 { "data-directory", Element::string },
40 { "preferred-lifetime", Element::integer },
41 { "min-preferred-lifetime", Element::integer },
42 { "max-preferred-lifetime", Element::integer },
43 { "valid-lifetime", Element::integer },
44 { "min-valid-lifetime", Element::integer },
45 { "max-valid-lifetime", Element::integer },
46 { "renew-timer", Element::integer },
47 { "rebind-timer", Element::integer },
48 { "decline-probation-period", Element::integer },
49 { "subnet6", Element::list },
50 { "shared-networks", Element::list },
51 { "interfaces-config", Element::map },
52 { "lease-database", Element::map },
53 { "hosts-database", Element::map },
54 { "hosts-databases", Element::list },
55 { "mac-sources", Element::list },
56 { "relay-supplied-options", Element::list },
57 { "host-reservation-identifiers", Element::list },
58 { "client-classes", Element::list },
59 { "option-def", Element::list },
60 { "option-data", Element::list },
61 { "hooks-libraries", Element::list },
62 { "expired-leases-processing", Element::map },
63 { "server-id", Element::map },
64 { "dhcp4o6-port", Element::integer },
65 { "control-socket", Element::map },
66 { "dhcp-queue-control", Element::map },
67 { "dhcp-ddns", Element::map },
68 { "user-context", Element::map },
69 { "comment", Element::string },
70 { "sanity-checks", Element::map },
71 { "reservations", Element::list },
72 { "config-control", Element::map },
73 { "server-tag", Element::string },
74 { "reservation-mode", Element::string },
75 { "reservations-global", Element::boolean },
76 { "reservations-in-subnet", Element::boolean },
77 { "reservations-out-of-pool", Element::boolean },
78 { "calculate-tee-times", Element::boolean },
79 { "t1-percent", Element::real },
80 { "t2-percent", Element::real },
81 { "loggers", Element::list },
82 { "hostname-char-set", Element::string },
83 { "hostname-char-replacement", Element::string },
84 { "ddns-send-updates", Element::boolean },
85 { "ddns-override-no-update", Element::boolean },
86 { "ddns-override-client-update", Element::boolean },
87 { "ddns-replace-client-name", Element::string },
88 { "ddns-generated-prefix", Element::string },
89 { "ddns-qualifying-suffix", Element::string },
90 { "store-extended-info", Element::boolean },
91 { "statistic-default-sample-count", Element::integer },
92 { "statistic-default-sample-age", Element::integer },
93 { "multi-threading", Element::map },
94 { "cache-threshold", Element::real },
95 { "cache-max-age", Element::integer },
96 { "ip-reservations-unique", Element::boolean },
97 { "ddns-update-on-renew", Element::boolean },
98 { "ddns-use-conflict-resolution", Element::boolean },
99 { "compatibility", Element::map },
100};
101
108 { "preferred-lifetime", Element::integer, "3600" },
109 { "valid-lifetime", Element::integer, "7200" },
110 { "decline-probation-period", Element::integer, "86400" }, // 24h
111 { "dhcp4o6-port", Element::integer, "0" },
112 { "server-tag", Element::string, "" },
113 { "reservations-global", Element::boolean, "false" },
114 { "reservations-in-subnet", Element::boolean, "true" },
115 { "reservations-out-of-pool", Element::boolean, "false" },
116 { "calculate-tee-times", Element::boolean, "true" },
117 { "t1-percent", Element::real, ".50" },
118 { "t2-percent", Element::real, ".80" },
119 { "ddns-send-updates", Element::boolean, "true" },
120 { "ddns-override-no-update", Element::boolean, "false" },
121 { "ddns-override-client-update", Element::boolean, "false" },
122 { "ddns-replace-client-name", Element::string, "never" },
123 { "ddns-generated-prefix", Element::string, "myhost" },
124 { "ddns-qualifying-suffix", Element::string, "" },
125 { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
126 { "hostname-char-replacement", Element::string, "" },
127 { "store-extended-info", Element::boolean, "false" },
128 { "statistic-default-sample-count", Element::integer, "20" },
129 { "statistic-default-sample-age", Element::integer, "0" },
130 { "ip-reservations-unique", Element::boolean, "true" },
131 { "ddns-update-on-renew", Element::boolean, "false" },
132 { "ddns-use-conflict-resolution", Element::boolean, "true" }
133};
134
141 { "name", Element::string },
142 { "code", Element::integer },
143 { "type", Element::string },
144 { "record-types", Element::string },
145 { "space", Element::string },
146 { "encapsulate", Element::string },
147 { "array", Element::boolean, },
148 { "user-context", Element::map },
149 { "comment", Element::string },
150 { "metadata", Element::map }
151};
152
158 { "record-types", Element::string, ""},
159 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
160 { "array", Element::boolean, "false"},
161 { "encapsulate", Element::string, "" }
162};
163
170 { "name", Element::string },
171 { "data", Element::string },
172 { "code", Element::integer },
173 { "space", Element::string },
174 { "csv-format", Element::boolean },
175 { "always-send", Element::boolean },
176 { "user-context", Element::map },
177 { "comment", Element::string },
178 { "metadata", Element::map }
179};
180
187 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
188 { "csv-format", Element::boolean, "true"},
189 { "always-send", Element::boolean, "false"}
190};
191
198 { "preferred-lifetime", Element::integer },
199 { "min-preferred-lifetime", Element::integer },
200 { "max-preferred-lifetime", Element::integer },
201 { "valid-lifetime", Element::integer },
202 { "min-valid-lifetime", Element::integer },
203 { "max-valid-lifetime", Element::integer },
204 { "renew-timer", Element::integer },
205 { "rebind-timer", Element::integer },
206 { "option-data", Element::list },
207 { "pools", Element::list },
208 { "pd-pools", Element::list },
209 { "subnet", Element::string },
210 { "interface", Element::string },
211 { "interface-id", Element::string },
212 { "id", Element::integer },
213 { "rapid-commit", Element::boolean },
214 { "client-class", Element::string },
215 { "require-client-classes", Element::list },
216 { "reservations", Element::list },
217 { "reservation-mode", Element::string },
218 { "reservations-global", Element::boolean },
219 { "reservations-in-subnet", Element::boolean },
220 { "reservations-out-of-pool", Element::boolean },
221 { "relay", Element::map },
222 { "user-context", Element::map },
223 { "comment", Element::string },
224 { "calculate-tee-times", Element::boolean },
225 { "t1-percent", Element::real },
226 { "t2-percent", Element::real },
227 { "ddns-send-updates", Element::boolean },
228 { "ddns-override-no-update", Element::boolean },
229 { "ddns-override-client-update", Element::boolean },
230 { "ddns-replace-client-name", Element::string },
231 { "ddns-generated-prefix", Element::string },
232 { "ddns-qualifying-suffix", Element::string },
233 { "hostname-char-set", Element::string },
234 { "hostname-char-replacement", Element::string },
235 { "store-extended-info", Element::boolean },
236 { "metadata", Element::map },
237 { "cache-threshold", Element::real },
238 { "cache-max-age", Element::integer },
239 { "ddns-update-on-renew", Element::boolean },
240 { "ddns-use-conflict-resolution", Element::boolean }
241};
242
250 { "id", Element::integer, "0" }, // 0 means autogenerate
251 { "interface", Element::string, "" },
252 { "client-class", Element::string, "" },
253 { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
254 { "interface-id", Element::string, "" }
255};
256
263 { "client-class", Element::string, "" },
264 { "interface", Element::string, "" },
265 { "interface-id", Element::string, "" },
266 { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
267};
268
279 "preferred-lifetime",
280 "min-preferred-lifetime",
281 "max-preferred-lifetime",
282 "rebind-timer",
283 "relay",
284 "renew-timer",
285 "valid-lifetime",
286 "min-valid-lifetime",
287 "max-valid-lifetime",
288 "calculate-tee-times",
289 "t1-percent",
290 "t2-percent",
291 "store-extended-info",
292 "cache-threshold",
293 "cache-max-age"
294};
295
302 { "pool", Element::string },
303 { "option-data", Element::list },
304 { "client-class", Element::string },
305 { "require-client-classes", Element::list },
306 { "user-context", Element::map },
307 { "comment", Element::string },
308 { "metadata", Element::map }
309};
310
317 { "prefix", Element::string },
318 { "prefix-len", Element::integer },
319 { "delegated-len", Element::integer },
320 { "option-data", Element::list },
321 { "client-class", Element::string },
322 { "require-client-classes", Element::list },
323 { "excluded-prefix", Element::string },
324 { "excluded-prefix-len", Element::integer },
325 { "user-context", Element::map },
326 { "comment", Element::string },
327 { "metadata", Element::map }
328};
329
336 { "name", Element::string },
337 { "subnet6", Element::list },
338 { "interface", Element::string },
339 { "interface-id", Element::string },
340 { "renew-timer", Element::integer },
341 { "rebind-timer", Element::integer },
342 { "option-data", Element::list },
343 { "relay", Element::map },
344 { "reservation-mode", Element::string },
345 { "reservations-global", Element::boolean },
346 { "reservations-in-subnet", Element::boolean },
347 { "reservations-out-of-pool", Element::boolean },
348 { "client-class", Element::string },
349 { "require-client-classes", Element::list },
350 { "preferred-lifetime", Element::integer },
351 { "min-preferred-lifetime", Element::integer },
352 { "max-preferred-lifetime", Element::integer },
353 { "rapid-commit", Element::boolean },
354 { "valid-lifetime", Element::integer },
355 { "min-valid-lifetime", Element::integer },
356 { "max-valid-lifetime", Element::integer },
357 { "user-context", Element::map },
358 { "comment", Element::string },
359 { "calculate-tee-times", Element::boolean },
360 { "t1-percent", Element::real },
361 { "t2-percent", Element::real },
362 { "ddns-send-updates", Element::boolean },
363 { "ddns-override-no-update", Element::boolean },
364 { "ddns-override-client-update", Element::boolean },
365 { "ddns-replace-client-name", Element::string },
366 { "ddns-generated-prefix", Element::string },
367 { "ddns-qualifying-suffix", Element::string },
368 { "hostname-char-set", Element::string },
369 { "hostname-char-replacement", Element::string },
370 { "store-extended-info", Element::boolean },
371 { "metadata", Element::map },
372 { "cache-threshold", Element::real },
373 { "cache-max-age", Element::integer },
374 { "ddns-update-on-renew", Element::boolean },
375 { "ddns-use-conflict-resolution", Element::boolean }
376};
377
380 { "id", Element::integer, "0" } // 0 means autogenerate
381};
382
385 { "re-detect", Element::boolean, "true" }
386};
387
390 { "enable-queue", Element::boolean, "false"},
391 { "queue-type", Element::string, "kea-ring6"},
392 { "capacity", Element::integer, "64"}
393};
394
397 { "enable-multi-threading", Element::boolean, "false" },
398 { "thread-pool-size", Element::integer, "0" },
399 { "packet-queue-size", Element::integer, "64" }
400};
401
404 { "lease-checks", Element::string, "warn" }
405};
406
408
412
414 size_t cnt = 0;
415
416 // Set global defaults first.
417 cnt = setDefaults(global, GLOBAL6_DEFAULTS);
418
419 // Now set the defaults for each specified option definition
420 ConstElementPtr option_defs = global->get("option-def");
421 if (option_defs) {
422 BOOST_FOREACH(ElementPtr option_def, option_defs->listValue()) {
423 cnt += SimpleParser::setDefaults(option_def, OPTION6_DEF_DEFAULTS);
424 }
425 }
426
427 // Set the defaults for option data
428 ConstElementPtr options = global->get("option-data");
429 if (options) {
430 BOOST_FOREACH(ElementPtr single_option, options->listValue()) {
431 cnt += SimpleParser::setDefaults(single_option, OPTION6_DEFAULTS);
432 }
433 }
434
435 // Now set the defaults for defined subnets
436 ConstElementPtr subnets = global->get("subnet6");
437 if (subnets) {
438 cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
439 }
440
441 // Set the defaults for interfaces config
442 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
443 if (ifaces_cfg) {
444 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
445 cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
446 }
447
448 // Set defaults for shared networks
449 ConstElementPtr shared = global->get("shared-networks");
450 if (shared) {
451 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
452
454
455 ConstElementPtr subs = net->get("subnet6");
456 if (subs) {
458 }
459 }
460 }
461
462 // Set the defaults for dhcp-queue-control. If the element isn't there
463 // we'll add it.
464 ConstElementPtr queue_control = global->get("dhcp-queue-control");
465 ElementPtr mutable_cfg;
466 if (queue_control) {
467 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
468 } else {
469 mutable_cfg = Element::createMap();
470 global->set("dhcp-queue-control", mutable_cfg);
471 }
472
473 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
474
475 // Set the defaults for multi-threading. If the element isn't there
476 // we'll add it.
477 ConstElementPtr multi_threading = global->get("multi-threading");
478 if (multi_threading) {
479 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
480 } else {
481 mutable_cfg = Element::createMap();
482 global->set("multi-threading", mutable_cfg);
483 }
484
485 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS);
486
487 // Set the defaults for sanity-checks. If the element isn't
488 // there we'll add it.
489 ConstElementPtr sanity_checks = global->get("sanity-checks");
490 if (sanity_checks) {
491 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
492 } else {
493 mutable_cfg = Element::createMap();
494 global->set("sanity-checks", mutable_cfg);
495 }
496
497 cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
498
499 return (cnt);
500}
501
503 size_t cnt = 0;
504
505 // Now derive global parameters into subnets.
506 ConstElementPtr subnets = global->get("subnet6");
507 if (subnets) {
508 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
509 cnt += SimpleParser::deriveParams(global, single_subnet,
511 }
512 }
513
514 // Deriving parameters for shared networks is a bit more involved.
515 // First, the shared-network level derives from global, and then
516 // subnets within derive from it.
517 ConstElementPtr shared = global->get("shared-networks");
518 if (shared) {
519 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
520 // First try to inherit the parameters from shared network,
521 // if defined there.
522 // Then try to inherit them from global.
523 cnt += SimpleParser::deriveParams(global, net,
525
526 // Now we need to go thrugh all the subnets in this net.
527 subnets = net->get("subnet6");
528 if (subnets) {
529 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
530 cnt += SimpleParser::deriveParams(net, single_subnet,
532 }
533 }
534 }
535 }
536
537 return (cnt);
538}
539
540} // namespace dhcp
541} // namespace isc
static size_t setListDefaults(isc::data::ConstElementPtr list, const SimpleDefaults &default_values)
Sets the default values for all entries in a list.
static size_t setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
static const isc::data::SimpleDefaults SHARED_SUBNET6_DEFAULTS
This table defines default values for each IPv6 subnet.
static const isc::data::SimpleDefaults SUBNET6_DEFAULTS
This table defines default values for each IPv6 subnet.
static const isc::data::SimpleDefaults DHCP_QUEUE_CONTROL6_DEFAULTS
This table defines default values for dhcp-queue-control in DHCPv6.
static const isc::data::SimpleKeywords POOL6_PARAMETERS
This table defines all pool parameters.
static const isc::data::SimpleKeywords SHARED_NETWORK6_PARAMETERS
This table defines all shared network parameters for DHCPv6.
static const isc::data::SimpleDefaults GLOBAL6_DEFAULTS
This table defines default global values for DHCPv6.
static const isc::data::SimpleKeywords SUBNET6_PARAMETERS
This table defines all subnet parameters for DHCPv6.
static const isc::data::SimpleDefaults IFACE6_DEFAULTS
This table defines default values for interfaces for DHCPv6.
static const isc::data::SimpleDefaults OPTION6_DEF_DEFAULTS
This table defines default values for option definitions in DHCPv6.
static const isc::data::SimpleKeywords GLOBAL6_PARAMETERS
This table defines all global parameters in DHCPv6.
static const isc::data::SimpleDefaults OPTION6_DEFAULTS
This table defines default values for options in DHCPv6.
static const isc::data::SimpleDefaults SHARED_NETWORK6_DEFAULTS
This table defines default values for each IPv6 subnet that is part of a shared network.
static const isc::data::SimpleKeywords OPTION6_PARAMETERS
This table defines all option parameters.
static size_t deriveParameters(isc::data::ElementPtr global)
Derives (inherits) all parameters from global to more specific scopes.
static size_t setAllDefaults(isc::data::ElementPtr global)
Sets all defaults for DHCPv6 configuration.
static const isc::data::SimpleKeywords OPTION6_DEF_PARAMETERS
This table defines all option definition parameters.
static const isc::data::SimpleDefaults DHCP_MULTI_THREADING6_DEFAULTS
This table defines default values for multi-threading in DHCPv6.
static const isc::data::ParamsList INHERIT_TO_SUBNET6
List of parameters that can be inherited from the global to subnet6 scope.
static const isc::data::SimpleDefaults SANITY_CHECKS6_DEFAULTS
This defines default values for sanity checking for DHCPv6.
static const isc::data::SimpleKeywords PD_POOL6_PARAMETERS
This table defines all prefix delegation pool parameters.
std::vector< std::string > ParamsList
This defines a list of all parameters that are derived (or inherited) between contexts.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet).
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
Defines the logger used by the top-level component of kea-lfc.