Kea 2.7.6
simple_parser4.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
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 { "metadata", Element::map }
345};
346
353 { "name", Element::string },
354 { "subnet4", Element::list },
355 { "interface", Element::string },
356 { "renew-timer", Element::integer },
357 { "rebind-timer", Element::integer },
358 { "option-data", Element::list },
359 { "match-client-id", Element::boolean },
360 { "authoritative", Element::boolean },
361 { "next-server", Element::string },
362 { "server-hostname", Element::string },
363 { "boot-file-name", Element::string },
364 { "relay", Element::map },
365 { "reservations-global", Element::boolean },
366 { "reservations-in-subnet", Element::boolean },
367 { "reservations-out-of-pool", Element::boolean },
368 { "client-class", Element::string },
369 { "client-classes", Element::list },
370 { "require-client-classes", Element::list },
371 { "evaluate-additional-classes", Element::list },
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 { "offer-lifetime", Element::integer },
395 { "ddns-ttl-percent", Element::real },
396 { "ddns-conflict-resolution-mode", Element::string },
397 { "ddns-ttl", Element::integer },
398 { "ddns-ttl-min", Element::integer },
399 { "ddns-ttl-max", Element::integer },
400};
401
404 { "re-detect", Element::boolean, "true" }
405};
406
409 { "enable-queue", Element::boolean, "false"},
410 { "queue-type", Element::string, "kea-ring4"},
411 { "capacity", Element::integer, "64"}
412};
413
416 { "enable-multi-threading", Element::boolean, "true" },
417 { "thread-pool-size", Element::integer, "0" },
418 { "packet-queue-size", Element::integer, "64" }
419};
420
423 { "lease-checks", Element::string, "warn" }
424};
425
427
431
433 size_t cnt = 0;
434
435 // Set global defaults first.
436 cnt = setDefaults(global, GLOBAL4_DEFAULTS);
437
438 // Now set option definition defaults for each specified option definition
439 ConstElementPtr option_defs = global->get("option-def");
440 if (option_defs) {
441 for (auto const& option_def : option_defs->listValue()) {
443 }
444 }
445
446 // Set the defaults for option data
447 ConstElementPtr options = global->get("option-data");
448 if (options) {
449 cnt += setListDefaults(options, OPTION4_DEFAULTS);
450 }
451
452 // Now set the defaults for defined subnets
453 ConstElementPtr subnets = global->get("subnet4");
454 if (subnets) {
455 cnt += setListDefaults(subnets, SUBNET4_DEFAULTS);
456 }
457
458 // Set the defaults for interfaces config
459 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
460 if (ifaces_cfg) {
461 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
462 cnt += setDefaults(mutable_cfg, IFACE4_DEFAULTS);
463 }
464
465 // Set defaults for shared networks
466 ConstElementPtr shared = global->get("shared-networks");
467 if (shared) {
468 for (auto const& net : shared->listValue()) {
469
471
472 ConstElementPtr subs = net->get("subnet4");
473 if (subs) {
475 }
476 }
477 }
478
479 // Set the defaults for dhcp-queue-control. If the element isn't
480 // there we'll add it.
481 ConstElementPtr queue_control = global->get("dhcp-queue-control");
482 ElementPtr mutable_cfg;
483 if (queue_control) {
484 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
485 } else {
486 mutable_cfg = Element::createMap();
487 global->set("dhcp-queue-control", mutable_cfg);
488 }
489
490 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL4_DEFAULTS);
491
492 // Set the defaults for multi-threading. If the element isn't there
493 // we'll add it.
494 ConstElementPtr multi_threading = global->get("multi-threading");
495 if (multi_threading) {
496 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
497 } else {
498 mutable_cfg = Element::createMap();
499 global->set("multi-threading", mutable_cfg);
500 }
501
502 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING4_DEFAULTS);
503
504 // Set the defaults for sanity-checks. If the element isn't
505 // there we'll add it.
506 ConstElementPtr sanity_checks = global->get("sanity-checks");
507 if (sanity_checks) {
508 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
509 } else {
510 mutable_cfg = Element::createMap();
511 global->set("sanity-checks", mutable_cfg);
512 }
513
514 cnt += setDefaults(mutable_cfg, SANITY_CHECKS4_DEFAULTS);
515
516 return (cnt);
517}
518
520 size_t cnt = 0;
521
522 // Now derive global parameters into subnets.
523 ConstElementPtr subnets = global->get("subnet4");
524 if (subnets) {
525 for (auto const& single_subnet : subnets->listValue()) {
526 cnt += SimpleParser::deriveParams(global, single_subnet,
528 }
529 }
530
531 // Deriving parameters for shared networks is a bit more involved.
532 // First, the shared-network level derives from global, and then
533 // subnets within derive from it.
534 ConstElementPtr shared = global->get("shared-networks");
535 if (shared) {
536 for (auto const& net : shared->listValue()) {
537 // First try to inherit the parameters from shared network,
538 // if defined there.
539 // Then try to inherit them from global.
540 cnt += SimpleParser::deriveParams(global, net,
542
543 // Now we need to go thrugh all the subnets in this net.
544 subnets = net->get("subnet4");
545 if (subnets) {
546 for (auto const& single_subnet : subnets->listValue()) {
547 cnt += SimpleParser::deriveParams(net, single_subnet,
549 }
550 }
551 }
552 }
553
554 return (cnt);
555}
556
557} // namespace dhcp
558} // 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.