Kea  1.9.9-git
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 
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  { "ip-reservations-unique", Element::boolean },
97  { "ddns-update-on-renew", Element::boolean },
98  { "ddns-use-conflict-resolution", Element::boolean },
99  { "compatibility", Element::map },
100 };
101 
107 const SimpleDefaults SimpleParser6::GLOBAL6_DEFAULTS = {
108  { "preferred-lifetime", Element::integer, "3600" },
109  { "valid-lifetime", Element::integer, "7200" },
110  { "decline-probation-period", Element::integer, "86400" }, // 24h
111  { "dhcp4o6-port", Element::integer, "0" },
112  { "server-tag", Element::string, "" },
113  { "reservations-global", Element::boolean, "false" },
114  { "reservations-in-subnet", Element::boolean, "true" },
115  { "reservations-out-of-pool", Element::boolean, "false" },
116  { "calculate-tee-times", Element::boolean, "true" },
117  { "t1-percent", Element::real, ".50" },
118  { "t2-percent", Element::real, ".80" },
119  { "ddns-send-updates", Element::boolean, "true" },
120  { "ddns-override-no-update", Element::boolean, "false" },
121  { "ddns-override-client-update", Element::boolean, "false" },
122  { "ddns-replace-client-name", Element::string, "never" },
123  { "ddns-generated-prefix", Element::string, "myhost" },
124  { "ddns-qualifying-suffix", Element::string, "" },
125  { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" },
126  { "hostname-char-replacement", Element::string, "" },
127  { "store-extended-info", Element::boolean, "false" },
128  { "statistic-default-sample-count", Element::integer, "20" },
129  { "statistic-default-sample-age", Element::integer, "0" },
130  { "ip-reservations-unique", Element::boolean, "true" },
131  { "ddns-update-on-renew", Element::boolean, "false" },
132  { "ddns-use-conflict-resolution", Element::boolean, "true" }
133 };
134 
140 const SimpleKeywords SimpleParser6::OPTION6_DEF_PARAMETERS = {
141  { "name", Element::string },
142  { "code", Element::integer },
143  { "type", Element::string },
144  { "record-types", Element::string },
145  { "space", Element::string },
146  { "encapsulate", Element::string },
147  { "array", Element::boolean, },
148  { "user-context", Element::map },
149  { "comment", Element::string },
150  { "metadata", Element::map }
151 };
152 
157 const SimpleDefaults SimpleParser6::OPTION6_DEF_DEFAULTS = {
158  { "record-types", Element::string, ""},
159  { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
160  { "array", Element::boolean, "false"},
161  { "encapsulate", Element::string, "" }
162 };
163 
169 const SimpleKeywords SimpleParser6::OPTION6_PARAMETERS = {
170  { "name", Element::string },
171  { "data", Element::string },
172  { "code", Element::integer },
173  { "space", Element::string },
174  { "csv-format", Element::boolean },
175  { "always-send", Element::boolean },
176  { "user-context", Element::map },
177  { "comment", Element::string },
178  { "metadata", Element::map }
179 };
180 
186 const SimpleDefaults SimpleParser6::OPTION6_DEFAULTS = {
187  { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE
188  { "csv-format", Element::boolean, "true"},
189  { "always-send", Element::boolean, "false"}
190 };
191 
197 const SimpleKeywords SimpleParser6::SUBNET6_PARAMETERS = {
198  { "preferred-lifetime", Element::integer },
199  { "min-preferred-lifetime", Element::integer },
200  { "max-preferred-lifetime", Element::integer },
201  { "valid-lifetime", Element::integer },
202  { "min-valid-lifetime", Element::integer },
203  { "max-valid-lifetime", Element::integer },
204  { "renew-timer", Element::integer },
205  { "rebind-timer", Element::integer },
206  { "option-data", Element::list },
207  { "pools", Element::list },
208  { "pd-pools", Element::list },
209  { "subnet", Element::string },
210  { "interface", Element::string },
211  { "interface-id", Element::string },
212  { "id", Element::integer },
213  { "rapid-commit", Element::boolean },
214  { "client-class", Element::string },
215  { "require-client-classes", Element::list },
216  { "reservations", Element::list },
217  { "reservation-mode", Element::string },
218  { "reservations-global", Element::boolean },
219  { "reservations-in-subnet", Element::boolean },
220  { "reservations-out-of-pool", Element::boolean },
221  { "relay", Element::map },
222  { "user-context", Element::map },
223  { "comment", Element::string },
224  { "calculate-tee-times", Element::boolean },
225  { "t1-percent", Element::real },
226  { "t2-percent", Element::real },
227  { "ddns-send-updates", Element::boolean },
228  { "ddns-override-no-update", Element::boolean },
229  { "ddns-override-client-update", Element::boolean },
230  { "ddns-replace-client-name", Element::string },
231  { "ddns-generated-prefix", Element::string },
232  { "ddns-qualifying-suffix", Element::string },
233  { "hostname-char-set", Element::string },
234  { "hostname-char-replacement", Element::string },
235  { "store-extended-info", Element::boolean },
236  { "metadata", Element::map },
237  { "cache-threshold", Element::real },
238  { "cache-max-age", Element::integer },
239  { "ddns-update-on-renew", Element::boolean },
240  { "ddns-use-conflict-resolution", Element::boolean }
241 };
242 
249 const SimpleDefaults SimpleParser6::SUBNET6_DEFAULTS = {
250  { "id", Element::integer, "0" }, // 0 means autogenerate
251  { "interface", Element::string, "" },
252  { "client-class", Element::string, "" },
253  { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
254  { "interface-id", Element::string, "" }
255 };
256 
262 const SimpleDefaults SimpleParser6::SHARED_NETWORK6_DEFAULTS = {
263  { "client-class", Element::string, "" },
264  { "interface", Element::string, "" },
265  { "interface-id", Element::string, "" },
266  { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
267 };
268 
278 const ParamsList SimpleParser6::INHERIT_TO_SUBNET6 = {
279  "preferred-lifetime",
280  "min-preferred-lifetime",
281  "max-preferred-lifetime",
282  "rebind-timer",
283  "relay",
284  "renew-timer",
285  "valid-lifetime",
286  "min-valid-lifetime",
287  "max-valid-lifetime",
288  "calculate-tee-times",
289  "t1-percent",
290  "t2-percent",
291  "store-extended-info",
292  "cache-threshold",
293  "cache-max-age"
294 };
295 
301 const SimpleKeywords SimpleParser6::POOL6_PARAMETERS = {
302  { "pool", Element::string },
303  { "option-data", Element::list },
304  { "client-class", Element::string },
305  { "require-client-classes", Element::list },
306  { "user-context", Element::map },
307  { "comment", Element::string },
308  { "metadata", Element::map }
309 };
310 
316 const SimpleKeywords SimpleParser6::PD_POOL6_PARAMETERS = {
317  { "prefix", Element::string },
318  { "prefix-len", Element::integer },
319  { "delegated-len", Element::integer },
320  { "option-data", Element::list },
321  { "client-class", Element::string },
322  { "require-client-classes", Element::list },
323  { "excluded-prefix", Element::string },
324  { "excluded-prefix-len", Element::integer },
325  { "user-context", Element::map },
326  { "comment", Element::string },
327  { "metadata", Element::map }
328 };
329 
335 const SimpleKeywords SimpleParser6::SHARED_NETWORK6_PARAMETERS = {
336  { "name", Element::string },
337  { "subnet6", Element::list },
338  { "interface", Element::string },
339  { "interface-id", Element::string },
340  { "renew-timer", Element::integer },
341  { "rebind-timer", Element::integer },
342  { "option-data", Element::list },
343  { "relay", Element::map },
344  { "reservation-mode", Element::string },
345  { "reservations-global", Element::boolean },
346  { "reservations-in-subnet", Element::boolean },
347  { "reservations-out-of-pool", Element::boolean },
348  { "client-class", Element::string },
349  { "require-client-classes", Element::list },
350  { "preferred-lifetime", Element::integer },
351  { "min-preferred-lifetime", Element::integer },
352  { "max-preferred-lifetime", Element::integer },
353  { "rapid-commit", Element::boolean },
354  { "valid-lifetime", Element::integer },
355  { "min-valid-lifetime", Element::integer },
356  { "max-valid-lifetime", Element::integer },
357  { "user-context", Element::map },
358  { "comment", Element::string },
359  { "calculate-tee-times", Element::boolean },
360  { "t1-percent", Element::real },
361  { "t2-percent", Element::real },
362  { "ddns-send-updates", Element::boolean },
363  { "ddns-override-no-update", Element::boolean },
364  { "ddns-override-client-update", Element::boolean },
365  { "ddns-replace-client-name", Element::string },
366  { "ddns-generated-prefix", Element::string },
367  { "ddns-qualifying-suffix", Element::string },
368  { "hostname-char-set", Element::string },
369  { "hostname-char-replacement", Element::string },
370  { "store-extended-info", Element::boolean },
371  { "metadata", Element::map },
372  { "cache-threshold", Element::real },
373  { "cache-max-age", Element::integer },
374  { "ddns-update-on-renew", Element::boolean },
375  { "ddns-use-conflict-resolution", Element::boolean }
376 };
377 
379 const SimpleDefaults SimpleParser6::SHARED_SUBNET6_DEFAULTS = {
380  { "id", Element::integer, "0" } // 0 means autogenerate
381 };
382 
384 const SimpleDefaults SimpleParser6::IFACE6_DEFAULTS = {
385  { "re-detect", Element::boolean, "true" }
386 };
387 
389 const SimpleDefaults SimpleParser6::DHCP_QUEUE_CONTROL6_DEFAULTS = {
390  { "enable-queue", Element::boolean, "false"},
391  { "queue-type", Element::string, "kea-ring6"},
392  { "capacity", Element::integer, "64"}
393 };
394 
396 const SimpleDefaults SimpleParser6::DHCP_MULTI_THREADING6_DEFAULTS = {
397  { "enable-multi-threading", Element::boolean, "false" },
398  { "thread-pool-size", Element::integer, "0" },
399  { "packet-queue-size", Element::integer, "64" }
400 };
401 
403 const SimpleDefaults SimpleParser6::SANITY_CHECKS6_DEFAULTS = {
404  { "lease-checks", Element::string, "warn" }
405 };
406 
408 
412 
413 size_t SimpleParser6::setAllDefaults(ElementPtr global) {
414  size_t cnt = 0;
415 
416  // Set global defaults first.
417  cnt = setDefaults(global, GLOBAL6_DEFAULTS);
418 
419  // Now set the defaults for each specified option definition
420  ConstElementPtr option_defs = global->get("option-def");
421  if (option_defs) {
422  BOOST_FOREACH(ElementPtr option_def, option_defs->listValue()) {
423  cnt += SimpleParser::setDefaults(option_def, OPTION6_DEF_DEFAULTS);
424  }
425  }
426 
427  // Set the defaults for option data
428  ConstElementPtr options = global->get("option-data");
429  if (options) {
430  BOOST_FOREACH(ElementPtr single_option, options->listValue()) {
431  cnt += SimpleParser::setDefaults(single_option, OPTION6_DEFAULTS);
432  }
433  }
434 
435  // Now set the defaults for defined subnets
436  ConstElementPtr subnets = global->get("subnet6");
437  if (subnets) {
438  cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
439  }
440 
441  // Set the defaults for interfaces config
442  ConstElementPtr ifaces_cfg = global->get("interfaces-config");
443  if (ifaces_cfg) {
444  ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
445  cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
446  }
447 
448  // Set defaults for shared networks
449  ConstElementPtr shared = global->get("shared-networks");
450  if (shared) {
451  BOOST_FOREACH(ElementPtr net, shared->listValue()) {
452 
453  cnt += setDefaults(net, SHARED_NETWORK6_DEFAULTS);
454 
455  ConstElementPtr subs = net->get("subnet6");
456  if (subs) {
457  cnt += setListDefaults(subs, SHARED_SUBNET6_DEFAULTS);
458  }
459  }
460  }
461 
462  // Set the defaults for dhcp-queue-control. If the element isn't there
463  // we'll add it.
464  ConstElementPtr queue_control = global->get("dhcp-queue-control");
465  ElementPtr mutable_cfg;
466  if (queue_control) {
467  mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
468  } else {
469  mutable_cfg = Element::createMap();
470  global->set("dhcp-queue-control", mutable_cfg);
471  }
472 
473  cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
474 
475  // Set the defaults for multi-threading. If the element isn't there
476  // we'll add it.
477  ConstElementPtr multi_threading = global->get("multi-threading");
478  if (multi_threading) {
479  mutable_cfg = boost::const_pointer_cast<Element>(multi_threading);
480  } else {
481  mutable_cfg = Element::createMap();
482  global->set("multi-threading", mutable_cfg);
483  }
484 
485  cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS);
486 
487  // Set the defaults for sanity-checks. If the element isn't
488  // there we'll add it.
489  ConstElementPtr sanity_checks = global->get("sanity-checks");
490  if (sanity_checks) {
491  mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
492  } else {
493  mutable_cfg = Element::createMap();
494  global->set("sanity-checks", mutable_cfg);
495  }
496 
497  cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
498 
499  return (cnt);
500 }
501 
502 size_t SimpleParser6::deriveParameters(ElementPtr global) {
503  size_t cnt = 0;
504 
505  // Now derive global parameters into subnets.
506  ConstElementPtr subnets = global->get("subnet6");
507  if (subnets) {
508  BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
509  cnt += SimpleParser::deriveParams(global, single_subnet,
510  INHERIT_TO_SUBNET6);
511  }
512  }
513 
514  // Deriving parameters for shared networks is a bit more involved.
515  // First, the shared-network level derives from global, and then
516  // subnets within derive from it.
517  ConstElementPtr shared = global->get("shared-networks");
518  if (shared) {
519  BOOST_FOREACH(ElementPtr net, shared->listValue()) {
520  // First try to inherit the parameters from shared network,
521  // if defined there.
522  // Then try to inherit them from global.
523  cnt += SimpleParser::deriveParams(global, net,
524  INHERIT_TO_SUBNET6);
525 
526  // Now we need to go thrugh all the subnets in this net.
527  subnets = net->get("subnet6");
528  if (subnets) {
529  BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
530  cnt += SimpleParser::deriveParams(net, single_subnet,
531  INHERIT_TO_SUBNET6);
532  }
533  }
534  }
535  }
536 
537  return (cnt);
538 }
539 
540 } // namespace dhcp
541 } // 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:20
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:267
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:23
Defines the logger used by the top-level component of kea-dhcp-ddns.
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:66