Kea 2.7.1
simple_parser6.cc
Go to the documentation of this file.
1// Copyright (C) 2016-2024 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-socket", Element::map },
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};
104
111 // preferred-lifetime is unspecified and defaults to 0.625 of valid-lifetime.
112 { "valid-lifetime", Element::integer, "7200" },
113 { "decline-probation-period", Element::integer, "86400" }, // 24h
114 { "dhcp4o6-port", Element::integer, "0" },
115 { "server-tag", Element::string, "" },
116 { "reservations-global", Element::boolean, "false" },
117 { "reservations-in-subnet", Element::boolean, "true" },
118 { "reservations-out-of-pool", Element::boolean, "false" },
119 { "calculate-tee-times", Element::boolean, "true" },
120 { "t1-percent", Element::real, ".50" },
121 { "t2-percent", Element::real, ".80" },
122 { "ddns-send-updates", Element::boolean, "true" },
123 { "ddns-override-no-update", Element::boolean, "false" },
124 { "ddns-override-client-update", Element::boolean, "false" },
125 { "ddns-replace-client-name", Element::string, "never" },
126 { "ddns-generated-prefix", Element::string, "myhost" },
127 { "ddns-qualifying-suffix", Element::string, "" },
128 { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
129 { "hostname-char-replacement", Element::string, "" },
130 { "store-extended-info", Element::boolean, "false" },
131 { "statistic-default-sample-count", Element::integer, "20" },
132 { "statistic-default-sample-age", Element::integer, "0" },
133 { "early-global-reservations-lookup", Element::boolean, "false" },
134 { "ip-reservations-unique", Element::boolean, "true" },
135 { "reservations-lookup-first", Element::boolean, "false" },
136 { "ddns-update-on-renew", Element::boolean, "false" },
137 { "parked-packet-limit", Element::integer, "256" },
138 { "allocator", Element::string, "iterative" },
139 { "pd-allocator", Element::string, "iterative" },
140 { "ddns-conflict-resolution-mode", Element::string, "check-with-dhcid" },
141};
142
149 { "name", Element::string },
150 { "code", Element::integer },
151 { "type", Element::string },
152 { "record-types", Element::string },
153 { "space", Element::string },
154 { "encapsulate", Element::string },
155 { "array", Element::boolean, },
156 { "user-context", Element::map },
157 { "comment", Element::string },
158 { "metadata", Element::map }
159};
160
166 { "record-types", Element::string, ""},
167 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
168 { "array", Element::boolean, "false"},
169 { "encapsulate", Element::string, "" }
170};
171
178 { "name", Element::string },
179 { "data", Element::string },
180 { "code", Element::integer },
181 { "space", Element::string },
182 { "csv-format", Element::boolean },
183 { "always-send", Element::boolean },
184 { "never-send", Element::boolean },
185 { "user-context", Element::map },
186 { "comment", Element::string },
187 { "metadata", Element::map }
188};
189
196 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
197 { "csv-format", Element::boolean, "true"},
198 { "always-send", Element::boolean, "false"},
199 { "never-send", Element::boolean, "false"}
200};
201
208 { "preferred-lifetime", Element::integer },
209 { "min-preferred-lifetime", Element::integer },
210 { "max-preferred-lifetime", Element::integer },
211 { "valid-lifetime", Element::integer },
212 { "min-valid-lifetime", Element::integer },
213 { "max-valid-lifetime", Element::integer },
214 { "renew-timer", Element::integer },
215 { "rebind-timer", Element::integer },
216 { "option-data", Element::list },
217 { "pools", Element::list },
218 { "pd-pools", Element::list },
219 { "subnet", Element::string },
220 { "interface", Element::string },
221 { "interface-id", Element::string },
222 { "id", Element::integer },
223 { "rapid-commit", Element::boolean },
224 { "client-class", Element::string },
225 { "require-client-classes", Element::list },
226 { "reservations", Element::list },
227 { "reservations-global", Element::boolean },
228 { "reservations-in-subnet", Element::boolean },
229 { "reservations-out-of-pool", Element::boolean },
230 { "relay", Element::map },
231 { "user-context", Element::map },
232 { "comment", Element::string },
233 { "calculate-tee-times", Element::boolean },
234 { "t1-percent", Element::real },
235 { "t2-percent", Element::real },
236 { "ddns-send-updates", Element::boolean },
237 { "ddns-override-no-update", Element::boolean },
238 { "ddns-override-client-update", Element::boolean },
239 { "ddns-replace-client-name", Element::string },
240 { "ddns-generated-prefix", Element::string },
241 { "ddns-qualifying-suffix", Element::string },
242 { "hostname-char-set", Element::string },
243 { "hostname-char-replacement", Element::string },
244 { "store-extended-info", Element::boolean },
245 { "metadata", Element::map },
246 { "cache-threshold", Element::real },
247 { "cache-max-age", Element::integer },
248 { "ddns-update-on-renew", Element::boolean },
249 { "allocator", Element::string },
250 { "pd-allocator", Element::string },
251 { "ddns-ttl-percent", Element::real },
252 { "ddns-conflict-resolution-mode", Element::string },
253};
254
262 { "interface", Element::string, "" },
263 { "client-class", Element::string, "" },
264 { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
265 { "interface-id", Element::string, "" }
266};
267
274};
275
278 { "client-class", Element::string, "" },
279 { "interface", Element::string, "" },
280 { "interface-id", Element::string, "" },
281 { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
282};
283
294 "preferred-lifetime",
295 "min-preferred-lifetime",
296 "max-preferred-lifetime",
297 "rebind-timer",
298 "relay",
299 "renew-timer",
300 "valid-lifetime",
301 "min-valid-lifetime",
302 "max-valid-lifetime",
303 "calculate-tee-times",
304 "t1-percent",
305 "t2-percent",
306 "store-extended-info",
307 "cache-threshold",
308 "cache-max-age",
309 "allocator",
310 "pd-allocator"
311};
312
319 { "pool", Element::string },
320 { "pool-id", Element::integer },
321 { "option-data", Element::list },
322 { "client-class", Element::string },
323 { "require-client-classes", Element::list },
324 { "user-context", Element::map },
325 { "comment", Element::string },
326 { "metadata", Element::map }
327};
328
335 { "prefix", Element::string },
336 { "prefix-len", Element::integer },
337 { "delegated-len", Element::integer },
338 { "pool-id", Element::integer },
339 { "option-data", Element::list },
340 { "client-class", Element::string },
341 { "require-client-classes", Element::list },
342 { "excluded-prefix", Element::string },
343 { "excluded-prefix-len", Element::integer },
344 { "user-context", Element::map },
345 { "comment", Element::string },
346 { "metadata", Element::map }
347};
348
355 { "name", Element::string },
356 { "subnet6", Element::list },
357 { "interface", Element::string },
358 { "interface-id", Element::string },
359 { "renew-timer", Element::integer },
360 { "rebind-timer", Element::integer },
361 { "option-data", Element::list },
362 { "relay", Element::map },
363 { "reservations-global", Element::boolean },
364 { "reservations-in-subnet", Element::boolean },
365 { "reservations-out-of-pool", Element::boolean },
366 { "client-class", Element::string },
367 { "require-client-classes", Element::list },
368 { "preferred-lifetime", Element::integer },
369 { "min-preferred-lifetime", Element::integer },
370 { "max-preferred-lifetime", Element::integer },
371 { "rapid-commit", Element::boolean },
372 { "valid-lifetime", Element::integer },
373 { "min-valid-lifetime", Element::integer },
374 { "max-valid-lifetime", Element::integer },
375 { "user-context", Element::map },
376 { "comment", Element::string },
377 { "calculate-tee-times", Element::boolean },
378 { "t1-percent", Element::real },
379 { "t2-percent", Element::real },
380 { "ddns-send-updates", Element::boolean },
381 { "ddns-override-no-update", Element::boolean },
382 { "ddns-override-client-update", Element::boolean },
383 { "ddns-replace-client-name", Element::string },
384 { "ddns-generated-prefix", Element::string },
385 { "ddns-qualifying-suffix", Element::string },
386 { "hostname-char-set", Element::string },
387 { "hostname-char-replacement", Element::string },
388 { "store-extended-info", Element::boolean },
389 { "metadata", Element::map },
390 { "cache-threshold", Element::real },
391 { "cache-max-age", Element::integer },
392 { "ddns-update-on-renew", Element::boolean },
393 { "allocator", Element::string },
394 { "pd-allocator", Element::string },
395 { "ddns-ttl-percent", Element::real },
396 { "ddns-conflict-resolution-mode", Element::string },
397};
398
401 { "re-detect", Element::boolean, "true" }
402};
403
406 { "enable-queue", Element::boolean, "false"},
407 { "queue-type", Element::string, "kea-ring6"},
408 { "capacity", Element::integer, "64"}
409};
410
413 { "enable-multi-threading", Element::boolean, "true" },
414 { "thread-pool-size", Element::integer, "0" },
415 { "packet-queue-size", Element::integer, "64" }
416};
417
420 { "lease-checks", Element::string, "warn" }
421};
422
424
428
430 size_t cnt = 0;
431
432 // Set global defaults first.
433 cnt = setDefaults(global, GLOBAL6_DEFAULTS);
434
435 // Now set the defaults for each specified option definition
436 ConstElementPtr option_defs = global->get("option-def");
437 if (option_defs) {
438 for (auto const& option_def : option_defs->listValue()) {
440 }
441 }
442
443 // Set the defaults for option data
444 ConstElementPtr options = global->get("option-data");
445 if (options) {
446 for (auto const& single_option : options->listValue()) {
447 cnt += SimpleParser::setDefaults(single_option, OPTION6_DEFAULTS);
448 }
449 }
450
451 // Now set the defaults for defined subnets
452 ConstElementPtr subnets = global->get("subnet6");
453 if (subnets) {
454 cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
455 }
456
457 // Set the defaults for interfaces config
458 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
459 if (ifaces_cfg) {
460 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
461 cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
462 }
463
464 // Set defaults for shared networks
465 ConstElementPtr shared = global->get("shared-networks");
466 if (shared) {
467 for (auto const& net : shared->listValue()) {
468
470
471 ConstElementPtr subs = net->get("subnet6");
472 if (subs) {
474 }
475 }
476 }
477
478 // Set the defaults for dhcp-queue-control. If the element isn't there
479 // we'll add it.
480 ConstElementPtr queue_control = global->get("dhcp-queue-control");
481 ElementPtr mutable_cfg;
482 if (queue_control) {
483 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
484 } else {
485 mutable_cfg = Element::createMap();
486 global->set("dhcp-queue-control", mutable_cfg);
487 }
488
489 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
490
491 // Set the defaults for multi-threading. If the element isn't there
492 // we'll add it.
493 ConstElementPtr multi_threading = global->get("multi-threading");
494 if (multi_threading) {
495 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
496 } else {
497 mutable_cfg = Element::createMap();
498 global->set("multi-threading", mutable_cfg);
499 }
500
501 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS);
502
503 // Set the defaults for sanity-checks. If the element isn't
504 // there we'll add it.
505 ConstElementPtr sanity_checks = global->get("sanity-checks");
506 if (sanity_checks) {
507 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
508 } else {
509 mutable_cfg = Element::createMap();
510 global->set("sanity-checks", mutable_cfg);
511 }
512
513 cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
514
515 return (cnt);
516}
517
519 size_t cnt = 0;
520
521 // Now derive global parameters into subnets.
522 ConstElementPtr subnets = global->get("subnet6");
523 if (subnets) {
524 for (auto const& single_subnet : subnets->listValue()) {
525 cnt += SimpleParser::deriveParams(global, single_subnet,
527 }
528 }
529
530 // Deriving parameters for shared networks is a bit more involved.
531 // First, the shared-network level derives from global, and then
532 // subnets within derive from it.
533 ConstElementPtr shared = global->get("shared-networks");
534 if (shared) {
535 for (auto const& net : shared->listValue()) {
536 // First try to inherit the parameters from shared network,
537 // if defined there.
538 // Then try to inherit them from global.
539 cnt += SimpleParser::deriveParams(global, net,
541
542 // Now we need to go thrugh all the subnets in this net.
543 subnets = net->get("subnet6");
544 if (subnets) {
545 for (auto const& single_subnet : subnets->listValue()) {
546 cnt += SimpleParser::deriveParams(net, single_subnet,
548 }
549 }
550 }
551 }
552
553 return (cnt);
554}
555
556} // namespace dhcp
557} // 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.