: 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) {
}
keys_ = rhs.keys_;
+
+ control_socket_ = rhs.control_socket_;
}
D2CfgContext::~D2CfgContext() {
// 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",
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
/// @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.
/// "interface" : "eth1" ,
/// "ip-address" : "192.168.1.33" ,
/// "port" : 88 ,
+/// "control-socket":
+/// {
+/// "socket-type": "unix" ,
+/// "socket-name": "/tmp/d2-ctrl-socket"
+//// },
/// "tsig-keys":
//// [
/// {
-// 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
#include <config.h>
+#include <config/command_mgr.h>
#include <d2/d2_controller.h>
#include <d2/d2_process.h>
#include <d2/parser_context.h>
#include <stdlib.h>
using namespace isc::process;
+using namespace isc::config;
namespace isc {
namespace d2 {
}
D2Controller::D2Controller()
- : DControllerBase(d2_app_name_, d2_bin_name_) {
+ : DControllerBase(d2_app_name_, d2_bin_name_),
+ has_command_channel_(false) {
}
isc::data::ConstElementPtr
}
D2Controller::~D2Controller() {
+ if (has_command_channel_) {
+ has_command_channel_ = false;
+ deregisterCommands();
+ }
}
std::string
}
+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
/// 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();
/// @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
#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>
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
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()){
-// 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
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
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,