Kea 2.0.0
simple_parser6.cc
Go to the documentation of this file.
1// Copyright (C) 2016-2021 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
12#include <boost/foreach.hpp>
13
14using namespace isc::data;
15
16namespace isc {
17namespace dhcp {
32
39 { "data-directory", Element::string },
40 { "preferred-lifetime", Element::integer },
41 { "min-preferred-lifetime", Element::integer },
42 { "max-preferred-lifetime", Element::integer },
43 { "valid-lifetime", Element::integer },
44 { "min-valid-lifetime", Element::integer },
45 { "max-valid-lifetime", Element::integer },
46 { "renew-timer", Element::integer },
47 { "rebind-timer", Element::integer },
48 { "decline-probation-period", Element::integer },
49 { "subnet6", Element::list },
50 { "shared-networks", Element::list },
51 { "interfaces-config", Element::map },
52 { "lease-database", Element::map },
53 { "hosts-database", Element::map },
54 { "hosts-databases", Element::list },
55 { "mac-sources", Element::list },
56 { "relay-supplied-options", Element::list },
57 { "host-reservation-identifiers", Element::list },
58 { "client-classes", Element::list },
59 { "option-def", Element::list },
60 { "option-data", Element::list },
61 { "hooks-libraries", Element::list },
62 { "expired-leases-processing", Element::map },
63 { "server-id", Element::map },
64 { "dhcp4o6-port", Element::integer },
65 { "control-socket", Element::map },
66 { "dhcp-queue-control", Element::map },
67 { "dhcp-ddns", Element::map },
68 { "user-context", Element::map },
69 { "comment", Element::string },
70 { "sanity-checks", Element::map },
71 { "reservations", Element::list },
72 { "config-control", Element::map },
73 { "server-tag", Element::string },
74 { "reservation-mode", Element::string },
75 { "reservations-global", Element::boolean },
76 { "reservations-in-subnet", Element::boolean },
77 { "reservations-out-of-pool", Element::boolean },
78 { "calculate-tee-times", Element::boolean },
79 { "t1-percent", Element::real },
80 { "t2-percent", Element::real },
81 { "loggers", Element::list },
82 { "hostname-char-set", Element::string },
83 { "hostname-char-replacement", Element::string },
84 { "ddns-send-updates", Element::boolean },
85 { "ddns-override-no-update", Element::boolean },
86 { "ddns-override-client-update", Element::boolean },
87 { "ddns-replace-client-name", Element::string },
88 { "ddns-generated-prefix", Element::string },
89 { "ddns-qualifying-suffix", Element::string },
90 { "store-extended-info", Element::boolean },
91 { "statistic-default-sample-count", Element::integer },
92 { "statistic-default-sample-age", Element::integer },
93 { "multi-threading", Element::map },
94 { "cache-threshold", Element::real },
95 { "cache-max-age", Element::integer },
96 { "ip-reservations-unique", Element::boolean },
97 { "ddns-update-on-renew", Element::boolean },
98 { "ddns-use-conflict-resolution", Element::boolean },
99 { "compatibility", Element::map },
100 { "parked-packet-limit", Element::integer },
101};
102
109 { "preferred-lifetime", Element::integer, "3600" },
110 { "valid-lifetime", Element::integer, "7200" },
111 { "decline-probation-period", Element::integer, "86400" }, // 24h
112 { "dhcp4o6-port", Element::integer, "0" },
113 { "server-tag", Element::string, "" },
114 { "reservations-global", Element::boolean, "false" },
115 { "reservations-in-subnet", Element::boolean, "true" },
116 { "reservations-out-of-pool", Element::boolean, "false" },
117 { "calculate-tee-times", Element::boolean, "true" },
118 { "t1-percent", Element::real, ".50" },
119 { "t2-percent", Element::real, ".80" },
120 { "ddns-send-updates", Element::boolean, "true" },
121 { "ddns-override-no-update", Element::boolean, "false" },
122 { "ddns-override-client-update", Element::boolean, "false" },
123 { "ddns-replace-client-name", Element::string, "never" },
124 { "ddns-generated-prefix", Element::string, "myhost" },
125 { "ddns-qualifying-suffix", Element::string, "" },
126 { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
127 { "hostname-char-replacement", Element::string, "" },
128 { "store-extended-info", Element::boolean, "false" },
129 { "statistic-default-sample-count", Element::integer, "20" },
130 { "statistic-default-sample-age", Element::integer, "0" },
131 { "ip-reservations-unique", Element::boolean, "true" },
132 { "ddns-update-on-renew", Element::boolean, "false" },
133 { "ddns-use-conflict-resolution", Element::boolean, "true" },
134 { "parked-packet-limit", Element::integer, "256" }
135};
136
143 { "name", Element::string },
144 { "code", Element::integer },
145 { "type", Element::string },
146 { "record-types", Element::string },
147 { "space", Element::string },
148 { "encapsulate", Element::string },
149 { "array", Element::boolean, },
150 { "user-context", Element::map },
151 { "comment", Element::string },
152 { "metadata", Element::map }
153};
154
160 { "record-types", Element::string, ""},
161 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
162 { "array", Element::boolean, "false"},
163 { "encapsulate", Element::string, "" }
164};
165
172 { "name", Element::string },
173 { "data", Element::string },
174 { "code", Element::integer },
175 { "space", Element::string },
176 { "csv-format", Element::boolean },
177 { "always-send", Element::boolean },
178 { "user-context", Element::map },
179 { "comment", Element::string },
180 { "metadata", Element::map }
181};
182
189 { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
190 { "csv-format", Element::boolean, "true"},
191 { "always-send", Element::boolean, "false"}
192};
193
200 { "preferred-lifetime", Element::integer },
201 { "min-preferred-lifetime", Element::integer },
202 { "max-preferred-lifetime", Element::integer },
203 { "valid-lifetime", Element::integer },
204 { "min-valid-lifetime", Element::integer },
205 { "max-valid-lifetime", Element::integer },
206 { "renew-timer", Element::integer },
207 { "rebind-timer", Element::integer },
208 { "option-data", Element::list },
209 { "pools", Element::list },
210 { "pd-pools", Element::list },
211 { "subnet", Element::string },
212 { "interface", Element::string },
213 { "interface-id", Element::string },
214 { "id", Element::integer },
215 { "rapid-commit", Element::boolean },
216 { "client-class", Element::string },
217 { "require-client-classes", Element::list },
218 { "reservations", Element::list },
219 { "reservation-mode", Element::string },
220 { "reservations-global", Element::boolean },
221 { "reservations-in-subnet", Element::boolean },
222 { "reservations-out-of-pool", Element::boolean },
223 { "relay", Element::map },
224 { "user-context", Element::map },
225 { "comment", Element::string },
226 { "calculate-tee-times", Element::boolean },
227 { "t1-percent", Element::real },
228 { "t2-percent", Element::real },
229 { "ddns-send-updates", Element::boolean },
230 { "ddns-override-no-update", Element::boolean },
231 { "ddns-override-client-update", Element::boolean },
232 { "ddns-replace-client-name", Element::string },
233 { "ddns-generated-prefix", Element::string },
234 { "ddns-qualifying-suffix", Element::string },
235 { "hostname-char-set", Element::string },
236 { "hostname-char-replacement", Element::string },
237 { "store-extended-info", Element::boolean },
238 { "metadata", Element::map },
239 { "cache-threshold", Element::real },
240 { "cache-max-age", Element::integer },
241 { "ddns-update-on-renew", Element::boolean },
242 { "ddns-use-conflict-resolution", Element::boolean }
243};
244
252 { "id", Element::integer, "0" }, // 0 means autogenerate
253 { "interface", Element::string, "" },
254 { "client-class", Element::string, "" },
255 { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
256 { "interface-id", Element::string, "" }
257};
258
265 { "client-class", Element::string, "" },
266 { "interface", Element::string, "" },
267 { "interface-id", Element::string, "" },
268 { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
269};
270
281 "preferred-lifetime",
282 "min-preferred-lifetime",
283 "max-preferred-lifetime",
284 "rebind-timer",
285 "relay",
286 "renew-timer",
287 "valid-lifetime",
288 "min-valid-lifetime",
289 "max-valid-lifetime",
290 "calculate-tee-times",
291 "t1-percent",
292 "t2-percent",
293 "store-extended-info",
294 "cache-threshold",
295 "cache-max-age"
296};
297
304 { "pool", Element::string },
305 { "option-data", Element::list },
306 { "client-class", Element::string },
307 { "require-client-classes", Element::list },
308 { "user-context", Element::map },
309 { "comment", Element::string },
310 { "metadata", Element::map }
311};
312
319 { "prefix", Element::string },
320 { "prefix-len", Element::integer },
321 { "delegated-len", Element::integer },
322 { "option-data", Element::list },
323 { "client-class", Element::string },
324 { "require-client-classes", Element::list },
325 { "excluded-prefix", Element::string },
326 { "excluded-prefix-len", Element::integer },
327 { "user-context", Element::map },
328 { "comment", Element::string },
329 { "metadata", Element::map }
330};
331
338 { "name", Element::string },
339 { "subnet6", Element::list },
340 { "interface", Element::string },
341 { "interface-id", Element::string },
342 { "renew-timer", Element::integer },
343 { "rebind-timer", Element::integer },
344 { "option-data", Element::list },
345 { "relay", Element::map },
346 { "reservation-mode", Element::string },
347 { "reservations-global", Element::boolean },
348 { "reservations-in-subnet", Element::boolean },
349 { "reservations-out-of-pool", Element::boolean },
350 { "client-class", Element::string },
351 { "require-client-classes", Element::list },
352 { "preferred-lifetime", Element::integer },
353 { "min-preferred-lifetime", Element::integer },
354 { "max-preferred-lifetime", Element::integer },
355 { "rapid-commit", Element::boolean },
356 { "valid-lifetime", Element::integer },
357 { "min-valid-lifetime", Element::integer },
358 { "max-valid-lifetime", Element::integer },
359 { "user-context", Element::map },
360 { "comment", Element::string },
361 { "calculate-tee-times", Element::boolean },
362 { "t1-percent", Element::real },
363 { "t2-percent", Element::real },
364 { "ddns-send-updates", Element::boolean },
365 { "ddns-override-no-update", Element::boolean },
366 { "ddns-override-client-update", Element::boolean },
367 { "ddns-replace-client-name", Element::string },
368 { "ddns-generated-prefix", Element::string },
369 { "ddns-qualifying-suffix", Element::string },
370 { "hostname-char-set", Element::string },
371 { "hostname-char-replacement", Element::string },
372 { "store-extended-info", Element::boolean },
373 { "metadata", Element::map },
374 { "cache-threshold", Element::real },
375 { "cache-max-age", Element::integer },
376 { "ddns-update-on-renew", Element::boolean },
377 { "ddns-use-conflict-resolution", Element::boolean }
378};
379
382 { "id", Element::integer, "0" } // 0 means autogenerate
383};
384
387 { "re-detect", Element::boolean, "true" }
388};
389
392 { "enable-queue", Element::boolean, "false"},
393 { "queue-type", Element::string, "kea-ring6"},
394 { "capacity", Element::integer, "64"}
395};
396
399 { "enable-multi-threading", Element::boolean, "false" },
400 { "thread-pool-size", Element::integer, "0" },
401 { "packet-queue-size", Element::integer, "64" }
402};
403
406 { "lease-checks", Element::string, "warn" }
407};
408
410
414
416 size_t cnt = 0;
417
418 // Set global defaults first.
419 cnt = setDefaults(global, GLOBAL6_DEFAULTS);
420
421 // Now set the defaults for each specified option definition
422 ConstElementPtr option_defs = global->get("option-def");
423 if (option_defs) {
424 BOOST_FOREACH(ElementPtr option_def, option_defs->listValue()) {
425 cnt += SimpleParser::setDefaults(option_def, OPTION6_DEF_DEFAULTS);
426 }
427 }
428
429 // Set the defaults for option data
430 ConstElementPtr options = global->get("option-data");
431 if (options) {
432 BOOST_FOREACH(ElementPtr single_option, options->listValue()) {
433 cnt += SimpleParser::setDefaults(single_option, OPTION6_DEFAULTS);
434 }
435 }
436
437 // Now set the defaults for defined subnets
438 ConstElementPtr subnets = global->get("subnet6");
439 if (subnets) {
440 cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
441 }
442
443 // Set the defaults for interfaces config
444 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
445 if (ifaces_cfg) {
446 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
447 cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
448 }
449
450 // Set defaults for shared networks
451 ConstElementPtr shared = global->get("shared-networks");
452 if (shared) {
453 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
454
456
457 ConstElementPtr subs = net->get("subnet6");
458 if (subs) {
460 }
461 }
462 }
463
464 // Set the defaults for dhcp-queue-control. If the element isn't there
465 // we'll add it.
466 ConstElementPtr queue_control = global->get("dhcp-queue-control");
467 ElementPtr mutable_cfg;
468 if (queue_control) {
469 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
470 } else {
471 mutable_cfg = Element::createMap();
472 global->set("dhcp-queue-control", mutable_cfg);
473 }
474
475 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
476
477 // Set the defaults for multi-threading. If the element isn't there
478 // we'll add it.
479 ConstElementPtr multi_threading = global->get("multi-threading");
480 if (multi_threading) {
481 mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
482 } else {
483 mutable_cfg = Element::createMap();
484 global->set("multi-threading", mutable_cfg);
485 }
486
487 cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS);
488
489 // Set the defaults for sanity-checks. If the element isn't
490 // there we'll add it.
491 ConstElementPtr sanity_checks = global->get("sanity-checks");
492 if (sanity_checks) {
493 mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
494 } else {
495 mutable_cfg = Element::createMap();
496 global->set("sanity-checks", mutable_cfg);
497 }
498
499 cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
500
501 return (cnt);
502}
503
505 size_t cnt = 0;
506
507 // Now derive global parameters into subnets.
508 ConstElementPtr subnets = global->get("subnet6");
509 if (subnets) {
510 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
511 cnt += SimpleParser::deriveParams(global, single_subnet,
513 }
514 }
515
516 // Deriving parameters for shared networks is a bit more involved.
517 // First, the shared-network level derives from global, and then
518 // subnets within derive from it.
519 ConstElementPtr shared = global->get("shared-networks");
520 if (shared) {
521 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
522 // First try to inherit the parameters from shared network,
523 // if defined there.
524 // Then try to inherit them from global.
525 cnt += SimpleParser::deriveParams(global, net,
527
528 // Now we need to go thrugh all the subnets in this net.
529 subnets = net->get("subnet6");
530 if (subnets) {
531 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
532 cnt += SimpleParser::deriveParams(net, single_subnet,
534 }
535 }
536 }
537 }
538
539 return (cnt);
540}
541
542} // namespace dhcp
543} // namespace isc
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 setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
static const isc::data::SimpleDefaults SHARED_SUBNET6_DEFAULTS
This table defines default values for each IPv6 subnet.
static const isc::data::SimpleDefaults SUBNET6_DEFAULTS
This table defines default values for each IPv6 subnet.
static const isc::data::SimpleDefaults DHCP_QUEUE_CONTROL6_DEFAULTS
This table defines default values for dhcp-queue-control in DHCPv6.
static const isc::data::SimpleKeywords POOL6_PARAMETERS
This table defines all pool parameters.
static const isc::data::SimpleKeywords SHARED_NETWORK6_PARAMETERS
This table defines all shared network parameters for DHCPv6.
static const isc::data::SimpleDefaults GLOBAL6_DEFAULTS
This table defines default global values for DHCPv6.
static const isc::data::SimpleKeywords SUBNET6_PARAMETERS
This table defines all subnet parameters for DHCPv6.
static const isc::data::SimpleDefaults IFACE6_DEFAULTS
This table defines default values for interfaces for DHCPv6.
static const isc::data::SimpleDefaults OPTION6_DEF_DEFAULTS
This table defines default values for option definitions in DHCPv6.
static const isc::data::SimpleKeywords GLOBAL6_PARAMETERS
This table defines all global parameters in DHCPv6.
static const isc::data::SimpleDefaults OPTION6_DEFAULTS
This table defines default values for options in DHCPv6.
static const isc::data::SimpleDefaults SHARED_NETWORK6_DEFAULTS
This table defines default values for each IPv6 subnet that is part of a shared network.
static const isc::data::SimpleKeywords OPTION6_PARAMETERS
This table defines all option 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 DHCPv6 configuration.
static const isc::data::SimpleKeywords OPTION6_DEF_PARAMETERS
This table defines all option definition parameters.
static const isc::data::SimpleDefaults DHCP_MULTI_THREADING6_DEFAULTS
This table defines default values for multi-threading in DHCPv6.
static const isc::data::ParamsList INHERIT_TO_SUBNET6
List of parameters that can be inherited from the global to subnet6 scope.
static const isc::data::SimpleDefaults SANITY_CHECKS6_DEFAULTS
This defines default values for sanity checking for DHCPv6.
static const isc::data::SimpleKeywords PD_POOL6_PARAMETERS
This table defines all prefix delegation pool parameters.
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:27
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:24
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.