51#include <boost/algorithm/string.hpp>
52#include <boost/lexical_cast.hpp>
53#include <boost/scoped_ptr.hpp>
54#include <boost/shared_ptr.hpp>
59#include <netinet/in.h>
80void dirExists(
const string& dir_path) {
82 if (stat(dir_path.c_str(), &statbuf) < 0) {
84 <<
"': " << strerror(errno));
86 if ((statbuf.st_mode & S_IFMT) != S_IFDIR) {
111 for (
auto const& source_elem : value->listValue()) {
112 std::string option_str = source_elem->stringValue();
116 code = boost::lexical_cast<int64_t>(option_str);
120 << option_str <<
"', the option code must be a"
121 " non-negative value");
123 }
else if (code > std::numeric_limits<uint16_t>::max()) {
125 << option_str <<
"', the option code must not be"
126 " greater than '" << std::numeric_limits<uint16_t>::max()
130 }
catch (
const boost::bad_lexical_cast &) {
138 code = def->getCode();
141 " specified option name '" << option_str <<
"'"
142 " while parsing the list of enabled"
143 " relay-supplied-options");
146 cfg->getCfgRSOO()->enable(code);
148 }
catch (
const std::exception& ex) {
184 if (global->contains(
"data-directory")) {
190 uint32_t probation_period =
191 getUint32(global,
"decline-probation-period");
192 cfg->setDeclinePeriod(probation_period);
195 uint16_t dhcp4o6_port = getUint16(global,
"dhcp4o6-port");
196 cfg->setDhcp4o6Port(dhcp4o6_port);
201 cfg->setContext(user_context);
205 std::string server_tag = getString(global,
"server-tag");
206 cfg->setServerTag(server_tag);
222 bool ip_reservations_unique = getBoolean(global,
"ip-reservations-unique");
223 cfg->setIPReservationsUnique(ip_reservations_unique);
235 if (!dest || !from) {
247 for (
auto const& net : *networks) {
258 for (
auto const& subnet : *subnets) {
276 cfg->sanityChecksLifetime(
"preferred-lifetime");
277 cfg->sanityChecksLifetime(
"valid-lifetime");
282 sharedNetworksSanityChecks(*networks, global->get(
"shared-networks"));
304 std::set<string> names;
307 for (
auto const& net : networks) {
312 string iface = net->getIface();
317 bool rapid_commit =
false;
321 if (subnets->size()) {
323 rapid_commit = (*subnets->begin())->getRapidCommit();
327 for (
auto const& subnet : *subnets) {
330 if (rapid_commit != subnet->getRapidCommit()) {
332 "must have the same rapid-commit value. Subnet "
334 <<
" has specified rapid-commit "
335 << (subnet->getRapidCommit() ?
"true" :
"false")
336 <<
", but earlier subnet in the same shared-network"
337 <<
" or the shared-network itself used rapid-commit "
338 << (rapid_commit ?
"true" :
"false"));
342 iface = subnet->getIface();
346 if (subnet->getIface().empty()) {
350 if (subnet->getIface() != iface) {
352 <<
" has specified interface " << subnet->getIface()
353 <<
", but earlier subnet in the same shared-network"
354 <<
" or the shared-network itself used " << iface);
359 txt += subnet->toText() +
" ";
364 if (net->getName().empty()) {
366 << txt <<
" is missing mandatory 'name' parameter");
370 if (names.find(net->getName()) != names.end()) {
372 "name " << net->getName() <<
" defined twice.");
374 names.insert(net->getName());
404 bool sock_changed = (sock_cfg && current_sock_cfg &&
405 !sock_cfg->equals(*current_sock_cfg));
412 if (!sock_cfg || !current_sock_cfg || sock_changed) {
445 string parameter_name;
455 mutable_cfg = boost::const_pointer_cast<Element>(config_set);
470 Dhcp6ConfigParser global_parser;
473 global_parser.parseEarly(srv_config, mutable_cfg);
477 if (data_directory) {
478 parameter_name =
"data-directory";
479 dirExists(data_directory->stringValue());
485 parameter_name =
"option-def";
488 parser.
parse(cfg_option_def, option_defs);
493 parameter_name =
"option-data";
496 parser.
parse(cfg_option, option_datas);
501 parameter_name =
"mac-sources";
504 parser.
parse(mac_source, mac_sources);
508 if (control_socket) {
509 parameter_name =
"control-socket";
511 parser.
parse(*srv_config, control_socket);
515 if (multi_threading) {
516 parameter_name =
"multi-threading";
518 parser.
parse(*srv_config, multi_threading);
521 bool multi_threading_enabled =
true;
522 uint32_t thread_count = 0;
523 uint32_t queue_size = 0;
525 multi_threading_enabled, thread_count, queue_size);
528 ConstElementPtr queue_control = mutable_cfg->get(
"dhcp-queue-control");
530 parameter_name =
"dhcp-queue-control";
532 srv_config->setDHCPQueueControl(parser.
parse(queue_control, multi_threading_enabled));
536 ConstElementPtr reservations_lookup_first = mutable_cfg->get(
"reservations-lookup-first");
537 if (reservations_lookup_first) {
538 parameter_name =
"reservations-lookup-first";
539 if (multi_threading_enabled) {
542 srv_config->setReservationsLookupFirst(reservations_lookup_first->boolValue());
546 mutable_cfg->get(
"host-reservation-identifiers");
547 if (hr_identifiers) {
548 parameter_name =
"host-reservation-identifiers";
550 parser.
parse(hr_identifiers);
555 parameter_name =
"server-id";
557 const CfgDUIDPtr& cfg = srv_config->getCfgDUID();
558 parser.
parse(cfg, server_id);
563 parameter_name =
"sanity-checks";
565 parser.
parse(*srv_config, sanity_checks);
569 mutable_cfg->get(
"expired-leases-processing");
570 if (expiration_cfg) {
571 parameter_name =
"expired-leases-processing";
580 if (hooks_libraries) {
581 parameter_name =
"hooks-libraries";
583 HooksConfig& libraries = srv_config->getHooksConfig();
584 hooks_parser.parse(libraries, hooks_libraries);
586 multi_threading_enabled);
595 parameter_name =
"dhcp-ddns";
599 d2_client_cfg = parser.
parse(dhcp_ddns);
603 if (client_classes) {
604 parameter_name =
"client-classes";
607 parser.
parse(client_classes, AF_INET6);
608 srv_config->setClientClassDictionary(dictionary);
613 if (lease_database) {
614 parameter_name =
"lease-database";
616 std::string access_string;
617 parser.
parse(access_string, lease_database);
619 cfg_db_access->setLeaseDbAccessString(access_string);
623 if (hosts_database) {
624 parameter_name =
"hosts-database";
626 std::string access_string;
627 parser.
parse(access_string, hosts_database);
629 cfg_db_access->setHostDbAccessString(access_string);
633 if (hosts_databases) {
634 parameter_name =
"hosts-databases";
636 for (
auto const& it : hosts_databases->listValue()) {
638 std::string access_string;
639 parser.
parse(access_string, it);
640 cfg_db_access->setHostDbAccessString(access_string);
646 if (shared_networks) {
647 parameter_name =
"shared-networks";
655 parser.parse(cfg, shared_networks);
659 global_parser.copySubnets6(srv_config->getCfgSubnets6(), cfg);
664 parameter_name =
"subnet6";
667 subnets_parser.
parse(srv_config, subnet6);
672 parameter_name =
"reservations";
674 HostReservationsListParser<HostReservationParser6> parser;
675 parser.parse(SUBNET_ID_GLOBAL, reservations, hosts);
676 for (
auto const& h : hosts) {
677 srv_config->getCfgHosts()->add(h);
682 if (config_control) {
683 parameter_name =
"config-control";
689 ConstElementPtr rsoo_list = mutable_cfg->get(
"relay-supplied-options");
691 parameter_name =
"relay-supplied-options";
692 RSOOListConfigParser parser;
693 parser.parse(srv_config, rsoo_list);
703 const std::map<std::string, ConstElementPtr>& values_map =
704 mutable_cfg->mapValue();
706 for (
auto const& config_pair : values_map) {
707 parameter_name = config_pair.first;
710 if ((config_pair.first ==
"data-directory") ||
711 (config_pair.first ==
"option-def") ||
712 (config_pair.first ==
"option-data") ||
713 (config_pair.first ==
"mac-sources") ||
714 (config_pair.first ==
"control-socket") ||
715 (config_pair.first ==
"multi-threading") ||
716 (config_pair.first ==
"dhcp-queue-control") ||
717 (config_pair.first ==
"host-reservation-identifiers") ||
718 (config_pair.first ==
"server-id") ||
719 (config_pair.first ==
"interfaces-config") ||
720 (config_pair.first ==
"sanity-checks") ||
721 (config_pair.first ==
"expired-leases-processing") ||
722 (config_pair.first ==
"hooks-libraries") ||
723 (config_pair.first ==
"dhcp-ddns") ||
724 (config_pair.first ==
"client-classes") ||
725 (config_pair.first ==
"lease-database") ||
726 (config_pair.first ==
"hosts-database") ||
727 (config_pair.first ==
"hosts-databases") ||
728 (config_pair.first ==
"subnet6") ||
729 (config_pair.first ==
"shared-networks") ||
730 (config_pair.first ==
"reservations") ||
731 (config_pair.first ==
"config-control") ||
732 (config_pair.first ==
"relay-supplied-options") ||
733 (config_pair.first ==
"loggers") ||
734 (config_pair.first ==
"compatibility")) {
748 if ( (config_pair.first ==
"renew-timer") ||
749 (config_pair.first ==
"rebind-timer") ||
750 (config_pair.first ==
"preferred-lifetime") ||
751 (config_pair.first ==
"min-preferred-lifetime") ||
752 (config_pair.first ==
"max-preferred-lifetime") ||
753 (config_pair.first ==
"valid-lifetime") ||
754 (config_pair.first ==
"min-valid-lifetime") ||
755 (config_pair.first ==
"max-valid-lifetime") ||
756 (config_pair.first ==
"decline-probation-period") ||
757 (config_pair.first ==
"dhcp4o6-port") ||
758 (config_pair.first ==
"server-tag") ||
759 (config_pair.first ==
"reservations-global") ||
760 (config_pair.first ==
"reservations-in-subnet") ||
761 (config_pair.first ==
"reservations-out-of-pool") ||
762 (config_pair.first ==
"calculate-tee-times") ||
763 (config_pair.first ==
"t1-percent") ||
764 (config_pair.first ==
"t2-percent") ||
765 (config_pair.first ==
"cache-threshold") ||
766 (config_pair.first ==
"cache-max-age") ||
767 (config_pair.first ==
"hostname-char-set") ||
768 (config_pair.first ==
"hostname-char-replacement") ||
769 (config_pair.first ==
"ddns-send-updates") ||
770 (config_pair.first ==
"ddns-override-no-update") ||
771 (config_pair.first ==
"ddns-override-client-update") ||
772 (config_pair.first ==
"ddns-replace-client-name") ||
773 (config_pair.first ==
"ddns-generated-prefix") ||
774 (config_pair.first ==
"ddns-qualifying-suffix") ||
775 (config_pair.first ==
"ddns-update-on-renew") ||
776 (config_pair.first ==
"ddns-use-conflict-resolution") ||
777 (config_pair.first ==
"ddns-conflict-resolution-mode") ||
778 (config_pair.first ==
"ddns-ttl-percent") ||
779 (config_pair.first ==
"store-extended-info") ||
780 (config_pair.first ==
"statistic-default-sample-count") ||
781 (config_pair.first ==
"statistic-default-sample-age") ||
782 (config_pair.first ==
"early-global-reservations-lookup") ||
783 (config_pair.first ==
"ip-reservations-unique") ||
784 (config_pair.first ==
"reservations-lookup-first") ||
785 (config_pair.first ==
"parked-packet-limit") ||
786 (config_pair.first ==
"allocator") ||
787 (config_pair.first ==
"pd-allocator") ) {
794 if (config_pair.first ==
"user-context") {
800 "unsupported global configuration parameter: " << config_pair.first
801 <<
" (" << config_pair.second->getPosition() <<
")");
805 parameter_name =
"<post parsing>";
808 global_parser.parse(srv_config, mutable_cfg);
813 global_parser.sanityChecks(srv_config, mutable_cfg);
816 if (!d2_client_cfg) {
819 d2_client_cfg->validateContents();
820 srv_config->setD2ClientConfig(d2_client_cfg);
823 .arg(parameter_name).arg(ex.what());
834 "Control-socket, hook-libraries, and D2 configuration "
835 "were sanity checked, but not applied.");
843 bool check_only,
bool extra_checks) {
846 "Can't parse NULL config");
851 .arg(server.redactConfig(config_set)->str());
869 string params =
"universe=6 persist=false";
875 cfg_db->setAppendedParameters(params);
876 cfg_db->createManagers();
877 }
catch (
const std::exception& ex) {
883 std::ostringstream err;
893 }
catch (
const std::exception& ex) {
894 err <<
"Error setting packet queue controls after server reconfiguration: "
913 server.discardPackets();
914 server.getCBControl()->reset();
918 string parameter_name;
927 mutable_cfg = boost::const_pointer_cast<Element>(config_set);
931 parameter_name =
"interfaces-config";
935 parser.
parse(cfg_iface, ifaces_config);
939 .arg(parameter_name).arg(ex.what());
946 " processing error");
1006 bool multi_threading_enabled =
true;
1007 uint32_t thread_count = 0;
1008 uint32_t queue_size = 0;
1010 multi_threading_enabled, thread_count, queue_size);
1011 libraries.loadLibraries(multi_threading_enabled);
1029 server.getCBControl()->databaseConfigFetch(srv_config,
1032 std::ostringstream err;
1033 err <<
"during update from config backend database: " << ex.what();
1039 std::ostringstream err;
1040 err <<
"during update from config backend database: "
1041 <<
"undefined configuration parsing error";
1056 if (notify_libraries) {
1057 return (notify_libraries);
1064 }
catch (
const std::exception& ex) {
1065 std::ostringstream err;
1066 err <<
"Error initializing hooks: "
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.
static IOServiceMgr & instance()
Access the IOServiceMgr singleton instance.
static std::string getHash(const isc::data::ConstElementPtr &config)
returns a hash of a given Element structure
static CommandMgr & instance()
CommandMgr is a singleton class.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Parse Database Parameters.
void parse(std::string &access_string, isc::data::ConstElementPtr database_config)
Parse configuration value.
Wrapper class that holds MAC/hardware address sources.
static CfgMgr & instance()
returns a single instance of Configuration Manager
static void extract(data::ConstElementPtr value, bool &enabled, uint32_t &thread_count, uint32_t &queue_size)
Extract multi-threading parameters from a given configuration.
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.
void parse(isc::data::ConstElementPtr cfg, isc::dhcp::SrvConfig &srv_cfg)
Parse compatibility flags.
Parser for the control-socket structure.
void parse(SrvConfig &srv_cfg, isc::data::ConstElementPtr value)
"Parses" control-socket structure
static isc::data::ConstElementPtr finishConfigHookLibraries(isc::data::ConstElementPtr config)
Configuration checker for hook libraries.
Parser for D2ClientConfig.
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.
Parser for the configuration of DHCP packet queue controls.
data::ElementPtr parse(const isc::data::ConstElementPtr &control_elem, bool multi_threading_enabled)
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.
Parser for the configuration parameters pertaining to the processing of expired leases.
void parse(isc::data::ConstElementPtr expiration_config, isc::dhcp::CfgExpirationPtr expiration)
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.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
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.
static OptionDefinitionPtr getOptionDef(const std::string &space, const uint16_t code)
Return the first option definition matching a particular option code.
static void revertRuntimeOptionDefs()
Reverts uncommitted changes to runtime option definitions.
parser for MAC/hardware acquisition sources
void parse(CfgMACSource &mac_sources, isc::data::ConstElementPtr value)
parses parameters value
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, bool encapsulate=true)
Parses a list of options, instantiates them and stores in cfg.
Parser for a list of option definitions.
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
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.
this class parses a list of DHCP6 subnets
size_t parse(SrvConfigPtr cfg, data::ConstElementPtr subnets_list, bool encapsulate_options=true)
parses contents of the list
static const TimerMgrPtr & instance()
Returns pointer to the sole instance of the TimerMgr.
Wrapper class that holds hooks libraries configuration.
void verifyLibraries(const isc::data::Element::Position &position, bool multi_threading_enabled) const
Verifies that libraries stored in libraries_ are valid.
Parser for hooks library list.
static bool unloadLibraries()
Unload libraries.
static void prepareUnloadLibraries()
Prepare the unloading of libraries.
Implements parser for config control information, "config-control".
ConfigControlInfoPtr parse(const data::ConstElementPtr &config_control)
Parses a configuration control Element.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
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.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
void configureCommandChannel()
Initialize the command channel based on the staging configuration.
boost::shared_ptr< CfgDUID > CfgDUIDPtr
Pointer to the Non-const object.
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.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
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.
isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv &server, isc::data::ConstElementPtr config_set, bool check_only, bool extra_checks)
Configure DHCPv6 server (Dhcpv6Srv) with a set of configuration values.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
isc::data::ConstElementPtr processDhcp6Config(isc::data::ConstElementPtr config_set)
Process a DHCPv6 confguration and return an answer stating if the configuration is valid,...
const int DBG_DHCP6_COMMAND
Debug level used to log receiving commands.
const isc::log::MessageID DHCP6_CONFIG_COMPLETE
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
boost::shared_ptr< CfgSubnets6 > CfgSubnets6Ptr
Non-const pointer.
std::vector< HostPtr > HostCollection
Collection of the Host objects.
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.
const isc::log::MessageID DHCP6_PARSER_COMMIT_EXCEPTION
const isc::log::MessageID DHCP6_CONFIG_START
SharedNetworksListParser< SharedNetwork6Parser > SharedNetworks6ListParser
Type of the shared networks list parser for IPv6.
const isc::log::MessageID DHCP6_PARSER_COMMIT_FAIL
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 server.
const isc::log::MessageID DHCP6_CONFIG_PACKET_QUEUE
boost::shared_ptr< ConfigControlInfo > ConfigControlInfoPtr
Defines a pointer to a ConfigControlInfo.
Defines the logger used by the top-level component of kea-lfc.
#define DHCP6_OPTION_SPACE