]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2960] removed more code
authorRazvan Becheriu <razvan@isc.org>
Wed, 22 May 2024 21:52:10 +0000 (00:52 +0300)
committerRazvan Becheriu <razvan@isc.org>
Thu, 23 May 2024 14:08:44 +0000 (17:08 +0300)
14 files changed:
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/ctrl_dhcp4_srv.h
src/bin/dhcp4/dhcp4_messages.cc
src/bin/dhcp4/dhcp4_messages.h
src/bin/dhcp4/dhcp4_messages.mes
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/hooks_unittest.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.h
src/bin/dhcp6/dhcp6_messages.cc
src/bin/dhcp6/dhcp6_messages.h
src/bin/dhcp6/dhcp6_messages.mes
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/hooks_unittest.cc

index deda6c1c064b4bbb99dfd2b059a94ebe0ea322a0..fb3565efa29226fb35b879f0be8b3e902be63cc5 100644 (file)
@@ -75,13 +75,14 @@ CtrlDhcp4Hooks Hooks;
 ///
 /// @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) {
     }
 }
 
@@ -108,10 +109,6 @@ ControlledDhcpv4Srv::init(const std::string& file_name) {
         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.
@@ -162,13 +159,19 @@ ControlledDhcpv4Srv::loadConfigFile(const std::string& file_name) {
         }
 
         // 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
@@ -833,45 +836,6 @@ ControlledDhcpv4Srv::commandStatisticSetMaxSampleAgeAllHandler(const string&,
     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();
index ab4fe16841f32265ce91b296b6cb4424e19c54cd..cf430ddf724e8e4495502d69ba7ea36cad2dd9c2 100644 (file)
@@ -72,22 +72,6 @@ public:
     /// @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.
index 8354fb97b448c071088a4c51f82edc22b8648d18..9ed0059925376976098d7657f50b721b6e6ada6e 100644 (file)
@@ -29,7 +29,6 @@ extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_DATA = "DHCP4_CLIENT_HOST
 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";
@@ -216,7 +215,6 @@ const char* values[] = {
     "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",
index af512461bd59952e198b7516b8913189ab1e5e9a..37cde40ed71abf4ac757d980dafe4f4021f3dab4 100644 (file)
@@ -30,7 +30,6 @@ extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_DATA;
 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;
index 074d5a9303b2e5866d971b75f9bbfaa4fff8ce27..4101afbd48e19500359cec073087b3f16253eae6 100644 (file)
@@ -149,10 +149,6 @@ name was malformed or due to internal server error. The first argument
 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
index 8ca7f74ba41c31655b344026985462a9492cd58b..64769cc0542608c0fc278f28c31fd1d66a086a19 100644 (file)
@@ -425,12 +425,12 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commands) {
     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.
@@ -440,7 +440,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commands) {
     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
 
index 04851b14352a469e29702ec3b3440e20da8b2f5a..d0f7a4a6160b36a1ed7b355eaee53a36039f2bb2 100644 (file)
@@ -4128,7 +4128,7 @@ TEST_F(LoadUnloadDhcpv4SrvTest, startServiceFail) {
 
     // 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;
index d5b8fb6e63059fb61b07a3384cbab90bd63dc717..6f7ef120564a4482804768472aebbac9d9a3f41f 100644 (file)
@@ -78,13 +78,14 @@ static const char* SERVER_DUID_FILE = "kea-dhcp6-serverid";
 ///
 /// @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) {
     }
 }
 
@@ -111,10 +112,6 @@ ControlledDhcpv6Srv::init(const std::string& file_name) {
         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.
@@ -165,13 +162,19 @@ ControlledDhcpv6Srv::loadConfigFile(const std::string& file_name) {
         }
 
         // 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
@@ -838,45 +841,6 @@ ControlledDhcpv6Srv::commandStatisticSetMaxSampleAgeAllHandler(const string&,
     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();
index ba6822d03ac94b0930f26106fd6f7e1f35a6f4c6..16db9320382ec01cda031c2a4f83fe9affb0ca22 100644 (file)
@@ -72,22 +72,6 @@ public:
     /// @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.
index 64460658038a9afb04fdf8844a94323e61d0d8da..7a449c6b2e58f3d331010278ec0421997ccfe737 100644 (file)
@@ -24,7 +24,6 @@ extern const isc::log::MessageID DHCP6_CLASS_ASSIGNED = "DHCP6_CLASS_ASSIGNED";
 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";
@@ -200,7 +199,6 @@ const char* values[] = {
     "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",
index 7e4f7b0b2fc80ef3d81ce786534197bb74b62a14..6203303c5c8e2fb1b23bcdda292ef11c745e95c7 100644 (file)
@@ -25,7 +25,6 @@ extern const isc::log::MessageID DHCP6_CLASS_ASSIGNED;
 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;
index bc055a6dfef4b666c46330592a63c78512500c3c..a20f16a3599d2ec9b160366736ddefaaf5db4205 100644 (file)
@@ -115,10 +115,6 @@ has no definition.
 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
index 85f86e9006d88e18451da2edbdadcfee05be50b4..7d28a6e9a15e188d10424558fea845e0b0158459 100644 (file)
@@ -451,12 +451,12 @@ TEST_F(CtrlDhcpv6SrvTest, commands) {
     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
 
@@ -464,7 +464,7 @@ TEST_F(CtrlDhcpv6SrvTest, commands) {
     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
 
index 214d3fc326284e7162aa3c71f212c39ab3781af7..6b6170a555f09f2763f1647734d3000649044cb4 100644 (file)
@@ -5922,7 +5922,7 @@ TEST_F(LoadUnloadDhcpv6SrvTest, startServiceFail) {
 
     // 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;