libkea_dhcpsrv_la_SOURCES += base_host_data_source.h
libkea_dhcpsrv_la_SOURCES += cache_host_data_source.h
libkea_dhcpsrv_la_SOURCES += callout_handle_store.h
+libkea_dhcpsrv_la_SOURCES += cb_ctl_dhcp.h
libkea_dhcpsrv_la_SOURCES += cb_ctl_dhcp4.cc cb_ctl_dhcp4.h
libkea_dhcpsrv_la_SOURCES += cfg_4o6.cc cfg_4o6.h
libkea_dhcpsrv_la_SOURCES += cfg_consistency.cc cfg_consistency.h
base_host_data_source.h \
cache_host_data_source.h \
callout_handle_store.h \
+ cb_ctl_dhcp.h \
cb_ctl_dhcp4.h \
cfg_4o6.h \
cfg_consistency.h \
--- /dev/null
+// Copyright (C) 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef CB_CTL_DHCP_H
+#define CB_CTL_DHCP_H
+
+#include <cc/stamped_value.h>
+#include <process/cb_ctl_base.h>
+#include <dhcpsrv/srv_config.h>
+
+namespace isc {
+namespace dhcp {
+
+/// @brief Base class for implementing mechanisms to control the use
+/// of the Configuration Backends by DHCPv4 and DHCPv6 servers.
+///
+/// It includes common methods used by the DHCPv4 and DHCPv6 specific
+/// derivations.
+///
+/// @tparam ConfigBackendMgrType Type of the Config Backend Manager used
+/// by the server implementing this class. For example, for the DHCPv4
+/// server it will be @c ConfigBackendDHCPv4Mgr.
+template<typename ConfigBackendMgrType>
+class CBControlDHCP : public process::CBControlBase<ConfigBackendMgrType> {
+public:
+
+ /// @brief Constructor.
+ CBControlDHCP()
+ : process::CBControlBase<ConfigBackendMgrType>() {
+ }
+
+protected:
+
+ /// @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) const {
+ const auto& index = cb_globals.get<data::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 namespace isc::dhcp
+} // end of namespace isc
+
+#endif // CB_CTL_DHCP_H
#include <config.h>
#include <dhcpsrv/cb_ctl_dhcp4.h>
+#include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/dhcpsrv_log.h>
+using namespace isc::data;
using namespace isc::process;
namespace isc {
namespace dhcp {
-CBControlDHCPv4::CBControlDHCPv4()
- : CBControlBase<ConfigBackendDHCPv4Mgr>() {
+void
+CBControlDHCPv4::databaseConfigApply(const ConfigPtr& srv_cfg,
+ const db::BackendSelector& backend_selector,
+ const db::ServerSelector& server_selector,
+ const boost::posix_time::ptime& lb_modification_time,
+ const db::AuditEntryCollection& audit_entries) {
+ // 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.
+ if (fetchConfigElement(audit_entries, "dhcp4_global_parameter")) {
+ data::StampedValueCollection globals;
+ globals = getMgr().getPool()->getModifiedGlobalParameters4(backend_selector, server_selector,
+ lb_modification_time);
+ addGlobalsToConfig(external_cfg, globals);
+ }
+
+ // Now we fetch the option definitions and add them.
+ if (fetchConfigElement(audit_entries, "dhcp4_option_def")) {
+ OptionDefContainer option_defs =
+ getMgr().getPool()->getModifiedOptionDefs4(backend_selector, server_selector,
+ lb_modification_time);
+ 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.
+ if (fetchConfigElement(audit_entries, "dhcp4_options")) {
+ OptionContainer options = getMgr().getPool()->getModifiedOptions4(backend_selector,
+ server_selector,
+ lb_modification_time);
+ for (auto option = options.begin(); option != options.end(); ++option) {
+ external_cfg->getCfgOption()->add((*option), (*option).space_name_);
+ }
+ }
+
+ // Now fetch the shared networks.
+ if (fetchConfigElement(audit_entries, "dhcp4_shared_network")) {
+ SharedNetwork4Collection networks =
+ getMgr().getPool()->getModifiedSharedNetworks4(backend_selector, server_selector,
+ lb_modification_time);
+ for (auto network = networks.begin(); network != networks.end(); ++network) {
+ external_cfg->getCfgSharedNetworks4()->add((*network));
+ }
+ }
+
+ // Next we fetch subnets.
+ if (fetchConfigElement(audit_entries, "dhcp4_subnet")) {
+ Subnet4Collection subnets = getMgr().getPool()->getModifiedSubnets4(backend_selector,
+ server_selector,
+ lb_modification_time);
+ for (auto subnet = subnets.begin(); subnet != subnets.end(); ++subnet) {
+ external_cfg->getCfgSubnets4()->add((*subnet));
+ }
+ }
+
+ if (audit_entries.empty()) {
+ CfgMgr::instance().mergeIntoStagingCfg(external_cfg->getSequence());
+
+ } else {
+ CfgMgr::instance().mergeIntoCurrentCfg(external_cfg->getSequence());
+ }
+ LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_CONFIG4_MERGED);
}
+
} // end of namespace isc::dhcp
} // end of namespace isc
#ifndef CB_CTL_DHCP4_H
#define CB_CTL_DHCP4_H
-#include <process/cb_ctl_base.h>
+#include <dhcpsrv/cb_ctl_dhcp.h>
#include <dhcpsrv/config_backend_dhcp4_mgr.h>
+#include <dhcpsrv/srv_config.h>
namespace isc {
namespace dhcp {
-class CBControlDHCPv4 : public process::CBControlBase<ConfigBackendDHCPv4Mgr> {
-public:
-
- CBControlDHCPv4();
+/// @brief Implementation of the mechanisms to control the use of
+/// the Configuration Backends by the DHCPv4 server.
+///
+/// It implements fetching and merging DHCPv4 server configuration from
+/// the database into the staging or current configuration.
+///
+/// @tparam ConfigBackendMgrType Type of the Config Backend Manager used
+/// by the server implementing this class. For example, for the DHCPv4
+/// server it will be @c ConfigBackendDHCPv4Mgr.
+class CBControlDHCPv4 : public CBControlDHCP<ConfigBackendDHCPv4Mgr> {
+protected:
+
+ /// @brief Fetches the entire or partial configuration from the database.
+ ///
+ /// This method is called by the starting up server to fetch and merge
+ /// the entire configuration from the database or to fetch configuration
+ /// updates periodically, e.g. as a result of triggering an interval
+ /// timer callback.
+ ///
+ /// @param srv_cfg pointer to the staging configuration that should
+ /// hold the config backends list and other partial configuration read
+ /// from the file in case the method is called upon the server's start
+ /// up. It is a pointer to the current server configuration if the
+ /// method is called to fetch configuration updates.
+ /// @param fetch_updates_only boolean value indicating if the method is
+ /// called upon the server start up (false) or it is called to fetch
+ /// configuration updates (true).
+ virtual void databaseConfigApply(const process::ConfigPtr& srv_cfg,
+ const db::BackendSelector& backend_selector,
+ const db::ServerSelector& server_selector,
+ const boost::posix_time::ptime& lb_modification_time,
+ const db::AuditEntryCollection& audit_entries);
};
+typedef boost::shared_ptr<CBControlDHCPv4> CBControlDHCPv4Ptr;
} // end of namespace isc::dhcp
} // end of namespace isc
libdhcpsrv_unittests_SOURCES += alloc_engine4_unittest.cc
libdhcpsrv_unittests_SOURCES += alloc_engine6_unittest.cc
libdhcpsrv_unittests_SOURCES += callout_handle_store_unittest.cc
+libdhcpsrv_unittests_SOURCES += cb_ctl_dhcp_unittest.cc
libdhcpsrv_unittests_SOURCES += cfg_db_access_unittest.cc
libdhcpsrv_unittests_SOURCES += cfg_duid_unittest.cc
libdhcpsrv_unittests_SOURCES += cfg_expiration_unittest.cc
--- /dev/null
+// Copyright (C) 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <dhcpsrv/cb_ctl_dhcp4.h>
+#include <gtest/gtest.h>
+
+using namespace isc::dhcp;
+
+namespace {
+
+/// @brief Test fixture class for @c CBControlDHCPv4 unit tests.
+class TestCBControlDHCPv4 : public CBControlDHCPv4 {
+public:
+
+ using CBControlDHCPv4::databaseConfigApply;
+};
+
+
+// This test verifies that the configuration updates are
+// merged into the current configuration.
+TEST(CBControlDHCPv4Test, databaseConfigApplyUpdates) {
+ TestCBControlDHCPv4 ctl;
+ /// @todo implement the actual test.
+}
+
+
+}