Skip to content

Commit f08c5d6

Browse files
author
Razvan Becheriu
committed
[#3619] destroy maangers before hook unload
1 parent 0f298df commit f08c5d6

6 files changed

+85
-61
lines changed

src/bin/dhcp4/ctrl_dhcp4_srv.cc

+6
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,12 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
850850
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND, DHCP4_CONFIG_RECEIVED)
851851
.arg(srv->redactConfig(config)->str());
852852

853+
// Destroy lease manager before hooks unload.
854+
LeaseMgrFactory::destroy();
855+
856+
// Destroy host manager before hooks unload.
857+
HostMgr::create();
858+
853859
ConstElementPtr answer = configureDhcp4Server(*srv, config);
854860

855861
// Check that configuration was successful. If not, do not reopen sockets

src/bin/dhcp4/dhcp4_srv.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <dhcpsrv/dhcpsrv_exceptions.h>
3939
#include <dhcpsrv/fuzz.h>
4040
#include <dhcpsrv/host_data_source_factory.h>
41+
#include <dhcpsrv/host_mgr.h>
4142
#include <dhcpsrv/lease_mgr.h>
4243
#include <dhcpsrv/lease_mgr_factory.h>
4344
#include <dhcpsrv/ncr_generator.h>
@@ -654,12 +655,13 @@ Dhcpv4Srv::Dhcpv4Srv(uint16_t server_port, uint16_t client_port,
654655

655656
} catch (const std::exception &e) {
656657
LOG_ERROR(dhcp4_logger, DHCP4_SRV_CONSTRUCT_ERROR).arg(e.what());
657-
shutdown_ = true;
658658
return;
659659
}
660660

661661
// Initializing all observations with default value
662662
setPacketStatisticsDefaults();
663+
664+
// All done, so can proceed
663665
shutdown_ = false;
664666
}
665667

@@ -697,6 +699,9 @@ Dhcpv4Srv::~Dhcpv4Srv() {
697699
// so we should clean up after ourselves.
698700
LeaseMgrFactory::destroy();
699701

702+
// Destroy the host manager before hooks unload.
703+
HostMgr::create();
704+
700705
// Explicitly unload hooks
701706
HooksManager::prepareUnloadLibraries();
702707
if (!HooksManager::unloadLibraries()) {

src/bin/dhcp4/json_config_parser.cc

+28-27
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
4242
#include <dhcpsrv/parsers/sanity_checks_parser.h>
4343
#include <dhcpsrv/host_data_source_factory.h>
44+
#include <dhcpsrv/host_mgr.h>
4445
#include <dhcpsrv/timer_mgr.h>
4546
#include <hooks/hooks_manager.h>
4647
#include <hooks/hooks_parser.h>
@@ -752,38 +753,22 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
752753
if (status_code == CONTROL_RESULT_SUCCESS) {
753754
if (check_only) {
754755
if (extra_checks) {
755-
// Re-open lease and host database with new parameters.
756+
std::ostringstream err;
757+
// Configure DHCP packet queueing
756758
try {
757-
// Get the staging configuration.
758-
srv_config = CfgMgr::instance().getStagingCfg();
759+
data::ConstElementPtr qc;
760+
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
761+
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET, qc)) {
762+
LOG_INFO(dhcp4_logger, DHCP4_CONFIG_PACKET_QUEUE)
763+
.arg(IfaceMgr::instance().getPacketQueue4()->getInfoStr());
764+
}
759765

760-
CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
761-
string params = "universe=4 persist=false";
762-
cfg_db->setAppendedParameters(params);
763-
cfg_db->createManagers();
764766
} catch (const std::exception& ex) {
765-
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
767+
err << "Error setting packet queue controls after server reconfiguration: "
768+
<< ex.what();
769+
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str());
766770
status_code = CONTROL_RESULT_ERROR;
767771
}
768-
769-
if (status_code == CONTROL_RESULT_SUCCESS) {
770-
std::ostringstream err;
771-
// Configure DHCP packet queueing
772-
try {
773-
data::ConstElementPtr qc;
774-
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
775-
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET, qc)) {
776-
LOG_INFO(dhcp4_logger, DHCP4_CONFIG_PACKET_QUEUE)
777-
.arg(IfaceMgr::instance().getPacketQueue4()->getInfoStr());
778-
}
779-
780-
} catch (const std::exception& ex) {
781-
err << "Error setting packet queue controls after server reconfiguration: "
782-
<< ex.what();
783-
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str());
784-
status_code = CONTROL_RESULT_ERROR;
785-
}
786-
}
787772
}
788773
} else {
789774
// disable multi-threading (it will be applied by new configuration)
@@ -907,6 +892,22 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
907892
" parsing error");
908893
status_code = CONTROL_RESULT_ERROR;
909894
}
895+
896+
if (extra_checks && status_code == CONTROL_RESULT_SUCCESS) {
897+
// Re-open lease and host database with new parameters.
898+
try {
899+
// Get the staging configuration.
900+
srv_config = CfgMgr::instance().getStagingCfg();
901+
902+
CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
903+
string params = "universe=4 persist=false";
904+
cfg_db->setAppendedParameters(params);
905+
cfg_db->createManagers();
906+
} catch (const std::exception& ex) {
907+
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
908+
status_code = CONTROL_RESULT_ERROR;
909+
}
910+
}
910911
}
911912

912913
// Log the list of known backends.

src/bin/dhcp6/ctrl_dhcp6_srv.cc

+6
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,12 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
855855
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_CONFIG_RECEIVED)
856856
.arg(srv->redactConfig(config)->str());
857857

858+
// Destroy lease manager before hooks unload.
859+
LeaseMgrFactory::destroy();
860+
861+
// Destroy host manager before hooks unload.
862+
HostMgr::create();
863+
858864
ConstElementPtr answer = configureDhcp6Server(*srv, config);
859865

860866
// Check that configuration was successful. If not, do not reopen sockets

src/bin/dhcp6/dhcp6_srv.cc

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <dhcpsrv/cfg_host_operations.h>
3838
#include <dhcpsrv/cfgmgr.h>
3939
#include <dhcpsrv/host_data_source_factory.h>
40+
#include <dhcpsrv/host_mgr.h>
4041
#include <dhcpsrv/lease_mgr.h>
4142
#include <dhcpsrv/lease_mgr_factory.h>
4243
#include <dhcpsrv/ncr_generator.h>
@@ -245,6 +246,7 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t server_port, uint16_t client_port)
245246
LOG_ERROR(dhcp6_logger, DHCP6_SRV_CONSTRUCT_ERROR).arg(e.what());
246247
return;
247248
}
249+
248250
// Initializing all observations with default value
249251
setPacketStatisticsDefaults();
250252

@@ -282,8 +284,13 @@ Dhcpv6Srv::~Dhcpv6Srv() {
282284

283285
IfaceMgr::instance().closeSockets();
284286

287+
// The lease manager was instantiated during DHCPv6Srv configuration,
288+
// so we should clean up after ourselves.
285289
LeaseMgrFactory::destroy();
286290

291+
// Destroy the host manager before hooks unload.
292+
HostMgr::create();
293+
287294
// Explicitly unload hooks
288295
HooksManager::prepareUnloadLibraries();
289296
if (!HooksManager::unloadLibraries()) {

src/bin/dhcp6/json_config_parser.cc

+32-33
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
4242
#include <dhcpsrv/parsers/sanity_checks_parser.h>
4343
#include <dhcpsrv/host_data_source_factory.h>
44+
#include <dhcpsrv/host_mgr.h>
4445
#include <dhcpsrv/pool.h>
4546
#include <dhcpsrv/subnet.h>
4647
#include <dhcpsrv/timer_mgr.h>
@@ -884,43 +885,22 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
884885
if (status_code == CONTROL_RESULT_SUCCESS) {
885886
if (check_only) {
886887
if (extra_checks) {
887-
// Re-open lease and host database with new parameters.
888+
std::ostringstream err;
889+
// Configure DHCP packet queueing
888890
try {
889-
// Get the staging configuration.
890-
srv_config = CfgMgr::instance().getStagingCfg();
891-
892-
CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
893-
string params = "universe=6 persist=false";
894-
// The "extended-info-tables" has no effect on -T command
895-
// line parameter so it is omitted on purpose.
896-
// Note that in this case, the current code creates managers
897-
// before hooks are loaded, so it can not be activated by
898-
// the BLQ hook.
899-
cfg_db->setAppendedParameters(params);
900-
cfg_db->createManagers();
891+
data::ConstElementPtr qc;
892+
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
893+
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET6, qc)) {
894+
LOG_INFO(dhcp6_logger, DHCP6_CONFIG_PACKET_QUEUE)
895+
.arg(IfaceMgr::instance().getPacketQueue6()->getInfoStr());
896+
}
897+
901898
} catch (const std::exception& ex) {
902-
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
899+
err << "Error setting packet queue controls after server reconfiguration: "
900+
<< ex.what();
901+
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str());
903902
status_code = CONTROL_RESULT_ERROR;
904903
}
905-
906-
if (status_code == CONTROL_RESULT_SUCCESS) {
907-
std::ostringstream err;
908-
// Configure DHCP packet queueing
909-
try {
910-
data::ConstElementPtr qc;
911-
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
912-
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET6, qc)) {
913-
LOG_INFO(dhcp6_logger, DHCP6_CONFIG_PACKET_QUEUE)
914-
.arg(IfaceMgr::instance().getPacketQueue6()->getInfoStr());
915-
}
916-
917-
} catch (const std::exception& ex) {
918-
err << "Error setting packet queue controls after server reconfiguration: "
919-
<< ex.what();
920-
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str());
921-
status_code = CONTROL_RESULT_ERROR;
922-
}
923-
}
924904
}
925905
} else {
926906
// disable multi-threading (it will be applied by new configuration)
@@ -1044,6 +1024,25 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
10441024
" parsing error");
10451025
status_code = CONTROL_RESULT_ERROR;
10461026
}
1027+
1028+
if (extra_checks && status_code == CONTROL_RESULT_SUCCESS) {
1029+
// Re-open lease and host database with new parameters.
1030+
try {
1031+
// Get the staging configuration.
1032+
srv_config = CfgMgr::instance().getStagingCfg();
1033+
1034+
CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
1035+
string params = "universe=6 persist=false";
1036+
if (cfg_db->getExtendedInfoTablesEnabled()) {
1037+
params += " extended-info-tables=true";
1038+
}
1039+
cfg_db->setAppendedParameters(params);
1040+
cfg_db->createManagers();
1041+
} catch (const std::exception& ex) {
1042+
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
1043+
status_code = CONTROL_RESULT_ERROR;
1044+
}
1045+
}
10471046
}
10481047

10491048
// Log the list of known backends.

0 commit comments

Comments
 (0)