Kea 2.7.7
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};
145
152 { "name", Element::string },
153 { "code", Element::integer },
154 { "type", Element::string },
155 { "record-types", Element::string },
156 { "space", Element::string },
157 { "encapsulate", Element::string },
158 { "array", Element::boolean, },
159 { "user-context", Element::map },
160 { "comment", Element::string },
161 { "metadata", Element::map }
162};
163
169 { "record-types", Element::string, ""},
170 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
171 { "array", Element::boolean, "false"},
172 { "encapsulate", Element::string, "" }
173};
174
181 { "name", Element::string },
182 { "data", Element::string },
183 { "code", Element::integer },
184 { "space", Element::string },
185 { "csv-format", Element::boolean },
186 { "always-send", Element::boolean },
187 { "never-send", Element::boolean },
188 { "user-context", Element::map },
189 { "comment", Element::string },
190 { "client-classes", Element::list },
191 { "metadata", Element::map }
192};
193
200 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
201 { "csv-format", Element::boolean, "true"},
202 { "always-send", Element::boolean, "false"},
203 { "never-send", Element::boolean, "false"}
204};
205
212 { "preferred-lifetime", Element::integer },
213 { "min-preferred-lifetime", Element::integer },
214 { "max-preferred-lifetime", Element::integer },
215 { "valid-lifetime", Element::integer },
216 { "min-valid-lifetime", Element::integer },
217 { "max-valid-lifetime", Element::integer },
218 { "renew-timer", Element::integer },
219 { "rebind-timer", Element::integer },
220 { "option-data", Element::list },
221 { "pools", Element::list },
222 { "pd-pools", Element::list },
223 { "subnet", Element::string },
224 { "interface", Element::string },
225 { "interface-id", Element::string },
226 { "id", Element::integer },
227 { "rapid-commit", Element::boolean },
228 { "client-class", Element::string },
229 { "client-classes", Element::list },
230 { "require-client-classes", Element::list },
231 { "evaluate-additional-classes", Element::list },
232 { "reservations", Element::list },
233 { "reservations-global", Element::boolean },
234 { "reservations-in-subnet", Element::boolean },
235 { "reservations-out-of-pool", Element::boolean },
236 { "relay", Element::map },
237 { "user-context", Element::map },
238 { "comment", Element::string },
239 { "calculate-tee-times", Element::boolean },
240 { "t1-percent", Element::real },
241 { "t2-percent", Element::real },
242 { "ddns-send-updates", Element::boolean },
243 { "ddns-override-no-update", Element::boolean },
244 { "ddns-override-client-update", Element::boolean },
245 { "ddns-replace-client-name", Element::string },
246 { "ddns-generated-prefix", Element::string },
247 { "ddns-qualifying-suffix", Element::string },
248 { "hostname-char-set", Element::string },
249 { "hostname-char-replacement", Element::string },
250 { "store-extended-info", Element::boolean },
251 { "metadata", Element::map },
252 { "cache-threshold", Element::real },
253 { "cache-max-age", Element::integer },
254 { "ddns-update-on-renew", Element::boolean },
255 { "allocator", Element::string },
256 { "pd-allocator", Element::string },
257 { "ddns-ttl-percent", Element::real },
258 { "ddns-conflict-resolution-mode", Element::string },
259 { "ddns-ttl", Element::integer },
260 { "ddns-ttl-min", Element::integer },
261 { "ddns-ttl-max", Element::integer },
262};
263
271 { "interface", Element::string, "" },
272 { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
273 { "interface-id", Element::string, "" }
274};
275
282};
283
286 { "interface", Element::string, "" },
287 { "interface-id", Element::string, "" },
288 { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
289};
290
301 "preferred-lifetime",
302 "min-preferred-lifetime",
303 "max-preferred-lifetime",
304 "rebind-timer",
305 "relay",
306 "renew-timer",
307 "valid-lifetime",
308 "min-valid-lifetime",
309 "max-valid-lifetime",
310 "calculate-tee-times",
311 "t1-percent",
312 "t2-percent",
313 "store-extended-info",
314 "cache-threshold",
315 "cache-max-age",
316 "allocator",
317 "pd-allocator"
318};
319
326 { "pool", Element::string },
327 { "pool-id", Element::integer },
328 { "option-data", Element::list },
329 { "client-class", Element::string },
330 { "client-classes", Element::list },
331 { "require-client-classes", Element::list },
332 { "evaluate-additional-classes", Element::list },
333 { "user-context", Element::map },
334 { "comment", Element::string },
335 { "ddns-send-updates", Element::boolean },
336 { "ddns-override-no-update", Element::boolean },
337 { "ddns-override-client-update", Element::boolean },
338 { "ddns-replace-client-name", Element::string },
339 { "ddns-generated-prefix", Element::string },
340 { "ddns-qualifying-suffix", Element::string },
341 { "hostname-char-set", Element::string },
342 { "hostname-char-replacement", Element::string },
343 { "ddns-update-on-renew", Element::boolean },
344 { "ddns-ttl-percent", Element::real },
345 { "ddns-conflict-resolution-mode", Element::string },
346 { "ddns-ttl", Element::integer },
347 { "ddns-ttl-min", Element::integer },
348 { "ddns-ttl-max", Element::integer },
349 { "metadata", Element::map }
350};
351
358 { "prefix", Element::string },
359 { "prefix-len", Element::integer },
360 { "delegated-len", Element::integer },
361 { "pool-id", Element::integer },
362 { "option-data", Element::list },
363 { "client-class", Element::string },
364 { "client-classes", Element::list },
365 { "require-client-classes", Element::list },
366 { "evaluate-additional-classes", Element::list },
367 { "excluded-prefix", Element::string },
368 { "excluded-prefix-len", Element::integer },
369 { "user-context", Element::map },
370 { "comment", Element::string },
371 { "metadata", Element::map }
372};
373
380 { "name", Element::string },
381 { "subnet6", Element::list },
382 { "interface", Element::string },
383 { "interface-id", Element::string },
384 { "renew-timer", Element::integer },
385 { "rebind-timer", Element::integer },
386 { "option-data", Element::list },
387 { "relay", Element::map },
388 { "reservations-global", Element::boolean },
389 { "reservations-in-subnet", Element::boolean },
390 { "reservations-out-of-pool", Element::boolean },
391 { "client-class", Element::string },
392 { "client-classes", Element::list },
393 { "require-client-classes", Element::list },
394 { "evaluate-additional-classes", Element::list },
395 { "preferred-lifetime", Element::integer },
396 { "min-preferred-lifetime", Element::integer },
397 { "max-preferred-lifetime", Element::integer },
398 { "rapid-commit", Element::boolean },
399 { "valid-lifetime", Element::integer },
400 { "min-valid-lifetime", Element::integer },
401 { "max-valid-lifetime", Element::integer },
402 { "user-context", Element::map },
403 { "comment", Element::string },
404 { "calculate-tee-times", Element::boolean },
405 { "t1-percent", Element::real },
406 { "t2-percent", Element::real },
407 { "ddns-send-updates", Element::boolean },
408 { "ddns-override-no-update", Element::boolean },
409 { "ddns-override-client-update", Element::boolean },
410 { "ddns-replace-client-name", Element::string },
411 { "ddns-generated-prefix", Element::string },
412 { "ddns-qualifying-suffix", Element::string },
413 { "hostname-char-set", Element::string },
414 { "hostname-char-replacement", Element::string },
415 { "store-extended-info", Element::boolean },
416 { "metadata", Element::map },
417 { "cache-threshold", Element::real },
418 { "cache-max-age", Element::integer },
419 { "ddns-update-on-renew", Element::boolean },
420 { "allocator", Element::string },
421 { "pd-allocator", Element::string },
422 { "ddns-ttl-percent", Element::real },
423 { "ddns-conflict-resolution-mode", Element::string },
424 { "ddns-ttl", Element::integer },
425 { "ddns-ttl-min", Element::integer },
426 { "ddns-ttl-max", Element::integer },
427};
428
431 { "re-detect", Element::boolean, "true" }
432};
433
436 { "enable-queue", Element::boolean, "false"},
437 { "queue-type", Element::string, "kea-ring6"},
438 { "capacity", Element::integer, "64"}
439};
440
443 { "enable-multi-threading", Element::boolean, "true" },
444 { "thread-pool-size", Element::integer, "0" },
445 { "packet-queue-size", Element::integer, "64" }
446};
447
450 { "lease-checks", Element::string, "warn" }
451};
452
454
458
460 size_t cnt = 0;
461
462 // Set global defaults first.
463 cnt = setDefaults(global, GLOBAL6_DEFAULTS);
464
465 // Now set the defaults for each specified option definition
466 ConstElementPtr option_defs = global->get("option-def");
467 if (option_defs) {
468 for (auto const& option_def : option_defs->listValue()) {
470 }
471 }
472
473 // Set the defaults for option data
474 ConstElementPtr options = global->get("option-data");
475 if (options) {
476 for (auto const& single_option : options->listValue()) {
477 cnt += SimpleParser::setDefaults(single_option, OPTION6_DEFAULTS);
478 }
479 }
480
481 // Now set the defaults for defined subnets
482 ConstElementPtr subnets = global->get("subnet6");
483 if (subnets) {
484 cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
485 }
486
487 // Set the defaults for interfaces config
488 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
489 if (ifaces_cfg) {
490 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
491 cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
492 }
493
494 // Set defaults for shared networks
495 ConstElementPtr shared = global->get("shared-networks");
496 if (shared) {
497 for (auto const& net : shared->listValue()) {
498
500
501 ConstElementPtr subs = net->get("subnet6");
502 if (subs) {
504 }
505 }
506 }
507
508 // Set the defaults for dhcp-queue-control. If the element isn't there
509 // we'll add it.
510 ConstElementPtr queue_control = global->get("dhcp-queue-control");
511 ElementPtr mutable_cfg;
512 if (queue_control) {
513 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
514 } else {
515 mutable_cfg = Element::createMap();
516 global->set("dhcp-queue-control", mutable_cfg);
517 }
518
519 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
520
521 // Set the defaults for multi-threading. If the element isn't there
522 // we'll add it.
523 ConstElementPtr multi_threading = global->get("multi-threading");
524 if (multi_threading) {
525 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
526 } else {
527 mutable_cfg = Element::createMap();
528 global->set("multi-threading", mutable_cfg);
529 }
530
531 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS);
532
533 // Set the defaults for sanity-checks. If the element isn't
534 // there we'll add it.
535 ConstElementPtr sanity_checks = global->get("sanity-checks");
536 if (sanity_checks) {
537 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
538 } else {
539 mutable_cfg = Element::createMap();
540 global->set("sanity-checks", mutable_cfg);
541 }
542
543 cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
544
545 return (cnt);
546}
547
549 size_t cnt = 0;
550
551 // Now derive global parameters into subnets.
552 ConstElementPtr subnets = global->get("subnet6");
553 if (subnets) {
554 for (auto const& single_subnet : subnets->listValue()) {
555 cnt += SimpleParser::deriveParams(global, single_subnet,
557 }
558 }
559
560 // Deriving parameters for shared networks is a bit more involved.
561 // First, the shared-network level derives from global, and then
562 // subnets within derive from it.
563 ConstElementPtr shared = global->get("shared-networks");
564 if (shared) {
565 for (auto const& net : shared->listValue()) {
566 // First try to inherit the parameters from shared network,
567 // if defined there.
568 // Then try to inherit them from global.
569 cnt += SimpleParser::deriveParams(global, net,
571
572 // Now we need to go thrugh all the subnets in this net.
573 subnets = net->get("subnet6");
574 if (subnets) {
575 for (auto const& single_subnet : subnets->listValue()) {
576 cnt += SimpleParser::deriveParams(net, single_subnet,
578 }
579 }
580 }
581 }
582
583 return (cnt);
584}
585
586} // namespace dhcp
587} // 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::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: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.