/src/kea/src/lib/dhcpsrv/parsers/simple_parser6.cc
Line | Count | Source |
1 | | // Copyright (C) 2016-2025 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> |
10 | | #include <dhcpsrv/parsers/simple_parser6.h> |
11 | | |
12 | | using namespace isc::data; |
13 | | |
14 | | namespace isc { |
15 | | namespace dhcp { |
16 | | /// @brief This sets of arrays define the default values and |
17 | | /// values inherited (derived) between various scopes. |
18 | | /// |
19 | | /// Each of those is documented in @file simple_parser6.cc. This |
20 | | /// is different than most other comments in Kea code. The reason |
21 | | /// for placing those in .cc rather than .h file is that it |
22 | | /// is expected to be one centralized place to look at for |
23 | | /// the default values. This is expected to be looked at also by |
24 | | /// people who are not skilled in C or C++, so they may be |
25 | | /// confused with the differences between declaration and definition. |
26 | | /// As such, there's one file to look at that hopefully is readable |
27 | | /// without any C or C++ skills. |
28 | | /// |
29 | | /// @{ |
30 | | |
31 | | /// @brief This table defines all global parameters in DHCPv6. |
32 | | /// |
33 | | /// Boolean, integer, real and string types are for scalar parameters, |
34 | | /// list and map types for entries. |
35 | | /// Order follows global_param rule in bison grammar. |
36 | | const SimpleKeywords SimpleParser6::GLOBAL6_PARAMETERS = { |
37 | | { "data-directory", Element::string }, |
38 | | { "preferred-lifetime", Element::integer }, |
39 | | { "min-preferred-lifetime", Element::integer }, |
40 | | { "max-preferred-lifetime", Element::integer }, |
41 | | { "valid-lifetime", Element::integer }, |
42 | | { "min-valid-lifetime", Element::integer }, |
43 | | { "max-valid-lifetime", Element::integer }, |
44 | | { "renew-timer", Element::integer }, |
45 | | { "rebind-timer", Element::integer }, |
46 | | { "decline-probation-period", Element::integer }, |
47 | | { "subnet6", Element::list }, |
48 | | { "shared-networks", Element::list }, |
49 | | { "interfaces-config", Element::map }, |
50 | | { "lease-database", Element::map }, |
51 | | { "hosts-database", Element::map }, |
52 | | { "hosts-databases", Element::list }, |
53 | | { "mac-sources", Element::list }, |
54 | | { "relay-supplied-options", Element::list }, |
55 | | { "host-reservation-identifiers", Element::list }, |
56 | | { "client-classes", Element::list }, |
57 | | { "option-def", Element::list }, |
58 | | { "option-data", Element::list }, |
59 | | { "hooks-libraries", Element::list }, |
60 | | { "expired-leases-processing", Element::map }, |
61 | | { "server-id", Element::map }, |
62 | | { "dhcp4o6-port", Element::integer }, |
63 | | { "control-sockets", Element::list }, |
64 | | { "dhcp-queue-control", Element::map }, |
65 | | { "dhcp-ddns", Element::map }, |
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 | | { "pd-allocator", Element::string }, |
101 | | { "ddns-ttl-percent", Element::real }, |
102 | | { "ddns-conflict-resolution-mode", Element::string }, |
103 | | { "ddns-ttl", Element::integer }, |
104 | | { "ddns-ttl-min", Element::integer }, |
105 | | { "ddns-ttl-max", Element::integer }, |
106 | | { "adaptive-lease-time-threshold", Element::real }, |
107 | | { "allow-address-registration", Element::boolean }, |
108 | | }; |
109 | | |
110 | | /// @brief This table defines default global values for DHCPv6 |
111 | | /// |
112 | | /// Some of the global parameters defined in the global scope (i.e. directly |
113 | | /// in Dhcp6) are optional. If not defined, the following values will be |
114 | | /// used. |
115 | | const SimpleDefaults SimpleParser6::GLOBAL6_DEFAULTS = { |
116 | | // preferred-lifetime is unspecified and defaults to 0.625 of valid-lifetime. |
117 | | { "valid-lifetime", Element::integer, "7200" }, |
118 | | { "decline-probation-period", Element::integer, "86400" }, // 24h |
119 | | { "dhcp4o6-port", Element::integer, "0" }, |
120 | | { "server-tag", Element::string, "" }, |
121 | | { "reservations-global", Element::boolean, "false" }, |
122 | | { "reservations-in-subnet", Element::boolean, "true" }, |
123 | | { "reservations-out-of-pool", Element::boolean, "false" }, |
124 | | { "calculate-tee-times", Element::boolean, "true" }, |
125 | | { "t1-percent", Element::real, ".50" }, |
126 | | { "t2-percent", Element::real, ".80" }, |
127 | | { "ddns-send-updates", Element::boolean, "true" }, |
128 | | { "ddns-override-no-update", Element::boolean, "false" }, |
129 | | { "ddns-override-client-update", Element::boolean, "false" }, |
130 | | { "ddns-replace-client-name", Element::string, "never" }, |
131 | | { "ddns-generated-prefix", Element::string, "myhost" }, |
132 | | { "ddns-qualifying-suffix", Element::string, "" }, |
133 | | { "hostname-char-set", Element::string, "[^A-Za-z0-9.-]" }, |
134 | | { "hostname-char-replacement", Element::string, "" }, |
135 | | { "store-extended-info", Element::boolean, "false" }, |
136 | | { "statistic-default-sample-count", Element::integer, "20" }, |
137 | | { "statistic-default-sample-age", Element::integer, "0" }, |
138 | | { "early-global-reservations-lookup", Element::boolean, "false" }, |
139 | | { "ip-reservations-unique", Element::boolean, "true" }, |
140 | | { "reservations-lookup-first", Element::boolean, "false" }, |
141 | | { "ddns-update-on-renew", Element::boolean, "false" }, |
142 | | { "parked-packet-limit", Element::integer, "256" }, |
143 | | { "allocator", Element::string, "iterative" }, |
144 | | { "pd-allocator", Element::string, "iterative" }, |
145 | | { "ddns-conflict-resolution-mode", Element::string, "check-with-dhcid" }, |
146 | | { "cache-threshold", Element::real, "0.25" }, |
147 | | { "allow-address-registration", Element::boolean, "true"}, |
148 | | }; |
149 | | |
150 | | const SimpleKeywords SimpleParser6::GLOBAL6_LIST_PARAMETERS = { |
151 | | { "host-reservation-identifiers", Element::list }, |
152 | | /* not yet supported |
153 | | { "interfaces-config.interfaces", Element::list }, |
154 | | */ |
155 | | }; |
156 | | |
157 | | const SimpleKeywords SimpleParser6::GLOBAL6_LIST_PARAMETER_TYPES = { |
158 | | { "host-reservation-identifiers", Element::string }, |
159 | | /* not yet supported |
160 | | { "interfaces-config.interfaces", Element::string }, |
161 | | */ |
162 | | }; |
163 | | |
164 | | /// @brief This table defines all option definition parameters. |
165 | | /// |
166 | | /// Boolean, integer, real and string types are for scalar parameters, |
167 | | /// list and map types for entries. |
168 | | /// Order follows option_def_param rules in bison grammar. |
169 | | const SimpleKeywords SimpleParser6::OPTION6_DEF_PARAMETERS = { |
170 | | { "name", Element::string }, |
171 | | { "code", Element::integer }, |
172 | | { "type", Element::string }, |
173 | | { "record-types", Element::string }, |
174 | | { "space", Element::string }, |
175 | | { "encapsulate", Element::string }, |
176 | | { "array", Element::boolean, }, |
177 | | { "user-context", Element::map }, |
178 | | { "comment", Element::string }, |
179 | | { "metadata", Element::map } |
180 | | }; |
181 | | |
182 | | /// @brief This table defines default values for option definitions in DHCPv6. |
183 | | /// |
184 | | /// Dhcp6 may contain an array called option-def that enumerates new option |
185 | | /// definitions. This array lists default values for those option definitions. |
186 | | const SimpleDefaults SimpleParser6::OPTION6_DEF_DEFAULTS = { |
187 | | { "record-types", Element::string, ""}, |
188 | | { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE |
189 | | { "array", Element::boolean, "false"}, |
190 | | { "encapsulate", Element::string, "" } |
191 | | }; |
192 | | |
193 | | /// @brief This table defines all option parameters. |
194 | | /// |
195 | | /// Boolean, integer, real and string types are for scalar parameters, |
196 | | /// list and map types for entries. |
197 | | /// Order follows option_param rules in bison grammar. |
198 | | const SimpleKeywords SimpleParser6::OPTION6_PARAMETERS = { |
199 | | { "name", Element::string }, |
200 | | { "data", Element::string }, |
201 | | { "code", Element::integer }, |
202 | | { "space", Element::string }, |
203 | | { "csv-format", Element::boolean }, |
204 | | { "always-send", Element::boolean }, |
205 | | { "never-send", Element::boolean }, |
206 | | { "user-context", Element::map }, |
207 | | { "comment", Element::string }, |
208 | | { "client-classes", Element::list }, |
209 | | { "metadata", Element::map } |
210 | | }; |
211 | | |
212 | | /// @brief This table defines default values for options in DHCPv6. |
213 | | /// |
214 | | /// Dhcp6 usually contains option values (option-data) defined in global, |
215 | | /// subnet, class or host reservations scopes. This array lists default values |
216 | | /// for those option-data declarations. |
217 | | const SimpleDefaults SimpleParser6::OPTION6_DEFAULTS = { |
218 | | { "space", Element::string, "dhcp6"}, // DHCP6_OPTION_SPACE |
219 | | { "csv-format", Element::boolean, "true"}, |
220 | | { "always-send", Element::boolean, "false"}, |
221 | | { "never-send", Element::boolean, "false"} |
222 | | }; |
223 | | |
224 | | /// @brief This table defines all subnet parameters for DHCPv6. |
225 | | /// |
226 | | /// Boolean, integer, real and string types are for scalar parameters, |
227 | | /// list and map types for entries. |
228 | | /// Order follows subnet6_param rule in bison grammar. |
229 | | const SimpleKeywords SimpleParser6::SUBNET6_PARAMETERS = { |
230 | | { "preferred-lifetime", Element::integer }, |
231 | | { "min-preferred-lifetime", Element::integer }, |
232 | | { "max-preferred-lifetime", Element::integer }, |
233 | | { "valid-lifetime", Element::integer }, |
234 | | { "min-valid-lifetime", Element::integer }, |
235 | | { "max-valid-lifetime", Element::integer }, |
236 | | { "renew-timer", Element::integer }, |
237 | | { "rebind-timer", Element::integer }, |
238 | | { "option-data", Element::list }, |
239 | | { "pools", Element::list }, |
240 | | { "pd-pools", Element::list }, |
241 | | { "subnet", Element::string }, |
242 | | { "interface", Element::string }, |
243 | | { "interface-id", Element::string }, |
244 | | { "id", Element::integer }, |
245 | | { "rapid-commit", Element::boolean }, |
246 | | { "client-class", Element::string }, |
247 | | { "client-classes", Element::list }, |
248 | | { "require-client-classes", Element::list }, |
249 | | { "evaluate-additional-classes", Element::list }, |
250 | | { "reservations", Element::list }, |
251 | | { "reservations-global", Element::boolean }, |
252 | | { "reservations-in-subnet", Element::boolean }, |
253 | | { "reservations-out-of-pool", Element::boolean }, |
254 | | { "relay", Element::map }, |
255 | | { "user-context", Element::map }, |
256 | | { "comment", Element::string }, |
257 | | { "calculate-tee-times", Element::boolean }, |
258 | | { "t1-percent", Element::real }, |
259 | | { "t2-percent", Element::real }, |
260 | | { "ddns-send-updates", Element::boolean }, |
261 | | { "ddns-override-no-update", Element::boolean }, |
262 | | { "ddns-override-client-update", Element::boolean }, |
263 | | { "ddns-replace-client-name", Element::string }, |
264 | | { "ddns-generated-prefix", Element::string }, |
265 | | { "ddns-qualifying-suffix", Element::string }, |
266 | | { "hostname-char-set", Element::string }, |
267 | | { "hostname-char-replacement", Element::string }, |
268 | | { "store-extended-info", Element::boolean }, |
269 | | { "metadata", Element::map }, |
270 | | { "cache-threshold", Element::real }, |
271 | | { "cache-max-age", Element::integer }, |
272 | | { "ddns-update-on-renew", Element::boolean }, |
273 | | { "allocator", Element::string }, |
274 | | { "pd-allocator", Element::string }, |
275 | | { "ddns-ttl-percent", Element::real }, |
276 | | { "ddns-conflict-resolution-mode", Element::string }, |
277 | | { "ddns-ttl", Element::integer }, |
278 | | { "ddns-ttl-min", Element::integer }, |
279 | | { "ddns-ttl-max", Element::integer }, |
280 | | { "adaptive-lease-time-threshold", Element::real }, |
281 | | }; |
282 | | |
283 | | /// @brief This table defines default values for each IPv6 subnet. |
284 | | /// |
285 | | /// Note: When updating this array, please also update SHARED_SUBNET6_DEFAULTS |
286 | | /// below. In most cases, those two should be kept in sync, except cases |
287 | | /// where a parameter can be derived from shared-networks, but is not |
288 | | /// defined on global level. |
289 | | const SimpleDefaults SimpleParser6::SUBNET6_DEFAULTS = { |
290 | | { "interface", Element::string, "" }, |
291 | | { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default |
292 | | { "interface-id", Element::string, "" } |
293 | | }; |
294 | | |
295 | | /// @brief This table defines default values for each IPv6 subnet that is |
296 | | /// part of a shared network |
297 | | /// |
298 | | /// This is mostly the same as @ref SUBNET6_DEFAULTS, except the parameters |
299 | | /// that can be derived from shared-network, but cannot from global scope. |
300 | | const SimpleDefaults SimpleParser6::SHARED_SUBNET6_DEFAULTS = { |
301 | | }; |
302 | | |
303 | | /// @brief This table defines default values for each IPv6 shared network. |
304 | | const SimpleDefaults SimpleParser6::SHARED_NETWORK6_DEFAULTS = { |
305 | | { "interface", Element::string, "" }, |
306 | | { "interface-id", Element::string, "" }, |
307 | | { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default |
308 | | }; |
309 | | |
310 | | /// @brief List of parameters that can be inherited from the global to subnet6 scope. |
311 | | /// |
312 | | /// Some parameters may be defined on both global (directly in Dhcp6) and |
313 | | /// subnet (Dhcp6/subnet6/...) scope. If not defined in the subnet scope, |
314 | | /// the value is being inherited (derived) from the global scope. This |
315 | | /// array lists all of such parameters. |
316 | | /// |
317 | | /// This list is also used for inheriting from global to shared networks |
318 | | /// and from shared networks to subnets within it. |
319 | | const ParamsList SimpleParser6::INHERIT_TO_SUBNET6 = { |
320 | | "preferred-lifetime", |
321 | | "min-preferred-lifetime", |
322 | | "max-preferred-lifetime", |
323 | | "rebind-timer", |
324 | | "relay", |
325 | | "renew-timer", |
326 | | "valid-lifetime", |
327 | | "min-valid-lifetime", |
328 | | "max-valid-lifetime", |
329 | | "calculate-tee-times", |
330 | | "t1-percent", |
331 | | "t2-percent", |
332 | | "store-extended-info", |
333 | | "cache-threshold", |
334 | | "cache-max-age", |
335 | | "allocator", |
336 | | "pd-allocator", |
337 | | "adaptive-lease-time-threshold", |
338 | | }; |
339 | | |
340 | | /// @brief This table defines all pool parameters. |
341 | | /// |
342 | | /// Boolean, integer, real and string types are for scalar parameters, |
343 | | /// list and map types for entries. |
344 | | /// Order follows pool_param rules in bison grammar. |
345 | | const SimpleKeywords SimpleParser6::POOL6_PARAMETERS = { |
346 | | { "pool", Element::string }, |
347 | | { "pool-id", Element::integer }, |
348 | | { "option-data", Element::list }, |
349 | | { "client-class", Element::string }, |
350 | | { "client-classes", Element::list }, |
351 | | { "require-client-classes", Element::list }, |
352 | | { "evaluate-additional-classes", Element::list }, |
353 | | { "user-context", Element::map }, |
354 | | { "comment", Element::string }, |
355 | | { "ddns-send-updates", Element::boolean }, |
356 | | { "ddns-override-no-update", Element::boolean }, |
357 | | { "ddns-override-client-update", Element::boolean }, |
358 | | { "ddns-replace-client-name", Element::string }, |
359 | | { "ddns-generated-prefix", Element::string }, |
360 | | { "ddns-qualifying-suffix", Element::string }, |
361 | | { "hostname-char-set", Element::string }, |
362 | | { "hostname-char-replacement", Element::string }, |
363 | | { "ddns-update-on-renew", Element::boolean }, |
364 | | { "ddns-ttl-percent", Element::real }, |
365 | | { "ddns-conflict-resolution-mode", Element::string }, |
366 | | { "ddns-ttl", Element::integer }, |
367 | | { "ddns-ttl-min", Element::integer }, |
368 | | { "ddns-ttl-max", Element::integer }, |
369 | | { "metadata", Element::map } |
370 | | }; |
371 | | |
372 | | /// @brief This table defines all prefix delegation pool parameters. |
373 | | /// |
374 | | /// Boolean, integer, real and string types are for scalar parameters, |
375 | | /// list and map types for entries. |
376 | | /// Order follows pd_pool_param rules in bison grammar. |
377 | | const SimpleKeywords SimpleParser6::PD_POOL6_PARAMETERS = { |
378 | | { "prefix", Element::string }, |
379 | | { "prefix-len", Element::integer }, |
380 | | { "delegated-len", Element::integer }, |
381 | | { "pool-id", Element::integer }, |
382 | | { "option-data", Element::list }, |
383 | | { "client-class", Element::string }, |
384 | | { "client-classes", Element::list }, |
385 | | { "require-client-classes", Element::list }, |
386 | | { "evaluate-additional-classes", Element::list }, |
387 | | { "excluded-prefix", Element::string }, |
388 | | { "excluded-prefix-len", Element::integer }, |
389 | | { "user-context", Element::map }, |
390 | | { "comment", Element::string }, |
391 | | { "metadata", Element::map } |
392 | | }; |
393 | | |
394 | | /// @brief This table defines all shared network parameters for DHCPv6. |
395 | | /// |
396 | | /// Boolean, integer, real and string types are for scalar parameters, |
397 | | /// list and map types for entries. |
398 | | /// Order follows shared_network_param rule in bison grammar. |
399 | | const SimpleKeywords SimpleParser6::SHARED_NETWORK6_PARAMETERS = { |
400 | | { "name", Element::string }, |
401 | | { "subnet6", Element::list }, |
402 | | { "interface", Element::string }, |
403 | | { "interface-id", Element::string }, |
404 | | { "renew-timer", Element::integer }, |
405 | | { "rebind-timer", Element::integer }, |
406 | | { "option-data", Element::list }, |
407 | | { "relay", Element::map }, |
408 | | { "reservations-global", Element::boolean }, |
409 | | { "reservations-in-subnet", Element::boolean }, |
410 | | { "reservations-out-of-pool", Element::boolean }, |
411 | | { "client-class", Element::string }, |
412 | | { "client-classes", Element::list }, |
413 | | { "require-client-classes", Element::list }, |
414 | | { "evaluate-additional-classes", Element::list }, |
415 | | { "preferred-lifetime", Element::integer }, |
416 | | { "min-preferred-lifetime", Element::integer }, |
417 | | { "max-preferred-lifetime", Element::integer }, |
418 | | { "rapid-commit", Element::boolean }, |
419 | | { "valid-lifetime", Element::integer }, |
420 | | { "min-valid-lifetime", Element::integer }, |
421 | | { "max-valid-lifetime", Element::integer }, |
422 | | { "user-context", Element::map }, |
423 | | { "comment", Element::string }, |
424 | | { "calculate-tee-times", Element::boolean }, |
425 | | { "t1-percent", Element::real }, |
426 | | { "t2-percent", Element::real }, |
427 | | { "ddns-send-updates", Element::boolean }, |
428 | | { "ddns-override-no-update", Element::boolean }, |
429 | | { "ddns-override-client-update", Element::boolean }, |
430 | | { "ddns-replace-client-name", Element::string }, |
431 | | { "ddns-generated-prefix", Element::string }, |
432 | | { "ddns-qualifying-suffix", Element::string }, |
433 | | { "hostname-char-set", Element::string }, |
434 | | { "hostname-char-replacement", Element::string }, |
435 | | { "store-extended-info", Element::boolean }, |
436 | | { "metadata", Element::map }, |
437 | | { "cache-threshold", Element::real }, |
438 | | { "cache-max-age", Element::integer }, |
439 | | { "ddns-update-on-renew", Element::boolean }, |
440 | | { "allocator", Element::string }, |
441 | | { "pd-allocator", Element::string }, |
442 | | { "ddns-ttl-percent", Element::real }, |
443 | | { "ddns-conflict-resolution-mode", Element::string }, |
444 | | { "ddns-ttl", Element::integer }, |
445 | | { "ddns-ttl-min", Element::integer }, |
446 | | { "ddns-ttl-max", Element::integer }, |
447 | | { "adaptive-lease-time-threshold", Element::real }, |
448 | | }; |
449 | | |
450 | | /// @brief This table defines default values for interfaces for DHCPv6. |
451 | | const SimpleDefaults SimpleParser6::IFACE6_DEFAULTS = { |
452 | | { "re-detect", Element::boolean, "true" } |
453 | | }; |
454 | | |
455 | | /// @brief This table defines default values for dhcp-queue-control in DHCPv6. |
456 | | const SimpleDefaults SimpleParser6::DHCP_QUEUE_CONTROL6_DEFAULTS = { |
457 | | { "enable-queue", Element::boolean, "false"}, |
458 | | { "queue-type", Element::string, "kea-ring6"}, |
459 | | { "capacity", Element::integer, "64"} |
460 | | }; |
461 | | |
462 | | /// @brief This table defines default values for multi-threading in DHCPv6. |
463 | | const SimpleDefaults SimpleParser6::DHCP_MULTI_THREADING6_DEFAULTS = { |
464 | | { "enable-multi-threading", Element::boolean, "true" }, |
465 | | { "thread-pool-size", Element::integer, "0" }, |
466 | | { "packet-queue-size", Element::integer, "64" } |
467 | | }; |
468 | | |
469 | | /// @brief This defines default values for sanity checking for DHCPv6. |
470 | | const SimpleDefaults SimpleParser6::SANITY_CHECKS6_DEFAULTS = { |
471 | | { "lease-checks", Element::string, "warn" } |
472 | | }; |
473 | | |
474 | | /// @} |
475 | | |
476 | | /// --------------------------------------------------------------------------- |
477 | | /// --- end of default values ------------------------------------------------- |
478 | | /// --------------------------------------------------------------------------- |
479 | | |
480 | 13.5k | size_t SimpleParser6::setAllDefaults(ElementPtr global) { |
481 | 13.5k | size_t cnt = 0; |
482 | | |
483 | | // Set global defaults first. |
484 | 13.5k | cnt = setDefaults(global, GLOBAL6_DEFAULTS); |
485 | | |
486 | | // Now set the defaults for each specified option definition |
487 | 13.5k | ConstElementPtr option_defs = global->get("option-def"); |
488 | 13.5k | if (option_defs) { |
489 | 2 | cnt += setListDefaults(option_defs, OPTION6_DEF_DEFAULTS); |
490 | 2 | } |
491 | | |
492 | | // Set the defaults for option data |
493 | 13.5k | ConstElementPtr options = global->get("option-data"); |
494 | 13.5k | if (options) { |
495 | 5.60k | cnt += setListDefaults(options, OPTION6_DEFAULTS); |
496 | 5.60k | } |
497 | | |
498 | | // Now set the defaults for defined subnets |
499 | 13.5k | ConstElementPtr subnets = global->get("subnet6"); |
500 | 13.5k | if (subnets) { |
501 | 242 | cnt += setListDefaults(subnets, SUBNET6_DEFAULTS); |
502 | 242 | } |
503 | | |
504 | | // Set the defaults for interfaces config |
505 | 13.5k | ConstElementPtr ifaces_cfg = global->get("interfaces-config"); |
506 | 13.5k | if (ifaces_cfg) { |
507 | 5.73k | ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg); |
508 | 5.73k | cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS); |
509 | 5.73k | } |
510 | | |
511 | | // Set defaults for shared networks |
512 | 13.5k | ConstElementPtr shared = global->get("shared-networks"); |
513 | 13.5k | if (shared) { |
514 | 6.25k | for (auto const& net : shared->listValue()) { |
515 | | |
516 | 6.25k | cnt += setDefaults(net, SHARED_NETWORK6_DEFAULTS); |
517 | | |
518 | 6.25k | ConstElementPtr subs = net->get("subnet6"); |
519 | 6.25k | if (subs) { |
520 | 272 | cnt += setListDefaults(subs, SHARED_SUBNET6_DEFAULTS); |
521 | 272 | } |
522 | 6.25k | } |
523 | 99 | } |
524 | | |
525 | | // Set the defaults for dhcp-queue-control. If the element isn't there |
526 | | // we'll add it. |
527 | 13.5k | ConstElementPtr queue_control = global->get("dhcp-queue-control"); |
528 | 13.5k | ElementPtr mutable_cfg; |
529 | 13.5k | if (queue_control) { |
530 | 4.36k | mutable_cfg = boost::const_pointer_cast<Element>(queue_control); |
531 | 9.22k | } else { |
532 | 9.22k | mutable_cfg = Element::createMap(); |
533 | 9.22k | global->set("dhcp-queue-control", mutable_cfg); |
534 | 9.22k | } |
535 | | |
536 | 13.5k | cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS); |
537 | | |
538 | | // Set the defaults for multi-threading. If the element isn't there |
539 | | // we'll add it. |
540 | 13.5k | ConstElementPtr multi_threading = global->get("multi-threading"); |
541 | 13.5k | if (multi_threading) { |
542 | 4.36k | mutable_cfg = boost::const_pointer_cast<Element>(multi_threading); |
543 | 9.22k | } else { |
544 | 9.22k | mutable_cfg = Element::createMap(); |
545 | 9.22k | global->set("multi-threading", mutable_cfg); |
546 | 9.22k | } |
547 | | |
548 | 13.5k | cnt += setDefaults(mutable_cfg, DHCP_MULTI_THREADING6_DEFAULTS); |
549 | | |
550 | | // Set the defaults for sanity-checks. If the element isn't |
551 | | // there we'll add it. |
552 | 13.5k | ConstElementPtr sanity_checks = global->get("sanity-checks"); |
553 | 13.5k | if (sanity_checks) { |
554 | 4.36k | mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks); |
555 | 9.22k | } else { |
556 | 9.22k | mutable_cfg = Element::createMap(); |
557 | 9.22k | global->set("sanity-checks", mutable_cfg); |
558 | 9.22k | } |
559 | | |
560 | 13.5k | cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS); |
561 | | |
562 | 13.5k | return (cnt); |
563 | 13.5k | } |
564 | | |
565 | 13.5k | size_t SimpleParser6::deriveParameters(ElementPtr global) { |
566 | 13.5k | size_t cnt = 0; |
567 | | |
568 | | // Now derive global parameters into subnets. |
569 | 13.5k | ConstElementPtr subnets = global->get("subnet6"); |
570 | 13.5k | if (subnets) { |
571 | 1.29k | for (auto const& single_subnet : subnets->listValue()) { |
572 | 1.29k | cnt += SimpleParser::deriveParams(global, single_subnet, |
573 | 1.29k | INHERIT_TO_SUBNET6); |
574 | 1.29k | } |
575 | 241 | } |
576 | | |
577 | | // Deriving parameters for shared networks is a bit more involved. |
578 | | // First, the shared-network level derives from global, and then |
579 | | // subnets within derive from it. |
580 | 13.5k | ConstElementPtr shared = global->get("shared-networks"); |
581 | 13.5k | if (shared) { |
582 | 6.24k | for (auto const& net : shared->listValue()) { |
583 | | // First try to inherit the parameters from shared network, |
584 | | // if defined there. |
585 | | // Then try to inherit them from global. |
586 | 6.24k | cnt += SimpleParser::deriveParams(global, net, |
587 | 6.24k | INHERIT_TO_SUBNET6); |
588 | | |
589 | | // Now we need to go thrugh all the subnets in this net. |
590 | 6.24k | subnets = net->get("subnet6"); |
591 | 6.24k | if (subnets) { |
592 | 755 | for (auto const& single_subnet : subnets->listValue()) { |
593 | 755 | cnt += SimpleParser::deriveParams(net, single_subnet, |
594 | 755 | INHERIT_TO_SUBNET6); |
595 | 755 | } |
596 | 270 | } |
597 | 6.24k | } |
598 | 97 | } |
599 | | |
600 | 13.5k | return (cnt); |
601 | 13.5k | } |
602 | | |
603 | | } // namespace dhcp |
604 | | } // namespace isc |