Kea 3.1.0
translator_config.cc
Go to the documentation of this file.
1// Copyright (C) 2018-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
11#include <yang/yang_models.h>
12
13#include <sstream>
14
15using namespace std;
16using namespace isc::data;
17using namespace libyang;
18using namespace sysrepo;
19
20namespace isc {
21namespace yang {
22
23TranslatorConfig::TranslatorConfig(Session session, const string& model)
24 : Translator(session, model),
25 TranslatorControlSocket(session, model),
26 TranslatorDatabase(session, model),
27 TranslatorDatabases(session, model),
28 TranslatorOptionData(session, model),
29 TranslatorOptionDataList(session, model),
30 TranslatorOptionDef(session, model),
31 TranslatorOptionDefList(session, model),
32 TranslatorClass(session, model),
33 TranslatorClasses(session, model),
34 TranslatorPool(session, model),
35 TranslatorPools(session, model),
36 TranslatorPdPool(session, model),
37 TranslatorPdPools(session, model),
38 TranslatorHost(session, model),
39 TranslatorHosts(session, model),
40 TranslatorSubnet(session, model),
41 TranslatorSubnets(session, model),
42 TranslatorSharedNetwork(session, model),
43 TranslatorSharedNetworks(session, model),
44 TranslatorLogger(session, model),
45 TranslatorLoggers(session, model) {
46}
47
50 try {
51 if (model_ == IETF_DHCPV6_SERVER) {
52 return (getConfigIetf6());
53 } else if (model_ == KEA_DHCP4_SERVER) {
54 return (getConfigKea4());
55 } else if (model_ == KEA_DHCP6_SERVER) {
56 return (getConfigKea6());
57 }
58 } catch (Error const& ex) {
59 isc_throw(NetconfError, "getting config: " << ex.what());
60 }
62 "getConfig not implemented for the model: " << model_);
63}
64
69 result->set("Dhcp6", dhcp6);
70 string const xpath("/ietf-dhcpv6-server:server");
71 optional<DataNode> config;
72 try {
73 config = findXPath(xpath);
74 } catch (NetconfError const&) {
75 return result;
76 }
77
78 checkAndGetDiverging(dhcp6, *config, "subnet6", "server-config/network-ranges",
79 [&](DataNode const& data_node) -> ElementPtr const {
80 return getSubnets(data_node);
81 });
82
83 // Skip everything else.
84 return (result);
85}
86
91 result->set("Dhcp4", dhcp);
92 return (result);
93}
94
99 result->set("Dhcp6", dhcp);
100 return (result);
101}
102
103ElementPtr TranslatorConfig::getHook(DataNode const& data_node) {
104 ElementPtr hook_library(Element::createMap());
105 checkAndGetLeaf(hook_library, data_node, "library");
106 checkAndGetAndJsonifyLeaf(hook_library, data_node, "parameters");
107 return hook_library;
108}
109
111TranslatorConfig::getHooksKea(DataNode const& data_node) {
112 return getList(data_node, "hook-library", *this, &TranslatorConfig::getHook);
113}
114
116TranslatorConfig::getExpiredKea(DataNode const& data_node) {
118
119 checkAndGetLeaf(result, data_node, "flush-reclaimed-timer-wait-time");
120 checkAndGetLeaf(result, data_node, "hold-reclaimed-time");
121 checkAndGetLeaf(result, data_node, "max-reclaim-leases");
122 checkAndGetLeaf(result, data_node, "max-reclaim-time");
123 checkAndGetLeaf(result, data_node, "reclaim-timer-wait-time");
124 checkAndGetLeaf(result, data_node, "unwarned-reclaim-cycles");
125
126 return (result->empty() ? ElementPtr() : result);
127}
128
130TranslatorConfig::getDdnsKea(DataNode const& data_node) {
132
133 checkAndGetLeaf(result, data_node, "enable-updates");
134 checkAndGetLeaf(result, data_node, "max-queue-size");
135 checkAndGetLeaf(result, data_node, "ncr-format");
136 checkAndGetLeaf(result, data_node, "ncr-protocol");
137 checkAndGetLeaf(result, data_node, "sender-ip");
138 checkAndGetLeaf(result, data_node, "sender-port");
139 checkAndGetLeaf(result, data_node, "server-ip");
140 checkAndGetLeaf(result, data_node, "server-port");
141
142 checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
143
144 return (result->empty() ? ElementPtr() : result);
145}
146
148TranslatorConfig::getConfigControlKea(DataNode const& data_node) {
150 checkAndGetLeaf(result, data_node, "config-fetch-wait-time");
151 ConstElementPtr databases = getDatabases(data_node, "config-database");
152 if (databases && !databases->empty()) {
153 result->set("config-databases", databases);
154 }
155 return (result->empty() ? ElementPtr() : result);
156}
157
160 ElementPtr result;
161 optional<DataNode> const& interfaces_config_optional(config.findPath("interfaces-config"));
162 if (interfaces_config_optional) {
163 DataNode const interfaces_config(*interfaces_config_optional);
164 result = Element::createMap();
165
166 checkAndGetLeaf(result, interfaces_config, "dhcp-socket-type");
167 checkAndGetLeaf(result, interfaces_config, "interfaces");
168 checkAndGetLeaf(result, interfaces_config, "outbound-interface");
169 checkAndGetLeaf(result, interfaces_config, "re-detect");
170 checkAndGetLeaf(result, interfaces_config, "service-sockets-max-retries");
171 checkAndGetLeaf(result, interfaces_config, "service-sockets-require-all");
172 checkAndGetLeaf(result, interfaces_config, "service-sockets-retry-wait-time");
173
174 checkAndGetAndJsonifyLeaf(result, interfaces_config, "user-context");
175 }
176 return (result->empty() ? ElementPtr() : result);
177}
178
182
183 checkAndGetLeaf(result, data_node, "allocator");
184 checkAndGetLeaf(result, data_node, "cache-max-age");
185 checkAndGetLeaf(result, data_node, "cache-threshold");
186 checkAndGetLeaf(result, data_node, "calculate-tee-times");
187 checkAndGetLeaf(result, data_node, "dhcp4o6-port");
188 checkAndGetLeaf(result, data_node, "ddns-generated-prefix");
189 checkAndGetLeaf(result, data_node, "ddns-override-client-update");
190 checkAndGetLeaf(result, data_node, "ddns-override-no-update");
191 checkAndGetLeaf(result, data_node, "ddns-qualifying-suffix");
192 checkAndGetLeaf(result, data_node, "ddns-replace-client-name");
193 checkAndGetLeaf(result, data_node, "ddns-send-updates");
194 checkAndGetLeaf(result, data_node, "ddns-ttl-percent");
195 checkAndGetLeaf(result, data_node, "ddns-ttl");
196 checkAndGetLeaf(result, data_node, "ddns-ttl-min");
197 checkAndGetLeaf(result, data_node, "ddns-ttl-max");
198 checkAndGetLeaf(result, data_node, "ddns-update-on-renew");
199 checkAndGetLeaf(result, data_node, "ddns-use-conflict-resolution");
200 checkAndGetLeaf(result, data_node, "ddns-conflict-resolution-mode");
201 checkAndGetLeaf(result, data_node, "decline-probation-period");
202 checkAndGetLeaf(result, data_node, "early-global-reservations-lookup");
203 checkAndGetLeaf(result, data_node, "host-reservation-identifiers");
204 checkAndGetLeaf(result, data_node, "hostname-char-replacement");
205 checkAndGetLeaf(result, data_node, "hostname-char-set");
206 checkAndGetLeaf(result, data_node, "ip-reservations-unique");
207 checkAndGetLeaf(result, data_node, "max-valid-lifetime");
208 checkAndGetLeaf(result, data_node, "min-valid-lifetime");
209 checkAndGetLeaf(result, data_node, "parked-packet-limit");
210 checkAndGetLeaf(result, data_node, "rebind-timer");
211 checkAndGetLeaf(result, data_node, "renew-timer");
212 checkAndGetLeaf(result, data_node, "reservations-global");
213 checkAndGetLeaf(result, data_node, "reservations-in-subnet");
214 checkAndGetLeaf(result, data_node, "reservations-lookup-first");
215 checkAndGetLeaf(result, data_node, "reservations-out-of-pool");
216 checkAndGetLeaf(result, data_node, "server-tag");
217 checkAndGetLeaf(result, data_node, "statistic-default-sample-age");
218 checkAndGetLeaf(result, data_node, "statistic-default-sample-count");
219 checkAndGetLeaf(result, data_node, "store-extended-info");
220 checkAndGetLeaf(result, data_node, "t1-percent");
221 checkAndGetLeaf(result, data_node, "t2-percent");
222 checkAndGetLeaf(result, data_node, "valid-lifetime");
223
224 checkAndGetAndJsonifyLeaf(result, data_node, "dhcp-queue-control");
225 checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
226
227 ConstElementPtr classes = getClasses(data_node);
228 if (classes && !classes->empty()) {
229 result->set("client-classes", classes);
230 }
231
232 checkAndGet(result, data_node, "compatibility",
233 [&](DataNode const& node) -> ElementPtr const {
234 ElementPtr compatibility(Element::createMap());
235 checkAndGetLeaf(compatibility, node, "ignore-rai-link-selection");
236 checkAndGetLeaf(compatibility, node, "lenient-option-parsing");
237 return compatibility;
238 });
239
240 checkAndGet(result, data_node, "config-control",
241 [&](DataNode const& node) -> ElementPtr const {
242 return getConfigControlKea(node);
243 });
244
245 ConstElementPtr control_sockets = getControlSockets(data_node);
246 if (control_sockets && !control_sockets->empty()) {
247 result->set("control-sockets", control_sockets);
248 } else {
249 checkAndGet(result, data_node, "control-socket",
250 [&](DataNode const& node) -> ElementPtr const {
251 return getControlSocket(node);
252 });
253 }
254
255 checkAndGet(result, data_node, "dhcp-ddns",
256 [&](DataNode const& node) -> ElementPtr const {
257 return getDdnsKea(node);
258 });
259
260 checkAndGet(result, data_node, "expired-leases-processing",
261 [&](DataNode const& node) -> ElementPtr const {
262 return getExpiredKea(node);
263 });
264
265 ConstElementPtr hooks = getHooksKea(data_node);
266 if (hooks && !hooks->empty()) {
267 result->set("hooks-libraries", hooks);
268 }
269
270 ConstElementPtr const& hosts_databases(getDatabases(data_node, "hosts-database"));
271 if (hosts_databases && !hosts_databases->empty()) {
272 result->set("hosts-databases", hosts_databases);
273 }
274
275 checkAndGet(result, data_node, "lease-database",
276 [&](DataNode const& node) -> ElementPtr const {
277 return getDatabase(node);
278 });
279
280 ConstElementPtr loggers = getLoggers(data_node);
281 if (loggers && !loggers->empty()) {
282 result->set("loggers", loggers);
283 }
284
285 checkAndGet(result, data_node, "multi-threading",
286 [&](DataNode const& node) -> ElementPtr const {
287 ElementPtr multi_threading(Element::createMap());
288 checkAndGetLeaf(multi_threading, node, "enable-multi-threading");
289 checkAndGetLeaf(multi_threading, node, "packet-queue-size");
290 checkAndGetLeaf(multi_threading, node, "thread-pool-size");
291 return multi_threading;
292 });
293
294 ConstElementPtr options = getOptionDataList(data_node);
295 if (options) {
296 result->set("option-data", options);
297 }
298
299 ConstElementPtr defs = getOptionDefList(data_node);
300 if (defs) {
301 result->set("option-def", defs);
302 }
303
304 ConstElementPtr hosts = getHosts(data_node);
305 if (hosts) {
306 result->set("reservations", hosts);
307 }
308
309 ConstElementPtr networks = getSharedNetworks(data_node);
310 if (networks) {
311 result->set("shared-networks", networks);
312 }
313
314 checkAndGet(result, data_node, "sanity-checks",
315 [&](DataNode const& node) -> ElementPtr const {
316 ElementPtr sanity_checks = Element::createMap();
317 checkAndGetLeaf(sanity_checks, node, "extended-info-checks");
318 checkAndGetLeaf(sanity_checks, node, "lease-checks");
319 return sanity_checks;
320 });
321
322 return (result);
323}
324
327 string xpath = "/kea-dhcp4-server:config";
328 optional<DataNode> config_optional;
329 try {
330 config_optional = findXPath(xpath);
331 } catch (NetconfError const&) {
332 return ElementPtr();
333 }
334 DataNode const config(*config_optional);
336
337 // Handle DHCPv4 specific global parameters.
338 checkAndGetLeaf(result, config, "authoritative");
339 checkAndGetLeaf(result, config, "boot-file-name");
340 checkAndGetLeaf(result, config, "echo-client-id");
341 checkAndGetLeaf(result, config, "match-client-id");
342 checkAndGetLeaf(result, config, "next-server");
343 checkAndGetLeaf(result, config, "offer-lifetime");
344 checkAndGetLeaf(result, config, "server-hostname");
345 checkAndGetLeaf(result, config, "stash-agent-options");
346
347 checkAndGet(result, config, "compatibility",
348 [&](DataNode const& node) -> ElementPtr const {
349 // If it exists, add to the existing compatibility map created in getServerKeaDhcpCommon.
350 ConstElementPtr const_compatibility(result->get("compatibility"));
351 ElementPtr compatibility;
352 if (const_compatibility) {
353 compatibility = copy(const_compatibility);
354 } else {
355 compatibility = Element::createMap();
356 }
357
358 checkAndGetLeaf(compatibility, node, "exclude-first-last-24");
359 checkAndGetLeaf(compatibility, node, "ignore-dhcp-server-identifier");
360 return compatibility;
361 });
362
363 // Handle interfaces.
364 ElementPtr interfaces_config(getInterfacesKea(config));
365 if (interfaces_config) {
366 result->set("interfaces-config", interfaces_config);
367 }
368
369 // Handle subnets.
371 if (subnets) {
372 result->set("subnet4", subnets);
373 }
374
375 return (result);
376}
377
380 string xpath = "/kea-dhcp6-server:config";
381 optional<DataNode> config_optional;
382 try {
383 config_optional = findXPath(xpath);
384 } catch (NetconfError const&) {
385 return ElementPtr();
386 }
387 DataNode const config(*config_optional);
389
390 // Handle DHCPv6 specific global parameters.
391 checkAndGetLeaf(result, config, "data-directory");
392 checkAndGetLeaf(result, config, "mac-sources");
393 checkAndGetLeaf(result, config, "max-preferred-lifetime");
394 checkAndGetLeaf(result, config, "min-preferred-lifetime");
395 checkAndGetLeaf(result, config, "pd-allocator");
396 checkAndGetLeaf(result, config, "preferred-lifetime");
397 checkAndGetLeaf(result, config, "relay-supplied-options");
398
399 // Handle interfaces.
400 ElementPtr interfaces_config(getInterfacesKea(config));
401 if (interfaces_config) {
402 result->set("interfaces-config", interfaces_config);
403 }
404
405 // Handle server-id.
406 optional<DataNode> const& server_id_optional(config.findPath("server-id"));
407 if (server_id_optional) {
408 DataNode const server_id(*server_id_optional);
409 ElementPtr server_id_map(Element::createMap());
410 checkAndGetLeaf(server_id_map, server_id, "type");
411 checkAndGetLeaf(server_id_map, server_id, "identifier");
412 checkAndGetLeaf(server_id_map, server_id, "time");
413 checkAndGetLeaf(server_id_map, server_id, "htype");
414 checkAndGetLeaf(server_id_map, server_id, "enterprise-id");
415 checkAndGetLeaf(server_id_map, server_id, "persist");
416 checkAndGetAndJsonifyLeaf(server_id_map, server_id, "user-context");
417 if (!server_id_map->empty()) {
418 result->set("server-id", server_id_map);
419 }
420 }
421
422 // Handle subnets.
424 if (subnets) {
425 result->set("subnet6", subnets);
426 }
427
428 return (result);
429}
430
431void
433 try {
434 if (model_ == IETF_DHCPV6_SERVER) {
435 if (elem) {
437 setConfigIetf6(elem);
438 } else {
440 }
441 } else if (model_ == KEA_DHCP4_SERVER) {
442 if (elem) {
444 setConfigKea4(elem);
445 } else {
446 delConfigKea();
447 }
448 } else if (model_ == KEA_DHCP6_SERVER) {
449 if (elem) {
451 setConfigKea6(elem);
452 } else {
453 delConfigKea();
454 }
455 } else {
457 "setConfig not implemented for the model: " << model_);
458 }
459 } catch (Error const& ex) {
461 "setting config '" << elem->str()
462 << "': " << ex.what());
463 }
464}
465
466void
468 deleteItem("/" + model_ + ":server");
469}
470
471void
473 string xpath = "/" + model_ + ":server/server-config";
474 ConstElementPtr dhcp6 = elem->get("Dhcp6");
475 if (!dhcp6) {
476 isc_throw(BadValue, "no Dhcp6 entry in " << elem->str());
477 }
478
479 ConstElementPtr ranges = dhcp6->get("subnet6");
480 if (ranges && !ranges->empty()) {
481 setSubnets(xpath + "/network-ranges", ranges);
482 }
483
484 // Skip everything else.
485}
486
487void
489 deleteItem("/" + model_ + ":config");
490}
491
492void
494 ConstElementPtr dhcp = elem->get("Dhcp4");
495 if (dhcp) {
497 }
498}
499
500void
502 ConstElementPtr dhcp = elem->get("Dhcp6");
503 if (dhcp) {
505 }
506}
507
508void
510 ConstElementPtr elem) {
511 checkAndSetLeaf(elem, xpath, "allocator", LeafBaseType::String);
512 checkAndSetLeaf(elem, xpath, "cache-max-age", LeafBaseType::Uint32);
513 checkAndSetLeaf(elem, xpath, "cache-threshold", LeafBaseType::Dec64);
514 checkAndSetLeaf(elem, xpath, "calculate-tee-times", LeafBaseType::Bool);
515 checkAndSetLeaf(elem, xpath, "ddns-generated-prefix", LeafBaseType::String);
516 checkAndSetLeaf(elem, xpath, "ddns-override-client-update", LeafBaseType::Bool);
517 checkAndSetLeaf(elem, xpath, "ddns-override-no-update", LeafBaseType::Bool);
518 checkAndSetLeaf(elem, xpath, "ddns-qualifying-suffix", LeafBaseType::String);
519 checkAndSetLeaf(elem, xpath, "ddns-replace-client-name", LeafBaseType::String);
520 checkAndSetLeaf(elem, xpath, "ddns-send-updates", LeafBaseType::Bool);
521 checkAndSetLeaf(elem, xpath, "ddns-ttl-percent", LeafBaseType::Dec64);
522 checkAndSetLeaf(elem, xpath, "ddns-ttl", LeafBaseType::Uint32);
523 checkAndSetLeaf(elem, xpath, "ddns-ttl-min", LeafBaseType::Uint32);
524 checkAndSetLeaf(elem, xpath, "ddns-ttl-max", LeafBaseType::Uint32);
525 checkAndSetLeaf(elem, xpath, "ddns-update-on-renew", LeafBaseType::Bool);
526 checkAndSetLeaf(elem, xpath, "ddns-use-conflict-resolution", LeafBaseType::Bool);
527 checkAndSetLeaf(elem, xpath, "ddns-conflict-resolution-mode", LeafBaseType::Enum);
528 checkAndSetLeaf(elem, xpath, "dhcp4o6-port", LeafBaseType::Uint16);
529 checkAndSetLeaf(elem, xpath, "decline-probation-period", LeafBaseType::Uint32);
530 checkAndSetLeaf(elem, xpath, "early-global-reservations-lookup", LeafBaseType::Bool);
531 checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String);
532 checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
533 checkAndSetLeaf(elem, xpath, "ip-reservations-unique", LeafBaseType::Bool);
534 checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
535 checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
536 checkAndSetLeaf(elem, xpath, "parked-packet-limit", LeafBaseType::Uint32);
537 checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32);
538 checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
539 checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool);
540 checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool);
541 checkAndSetLeaf(elem, xpath, "reservations-lookup-first", LeafBaseType::Bool);
542 checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool);
543 checkAndSetLeaf(elem, xpath, "server-tag", LeafBaseType::String);
544 checkAndSetLeaf(elem, xpath, "statistic-default-sample-age", LeafBaseType::Uint32);
545 checkAndSetLeaf(elem, xpath, "statistic-default-sample-count", LeafBaseType::Uint32);
546 checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool);
547 checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64);
548 checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64);
549 checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
550
551 checkAndSetLeafList(elem, xpath, "host-reservation-identifiers", LeafBaseType::Enum);
552
553 checkAndStringifyAndSetLeaf(elem, xpath, "dhcp-queue-control");
554
555 checkAndSetUserContext(elem, xpath);
556
557 ConstElementPtr classes = elem->get("client-classes");
558 if (classes && !classes->empty()) {
559 setClasses(xpath, classes);
560 }
561
562 ConstElementPtr compatibility(elem->get("compatibility"));
563 if (compatibility) {
564 checkAndSetLeaf(compatibility, xpath + "/compatibility", "ignore-rai-link-selection", LeafBaseType::Bool);
565 checkAndSetLeaf(compatibility, xpath + "/compatibility", "lenient-option-parsing", LeafBaseType::Bool);
566 }
567
568 ConstElementPtr config_ctrl = elem->get("config-control");
569 if (config_ctrl && !config_ctrl->empty()) {
570 checkAndSetLeaf(config_ctrl, xpath + "/config-control", "config-fetch-wait-time", LeafBaseType::Uint32);
571 ConstElementPtr config_databases = config_ctrl->get("config-databases");
572 if (config_databases && !config_databases->empty()) {
573 setDatabases(xpath + "/config-control/config-database", config_databases);
574 }
575 }
576
577 ConstElementPtr control_sockets = elem->get("control-sockets");
578 if (control_sockets && !control_sockets->empty()) {
579 setControlSockets(xpath + "/control-sockets", control_sockets);
580 } else {
581 ConstElementPtr control_socket = elem->get("control-socket");
582 if (control_socket && !control_socket->empty()) {
583 setControlSocket(xpath + "/control-socket", control_socket);
584 }
585 }
586
587 ConstElementPtr ddns = elem->get("dhcp-ddns");
588 if (ddns) {
589 string const ddns_xpath(xpath + "/dhcp-ddns");
590 checkAndSetLeaf(ddns, ddns_xpath, "enable-updates", LeafBaseType::Bool);
591 checkAndSetLeaf(ddns, ddns_xpath, "max-queue-size", LeafBaseType::Uint32);
592 checkAndSetLeaf(ddns, ddns_xpath, "ncr-format", LeafBaseType::Enum);
593 checkAndSetLeaf(ddns, ddns_xpath, "ncr-protocol", LeafBaseType::Enum);
594 checkAndSetLeaf(ddns, ddns_xpath, "sender-ip", LeafBaseType::String);
595 checkAndSetLeaf(ddns, ddns_xpath, "sender-port", LeafBaseType::Uint16);
596 checkAndSetLeaf(ddns, ddns_xpath, "server-ip", LeafBaseType::String);
597 checkAndSetLeaf(ddns, ddns_xpath, "server-port", LeafBaseType::Uint16);
598 checkAndSetUserContext(ddns, ddns_xpath);
599 }
600
601 ConstElementPtr expired = elem->get("expired-leases-processing");
602 if (expired) {
603 string const expired_xpath(xpath + "/expired-leases-processing");
604 checkAndSetLeaf(expired, expired_xpath, "flush-reclaimed-timer-wait-time", LeafBaseType::Uint32);
605 checkAndSetLeaf(expired, expired_xpath, "hold-reclaimed-time", LeafBaseType::Uint32);
606 checkAndSetLeaf(expired, expired_xpath, "max-reclaim-leases", LeafBaseType::Uint32);
607 checkAndSetLeaf(expired, expired_xpath, "max-reclaim-time", LeafBaseType::Uint32);
608 checkAndSetLeaf(expired, expired_xpath, "reclaim-timer-wait-time", LeafBaseType::Uint32);
609 checkAndSetLeaf(expired, expired_xpath, "unwarned-reclaim-cycles", LeafBaseType::Uint32);
610 }
611
612 ConstElementPtr hook_libs = elem->get("hooks-libraries");
613 if (hook_libs) {
614 for (ElementPtr const& lib : hook_libs->listValue()) {
615 ConstElementPtr name = lib->get("library");
616 if (!name) {
617 continue;
618 }
619 ostringstream hook_lib;
620 hook_lib << xpath << "/hook-library[library='"
621 << name->stringValue() << "']";
622 string const hook_xpath(hook_lib.str());
623 setItem(hook_xpath, ElementPtr(), LeafBaseType::Unknown);
624 checkAndStringifyAndSetLeaf(lib, hook_xpath, "parameters");
625 }
626 }
627
628 ConstElementPtr hosts_databases = elem->get("hosts-databases");
629 if (hosts_databases && !hosts_databases->empty()) {
630 setDatabases(xpath + "/hosts-database", hosts_databases);
631 }
632
633 ConstElementPtr database = elem->get("lease-database");
634 if (database && !database->empty()) {
635 setDatabase(xpath + "/lease-database", database, /* has_mandatory_key = */ false);
636 }
637
638 ConstElementPtr loggers = elem->get("loggers");
639 if (loggers) {
640 setLoggers(xpath, loggers);
641 }
642
643 ConstElementPtr multi_threading(elem->get("multi-threading"));
644 if (multi_threading) {
645 string const mt_xpath(xpath + "/multi-threading");
646 checkAndSetLeaf(multi_threading, mt_xpath, "enable-multi-threading", LeafBaseType::Bool);
647 checkAndSetLeaf(multi_threading, mt_xpath, "packet-queue-size", LeafBaseType::Uint32);
648 checkAndSetLeaf(multi_threading, mt_xpath, "thread-pool-size", LeafBaseType::Uint32);
649 }
650
651 ConstElementPtr options = elem->get("option-data");
652 if (options && !options->empty()) {
653 setOptionDataList(xpath, options);
654 }
655
656 ConstElementPtr defs = elem->get("option-def");
657 if (defs && !defs->empty()) {
658 setOptionDefList(xpath, defs);
659 }
660
661 ConstElementPtr hosts = elem->get("reservations");
662 if (hosts && !hosts->empty()) {
663 setHosts(xpath, hosts);
664 }
665
666 ConstElementPtr sanity = elem->get("sanity-checks");
667 if (sanity) {
668 checkAndSetLeaf(sanity, xpath + "/sanity-checks", "extended-info-checks", LeafBaseType::Enum);
669 checkAndSetLeaf(sanity, xpath + "/sanity-checks", "lease-checks", LeafBaseType::Enum);
670 }
671
672 ConstElementPtr networks = elem->get("shared-networks");
673 if (networks && !networks->empty()) {
674 setSharedNetworks(xpath, networks);
675 }
676}
677
678void
680 string xpath = "/kea-dhcp4-server:config";
681
682 setServerKeaDhcpCommon(xpath, elem);
683
684 checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool);
685 checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String);
686 checkAndSetLeaf(elem, xpath, "echo-client-id", LeafBaseType::Bool);
687 checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool);
688 checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String);
689 checkAndSetLeaf(elem, xpath, "offer-lifetime", LeafBaseType::Uint32);
690 checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String);
691 checkAndSetLeaf(elem, xpath, "stash-agent-options", LeafBaseType::Bool);
692
693 ConstElementPtr compatibility(elem->get("compatibility"));
694 if (compatibility) {
695 checkAndSetLeaf(compatibility, xpath + "/compatibility", "exclude-first-last-24", LeafBaseType::Bool);
696 checkAndSetLeaf(compatibility, xpath + "/compatibility", "ignore-dhcp-server-identifier", LeafBaseType::Bool);
697 }
698
699 ConstElementPtr if_config = elem->get("interfaces-config");
700 if (if_config) {
701 string const if_cfg_xpath(xpath + "/interfaces-config");
702 checkAndSetLeaf(if_config, if_cfg_xpath, "dhcp-socket-type", LeafBaseType::Enum);
703 checkAndSetLeaf(if_config, if_cfg_xpath, "outbound-interface", LeafBaseType::Enum);
704 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32);
705 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
706 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32);
707 checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool);
708 checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String);
709 checkAndSetUserContext(if_config, if_cfg_xpath);
710 }
711
712 ConstElementPtr subnets = elem->get("subnet4");
713 if (subnets) {
714 setSubnets(xpath, subnets);
715 }
716}
717
718void
720 string xpath = "/kea-dhcp6-server:config";
721
722 setServerKeaDhcpCommon(xpath, elem);
723
724 checkAndSetLeaf(elem, xpath, "data-directory", LeafBaseType::String);
725 checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32);
726 checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32);
727 checkAndSetLeaf(elem, xpath, "pd-allocator", LeafBaseType::String);
728 checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32);
729
730 checkAndSetLeafList(elem, xpath, "mac-sources", LeafBaseType::String);
731 checkAndSetLeafList(elem, xpath, "relay-supplied-options", LeafBaseType::String);
732
733 ConstElementPtr if_config = elem->get("interfaces-config");
734 if (if_config) {
735 string const if_cfg_xpath(xpath + "/interfaces-config");
736 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-max-retries", LeafBaseType::Uint32);
737 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-require-all", LeafBaseType::Bool);
738 checkAndSetLeaf(if_config, if_cfg_xpath, "service-sockets-retry-wait-time", LeafBaseType::Uint32);
739 checkAndSetLeaf(if_config, if_cfg_xpath, "re-detect", LeafBaseType::Bool);
740 checkAndSetLeafList(if_config, if_cfg_xpath, "interfaces", LeafBaseType::String);
741 checkAndSetUserContext(if_config, if_cfg_xpath);
742 }
743
744 ConstElementPtr server_id = elem->get("server-id");
745 if (server_id) {
746 string const srv_id_xpath(xpath + "/server-id");
747 checkAndSetLeaf(server_id, srv_id_xpath, "type", LeafBaseType::Enum);
748 checkAndSetLeaf(server_id, srv_id_xpath, "identifier", LeafBaseType::String);
749 checkAndSetLeaf(server_id, srv_id_xpath, "time", LeafBaseType::Uint32);
750 checkAndSetLeaf(server_id, srv_id_xpath, "htype", LeafBaseType::Uint16);
751 checkAndSetLeaf(server_id, srv_id_xpath, "enterprise-id", LeafBaseType::Uint32);
752 checkAndSetLeaf(server_id, srv_id_xpath, "persist", LeafBaseType::Bool);
753 checkAndSetUserContext(server_id, srv_id_xpath);
754 }
755
756 ConstElementPtr subnets = elem->get("subnet6");
757 if (subnets) {
758 setSubnets(xpath, subnets);
759 }
760}
761
762} // namespace yang
763} // namespace isc
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
static void preProcess4(isc::data::ElementPtr config)
Pre process a DHCPv4 configuration.
static void preProcess6(isc::data::ElementPtr config)
Pre process a DHCPv6 configuration.
Client class translation between YANG and JSON.
isc::data::ElementPtr getClasses(libyang::DataNode const &data_node)
Translate client classes from YANG to JSON.
void setClasses(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set client classes from JSON to YANG.
TranslatorClasses(sysrepo::Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getConfigKea4()
getConfig for kea-dhcp4-server.
isc::data::ElementPtr getHook(libyang::DataNode const &data_node)
void setServerKeaDhcpCommon(const std::string &xpath, isc::data::ConstElementPtr elem)
setServer common part for kea-dhcp[46]-server:config.
void delConfigKea()
delConfig for kea-dhcp[46]-server.
isc::data::ElementPtr getExpiredKea(libyang::DataNode const &data_node)
Retrieves expired leases processing parameters from sysrepo.
isc::data::ElementPtr getServerKeaDhcp4()
getServer for kea-dhcp4-server:config.
void setConfigKea6(isc::data::ConstElementPtr elem)
setConfig for kea-dhcp6-server.
TranslatorConfig(sysrepo::Session session, const std::string &model)
Constructor.
void setConfigIetf6(isc::data::ConstElementPtr elem)
setConfig for ietf-dhcpv6-server.
isc::data::ElementPtr getDdnsKea(libyang::DataNode const &data_node)
Retrieves DDNS configuration from sysrepo.
isc::data::ElementPtr getInterfacesKea(libyang::DataNode const &data_node)
Retrieves interfaces configuration from sysrepo.
void setConfigKea4(isc::data::ConstElementPtr elem)
setConfig for kea-dhcp[46]-server.
void setConfig(isc::data::ElementPtr elem)
Translate and set the DHCP server configuration from JSON to YANG.
isc::data::ElementPtr getConfigControlKea(libyang::DataNode const &data_node)
Retrieves configuration control from sysrepo.
void setServerKeaDhcp6(isc::data::ConstElementPtr elem)
setServer for kea-dhcp6-server:config.
isc::data::ElementPtr getConfigKea6()
getConfig for kea-dhcp6-server.
isc::data::ElementPtr getConfigIetf6()
getConfig for ietf-dhcpv6-server.
void setServerKeaDhcp4(isc::data::ConstElementPtr elem)
setServer for kea-dhcp4-server:config.
isc::data::ElementPtr getServerKeaDhcp6()
getServer for kea-dhcp6-server:config.
void delConfigIetf6()
delConfig for ietf-dhcpv6-server.
isc::data::ElementPtr getConfig()
Translate the whole DHCP server configuration from YANG to JSON.
isc::data::ElementPtr getServerKeaDhcpCommon(libyang::DataNode const &data_node)
getServer common part for kea-dhcp[46]-server:config.
isc::data::ElementPtr getHooksKea(libyang::DataNode const &data_node)
Retrieves hooks configuration from sysrepo.
void setControlSocket(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control socket from JSON to YANG.
TranslatorControlSocket(sysrepo::Session session, const std::string &model)
Constructor.
void setControlSockets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control sockets from JSON to YANG.
isc::data::ElementPtr getControlSocket(libyang::DataNode const &data_node)
Translate a control socket from YANG to JSON.
isc::data::ElementPtr getControlSockets(libyang::DataNode const &data_node)
Translate a control socket from YANG to JSON.
Database access translation between YANG and JSON.
isc::data::ElementPtr getDatabase(libyang::DataNode const &data_node)
Translate a database access from YANG to JSON.
void setDatabase(const std::string &xpath, isc::data::ConstElementPtr elem, bool has_mandatory_key)
Translate and set database access from JSON to YANG.
void setDatabases(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set database accesses from JSON to YANG.
isc::data::ElementPtr getDatabases(libyang::DataNode const &data_node, std::string const &xpath)
Translate database accesses from YANG to JSON.
TranslatorDatabases(sysrepo::Session session, const std::string &model)
Constructor.
Translation between YANG and JSON for a single host reservation.
A translator class for converting host reservations list between YANG and JSON.
isc::data::ElementPtr getHosts(libyang::DataNode const &data_node)
Translate host reservations from YANG to JSON.
void setHosts(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set (address) host reservations from JSON to YANG.
Logger translation between YANG and JSON.
void setLoggers(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set loggers from JSON to YANG.
isc::data::ConstElementPtr getLoggers(libyang::DataNode const &data_node)
Translate loggers from YANG to JSON.
TranslatorLoggers(sysrepo::Session session, const std::string &model)
Constructor.
A translator class for converting an option data list between YANG and JSON.
void setOptionDataList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option data list from JSON to YANG.
isc::data::ConstElementPtr getOptionDataList(libyang::DataNode const &data_node)
Translate option data list from YANG to JSON.
Option data translation between YANG and JSON.
Currently supports kea-dhcp[46]-server models.
isc::data::ConstElementPtr getOptionDefList(libyang::DataNode const &data_node)
Translate option definition list from YANG to JSON.
void setOptionDefList(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set option definition list from JSON to YANG.
Option definition translation between YANG and JSON.
Prefix delegation pool translation between YANG and JSON.
A translator class for converting a pd-pool list between YANG and JSON.
A translator class for converting a pool between YANG and JSON.
A translator class for converting pools between YANG and JSON.
Shared network translation between YANG and JSON.
TranslatorSharedNetworks(sysrepo::Session session, const std::string &model)
Constructor.
isc::data::ElementPtr getSharedNetworks(libyang::DataNode const &data_node)
Translate shared networks from YANG to JSON.
void setSharedNetworks(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set shared networks from JSON to YANG.
Subnet (aka network range) translation between YANG and JSON.
A translator class for converting a subnet list between YANG and JSON.
void setSubnets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set subnets from JSON to YANG.
isc::data::ElementPtr getSubnets(libyang::DataNode const &data_node)
Get and translate subnets from YANG to JSON.
Between YANG and JSON translator class for basic values.
Definition translator.h:23
isc::data::ElementPtr getList(libyang::DataNode const &data_node, std::string const &xpath, T &t, isc::data::ElementPtr(T::*f)(libyang::DataNode const &)) const
Retrieve a list as ElementPtr from sysrepo from a certain xpath.
Definition translator.h:274
void checkAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
Definition translator.cc:63
void checkAndGet(isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &xpath, T translate) const
Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {st...
Definition translator.h:44
libyang::DataNode findXPath(std::string const &xpath) const
Retrieves a YANG data node by xpath.
void checkAndGetLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
Definition translator.cc:32
void checkAndSetUserContext(isc::data::ConstElementPtr const &from, std::string const &xpath)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
Definition translator.cc:99
void deleteItem(const std::string &xpath)
Delete basic value from YANG.
void setItem(const std::string &xpath, isc::data::ConstElementPtr const elem, libyang::LeafBaseType const type)
Translate and set basic value from JSON to YANG.
std::string model_
The model.
Definition translator.h:427
void checkAndGetAndJsonifyLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, const std::string &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node,...
Definition translator.cc:53
void checkAndSetLeafList(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath as a leaf-list.
Definition translator.cc:86
void checkAndStringifyAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void checkAndGetDiverging(isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &key, std::string const &xpath, T translate) const
Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {st...
Definition translator.h:71
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
Definition data.cc:1420
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
Defines the logger used by the top-level component of kea-lfc.
Generic NETCONF error.