]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3542] do not open sockets in test mode
authorRazvan Becheriu <razvan@isc.org>
Mon, 26 Aug 2024 20:19:48 +0000 (23:19 +0300)
committerRazvan Becheriu <razvan@isc.org>
Wed, 11 Sep 2024 11:04:32 +0000 (11:04 +0000)
ChangeLog
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
src/lib/config/cmd_http_listener.cc
src/lib/tcp/mt_tcp_listener_mgr.cc
src/lib/util/multi_threading_mgr.cc
src/lib/util/multi_threading_mgr.h

index 66a423c03f44b96fdd1cafba3f8092c9291dcd78..5e2de2848057c1cb3b247416520c22d43ddc763a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -52,8 +52,8 @@ Kea 2.7.2 (development) released on August 28, 2024
 2273.  [func]*         fdupont
        The RBAC (role-based access control) hook library was
        extended to support the new HTTP/HTTPS control socket
-       of Kea servers. Its name changed to "libdhcp_rbac.so".
-       "libca_rbac.so" is now a symbolic link to it.
+       of Kea servers. Note its name changed too from
+       "libca_rbac.so" to "libdhcp_rbac.so".
        (Gitlab #3483)
 
 2272.  [perf]          fdupont
index 85b6f5c6e338c18d2dcfe699ad8aba343b7edc64..d22f8028cfad6a45ac7a423c8a5fe0f6927069db 100644 (file)
@@ -733,6 +733,10 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
     LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND, DHCP4_CONFIG_START)
         .arg(server.redactConfig(config_set)->str());
 
+    if (check_only) {
+        MultiThreadingMgr::instance().setTestMode(true);
+    }
+
     auto answer = processDhcp4Config(config_set);
 
     int status_code = CONTROL_RESULT_SUCCESS;
index c4c506bc9b2bd603a1c107248b6f087dd2467d90..f5e283a42286f3266b1a1fee72e5a69cb4af5fe6 100644 (file)
@@ -524,6 +524,7 @@ processDhcp6Config(isc::data::ConstElementPtr config_set) {
             ControlSocketsParser parser;
             parser.parse(*srv_config, control_sockets);
         }
+
         ConstElementPtr multi_threading = mutable_cfg->get("multi-threading");
         if (multi_threading) {
             parameter_name = "multi-threading";
@@ -864,6 +865,10 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
     LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_CONFIG_START)
         .arg(server.redactConfig(config_set)->str());
 
+    if (check_only) {
+        MultiThreadingMgr::instance().setTestMode(true);
+    }
+
     auto answer = processDhcp6Config(config_set);
 
     int status_code = CONTROL_RESULT_SUCCESS;
@@ -967,7 +972,7 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
     // configuration. This will add created subnets and option values into
     // the server's configuration.
     // This operation should be exception safe but let's make sure.
-    if (status_code == CONTROL_RESULT_SUCCESS && (!check_only || extra_checks)) {
+    if (status_code == CONTROL_RESULT_SUCCESS && !check_only) {
         try {
 
             // Setup the command channel.
index 9dfea59bdf8cdf61fce44abb373ec3402c36ce36..394806e35c8cc18a048e7f2c31100e4c73f420f8 100644 (file)
@@ -40,6 +40,9 @@ CmdHttpListener::~CmdHttpListener() {
 
 void
 CmdHttpListener::start() {
+    if (MultiThreadingMgr::instance().isTestMode()) {
+        return;
+    }
     // We must be in multi-threading mode.
     if (!MultiThreadingMgr::instance().getMode()) {
         isc_throw(InvalidOperation, "CmdHttpListener cannot be started"
index e880284bde4661f5c00ead4dbf6e1a7c89222546..468071746309c517adc21d1bb70878fd264c09ac 100644 (file)
@@ -40,6 +40,9 @@ MtTcpListenerMgr::~MtTcpListenerMgr() {
 
 void
 MtTcpListenerMgr::start() {
+    if (MultiThreadingMgr::instance().isTestMode()) {
+        return;
+    }
     // We must be in multi-threading mode.
     if (!MultiThreadingMgr::instance().getMode()) {
         isc_throw(InvalidOperation, "MtTcpListenerMgr cannot be started"
index d1526b9b021355538c8b0b63dbafdbd3e05ae392..cab284d481b9fceeab8d998e63a7846a23627c3b 100644 (file)
@@ -14,7 +14,8 @@ namespace isc {
 namespace util {
 
 MultiThreadingMgr::MultiThreadingMgr()
-    : enabled_(false), critical_section_count_(0), thread_pool_size_(0) {
+    : enabled_(false), test_mode_(false), critical_section_count_(0),
+      thread_pool_size_(0) {
 }
 
 MultiThreadingMgr::~MultiThreadingMgr() {
index e86c48827ed0c18311ab7a0a1a34ba479d87179c..f3da67bdde299a69df2df21bf078bddeb6da2887 100644 (file)
@@ -154,6 +154,22 @@ public:
     /// @param enabled The new mode.
     void setMode(bool enabled);
 
+    /// @brief Sets or clears the test mode for @c MultiThreadingMgr.
+    ///
+    /// @param test_mode A flag which indicates that the @c MultiThreadingMgr is
+    /// in the test mode (if true), or not (if false).
+    void setTestMode(const bool test_mode) {
+        test_mode_ = test_mode;
+    }
+
+    /// @brief Checks if the @c MultiThreadingMgr is in the test mode.
+    ///
+    /// @return true if the @c MultiThreadingMgr is in the test mode, false
+    /// otherwise.
+    bool isTestMode() const {
+        return (test_mode_);
+    }
+
     /// @brief Enter critical section.
     ///
     /// When entering @ref MultiThreadingCriticalSection, increment internal
@@ -308,6 +324,9 @@ private:
     /// otherwise.
     bool enabled_;
 
+    /// @brief Indicates if the @c MultiThreadingMgr is in the test mode.
+    bool test_mode_;
+
     /// @brief The critical section count.
     ///
     /// In case the configuration is applied within a