]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[421-create-config-backend-for-dhcpv6-base] Added DHCPv6 config backend support in... 421-create-config-backend-for-dhcpv6-base
authorFrancis Dupont <fdupont@isc.org>
Mon, 21 Jan 2019 12:51:48 +0000 (13:51 +0100)
committerFrancis Dupont <fdupont@isc.org>
Mon, 21 Jan 2019 12:51:48 +0000 (13:51 +0100)
src/bin/dhcp6/dhcp6_messages.mes
src/bin/dhcp6/json_config_parser.cc
src/bin/dhcp6/json_config_parser.h
src/bin/dhcp6/tests/config_parser_unittest.cc

index 9079efb09ef79eeff3678c74c1f0c2822eae9644..8896715477fcd817cb7da94ee32d6afd24a59ab3 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
@@ -472,6 +472,11 @@ This warning message is issued when current server configuration specifies
 no interfaces that server should listen on, or specified interfaces are not
 configured to receive the traffic.
 
+% DHCP6_OPEN_CONFIG_DB Opening configuration database: %1
+This message is printed when the DHCPv6 server is attempting to open a
+configuration database.  The database access string with password redacted
+is logged.
+
 % DHCP6_OPEN_SOCKET opening service sockets on port %1
 A debug message issued during startup, this indicates that the IPv6 DHCP
 server is about to open sockets on the specified port.
index 26d48310618915b12d4ee9a950197884bfa78f9e..2593030a7b61291043809ad913a70515592bd06c 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
@@ -18,6 +18,7 @@
 #include <dhcp/iface_mgr.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/config_backend_dhcp6_mgr.h>
 #include <dhcpsrv/db_type.h>
 #include <dhcpsrv/pool.h>
 #include <dhcpsrv/subnet.h>
@@ -62,6 +63,7 @@ using namespace isc::data;
 using namespace isc::dhcp;
 using namespace isc::asiolink;
 using namespace isc::hooks;
+using namespace isc::process;
 
 namespace {
 
@@ -619,8 +621,8 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
             }
 
             if (config_pair.first == "config-control") {
-                process::ConfigControlParser parser;
-                process::ConfigControlInfoPtr config_ctl_info = parser.parse(config_pair.second);
+                ConfigControlParser parser;
+                ConfigControlInfoPtr config_ctl_info = parser.parse(config_pair.second);
                 CfgMgr::instance().getStagingCfg()->setConfigControlInfo(config_ctl_info);
                 continue;
             }
@@ -711,6 +713,11 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
             const HooksConfig& libraries =
                 CfgMgr::instance().getStagingCfg()->getHooksConfig();
             libraries.loadLibraries();
+
+#ifdef CONFIG_BACKEND // Disabled until we restart CB work
+            // If there are config backends, fetch and merge into staging config
+            databaseConfigFetch(srv_cfg, mutable_cfg);
+#endif
         }
         catch (const isc::Exception& ex) {
             LOG_ERROR(dhcp6_logger, DHCP6_PARSER_COMMIT_FAIL).arg(ex.what());
@@ -744,5 +751,48 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
     return (answer);
 }
 
+bool databaseConfigConnect(const SrvConfigPtr& srv_cfg) {
+    // We need to get rid of any existing backends.  These would be any
+    // opened by previous configuration cycle.
+    ConfigBackendDHCPv6Mgr& mgr = ConfigBackendDHCPv6Mgr::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(dhcp6_logger, DHCP6_OPEN_CONFIG_DB)
+                 .arg(db.redactedAccessString());
+        mgr.addBackend(db.getAccessString());
+    }
+
+    // Let the caller know we have opened DBs.
+    return (true);
+}
+
+void databaseConfigFetch(const SrvConfigPtr& srv_cfg, ElementPtr /* mutable_cfg */) {
+
+    // 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;
+    }
+
+    // @todo Fetching and merging the configuration falls under #99
+    // ConfigBackendDHCPv6Mgr& mgr = ConfigBackendDHCPv6Mgr::instance();
+    // Next we have to fetch the pieces we care about it and merge them
+    // probably in this order?
+    // globals
+    // option defs
+    // options
+    // shared networks
+    // subnets
+}
+
 }; // end of isc::dhcp namespace
 }; // end of isc namespace
index 3267eac4ba16f265c617f809955fa663bcc9a23c..95a42dc126fa22641c896c796a883bcaecd5c6a7 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2017 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
@@ -44,6 +44,35 @@ isc::data::ConstElementPtr
 configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
                      bool check_only = false);
 
+/// @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 Fetch configuration from CB databases and merge it into the given configuration
+///
+/// It will call @c databaseConfigConnect, passing in the given server configuration. If
+/// that call results in open CB databases, the function will then proceed to fetch
+/// configuration components from said databases and merge them into the given server
+/// configuration.
+///
+/// @param srv_cfg Server configuration into which database configuration should be merged
+/// @param mutable_cfg parsed configuration from the configuration file plus default values (ignored)
+void
+databaseConfigFetch(const SrvConfigPtr& srv_cfg, isc::data::ElementPtr mutable_cfg);
+
 }; // end of isc::dhcp namespace
 }; // end of isc namespace
 
index f2f96d9c4720efc2133241af8474e4d37e2d0314..395f4840713dc05597f8afa65dd54fbda59b3be7 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
@@ -25,6 +25,7 @@
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/subnet_selector.h>
 #include <dhcpsrv/testutils/config_result_check.h>
+#include <dhcpsrv/testutils/test_config_backend_dhcp6.h>
 #include <hooks/hooks_manager.h>
 #include <process/config_ctl_info.h>
 
@@ -6919,6 +6920,19 @@ TEST_F(Dhcp6ParserTest, globalReservations) {
     EXPECT_EQ(11, static_cast<int>(opt_prf->getValue()));
 }
 
+// Rather than disable these tests they are compiled out.  This avoids them
+// reporting as disbabled and thereby drawing attention to them.
+#ifdef CONFIG_BACKEND
+// This test verifies that configuration control with unsupported type fails
+TEST_F(Dhcp6ParserTest, configControlInfoNoFactory) {
+    string config = PARSER_CONFIGS[6];
+    extractConfig(config);
+
+    // Should fail because "type=mysql" has no factories.
+    configure(config, CONTROL_RESULT_ERROR,
+              "The type of the configuration backend: 'mysql' is not supported");
+#endif // CONFIG_BACKEND}
+
 // This test verifies that configuration control info gets populated.
 TEST_F(Dhcp6ParserTest, configControlInfo) {
     string config = PARSER_CONFIGS[8];