From f5cac323c829e9e97a990b9e4f967fb236121781 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Mon, 21 Jan 2019 13:51:48 +0100 Subject: [PATCH] [421-create-config-backend-for-dhcpv6-base] Added DHCPv6 config backend support in src/bin --- src/bin/dhcp6/dhcp6_messages.mes | 7 ++- src/bin/dhcp6/json_config_parser.cc | 56 ++++++++++++++++++- src/bin/dhcp6/json_config_parser.h | 31 +++++++++- src/bin/dhcp6/tests/config_parser_unittest.cc | 16 +++++- 4 files changed, 104 insertions(+), 6 deletions(-) diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index 9079efb09e..8896715477 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -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. diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 26d4831061..2593030a7b 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -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 #include #include +#include #include #include #include @@ -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 diff --git a/src/bin/dhcp6/json_config_parser.h b/src/bin/dhcp6/json_config_parser.h index 3267eac4ba..95a42dc126 100644 --- a/src/bin/dhcp6/json_config_parser.h +++ b/src/bin/dhcp6/json_config_parser.h @@ -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 diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index f2f96d9c47..395f484071 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -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 #include #include +#include #include #include @@ -6919,6 +6920,19 @@ TEST_F(Dhcp6ParserTest, globalReservations) { EXPECT_EQ(11, static_cast(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]; -- 2.47.2