]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#103,!277] DHCPv4 server is using CBControlDHCPv4.
authorMarcin Siodelski <marcin@isc.org>
Tue, 19 Mar 2019 12:26:00 +0000 (13:26 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 26 Mar 2019 07:08:56 +0000 (03:08 -0400)
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.h
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/json_config_parser.h

index 40bbe2ca293c7b66c48981032cc215574ada7e98..9f3727122589af39366752b407118694c41c2214 100644 (file)
@@ -447,7 +447,8 @@ Dhcpv4Srv::Dhcpv4Srv(uint16_t server_port, uint16_t client_port,
     : io_service_(new IOService()), shutdown_(true), alloc_engine_(),
       server_port_(server_port), use_bcast_(use_bcast),
       client_port_(client_port),
-      network_state_(new NetworkState(NetworkState::DHCPv4)) {
+      network_state_(new NetworkState(NetworkState::DHCPv4)),
+      cb_control_(new CBControlDHCPv4()) {
 
     LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_OPEN_SOCKET)
         .arg(server_port);
index ccc1ce88a803b79ab2ab7add5196e87f46e3a58d..a92f9f1f7ccb0854491ca1b2f39b09031f78a3fa 100644 (file)
@@ -16,6 +16,7 @@
 #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>
@@ -243,6 +244,15 @@ public:
         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);
@@ -973,6 +983,9 @@ protected:
     /// 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
 
index 549e0957bd298fc4805ddfb8c7d876e4663b95cf..9851dbf16e6b08b40cb791adc1db004007bebcb5 100644 (file)
@@ -15,6 +15,7 @@
 #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>
@@ -623,7 +624,7 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
             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());
@@ -656,101 +657,5 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
     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
index 9a3cfe51310dab0f71cc95a2101711b9ce053f4a..8d1cb9057e945d36ebc0961b789ac9111cdbb8db 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -60,47 +60,6 @@ configureDhcp4Server(Dhcpv4Srv&,
                      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