Kea 3.1.1
simple_parser4.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 { "valid-lifetime", Element::integer },
38 { "min-valid-lifetime", Element::integer },
39 { "max-valid-lifetime", Element::integer },
40 { "renew-timer", Element::integer },
41 { "rebind-timer", Element::integer },
42 { "decline-probation-period", Element::integer },
43 { "subnet4", Element::list },
44 { "shared-networks", Element::list },
45 { "interfaces-config", Element::map },
46 { "lease-database", Element::map },
47 { "hosts-database", Element::map },
48 { "hosts-databases", Element::list },
49 { "host-reservation-identifiers", Element::list },
50 { "client-classes", Element::list },
51 { "option-def", Element::list },
52 { "option-data", Element::list },
53 { "hooks-libraries", Element::list },
54 { "expired-leases-processing", Element::map },
55 { "dhcp4o6-port", Element::integer },
56 { "control-sockets", Element::list },
57 { "dhcp-queue-control", Element::map },
58 { "dhcp-ddns", Element::map },
59 { "echo-client-id", Element::boolean },
60 { "match-client-id", Element::boolean },
61 { "authoritative", Element::boolean },
62 { "next-server", Element::string },
63 { "server-hostname", Element::string },
64 { "boot-file-name", Element::string },
65 { "user-context", Element::map },
66 { "comment", Element::string },
67 { "sanity-checks", Element::map },
68 { "reservations", Element::list },
69 { "config-control", Element::map },
70 { "server-tag", Element::string },
71 { "reservations-global", Element::boolean },
72 { "reservations-in-subnet", Element::boolean },
73 { "reservations-out-of-pool", Element::boolean },
74 { "calculate-tee-times", Element::boolean },
75 { "t1-percent", Element::real },
76 { "t2-percent", Element::real },
77 { "loggers", Element::list },
78 { "hostname-char-set", Element::string },
79 { "hostname-char-replacement", Element::string },
80 { "ddns-send-updates", Element::boolean },
81 { "ddns-override-no-update", Element::boolean },
82 { "ddns-override-client-update", Element::boolean },
83 { "ddns-replace-client-name", Element::string },
84 { "ddns-generated-prefix", Element::string },
85 { "ddns-qualifying-suffix", Element::string },
86 { "store-extended-info", Element::boolean },
87 { "statistic-default-sample-count", Element::integer },
88 { "statistic-default-sample-age", Element::integer },
89 { "multi-threading", Element::map },
90 { "cache-threshold", Element::real },
91 { "cache-max-age", Element::integer },
92 { "early-global-reservations-lookup", Element::boolean },
93 { "ip-reservations-unique", Element::boolean },
94 { "reservations-lookup-first", Element::boolean },
95 { "ddns-update-on-renew", Element::boolean },
96 { "compatibility", Element::map },
97 { "parked-packet-limit", Element::integer },
98 { "allocator", Element::string },
99 { "offer-lifetime", Element::integer },
100 { "ddns-ttl-percent", Element::real },
101 { "ddns-conflict-resolution-mode", Element::string },
102 { "stash-agent-options", Element::boolean },
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 { "valid-lifetime", Element::integer, "7200" },
116 { "decline-probation-period", Element::integer, "86400" }, // 24h
117 { "dhcp4o6-port", Element::integer, "0" },
118 { "echo-client-id", Element::boolean, "true" },
119 { "match-client-id", Element::boolean, "true" },
120 { "authoritative", Element::boolean, "false" },
121 { "next-server", Element::string, "0.0.0.0" },
122 { "server-hostname", Element::string, "" },
123 { "boot-file-name", Element::string, "" },
124 { "server-tag", Element::string, "" },
125 { "reservations-global", Element::boolean, "false" },
126 { "reservations-in-subnet", Element::boolean, "true" },
127 { "reservations-out-of-pool", Element::boolean, "false" },
128 { "calculate-tee-times", Element::boolean, "false" },
129 { "t1-percent", Element::real, ".50" },
130 { "t2-percent", Element::real, ".875" },
131 { "ddns-send-updates", Element::boolean, "true" },
132 { "ddns-override-no-update", Element::boolean, "false" },
133 { "ddns-override-client-update", Element::boolean, "false" },
134 { "ddns-replace-client-name", Element::string, "never" },
135 { "ddns-generated-prefix", Element::string, "myhost" },
136 { "ddns-qualifying-suffix", Element::string, "" },
137 { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
138 { "hostname-char-replacement", Element::string, "" },
139 { "store-extended-info", Element::boolean, "false" },
140 { "statistic-default-sample-count", Element::integer, "20" },
141 { "statistic-default-sample-age", Element::integer, "0" },
142 { "early-global-reservations-lookup", Element::boolean, "false" },
143 { "ip-reservations-unique", Element::boolean, "true" },
144 { "reservations-lookup-first", Element::boolean, "false" },
145 { "ddns-update-on-renew", Element::boolean, "false" },
146 { "parked-packet-limit", Element::integer, "256" },
147 { "allocator", Element::string, "iterative" },
148 { "ddns-conflict-resolution-mode", Element::string, "check-with-dhcid" },
149 { "stash-agent-options", Element::boolean, "false" },
150 { "cache-threshold", Element::real, "0.25" },
151};
152
154 { "host-reservation-identifiers", Element::list },
155 /* not yet supported
156 { "interfaces-config.interfaces", Element::list },
157 */
158};
159
161 { "host-reservation-identifiers", Element::string },
162 /* not yet supported
163 { "interfaces-config.interfaces", Element::string },
164 */
165};
166
173 { "name", Element::string },
174 { "code", Element::integer },
175 { "type", Element::string },
176 { "record-types", Element::string },
177 { "space", Element::string },
178 { "encapsulate", Element::string },
179 { "array", Element::boolean, },
180 { "user-context", Element::map },
181 { "comment", Element::string },
182 { "metadata", Element::map }
183};
184
190 { "record-types", Element::string, ""},
191 { "space", Element::string, "dhcp4"}, // DHCP4_OPTION_SPACE
192 { "array", Element::boolean, "false"},
193 { "encapsulate", Element::string, "" }
194};
195
202 { "name", Element::string },
203 { "data", Element::string },
204 { "code", Element::integer },
205 { "space", Element::string },
206 { "csv-format", Element::boolean },
207 { "always-send", Element::boolean },
208 { "never-send", Element::boolean },
209 { "user-context", Element::map },
210 { "comment", Element::string },
211 { "client-classes", Element::list },
212 { "metadata", Element::map }
213};
214
221 { "space", Element::string, "dhcp4"}, // DHCP4_OPTION_SPACE
222 { "csv-format", Element::boolean, "true"},
223 { "always-send", Element::boolean, "false"},
224 { "never-send", Element::boolean, "false"}
225};
226
233 { "valid-lifetime", Element::integer },
234 { "min-valid-lifetime", Element::integer },
235 { "max-valid-lifetime", Element::integer },
236 { "renew-timer", Element::integer },
237 { "rebind-timer", Element::integer },
238 { "option-data", Element::list },
239 { "pools", Element::list },
240 { "subnet", Element::string },
241 { "interface", Element::string },
242 { "id", Element::integer },
243 { "client-class", Element::string },
244 { "client-classes", Element::list },
245 { "require-client-classes", Element::list },
246 { "evaluate-additional-classes", Element::list },
247 { "reservations", Element::list },
248 { "reservations-global", Element::boolean },
249 { "reservations-in-subnet", Element::boolean },
250 { "reservations-out-of-pool", Element::boolean },
251 { "relay", Element::map },
252 { "match-client-id", Element::boolean },
253 { "authoritative", Element::boolean },
254 { "next-server", Element::string },
255 { "server-hostname", Element::string },
256 { "boot-file-name", Element::string },
257 { "4o6-interface", Element::string },
258 { "4o6-interface-id", Element::string },
259 { "4o6-subnet", Element::string },
260 { "user-context", Element::map },
261 { "comment", Element::string },
262 { "calculate-tee-times", Element::boolean },
263 { "t1-percent", Element::real },
264 { "t2-percent", Element::real },
265 { "ddns-send-updates", Element::boolean },
266 { "ddns-override-no-update", Element::boolean },
267 { "ddns-override-client-update", Element::boolean },
268 { "ddns-replace-client-name", Element::string },
269 { "ddns-generated-prefix", Element::string },
270 { "ddns-qualifying-suffix", Element::string },
271 { "hostname-char-set", Element::string },
272 { "hostname-char-replacement", Element::string },
273 { "store-extended-info", Element::boolean },
274 { "metadata", Element::map },
275 { "cache-threshold", Element::real },
276 { "cache-max-age", Element::integer },
277 { "ddns-update-on-renew", Element::boolean },
278 { "allocator", Element::string },
279 { "offer-lifetime", Element::integer },
280 { "ddns-ttl-percent", Element::real },
281 { "ddns-conflict-resolution-mode", Element::string },
282 { "ddns-ttl", Element::integer },
283 { "ddns-ttl-min", Element::integer },
284 { "ddns-ttl-max", Element::integer },
285 { "adaptive-lease-time-threshold", Element::real },
286};
287
296 { "interface", Element::string, "" },
297 { "4o6-interface", Element::string, "" },
298 { "4o6-interface-id", Element::string, "" },
299 { "4o6-subnet", Element::string, "" },
300};
301
309 { "4o6-interface", Element::string, "" },
310 { "4o6-interface-id", Element::string, "" },
311 { "4o6-subnet", Element::string, "" },
312};
313
316 { "interface", Element::string, "" }
317};
318
329 "rebind-timer",
330 "relay",
331 "renew-timer",
332 "valid-lifetime",
333 "min-valid-lifetime",
334 "max-valid-lifetime",
335 "calculate-tee-times",
336 "t1-percent",
337 "t2-percent",
338 "store-extended-info",
339 "cache-threshold",
340 "cache-max-age",
341 "allocator",
342 "offer-lifetime",
343 "adaptive-lease-time-threshold",
344};
345
352 { "pool", Element::string },
353 { "pool-id", Element::integer },
354 { "option-data", Element::list },
355 { "client-class", Element::string },
356 { "client-classes", Element::list },
357 { "require-client-classes", Element::list },
358 { "evaluate-additional-classes", Element::list },
359 { "user-context", Element::map },
360 { "comment", Element::string },
361 { "ddns-send-updates", Element::boolean },
362 { "ddns-override-no-update", Element::boolean },
363 { "ddns-override-client-update", Element::boolean },
364 { "ddns-replace-client-name", Element::string },
365 { "ddns-generated-prefix", Element::string },
366 { "ddns-qualifying-suffix", Element::string },
367 { "hostname-char-set", Element::string },
368 { "hostname-char-replacement", Element::string },
369 { "ddns-update-on-renew", Element::boolean },
370 { "ddns-ttl-percent", Element::real },
371 { "ddns-conflict-resolution-mode", Element::string },
372 { "ddns-ttl", Element::integer },
373 { "ddns-ttl-min", Element::integer },
374 { "ddns-ttl-max", Element::integer },
375 { "metadata", Element::map }
376};
377
384 { "name", Element::string },
385 { "subnet4", Element::list },
386 { "interface", Element::string },
387 { "renew-timer", Element::integer },
388 { "rebind-timer", Element::integer },
389 { "option-data", Element::list },
390 { "match-client-id", Element::boolean },
391 { "authoritative", Element::boolean },
392 { "next-server", Element::string },
393 { "server-hostname", Element::string },
394 { "boot-file-name", Element::string },
395 { "relay", Element::map },
396 { "reservations-global", Element::boolean },
397 { "reservations-in-subnet", Element::boolean },
398 { "reservations-out-of-pool", Element::boolean },
399 { "client-class", Element::string },
400 { "client-classes", Element::list },
401 { "require-client-classes", Element::list },
402 { "evaluate-additional-classes", Element::list },
403 { "valid-lifetime", Element::integer },
404 { "min-valid-lifetime", Element::integer },
405 { "max-valid-lifetime", Element::integer },
406 { "user-context", Element::map },
407 { "comment", Element::string },
408 { "calculate-tee-times", Element::boolean },
409 { "t1-percent", Element::real },
410 { "t2-percent", Element::real },
411 { "ddns-send-updates", Element::boolean },
412 { "ddns-override-no-update", Element::boolean },
413 { "ddns-override-client-update", Element::boolean },
414 { "ddns-replace-client-name", Element::string },
415 { "ddns-generated-prefix", Element::string },
416 { "ddns-qualifying-suffix", Element::string },
417 { "hostname-char-set", Element::string },
418 { "hostname-char-replacement", Element::string },
419 { "store-extended-info", Element::boolean },
420 { "metadata", Element::map },
421 { "cache-threshold", Element::real },
422 { "cache-max-age", Element::integer },
423 { "ddns-update-on-renew", Element::boolean },
424 { "allocator", Element::string },
425 { "offer-lifetime", Element::integer },
426 { "ddns-ttl-percent", Element::real },
427 { "ddns-conflict-resolution-mode", Element::string },
428 { "ddns-ttl", Element::integer },
429 { "ddns-ttl-min", Element::integer },
430 { "ddns-ttl-max", Element::integer },
431 { "adaptive-lease-time-threshold", Element::real },
432};
433
436 { "re-detect", Element::boolean, "true" }
437};
438
441 { "enable-queue", Element::boolean, "false"},
442 { "queue-type", Element::string, "kea-ring4"},
443 { "capacity", Element::integer, "64"}
444};
445
448 { "enable-multi-threading", Element::boolean, "true" },
449 { "thread-pool-size", Element::integer, "0" },
450 { "packet-queue-size", Element::integer, "64" }
451};
452
455 { "lease-checks", Element::string, "warn" }
456};
457
459
463
465 size_t cnt = 0;
466
467 // Set global defaults first.
468 cnt = setDefaults(global, GLOBAL4_DEFAULTS);
469
470 // Now set the defaults for each specified option definition
471 ConstElementPtr option_defs = global->get("option-def");
472 if (option_defs) {
473 cnt += setListDefaults(option_defs, OPTION4_DEF_DEFAULTS);
474 }
475
476 // Set the defaults for option data
477 ConstElementPtr options = global->get("option-data");
478 if (options) {
479 cnt += setListDefaults(options, OPTION4_DEFAULTS);
480 }
481
482 // Now set the defaults for defined subnets
483 ConstElementPtr subnets = global->get("subnet4");
484 if (subnets) {
485 cnt += setListDefaults(subnets, SUBNET4_DEFAULTS);
486 }
487
488 // Set the defaults for interfaces config
489 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
490 if (ifaces_cfg) {
491 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
492 cnt += setDefaults(mutable_cfg, IFACE4_DEFAULTS);
493 }
494
495 // Set defaults for shared networks
496 ConstElementPtr shared = global->get("shared-networks");
497 if (shared) {
498 for (auto const& net : shared->listValue()) {
499
501
502 ConstElementPtr subs = net->get("subnet4");
503 if (subs) {
505 }
506 }
507 }
508
509 // Set the defaults for dhcp-queue-control. If the element isn't there
510 // we'll add it.
511 ConstElementPtr queue_control = global->get("dhcp-queue-control");
512 ElementPtr mutable_cfg;
513 if (queue_control) {
514 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
515 } else {
516 mutable_cfg = Element::createMap();
517 global->set("dhcp-queue-control", mutable_cfg);
518 }
519
520 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL4_DEFAULTS);
521
522 // Set the defaults for multi-threading. If the element isn't there
523 // we'll add it.
524 ConstElementPtr multi_threading = global->get("multi-threading");
525 if (multi_threading) {
526 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
527 } else {
528 mutable_cfg = Element::createMap();
529 global->set("multi-threading", mutable_cfg);
530 }
531
532 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING4_DEFAULTS);
533
534 // Set the defaults for sanity-checks. If the element isn't
535 // there we'll add it.
536 ConstElementPtr sanity_checks = global->get("sanity-checks");
537 if (sanity_checks) {
538 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
539 } else {
540 mutable_cfg = Element::createMap();
541 global->set("sanity-checks", mutable_cfg);
542 }
543
544 cnt += setDefaults(mutable_cfg, SANITY_CHECKS4_DEFAULTS);
545
546 return (cnt);
547}
548
550 size_t cnt = 0;
551
552 // Now derive global parameters into subnets.
553 ConstElementPtr subnets = global->get("subnet4");
554 if (subnets) {
555 for (auto const& single_subnet : subnets->listValue()) {
556 cnt += SimpleParser::deriveParams(global, single_subnet,
558 }
559 }
560
561 // Deriving parameters for shared networks is a bit more involved.
562 // First, the shared-network level derives from global, and then
563 // subnets within derive from it.
564 ConstElementPtr shared = global->get("shared-networks");
565 if (shared) {
566 for (auto const& net : shared->listValue()) {
567 // First try to inherit the parameters from shared network,
568 // if defined there.
569 // Then try to inherit them from global.
570 cnt += SimpleParser::deriveParams(global, net,
572
573 // Now we need to go thrugh all the subnets in this net.
574 subnets = net->get("subnet4");
575 if (subnets) {
576 for (auto const& single_subnet : subnets->listValue()) {
577 cnt += SimpleParser::deriveParams(net, single_subnet,
579 }
580 }
581 }
582 }
583
584 return (cnt);
585}
586
587} // namespace dhcp
588} // 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 DHCP_MULTI_THREADING4_DEFAULTS
This table defines default values for multi-threading in DHCPv4.
static const isc::data::SimpleDefaults SUBNET4_DEFAULTS
This table defines default values for each IPv4 subnet.
static const isc::data::SimpleKeywords SUBNET4_PARAMETERS
This table defines all subnet parameters for DHCPv4.
static const isc::data::SimpleKeywords GLOBAL4_PARAMETERS
This table defines all global parameters in DHCPv4.
static const isc::data::SimpleDefaults GLOBAL4_DEFAULTS
This table defines default global values for DHCPv4.
static const isc::data::ParamsList INHERIT_TO_SUBNET4
List of parameters that can be inherited from the global to subnet4 scope.
static const isc::data::SimpleDefaults IFACE4_DEFAULTS
This table defines default values for interfaces for DHCPv4.
static const isc::data::SimpleKeywords OPTION4_DEF_PARAMETERS
This table defines all option definition parameters.
static const isc::data::SimpleDefaults SHARED_NETWORK4_DEFAULTS
This table defines default values for each IPv4 shared network.
static const isc::data::SimpleKeywords OPTION4_PARAMETERS
This table defines all option parameters.
static const isc::data::SimpleKeywords POOL4_PARAMETERS
This table defines all pool parameters.
static const isc::data::SimpleKeywords GLOBAL4_LIST_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 DHCPv4 configuration.
static const isc::data::SimpleDefaults SHARED_SUBNET4_DEFAULTS
This table defines default values for each IPv4 subnet that is part of a shared network.
static const isc::data::SimpleDefaults OPTION4_DEFAULTS
This table defines default values for options in DHCPv4.
static const isc::data::SimpleKeywords SHARED_NETWORK4_PARAMETERS
This table defines all shared network parameters for DHCPv4.
static const isc::data::SimpleDefaults SANITY_CHECKS4_DEFAULTS
This defines default values for sanity checking for DHCPv4.
static const isc::data::SimpleDefaults DHCP_QUEUE_CONTROL4_DEFAULTS
This table defines default values for dhcp-queue-control in DHCPv4.
static const isc::data::SimpleDefaults OPTION4_DEF_DEFAULTS
This table defines default values for option definitions in DHCPv4.
static const isc::data::SimpleKeywords GLOBAL4_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.