#include <dhcp/option_custom.h>
#include <dhcp_ddns/ncr_msg.h>
#include <dhcpsrv/alloc_engine.h>
+#include <dhcpsrv/cb_ctl_dhcp4.h>
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/callout_handle_store.h>
#include <dhcpsrv/d2_client_mgr.h>
return (network_state_);
}
+ /// @brief Returns an object which controls access to the configuration
+ /// backends.
+ ///
+ /// @return Pointer to the instance of the object which controls
+ /// access to the configuration backends.
+ CBControlDHCPv4Ptr getCBControl() const {
+ return (cb_control_);
+ }
+
/// @brief returns Kea version on stdout and exit.
/// redeclaration/redefinition. @ref isc::process::Daemon::getVersion()
static std::string getVersion(bool extended);
/// disabled subnet/network scopes.
NetworkStatePtr network_state_;
+ /// @brief Controls access to the configuration backends.
+ CBControlDHCPv4Ptr cb_control_;
+
public:
/// Class methods for DHCPv4-over-DHCPv6 handler
#include <dhcp4/json_config_parser.h>
#include <dhcp/libdhcp++.h>
#include <dhcp/option_definition.h>
+#include <dhcpsrv/cb_ctl_dhcp4.h>
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/config_backend_dhcp4_mgr.h>
libraries.loadLibraries();
// If there are config backends, fetch and merge into staging config
- databaseConfigFetch(srv_cfg);
+ server.getCBControl()->databaseConfigFetch(srv_cfg, false);
}
catch (const isc::Exception& ex) {
LOG_ERROR(dhcp4_logger, DHCP4_PARSER_COMMIT_FAIL).arg(ex.what());
return (answer);
}
-void databaseConfigFetch(const SrvConfigPtr& srv_cfg) {
-
- ConfigBackendDHCPv4Mgr& mgr = ConfigBackendDHCPv4Mgr::instance();
-
- // Close any existing CB databasess, then open all in srv_cfg (if any)
- if (!databaseConfigConnect(srv_cfg)) {
- // There are no CB databases so we're done
- return;
- }
-
- LOG_INFO(dhcp4_logger, DHCP4_CONFIG_FETCH);
-
- // For now we find data based on first backend that has it.
- BackendSelector backend_selector(BackendSelector::Type::UNSPEC);
-
- // Use the server_tag if set, otherwise use ALL.
- std::string server_tag = srv_cfg->getServerTag();
- ServerSelector& server_selector = (server_tag.empty()? ServerSelector::ALL()
- : ServerSelector::ONE(server_tag));
- // Create the external config into which we'll fetch backend config data.
- SrvConfigPtr external_cfg = CfgMgr::instance().createExternalCfg();
-
- // First let's fetch the globals and add them to external config.
- data::StampedValueCollection globals;
- globals = mgr.getPool()->getAllGlobalParameters4(backend_selector, server_selector);
- addGlobalsToConfig(external_cfg, globals);
-
- // Now we fetch the option definitions and add them.
- OptionDefContainer option_defs = mgr.getPool()->getAllOptionDefs4(backend_selector,
- server_selector);
- for (auto option_def = option_defs.begin(); option_def != option_defs.end(); ++option_def) {
- external_cfg->getCfgOptionDef()->add((*option_def), (*option_def)->getOptionSpaceName());
- }
-
- // Next fetch the options. They are returned as a container of OptionDescriptors.
- OptionContainer options = mgr.getPool()->getAllOptions4(backend_selector, server_selector);
- for (auto option = options.begin(); option != options.end(); ++option) {
- external_cfg->getCfgOption()->add((*option), (*option).space_name_);
- }
-
- // Now fetch the shared networks.
- SharedNetwork4Collection networks = mgr.getPool()->getAllSharedNetworks4(backend_selector,
- server_selector);
- for (auto network = networks.begin(); network != networks.end(); ++network) {
- external_cfg->getCfgSharedNetworks4()->add((*network));
- }
-
- // Next we fetch subnets.
- Subnet4Collection subnets = mgr.getPool()->getAllSubnets4(backend_selector, server_selector);
- for (auto subnet = subnets.begin(); subnet != subnets.end(); ++subnet) {
- external_cfg->getCfgSubnets4()->add((*subnet));
- }
-
- // Now we merge the fecthed configuration into the staging configuration.
- CfgMgr::instance().mergeIntoStagingCfg(external_cfg->getSequence());
- LOG_INFO(dhcp4_logger, DHCP4_CONFIG_MERGED);
-}
-
-bool databaseConfigConnect(const SrvConfigPtr& srv_cfg) {
- // We need to get rid of any existing backends. These would be any
- // opened by previous configuration cycle.
- ConfigBackendDHCPv4Mgr& mgr = ConfigBackendDHCPv4Mgr::instance();
- mgr.delAllBackends();
-
- // Fetch the config-control info.
- ConstConfigControlInfoPtr config_ctl = srv_cfg->getConfigControlInfo();
- if (!config_ctl || config_ctl->getConfigDatabases().empty()) {
- // No config dbs, nothing to do.
- return (false);
- }
-
- // Iterate over the configured DBs and instantiate them.
- for (auto db : config_ctl->getConfigDatabases()) {
- LOG_INFO(dhcp4_logger, DHCP4_OPEN_CONFIG_DB)
- .arg(db.redactedAccessString());
- mgr.addBackend(db.getAccessString());
- }
-
- // Let the caller know we have opened DBs.
- return (true);
-}
-
-
-void addGlobalsToConfig(SrvConfigPtr external_cfg, data::StampedValueCollection& cb_globals) {
- const auto& index = cb_globals.get<StampedValueNameIndexTag>();
- for (auto cb_global = index.begin(); cb_global != index.end(); ++cb_global) {
-
- if ((*cb_global)->amNull()) {
- continue;
- }
-
- external_cfg->addConfiguredGlobal((*cb_global)->getName(),
- (*cb_global)->getElementValue());
- }
-}
-
}; // end of isc::dhcp namespace
}; // end of isc namespace
-// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2019 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
isc::data::ConstElementPtr config_set,
bool check_only = false);
-/// @brief Fetch and merge data from config backends into the staging config
-///
-/// If the given SrvConfig specifies one or more config backends it calls
-/// @c databaseConfigConnect() to open connections to them, otherwise it
-/// simply returns. Next it creates an external SrvConfig instance,
-/// and populates with data it fetches from the config backends.
-/// Finally, it merges this external config into the staging config.
-///
-/// @param srv_cfg server configuration that (may) specify the backends
-/// should be merged
-void
-databaseConfigFetch(const SrvConfigPtr& srv_cfg);
-
-/// @brief Attempts to connect to configured CB databases
-///
-/// First, this function will close all existing CB backends. It
-/// will then attempt to connect to all of the CB backends defined
-/// in the given SrvConfig (if any).
-///
-/// It will return true if there are configured CB databases,
-/// and false otherwise. Any errors encountered along the way
-/// should generate throws.
-///
-/// @param srv_cfg Server configuration from which to get
-/// the config-control information to use.
-///
-/// @return True if there are configured CB databases, false if not.
-bool
-databaseConfigConnect(const SrvConfigPtr& srv_cfg);
-
-/// @brief Adds globals fetched from config backend(s) to a SrvConfig instance
-///
-/// Iterates over the given collection of global parameters and adds them to the
-/// given configuration's list of configured globals.
-///
-/// @param external_cfg SrvConfig instance to update
-/// @param cb_globals collection of global parameters supplied by configuration
-/// backend
-void addGlobalsToConfig(SrvConfigPtr external_cfg,
- data::StampedValueCollection& cb_globals);
-
}; // end of isc::dhcp namespace
}; // end of isc namespace