Kea 2.7.5
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};
105
112 { "valid-lifetime", Element::integer, "7200" },
113 { "decline-probation-period", Element::integer, "86400" }, // 24h
114 { "dhcp4o6-port", Element::integer, "0" },
115 { "echo-client-id", Element::boolean, "true" },
116 { "match-client-id", Element::boolean, "true" },
117 { "authoritative", Element::boolean, "false" },
118 { "next-server", Element::string, "0.0.0.0" },
119 { "server-hostname", Element::string, "" },
120 { "boot-file-name", Element::string, "" },
121 { "server-tag", Element::string, "" },
122 { "reservations-global", Element::boolean, "false" },
123 { "reservations-in-subnet", Element::boolean, "true" },
124 { "reservations-out-of-pool", Element::boolean, "false" },
125 { "calculate-tee-times", Element::boolean, "false" },
126 { "t1-percent", Element::real, ".50" },
127 { "t2-percent", Element::real, ".875" },
128 { "ddns-send-updates", Element::boolean, "true" },
129 { "ddns-override-no-update", Element::boolean, "false" },
130 { "ddns-override-client-update", Element::boolean, "false" },
131 { "ddns-replace-client-name", Element::string, "never" },
132 { "ddns-generated-prefix", Element::string, "myhost" },
133 { "ddns-qualifying-suffix", Element::string, "" },
134 { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
135 { "hostname-char-replacement", Element::string, "" },
136 { "store-extended-info", Element::boolean, "false" },
137 { "statistic-default-sample-count", Element::integer, "20" },
138 { "statistic-default-sample-age", Element::integer, "0" },
139 { "early-global-reservations-lookup", Element::boolean, "false" },
140 { "ip-reservations-unique", Element::boolean, "true" },
141 { "reservations-lookup-first", Element::boolean, "false" },
142 { "ddns-update-on-renew", Element::boolean, "false" },
143 { "parked-packet-limit", Element::integer, "256" },
144 { "allocator", Element::string, "iterative" },
145 { "ddns-conflict-resolution-mode", Element::string, "check-with-dhcid" },
146 { "stash-agent-options", Element::boolean, "false" },
147};
148
155 { "name", Element::string },
156 { "code", Element::integer },
157 { "type", Element::string },
158 { "record-types", Element::string },
159 { "space", Element::string },
160 { "encapsulate", Element::string },
161 { "array", Element::boolean, },
162 { "user-context", Element::map },
163 { "comment", Element::string },
164 { "metadata", Element::map }
165};
166
172 { "record-types", Element::string, ""},
173 { "space", Element::string, "dhcp4"}, // DHCP4_OPTION_SPACE
174 { "array", Element::boolean, "false"},
175 { "encapsulate", Element::string, "" }
176};
177
184 { "name", Element::string },
185 { "data", Element::string },
186 { "code", Element::integer },
187 { "space", Element::string },
188 { "csv-format", Element::boolean },
189 { "always-send", Element::boolean },
190 { "never-send", Element::boolean },
191 { "user-context", Element::map },
192 { "comment", Element::string },
193 { "client-classes", Element::list },
194 { "metadata", Element::map }
195};
196
203 { "space", Element::string, "dhcp4"}, // DHCP4_OPTION_SPACE
204 { "csv-format", Element::boolean, "true"},
205 { "always-send", Element::boolean, "false"},
206 { "never-send", Element::boolean, "false"}
207};
208
215 { "valid-lifetime", Element::integer },
216 { "min-valid-lifetime", Element::integer },
217 { "max-valid-lifetime", Element::integer },
218 { "renew-timer", Element::integer },
219 { "rebind-timer", Element::integer },
220 { "option-data", Element::list },
221 { "pools", Element::list },
222 { "subnet", Element::string },
223 { "interface", Element::string },
224 { "id", Element::integer },
225 { "client-class", Element::string },
226 { "require-client-classes", Element::list },
227 { "evaluate-additional-classes", Element::list },
228 { "reservations", Element::list },
229 { "reservations-global", Element::boolean },
230 { "reservations-in-subnet", Element::boolean },
231 { "reservations-out-of-pool", Element::boolean },
232 { "relay", Element::map },
233 { "match-client-id", Element::boolean },
234 { "authoritative", Element::boolean },
235 { "next-server", Element::string },
236 { "server-hostname", Element::string },
237 { "boot-file-name", Element::string },
238 { "4o6-interface", Element::string },
239 { "4o6-interface-id", Element::string },
240 { "4o6-subnet", Element::string },
241 { "user-context", Element::map },
242 { "comment", Element::string },
243 { "calculate-tee-times", Element::boolean },
244 { "t1-percent", Element::real },
245 { "t2-percent", Element::real },
246 { "ddns-send-updates", Element::boolean },
247 { "ddns-override-no-update", Element::boolean },
248 { "ddns-override-client-update", Element::boolean },
249 { "ddns-replace-client-name", Element::string },
250 { "ddns-generated-prefix", Element::string },
251 { "ddns-qualifying-suffix", Element::string },
252 { "hostname-char-set", Element::string },
253 { "hostname-char-replacement", Element::string },
254 { "store-extended-info", Element::boolean },
255 { "metadata", Element::map },
256 { "cache-threshold", Element::real },
257 { "cache-max-age", Element::integer },
258 { "ddns-update-on-renew", Element::boolean },
259 { "allocator", Element::string },
260 { "offer-lifetime", Element::integer },
261 { "ddns-ttl-percent", Element::real },
262 { "ddns-conflict-resolution-mode", Element::string },
263};
264
273 { "interface", Element::string, "" },
274 { "client-class", Element::string, "" },
275 { "4o6-interface", Element::string, "" },
276 { "4o6-interface-id", Element::string, "" },
277 { "4o6-subnet", Element::string, "" },
278};
279
287 { "4o6-interface", Element::string, "" },
288 { "4o6-interface-id", Element::string, "" },
289 { "4o6-subnet", Element::string, "" },
290};
291
294 { "client-class", Element::string, "" },
295 { "interface", Element::string, "" }
296};
297
308 "rebind-timer",
309 "relay",
310 "renew-timer",
311 "valid-lifetime",
312 "min-valid-lifetime",
313 "max-valid-lifetime",
314 "calculate-tee-times",
315 "t1-percent",
316 "t2-percent",
317 "store-extended-info",
318 "cache-threshold",
319 "cache-max-age",
320 "allocator",
321 "offer-lifetime",
322};
323
330 { "pool", Element::string },
331 { "pool-id", Element::integer },
332 { "option-data", Element::list },
333 { "client-class", Element::string },
334 { "require-client-classes", Element::list },
335 { "evaluate-additional-classes", Element::list },
336 { "user-context", Element::map },
337 { "comment", Element::string },
338 { "metadata", Element::map }
339};
340
347 { "name", Element::string },
348 { "subnet4", Element::list },
349 { "interface", Element::string },
350 { "renew-timer", Element::integer },
351 { "rebind-timer", Element::integer },
352 { "option-data", Element::list },
353 { "match-client-id", Element::boolean },
354 { "authoritative", Element::boolean },
355 { "next-server", Element::string },
356 { "server-hostname", Element::string },
357 { "boot-file-name", Element::string },
358 { "relay", Element::map },
359 { "reservations-global", Element::boolean },
360 { "reservations-in-subnet", Element::boolean },
361 { "reservations-out-of-pool", Element::boolean },
362 { "client-class", Element::string },
363 { "require-client-classes", Element::list },
364 { "evaluate-additional-classes", Element::list },
365 { "valid-lifetime", Element::integer },
366 { "min-valid-lifetime", Element::integer },
367 { "max-valid-lifetime", Element::integer },
368 { "user-context", Element::map },
369 { "comment", Element::string },
370 { "calculate-tee-times", Element::boolean },
371 { "t1-percent", Element::real },
372 { "t2-percent", Element::real },
373 { "ddns-send-updates", Element::boolean },
374 { "ddns-override-no-update", Element::boolean },
375 { "ddns-override-client-update", Element::boolean },
376 { "ddns-replace-client-name", Element::string },
377 { "ddns-generated-prefix", Element::string },
378 { "ddns-qualifying-suffix", Element::string },
379 { "hostname-char-set", Element::string },
380 { "hostname-char-replacement", Element::string },
381 { "store-extended-info", Element::boolean },
382 { "metadata", Element::map },
383 { "cache-threshold", Element::real },
384 { "cache-max-age", Element::integer },
385 { "ddns-update-on-renew", Element::boolean },
386 { "allocator", Element::string },
387 { "offer-lifetime", Element::integer },
388 { "ddns-ttl-percent", Element::real },
389 { "ddns-conflict-resolution-mode", Element::string },
390};
391
394 { "re-detect", Element::boolean, "true" }
395};
396
399 { "enable-queue", Element::boolean, "false"},
400 { "queue-type", Element::string, "kea-ring4"},
401 { "capacity", Element::integer, "64"}
402};
403
406 { "enable-multi-threading", Element::boolean, "true" },
407 { "thread-pool-size", Element::integer, "0" },
408 { "packet-queue-size", Element::integer, "64" }
409};
410
413 { "lease-checks", Element::string, "warn" }
414};
415
417
421
423 size_t cnt = 0;
424
425 // Set global defaults first.
426 cnt = setDefaults(global, GLOBAL4_DEFAULTS);
427
428 // Now set option definition defaults for each specified option definition
429 ConstElementPtr option_defs = global->get("option-def");
430 if (option_defs) {
431 for (auto const& option_def : option_defs->listValue()) {
433 }
434 }
435
436 // Set the defaults for option data
437 ConstElementPtr options = global->get("option-data");
438 if (options) {
439 cnt += setListDefaults(options, OPTION4_DEFAULTS);
440 }
441
442 // Now set the defaults for defined subnets
443 ConstElementPtr subnets = global->get("subnet4");
444 if (subnets) {
445 cnt += setListDefaults(subnets, SUBNET4_DEFAULTS);
446 }
447
448 // Set the defaults for interfaces config
449 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
450 if (ifaces_cfg) {
451 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
452 cnt += setDefaults(mutable_cfg, IFACE4_DEFAULTS);
453 }
454
455 // Set defaults for shared networks
456 ConstElementPtr shared = global->get("shared-networks");
457 if (shared) {
458 for (auto const& net : shared->listValue()) {
459
461
462 ConstElementPtr subs = net->get("subnet4");
463 if (subs) {
465 }
466 }
467 }
468
469 // Set the defaults for dhcp-queue-control. If the element isn't
470 // there we'll add it.
471 ConstElementPtr queue_control = global->get("dhcp-queue-control");
472 ElementPtr mutable_cfg;
473 if (queue_control) {
474 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
475 } else {
476 mutable_cfg = Element::createMap();
477 global->set("dhcp-queue-control", mutable_cfg);
478 }
479
480 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL4_DEFAULTS);
481
482 // Set the defaults for multi-threading. If the element isn't there
483 // we'll add it.
484 ConstElementPtr multi_threading = global->get("multi-threading");
485 if (multi_threading) {
486 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
487 } else {
488 mutable_cfg = Element::createMap();
489 global->set("multi-threading", mutable_cfg);
490 }
491
492 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING4_DEFAULTS);
493
494 // Set the defaults for sanity-checks. If the element isn't
495 // there we'll add it.
496 ConstElementPtr sanity_checks = global->get("sanity-checks");
497 if (sanity_checks) {
498 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
499 } else {
500 mutable_cfg = Element::createMap();
501 global->set("sanity-checks", mutable_cfg);
502 }
503
504 cnt += setDefaults(mutable_cfg, SANITY_CHECKS4_DEFAULTS);
505
506 return (cnt);
507}
508
510 size_t cnt = 0;
511
512 // Now derive global parameters into subnets.
513 ConstElementPtr subnets = global->get("subnet4");
514 if (subnets) {
515 for (auto const& single_subnet : subnets->listValue()) {
516 cnt += SimpleParser::deriveParams(global, single_subnet,
518 }
519 }
520
521 // Deriving parameters for shared networks is a bit more involved.
522 // First, the shared-network level derives from global, and then
523 // subnets within derive from it.
524 ConstElementPtr shared = global->get("shared-networks");
525 if (shared) {
526 for (auto const& net : shared->listValue()) {
527 // First try to inherit the parameters from shared network,
528 // if defined there.
529 // Then try to inherit them from global.
530 cnt += SimpleParser::deriveParams(global, net,
532
533 // Now we need to go thrugh all the subnets in this net.
534 subnets = net->get("subnet4");
535 if (subnets) {
536 for (auto const& single_subnet : subnets->listValue()) {
537 cnt += SimpleParser::deriveParams(net, single_subnet,
539 }
540 }
541 }
542 }
543
544 return (cnt);
545}
546
547} // namespace dhcp
548} // 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.