44 #include <boost/foreach.hpp>
45 #include <boost/lexical_cast.hpp>
46 #include <boost/algorithm/string.hpp>
51 #include <netinet/in.h>
95 bool echo_client_id = getBoolean(global,
"echo-client-id");
96 cfg->setEchoClientId(echo_client_id);
99 uint32_t probation_period =
100 getUint32(global,
"decline-probation-period");
101 cfg->setDeclinePeriod(probation_period);
104 uint16_t dhcp4o6_port = getUint16(global,
"dhcp4o6-port");
105 cfg->setDhcp4o6Port(dhcp4o6_port);
110 cfg->setContext(user_context);
114 std::string server_tag = getString(global,
"server-tag");
115 cfg->setServerTag(server_tag);
131 bool ip_reservations_unique = getBoolean(global,
"ip-reservations-unique");
132 cfg->setIPReservationsUnique(ip_reservations_unique);
144 if (!dest || !from) {
156 for (
auto net = networks->begin(); net != networks->end(); ++net) {
167 for (
auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
185 cfg->sanityChecksLifetime(
"valid-lifetime");
190 sharedNetworksSanityChecks(*networks, global->get(
"shared-networks"));
212 std::set<string> names;
215 for (
auto net = networks.begin(); net != networks.end(); ++net) {
220 bool authoritative = (*net)->getAuthoritative();
221 string iface = (*net)->getIface();
226 for (
auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
227 if ((*subnet)->getAuthoritative() != authoritative) {
229 << (*subnet)->toText()
230 <<
" has different authoritative setting "
231 << (*subnet)->getAuthoritative()
232 <<
" than the shared-network itself: "
237 iface = (*subnet)->getIface();
241 if ((*subnet)->getIface().empty()) {
245 if ((*subnet)->getIface() != iface) {
247 <<
" has specified interface " << (*subnet)->getIface()
248 <<
", but earlier subnet in the same shared-network"
249 <<
" or the shared-network itself used " << iface);
254 txt += (*subnet)->toText() +
" ";
259 if ((*net)->getName().empty()) {
261 << txt <<
" is missing mandatory 'name' parameter");
265 if (names.find((*net)->getName()) != names.end()) {
267 "name " << (*net)->getName() <<
" defined twice.");
269 names.insert((*net)->getName());
290 CfgMgr::instance().getStagingCfg()->getControlSocketInfo();
294 CfgMgr::instance().getCurrentCfg()->getControlSocketInfo();
299 bool sock_changed = (sock_cfg && current_sock_cfg &&
300 !sock_cfg->equals(*current_sock_cfg));
307 if (!sock_cfg || !current_sock_cfg || sock_changed) {
326 string(
"Can't parse NULL config"));
335 Subnet::resetSubnetID();
339 IfaceMgr::instance().closeSockets();
340 TimerMgr::instance()->unregisterTimers();
346 LibDHCP::revertRuntimeOptionDefs();
352 HostDataSourceFactory::printRegistered();
358 bool rollback =
false;
360 string parameter_name;
365 srv_cfg = CfgMgr::instance().getStagingCfg();
370 mutable_cfg = boost::const_pointer_cast<
Element>(config_set);
376 srv_cfg->moveDdnsParams(mutable_cfg);
380 BaseNetworkParser::moveReservationMode(mutable_cfg);
383 SimpleParser4::setAllDefaults(mutable_cfg);
386 SimpleParser4::deriveParameters(mutable_cfg);
395 Dhcp4ConfigParser global_parser;
398 global_parser.parseEarly(srv_cfg, mutable_cfg);
403 parameter_name =
"option-def";
406 parser.
parse(cfg_option_def, option_defs);
411 parameter_name =
"option-data";
414 parser.
parse(cfg_option, option_datas);
418 if (control_socket) {
419 parameter_name =
"control-socket";
421 parser.
parse(*srv_cfg, control_socket);
425 if (multi_threading) {
426 parameter_name =
"multi-threading";
428 parser.
parse(*srv_cfg, multi_threading);
431 ConstElementPtr queue_control = mutable_cfg->get(
"dhcp-queue-control");
433 parameter_name =
"dhcp-queue-control";
435 srv_cfg->setDHCPQueueControl(parser.
parse(queue_control));
439 mutable_cfg->get(
"host-reservation-identifiers");
440 if (hr_identifiers) {
441 parameter_name =
"host-reservation-identifiers";
443 parser.
parse(hr_identifiers);
448 parameter_name =
"interfaces-config";
451 parser.
parse(cfg_iface, ifaces_config);
456 parameter_name =
"sanity-checks";
458 parser.
parse(*srv_cfg, sanity_checks);
462 mutable_cfg->get(
"expired-leases-processing");
463 if (expiration_cfg) {
464 parameter_name =
"expired-leases-processing";
466 parser.
parse(expiration_cfg);
473 if (hooks_libraries) {
474 parameter_name =
"hooks-libraries";
476 HooksConfig& libraries = srv_cfg->getHooksConfig();
477 hooks_parser.
parse(libraries, hooks_libraries);
487 parameter_name =
"dhcp-ddns";
489 D2ClientConfigParser::setAllDefaults(dhcp_ddns);
491 d2_client_cfg = parser.
parse(dhcp_ddns);
495 if (client_classes) {
496 parameter_name =
"client-classes";
499 parser.
parse(client_classes, AF_INET);
500 srv_cfg->setClientClassDictionary(dictionary);
505 if (lease_database) {
506 parameter_name =
"lease-database";
508 std::string access_string;
509 parser.
parse(access_string, lease_database);
511 cfg_db_access->setLeaseDbAccessString(access_string);
515 if (hosts_database) {
516 parameter_name =
"hosts-database";
518 std::string access_string;
519 parser.
parse(access_string, hosts_database);
521 cfg_db_access->setHostDbAccessString(access_string);
525 if (hosts_databases) {
526 parameter_name =
"hosts-databases";
529 for (
auto it : hosts_databases->listValue()) {
530 std::string access_string;
531 parser.
parse(access_string, it);
532 cfg_db_access->setHostDbAccessString(access_string);
538 if (shared_networks) {
539 parameter_name =
"shared-networks";
547 parser.
parse(cfg, shared_networks);
551 global_parser.copySubnets4(srv_cfg->getCfgSubnets4(), cfg);
556 parameter_name =
"subnet4";
559 subnets_parser.
parse(srv_cfg, subnet4);
564 parameter_name =
"reservations";
567 parser.
parse(SUBNET_ID_GLOBAL, reservations, hosts);
568 for (
auto h = hosts.begin(); h != hosts.end(); ++h) {
569 srv_cfg->getCfgHosts()->add(*h);
574 if (config_control) {
575 parameter_name =
"config-control";
578 CfgMgr::instance().getStagingCfg()->setConfigControlInfo(config_ctl_info);
583 for (
auto kv : compatibility->mapValue()) {
584 if (kv.first ==
"lenient-option-parsing") {
585 CfgMgr::instance().getStagingCfg()->setLenientOptionParsing(
586 kv.second->boolValue());
593 const std::map<std::string, ConstElementPtr>& values_map =
594 mutable_cfg->mapValue();
596 BOOST_FOREACH(config_pair, values_map) {
598 parameter_name = config_pair.first;
601 if ((config_pair.first ==
"option-def") ||
602 (config_pair.first ==
"option-data") ||
603 (config_pair.first ==
"control-socket") ||
604 (config_pair.first ==
"multi-threading") ||
605 (config_pair.first ==
"dhcp-queue-control") ||
606 (config_pair.first ==
"host-reservation-identifiers") ||
607 (config_pair.first ==
"interfaces-config") ||
608 (config_pair.first ==
"sanity-checks") ||
609 (config_pair.first ==
"expired-leases-processing") ||
610 (config_pair.first ==
"hooks-libraries") ||
611 (config_pair.first ==
"dhcp-ddns") ||
612 (config_pair.first ==
"client-classes") ||
613 (config_pair.first ==
"lease-database") ||
614 (config_pair.first ==
"hosts-database") ||
615 (config_pair.first ==
"hosts-databases") ||
616 (config_pair.first ==
"subnet4") ||
617 (config_pair.first ==
"shared-networks") ||
618 (config_pair.first ==
"reservations") ||
619 (config_pair.first ==
"config-control") ||
620 (config_pair.first ==
"compatibility")) {
634 if ( (config_pair.first ==
"renew-timer") ||
635 (config_pair.first ==
"rebind-timer") ||
636 (config_pair.first ==
"valid-lifetime") ||
637 (config_pair.first ==
"min-valid-lifetime") ||
638 (config_pair.first ==
"max-valid-lifetime") ||
639 (config_pair.first ==
"decline-probation-period") ||
640 (config_pair.first ==
"dhcp4o6-port") ||
641 (config_pair.first ==
"echo-client-id") ||
642 (config_pair.first ==
"match-client-id") ||
643 (config_pair.first ==
"authoritative") ||
644 (config_pair.first ==
"next-server") ||
645 (config_pair.first ==
"server-hostname") ||
646 (config_pair.first ==
"boot-file-name") ||
647 (config_pair.first ==
"server-tag") ||
648 (config_pair.first ==
"reservation-mode") ||
649 (config_pair.first ==
"reservations-global") ||
650 (config_pair.first ==
"reservations-in-subnet") ||
651 (config_pair.first ==
"reservations-out-of-pool") ||
652 (config_pair.first ==
"calculate-tee-times") ||
653 (config_pair.first ==
"t1-percent") ||
654 (config_pair.first ==
"t2-percent") ||
655 (config_pair.first ==
"cache-threshold") ||
656 (config_pair.first ==
"cache-max-age") ||
657 (config_pair.first ==
"loggers") ||
658 (config_pair.first ==
"hostname-char-set") ||
659 (config_pair.first ==
"hostname-char-replacement") ||
660 (config_pair.first ==
"ddns-send-updates") ||
661 (config_pair.first ==
"ddns-override-no-update") ||
662 (config_pair.first ==
"ddns-override-client-update") ||
663 (config_pair.first ==
"ddns-replace-client-name") ||
664 (config_pair.first ==
"ddns-generated-prefix") ||
665 (config_pair.first ==
"ddns-qualifying-suffix") ||
666 (config_pair.first ==
"ddns-update-on-renew") ||
667 (config_pair.first ==
"ddns-use-conflict-resolution") ||
668 (config_pair.first ==
"store-extended-info") ||
669 (config_pair.first ==
"statistic-default-sample-count") ||
670 (config_pair.first ==
"statistic-default-sample-age") ||
671 (config_pair.first ==
"ip-reservations-unique")) {
672 CfgMgr::instance().getStagingCfg()->addConfiguredGlobal(config_pair.first,
678 if (config_pair.first ==
"user-context") {
684 "unsupported global configuration parameter: " << config_pair.first
685 <<
" (" << config_pair.second->getPosition() <<
")");
689 parameter_name =
"<post parsing>";
692 global_parser.parse(srv_cfg, mutable_cfg);
697 global_parser.sanityChecks(srv_cfg, mutable_cfg);
700 if (!d2_client_cfg) {
703 d2_client_cfg->validateContents();
704 srv_cfg->setD2ClientConfig(d2_client_cfg);
707 .arg(parameter_name).arg(ex.
what());
716 " processing error");
726 "Configuration seems sane. Control-socket, hook-libraries, and D2 "
727 "configuration were sanity checked, but not applied.");
746 cfg = CfgMgr::instance().getStagingCfg()->getD2ClientConfig();
747 CfgMgr::instance().setD2ClientConfig(cfg);
752 HooksManager::prepareUnloadLibraries();
753 static_cast<void>(HooksManager::unloadLibraries());
755 CfgMgr::instance().getStagingCfg()->getHooksConfig();
781 CBControlDHCPv4::FetchMode::FETCH_ALL);
784 std::ostringstream err;
785 err <<
"during update from config backend database: " << ex.
what();
793 std::ostringstream err;
794 err <<
"during update from config backend database: "
795 <<
"undefined configuration parsing error";
808 LibDHCP::revertRuntimeOptionDefs();
813 .arg(CfgMgr::instance().getStagingCfg()->
814 getConfigSummary(SrvConfig::CFGSEL_ALL4));
void parse(isc::data::ConstElementPtr expiration_config)
Parses parameters in the JSON map, pertaining to the processing of the expired leases.
Parser for the configuration of DHCP packet queue controls.
std::pair< std::string, isc::data::ConstElementPtr > ConfigPair
Combination of parameter name and configuration contents.
const isc::log::MessageID DHCP4_PARSER_EXCEPTION
void parse(const CfgOptionPtr &cfg, isc::data::ConstElementPtr option_data_list)
Parses a list of options, instantiates them and stores in cfg.
const isc::log::MessageID DHCP4_PARSER_COMMIT_FAIL
D2ClientConfigPtr parse(isc::data::ConstElementPtr d2_client_cfg)
Parses a given dhcp-ddns element into D2ClientConfig.
Parser for hooks library list.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
size_t parse(SrvConfigPtr cfg, data::ConstElementPtr subnets_list)
parses contents of the list
Parse Database Parameters.
ClientClassDictionaryPtr parse(isc::data::ConstElementPtr class_def_list, uint16_t family)
Parse configuration entries.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
const isc::log::MessageID DHCP4_PARSER_COMMIT_EXCEPTION
Parser for the configuration parameters pertaining to the processing of expired leases.
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Wrapper class that holds hooks libraries configuration.
data::ElementPtr parse(const isc::data::ConstElementPtr &control_elem)
Parses content of the "dhcp-queue-control".
this class parses list of DHCP4 subnets
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
void discardPackets()
Discards parked packets Clears the packet parking lots of all packets.
boost::shared_ptr< CfgSubnets4 > CfgSubnets4Ptr
Non-const pointer.
Parser for D2ClientConfig.
void parse(SrvConfig &srv_cfg, const isc::data::ConstElementPtr &value)
parses JSON structure.
Parser for the configuration of interfaces.
isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configure DHCPv4 server (Dhcpv4Srv) with a set of configuration values.
Class of option definition space container.
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
void parse(const SubnetID &subnet_id, isc::data::ConstElementPtr hr_list, HostCollection &hosts_list)
Parses a list of host reservation entries for a subnet.
void parse(isc::data::ConstElementPtr ids_list)
Parses a list of host identifiers.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< CfgSharedNetworks4 > CfgSharedNetworks4Ptr
Pointer to the configuration of IPv4 shared networks.
Parsers for client class definitions.
Implements parser for config control information, "config-control".
boost::multi_index_container< Subnet4Ptr, 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 > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress,&Network4::getServerId > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime,&data::BaseStampedElement::getModificationTime > > >> Subnet4Collection
A collection of Subnet4 objects.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
To be removed. Please use ConfigError instead.
Acts as a storage vault for D2 client configuration.
void closeCommandSocket()
Shuts down any open control sockets.
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
Parser for a list of shared networks.
boost::shared_ptr< const Element > ConstElementPtr
Parser for option data values within a subnet.
Parser for a list of option definitions.
isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr const &config)
Redact a configuration.
void parse(const CfgIfacePtr &config, const isc::data::ConstElementPtr &values)
Parses content of the "interfaces-config".
Simple parser for sanity-checks structure.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void configureCommandChannel()
Initialize the command channel based on the staging configuration.
ConfigControlInfoPtr parse(const data::ConstElementPtr &config_control)
Parses a configuration control Element.
Parser for a list of host identifiers for DHCPv4.
void loadLibraries() const
Commits hooks libraries configuration.
This is a base class for exceptions thrown from the DNS library module.
void openCommandSocket(const isc::data::ConstElementPtr &socket_info)
Opens control socket with parameters specified in socket_info.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void parse(SrvConfig &srv_cfg, isc::data::ConstElementPtr value)
"Parses" control-socket structure
boost::multi_index_container< SharedNetwork4Ptr, 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< SharedNetwork4, std::string,&SharedNetwork4::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SharedNetworkServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress,&Network4::getServerId > >, 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 > > >> SharedNetwork4Collection
Multi index container holding shared networks.
This file contains several functions and constants that are used for handling commands and responses ...
const isc::log::MessageID DHCP4_PARSER_FAIL
const isc::log::MessageID DHCP4_CONFIG_START
void parse(CfgSharedNetworksTypePtr &cfg, const data::ConstElementPtr &shared_networks_list_data)
Parses a list of shared networks.
The Element class represents a piece of data, used by the command channel and configuration parts...
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
Parser for a list of host reservations for a subnet.
void parse(SrvConfig &srv_cfg, const isc::data::ConstElementPtr &value)
parses JSON structure
void parse(CfgOptionDefPtr cfg, isc::data::ConstElementPtr def_list)
Parses a list of option definitions, create them and store in cfg.
Parser for the control-socket structure.
const int DBG_DHCP4_COMMAND
Debug level used to log receiving commands.
CBControlDHCPv4Ptr getCBControl() const
Returns an object which controls access to the configuration backends.
boost::shared_ptr< D2ClientConfig > D2ClientConfigPtr
Defines a pointer for D2ClientConfig instances.
boost::shared_ptr< ConfigControlInfo > ConfigControlInfoPtr
Defines a pointer to a ConfigControlInfo.
Simple parser for multi-threading structure.
const isc::log::MessageID DHCP4_CONFIG_COMPLETE
void parse(std::string &access_string, isc::data::ConstElementPtr database_config)
Parse configuration value.
void parse(HooksConfig &libraries, isc::data::ConstElementPtr value)
Parses parameters value.
Parser for a list of client class definitions.
Contains declarations for loggers used by the DHCPv4 server component.
void verifyLibraries(const isc::data::Element::Position &position) const
Verifies that libraries stored in libraries_ are valid.
static CommandMgr & instance()
CommandMgr is a singleton class.