///
/// @param signo Signal number received.
void signalHandler(int signo) {
- // SIGHUP signals a request to reconfigure the server.
- if (signo == SIGHUP) {
- ControlledDhcpv4Srv::processCommand("config-reload",
- ConstElementPtr());
- } else if ((signo == SIGTERM) || (signo == SIGINT)) {
- ControlledDhcpv4Srv::processCommand("shutdown",
- ConstElementPtr());
+ try {
+ // SIGHUP signals a request to reconfigure the server.
+ if (signo == SIGHUP) {
+ CommandMgr::instance().processCommand(createCommand("config-reload"));
+ } else if ((signo == SIGTERM) || (signo == SIGINT)) {
+ CommandMgr::instance().processCommand(createCommand("shutdown"));
+ }
+ } catch (const isc::Exception& ex) {
}
}
isc_throw(isc::BadValue, reason);
}
- // We don't need to call openActiveSockets() or startD2() as these
- // methods are called in processConfig() which is called by
- // processCommand("config-set", ...)
-
// Set signal handlers. When the SIGHUP is received by the process
// the server reconfiguration will be triggered. When SIGTERM or
// SIGINT will be received, the server will start shutting down.
}
// Use parsed JSON structures to configure the server
- result = ControlledDhcpv4Srv::processCommand("config-set", json);
+ try {
+ result = CommandMgr::instance().processCommand(createCommand("config-set", json));
+ } catch (const isc::Exception& ex) {
+ result = isc::config::createAnswer(CONTROL_RESULT_ERROR, string("Error while processing command "
+ "'config-set': ") + ex.what() +
+ ", params: '" + json->str() + "'");
+ }
if (!result) {
// Undetermined status of the configuration. This should never
// happen, but as the configureDhcp4Server returns a pointer, it is
// theoretically possible that it will return NULL.
isc_throw(isc::BadValue, "undefined result of "
- "processCommand(\"config-set\", json)");
+ "process command \"config-set\"");
}
// Now check is the returned result is successful (rcode=0) or not
return (answer);
}
-ConstElementPtr
-ControlledDhcpv4Srv::processCommand(const string& command,
- ConstElementPtr args) {
- string txt = args ? args->str() : "(none)";
-
- LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND, DHCP4_COMMAND_RECEIVED)
- .arg(command).arg(txt);
-
- ControlledDhcpv4Srv* srv = ControlledDhcpv4Srv::getInstance();
-
- if (!srv) {
- ConstElementPtr no_srv = isc::config::createAnswer(CONTROL_RESULT_ERROR,
- "Server object not initialized, so can't process command '" +
- command + "', arguments: '" + txt + "'.");
- return (no_srv);
- }
-
- try {
- if (command == "shutdown") {
- return (srv->commandShutdownHandler(command, args));
-
- } else if (command == "config-reload") {
- return (srv->commandConfigReloadHandler(command, args));
-
- } else if (command == "config-set") {
- return (srv->commandConfigSetHandler(command, args));
-
- }
-
- return (isc::config::createAnswer(CONTROL_RESULT_ERROR, "Unrecognized command:"
- + command));
-
- } catch (const isc::Exception& ex) {
- return (isc::config::createAnswer(CONTROL_RESULT_ERROR, "Error while processing command '"
- + command + "': " + ex.what() +
- ", params: '" + txt + "'"));
- }
-}
-
isc::data::ConstElementPtr
ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
ControlledDhcpv4Srv* srv = ControlledDhcpv4Srv::getInstance();
/// @param exit_value integer value to the process should exit with.
virtual void shutdownServer(int exit_value);
- /// @brief Command processor
- ///
- /// Currently supported commands are:
- /// - shutdown
- /// - config-reload
- /// - config-set
- ///
- /// @note It never throws.
- ///
- /// @param command Text representation of the command (e.g. "shutdown")
- /// @param args Optional parameters
- ///
- /// @return status of the command
- static isc::data::ConstElementPtr
- processCommand(const std::string& command, isc::data::ConstElementPtr args);
-
/// @brief Configuration processor
///
/// This is a method for handling incoming configuration updates.
extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_MALFORMED = "DHCP4_CLIENT_HOSTNAME_MALFORMED";
extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_PROCESS = "DHCP4_CLIENT_HOSTNAME_PROCESS";
extern const isc::log::MessageID DHCP4_CLIENT_NAME_PROC_FAIL = "DHCP4_CLIENT_NAME_PROC_FAIL";
-extern const isc::log::MessageID DHCP4_COMMAND_RECEIVED = "DHCP4_COMMAND_RECEIVED";
extern const isc::log::MessageID DHCP4_CONFIG_COMPLETE = "DHCP4_CONFIG_COMPLETE";
extern const isc::log::MessageID DHCP4_CONFIG_FETCH = "DHCP4_CONFIG_FETCH";
extern const isc::log::MessageID DHCP4_CONFIG_LOAD_FAIL = "DHCP4_CONFIG_LOAD_FAIL";
"DHCP4_CLIENT_HOSTNAME_MALFORMED", "%1: client hostname option malformed: %2",
"DHCP4_CLIENT_HOSTNAME_PROCESS", "%1: processing client's Hostname option",
"DHCP4_CLIENT_NAME_PROC_FAIL", "%1: failed to process the fqdn or hostname sent by a client: %2",
- "DHCP4_COMMAND_RECEIVED", "received command %1, arguments: %2",
"DHCP4_CONFIG_COMPLETE", "DHCPv4 server has completed configuration: %1",
"DHCP4_CONFIG_FETCH", "Fetching configuration data from config backends.",
"DHCP4_CONFIG_LOAD_FAIL", "configuration error using file: %1, reason: %2",
extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_MALFORMED;
extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_PROCESS;
extern const isc::log::MessageID DHCP4_CLIENT_NAME_PROC_FAIL;
-extern const isc::log::MessageID DHCP4_COMMAND_RECEIVED;
extern const isc::log::MessageID DHCP4_CONFIG_COMPLETE;
extern const isc::log::MessageID DHCP4_CONFIG_FETCH;
extern const isc::log::MessageID DHCP4_CONFIG_LOAD_FAIL;
contains the client and transaction identification information. The
second argument holds the detailed description of the error.
-% DHCP4_COMMAND_RECEIVED received command %1, arguments: %2
-A debug message listing the command (and possible arguments) received
-from the Kea control system by the DHCPv4 server.
-
% DHCP4_CONFIG_COMPLETE DHCPv4 server has completed configuration: %1
This is an informational message announcing the successful processing of a
new configuration. It is output during server startup, and when an updated
int rcode = -1;
// Case 1: send bogus command
- ConstElementPtr result = ControlledDhcpv4Srv::processCommand("blah", params);
+ ConstElementPtr result = CommandMgr::instance().processCommand(createCommand("blah", params));
ConstElementPtr comment = parseAnswer(rcode, result);
- EXPECT_EQ(1, rcode); // expect failure (no such command as blah)
+ EXPECT_EQ(2, rcode); // expect failure (no such command as blah)
// Case 2: send shutdown command without any parameters
- result = ControlledDhcpv4Srv::processCommand("shutdown", params);
+ result = CommandMgr::instance().processCommand(createCommand("shutdown", params));
comment = parseAnswer(rcode, result);
EXPECT_EQ(0, rcode); // expect success
// Exit value should default to 0.
ConstElementPtr x(new isc::data::IntElement(77));
params->set("exit-value", x);
- result = ControlledDhcpv4Srv::processCommand("shutdown", params);
+ result = CommandMgr::instance().processCommand(createCommand("shutdown", params));
comment = parseAnswer(rcode, result);
EXPECT_EQ(0, rcode); // expect success
// Configure the server.
ConstElementPtr answer;
- ASSERT_NO_THROW(answer = srv->processCommand("config-set", config));
+ ASSERT_NO_THROW(answer = CommandMgr::instance().processCommand(createCommand("config-set", config)));
// Make sure there was an error with expected message.
int status_code;
///
/// @param signo Signal number received.
void signalHandler(int signo) {
- // SIGHUP signals a request to reconfigure the server.
- if (signo == SIGHUP) {
- ControlledDhcpv6Srv::processCommand("config-reload",
- ConstElementPtr());
- } else if ((signo == SIGTERM) || (signo == SIGINT)) {
- ControlledDhcpv6Srv::processCommand("shutdown",
- ConstElementPtr());
+ try {
+ // SIGHUP signals a request to reconfigure the server.
+ if (signo == SIGHUP) {
+ CommandMgr::instance().processCommand(createCommand("config-reload"));
+ } else if ((signo == SIGTERM) || (signo == SIGINT)) {
+ CommandMgr::instance().processCommand(createCommand("shutdown"));
+ }
+ } catch (const isc::Exception& ex) {
}
}
isc_throw(isc::BadValue, reason);
}
- // We don't need to call openActiveSockets() or startD2() as these
- // methods are called in processConfig() which is called by
- // processCommand("config-set", ...)
-
// Set signal handlers. When the SIGHUP is received by the process
// the server reconfiguration will be triggered. When SIGTERM or
// SIGINT will be received, the server will start shutting down.
}
// Use parsed JSON structures to configure the server
- result = ControlledDhcpv6Srv::processCommand("config-set", json);
+ try {
+ result = CommandMgr::instance().processCommand(createCommand("config-set", json));
+ } catch (const isc::Exception& ex) {
+ result = isc::config::createAnswer(CONTROL_RESULT_ERROR, string("Error while processing command "
+ "'config-set': ") + ex.what() +
+ ", params: '" + json->str() + "'");
+ }
if (!result) {
// Undetermined status of the configuration. This should never
// happen, but as the configureDhcp6Server returns a pointer, it is
// theoretically possible that it will return NULL.
isc_throw(isc::BadValue, "undefined result of "
- "processCommand(\"config-set\", json)");
+ "process command \"config-set\"");
}
// Now check is the returned result is successful (rcode=0) or not
return (answer);
}
-ConstElementPtr
-ControlledDhcpv6Srv::processCommand(const string& command,
- ConstElementPtr args) {
- string txt = args ? args->str() : "(none)";
-
- LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_COMMAND_RECEIVED)
- .arg(command).arg(txt);
-
- ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
-
- if (!srv) {
- ConstElementPtr no_srv = isc::config::createAnswer(CONTROL_RESULT_ERROR,
- "Server object not initialized, so can't process command '" +
- command + "', arguments: '" + txt + "'.");
- return (no_srv);
- }
-
- try {
- if (command == "shutdown") {
- return (srv->commandShutdownHandler(command, args));
-
- } else if (command == "config-reload") {
- return (srv->commandConfigReloadHandler(command, args));
-
- } else if (command == "config-set") {
- return (srv->commandConfigSetHandler(command, args));
-
- }
-
- return (isc::config::createAnswer(CONTROL_RESULT_ERROR, "Unrecognized command:"
- + command));
-
- } catch (const isc::Exception& ex) {
- return (isc::config::createAnswer(CONTROL_RESULT_ERROR, "Error while processing command '"
- + command + "': " + ex.what() +
- ", params: '" + txt + "'"));
- }
-}
-
isc::data::ConstElementPtr
ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
/// @param exit_value integer value to the process should exit with.
virtual void shutdownServer(int exit_value);
- /// @brief Command processor
- ///
- /// Currently supported commands are:
- /// - shutdown
- /// - config-reload
- /// - config-set
- ///
- /// @note It never throws.
- ///
- /// @param command Text representation of the command (e.g. "shutdown")
- /// @param args Optional parameters
- ///
- /// @return status of the command
- static isc::data::ConstElementPtr
- processCommand(const std::string& command, isc::data::ConstElementPtr args);
-
/// @brief Configuration processor
///
/// This is a method for handling incoming configuration updates.
extern const isc::log::MessageID DHCP6_CLASS_UNCONFIGURED = "DHCP6_CLASS_UNCONFIGURED";
extern const isc::log::MessageID DHCP6_CLASS_UNDEFINED = "DHCP6_CLASS_UNDEFINED";
extern const isc::log::MessageID DHCP6_CLASS_UNTESTABLE = "DHCP6_CLASS_UNTESTABLE";
-extern const isc::log::MessageID DHCP6_COMMAND_RECEIVED = "DHCP6_COMMAND_RECEIVED";
extern const isc::log::MessageID DHCP6_CONFIG_COMPLETE = "DHCP6_CONFIG_COMPLETE";
extern const isc::log::MessageID DHCP6_CONFIG_LOAD_FAIL = "DHCP6_CONFIG_LOAD_FAIL";
extern const isc::log::MessageID DHCP6_CONFIG_PACKET_QUEUE = "DHCP6_CONFIG_PACKET_QUEUE";
"DHCP6_CLASS_UNCONFIGURED", "%1: client packet belongs to an unconfigured class: %2",
"DHCP6_CLASS_UNDEFINED", "required class %1 has no definition",
"DHCP6_CLASS_UNTESTABLE", "required class %1 has no test expression",
- "DHCP6_COMMAND_RECEIVED", "received command %1, arguments: %2",
"DHCP6_CONFIG_COMPLETE", "DHCPv6 server has completed configuration: %1",
"DHCP6_CONFIG_LOAD_FAIL", "configuration error using file: %1, reason: %2",
"DHCP6_CONFIG_PACKET_QUEUE", "DHCPv6 packet queue info after configuration: %1",
extern const isc::log::MessageID DHCP6_CLASS_UNCONFIGURED;
extern const isc::log::MessageID DHCP6_CLASS_UNDEFINED;
extern const isc::log::MessageID DHCP6_CLASS_UNTESTABLE;
-extern const isc::log::MessageID DHCP6_COMMAND_RECEIVED;
extern const isc::log::MessageID DHCP6_CONFIG_COMPLETE;
extern const isc::log::MessageID DHCP6_CONFIG_LOAD_FAIL;
extern const isc::log::MessageID DHCP6_CONFIG_PACKET_QUEUE;
This debug message informs that a class was listed for required evaluation but
its definition does not include a test expression to evaluate.
-% DHCP6_COMMAND_RECEIVED received command %1, arguments: %2
-A debug message listing the command (and possible arguments) received
-from the Kea control system by the IPv6 DHCP server.
-
% DHCP6_CONFIG_COMPLETE DHCPv6 server has completed configuration: %1
This is an informational message announcing the successful processing of a
new configuration. it is output during server startup, and when an updated
int rcode = -1;
// Case 1: send bogus command
- ConstElementPtr result = ControlledDhcpv6Srv::processCommand("blah", params);
+ ConstElementPtr result = CommandMgr::instance().processCommand(createCommand("blah", params));
ConstElementPtr comment = parseAnswer(rcode, result);
- EXPECT_EQ(1, rcode); // expect failure (no such command as blah)
+ EXPECT_EQ(2, rcode); // expect failure (no such command as blah)
// Case 2: send shutdown command without any parameters
- result = ControlledDhcpv6Srv::processCommand("shutdown", params);
+ result = CommandMgr::instance().processCommand(createCommand("shutdown", params));
comment = parseAnswer(rcode, result);
EXPECT_EQ(0, rcode); // expect success
ConstElementPtr x(new isc::data::IntElement(77));
params->set("exit-value", x);
- result = ControlledDhcpv6Srv::processCommand("shutdown", params);
+ result = CommandMgr::instance().processCommand(createCommand("shutdown", params));
comment = parseAnswer(rcode, result);
EXPECT_EQ(0, rcode); // expect success
// Configure the server.
ConstElementPtr answer;
- ASSERT_NO_THROW(answer = srv->processCommand("config-set", config));
+ ASSERT_NO_THROW(answer = CommandMgr::instance().processCommand(createCommand("config-set", config)));
// Make sure there was an error with expected message.
int status_code;