Kea 2.2.0
dhcp6/json_config_parser.cc
Go to the documentation of this file.
1// Copyright (C) 2012-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
10#include <cc/data.h>
12#include <config/command_mgr.h>
15#include <dhcp6/dhcp6_log.h>
16#include <dhcp6/dhcp6_srv.h>
17#include <dhcp/libdhcp++.h>
18#include <dhcp/iface_mgr.h>
20#include <dhcpsrv/cfg_option.h>
21#include <dhcpsrv/cfgmgr.h>
22#include <dhcpsrv/db_type.h>
37#include <dhcpsrv/pool.h>
38#include <dhcpsrv/subnet.h>
39#include <dhcpsrv/timer_mgr.h>
40#include <hooks/hooks_manager.h>
41#include <hooks/hooks_parser.h>
42#include <log/logger_support.h>
44#include <util/encode/hex.h>
46#include <util/strutil.h>
47#include <util/triplet.h>
48
49#include <boost/algorithm/string.hpp>
50#include <boost/foreach.hpp>
51#include <boost/lexical_cast.hpp>
52#include <boost/scoped_ptr.hpp>
53#include <boost/shared_ptr.hpp>
54
55#include <iostream>
56#include <limits>
57#include <map>
58#include <netinet/in.h>
59#include <vector>
60
61#include <stdint.h>
62
63using namespace std;
64using namespace isc;
65using namespace isc::data;
66using namespace isc::dhcp;
67using namespace isc::asiolink;
68using namespace isc::hooks;
69using namespace isc::process;
70using namespace isc::config;
71using namespace isc::util;
72
73namespace {
74
79void dirExists(const string& dir_path) {
80 struct stat statbuf;
81 if (stat(dir_path.c_str(), &statbuf) < 0) {
82 isc_throw(BadValue, "Bad directory '" << dir_path
83 << "': " << strerror(errno));
84 }
85 if ((statbuf.st_mode & S_IFMT) != S_IFDIR) {
86 isc_throw(BadValue, "'" << dir_path << "' is not a directory");
87 }
88}
89
98class RSOOListConfigParser : public isc::data::SimpleParser {
99public:
100
108 void parse(const SrvConfigPtr& cfg, const isc::data::ConstElementPtr& value) {
109 try {
110 BOOST_FOREACH(ConstElementPtr source_elem, value->listValue()) {
111 std::string option_str = source_elem->stringValue();
112 // This option can be either code (integer) or name. Let's try code first
113 int64_t code = 0;
114 try {
115 code = boost::lexical_cast<int64_t>(option_str);
116 // Protect against the negative value and too high value.
117 if (code < 0) {
118 isc_throw(BadValue, "invalid option code value specified '"
119 << option_str << "', the option code must be a"
120 " non-negative value");
121
122 } else if (code > std::numeric_limits<uint16_t>::max()) {
123 isc_throw(BadValue, "invalid option code value specified '"
124 << option_str << "', the option code must not be"
125 " greater than '" << std::numeric_limits<uint16_t>::max()
126 << "'");
127 }
128
129 } catch (const boost::bad_lexical_cast &) {
130 // Oh well, it's not a number
131 }
132
133 if (!code) {
134 const OptionDefinitionPtr def = LibDHCP::getOptionDef(DHCP6_OPTION_SPACE,
135 option_str);
136 if (def) {
137 code = def->getCode();
138 } else {
139 isc_throw(BadValue, "unable to find option code for the "
140 " specified option name '" << option_str << "'"
141 " while parsing the list of enabled"
142 " relay-supplied-options");
143 }
144 }
145 cfg->getCfgRSOO()->enable(code);
146 }
147 } catch (const std::exception& ex) {
148 // Rethrow exception with the appended position of the parsed
149 // element.
150 isc_throw(DhcpConfigError, ex.what() << " (" << value->getPosition() << ")");
151 }
152 }
153};
154
163class Dhcp6ConfigParser : public isc::data::SimpleParser {
164public:
165
180 void parse(const SrvConfigPtr& cfg, const ConstElementPtr& global) {
181
182 // Set the data directory for server id file.
183 if (global->contains("data-directory")) {
184 CfgMgr::instance().setDataDir(getString(global, "data-directory"),
185 false);
186 }
187
188 // Set the probation period for decline handling.
189 uint32_t probation_period =
190 getUint32(global, "decline-probation-period");
191 cfg->setDeclinePeriod(probation_period);
192
193 // Set the DHCPv4-over-DHCPv6 interserver port.
194 uint16_t dhcp4o6_port = getUint16(global, "dhcp4o6-port");
195 cfg->setDhcp4o6Port(dhcp4o6_port);
196
197 // Set the global user context.
198 ConstElementPtr user_context = global->get("user-context");
199 if (user_context) {
200 cfg->setContext(user_context);
201 }
202
203 // Set the server's logical name
204 std::string server_tag = getString(global, "server-tag");
205 cfg->setServerTag(server_tag);
206 }
207
219 void parseEarly(const SrvConfigPtr& cfg, const ConstElementPtr& global) {
220 // Set ip-reservations-unique flag.
221 bool ip_reservations_unique = getBoolean(global, "ip-reservations-unique");
222 cfg->setIPReservationsUnique(ip_reservations_unique);
223 }
224
231 void
232 copySubnets6(const CfgSubnets6Ptr& dest, const CfgSharedNetworks6Ptr& from) {
233
234 if (!dest || !from) {
235 isc_throw(BadValue, "Unable to copy subnets: at least one pointer is null");
236 }
237
238 const SharedNetwork6Collection* networks = from->getAll();
239 if (!networks) {
240 // Nothing to copy. Technically, it should return a pointer to empty
241 // container, but let's handle null pointer as well.
242 return;
243 }
244
245 // Let's go through all the networks one by one
246 for (auto net = networks->begin(); net != networks->end(); ++net) {
247
248 // For each network go through all the subnets in it.
249 const Subnet6SimpleCollection* subnets = (*net)->getAllSubnets();
250 if (!subnets) {
251 // Shared network without subnets it weird, but we decided to
252 // accept such configurations.
253 continue;
254 }
255
256 // For each subnet, add it to a list of regular subnets.
257 for (auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
258 dest->add(*subnet);
259 }
260 }
261 }
262
271 void
272 sanityChecks(const SrvConfigPtr& cfg, const ConstElementPtr& global) {
273
275 cfg->sanityChecksLifetime("preferred-lifetime");
276 cfg->sanityChecksLifetime("valid-lifetime");
277
279 const SharedNetwork6Collection* networks = cfg->getCfgSharedNetworks6()->getAll();
280 if (networks) {
281 sharedNetworksSanityChecks(*networks, global->get("shared-networks"));
282 }
283 }
284
291 void
292 sharedNetworksSanityChecks(const SharedNetwork6Collection& networks,
293 ConstElementPtr json) {
294
296 if (!json) {
297 // No json? That means that the shared-networks was never specified
298 // in the config.
299 return;
300 }
301
302 // Used for names uniqueness checks.
303 std::set<string> names;
304
305 // Let's go through all the networks one by one
306 for (auto net = networks.begin(); net != networks.end(); ++net) {
307 string txt;
308
309 // Let's check if all subnets have either the same interface
310 // or don't have the interface specified at all.
311 string iface = (*net)->getIface();
312
313 const Subnet6SimpleCollection* subnets = (*net)->getAllSubnets();
314 if (subnets) {
315
316 bool rapid_commit = false;
317
318 // For each subnet, add it to a list of regular subnets.
319 for (auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
320
321 // Rapid commit must either be enabled or disabled in all subnets
322 // in the shared network.
323 if (subnet == subnets->begin()) {
324 // If this is the first subnet, remember the value.
325 rapid_commit = (*subnet)->getRapidCommit();
326 } else {
327 // Ok, this is the second or following subnets. The value
328 // must match what was set in the first subnet.
329 if (rapid_commit != (*subnet)->getRapidCommit()) {
330 isc_throw(DhcpConfigError, "All subnets in a shared network "
331 "must have the same rapid-commit value. Subnet "
332 << (*subnet)->toText()
333 << " has specified rapid-commit "
334 << ( (*subnet)->getRapidCommit() ? "true" : "false")
335 << ", but earlier subnet in the same shared-network"
336 << " or the shared-network itself used rapid-commit "
337 << (rapid_commit ? "true" : "false"));
338 }
339 }
340
341 if (iface.empty()) {
342 iface = (*subnet)->getIface();
343 continue;
344 }
345
346 if ((*subnet)->getIface().empty()) {
347 continue;
348 }
349
350 if ((*subnet)->getIface() != iface) {
351 isc_throw(DhcpConfigError, "Subnet " << (*subnet)->toText()
352 << " has specified interface " << (*subnet)->getIface()
353 << ", but earlier subnet in the same shared-network"
354 << " or the shared-network itself used " << iface);
355 }
356
357 // Let's collect the subnets in case we later find out the
358 // subnet doesn't have a mandatory name.
359 txt += (*subnet)->toText() + " ";
360 }
361 }
362
363 // Next, let's check name of the shared network.
364 if ((*net)->getName().empty()) {
365 isc_throw(DhcpConfigError, "Shared-network with subnets "
366 << txt << " is missing mandatory 'name' parameter");
367 }
368
369 // Is it unique?
370 if (names.find((*net)->getName()) != names.end()) {
371 isc_throw(DhcpConfigError, "A shared-network with "
372 "name " << (*net)->getName() << " defined twice.");
373 }
374 names.insert((*net)->getName());
375
376 }
377 }
378};
379
380} // anonymous namespace
381
382namespace isc {
383namespace dhcp {
384
393 // Get new socket configuration.
394 ConstElementPtr sock_cfg =
395 CfgMgr::instance().getStagingCfg()->getControlSocketInfo();
396
397 // Get current socket configuration.
398 ConstElementPtr current_sock_cfg =
399 CfgMgr::instance().getCurrentCfg()->getControlSocketInfo();
400
401 // Determine if the socket configuration has changed. It has if
402 // both old and new configuration is specified but respective
403 // data elements aren't equal.
404 bool sock_changed = (sock_cfg && current_sock_cfg &&
405 !sock_cfg->equals(*current_sock_cfg));
406
407 // If the previous or new socket configuration doesn't exist or
408 // the new configuration differs from the old configuration we
409 // close the existing socket and open a new socket as appropriate.
410 // Note that closing an existing socket means the client will not
411 // receive the configuration result.
412 if (!sock_cfg || !current_sock_cfg || sock_changed) {
413 // Close the existing socket (if any).
415
416 if (sock_cfg) {
417 // This will create a control socket and install the external
418 // socket in IfaceMgr. That socket will be monitored when
419 // Dhcp4Srv::receivePacket() calls IfaceMgr::receive4() and
420 // callback in CommandMgr will be called, if necessary.
422 }
423 }
424}
425
428 bool check_only) {
429 if (!config_set) {
431 string("Can't parse NULL config"));
432 return (answer);
433 }
434
436 .arg(server.redactConfig(config_set)->str());
437
438 // Before starting any subnet operations, let's reset the subnet-id counter,
439 // so newly recreated configuration starts with first subnet-id equal 1.
441
442 // Close DHCP sockets and remove any existing timers.
443 if (!check_only) {
445 TimerMgr::instance()->unregisterTimers();
446 server.discardPackets();
447 server.getCBControl()->reset();
448 }
449
450 // Revert any runtime option definitions configured so far and not committed.
452 // Let's set empty container in case a user hasn't specified any configuration
453 // for option definitions. This is equivalent to committing empty container.
455
456 // Print the list of known backends.
458
459 // Answer will hold the result.
460 ConstElementPtr answer;
461 // Rollback informs whether error occurred and original data
462 // have to be restored to global storages.
463 bool rollback = false;
464 // Global parameter name in case of an error.
465 string parameter_name;
466 ElementPtr mutable_cfg;
467 SrvConfigPtr srv_config;
468 try {
469 // Get the staging configuration.
470 srv_config = CfgMgr::instance().getStagingCfg();
471
472 // This is a way to convert ConstElementPtr to ElementPtr.
473 // We need a config that can be edited, because we will insert
474 // default values and will insert derived values as well.
475 mutable_cfg = boost::const_pointer_cast<Element>(config_set);
476
477 // Relocate dhcp-ddns parameters that have moved to global scope.
478 // Rule is that a global value overrides the dhcp-ddns value, so
479 // we need to do this before we apply global defaults.
480 // Note this is done for backward compatibility.
481 srv_config->moveDdnsParams(mutable_cfg);
482
483 // Move from reservation mode to new reservations flags.
484 // @todo add warning
486
487 // Set all default values if not specified by the user.
489
490 // And now derive (inherit) global parameters to subnets, if not specified.
492
493 // In principle we could have the following code structured as a series
494 // of long if else if clauses. That would give a marginal performance
495 // boost, but would make the code less readable. We had serious issues
496 // with the parser code debugability, so I decided to keep it as a
497 // series of independent ifs.
498
499 // This parser is used in several places.
500 Dhcp6ConfigParser global_parser;
501
502 // Apply global options in the staging config, e.g. ip-reservations-unique
503 global_parser.parseEarly(srv_config, mutable_cfg);
504
505 // Specific check for this global parameter.
506 ConstElementPtr data_directory = mutable_cfg->get("data-directory");
507 if (data_directory) {
508 parameter_name = "data-directory";
509 dirExists(data_directory->stringValue());
510 }
511
512 // We need definitions first
513 ConstElementPtr option_defs = mutable_cfg->get("option-def");
514 if (option_defs) {
515 parameter_name = "option-def";
516 OptionDefListParser parser(AF_INET6);
517 CfgOptionDefPtr cfg_option_def = srv_config->getCfgOptionDef();
518 parser.parse(cfg_option_def, option_defs);
519 }
520
521 ConstElementPtr option_datas = mutable_cfg->get("option-data");
522 if (option_datas) {
523 parameter_name = "option-data";
524 OptionDataListParser parser(AF_INET6);
525 CfgOptionPtr cfg_option = srv_config->getCfgOption();
526 parser.parse(cfg_option, option_datas);
527 }
528
529 ConstElementPtr mac_sources = mutable_cfg->get("mac-sources");
530 if (mac_sources) {
531 parameter_name = "mac-sources";
533 CfgMACSource& mac_source = srv_config->getMACSources();
534 parser.parse(mac_source, mac_sources);
535 }
536
537 ConstElementPtr control_socket = mutable_cfg->get("control-socket");
538 if (control_socket) {
539 parameter_name = "control-socket";
540 ControlSocketParser parser;
541 parser.parse(*srv_config, control_socket);
542 }
543
544 ConstElementPtr multi_threading = mutable_cfg->get("multi-threading");
545 if (multi_threading) {
546 parameter_name = "multi-threading";
548 parser.parse(*srv_config, multi_threading);
549 }
550
552 ConstElementPtr queue_control = mutable_cfg->get("dhcp-queue-control");
553 if (queue_control) {
554 parameter_name = "dhcp-queue-control";
556 srv_config->setDHCPQueueControl(parser.parse(queue_control));
557 }
558
560 ConstElementPtr reservations_lookup_first = mutable_cfg->get("reservations-lookup-first");
561 if (reservations_lookup_first) {
562 parameter_name = "reservations-lookup-first";
563 if (MultiThreadingMgr::instance().getMode()) {
565 }
566 srv_config->setReservationsLookupFirst(reservations_lookup_first->boolValue());
567 }
568
569 ConstElementPtr hr_identifiers =
570 mutable_cfg->get("host-reservation-identifiers");
571 if (hr_identifiers) {
572 parameter_name = "host-reservation-identifiers";
574 parser.parse(hr_identifiers);
575 }
576
577 ConstElementPtr server_id = mutable_cfg->get("server-id");
578 if (server_id) {
579 parameter_name = "server-id";
580 DUIDConfigParser parser;
581 const CfgDUIDPtr& cfg = srv_config->getCfgDUID();
582 parser.parse(cfg, server_id);
583 }
584
585 ConstElementPtr ifaces_config = mutable_cfg->get("interfaces-config");
586 if (ifaces_config) {
587 parameter_name = "interfaces-config";
588 IfacesConfigParser parser(AF_INET6, check_only);
589 CfgIfacePtr cfg_iface = srv_config->getCfgIface();
590 parser.parse(cfg_iface, ifaces_config);
591 }
592
593 ConstElementPtr sanity_checks = mutable_cfg->get("sanity-checks");
594 if (sanity_checks) {
595 parameter_name = "sanity-checks";
596 SanityChecksParser parser;
597 parser.parse(*srv_config, sanity_checks);
598 }
599
600 ConstElementPtr expiration_cfg =
601 mutable_cfg->get("expired-leases-processing");
602 if (expiration_cfg) {
603 parameter_name = "expired-leases-processing";
605 parser.parse(expiration_cfg);
606 }
607
608 // The hooks-libraries configuration must be parsed after parsing
609 // multi-threading configuration so that libraries are checked
610 // for multi-threading compatibility.
611 ConstElementPtr hooks_libraries = mutable_cfg->get("hooks-libraries");
612 if (hooks_libraries) {
613 parameter_name = "hooks-libraries";
614 HooksLibrariesParser hooks_parser;
615 HooksConfig& libraries = srv_config->getHooksConfig();
616 hooks_parser.parse(libraries, hooks_libraries);
617 libraries.verifyLibraries(hooks_libraries->getPosition());
618 }
619
620 // D2 client configuration.
621 D2ClientConfigPtr d2_client_cfg;
622
623 // Legacy DhcpConfigParser stuff below.
624 ConstElementPtr dhcp_ddns = mutable_cfg->get("dhcp-ddns");
625 if (dhcp_ddns) {
626 parameter_name = "dhcp-ddns";
627 // Apply defaults
630 d2_client_cfg = parser.parse(dhcp_ddns);
631 }
632
633 ConstElementPtr client_classes = mutable_cfg->get("client-classes");
634 if (client_classes) {
635 parameter_name = "client-classes";
637 ClientClassDictionaryPtr dictionary =
638 parser.parse(client_classes, AF_INET6);
639 srv_config->setClientClassDictionary(dictionary);
640 }
641
642 // Please move at the end when migration will be finished.
643 ConstElementPtr lease_database = mutable_cfg->get("lease-database");
644 if (lease_database) {
645 parameter_name = "lease-database";
646 db::DbAccessParser parser;
647 std::string access_string;
648 parser.parse(access_string, lease_database);
649 CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
650 cfg_db_access->setLeaseDbAccessString(access_string);
651 }
652
653 ConstElementPtr hosts_database = mutable_cfg->get("hosts-database");
654 if (hosts_database) {
655 parameter_name = "hosts-database";
656 db::DbAccessParser parser;
657 std::string access_string;
658 parser.parse(access_string, hosts_database);
659 CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
660 cfg_db_access->setHostDbAccessString(access_string);
661 }
662
663 ConstElementPtr hosts_databases = mutable_cfg->get("hosts-databases");
664 if (hosts_databases) {
665 parameter_name = "hosts-databases";
666 CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
667 for (auto it : hosts_databases->listValue()) {
668 db::DbAccessParser parser;
669 std::string access_string;
670 parser.parse(access_string, it);
671 cfg_db_access->setHostDbAccessString(access_string);
672 }
673 }
674
675 // Keep relative orders of shared networks and subnets.
676 ConstElementPtr shared_networks = mutable_cfg->get("shared-networks");
677 if (shared_networks) {
678 parameter_name = "shared-networks";
685 CfgSharedNetworks6Ptr cfg = srv_config->getCfgSharedNetworks6();
686 parser.parse(cfg, shared_networks);
687
688 // We also need to put the subnets it contains into normal
689 // subnets list.
690 global_parser.copySubnets6(srv_config->getCfgSubnets6(), cfg);
691 }
692
693 ConstElementPtr subnet6 = mutable_cfg->get("subnet6");
694 if (subnet6) {
695 parameter_name = "subnet6";
696 Subnets6ListConfigParser subnets_parser;
697 // parse() returns number of subnets parsed. We may log it one day.
698 subnets_parser.parse(srv_config, subnet6);
699 }
700
701 ConstElementPtr reservations = mutable_cfg->get("reservations");
702 if (reservations) {
703 parameter_name = "reservations";
704 HostCollection hosts;
706 parser.parse(SUBNET_ID_GLOBAL, reservations, hosts);
707 for (auto h = hosts.begin(); h != hosts.end(); ++h) {
708 srv_config->getCfgHosts()->add(*h);
709 }
710 }
711
712 ConstElementPtr config_control = mutable_cfg->get("config-control");
713 if (config_control) {
714 parameter_name = "config-control";
715 ConfigControlParser parser;
716 ConfigControlInfoPtr config_ctl_info = parser.parse(config_control);
717 CfgMgr::instance().getStagingCfg()->setConfigControlInfo(config_ctl_info);
718 }
719
720 ConstElementPtr rsoo_list = mutable_cfg->get("relay-supplied-options");
721 if (rsoo_list) {
722 parameter_name = "relay-supplied-options";
723 RSOOListConfigParser parser;
724 parser.parse(srv_config, rsoo_list);
725 }
726
727 ConstElementPtr compatibility = mutable_cfg->get("compatibility");
728 if (compatibility) {
729 for (auto kv : compatibility->mapValue()) {
730 if (kv.first == "lenient-option-parsing") {
731 CfgMgr::instance().getStagingCfg()->setLenientOptionParsing(
732 kv.second->boolValue());
733 }
734 }
735 }
736
737 // Make parsers grouping.
738 ConfigPair config_pair;
739 const std::map<std::string, ConstElementPtr>& values_map =
740 mutable_cfg->mapValue();
741
742 BOOST_FOREACH(config_pair, values_map) {
743
744 parameter_name = config_pair.first;
745
746 // These are converted to SimpleParser and are handled already above.
747 if ((config_pair.first == "data-directory") ||
748 (config_pair.first == "option-def") ||
749 (config_pair.first == "option-data") ||
750 (config_pair.first == "mac-sources") ||
751 (config_pair.first == "control-socket") ||
752 (config_pair.first == "multi-threading") ||
753 (config_pair.first == "dhcp-queue-control") ||
754 (config_pair.first == "host-reservation-identifiers") ||
755 (config_pair.first == "server-id") ||
756 (config_pair.first == "interfaces-config") ||
757 (config_pair.first == "sanity-checks") ||
758 (config_pair.first == "expired-leases-processing") ||
759 (config_pair.first == "hooks-libraries") ||
760 (config_pair.first == "dhcp-ddns") ||
761 (config_pair.first == "client-classes") ||
762 (config_pair.first == "lease-database") ||
763 (config_pair.first == "hosts-database") ||
764 (config_pair.first == "hosts-databases") ||
765 (config_pair.first == "subnet6") ||
766 (config_pair.first == "shared-networks") ||
767 (config_pair.first == "reservations") ||
768 (config_pair.first == "config-control") ||
769 (config_pair.first == "relay-supplied-options") ||
770 (config_pair.first == "loggers") ||
771 (config_pair.first == "compatibility")) {
772 continue;
773 }
774
775 // As of Kea 1.6.0 we have two ways of inheriting the global parameters.
776 // The old method is used in JSON configuration parsers when the global
777 // parameters are derived into the subnets and shared networks and are
778 // being treated as explicitly specified. The new way used by the config
779 // backend is the dynamic inheritance whereby each subnet and shared
780 // network uses a callback function to return global parameter if it
781 // is not specified at lower level. This callback uses configured globals.
782 // We deliberately include both default and explicitly specified globals
783 // so as the callback can access the appropriate global values regardless
784 // whether they are set to a default or other value.
785 if ( (config_pair.first == "renew-timer") ||
786 (config_pair.first == "rebind-timer") ||
787 (config_pair.first == "preferred-lifetime") ||
788 (config_pair.first == "min-preferred-lifetime") ||
789 (config_pair.first == "max-preferred-lifetime") ||
790 (config_pair.first == "valid-lifetime") ||
791 (config_pair.first == "min-valid-lifetime") ||
792 (config_pair.first == "max-valid-lifetime") ||
793 (config_pair.first == "decline-probation-period") ||
794 (config_pair.first == "dhcp4o6-port") ||
795 (config_pair.first == "server-tag") ||
796 (config_pair.first == "reservation-mode") ||
797 (config_pair.first == "reservations-global") ||
798 (config_pair.first == "reservations-in-subnet") ||
799 (config_pair.first == "reservations-out-of-pool") ||
800 (config_pair.first == "calculate-tee-times") ||
801 (config_pair.first == "t1-percent") ||
802 (config_pair.first == "t2-percent") ||
803 (config_pair.first == "cache-threshold") ||
804 (config_pair.first == "cache-max-age") ||
805 (config_pair.first == "hostname-char-set") ||
806 (config_pair.first == "hostname-char-replacement") ||
807 (config_pair.first == "ddns-send-updates") ||
808 (config_pair.first == "ddns-override-no-update") ||
809 (config_pair.first == "ddns-override-client-update") ||
810 (config_pair.first == "ddns-replace-client-name") ||
811 (config_pair.first == "ddns-generated-prefix") ||
812 (config_pair.first == "ddns-qualifying-suffix") ||
813 (config_pair.first == "ddns-update-on-renew") ||
814 (config_pair.first == "ddns-use-conflict-resolution") ||
815 (config_pair.first == "store-extended-info") ||
816 (config_pair.first == "statistic-default-sample-count") ||
817 (config_pair.first == "statistic-default-sample-age") ||
818 (config_pair.first == "early-global-reservations-lookup") ||
819 (config_pair.first == "ip-reservations-unique") ||
820 (config_pair.first == "reservations-lookup-first") ||
821 (config_pair.first == "parked-packet-limit")) {
822 CfgMgr::instance().getStagingCfg()->addConfiguredGlobal(config_pair.first,
823 config_pair.second);
824 continue;
825 }
826
827 // Nothing to configure for the user-context.
828 if (config_pair.first == "user-context") {
829 continue;
830 }
831
832 // If we got here, no code handled this parameter, so we bail out.
834 "unsupported global configuration parameter: " << config_pair.first
835 << " (" << config_pair.second->getPosition() << ")");
836 }
837
838 // Reset parameter name.
839 parameter_name = "<post parsing>";
840
841 // Apply global options in the staging config.
842 global_parser.parse(srv_config, mutable_cfg);
843
844 // This method conducts final sanity checks and tweaks. In particular,
845 // it checks that there is no conflict between plain subnets and those
846 // defined as part of shared networks.
847 global_parser.sanityChecks(srv_config, mutable_cfg);
848
849 // Validate D2 client configuration.
850 if (!d2_client_cfg) {
851 d2_client_cfg.reset(new D2ClientConfig());
852 }
853 d2_client_cfg->validateContents();
854 srv_config->setD2ClientConfig(d2_client_cfg);
855 } catch (const isc::Exception& ex) {
857 .arg(parameter_name).arg(ex.what());
859
860 // An error occurred, so make sure that we restore original data.
861 rollback = true;
862 } catch (...) {
863 // For things like bad_cast in boost::lexical_cast
864 LOG_ERROR(dhcp6_logger, DHCP6_PARSER_EXCEPTION).arg(parameter_name);
865 answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, "undefined configuration"
866 " processing error");
867
868 // An error occurred, so make sure that we restore original data.
869 rollback = true;
870 }
871
872 if (check_only) {
873 rollback = true;
874 if (!answer) {
876 "Configuration seems sane. Control-socket, hook-libraries, and D2 "
877 "configuration were sanity checked, but not applied.");
878 }
879 }
880
881 // So far so good, there was no parsing error so let's commit the
882 // configuration. This will add created subnets and option values into
883 // the server's configuration.
884 // This operation should be exception safe but let's make sure.
885 if (!rollback) {
886 try {
887
888 // Setup the command channel.
890
891 // No need to commit interface names as this is handled by the
892 // CfgMgr::commit() function.
893
894 // Apply the staged D2ClientConfig, used to be done by parser commit
896 cfg = CfgMgr::instance().getStagingCfg()->getD2ClientConfig();
898
899 // This occurs last as if it succeeds, there is no easy way to
900 // revert it. As a result, the failure to commit a subsequent
901 // change causes problems when trying to roll back.
902 HooksManager::prepareUnloadLibraries();
903 static_cast<void>(HooksManager::unloadLibraries());
904 const HooksConfig& libraries =
905 CfgMgr::instance().getStagingCfg()->getHooksConfig();
906 libraries.loadLibraries();
907 } catch (const isc::Exception& ex) {
910
911 // An error occurred, so make sure to restore the original data.
912 rollback = true;
913 } catch (...) {
914 // For things like bad_cast in boost::lexical_cast
916 answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, "undefined configuration"
917 " parsing error");
918
919 // An error occurred, so make sure to restore the original data.
920 rollback = true;
921 }
922 }
923
924 // Moved from the commit block to add the config backend indication.
925 if (!rollback) {
926 try {
927
928 // If there are config backends, fetch and merge into staging config
929 server.getCBControl()->databaseConfigFetch(srv_config,
930 CBControlDHCPv6::FetchMode::FETCH_ALL);
931 } catch (const isc::Exception& ex) {
932 std::ostringstream err;
933 err << "during update from config backend database: " << ex.what();
936
937 // An error occurred, so make sure to restore the original data.
938 rollback = true;
939 } catch (...) {
940 // For things like bad_cast in boost::lexical_cast
941 std::ostringstream err;
942 err << "during update from config backend database: "
943 << "undefined configuration parsing error";
946
947 // An error occurred, so make sure to restore the original data.
948 rollback = true;
949 }
950 }
951
952 // Rollback changes as the configuration parsing failed.
953 if (rollback) {
954 // Revert to original configuration of runtime option definitions
955 // in the libdhcp++.
957 return (answer);
958 }
959
961 .arg(CfgMgr::instance().getStagingCfg()->
962 getConfigSummary(SrvConfig::CFGSEL_ALL6));
963
964 // Everything was fine. Configuration is successful.
965 answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Configuration successful.");
966 return (answer);
967}
968
969} // namespace dhcp
970} // namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void closeCommandSocket()
Shuts down any open control sockets.
Definition: command_mgr.cc:627
static CommandMgr & instance()
CommandMgr is a singleton class.
Definition: command_mgr.cc:650
void openCommandSocket(const isc::data::ConstElementPtr &socket_info)
Opens control socket with parameters specified in socket_info.
Definition: command_mgr.cc:623
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
uint32_t getUint32(isc::data::ConstElementPtr scope, const std::string &name)
Returns a value converted to uint32_t.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
uint16_t getUint16(isc::data::ConstElementPtr scope, const std::string &name)
Returns a value converted to uint16_t.
Parse Database Parameters.
void parse(std::string &access_string, isc::data::ConstElementPtr database_config)
Parse configuration value.
static void moveReservationMode(isc::data::ElementPtr config)
Moves deprecated reservation-mode parameter to new reservations flags.
Wrapper class that holds MAC/hardware address sources.
void setD2ClientConfig(D2ClientConfigPtr &new_config)
Updates the DHCP-DDNS client configuration to the given value.
Definition: cfgmgr.cc:41
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition: cfgmgr.cc:25
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
Definition: cfgmgr.cc:167
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Definition: cfgmgr.cc:161
Parser for a list of client class definitions.
ClientClassDictionaryPtr parse(isc::data::ConstElementPtr class_def_list, uint16_t family, bool check_dependencies=true)
Parse configuration entries.
Parser for the control-socket structure.
Definition: dhcp_parsers.h:211
void parse(SrvConfig &srv_cfg, isc::data::ConstElementPtr value)
"Parses" control-socket structure
Definition: dhcp_parsers.cc:76
Parser for D2ClientConfig.
Definition: dhcp_parsers.h:981
D2ClientConfigPtr parse(isc::data::ConstElementPtr d2_client_cfg)
Parses a given dhcp-ddns element into D2ClientConfig.
static size_t setAllDefaults(isc::data::ConstElementPtr d2_config)
Sets all defaults for D2 client configuration.
Acts as a storage vault for D2 client configuration.
Definition: d2_client_cfg.h:57
Parser for the configuration of DHCP packet queue controls.
data::ElementPtr parse(const isc::data::ConstElementPtr &control_elem)
Parses content of the "dhcp-queue-control".
Parser for server DUID configuration.
void parse(const CfgDUIDPtr &cfg, isc::data::ConstElementPtr duid_configuration)
Parses DUID configuration.
To be removed. Please use ConfigError instead.
DHCPv6 server service.
Definition: dhcp6_srv.h:66
CBControlDHCPv6Ptr getCBControl() const
Returns an object which controls access to the configuration backends.
Definition: dhcp6_srv.h:124
void discardPackets()
Discards parked packets Clears the packet parking lots of all packets.
Definition: dhcp6_srv.cc:4421
Parser for the configuration parameters pertaining to the processing of expired leases.
void parse(isc::data::ConstElementPtr expiration_config)
Parses parameters in the JSON map, pertaining to the processing of the expired leases.
static void printRegistered()
Prints out all registered backends.
Parser for a list of host identifiers for DHCPv6.
void parse(isc::data::ConstElementPtr ids_list)
Parses a list of host identifiers.
Parser for a list of host reservations for a subnet.
void parse(const SubnetID &subnet_id, isc::data::ConstElementPtr hr_list, HostCollection &hosts_list)
Parses a list of host reservation entries for a subnet.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Definition: iface_mgr.cc:53
void closeSockets()
Closes all open sockets.
Definition: iface_mgr.cc:287
Parser for the configuration of interfaces.
void parse(const CfgIfacePtr &config, const isc::data::ConstElementPtr &values)
Parses content of the "interfaces-config".
static void setRuntimeOptionDefs(const OptionDefSpaceContainer &defs)
Copies option definitions created at runtime.
Definition: libdhcp++.cc:214
static void revertRuntimeOptionDefs()
Reverts uncommitted changes to runtime option definitions.
Definition: libdhcp++.cc:233
parser for MAC/hardware acquisition sources
Definition: dhcp_parsers.h:195
void parse(CfgMACSource &mac_sources, isc::data::ConstElementPtr value)
parses parameters value
Definition: dhcp_parsers.cc:46
Simple parser for multi-threading structure.
void parse(SrvConfig &srv_cfg, const isc::data::ConstElementPtr &value)
parses JSON structure.
Parser for option data values within a subnet.
void parse(const CfgOptionPtr &cfg, isc::data::ConstElementPtr option_data_list)
Parses a list of options, instantiates them and stores in cfg.
Parser for a list of option definitions.
Definition: dhcp_parsers.h:254
void parse(CfgOptionDefPtr cfg, isc::data::ConstElementPtr def_list)
Parses a list of option definitions, create them and store in cfg.
Class of option definition space container.
Simple parser for sanity-checks structure.
void parse(SrvConfig &srv_cfg, const isc::data::ConstElementPtr &value)
parses JSON structure
Parser for a list of shared networks.
void parse(CfgSharedNetworksTypePtr &cfg, const data::ConstElementPtr &shared_networks_list_data)
Parses a list of shared networks.
static size_t deriveParameters(isc::data::ElementPtr global)
Derives (inherits) all parameters from global to more specific scopes.
static size_t setAllDefaults(isc::data::ElementPtr global)
Sets all defaults for DHCPv6 configuration.
static const uint32_t CFGSEL_ALL6
IPv6 related config.
Definition: srv_config.h:203
static void resetSubnetID()
Resets subnet-id counter to its initial value (1).
Definition: subnet.h:243
this class parses a list of DHCP6 subnets
Definition: dhcp_parsers.h:929
size_t parse(SrvConfigPtr cfg, data::ConstElementPtr subnets_list)
parses contents of the list
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
Definition: timer_mgr.cc:449
Wrapper class that holds hooks libraries configuration.
Definition: hooks_config.h:36
void verifyLibraries(const isc::data::Element::Position &position) const
Verifies that libraries stored in libraries_ are valid.
Definition: hooks_config.cc:20
void loadLibraries() const
Commits hooks libraries configuration.
Definition: hooks_config.cc:55
Parser for hooks library list.
Definition: hooks_parser.h:21
void parse(HooksConfig &libraries, isc::data::ConstElementPtr value)
Parses parameters value.
Definition: hooks_parser.cc:28
Implements parser for config control information, "config-control".
ConfigControlInfoPtr parse(const data::ConstElementPtr &config_control)
Parses a configuration control Element.
isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr const &config)
Redact a configuration.
Definition: daemon.cc:257
Parsers for client class definitions.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Logging initialization functions.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Definition: macros.h:32
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition: macros.h:20
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
Definition: macros.h:26
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Definition: macros.h:14
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
void configureCommandChannel()
Initialize the command channel based on the staging configuration.
boost::shared_ptr< CfgDUID > CfgDUIDPtr
Pointer to the Non-const object.
Definition: cfg_duid.h:161
std::pair< std::string, isc::data::ConstElementPtr > ConfigPair
Combination of parameter name and configuration contents.
Definition: dhcp_parsers.h:175
const isc::log::MessageID DHCP6_PARSER_FAIL
const isc::log::MessageID DHCP6_PARSER_EXCEPTION
boost::shared_ptr< D2ClientConfig > D2ClientConfigPtr
Defines a pointer for D2ClientConfig instances.
isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configures DHCPv6 server.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:706
boost::multi_index_container< SharedNetwork6Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SharedNetworkRandomAccessIndexTag > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< SharedNetworkIdIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, uint64_t, &data::BaseStampedElement::getId > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SharedNetworkNameIndexTag >, boost::multi_index::const_mem_fun< SharedNetwork6, std::string, &SharedNetwork6::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SharedNetworkModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > SharedNetwork6Collection
Multi index container holding shared networks.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
const int DBG_DHCP6_COMMAND
Debug level used to log receiving commands.
Definition: dhcp6_log.h:28
const isc::log::MessageID DHCP6_CONFIG_COMPLETE
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
Definition: cfg_iface.h:501
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
Definition: srv_config.h:1165
boost::shared_ptr< CfgSubnets6 > CfgSubnets6Ptr
Non-const pointer.
Definition: cfg_subnets6.h:331
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition: host.h:794
const isc::log::MessageID DHCP6_RESERVATIONS_LOOKUP_FIRST_ENABLED
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
boost::shared_ptr< CfgSharedNetworks6 > CfgSharedNetworks6Ptr
Pointer to the configuration of IPv6 shared networks.
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > > > > Subnet6SimpleCollection
A simple collection of Subnet6 objects.
Definition: subnet.h:917
const isc::log::MessageID DHCP6_PARSER_COMMIT_EXCEPTION
const isc::log::MessageID DHCP6_CONFIG_START
const isc::log::MessageID DHCP6_PARSER_COMMIT_FAIL
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 server.
Definition: dhcp6_log.h:88
boost::shared_ptr< ConfigControlInfo > ConfigControlInfoPtr
Defines a pointer to a ConfigControlInfo.
Definition: edns.h:19
Defines the logger used by the top-level component of kea-lfc.
#define DHCP6_OPTION_SPACE