Kea  2.1.7-git
simple_parser6.cc
Go to the documentation of this file.
1 // Copyright (C) 2016-2022 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 
14 using namespace isc::data;
15 
16 namespace isc {
17 namespace dhcp {
32 
38 const SimpleKeywords SimpleParser6::GLOBAL6_PARAMETERS = {
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  { "early-global-reservations-lookup", Element::boolean },
97  { "ip-reservations-unique", Element::boolean },
98  { "reservations-lookup-first", Element::boolean },
99  { "ddns-update-on-renew", Element::boolean },
100  { "ddns-use-conflict-resolution", Element::boolean },
101  { "compatibility", Element::map },
102  { "parked-packet-limit", Element::integer },
103 };
104 
110 const SimpleDefaults SimpleParser6::GLOBAL6_DEFAULTS = {
111  { "preferred-lifetime", Element::integer, "3600" },
112  { "valid-lifetime", Element::integer, "7200" },
113  { "decline-probation-period", Element::integer, "86400" }, // 24h
114  { "dhcp4o6-port", Element::integer, "0" },
115  { "server-tag", Element::string, "" },
116  { "reservations-global", Element::boolean, "false" },
117  { "reservations-in-subnet", Element::boolean, "true" },
118  { "reservations-out-of-pool", Element::boolean, "false" },
119  { "calculate-tee-times", Element::boolean, "true" },
120  { "t1-percent", Element::real, ".50" },
121  { "t2-percent", Element::real, ".80" },
122  { "ddns-send-updates", Element::boolean, "true" },
123  { "ddns-override-no-update", Element::boolean, "false" },
124  { "ddns-override-client-update", Element::boolean, "false" },
125  { "ddns-replace-client-name", Element::string, "never" },
126  { "ddns-generated-prefix", Element::string, "myhost" },
127  { "ddns-qualifying-suffix", Element::string, "" },
128  { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
129  { "hostname-char-replacement", Element::string, "" },
130  { "store-extended-info", Element::boolean, "false" },
131  { "statistic-default-sample-count", Element::integer, "20" },
132  { "statistic-default-sample-age", Element::integer, "0" },
133  { "early-global-reservations-lookup", Element::boolean, "false" },
134  { "ip-reservations-unique", Element::boolean, "true" },
135  { "reservations-lookup-first", Element::boolean, "false" },
136  { "ddns-update-on-renew", Element::boolean, "false" },
137  { "ddns-use-conflict-resolution", Element::boolean, "true" },
138  { "parked-packet-limit", Element::integer, "256" }
139 };
140 
146 const SimpleKeywords SimpleParser6::OPTION6_DEF_PARAMETERS = {
147  { "name", Element::string },
148  { "code", Element::integer },
149  { "type", Element::string },
150  { "record-types", Element::string },
151  { "space", Element::string },
152  { "encapsulate", Element::string },
153  { "array", Element::boolean, },
154  { "user-context", Element::map },
155  { "comment", Element::string },
156  { "metadata", Element::map }
157 };
158 
163 const SimpleDefaults SimpleParser6::OPTION6_DEF_DEFAULTS = {
164  { "record-types", Element::string, ""},
165  { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
166  { "array", Element::boolean, "false"},
167  { "encapsulate", Element::string, "" }
168 };
169 
175 const SimpleKeywords SimpleParser6::OPTION6_PARAMETERS = {
176  { "name", Element::string },
177  { "data", Element::string },
178  { "code", Element::integer },
179  { "space", Element::string },
180  { "csv-format", Element::boolean },
181  { "always-send", Element::boolean },
182  { "user-context", Element::map },
183  { "comment", Element::string },
184  { "metadata", Element::map }
185 };
186 
192 const SimpleDefaults SimpleParser6::OPTION6_DEFAULTS = {
193  { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
194  { "csv-format", Element::boolean, "true"},
195  { "always-send", Element::boolean, "false"}
196 };
197 
203 const SimpleKeywords SimpleParser6::SUBNET6_PARAMETERS = {
204  { "preferred-lifetime", Element::integer },
205  { "min-preferred-lifetime", Element::integer },
206  { "max-preferred-lifetime", Element::integer },
207  { "valid-lifetime", Element::integer },
208  { "min-valid-lifetime", Element::integer },
209  { "max-valid-lifetime", Element::integer },
210  { "renew-timer", Element::integer },
211  { "rebind-timer", Element::integer },
212  { "option-data", Element::list },
213  { "pools", Element::list },
214  { "pd-pools", Element::list },
215  { "subnet", Element::string },
216  { "interface", Element::string },
217  { "interface-id", Element::string },
218  { "id", Element::integer },
219  { "rapid-commit", Element::boolean },
220  { "client-class", Element::string },
221  { "require-client-classes", Element::list },
222  { "reservations", Element::list },
223  { "reservation-mode", Element::string },
224  { "reservations-global", Element::boolean },
225  { "reservations-in-subnet", Element::boolean },
226  { "reservations-out-of-pool", Element::boolean },
227  { "relay", Element::map },
228  { "user-context", Element::map },
229  { "comment", Element::string },
230  { "calculate-tee-times", Element::boolean },
231  { "t1-percent", Element::real },
232  { "t2-percent", Element::real },
233  { "ddns-send-updates", Element::boolean },
234  { "ddns-override-no-update", Element::boolean },
235  { "ddns-override-client-update", Element::boolean },
236  { "ddns-replace-client-name", Element::string },
237  { "ddns-generated-prefix", Element::string },
238  { "ddns-qualifying-suffix", Element::string },
239  { "hostname-char-set", Element::string },
240  { "hostname-char-replacement", Element::string },
241  { "store-extended-info", Element::boolean },
242  { "metadata", Element::map },
243  { "cache-threshold", Element::real },
244  { "cache-max-age", Element::integer },
245  { "ddns-update-on-renew", Element::boolean },
246  { "ddns-use-conflict-resolution", Element::boolean }
247 };
248 
255 const SimpleDefaults SimpleParser6::SUBNET6_DEFAULTS = {
256  { "id", Element::integer, "0" }, // 0 means autogenerate
257  { "interface", Element::string, "" },
258  { "client-class", Element::string, "" },
259  { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
260  { "interface-id", Element::string, "" }
261 };
262 
268 const SimpleDefaults SimpleParser6::SHARED_NETWORK6_DEFAULTS = {
269  { "client-class", Element::string, "" },
270  { "interface", Element::string, "" },
271  { "interface-id", Element::string, "" },
272  { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
273 };
274 
284 const ParamsList SimpleParser6::INHERIT_TO_SUBNET6 = {
285  "preferred-lifetime",
286  "min-preferred-lifetime",
287  "max-preferred-lifetime",
288  "rebind-timer",
289  "relay",
290  "renew-timer",
291  "valid-lifetime",
292  "min-valid-lifetime",
293  "max-valid-lifetime",
294  "calculate-tee-times",
295  "t1-percent",
296  "t2-percent",
297  "store-extended-info",
298  "cache-threshold",
299  "cache-max-age"
300 };
301 
307 const SimpleKeywords SimpleParser6::POOL6_PARAMETERS = {
308  { "pool", Element::string },
309  { "option-data", Element::list },
310  { "client-class", Element::string },
311  { "require-client-classes", Element::list },
312  { "user-context", Element::map },
313  { "comment", Element::string },
314  { "metadata", Element::map }
315 };
316 
322 const SimpleKeywords SimpleParser6::PD_POOL6_PARAMETERS = {
323  { "prefix", Element::string },
324  { "prefix-len", Element::integer },
325  { "delegated-len", Element::integer },
326  { "option-data", Element::list },
327  { "client-class", Element::string },
328  { "require-client-classes", Element::list },
329  { "excluded-prefix", Element::string },
330  { "excluded-prefix-len", Element::integer },
331  { "user-context", Element::map },
332  { "comment", Element::string },
333  { "metadata", Element::map }
334 };
335 
341 const SimpleKeywords SimpleParser6::SHARED_NETWORK6_PARAMETERS = {
342  { "name", Element::string },
343  { "subnet6", Element::list },
344  { "interface", Element::string },
345  { "interface-id", Element::string },
346  { "renew-timer", Element::integer },
347  { "rebind-timer", Element::integer },
348  { "option-data", Element::list },
349  { "relay", Element::map },
350  { "reservation-mode", Element::string },
351  { "reservations-global", Element::boolean },
352  { "reservations-in-subnet", Element::boolean },
353  { "reservations-out-of-pool", Element::boolean },
354  { "client-class", Element::string },
355  { "require-client-classes", Element::list },
356  { "preferred-lifetime", Element::integer },
357  { "min-preferred-lifetime", Element::integer },
358  { "max-preferred-lifetime", Element::integer },
359  { "rapid-commit", Element::boolean },
360  { "valid-lifetime", Element::integer },
361  { "min-valid-lifetime", Element::integer },
362  { "max-valid-lifetime", Element::integer },
363  { "user-context", Element::map },
364  { "comment", Element::string },
365  { "calculate-tee-times", Element::boolean },
366  { "t1-percent", Element::real },
367  { "t2-percent", Element::real },
368  { "ddns-send-updates", Element::boolean },
369  { "ddns-override-no-update", Element::boolean },
370  { "ddns-override-client-update", Element::boolean },
371  { "ddns-replace-client-name", Element::string },
372  { "ddns-generated-prefix", Element::string },
373  { "ddns-qualifying-suffix", Element::string },
374  { "hostname-char-set", Element::string },
375  { "hostname-char-replacement", Element::string },
376  { "store-extended-info", Element::boolean },
377  { "metadata", Element::map },
378  { "cache-threshold", Element::real },
379  { "cache-max-age", Element::integer },
380  { "ddns-update-on-renew", Element::boolean },
381  { "ddns-use-conflict-resolution", Element::boolean }
382 };
383 
385 const SimpleDefaults SimpleParser6::SHARED_SUBNET6_DEFAULTS = {
386  { "id", Element::integer, "0" } // 0 means autogenerate
387 };
388 
390 const SimpleDefaults SimpleParser6::IFACE6_DEFAULTS = {
391  { "re-detect", Element::boolean, "true" }
392 };
393 
395 const SimpleDefaults SimpleParser6::DHCP_QUEUE_CONTROL6_DEFAULTS = {
396  { "enable-queue", Element::boolean, "false"},
397  { "queue-type", Element::string, "kea-ring6"},
398  { "capacity", Element::integer, "64"}
399 };
400 
402 const SimpleDefaults SimpleParser6::DHCP_MULTI_THREADING6_DEFAULTS = {
403  { "enable-multi-threading", Element::boolean, "false" },
404  { "thread-pool-size", Element::integer, "0" },
405  { "packet-queue-size", Element::integer, "64" }
406 };
407 
409 const SimpleDefaults SimpleParser6::SANITY_CHECKS6_DEFAULTS = {
410  { "lease-checks", Element::string, "warn" }
411 };
412 
414 
418 
419 size_t SimpleParser6::setAllDefaults(ElementPtr global) {
420  size_t cnt = 0;
421 
422  // Set global defaults first.
423  cnt = setDefaults(global, GLOBAL6_DEFAULTS);
424 
425  // Now set the defaults for each specified option definition
426  ConstElementPtr option_defs = global->get("option-def");
427  if (option_defs) {
428  BOOST_FOREACH(ElementPtr option_def, option_defs->listValue()) {
429  cnt += SimpleParser::setDefaults(option_def, OPTION6_DEF_DEFAULTS);
430  }
431  }
432 
433  // Set the defaults for option data
434  ConstElementPtr options = global->get("option-data");
435  if (options) {
436  BOOST_FOREACH(ElementPtr single_option, options->listValue()) {
437  cnt += SimpleParser::setDefaults(single_option, OPTION6_DEFAULTS);
438  }
439  }
440 
441  // Now set the defaults for defined subnets
442  ConstElementPtr subnets = global->get("subnet6");
443  if (subnets) {
444  cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
445  }
446 
447  // Set the defaults for interfaces config
448  ConstElementPtr ifaces_cfg = global->get("interfaces-config");
449  if (ifaces_cfg) {
450  ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
451  cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
452  }
453 
454  // Set defaults for shared networks
455  ConstElementPtr shared = global->get("shared-networks");
456  if (shared) {
457  BOOST_FOREACH(ElementPtr net, shared->listValue()) {
458 
459  cnt += setDefaults(net, SHARED_NETWORK6_DEFAULTS);
460 
461  ConstElementPtr subs = net->get("subnet6");
462  if (subs) {
463  cnt += setListDefaults(subs, SHARED_SUBNET6_DEFAULTS);
464  }
465  }
466  }
467 
468  // Set the defaults for dhcp-queue-control. If the element isn't there
469  // we'll add it.
470  ConstElementPtr queue_control = global->get("dhcp-queue-control");
471  ElementPtr mutable_cfg;
472  if (queue_control) {
473  mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
474  } else {
475  mutable_cfg = Element::createMap();
476  global->set("dhcp-queue-control", mutable_cfg);
477  }
478 
479  cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
480 
481  // Set the defaults for multi-threading. If the element isn't there
482  // we'll add it.
483  ConstElementPtr multi_threading = global->get("multi-threading");
484  if (multi_threading) {
485  mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
486  } else {
487  mutable_cfg = Element::createMap();
488  global->set("multi-threading", mutable_cfg);
489  }
490 
491  cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS);
492 
493  // Set the defaults for sanity-checks. If the element isn't
494  // there we'll add it.
495  ConstElementPtr sanity_checks = global->get("sanity-checks");
496  if (sanity_checks) {
497  mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
498  } else {
499  mutable_cfg = Element::createMap();
500  global->set("sanity-checks", mutable_cfg);
501  }
502 
503  cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
504 
505  return (cnt);
506 }
507 
508 size_t SimpleParser6::deriveParameters(ElementPtr global) {
509  size_t cnt = 0;
510 
511  // Now derive global parameters into subnets.
512  ConstElementPtr subnets = global->get("subnet6");
513  if (subnets) {
514  BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
515  cnt += SimpleParser::deriveParams(global, single_subnet,
516  INHERIT_TO_SUBNET6);
517  }
518  }
519 
520  // Deriving parameters for shared networks is a bit more involved.
521  // First, the shared-network level derives from global, and then
522  // subnets within derive from it.
523  ConstElementPtr shared = global->get("shared-networks");
524  if (shared) {
525  BOOST_FOREACH(ElementPtr net, shared->listValue()) {
526  // First try to inherit the parameters from shared network,
527  // if defined there.
528  // Then try to inherit them from global.
529  cnt += SimpleParser::deriveParams(global, net,
530  INHERIT_TO_SUBNET6);
531 
532  // Now we need to go thrugh all the subnets in this net.
533  subnets = net->get("subnet6");
534  if (subnets) {
535  BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
536  cnt += SimpleParser::deriveParams(net, single_subnet,
537  INHERIT_TO_SUBNET6);
538  }
539  }
540  }
541  }
542 
543  return (cnt);
544 }
545 
546 } // namespace dhcp
547 } // namespace isc
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
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
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:286
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.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
Defines the logger used by the top-level component of kea-lfc.
std::vector< std::string > ParamsList
This defines a list of all parameters that are derived (or inherited) between contexts.
The Element class represents a piece of data, used by the command channel and configuration parts...
Definition: data.h:70