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