45 #include <boost/algorithm/string.hpp> 46 #include <boost/foreach.hpp> 47 #include <boost/lexical_cast.hpp> 53 #include <netinet/in.h> 97 bool echo_client_id = getBoolean(global,
"echo-client-id");
98 cfg->setEchoClientId(echo_client_id);
101 uint32_t probation_period =
102 getUint32(global,
"decline-probation-period");
103 cfg->setDeclinePeriod(probation_period);
106 uint16_t dhcp4o6_port = getUint16(global,
"dhcp4o6-port");
107 cfg->setDhcp4o6Port(dhcp4o6_port);
112 cfg->setContext(user_context);
116 std::string server_tag = getString(global,
"server-tag");
117 cfg->setServerTag(server_tag);
133 bool ip_reservations_unique = getBoolean(global,
"ip-reservations-unique");
134 cfg->setIPReservationsUnique(ip_reservations_unique);
146 if (!dest || !from) {
158 for (
auto net = networks->begin(); net != networks->end(); ++net) {
169 for (
auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
187 cfg->sanityChecksLifetime(
"valid-lifetime");
192 sharedNetworksSanityChecks(*networks, global->get(
"shared-networks"));
214 std::set<string> names;
217 for (
auto net = networks.begin(); net != networks.end(); ++net) {
222 bool authoritative = (*net)->getAuthoritative();
223 string iface = (*net)->getIface();
228 for (
auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
229 if ((*subnet)->getAuthoritative() != authoritative) {
231 << (*subnet)->toText()
232 <<
" has different authoritative setting " 233 << (*subnet)->getAuthoritative()
234 <<
" than the shared-network itself: " 239 iface = (*subnet)->getIface();
243 if ((*subnet)->getIface().empty()) {
247 if ((*subnet)->getIface() != iface) {
249 <<
" has specified interface " << (*subnet)->getIface()
250 <<
", but earlier subnet in the same shared-network" 251 <<
" or the shared-network itself used " << iface);
256 txt += (*subnet)->toText() +
" ";
261 if ((*net)->getName().empty()) {
263 << txt <<
" is missing mandatory 'name' parameter");
267 if (names.find((*net)->getName()) != names.end()) {
269 "name " << (*net)->getName() <<
" defined twice.");
271 names.insert((*net)->getName());
292 CfgMgr::instance().getStagingCfg()->getControlSocketInfo();
296 CfgMgr::instance().getCurrentCfg()->getControlSocketInfo();
301 bool sock_changed = (sock_cfg && current_sock_cfg &&
302 !sock_cfg->equals(*current_sock_cfg));
309 if (!sock_cfg || !current_sock_cfg || sock_changed) {
328 string(
"Can't parse NULL config"));
337 Subnet::resetSubnetID();
341 IfaceMgr::instance().closeSockets();
342 TimerMgr::instance()->unregisterTimers();
348 LibDHCP::revertRuntimeOptionDefs();
354 HostDataSourceFactory::printRegistered();
360 bool rollback =
false;
362 string parameter_name;
367 srv_config = CfgMgr::instance().getStagingCfg();
372 mutable_cfg = boost::const_pointer_cast<
Element>(config_set);
378 srv_config->moveDdnsParams(mutable_cfg);
382 BaseNetworkParser::moveReservationMode(mutable_cfg);
385 SimpleParser4::setAllDefaults(mutable_cfg);
388 SimpleParser4::deriveParameters(mutable_cfg);
397 Dhcp4ConfigParser global_parser;
400 global_parser.parseEarly(srv_config, mutable_cfg);
405 parameter_name =
"option-def";
408 parser.
parse(cfg_option_def, option_defs);
413 parameter_name =
"option-data";
416 parser.
parse(cfg_option, option_datas);
420 if (control_socket) {
421 parameter_name =
"control-socket";
423 parser.
parse(*srv_config, control_socket);
427 if (multi_threading) {
428 parameter_name =
"multi-threading";
430 parser.
parse(*srv_config, multi_threading);
434 ConstElementPtr queue_control = mutable_cfg->get(
"dhcp-queue-control");
436 parameter_name =
"dhcp-queue-control";
438 srv_config->setDHCPQueueControl(parser.
parse(queue_control));
442 ConstElementPtr reservations_lookup_first = mutable_cfg->get(
"reservations-lookup-first");
443 if (reservations_lookup_first) {
444 parameter_name =
"reservations-lookup-first";
445 if (MultiThreadingMgr::instance().getMode()) {
448 srv_config->setReservationsLookupFirst(reservations_lookup_first->boolValue());
452 mutable_cfg->get(
"host-reservation-identifiers");
453 if (hr_identifiers) {
454 parameter_name =
"host-reservation-identifiers";
456 parser.
parse(hr_identifiers);
461 parameter_name =
"interfaces-config";
464 parser.
parse(cfg_iface, ifaces_config);
469 parameter_name =
"sanity-checks";
471 parser.
parse(*srv_config, sanity_checks);
475 mutable_cfg->get(
"expired-leases-processing");
476 if (expiration_cfg) {
477 parameter_name =
"expired-leases-processing";
479 parser.
parse(expiration_cfg);
486 if (hooks_libraries) {
487 parameter_name =
"hooks-libraries";
489 HooksConfig& libraries = srv_config->getHooksConfig();
490 hooks_parser.
parse(libraries, hooks_libraries);
500 parameter_name =
"dhcp-ddns";
502 D2ClientConfigParser::setAllDefaults(dhcp_ddns);
504 d2_client_cfg = parser.
parse(dhcp_ddns);
508 if (client_classes) {
509 parameter_name =
"client-classes";
512 parser.
parse(client_classes, AF_INET);
513 srv_config->setClientClassDictionary(dictionary);
518 if (lease_database) {
519 parameter_name =
"lease-database";
521 std::string access_string;
522 parser.
parse(access_string, lease_database);
524 cfg_db_access->setLeaseDbAccessString(access_string);
528 if (hosts_database) {
529 parameter_name =
"hosts-database";
531 std::string access_string;
532 parser.
parse(access_string, hosts_database);
534 cfg_db_access->setHostDbAccessString(access_string);
538 if (hosts_databases) {
539 parameter_name =
"hosts-databases";
541 for (
auto it : hosts_databases->listValue()) {
543 std::string access_string;
544 parser.
parse(access_string, it);
545 cfg_db_access->setHostDbAccessString(access_string);
551 if (shared_networks) {
552 parameter_name =
"shared-networks";
560 parser.
parse(cfg, shared_networks);
564 global_parser.copySubnets4(srv_config->getCfgSubnets4(), cfg);
569 parameter_name =
"subnet4";
572 subnets_parser.
parse(srv_config, subnet4);
577 parameter_name =
"reservations";
580 parser.
parse(SUBNET_ID_GLOBAL, reservations, hosts);
581 for (
auto h = hosts.begin(); h != hosts.end(); ++h) {
582 srv_config->getCfgHosts()->add(*h);
587 if (config_control) {
588 parameter_name =
"config-control";
591 CfgMgr::instance().getStagingCfg()->setConfigControlInfo(config_ctl_info);
596 for (
auto kv : compatibility->mapValue()) {
597 if (kv.first ==
"lenient-option-parsing") {
598 CfgMgr::instance().getStagingCfg()->setLenientOptionParsing(
599 kv.second->boolValue());
601 if (kv.first ==
"ignore-rai-link-selection") {
602 CfgMgr::instance().getStagingCfg()->setIgnoreRAILinkSelection(
603 kv.second->boolValue());
610 const std::map<std::string, ConstElementPtr>& values_map =
611 mutable_cfg->mapValue();
613 BOOST_FOREACH(config_pair, values_map) {
615 parameter_name = config_pair.first;
618 if ((config_pair.first ==
"option-def") ||
619 (config_pair.first ==
"option-data") ||
620 (config_pair.first ==
"control-socket") ||
621 (config_pair.first ==
"multi-threading") ||
622 (config_pair.first ==
"dhcp-queue-control") ||
623 (config_pair.first ==
"host-reservation-identifiers") ||
624 (config_pair.first ==
"interfaces-config") ||
625 (config_pair.first ==
"sanity-checks") ||
626 (config_pair.first ==
"expired-leases-processing") ||
627 (config_pair.first ==
"hooks-libraries") ||
628 (config_pair.first ==
"dhcp-ddns") ||
629 (config_pair.first ==
"client-classes") ||
630 (config_pair.first ==
"lease-database") ||
631 (config_pair.first ==
"hosts-database") ||
632 (config_pair.first ==
"hosts-databases") ||
633 (config_pair.first ==
"subnet4") ||
634 (config_pair.first ==
"shared-networks") ||
635 (config_pair.first ==
"reservations") ||
636 (config_pair.first ==
"config-control") ||
637 (config_pair.first ==
"loggers") ||
638 (config_pair.first ==
"compatibility")) {
652 if ( (config_pair.first ==
"renew-timer") ||
653 (config_pair.first ==
"rebind-timer") ||
654 (config_pair.first ==
"valid-lifetime") ||
655 (config_pair.first ==
"min-valid-lifetime") ||
656 (config_pair.first ==
"max-valid-lifetime") ||
657 (config_pair.first ==
"decline-probation-period") ||
658 (config_pair.first ==
"dhcp4o6-port") ||
659 (config_pair.first ==
"echo-client-id") ||
660 (config_pair.first ==
"match-client-id") ||
661 (config_pair.first ==
"authoritative") ||
662 (config_pair.first ==
"next-server") ||
663 (config_pair.first ==
"server-hostname") ||
664 (config_pair.first ==
"boot-file-name") ||
665 (config_pair.first ==
"server-tag") ||
666 (config_pair.first ==
"reservation-mode") ||
667 (config_pair.first ==
"reservations-global") ||
668 (config_pair.first ==
"reservations-in-subnet") ||
669 (config_pair.first ==
"reservations-out-of-pool") ||
670 (config_pair.first ==
"calculate-tee-times") ||
671 (config_pair.first ==
"t1-percent") ||
672 (config_pair.first ==
"t2-percent") ||
673 (config_pair.first ==
"cache-threshold") ||
674 (config_pair.first ==
"cache-max-age") ||
675 (config_pair.first ==
"hostname-char-set") ||
676 (config_pair.first ==
"hostname-char-replacement") ||
677 (config_pair.first ==
"ddns-send-updates") ||
678 (config_pair.first ==
"ddns-override-no-update") ||
679 (config_pair.first ==
"ddns-override-client-update") ||
680 (config_pair.first ==
"ddns-replace-client-name") ||
681 (config_pair.first ==
"ddns-generated-prefix") ||
682 (config_pair.first ==
"ddns-qualifying-suffix") ||
683 (config_pair.first ==
"ddns-update-on-renew") ||
684 (config_pair.first ==
"ddns-use-conflict-resolution") ||
685 (config_pair.first ==
"store-extended-info") ||
686 (config_pair.first ==
"statistic-default-sample-count") ||
687 (config_pair.first ==
"statistic-default-sample-age") ||
688 (config_pair.first ==
"early-global-reservations-lookup") ||
689 (config_pair.first ==
"ip-reservations-unique") ||
690 (config_pair.first ==
"reservations-lookup-first") ||
691 (config_pair.first ==
"parked-packet-limit") ||
692 (config_pair.first ==
"allocator") ) {
693 CfgMgr::instance().getStagingCfg()->addConfiguredGlobal(config_pair.first,
699 if (config_pair.first ==
"user-context") {
705 "unsupported global configuration parameter: " << config_pair.first
706 <<
" (" << config_pair.second->getPosition() <<
")");
710 parameter_name =
"<post parsing>";
713 global_parser.parse(srv_config, mutable_cfg);
718 global_parser.sanityChecks(srv_config, mutable_cfg);
721 if (!d2_client_cfg) {
724 d2_client_cfg->validateContents();
725 srv_config->setD2ClientConfig(d2_client_cfg);
728 .arg(parameter_name).arg(ex.
what());
737 " processing error");
747 "Configuration seems sane. Control-socket, hook-libraries, and D2 " 748 "configuration were sanity checked, but not applied.");
767 cfg = CfgMgr::instance().getStagingCfg()->getD2ClientConfig();
768 CfgMgr::instance().setD2ClientConfig(cfg);
773 HooksManager::prepareUnloadLibraries();
774 static_cast<void>(HooksManager::unloadLibraries());
776 CfgMgr::instance().getStagingCfg()->getHooksConfig();
801 CBControlDHCPv4::FetchMode::FETCH_ALL);
803 std::ostringstream err;
804 err <<
"during update from config backend database: " << ex.
what();
812 std::ostringstream err;
813 err <<
"during update from config backend database: " 814 <<
"undefined configuration parsing error";
827 LibDHCP::revertRuntimeOptionDefs();
832 .arg(CfgMgr::instance().getStagingCfg()->
833 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.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
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.
#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.
isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configure DHCPv4 server (Dhcpv4Srv) with a set of configuration values.
const isc::log::MessageID DHCP4_PARSER_COMMIT_EXCEPTION
const isc::log::MessageID DHCP4_RESERVATIONS_LOOKUP_FIRST_ENABLED
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.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void parse(SrvConfig &srv_cfg, const isc::data::ConstElementPtr &value)
parses JSON structure.
Parser for the configuration of interfaces.
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::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.
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 > > >> Subnet4SimpleCollection
A simple collection of Subnet4 objects.
Parser for a list of shared networks.
boost::shared_ptr< const Element > ConstElementPtr
void verifyLibraries(const isc::data::Element::Position &position) const
Verifies that libraries stored in libraries_ are valid.
Parser for option data values within a subnet.
Parser for a list of option definitions.
void loadLibraries() const
Commits hooks libraries configuration.
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.
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.
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-lfc.
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.
ClientClassDictionaryPtr parse(isc::data::ConstElementPtr class_def_list, uint16_t family, bool check_dependencies=true)
Parse configuration entries.
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.
CBControlDHCPv4Ptr getCBControl() const
Returns an object which controls access to the configuration backends.
Parser for the control-socket structure.
const int DBG_DHCP4_COMMAND
Debug level used to log receiving commands.
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.
static CommandMgr & instance()
CommandMgr is a singleton class.