Kea 2.7.7
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
10#include <cc/data.h>
11#include <iostream>
12
13using namespace isc::data;
14
15namespace isc {
16namespace dhcp {
31
38 { "valid-lifetime", Element::integer },
39 { "min-valid-lifetime", Element::integer },
40 { "max-valid-lifetime", Element::integer },
41 { "renew-timer", Element::integer },
42 { "rebind-timer", Element::integer },
43 { "decline-probation-period", Element::integer },
44 { "subnet4", Element::list },
45 { "shared-networks", Element::list },
46 { "interfaces-config", Element::map },
47 { "lease-database", Element::map },
48 { "hosts-database", Element::map },
49 { "hosts-databases", Element::list },
50 { "host-reservation-identifiers", Element::list },
51 { "client-classes", Element::list },
52 { "option-def", Element::list },
53 { "option-data", Element::list },
54 { "hooks-libraries", Element::list },
55 { "expired-leases-processing", Element::map },
56 { "dhcp4o6-port", Element::integer },
57 { "control-sockets", Element::list },
58 { "dhcp-queue-control", Element::map },
59 { "dhcp-ddns", Element::map },
60 { "echo-client-id", Element::boolean },
61 { "match-client-id", Element::boolean },
62 { "authoritative", Element::boolean },
63 { "next-server", Element::string },
64 { "server-hostname", Element::string },
65 { "boot-file-name", Element::string },
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 { "offer-lifetime", Element::integer },
101 { "ddns-ttl-percent", Element::real },
102 { "ddns-conflict-resolution-mode", Element::string },
103 { "stash-agent-options", Element::boolean },
104 { "ddns-ttl", Element::integer },
105 { "ddns-ttl-min", Element::integer },
106 { "ddns-ttl-max", Element::integer },
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};
151
158 { "name", Element::string },
159 { "code", Element::integer },
160 { "type", Element::string },
161 { "record-types", Element::string },
162 { "space", Element::string },
163 { "encapsulate", Element::string },
164 { "array", Element::boolean, },
165 { "user-context", Element::map },
166 { "comment", Element::string },
167 { "metadata", Element::map }
168};
169
175 { "record-types", Element::string, ""},
176 { "space", Element::string, "dhcp4"}, // DHCP4_OPTION_SPACE
177 { "array", Element::boolean, "false"},
178 { "encapsulate", Element::string, "" }
179};
180
187 { "name", Element::string },
188 { "data", Element::string },
189 { "code", Element::integer },
190 { "space", Element::string },
191 { "csv-format", Element::boolean },
192 { "always-send", Element::boolean },
193 { "never-send", Element::boolean },
194 { "user-context", Element::map },
195 { "comment", Element::string },
196 { "client-classes", Element::list },
197 { "metadata", Element::map }
198};
199
206 { "space", Element::string, "dhcp4"}, // DHCP4_OPTION_SPACE
207 { "csv-format", Element::boolean, "true"},
208 { "always-send", Element::boolean, "false"},
209 { "never-send", Element::boolean, "false"}
210};
211
218 { "valid-lifetime", Element::integer },
219 { "min-valid-lifetime", Element::integer },
220 { "max-valid-lifetime", Element::integer },
221 { "renew-timer", Element::integer },
222 { "rebind-timer", Element::integer },
223 { "option-data", Element::list },
224 { "pools", Element::list },
225 { "subnet", Element::string },
226 { "interface", Element::string },
227 { "id", Element::integer },
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 { "match-client-id", Element::boolean },
238 { "authoritative", Element::boolean },
239 { "next-server", Element::string },
240 { "server-hostname", Element::string },
241 { "boot-file-name", Element::string },
242 { "4o6-interface", Element::string },
243 { "4o6-interface-id", Element::string },
244 { "4o6-subnet", Element::string },
245 { "user-context", Element::map },
246 { "comment", Element::string },
247 { "calculate-tee-times", Element::boolean },
248 { "t1-percent", Element::real },
249 { "t2-percent", Element::real },
250 { "ddns-send-updates", Element::boolean },
251 { "ddns-override-no-update", Element::boolean },
252 { "ddns-override-client-update", Element::boolean },
253 { "ddns-replace-client-name", Element::string },
254 { "ddns-generated-prefix", Element::string },
255 { "ddns-qualifying-suffix", Element::string },
256 { "hostname-char-set", Element::string },
257 { "hostname-char-replacement", Element::string },
258 { "store-extended-info", Element::boolean },
259 { "metadata", Element::map },
260 { "cache-threshold", Element::real },
261 { "cache-max-age", Element::integer },
262 { "ddns-update-on-renew", Element::boolean },
263 { "allocator", Element::string },
264 { "offer-lifetime", Element::integer },
265 { "ddns-ttl-percent", Element::real },
266 { "ddns-conflict-resolution-mode", Element::string },
267 { "ddns-ttl", Element::integer },
268 { "ddns-ttl-min", Element::integer },
269 { "ddns-ttl-max", Element::integer },
270};
271
280 { "interface", Element::string, "" },
281 { "4o6-interface", Element::string, "" },
282 { "4o6-interface-id", Element::string, "" },
283 { "4o6-subnet", Element::string, "" },
284};
285
293 { "4o6-interface", Element::string, "" },
294 { "4o6-interface-id", Element::string, "" },
295 { "4o6-subnet", Element::string, "" },
296};
297
300 { "interface", Element::string, "" }
301};
302
313 "rebind-timer",
314 "relay",
315 "renew-timer",
316 "valid-lifetime",
317 "min-valid-lifetime",
318 "max-valid-lifetime",
319 "calculate-tee-times",
320 "t1-percent",
321 "t2-percent",
322 "store-extended-info",
323 "cache-threshold",
324 "cache-max-age",
325 "allocator",
326 "offer-lifetime",
327};
328
335 { "pool", Element::string },
336 { "pool-id", Element::integer },
337 { "option-data", Element::list },
338 { "client-class", Element::string },
339 { "client-classes", Element::list },
340 { "require-client-classes", Element::list },
341 { "evaluate-additional-classes", Element::list },
342 { "user-context", Element::map },
343 { "comment", Element::string },
344 { "ddns-send-updates", Element::boolean },
345 { "ddns-override-no-update", Element::boolean },
346 { "ddns-override-client-update", Element::boolean },
347 { "ddns-replace-client-name", Element::string },
348 { "ddns-generated-prefix", Element::string },
349 { "ddns-qualifying-suffix", Element::string },
350 { "hostname-char-set", Element::string },
351 { "hostname-char-replacement", Element::string },
352 { "ddns-update-on-renew", Element::boolean },
353 { "ddns-ttl-percent", Element::real },
354 { "ddns-conflict-resolution-mode", Element::string },
355 { "ddns-ttl", Element::integer },
356 { "ddns-ttl-min", Element::integer },
357 { "ddns-ttl-max", Element::integer },
358 { "metadata", Element::map }
359};
360
367 { "name", Element::string },
368 { "subnet4", Element::list },
369 { "interface", Element::string },
370 { "renew-timer", Element::integer },
371 { "rebind-timer", Element::integer },
372 { "option-data", Element::list },
373 { "match-client-id", Element::boolean },
374 { "authoritative", Element::boolean },
375 { "next-server", Element::string },
376 { "server-hostname", Element::string },
377 { "boot-file-name", Element::string },
378 { "relay", Element::map },
379 { "reservations-global", Element::boolean },
380 { "reservations-in-subnet", Element::boolean },
381 { "reservations-out-of-pool", Element::boolean },
382 { "client-class", Element::string },
383 { "client-classes", Element::list },
384 { "require-client-classes", Element::list },
385 { "evaluate-additional-classes", Element::list },
386 { "valid-lifetime", Element::integer },
387 { "min-valid-lifetime", Element::integer },
388 { "max-valid-lifetime", Element::integer },
389 { "user-context", Element::map },
390 { "comment", Element::string },
391 { "calculate-tee-times", Element::boolean },
392 { "t1-percent", Element::real },
393 { "t2-percent", Element::real },
394 { "ddns-send-updates", Element::boolean },
395 { "ddns-override-no-update", Element::boolean },
396 { "ddns-override-client-update", Element::boolean },
397 { "ddns-replace-client-name", Element::string },
398 { "ddns-generated-prefix", Element::string },
399 { "ddns-qualifying-suffix", Element::string },
400 { "hostname-char-set", Element::string },
401 { "hostname-char-replacement", Element::string },
402 { "store-extended-info", Element::boolean },
403 { "metadata", Element::map },
404 { "cache-threshold", Element::real },
405 { "cache-max-age", Element::integer },
406 { "ddns-update-on-renew", Element::boolean },
407 { "allocator", Element::string },
408 { "offer-lifetime", Element::integer },
409 { "ddns-ttl-percent", Element::real },
410 { "ddns-conflict-resolution-mode", Element::string },
411 { "ddns-ttl", Element::integer },
412 { "ddns-ttl-min", Element::integer },
413 { "ddns-ttl-max", Element::integer },
414};
415
418 { "re-detect", Element::boolean, "true" }
419};
420
423 { "enable-queue", Element::boolean, "false"},
424 { "queue-type", Element::string, "kea-ring4"},
425 { "capacity", Element::integer, "64"}
426};
427
430 { "enable-multi-threading", Element::boolean, "true" },
431 { "thread-pool-size", Element::integer, "0" },
432 { "packet-queue-size", Element::integer, "64" }
433};
434
437 { "lease-checks", Element::string, "warn" }
438};
439
441
445
447 size_t cnt = 0;
448
449 // Set global defaults first.
450 cnt = setDefaults(global, GLOBAL4_DEFAULTS);
451
452 // Now set option definition defaults for each specified option definition
453 ConstElementPtr option_defs = global->get("option-def");
454 if (option_defs) {
455 for (auto const& option_def : option_defs->listValue()) {
457 }
458 }
459
460 // Set the defaults for option data
461 ConstElementPtr options = global->get("option-data");
462 if (options) {
463 cnt += setListDefaults(options, OPTION4_DEFAULTS);
464 }
465
466 // Now set the defaults for defined subnets
467 ConstElementPtr subnets = global->get("subnet4");
468 if (subnets) {
469 cnt += setListDefaults(subnets, SUBNET4_DEFAULTS);
470 }
471
472 // Set the defaults for interfaces config
473 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
474 if (ifaces_cfg) {
475 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
476 cnt += setDefaults(mutable_cfg, IFACE4_DEFAULTS);
477 }
478
479 // Set defaults for shared networks
480 ConstElementPtr shared = global->get("shared-networks");
481 if (shared) {
482 for (auto const& net : shared->listValue()) {
483
485
486 ConstElementPtr subs = net->get("subnet4");
487 if (subs) {
489 }
490 }
491 }
492
493 // Set the defaults for dhcp-queue-control. If the element isn't
494 // there we'll add it.
495 ConstElementPtr queue_control = global->get("dhcp-queue-control");
496 ElementPtr mutable_cfg;
497 if (queue_control) {
498 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
499 } else {
500 mutable_cfg = Element::createMap();
501 global->set("dhcp-queue-control", mutable_cfg);
502 }
503
504 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL4_DEFAULTS);
505
506 // Set the defaults for multi-threading. If the element isn't there
507 // we'll add it.
508 ConstElementPtr multi_threading = global->get("multi-threading");
509 if (multi_threading) {
510 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
511 } else {
512 mutable_cfg = Element::createMap();
513 global->set("multi-threading", mutable_cfg);
514 }
515
516 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING4_DEFAULTS);
517
518 // Set the defaults for sanity-checks. If the element isn't
519 // there we'll add it.
520 ConstElementPtr sanity_checks = global->get("sanity-checks");
521 if (sanity_checks) {
522 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
523 } else {
524 mutable_cfg = Element::createMap();
525 global->set("sanity-checks", mutable_cfg);
526 }
527
528 cnt += setDefaults(mutable_cfg, SANITY_CHECKS4_DEFAULTS);
529
530 return (cnt);
531}
532
534 size_t cnt = 0;
535
536 // Now derive global parameters into subnets.
537 ConstElementPtr subnets = global->get("subnet4");
538 if (subnets) {
539 for (auto const& single_subnet : subnets->listValue()) {
540 cnt += SimpleParser::deriveParams(global, single_subnet,
542 }
543 }
544
545 // Deriving parameters for shared networks is a bit more involved.
546 // First, the shared-network level derives from global, and then
547 // subnets within derive from it.
548 ConstElementPtr shared = global->get("shared-networks");
549 if (shared) {
550 for (auto const& net : shared->listValue()) {
551 // First try to inherit the parameters from shared network,
552 // if defined there.
553 // Then try to inherit them from global.
554 cnt += SimpleParser::deriveParams(global, net,
556
557 // Now we need to go thrugh all the subnets in this net.
558 subnets = net->get("subnet4");
559 if (subnets) {
560 for (auto const& single_subnet : subnets->listValue()) {
561 cnt += SimpleParser::deriveParams(net, single_subnet,
563 }
564 }
565 }
566 }
567
568 return (cnt);
569}
570
571} // namespace dhcp
572} // 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 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 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.
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.