Kea 2.7.4
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 { "metadata", Element::map }
194};
195
202 { "space", Element::string, "dhcp4"}, // DHCP4_OPTION_SPACE
203 { "csv-format", Element::boolean, "true"},
204 { "always-send", Element::boolean, "false"},
205 { "never-send", Element::boolean, "false"}
206};
207
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 { "subnet", Element::string },
222 { "interface", Element::string },
223 { "id", Element::integer },
224 { "client-class", Element::string },
225 { "require-client-classes", Element::list },
226 { "reservations", Element::list },
227 { "reservations-global", Element::boolean },
228 { "reservations-in-subnet", Element::boolean },
229 { "reservations-out-of-pool", Element::boolean },
230 { "relay", Element::map },
231 { "match-client-id", Element::boolean },
232 { "authoritative", Element::boolean },
233 { "next-server", Element::string },
234 { "server-hostname", Element::string },
235 { "boot-file-name", Element::string },
236 { "4o6-interface", Element::string },
237 { "4o6-interface-id", Element::string },
238 { "4o6-subnet", Element::string },
239 { "user-context", Element::map },
240 { "comment", Element::string },
241 { "calculate-tee-times", Element::boolean },
242 { "t1-percent", Element::real },
243 { "t2-percent", Element::real },
244 { "ddns-send-updates", Element::boolean },
245 { "ddns-override-no-update", Element::boolean },
246 { "ddns-override-client-update", Element::boolean },
247 { "ddns-replace-client-name", Element::string },
248 { "ddns-generated-prefix", Element::string },
249 { "ddns-qualifying-suffix", Element::string },
250 { "hostname-char-set", Element::string },
251 { "hostname-char-replacement", Element::string },
252 { "store-extended-info", Element::boolean },
253 { "metadata", Element::map },
254 { "cache-threshold", Element::real },
255 { "cache-max-age", Element::integer },
256 { "ddns-update-on-renew", Element::boolean },
257 { "allocator", Element::string },
258 { "offer-lifetime", Element::integer },
259 { "ddns-ttl-percent", Element::real },
260 { "ddns-conflict-resolution-mode", Element::string },
261};
262
271 { "interface", Element::string, "" },
272 { "client-class", Element::string, "" },
273 { "4o6-interface", Element::string, "" },
274 { "4o6-interface-id", Element::string, "" },
275 { "4o6-subnet", Element::string, "" },
276};
277
285 { "4o6-interface", Element::string, "" },
286 { "4o6-interface-id", Element::string, "" },
287 { "4o6-subnet", Element::string, "" },
288};
289
292 { "client-class", Element::string, "" },
293 { "interface", Element::string, "" }
294};
295
306 "rebind-timer",
307 "relay",
308 "renew-timer",
309 "valid-lifetime",
310 "min-valid-lifetime",
311 "max-valid-lifetime",
312 "calculate-tee-times",
313 "t1-percent",
314 "t2-percent",
315 "store-extended-info",
316 "cache-threshold",
317 "cache-max-age",
318 "allocator",
319 "offer-lifetime",
320};
321
328 { "pool", Element::string },
329 { "pool-id", Element::integer },
330 { "option-data", Element::list },
331 { "client-class", Element::string },
332 { "require-client-classes", Element::list },
333 { "user-context", Element::map },
334 { "comment", Element::string },
335 { "metadata", Element::map }
336};
337
344 { "name", Element::string },
345 { "subnet4", Element::list },
346 { "interface", Element::string },
347 { "renew-timer", Element::integer },
348 { "rebind-timer", Element::integer },
349 { "option-data", Element::list },
350 { "match-client-id", Element::boolean },
351 { "authoritative", Element::boolean },
352 { "next-server", Element::string },
353 { "server-hostname", Element::string },
354 { "boot-file-name", Element::string },
355 { "relay", Element::map },
356 { "reservations-global", Element::boolean },
357 { "reservations-in-subnet", Element::boolean },
358 { "reservations-out-of-pool", Element::boolean },
359 { "client-class", Element::string },
360 { "require-client-classes", Element::list },
361 { "valid-lifetime", Element::integer },
362 { "min-valid-lifetime", Element::integer },
363 { "max-valid-lifetime", Element::integer },
364 { "user-context", Element::map },
365 { "comment", Element::string },
366 { "calculate-tee-times", Element::boolean },
367 { "t1-percent", Element::real },
368 { "t2-percent", Element::real },
369 { "ddns-send-updates", Element::boolean },
370 { "ddns-override-no-update", Element::boolean },
371 { "ddns-override-client-update", Element::boolean },
372 { "ddns-replace-client-name", Element::string },
373 { "ddns-generated-prefix", Element::string },
374 { "ddns-qualifying-suffix", Element::string },
375 { "hostname-char-set", Element::string },
376 { "hostname-char-replacement", Element::string },
377 { "store-extended-info", Element::boolean },
378 { "metadata", Element::map },
379 { "cache-threshold", Element::real },
380 { "cache-max-age", Element::integer },
381 { "ddns-update-on-renew", Element::boolean },
382 { "allocator", Element::string },
383 { "offer-lifetime", Element::integer },
384 { "ddns-ttl-percent", Element::real },
385 { "ddns-conflict-resolution-mode", Element::string },
386};
387
390 { "re-detect", Element::boolean, "true" }
391};
392
395 { "enable-queue", Element::boolean, "false"},
396 { "queue-type", Element::string, "kea-ring4"},
397 { "capacity", Element::integer, "64"}
398};
399
402 { "enable-multi-threading", Element::boolean, "true" },
403 { "thread-pool-size", Element::integer, "0" },
404 { "packet-queue-size", Element::integer, "64" }
405};
406
409 { "lease-checks", Element::string, "warn" }
410};
411
413
417
419 size_t cnt = 0;
420
421 // Set global defaults first.
422 cnt = setDefaults(global, GLOBAL4_DEFAULTS);
423
424 // Now set option definition defaults for each specified option definition
425 ConstElementPtr option_defs = global->get("option-def");
426 if (option_defs) {
427 for (auto const& option_def : option_defs->listValue()) {
429 }
430 }
431
432 // Set the defaults for option data
433 ConstElementPtr options = global->get("option-data");
434 if (options) {
435 cnt += setListDefaults(options, OPTION4_DEFAULTS);
436 }
437
438 // Now set the defaults for defined subnets
439 ConstElementPtr subnets = global->get("subnet4");
440 if (subnets) {
441 cnt += setListDefaults(subnets, SUBNET4_DEFAULTS);
442 }
443
444 // Set the defaults for interfaces config
445 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
446 if (ifaces_cfg) {
447 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
448 cnt += setDefaults(mutable_cfg, IFACE4_DEFAULTS);
449 }
450
451 // Set defaults for shared networks
452 ConstElementPtr shared = global->get("shared-networks");
453 if (shared) {
454 for (auto const& net : shared->listValue()) {
455
457
458 ConstElementPtr subs = net->get("subnet4");
459 if (subs) {
461 }
462 }
463 }
464
465 // Set the defaults for dhcp-queue-control. If the element isn't
466 // there we'll add it.
467 ConstElementPtr queue_control = global->get("dhcp-queue-control");
468 ElementPtr mutable_cfg;
469 if (queue_control) {
470 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
471 } else {
472 mutable_cfg = Element::createMap();
473 global->set("dhcp-queue-control", mutable_cfg);
474 }
475
476 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL4_DEFAULTS);
477
478 // Set the defaults for multi-threading. If the element isn't there
479 // we'll add it.
480 ConstElementPtr multi_threading = global->get("multi-threading");
481 if (multi_threading) {
482 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
483 } else {
484 mutable_cfg = Element::createMap();
485 global->set("multi-threading", mutable_cfg);
486 }
487
488 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING4_DEFAULTS);
489
490 // Set the defaults for sanity-checks. If the element isn't
491 // there we'll add it.
492 ConstElementPtr sanity_checks = global->get("sanity-checks");
493 if (sanity_checks) {
494 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
495 } else {
496 mutable_cfg = Element::createMap();
497 global->set("sanity-checks", mutable_cfg);
498 }
499
500 cnt += setDefaults(mutable_cfg, SANITY_CHECKS4_DEFAULTS);
501
502 return (cnt);
503}
504
506 size_t cnt = 0;
507
508 // Now derive global parameters into subnets.
509 ConstElementPtr subnets = global->get("subnet4");
510 if (subnets) {
511 for (auto const& single_subnet : subnets->listValue()) {
512 cnt += SimpleParser::deriveParams(global, single_subnet,
514 }
515 }
516
517 // Deriving parameters for shared networks is a bit more involved.
518 // First, the shared-network level derives from global, and then
519 // subnets within derive from it.
520 ConstElementPtr shared = global->get("shared-networks");
521 if (shared) {
522 for (auto const& net : shared->listValue()) {
523 // First try to inherit the parameters from shared network,
524 // if defined there.
525 // Then try to inherit them from global.
526 cnt += SimpleParser::deriveParams(global, net,
528
529 // Now we need to go thrugh all the subnets in this net.
530 subnets = net->get("subnet4");
531 if (subnets) {
532 for (auto const& single_subnet : subnets->listValue()) {
533 cnt += SimpleParser::deriveParams(net, single_subnet,
535 }
536 }
537 }
538 }
539
540 return (cnt);
541}
542
543} // namespace dhcp
544} // 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.