Kea 3.1.0
simple_parser6.cc
Go to the documentation of this file.
1// Copyright (C) 2016-2025 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
12using namespace isc::data;
13
14namespace isc {
15namespace dhcp {
30
37 { "data-directory", Element::string },
38 { "preferred-lifetime", Element::integer },
39 { "min-preferred-lifetime", Element::integer },
40 { "max-preferred-lifetime", Element::integer },
41 { "valid-lifetime", Element::integer },
42 { "min-valid-lifetime", Element::integer },
43 { "max-valid-lifetime", Element::integer },
44 { "renew-timer", Element::integer },
45 { "rebind-timer", Element::integer },
46 { "decline-probation-period", Element::integer },
47 { "subnet6", Element::list },
48 { "shared-networks", Element::list },
49 { "interfaces-config", Element::map },
50 { "lease-database", Element::map },
51 { "hosts-database", Element::map },
52 { "hosts-databases", Element::list },
53 { "mac-sources", Element::list },
54 { "relay-supplied-options", Element::list },
55 { "host-reservation-identifiers", Element::list },
56 { "client-classes", Element::list },
57 { "option-def", Element::list },
58 { "option-data", Element::list },
59 { "hooks-libraries", Element::list },
60 { "expired-leases-processing", Element::map },
61 { "server-id", Element::map },
62 { "dhcp4o6-port", Element::integer },
63 { "control-sockets", Element::list },
64 { "dhcp-queue-control", Element::map },
65 { "dhcp-ddns", Element::map },
66 { "user-context", Element::map },
67 { "comment", Element::string },
68 { "sanity-checks", Element::map },
69 { "reservations", Element::list },
70 { "config-control", Element::map },
71 { "server-tag", Element::string },
72 { "reservations-global", Element::boolean },
73 { "reservations-in-subnet", Element::boolean },
74 { "reservations-out-of-pool", Element::boolean },
75 { "calculate-tee-times", Element::boolean },
76 { "t1-percent", Element::real },
77 { "t2-percent", Element::real },
78 { "loggers", Element::list },
79 { "hostname-char-set", Element::string },
80 { "hostname-char-replacement", Element::string },
81 { "ddns-send-updates", Element::boolean },
82 { "ddns-override-no-update", Element::boolean },
83 { "ddns-override-client-update", Element::boolean },
84 { "ddns-replace-client-name", Element::string },
85 { "ddns-generated-prefix", Element::string },
86 { "ddns-qualifying-suffix", Element::string },
87 { "store-extended-info", Element::boolean },
88 { "statistic-default-sample-count", Element::integer },
89 { "statistic-default-sample-age", Element::integer },
90 { "multi-threading", Element::map },
91 { "cache-threshold", Element::real },
92 { "cache-max-age", Element::integer },
93 { "early-global-reservations-lookup", Element::boolean },
94 { "ip-reservations-unique", Element::boolean },
95 { "reservations-lookup-first", Element::boolean },
96 { "ddns-update-on-renew", Element::boolean },
97 { "compatibility", Element::map },
98 { "parked-packet-limit", Element::integer },
99 { "allocator", Element::string },
100 { "pd-allocator", Element::string },
101 { "ddns-ttl-percent", Element::real },
102 { "ddns-conflict-resolution-mode", Element::string },
103 { "ddns-ttl", Element::integer },
104 { "ddns-ttl-min", Element::integer },
105 { "ddns-ttl-max", Element::integer },
106};
107
114 // preferred-lifetime is unspecified and defaults to 0.625 of valid-lifetime.
115 { "valid-lifetime", Element::integer, "7200" },
116 { "decline-probation-period", Element::integer, "86400" }, // 24h
117 { "dhcp4o6-port", Element::integer, "0" },
118 { "server-tag", Element::string, "" },
119 { "reservations-global", Element::boolean, "false" },
120 { "reservations-in-subnet", Element::boolean, "true" },
121 { "reservations-out-of-pool", Element::boolean, "false" },
122 { "calculate-tee-times", Element::boolean, "true" },
123 { "t1-percent", Element::real, ".50" },
124 { "t2-percent", Element::real, ".80" },
125 { "ddns-send-updates", Element::boolean, "true" },
126 { "ddns-override-no-update", Element::boolean, "false" },
127 { "ddns-override-client-update", Element::boolean, "false" },
128 { "ddns-replace-client-name", Element::string, "never" },
129 { "ddns-generated-prefix", Element::string, "myhost" },
130 { "ddns-qualifying-suffix", Element::string, "" },
131 { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
132 { "hostname-char-replacement", Element::string, "" },
133 { "store-extended-info", Element::boolean, "false" },
134 { "statistic-default-sample-count", Element::integer, "20" },
135 { "statistic-default-sample-age", Element::integer, "0" },
136 { "early-global-reservations-lookup", Element::boolean, "false" },
137 { "ip-reservations-unique", Element::boolean, "true" },
138 { "reservations-lookup-first", Element::boolean, "false" },
139 { "ddns-update-on-renew", Element::boolean, "false" },
140 { "parked-packet-limit", Element::integer, "256" },
141 { "allocator", Element::string, "iterative" },
142 { "pd-allocator", Element::string, "iterative" },
143 { "ddns-conflict-resolution-mode", Element::string, "check-with-dhcid" },
144 { "cache-threshold", Element::real, "0.25" },
145};
146
148 { "host-reservation-identifiers", Element::list },
149 /* not yet supported
150 { "interfaces-config.interfaces", Element::list },
151 */
152};
153
155 { "host-reservation-identifiers", Element::string },
156 /* not yet supported
157 { "interfaces-config.interfaces", Element::string },
158 */
159};
160
167 { "name", Element::string },
168 { "code", Element::integer },
169 { "type", Element::string },
170 { "record-types", Element::string },
171 { "space", Element::string },
172 { "encapsulate", Element::string },
173 { "array", Element::boolean, },
174 { "user-context", Element::map },
175 { "comment", Element::string },
176 { "metadata", Element::map }
177};
178
184 { "record-types", Element::string, ""},
185 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
186 { "array", Element::boolean, "false"},
187 { "encapsulate", Element::string, "" }
188};
189
196 { "name", Element::string },
197 { "data", Element::string },
198 { "code", Element::integer },
199 { "space", Element::string },
200 { "csv-format", Element::boolean },
201 { "always-send", Element::boolean },
202 { "never-send", Element::boolean },
203 { "user-context", Element::map },
204 { "comment", Element::string },
205 { "client-classes", Element::list },
206 { "metadata", Element::map }
207};
208
215 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
216 { "csv-format", Element::boolean, "true"},
217 { "always-send", Element::boolean, "false"},
218 { "never-send", Element::boolean, "false"}
219};
220
227 { "preferred-lifetime", Element::integer },
228 { "min-preferred-lifetime", Element::integer },
229 { "max-preferred-lifetime", Element::integer },
230 { "valid-lifetime", Element::integer },
231 { "min-valid-lifetime", Element::integer },
232 { "max-valid-lifetime", Element::integer },
233 { "renew-timer", Element::integer },
234 { "rebind-timer", Element::integer },
235 { "option-data", Element::list },
236 { "pools", Element::list },
237 { "pd-pools", Element::list },
238 { "subnet", Element::string },
239 { "interface", Element::string },
240 { "interface-id", Element::string },
241 { "id", Element::integer },
242 { "rapid-commit", Element::boolean },
243 { "client-class", Element::string },
244 { "client-classes", Element::list },
245 { "require-client-classes", Element::list },
246 { "evaluate-additional-classes", Element::list },
247 { "reservations", Element::list },
248 { "reservations-global", Element::boolean },
249 { "reservations-in-subnet", Element::boolean },
250 { "reservations-out-of-pool", Element::boolean },
251 { "relay", Element::map },
252 { "user-context", Element::map },
253 { "comment", Element::string },
254 { "calculate-tee-times", Element::boolean },
255 { "t1-percent", Element::real },
256 { "t2-percent", Element::real },
257 { "ddns-send-updates", Element::boolean },
258 { "ddns-override-no-update", Element::boolean },
259 { "ddns-override-client-update", Element::boolean },
260 { "ddns-replace-client-name", Element::string },
261 { "ddns-generated-prefix", Element::string },
262 { "ddns-qualifying-suffix", Element::string },
263 { "hostname-char-set", Element::string },
264 { "hostname-char-replacement", Element::string },
265 { "store-extended-info", Element::boolean },
266 { "metadata", Element::map },
267 { "cache-threshold", Element::real },
268 { "cache-max-age", Element::integer },
269 { "ddns-update-on-renew", Element::boolean },
270 { "allocator", Element::string },
271 { "pd-allocator", Element::string },
272 { "ddns-ttl-percent", Element::real },
273 { "ddns-conflict-resolution-mode", Element::string },
274 { "ddns-ttl", Element::integer },
275 { "ddns-ttl-min", Element::integer },
276 { "ddns-ttl-max", Element::integer },
277};
278
286 { "interface", Element::string, "" },
287 { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
288 { "interface-id", Element::string, "" }
289};
290
297};
298
301 { "interface", Element::string, "" },
302 { "interface-id", Element::string, "" },
303 { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
304};
305
316 "preferred-lifetime",
317 "min-preferred-lifetime",
318 "max-preferred-lifetime",
319 "rebind-timer",
320 "relay",
321 "renew-timer",
322 "valid-lifetime",
323 "min-valid-lifetime",
324 "max-valid-lifetime",
325 "calculate-tee-times",
326 "t1-percent",
327 "t2-percent",
328 "store-extended-info",
329 "cache-threshold",
330 "cache-max-age",
331 "allocator",
332 "pd-allocator"
333};
334
341 { "pool", Element::string },
342 { "pool-id", Element::integer },
343 { "option-data", Element::list },
344 { "client-class", Element::string },
345 { "client-classes", Element::list },
346 { "require-client-classes", Element::list },
347 { "evaluate-additional-classes", Element::list },
348 { "user-context", Element::map },
349 { "comment", Element::string },
350 { "ddns-send-updates", Element::boolean },
351 { "ddns-override-no-update", Element::boolean },
352 { "ddns-override-client-update", Element::boolean },
353 { "ddns-replace-client-name", Element::string },
354 { "ddns-generated-prefix", Element::string },
355 { "ddns-qualifying-suffix", Element::string },
356 { "hostname-char-set", Element::string },
357 { "hostname-char-replacement", Element::string },
358 { "ddns-update-on-renew", Element::boolean },
359 { "ddns-ttl-percent", Element::real },
360 { "ddns-conflict-resolution-mode", Element::string },
361 { "ddns-ttl", Element::integer },
362 { "ddns-ttl-min", Element::integer },
363 { "ddns-ttl-max", Element::integer },
364 { "metadata", Element::map }
365};
366
373 { "prefix", Element::string },
374 { "prefix-len", Element::integer },
375 { "delegated-len", Element::integer },
376 { "pool-id", Element::integer },
377 { "option-data", Element::list },
378 { "client-class", Element::string },
379 { "client-classes", Element::list },
380 { "require-client-classes", Element::list },
381 { "evaluate-additional-classes", Element::list },
382 { "excluded-prefix", Element::string },
383 { "excluded-prefix-len", Element::integer },
384 { "user-context", Element::map },
385 { "comment", Element::string },
386 { "metadata", Element::map }
387};
388
395 { "name", Element::string },
396 { "subnet6", Element::list },
397 { "interface", Element::string },
398 { "interface-id", Element::string },
399 { "renew-timer", Element::integer },
400 { "rebind-timer", Element::integer },
401 { "option-data", Element::list },
402 { "relay", Element::map },
403 { "reservations-global", Element::boolean },
404 { "reservations-in-subnet", Element::boolean },
405 { "reservations-out-of-pool", Element::boolean },
406 { "client-class", Element::string },
407 { "client-classes", Element::list },
408 { "require-client-classes", Element::list },
409 { "evaluate-additional-classes", Element::list },
410 { "preferred-lifetime", Element::integer },
411 { "min-preferred-lifetime", Element::integer },
412 { "max-preferred-lifetime", Element::integer },
413 { "rapid-commit", Element::boolean },
414 { "valid-lifetime", Element::integer },
415 { "min-valid-lifetime", Element::integer },
416 { "max-valid-lifetime", Element::integer },
417 { "user-context", Element::map },
418 { "comment", Element::string },
419 { "calculate-tee-times", Element::boolean },
420 { "t1-percent", Element::real },
421 { "t2-percent", Element::real },
422 { "ddns-send-updates", Element::boolean },
423 { "ddns-override-no-update", Element::boolean },
424 { "ddns-override-client-update", Element::boolean },
425 { "ddns-replace-client-name", Element::string },
426 { "ddns-generated-prefix", Element::string },
427 { "ddns-qualifying-suffix", Element::string },
428 { "hostname-char-set", Element::string },
429 { "hostname-char-replacement", Element::string },
430 { "store-extended-info", Element::boolean },
431 { "metadata", Element::map },
432 { "cache-threshold", Element::real },
433 { "cache-max-age", Element::integer },
434 { "ddns-update-on-renew", Element::boolean },
435 { "allocator", Element::string },
436 { "pd-allocator", Element::string },
437 { "ddns-ttl-percent", Element::real },
438 { "ddns-conflict-resolution-mode", Element::string },
439 { "ddns-ttl", Element::integer },
440 { "ddns-ttl-min", Element::integer },
441 { "ddns-ttl-max", Element::integer },
442};
443
446 { "re-detect", Element::boolean, "true" }
447};
448
451 { "enable-queue", Element::boolean, "false"},
452 { "queue-type", Element::string, "kea-ring6"},
453 { "capacity", Element::integer, "64"}
454};
455
458 { "enable-multi-threading", Element::boolean, "true" },
459 { "thread-pool-size", Element::integer, "0" },
460 { "packet-queue-size", Element::integer, "64" }
461};
462
465 { "lease-checks", Element::string, "warn" }
466};
467
469
473
475 size_t cnt = 0;
476
477 // Set global defaults first.
478 cnt = setDefaults(global, GLOBAL6_DEFAULTS);
479
480 // Now set the defaults for each specified option definition
481 ConstElementPtr option_defs = global->get("option-def");
482 if (option_defs) {
483 cnt += setListDefaults(option_defs, OPTION6_DEF_DEFAULTS);
484 }
485
486 // Set the defaults for option data
487 ConstElementPtr options = global->get("option-data");
488 if (options) {
489 cnt += setListDefaults(options, OPTION6_DEFAULTS);
490 }
491
492 // Now set the defaults for defined subnets
493 ConstElementPtr subnets = global->get("subnet6");
494 if (subnets) {
495 cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
496 }
497
498 // Set the defaults for interfaces config
499 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
500 if (ifaces_cfg) {
501 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
502 cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
503 }
504
505 // Set defaults for shared networks
506 ConstElementPtr shared = global->get("shared-networks");
507 if (shared) {
508 for (auto const& net : shared->listValue()) {
509
511
512 ConstElementPtr subs = net->get("subnet6");
513 if (subs) {
515 }
516 }
517 }
518
519 // Set the defaults for dhcp-queue-control. If the element isn't there
520 // we'll add it.
521 ConstElementPtr queue_control = global->get("dhcp-queue-control");
522 ElementPtr mutable_cfg;
523 if (queue_control) {
524 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
525 } else {
526 mutable_cfg = Element::createMap();
527 global->set("dhcp-queue-control", mutable_cfg);
528 }
529
530 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
531
532 // Set the defaults for multi-threading. If the element isn't there
533 // we'll add it.
534 ConstElementPtr multi_threading = global->get("multi-threading");
535 if (multi_threading) {
536 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
537 } else {
538 mutable_cfg = Element::createMap();
539 global->set("multi-threading", mutable_cfg);
540 }
541
542 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS);
543
544 // Set the defaults for sanity-checks. If the element isn't
545 // there we'll add it.
546 ConstElementPtr sanity_checks = global->get("sanity-checks");
547 if (sanity_checks) {
548 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
549 } else {
550 mutable_cfg = Element::createMap();
551 global->set("sanity-checks", mutable_cfg);
552 }
553
554 cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
555
556 return (cnt);
557}
558
560 size_t cnt = 0;
561
562 // Now derive global parameters into subnets.
563 ConstElementPtr subnets = global->get("subnet6");
564 if (subnets) {
565 for (auto const& single_subnet : subnets->listValue()) {
566 cnt += SimpleParser::deriveParams(global, single_subnet,
568 }
569 }
570
571 // Deriving parameters for shared networks is a bit more involved.
572 // First, the shared-network level derives from global, and then
573 // subnets within derive from it.
574 ConstElementPtr shared = global->get("shared-networks");
575 if (shared) {
576 for (auto const& net : shared->listValue()) {
577 // First try to inherit the parameters from shared network,
578 // if defined there.
579 // Then try to inherit them from global.
580 cnt += SimpleParser::deriveParams(global, net,
582
583 // Now we need to go thrugh all the subnets in this net.
584 subnets = net->get("subnet6");
585 if (subnets) {
586 for (auto const& single_subnet : subnets->listValue()) {
587 cnt += SimpleParser::deriveParams(net, single_subnet,
589 }
590 }
591 }
592 }
593
594 return (cnt);
595}
596
597} // namespace dhcp
598} // namespace isc
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
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 deriveParams(isc::data::ConstElementPtr parent, isc::data::ElementPtr child, const ParamsList &params)
Derives (inherits) parameters from parent scope to a child.
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 that is part of a shared network.
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 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::SimpleKeywords GLOBAL6_LIST_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.
static const isc::data::SimpleKeywords GLOBAL6_LIST_PARAMETER_TYPES
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:29
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:28
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.