Kea 3.1.5
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 { "adaptive-lease-time-threshold", Element::real },
107 { "allow-address-registration", Element::boolean },
108};
109
116 // preferred-lifetime is unspecified and defaults to 0.625 of valid-lifetime.
117 { "valid-lifetime", Element::integer, "7200" },
118 { "decline-probation-period", Element::integer, "86400" }, // 24h
119 { "dhcp4o6-port", Element::integer, "0" },
120 { "server-tag", Element::string, "" },
121 { "reservations-global", Element::boolean, "false" },
122 { "reservations-in-subnet", Element::boolean, "true" },
123 { "reservations-out-of-pool", Element::boolean, "false" },
124 { "calculate-tee-times", Element::boolean, "true" },
125 { "t1-percent", Element::real, ".50" },
126 { "t2-percent", Element::real, ".80" },
127 { "ddns-send-updates", Element::boolean, "true" },
128 { "ddns-override-no-update", Element::boolean, "false" },
129 { "ddns-override-client-update", Element::boolean, "false" },
130 { "ddns-replace-client-name", Element::string, "never" },
131 { "ddns-generated-prefix", Element::string, "myhost" },
132 { "ddns-qualifying-suffix", Element::string, "" },
133 { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
134 { "hostname-char-replacement", Element::string, "" },
135 { "store-extended-info", Element::boolean, "false" },
136 { "statistic-default-sample-count", Element::integer, "20" },
137 { "statistic-default-sample-age", Element::integer, "0" },
138 { "early-global-reservations-lookup", Element::boolean, "false" },
139 { "ip-reservations-unique", Element::boolean, "true" },
140 { "reservations-lookup-first", Element::boolean, "false" },
141 { "ddns-update-on-renew", Element::boolean, "false" },
142 { "parked-packet-limit", Element::integer, "256" },
143 { "allocator", Element::string, "iterative" },
144 { "pd-allocator", Element::string, "iterative" },
145 { "ddns-conflict-resolution-mode", Element::string, "check-with-dhcid" },
146 { "cache-threshold", Element::real, "0.25" },
147 { "allow-address-registration", Element::boolean, "true"},
148};
149
151 { "host-reservation-identifiers", Element::list },
152 /* not yet supported
153 { "interfaces-config.interfaces", Element::list },
154 */
155};
156
158 { "host-reservation-identifiers", Element::string },
159 /* not yet supported
160 { "interfaces-config.interfaces", Element::string },
161 */
162};
163
170 { "name", Element::string },
171 { "code", Element::integer },
172 { "type", Element::string },
173 { "record-types", Element::string },
174 { "space", Element::string },
175 { "encapsulate", Element::string },
176 { "array", Element::boolean, },
177 { "user-context", Element::map },
178 { "comment", Element::string },
179 { "metadata", Element::map }
180};
181
187 { "record-types", Element::string, ""},
188 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
189 { "array", Element::boolean, "false"},
190 { "encapsulate", Element::string, "" }
191};
192
199 { "name", Element::string },
200 { "data", Element::string },
201 { "code", Element::integer },
202 { "space", Element::string },
203 { "csv-format", Element::boolean },
204 { "always-send", Element::boolean },
205 { "never-send", Element::boolean },
206 { "user-context", Element::map },
207 { "comment", Element::string },
208 { "client-classes", Element::list },
209 { "metadata", Element::map }
210};
211
218 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
219 { "csv-format", Element::boolean, "true"},
220 { "always-send", Element::boolean, "false"},
221 { "never-send", Element::boolean, "false"}
222};
223
230 { "preferred-lifetime", Element::integer },
231 { "min-preferred-lifetime", Element::integer },
232 { "max-preferred-lifetime", Element::integer },
233 { "valid-lifetime", Element::integer },
234 { "min-valid-lifetime", Element::integer },
235 { "max-valid-lifetime", Element::integer },
236 { "renew-timer", Element::integer },
237 { "rebind-timer", Element::integer },
238 { "option-data", Element::list },
239 { "pools", Element::list },
240 { "pd-pools", Element::list },
241 { "subnet", Element::string },
242 { "interface", Element::string },
243 { "interface-id", Element::string },
244 { "id", Element::integer },
245 { "rapid-commit", Element::boolean },
246 { "client-class", Element::string },
247 { "client-classes", Element::list },
248 { "require-client-classes", Element::list },
249 { "evaluate-additional-classes", Element::list },
250 { "reservations", Element::list },
251 { "reservations-global", Element::boolean },
252 { "reservations-in-subnet", Element::boolean },
253 { "reservations-out-of-pool", Element::boolean },
254 { "relay", Element::map },
255 { "user-context", Element::map },
256 { "comment", Element::string },
257 { "calculate-tee-times", Element::boolean },
258 { "t1-percent", Element::real },
259 { "t2-percent", Element::real },
260 { "ddns-send-updates", Element::boolean },
261 { "ddns-override-no-update", Element::boolean },
262 { "ddns-override-client-update", Element::boolean },
263 { "ddns-replace-client-name", Element::string },
264 { "ddns-generated-prefix", Element::string },
265 { "ddns-qualifying-suffix", Element::string },
266 { "hostname-char-set", Element::string },
267 { "hostname-char-replacement", Element::string },
268 { "store-extended-info", Element::boolean },
269 { "metadata", Element::map },
270 { "cache-threshold", Element::real },
271 { "cache-max-age", Element::integer },
272 { "ddns-update-on-renew", Element::boolean },
273 { "allocator", Element::string },
274 { "pd-allocator", Element::string },
275 { "ddns-ttl-percent", Element::real },
276 { "ddns-conflict-resolution-mode", Element::string },
277 { "ddns-ttl", Element::integer },
278 { "ddns-ttl-min", Element::integer },
279 { "ddns-ttl-max", Element::integer },
280 { "adaptive-lease-time-threshold", Element::real },
281};
282
290 { "interface", Element::string, "" },
291 { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
292 { "interface-id", Element::string, "" }
293};
294
301};
302
305 { "interface", Element::string, "" },
306 { "interface-id", Element::string, "" },
307 { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
308};
309
320 "preferred-lifetime",
321 "min-preferred-lifetime",
322 "max-preferred-lifetime",
323 "rebind-timer",
324 "relay",
325 "renew-timer",
326 "valid-lifetime",
327 "min-valid-lifetime",
328 "max-valid-lifetime",
329 "calculate-tee-times",
330 "t1-percent",
331 "t2-percent",
332 "store-extended-info",
333 "cache-threshold",
334 "cache-max-age",
335 "allocator",
336 "pd-allocator",
337 "adaptive-lease-time-threshold",
338};
339
346 { "pool", Element::string },
347 { "pool-id", Element::integer },
348 { "option-data", Element::list },
349 { "client-class", Element::string },
350 { "client-classes", Element::list },
351 { "require-client-classes", Element::list },
352 { "evaluate-additional-classes", Element::list },
353 { "user-context", Element::map },
354 { "comment", Element::string },
355 { "ddns-send-updates", Element::boolean },
356 { "ddns-override-no-update", Element::boolean },
357 { "ddns-override-client-update", Element::boolean },
358 { "ddns-replace-client-name", Element::string },
359 { "ddns-generated-prefix", Element::string },
360 { "ddns-qualifying-suffix", Element::string },
361 { "hostname-char-set", Element::string },
362 { "hostname-char-replacement", Element::string },
363 { "ddns-update-on-renew", Element::boolean },
364 { "ddns-ttl-percent", Element::real },
365 { "ddns-conflict-resolution-mode", Element::string },
366 { "ddns-ttl", Element::integer },
367 { "ddns-ttl-min", Element::integer },
368 { "ddns-ttl-max", Element::integer },
369 { "metadata", Element::map }
370};
371
378 { "prefix", Element::string },
379 { "prefix-len", Element::integer },
380 { "delegated-len", Element::integer },
381 { "pool-id", Element::integer },
382 { "option-data", Element::list },
383 { "client-class", Element::string },
384 { "client-classes", Element::list },
385 { "require-client-classes", Element::list },
386 { "evaluate-additional-classes", Element::list },
387 { "excluded-prefix", Element::string },
388 { "excluded-prefix-len", Element::integer },
389 { "user-context", Element::map },
390 { "comment", Element::string },
391 { "metadata", Element::map }
392};
393
400 { "name", Element::string },
401 { "subnet6", Element::list },
402 { "interface", Element::string },
403 { "interface-id", Element::string },
404 { "renew-timer", Element::integer },
405 { "rebind-timer", Element::integer },
406 { "option-data", Element::list },
407 { "relay", Element::map },
408 { "reservations-global", Element::boolean },
409 { "reservations-in-subnet", Element::boolean },
410 { "reservations-out-of-pool", Element::boolean },
411 { "client-class", Element::string },
412 { "client-classes", Element::list },
413 { "require-client-classes", Element::list },
414 { "evaluate-additional-classes", Element::list },
415 { "preferred-lifetime", Element::integer },
416 { "min-preferred-lifetime", Element::integer },
417 { "max-preferred-lifetime", Element::integer },
418 { "rapid-commit", Element::boolean },
419 { "valid-lifetime", Element::integer },
420 { "min-valid-lifetime", Element::integer },
421 { "max-valid-lifetime", Element::integer },
422 { "user-context", Element::map },
423 { "comment", Element::string },
424 { "calculate-tee-times", Element::boolean },
425 { "t1-percent", Element::real },
426 { "t2-percent", Element::real },
427 { "ddns-send-updates", Element::boolean },
428 { "ddns-override-no-update", Element::boolean },
429 { "ddns-override-client-update", Element::boolean },
430 { "ddns-replace-client-name", Element::string },
431 { "ddns-generated-prefix", Element::string },
432 { "ddns-qualifying-suffix", Element::string },
433 { "hostname-char-set", Element::string },
434 { "hostname-char-replacement", Element::string },
435 { "store-extended-info", Element::boolean },
436 { "metadata", Element::map },
437 { "cache-threshold", Element::real },
438 { "cache-max-age", Element::integer },
439 { "ddns-update-on-renew", Element::boolean },
440 { "allocator", Element::string },
441 { "pd-allocator", Element::string },
442 { "ddns-ttl-percent", Element::real },
443 { "ddns-conflict-resolution-mode", Element::string },
444 { "ddns-ttl", Element::integer },
445 { "ddns-ttl-min", Element::integer },
446 { "ddns-ttl-max", Element::integer },
447 { "adaptive-lease-time-threshold", Element::real },
448};
449
452 { "re-detect", Element::boolean, "true" }
453};
454
457 { "enable-queue", Element::boolean, "false"},
458 { "queue-type", Element::string, "kea-ring6"},
459 { "capacity", Element::integer, "64"}
460};
461
464 { "enable-multi-threading", Element::boolean, "true" },
465 { "thread-pool-size", Element::integer, "0" },
466 { "packet-queue-size", Element::integer, "64" }
467};
468
471 { "lease-checks", Element::string, "warn" }
472};
473
475
479
481 size_t cnt = 0;
482
483 // Set global defaults first.
484 cnt = setDefaults(global, GLOBAL6_DEFAULTS);
485
486 // Now set the defaults for each specified option definition
487 ConstElementPtr option_defs = global->get("option-def");
488 if (option_defs) {
489 cnt += setListDefaults(option_defs, OPTION6_DEF_DEFAULTS);
490 }
491
492 // Set the defaults for option data
493 ConstElementPtr options = global->get("option-data");
494 if (options) {
495 cnt += setListDefaults(options, OPTION6_DEFAULTS);
496 }
497
498 // Now set the defaults for defined subnets
499 ConstElementPtr subnets = global->get("subnet6");
500 if (subnets) {
501 cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
502 }
503
504 // Set the defaults for interfaces config
505 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
506 if (ifaces_cfg) {
507 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
508 cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
509 }
510
511 // Set defaults for shared networks
512 ConstElementPtr shared = global->get("shared-networks");
513 if (shared) {
514 for (auto const& net : shared->listValue()) {
515
517
518 ConstElementPtr subs = net->get("subnet6");
519 if (subs) {
521 }
522 }
523 }
524
525 // Set the defaults for dhcp-queue-control. If the element isn't there
526 // we'll add it.
527 ConstElementPtr queue_control = global->get("dhcp-queue-control");
528 ElementPtr mutable_cfg;
529 if (queue_control) {
530 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
531 } else {
532 mutable_cfg = Element::createMap();
533 global->set("dhcp-queue-control", mutable_cfg);
534 }
535
536 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
537
538 // Set the defaults for multi-threading. If the element isn't there
539 // we'll add it.
540 ConstElementPtr multi_threading = global->get("multi-threading");
541 if (multi_threading) {
542 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
543 } else {
544 mutable_cfg = Element::createMap();
545 global->set("multi-threading", mutable_cfg);
546 }
547
548 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS);
549
550 // Set the defaults for sanity-checks. If the element isn't
551 // there we'll add it.
552 ConstElementPtr sanity_checks = global->get("sanity-checks");
553 if (sanity_checks) {
554 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
555 } else {
556 mutable_cfg = Element::createMap();
557 global->set("sanity-checks", mutable_cfg);
558 }
559
560 cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
561
562 return (cnt);
563}
564
566 size_t cnt = 0;
567
568 // Now derive global parameters into subnets.
569 ConstElementPtr subnets = global->get("subnet6");
570 if (subnets) {
571 for (auto const& single_subnet : subnets->listValue()) {
572 cnt += SimpleParser::deriveParams(global, single_subnet,
574 }
575 }
576
577 // Deriving parameters for shared networks is a bit more involved.
578 // First, the shared-network level derives from global, and then
579 // subnets within derive from it.
580 ConstElementPtr shared = global->get("shared-networks");
581 if (shared) {
582 for (auto const& net : shared->listValue()) {
583 // First try to inherit the parameters from shared network,
584 // if defined there.
585 // Then try to inherit them from global.
586 cnt += SimpleParser::deriveParams(global, net,
588
589 // Now we need to go thrugh all the subnets in this net.
590 subnets = net->get("subnet6");
591 if (subnets) {
592 for (auto const& single_subnet : subnets->listValue()) {
593 cnt += SimpleParser::deriveParams(net, single_subnet,
595 }
596 }
597 }
598 }
599
600 return (cnt);
601}
602
603} // namespace dhcp
604} // 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.