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