]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3543] Checkpoint: began code
authorFrancis Dupont <fdupont@isc.org>
Mon, 25 Jun 2018 18:54:18 +0000 (20:54 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 27 Dec 2018 20:00:11 +0000 (21:00 +0100)
src/bin/d2/d2_cfg_mgr.cc
src/bin/d2/d2_cfg_mgr.h
src/bin/d2/d2_config.h
src/bin/d2/d2_controller.cc
src/bin/d2/d2_controller.h
src/bin/d2/d2_process.cc
src/bin/d2/d2_process.h
src/bin/d2/d2_simple_parser.cc

index cb163d1fbc38f556cef19308509613e89767dceb..c8cad8068404f6b58e41abe7b79c2331d7a7547c 100644 (file)
@@ -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<int64_t>(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",
index 83f9d167c8d4351a0f078432a005a018ae6e5f3b..d8b51763d1be0b1b624f9c642cbf106f1656979a 100644 (file)
@@ -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.
index 97d754d04e5e0955633a28d6fa69c73cecac5695..e92bb9b263f6d3cd68892cef7d865fac764350f7 100644 (file)
@@ -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":
 //// [
 ///    {
index d86857db09ec83ed3df41d0d1519e4813a5ff113..947a2baea2f862e944a94e9e7ebe4f96ac68df3c 100644 (file)
@@ -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 <config.h>
 
+#include <config/command_mgr.h>
 #include <d2/d2_controller.h>
 #include <d2/d2_process.h>
 #include <d2/parser_context.h>
@@ -13,6 +14,7 @@
 #include <stdlib.h>
 
 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
index 7911bad525b2e0d793c1ae20df4c4906eede8e6a..e34bfd5d2afc083109685322f10af3a0813f8693 100644 (file)
@@ -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
index 64a23d31521f7efc62fa43e16d57b227571cfd76..215c146ba8a9d0549caec4c1336a33649c5e34f4 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 #include <asiolink/asio_wrapper.h>
 #include <cc/command_interpreter.h>
+#include <config/command_mgr.h>
 #include <d2/d2_log.h>
 #include <d2/d2_cfg_mgr.h>
 #include <d2/d2_process.h>
@@ -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()){
index afeaf52c2f288a7d5f53251dc89c4fe4ae4130ce..83fa834cb162efdb9e50ecbb085ffe6ac3fc91f1 100644 (file)
@@ -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
index 89654d85938356878b0aacbe0c8d2fee529de5b3..ad5c68314e69fa64787cfa25a95c5c0a4b1c5a09 100644 (file)
@@ -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,