From: Francis Dupont Date: Mon, 25 Jun 2018 18:54:18 +0000 (+0200) Subject: [3543] Checkpoint: began code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=528f83cce32820ed248698a6f428fdc8f4003346;p=thirdparty%2Fkea.git [3543] Checkpoint: began code --- diff --git a/src/bin/d2/d2_cfg_mgr.cc b/src/bin/d2/d2_cfg_mgr.cc index cb163d1fbc..c8cad80684 100644 --- a/src/bin/d2/d2_cfg_mgr.cc +++ b/src/bin/d2/d2_cfg_mgr.cc @@ -34,7 +34,8 @@ D2CfgContext::D2CfgContext() : d2_params_(new D2Params()), forward_mgr_(new DdnsDomainListMgr("forward-ddns")), reverse_mgr_(new DdnsDomainListMgr("reverse-ddns")), - keys_(new TSIGKeyInfoMap()) { + keys_(new TSIGKeyInfoMap()), + control_socket_(ConstElementPtr()) { } D2CfgContext::D2CfgContext(const D2CfgContext& rhs) : ConfigBase(rhs) { @@ -50,6 +51,8 @@ D2CfgContext::D2CfgContext(const D2CfgContext& rhs) : ConfigBase(rhs) { } keys_ = rhs.keys_; + + control_socket_ = rhs.control_socket_; } D2CfgContext::~D2CfgContext() { @@ -66,6 +69,10 @@ D2CfgContext::toElement() const { // Set port size_t port = d2_params_->getPort(); d2->set("port", Element::create(static_cast(port))); + // Set control-socket (skip if null as empty is not legal) + if (!isNull(control_socket_)) { + d2->set("control-socket", UserContext::toElement(control_socket_)); + } // Set dns-server-timeout size_t dns_server_timeout = d2_params_->getDnsServerTimeout(); d2->set("dns-server-timeout", diff --git a/src/bin/d2/d2_cfg_mgr.h b/src/bin/d2/d2_cfg_mgr.h index 83f9d167c8..d8b51763d1 100644 --- a/src/bin/d2/d2_cfg_mgr.h +++ b/src/bin/d2/d2_cfg_mgr.h @@ -90,6 +90,18 @@ public: keys_ = keys; } + /// @brief Returns information about control socket + /// @return pointer to the Element that holds control-socket map + const isc::data::ConstElementPtr getControlSocketInfo() const { + return (control_socket_); + } + + /// @brief Sets information about the control socket + /// @param control_socket Element that holds control-socket map + void setControlSocketInfo(const isc::data::ConstElementPtr& control_socket) { + control_socket_ = control_socket; + } + /// @brief Unparse a configuration object /// /// @return a pointer to a configuration @@ -114,6 +126,9 @@ private: /// @brief Storage for the map of TSIGKeyInfos TSIGKeyInfoMapPtr keys_; + + /// @brief Pointer to the control-socket information + isc::data::ConstElementPtr control_socket_; }; /// @brief Defines a pointer for DdnsDomain instances. diff --git a/src/bin/d2/d2_config.h b/src/bin/d2/d2_config.h index 97d754d04e..e92bb9b263 100644 --- a/src/bin/d2/d2_config.h +++ b/src/bin/d2/d2_config.h @@ -77,6 +77,11 @@ namespace d2 { /// "interface" : "eth1" , /// "ip-address" : "192.168.1.33" , /// "port" : 88 , +/// "control-socket": +/// { +/// "socket-type": "unix" , +/// "socket-name": "/tmp/d2-ctrl-socket" +//// }, /// "tsig-keys": //// [ /// { diff --git a/src/bin/d2/d2_controller.cc b/src/bin/d2/d2_controller.cc index d86857db09..947a2baea2 100644 --- a/src/bin/d2/d2_controller.cc +++ b/src/bin/d2/d2_controller.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2018 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 @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -13,6 +14,7 @@ #include using namespace isc::process; +using namespace isc::config; namespace isc { namespace d2 { @@ -43,7 +45,8 @@ DProcessBase* D2Controller::createProcess() { } D2Controller::D2Controller() - : DControllerBase(d2_app_name_, d2_bin_name_) { + : DControllerBase(d2_app_name_, d2_bin_name_), + has_command_channel_(false) { } isc::data::ConstElementPtr @@ -61,6 +64,10 @@ D2Controller::parseFile(const std::string& file_name) { } D2Controller::~D2Controller() { + if (has_command_channel_) { + has_command_channel_ = false; + deregisterCommands(); + } } std::string @@ -72,5 +79,47 @@ D2Controller::getVersionAddendum() { } +void +D2Controller::registerCommands() { + has_command_channel_ = true; + + // CommandMgr uses IO service to run asynchronous socket operations. + CommandMgr::instance().setIOService(getIOService()); + + // These are the commands always supported by the D2 server. + // Please keep the list in alphabetic order. + CommandMgr::instance().registerCommand("build-report", + boost::bind(&D2Controller::buildReportHandler, this, _1, _2)); + + CommandMgr::instance().registerCommand("config-get", + boost::bind(&D2Controller::configGetHandler, this, _1, _2)); + + CommandMgr::instance().registerCommand("config-test", + boost::bind(&D2Controller::configTestHandler, this, _1, _2)); + + CommandMgr::instance().registerCommand("config-write", + boost::bind(&D2Controller::configWriteHandler, this, _1, _2)); + + CommandMgr::instance().registerCommand("shutdown", + boost::bind(&D2Controller::shutdownHandler, this, _1, _2)); + + CommandMgr::instance().registerCommand("version-get", + boost::bind(&D2Controller::versionGetHandler, this, _1, _2)); +} + +void +D2Controller::deregisterCommands() { + // Close the command socket (if it exists). + CommandMgr::instance().closeCommandSocket(); + + // Deregister any registered commands (please keep in alphabetic order) + CommandMgr::instance().deregisterCommand("build-report"); + CommandMgr::instance().deregisterCommand("config-get"); + CommandMgr::instance().deregisterCommand("config-test"); + CommandMgr::instance().deregisterCommand("config-write"); + CommandMgr::instance().deregisterCommand("shutdown"); + CommandMgr::instance().deregisterCommand("version-get"); +} + }; // end namespace isc::d2 }; // end namespace isc diff --git a/src/bin/d2/d2_controller.h b/src/bin/d2/d2_controller.h index 7911bad525..e34bfd5d2a 100644 --- a/src/bin/d2/d2_controller.h +++ b/src/bin/d2/d2_controller.h @@ -42,6 +42,12 @@ public: /// by convention this should match the executable name. static const char* d2_bin_name_; + /// @brief Register commands. + void registerCommands(); + + /// @brief Deregister commands. + void deregisterCommands(); + protected: /// @brief Returns version info specific to D2 virtual std::string getVersionAddendum(); @@ -68,15 +74,12 @@ private: /// @throw BadValue if the file is empty virtual isc::data::ConstElementPtr parseFile(const std::string& file_name); - /// @brief Register commands. - void registerCommands(); - - /// @brief Deregister commands. - void deregisterCommands(); - /// @brief Constructor is declared private to maintain the integrity of /// the singleton instance. D2Controller(); + + /// @brief Flag set to true when command channel is enabled. + bool has_command_channel_; }; }; // namespace isc::d2 diff --git a/src/bin/d2/d2_process.cc b/src/bin/d2/d2_process.cc index 64a23d3152..215c146ba8 100644 --- a/src/bin/d2/d2_process.cc +++ b/src/bin/d2/d2_process.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -215,6 +216,9 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) { return (answer); } + // Set the command channel. + configureCommandChannel(); + // Set the reconf_queue_flag to indicate that we need to reconfigure // the queue manager. Reconfiguring the queue manager may be asynchronous // and require one or more events to occur, therefore we set a flag @@ -234,6 +238,23 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) { return (answer); } +void +D2Process::configureCommandChannel() { + D2CfgMgrPtr mgr = getD2CfgMgr(); + if (!mgr) { + return; + } + D2CfgContextPtr ctx = mgr->getD2CfgContext(); + if (!ctx) { + return; + } + isc::data::ConstElementPtr sock_cfg = ctx->getControlSocketInfo(); + if (sock_cfg) { + // Assume that CommandMgr works with D2 I/O. + isc::config::CommandMgr::instance().openCommandSocket(sock_cfg); + } +} + void D2Process::checkQueueStatus() { switch (queue_mgr_->getMgrState()){ diff --git a/src/bin/d2/d2_process.h b/src/bin/d2/d2_process.h index afeaf52c2f..83fa834cb1 100644 --- a/src/bin/d2/d2_process.h +++ b/src/bin/d2/d2_process.h @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2018 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 @@ -254,6 +254,11 @@ protected: shutdown_type_ = value; } + /// @brief Configure the command channel. + /// + /// Strip down code used in DHCPv4 / DHCPv6 servers. + void configureCommandChannel(); + public: /// @brief Returns a pointer to the configuration manager. /// Note, this method cannot return a reference as it uses dynamic diff --git a/src/bin/d2/d2_simple_parser.cc b/src/bin/d2/d2_simple_parser.cc index 89654d8593..ad5c68314e 100644 --- a/src/bin/d2/d2_simple_parser.cc +++ b/src/bin/d2/d2_simple_parser.cc @@ -265,6 +265,11 @@ void D2SimpleParser::parse(const D2CfgContextPtr& ctx, ctx->setContext(user); } + ConstElementPtr socket = config->get("control-socket"); + if (socket) { + ctx->setControlSocketInfo(socket); + } + // Attempt to create the new client config. This ought to fly as // we already validated everything. D2ParamsPtr params(new D2Params(ip_address, port, dns_server_timeout,