Skip to content

Commit 0fbb3ac

Browse files
author
Razvan Becheriu
committed
[#3542] do not open sockets in test mode
1 parent 56a1b39 commit 0fbb3ac

7 files changed

+39
-4
lines changed

ChangeLog

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ Kea 2.7.2 (development) released on August 28, 2024
5252
2273. [func]* fdupont
5353
The RBAC (role-based access control) hook library was
5454
extended to support the new HTTP/HTTPS control socket
55-
of Kea servers. Its name changed to "libdhcp_rbac.so".
56-
"libca_rbac.so" is now a symbolic link to it.
55+
of Kea servers. Note its name changed too from
56+
"libca_rbac.so" to "libdhcp_rbac.so".
5757
(Gitlab #3483)
5858

5959
2272. [perf] fdupont

src/bin/dhcp4/json_config_parser.cc

+4
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
733733
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND, DHCP4_CONFIG_START)
734734
.arg(server.redactConfig(config_set)->str());
735735

736+
if (check_only) {
737+
MultiThreadingMgr::instance().setTestMode(true);
738+
}
739+
736740
auto answer = processDhcp4Config(config_set);
737741

738742
int status_code = CONTROL_RESULT_SUCCESS;

src/bin/dhcp6/json_config_parser.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ processDhcp6Config(isc::data::ConstElementPtr config_set) {
524524
ControlSocketsParser parser;
525525
parser.parse(*srv_config, control_sockets);
526526
}
527+
527528
ConstElementPtr multi_threading = mutable_cfg->get("multi-threading");
528529
if (multi_threading) {
529530
parameter_name = "multi-threading";
@@ -864,6 +865,10 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
864865
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_CONFIG_START)
865866
.arg(server.redactConfig(config_set)->str());
866867

868+
if (check_only) {
869+
MultiThreadingMgr::instance().setTestMode(true);
870+
}
871+
867872
auto answer = processDhcp6Config(config_set);
868873

869874
int status_code = CONTROL_RESULT_SUCCESS;
@@ -967,7 +972,7 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
967972
// configuration. This will add created subnets and option values into
968973
// the server's configuration.
969974
// This operation should be exception safe but let's make sure.
970-
if (status_code == CONTROL_RESULT_SUCCESS && (!check_only || extra_checks)) {
975+
if (status_code == CONTROL_RESULT_SUCCESS && !check_only) {
971976
try {
972977

973978
// Setup the command channel.

src/lib/config/cmd_http_listener.cc

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ CmdHttpListener::~CmdHttpListener() {
4040

4141
void
4242
CmdHttpListener::start() {
43+
if (MultiThreadingMgr::instance().isTestMode()) {
44+
return;
45+
}
4346
// We must be in multi-threading mode.
4447
if (!MultiThreadingMgr::instance().getMode()) {
4548
isc_throw(InvalidOperation, "CmdHttpListener cannot be started"

src/lib/tcp/mt_tcp_listener_mgr.cc

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ MtTcpListenerMgr::~MtTcpListenerMgr() {
4040

4141
void
4242
MtTcpListenerMgr::start() {
43+
if (MultiThreadingMgr::instance().isTestMode()) {
44+
return;
45+
}
4346
// We must be in multi-threading mode.
4447
if (!MultiThreadingMgr::instance().getMode()) {
4548
isc_throw(InvalidOperation, "MtTcpListenerMgr cannot be started"

src/lib/util/multi_threading_mgr.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace isc {
1414
namespace util {
1515

1616
MultiThreadingMgr::MultiThreadingMgr()
17-
: enabled_(false), critical_section_count_(0), thread_pool_size_(0) {
17+
: enabled_(false), test_mode_(false), critical_section_count_(0),
18+
thread_pool_size_(0) {
1819
}
1920

2021
MultiThreadingMgr::~MultiThreadingMgr() {

src/lib/util/multi_threading_mgr.h

+19
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ class MultiThreadingMgr : public boost::noncopyable {
154154
/// @param enabled The new mode.
155155
void setMode(bool enabled);
156156

157+
/// @brief Sets or clears the test mode for @c MultiThreadingMgr.
158+
///
159+
/// @param test_mode A flag which indicates that the @c MultiThreadingMgr is
160+
/// in the test mode (if true), or not (if false).
161+
void setTestMode(const bool test_mode) {
162+
test_mode_ = test_mode;
163+
}
164+
165+
/// @brief Checks if the @c MultiThreadingMgr is in the test mode.
166+
///
167+
/// @return true if the @c MultiThreadingMgr is in the test mode, false
168+
/// otherwise.
169+
bool isTestMode() const {
170+
return (test_mode_);
171+
}
172+
157173
/// @brief Enter critical section.
158174
///
159175
/// When entering @ref MultiThreadingCriticalSection, increment internal
@@ -308,6 +324,9 @@ class MultiThreadingMgr : public boost::noncopyable {
308324
/// otherwise.
309325
bool enabled_;
310326

327+
/// @brief Indicates if the @c MultiThreadingMgr is in the test mode.
328+
bool test_mode_;
329+
311330
/// @brief The critical section count.
312331
///
313332
/// In case the configuration is applied within a

0 commit comments

Comments
 (0)