Kea 2.5.5
simple_parser6.cc
Go to the documentation of this file.
1// Copyright (C) 2016-2023 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
12#include <boost/foreach.hpp>
13
14using namespace isc::data;
15
16namespace isc {
17namespace dhcp {
32
39 { "data-directory", Element::string },
40 { "preferred-lifetime", Element::integer },
41 { "min-preferred-lifetime", Element::integer },
42 { "max-preferred-lifetime", Element::integer },
43 { "valid-lifetime", Element::integer },
44 { "min-valid-lifetime", Element::integer },
45 { "max-valid-lifetime", Element::integer },
46 { "renew-timer", Element::integer },
47 { "rebind-timer", Element::integer },
48 { "decline-probation-period", Element::integer },
49 { "subnet6", Element::list },
50 { "shared-networks", Element::list },
51 { "interfaces-config", Element::map },
52 { "lease-database", Element::map },
53 { "hosts-database", Element::map },
54 { "hosts-databases", Element::list },
55 { "mac-sources", Element::list },
56 { "relay-supplied-options", Element::list },
57 { "host-reservation-identifiers", Element::list },
58 { "client-classes", Element::list },
59 { "option-def", Element::list },
60 { "option-data", Element::list },
61 { "hooks-libraries", Element::list },
62 { "expired-leases-processing", Element::map },
63 { "server-id", Element::map },
64 { "dhcp4o6-port", Element::integer },
65 { "control-socket", Element::map },
66 { "dhcp-queue-control", Element::map },
67 { "dhcp-ddns", Element::map },
68 { "user-context", Element::map },
69 { "comment", Element::string },
70 { "sanity-checks", Element::map },
71 { "reservations", Element::list },
72 { "config-control", Element::map },
73 { "server-tag", Element::string },
74 { "reservation-mode", Element::string },
75 { "reservations-global", Element::boolean },
76 { "reservations-in-subnet", Element::boolean },
77 { "reservations-out-of-pool", Element::boolean },
78 { "calculate-tee-times", Element::boolean },
79 { "t1-percent", Element::real },
80 { "t2-percent", Element::real },
81 { "loggers", Element::list },
82 { "hostname-char-set", Element::string },
83 { "hostname-char-replacement", Element::string },
84 { "ddns-send-updates", Element::boolean },
85 { "ddns-override-no-update", Element::boolean },
86 { "ddns-override-client-update", Element::boolean },
87 { "ddns-replace-client-name", Element::string },
88 { "ddns-generated-prefix", Element::string },
89 { "ddns-qualifying-suffix", Element::string },
90 { "store-extended-info", Element::boolean },
91 { "statistic-default-sample-count", Element::integer },
92 { "statistic-default-sample-age", Element::integer },
93 { "multi-threading", Element::map },
94 { "cache-threshold", Element::real },
95 { "cache-max-age", Element::integer },
96 { "early-global-reservations-lookup", Element::boolean },
97 { "ip-reservations-unique", Element::boolean },
98 { "reservations-lookup-first", Element::boolean },
99 { "ddns-update-on-renew", Element::boolean },
100 { "compatibility", Element::map },
101 { "parked-packet-limit", Element::integer },
102 { "allocator", Element::string },
103 { "pd-allocator", Element::string },
104 { "ddns-ttl-percent", Element::real },
105 { "ddns-conflict-resolution-mode", Element::string },
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 { "metadata", Element::map }
191};
192
199 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
200 { "csv-format", Element::boolean, "true"},
201 { "always-send", Element::boolean, "false"},
202 { "never-send", Element::boolean, "false"}
203};
204
211 { "preferred-lifetime", Element::integer },
212 { "min-preferred-lifetime", Element::integer },
213 { "max-preferred-lifetime", Element::integer },
214 { "valid-lifetime", Element::integer },
215 { "min-valid-lifetime", Element::integer },
216 { "max-valid-lifetime", Element::integer },
217 { "renew-timer", Element::integer },
218 { "rebind-timer", Element::integer },
219 { "option-data", Element::list },
220 { "pools", Element::list },
221 { "pd-pools", Element::list },
222 { "subnet", Element::string },
223 { "interface", Element::string },
224 { "interface-id", Element::string },
225 { "id", Element::integer },
226 { "rapid-commit", Element::boolean },
227 { "client-class", Element::string },
228 { "require-client-classes", Element::list },
229 { "reservations", Element::list },
230 { "reservation-mode", Element::string },
231 { "reservations-global", Element::boolean },
232 { "reservations-in-subnet", Element::boolean },
233 { "reservations-out-of-pool", Element::boolean },
234 { "relay", Element::map },
235 { "user-context", Element::map },
236 { "comment", Element::string },
237 { "calculate-tee-times", Element::boolean },
238 { "t1-percent", Element::real },
239 { "t2-percent", Element::real },
240 { "ddns-send-updates", Element::boolean },
241 { "ddns-override-no-update", Element::boolean },
242 { "ddns-override-client-update", Element::boolean },
243 { "ddns-replace-client-name", Element::string },
244 { "ddns-generated-prefix", Element::string },
245 { "ddns-qualifying-suffix", Element::string },
246 { "hostname-char-set", Element::string },
247 { "hostname-char-replacement", Element::string },
248 { "store-extended-info", Element::boolean },
249 { "metadata", Element::map },
250 { "cache-threshold", Element::real },
251 { "cache-max-age", Element::integer },
252 { "ddns-update-on-renew", Element::boolean },
253 { "allocator", Element::string },
254 { "pd-allocator", Element::string },
255 { "ddns-ttl-percent", Element::real },
256 { "ddns-conflict-resolution-mode", Element::string },
257};
258
266 { "id", Element::integer, "0" }, // 0 means autogenerate
267 { "interface", Element::string, "" },
268 { "client-class", Element::string, "" },
269 { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
270 { "interface-id", Element::string, "" }
271};
272
279 { "id", Element::integer, "0" } // 0 means autogenerate
280};
281
284 { "client-class", Element::string, "" },
285 { "interface", Element::string, "" },
286 { "interface-id", Element::string, "" },
287 { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
288};
289
300 "preferred-lifetime",
301 "min-preferred-lifetime",
302 "max-preferred-lifetime",
303 "rebind-timer",
304 "relay",
305 "renew-timer",
306 "valid-lifetime",
307 "min-valid-lifetime",
308 "max-valid-lifetime",
309 "calculate-tee-times",
310 "t1-percent",
311 "t2-percent",
312 "store-extended-info",
313 "cache-threshold",
314 "cache-max-age",
315 "allocator",
316 "pd-allocator"
317};
318
325 { "pool", Element::string },
326 { "pool-id", Element::integer },
327 { "option-data", Element::list },
328 { "client-class", Element::string },
329 { "require-client-classes", Element::list },
330 { "user-context", Element::map },
331 { "comment", Element::string },
332 { "metadata", Element::map }
333};
334
341 { "prefix", Element::string },
342 { "prefix-len", Element::integer },
343 { "delegated-len", Element::integer },
344 { "pool-id", Element::integer },
345 { "option-data", Element::list },
346 { "client-class", Element::string },
347 { "require-client-classes", Element::list },
348 { "excluded-prefix", Element::string },
349 { "excluded-prefix-len", Element::integer },
350 { "user-context", Element::map },
351 { "comment", Element::string },
352 { "metadata", Element::map }
353};
354
361 { "name", Element::string },
362 { "subnet6", Element::list },
363 { "interface", Element::string },
364 { "interface-id", Element::string },
365 { "renew-timer", Element::integer },
366 { "rebind-timer", Element::integer },
367 { "option-data", Element::list },
368 { "relay", Element::map },
369 { "reservation-mode", Element::string },
370 { "reservations-global", Element::boolean },
371 { "reservations-in-subnet", Element::boolean },
372 { "reservations-out-of-pool", Element::boolean },
373 { "client-class", Element::string },
374 { "require-client-classes", Element::list },
375 { "preferred-lifetime", Element::integer },
376 { "min-preferred-lifetime", Element::integer },
377 { "max-preferred-lifetime", Element::integer },
378 { "rapid-commit", Element::boolean },
379 { "valid-lifetime", Element::integer },
380 { "min-valid-lifetime", Element::integer },
381 { "max-valid-lifetime", Element::integer },
382 { "user-context", Element::map },
383 { "comment", Element::string },
384 { "calculate-tee-times", Element::boolean },
385 { "t1-percent", Element::real },
386 { "t2-percent", Element::real },
387 { "ddns-send-updates", Element::boolean },
388 { "ddns-override-no-update", Element::boolean },
389 { "ddns-override-client-update", Element::boolean },
390 { "ddns-replace-client-name", Element::string },
391 { "ddns-generated-prefix", Element::string },
392 { "ddns-qualifying-suffix", Element::string },
393 { "hostname-char-set", Element::string },
394 { "hostname-char-replacement", Element::string },
395 { "store-extended-info", Element::boolean },
396 { "metadata", Element::map },
397 { "cache-threshold", Element::real },
398 { "cache-max-age", Element::integer },
399 { "ddns-update-on-renew", Element::boolean },
400 { "allocator", Element::string },
401 { "pd-allocator", Element::string },
402 { "ddns-ttl-percent", Element::real },
403 { "ddns-conflict-resolution-mode", Element::string },
404};
405
408 { "re-detect", Element::boolean, "true" }
409};
410
413 { "enable-queue", Element::boolean, "false"},
414 { "queue-type", Element::string, "kea-ring6"},
415 { "capacity", Element::integer, "64"}
416};
417
420 { "enable-multi-threading", Element::boolean, "true" },
421 { "thread-pool-size", Element::integer, "0" },
422 { "packet-queue-size", Element::integer, "64" }
423};
424
427 { "lease-checks", Element::string, "warn" }
428};
429
431
435
437 size_t cnt = 0;
438
439 // Set global defaults first.
440 cnt = setDefaults(global, GLOBAL6_DEFAULTS);
441
442 // Now set the defaults for each specified option definition
443 ConstElementPtr option_defs = global->get("option-def");
444 if (option_defs) {
445 BOOST_FOREACH(ElementPtr option_def, option_defs->listValue()) {
447 }
448 }
449
450 // Set the defaults for option data
451 ConstElementPtr options = global->get("option-data");
452 if (options) {
453 BOOST_FOREACH(ElementPtr single_option, options->listValue()) {
454 cnt += SimpleParser::setDefaults(single_option, OPTION6_DEFAULTS);
455 }
456 }
457
458 // Now set the defaults for defined subnets
459 ConstElementPtr subnets = global->get("subnet6");
460 if (subnets) {
461 cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
462 }
463
464 // Set the defaults for interfaces config
465 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
466 if (ifaces_cfg) {
467 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
468 cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
469 }
470
471 // Set defaults for shared networks
472 ConstElementPtr shared = global->get("shared-networks");
473 if (shared) {
474 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
475
477
478 ConstElementPtr subs = net->get("subnet6");
479 if (subs) {
481 }
482 }
483 }
484
485 // Set the defaults for dhcp-queue-control. If the element isn't there
486 // we'll add it.
487 ConstElementPtr queue_control = global->get("dhcp-queue-control");
488 ElementPtr mutable_cfg;
489 if (queue_control) {
490 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
491 } else {
492 mutable_cfg = Element::createMap();
493 global->set("dhcp-queue-control", mutable_cfg);
494 }
495
496 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
497
498 // Set the defaults for multi-threading. If the element isn't there
499 // we'll add it.
500 ConstElementPtr multi_threading = global->get("multi-threading");
501 if (multi_threading) {
502 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
503 } else {
504 mutable_cfg = Element::createMap();
505 global->set("multi-threading", mutable_cfg);
506 }
507
508 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS);
509
510 // Set the defaults for sanity-checks. If the element isn't
511 // there we'll add it.
512 ConstElementPtr sanity_checks = global->get("sanity-checks");
513 if (sanity_checks) {
514 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
515 } else {
516 mutable_cfg = Element::createMap();
517 global->set("sanity-checks", mutable_cfg);
518 }
519
520 cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
521
522 return (cnt);
523}
524
526 size_t cnt = 0;
527
528 // Now derive global parameters into subnets.
529 ConstElementPtr subnets = global->get("subnet6");
530 if (subnets) {
531 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
532 cnt += SimpleParser::deriveParams(global, single_subnet,
534 }
535 }
536
537 // Deriving parameters for shared networks is a bit more involved.
538 // First, the shared-network level derives from global, and then
539 // subnets within derive from it.
540 ConstElementPtr shared = global->get("shared-networks");
541 if (shared) {
542 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
543 // First try to inherit the parameters from shared network,
544 // if defined there.
545 // Then try to inherit them from global.
546 cnt += SimpleParser::deriveParams(global, net,
548
549 // Now we need to go thrugh all the subnets in this net.
550 subnets = net->get("subnet6");
551 if (subnets) {
552 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
553 cnt += SimpleParser::deriveParams(net, single_subnet,
555 }
556 }
557 }
558 }
559
560 return (cnt);
561}
562
563} // namespace dhcp
564} // 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.