39#include <boost/foreach.hpp>
40#include <boost/lexical_cast.hpp>
41#include <boost/algorithm/string.hpp>
45#include <netinet/in.h>
89 bool echo_client_id =
getBoolean(global,
"echo-client-id");
90 cfg->setEchoClientId(echo_client_id);
93 uint32_t probation_period =
94 getUint32(global,
"decline-probation-period");
95 cfg->setDeclinePeriod(probation_period);
98 uint16_t dhcp4o6_port =
getUint16(global,
"dhcp4o6-port");
99 cfg->setDhcp4o6Port(dhcp4o6_port);
104 cfg->setContext(user_context);
108 std::string server_tag =
getString(global,
"server-tag");
109 cfg->setServerTag(server_tag);
121 if (!dest || !from) {
133 for (
auto net = networks->begin(); net != networks->end(); ++net) {
144 for (
auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
164 sharedNetworksSanityChecks(*networks, global->get(
"shared-networks"));
186 std::set<string> names;
189 for (
auto net = networks.begin(); net != networks.end(); ++net) {
194 string iface = (*net)->getIface();
195 bool authoritative = (*net)->getAuthoritative();
200 for (
auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
202 iface = (*subnet)->getIface();
206 if ((*subnet)->getIface().empty()) {
210 if (iface != (*subnet)->getIface()) {
212 <<
" has specified interface " << (*subnet)->getIface()
213 <<
", but earlier subnet in the same shared-network"
214 <<
" or the shared-network itself used " << iface);
217 if (authoritative != (*subnet)->getAuthoritative()) {
219 <<
" has different authoritative setting "
220 << (*subnet)->getAuthoritative()
221 <<
" than the shared-network itself: "
227 txt += (*subnet)->toText() +
" ";
232 if ((*net)->getName().empty()) {
234 << txt <<
" is missing mandatory 'name' parameter");
238 if (names.find((*net)->getName()) != names.end()) {
240 "name " << (*net)->getName() <<
" defined twice.");
242 names.insert((*net)->getName());
272 bool sock_changed = (sock_cfg && current_sock_cfg &&
273 !sock_cfg->equals(*current_sock_cfg));
280 if (!sock_cfg || !current_sock_cfg || sock_changed) {
299 string(
"Can't parse NULL config"));
304 DHCP4_CONFIG_START).arg(config_set->str());
329 bool rollback =
false;
341 srv_cfg->extractConfiguredGlobals(config_set);
346 mutable_cfg = boost::const_pointer_cast<Element>(config_set);
359 parser.
parse(cfg_option_def, option_defs);
364 Dhcp4ConfigParser global_parser;
367 const std::map<std::string, ConstElementPtr>& values_map =
368 mutable_cfg->mapValue();
369 BOOST_FOREACH(config_pair, values_map) {
375 if (config_pair.first ==
"option-def") {
380 if (config_pair.first ==
"option-data") {
383 parser.
parse(cfg_option, config_pair.second);
387 if (config_pair.first ==
"control-socket") {
389 parser.
parse(*srv_cfg, config_pair.second);
393 if (config_pair.first ==
"dhcp-queue-control") {
395 srv_cfg->setDHCPQueueControl(parser.
parse(config_pair.second));
399 if (config_pair.first ==
"host-reservation-identifiers") {
401 parser.
parse(config_pair.second);
405 if (config_pair.first ==
"interfaces-config") {
407 boost::const_pointer_cast<Element>(config_pair.second);
414 parser.
parse(cfg_iface, ifaces_cfg);
418 if (config_pair.first ==
"sanity-checks") {
420 parser.
parse(*srv_cfg, config_pair.second);
424 if (config_pair.first ==
"expired-leases-processing") {
426 parser.
parse(config_pair.second);
430 if (config_pair.first ==
"hooks-libraries") {
432 HooksConfig& libraries = srv_cfg->getHooksConfig();
433 hooks_parser.
parse(libraries, config_pair.second);
439 if (config_pair.first ==
"dhcp-ddns") {
444 srv_cfg->setD2ClientConfig(cfg);
448 if (config_pair.first ==
"client-classes") {
451 parser.
parse(config_pair.second, AF_INET);
452 srv_cfg->setClientClassDictionary(dictionary);
457 if (config_pair.first ==
"lease-database") {
459 std::string access_string;
460 parser.
parse(access_string, config_pair.second);
462 cfg_db_access->setLeaseDbAccessString(access_string);
466 if (config_pair.first ==
"hosts-database") {
468 std::string access_string;
469 parser.
parse(access_string, config_pair.second);
471 cfg_db_access->setHostDbAccessString(access_string);
475 if (config_pair.first ==
"hosts-databases") {
478 auto list = config_pair.second->listValue();
479 for (
auto it : list) {
480 std::string access_string;
481 parser.
parse(access_string, it);
482 cfg_db_access->setHostDbAccessString(access_string);
487 if (config_pair.first ==
"subnet4") {
490 subnets_parser.
parse(srv_cfg, config_pair.second);
494 if (config_pair.first ==
"shared-networks") {
503 parser.
parse(cfg, config_pair.second);
507 global_parser.copySubnets4(srv_cfg->getCfgSubnets4(), cfg);
511 if (config_pair.first ==
"reservations") {
514 parser.
parse(SUBNET_ID_GLOBAL, config_pair.second, hosts);
515 for (
auto h = hosts.begin(); h != hosts.end(); ++h) {
516 srv_cfg->getCfgHosts()->add(*h);
522 if (config_pair.first ==
"config-control") {
536 if ( (config_pair.first ==
"renew-timer") ||
537 (config_pair.first ==
"rebind-timer") ||
538 (config_pair.first ==
"valid-lifetime") ||
539 (config_pair.first ==
"decline-probation-period") ||
540 (config_pair.first ==
"dhcp4o6-port") ||
541 (config_pair.first ==
"echo-client-id") ||
542 (config_pair.first ==
"user-context") ||
543 (config_pair.first ==
"match-client-id") ||
544 (config_pair.first ==
"authoritative") ||
545 (config_pair.first ==
"next-server") ||
546 (config_pair.first ==
"server-hostname") ||
547 (config_pair.first ==
"boot-file-name") ||
548 (config_pair.first ==
"server-tag") ||
549 (config_pair.first ==
"reservation-mode")) {
555 "unsupported global configuration parameter: " << config_pair.first
556 <<
" (" << config_pair.second->getPosition() <<
")");
560 global_parser.parse(srv_cfg, mutable_cfg);
565 global_parser.sanityChecks(srv_cfg, mutable_cfg);
569 .arg(config_pair.first).arg(ex.
what());
579 " processing error");
589 "Configuration seems sane. Control-socket, hook-libraries, and D2 "
590 "configuration were sanity checked, but not applied.");
662 if (!config_ctl || config_ctl->getConfigDatabases().empty()) {
668 for (
auto db : config_ctl->getConfigDatabases()) {
670 .arg(db.redactedAccessString());
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 addBackend(const std::string &dbaccess)
Create an instance of a configuration backend.
void delAllBackends()
Removes all backends from the pool.
void closeCommandSocket()
Shuts down any open control sockets.
static CommandMgr & instance()
CommandMgr is a singleton class.
void openCommandSocket(const isc::data::ConstElementPtr &socket_info)
Opens control socket with parameters specified in socket_info.
static ElementPtr create(const Position &pos=ZERO_POSITION())
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.
void setD2ClientConfig(D2ClientConfigPtr &new_config)
Updates the DHCP-DDNS client configuration to the given value.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Parser for a list of client class definitions.
ClientClassDictionaryPtr parse(isc::data::ConstElementPtr class_def_list, uint16_t family)
Parse configuration entries.
Configuration Backend Manager for DHPCv4 servers.
static ConfigBackendDHCPv4Mgr & instance()
Returns a sole instance of the ConfigBackendDHCPv4Mgr.
Parser for the control-socket structure.
void parse(SrvConfig &srv_cfg, isc::data::ConstElementPtr value)
"Parses" control-socket structure
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.
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".
To be removed. Please use ConfigError instead.
void discardPackets()
Discard all in-progress packets.
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 DHCPv4.
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.
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 void revertRuntimeOptionDefs()
Reverts uncommitted changes to runtime option definitions.
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.
void parse(CfgOptionDefPtr cfg, isc::data::ConstElementPtr def_list)
Parses a list of option definitions, create them and store in cfg.
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 DHCPv4 configuration.
static const uint32_t CFGSEL_ALL4
IPv4 related config.
static void resetSubnetID()
Resets subnet-id counter to its initial value (1)
this class parses list of DHCP4 subnets
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.
Wrapper class that holds hooks libraries configuration.
void verifyLibraries(const isc::data::Element::Position &position) const
Verifies that libraries stored in libraries_ are valid.
void loadLibraries() const
Commits hooks libraries configuration.
Parser for hooks library list.
void parse(HooksConfig &libraries, isc::data::ConstElementPtr value)
Parses parameters value.
Implements parser for config control information, "config-control".
ConfigControlInfoPtr parse(const data::ConstElementPtr &config_control)
Parses a configuration control Element.
Parsers for client class definitions.
This file contains several functions and constants that are used for handling commands and responses ...
Contains declarations for loggers used by the DHCPv4 server component.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#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_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.
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::multi_index_container< SharedNetwork4Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SharedNetworkRandomAccessIndexTag > >, 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 > > > > SharedNetwork4Collection
Multi index container holding shared networks.
OptionSpaceContainer< OptionDefContainer, OptionDefinitionPtr, std::string > OptionDefSpaceContainer
std::pair< std::string, isc::data::ConstElementPtr > ConfigPair
Combination of parameter name and configuration contents.
boost::shared_ptr< D2ClientConfig > D2ClientConfigPtr
Defines a pointer for D2ClientConfig instances.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
void databaseConfigFetch(const SrvConfigPtr &srv_cfg, ElementPtr)
Fetch configuration from CB databases and merge it into the given configuration.
bool databaseConfigConnect(const SrvConfigPtr &srv_cfg)
Attempts to connect to configured CB databases.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< CfgDbAccess > CfgDbAccessPtr
A pointer to the CfgDbAccess.
isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configure DHCPv4 server (Dhcpv4Srv) with a set of configuration values.
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
std::vector< HostPtr > HostCollection
Collection of the Host objects.
const int DBG_DHCP4_COMMAND
Debug level used to log receiving commands.
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
boost::shared_ptr< CfgSubnets4 > CfgSubnets4Ptr
Non-const pointer.
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SubnetRandomAccessIndexTag > >, 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 > > > > Subnet4Collection
A collection of Subnet4 objects.
boost::shared_ptr< CfgSharedNetworks4 > CfgSharedNetworks4Ptr
Pointer to the configuration of IPv4 shared networks.
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
boost::shared_ptr< const ConfigControlInfo > ConstConfigControlInfoPtr
Defines a pointer to a const ConfigControlInfo.
boost::shared_ptr< ConfigControlInfo > ConfigControlInfoPtr
Defines a pointer to a ConfigControlInfo.
Defines the logger used by the top-level component of kea-dhcp-ddns.