Skip to content

Commit

Permalink
[#3619] destroy maangers before hook unload
Browse files Browse the repository at this point in the history
  • Loading branch information
Razvan Becheriu committed Oct 22, 2024
1 parent 0f298df commit f08c5d6
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 61 deletions.
6 changes: 6 additions & 0 deletions src/bin/dhcp4/ctrl_dhcp4_srv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,12 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND, DHCP4_CONFIG_RECEIVED)
.arg(srv->redactConfig(config)->str());

// Destroy lease manager before hooks unload.
LeaseMgrFactory::destroy();

// Destroy host manager before hooks unload.
HostMgr::create();

ConstElementPtr answer = configureDhcp4Server(*srv, config);

// Check that configuration was successful. If not, do not reopen sockets
Expand Down
7 changes: 6 additions & 1 deletion src/bin/dhcp4/dhcp4_srv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <dhcpsrv/dhcpsrv_exceptions.h>
#include <dhcpsrv/fuzz.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/ncr_generator.h>
Expand Down Expand Up @@ -654,12 +655,13 @@ Dhcpv4Srv::Dhcpv4Srv(uint16_t server_port, uint16_t client_port,

} catch (const std::exception &e) {
LOG_ERROR(dhcp4_logger, DHCP4_SRV_CONSTRUCT_ERROR).arg(e.what());
shutdown_ = true;
return;
}

// Initializing all observations with default value
setPacketStatisticsDefaults();

// All done, so can proceed
shutdown_ = false;
}

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

// Destroy the host manager before hooks unload.
HostMgr::create();

// Explicitly unload hooks
HooksManager::prepareUnloadLibraries();
if (!HooksManager::unloadLibraries()) {
Expand Down
55 changes: 28 additions & 27 deletions src/bin/dhcp4/json_config_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
#include <dhcpsrv/parsers/sanity_checks_parser.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/timer_mgr.h>
#include <hooks/hooks_manager.h>
#include <hooks/hooks_parser.h>
Expand Down Expand Up @@ -752,38 +753,22 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
if (status_code == CONTROL_RESULT_SUCCESS) {
if (check_only) {
if (extra_checks) {
// Re-open lease and host database with new parameters.
std::ostringstream err;
// Configure DHCP packet queueing
try {
// Get the staging configuration.
srv_config = CfgMgr::instance().getStagingCfg();
data::ConstElementPtr qc;
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET, qc)) {
LOG_INFO(dhcp4_logger, DHCP4_CONFIG_PACKET_QUEUE)
.arg(IfaceMgr::instance().getPacketQueue4()->getInfoStr());
}

CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
string params = "universe=4 persist=false";
cfg_db->setAppendedParameters(params);
cfg_db->createManagers();
} catch (const std::exception& ex) {
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
err << "Error setting packet queue controls after server reconfiguration: "
<< ex.what();
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str());
status_code = CONTROL_RESULT_ERROR;
}

if (status_code == CONTROL_RESULT_SUCCESS) {
std::ostringstream err;
// Configure DHCP packet queueing
try {
data::ConstElementPtr qc;
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET, qc)) {
LOG_INFO(dhcp4_logger, DHCP4_CONFIG_PACKET_QUEUE)
.arg(IfaceMgr::instance().getPacketQueue4()->getInfoStr());
}

} catch (const std::exception& ex) {
err << "Error setting packet queue controls after server reconfiguration: "
<< ex.what();
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str());
status_code = CONTROL_RESULT_ERROR;
}
}
}
} else {
// disable multi-threading (it will be applied by new configuration)
Expand Down Expand Up @@ -907,6 +892,22 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
" parsing error");
status_code = CONTROL_RESULT_ERROR;
}

if (extra_checks && status_code == CONTROL_RESULT_SUCCESS) {
// Re-open lease and host database with new parameters.
try {
// Get the staging configuration.
srv_config = CfgMgr::instance().getStagingCfg();

CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
string params = "universe=4 persist=false";
cfg_db->setAppendedParameters(params);
cfg_db->createManagers();
} catch (const std::exception& ex) {
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
status_code = CONTROL_RESULT_ERROR;
}
}
}

// Log the list of known backends.
Expand Down
6 changes: 6 additions & 0 deletions src/bin/dhcp6/ctrl_dhcp6_srv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,12 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_CONFIG_RECEIVED)
.arg(srv->redactConfig(config)->str());

// Destroy lease manager before hooks unload.
LeaseMgrFactory::destroy();

// Destroy host manager before hooks unload.
HostMgr::create();

ConstElementPtr answer = configureDhcp6Server(*srv, config);

// Check that configuration was successful. If not, do not reopen sockets
Expand Down
7 changes: 7 additions & 0 deletions src/bin/dhcp6/dhcp6_srv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <dhcpsrv/cfg_host_operations.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/ncr_generator.h>
Expand Down Expand Up @@ -245,6 +246,7 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t server_port, uint16_t client_port)
LOG_ERROR(dhcp6_logger, DHCP6_SRV_CONSTRUCT_ERROR).arg(e.what());
return;
}

// Initializing all observations with default value
setPacketStatisticsDefaults();

Expand Down Expand Up @@ -282,8 +284,13 @@ Dhcpv6Srv::~Dhcpv6Srv() {

IfaceMgr::instance().closeSockets();

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

// Destroy the host manager before hooks unload.
HostMgr::create();

// Explicitly unload hooks
HooksManager::prepareUnloadLibraries();
if (!HooksManager::unloadLibraries()) {
Expand Down
65 changes: 32 additions & 33 deletions src/bin/dhcp6/json_config_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
#include <dhcpsrv/parsers/sanity_checks_parser.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/pool.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/timer_mgr.h>
Expand Down Expand Up @@ -884,43 +885,22 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
if (status_code == CONTROL_RESULT_SUCCESS) {
if (check_only) {
if (extra_checks) {
// Re-open lease and host database with new parameters.
std::ostringstream err;
// Configure DHCP packet queueing
try {
// Get the staging configuration.
srv_config = CfgMgr::instance().getStagingCfg();

CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
string params = "universe=6 persist=false";
// The "extended-info-tables" has no effect on -T command
// line parameter so it is omitted on purpose.
// Note that in this case, the current code creates managers
// before hooks are loaded, so it can not be activated by
// the BLQ hook.
cfg_db->setAppendedParameters(params);
cfg_db->createManagers();
data::ConstElementPtr qc;
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET6, qc)) {
LOG_INFO(dhcp6_logger, DHCP6_CONFIG_PACKET_QUEUE)
.arg(IfaceMgr::instance().getPacketQueue6()->getInfoStr());
}

} catch (const std::exception& ex) {
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
err << "Error setting packet queue controls after server reconfiguration: "
<< ex.what();
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str());
status_code = CONTROL_RESULT_ERROR;
}

if (status_code == CONTROL_RESULT_SUCCESS) {
std::ostringstream err;
// Configure DHCP packet queueing
try {
data::ConstElementPtr qc;
qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
if (IfaceMgr::instance().configureDHCPPacketQueue(AF_INET6, qc)) {
LOG_INFO(dhcp6_logger, DHCP6_CONFIG_PACKET_QUEUE)
.arg(IfaceMgr::instance().getPacketQueue6()->getInfoStr());
}

} catch (const std::exception& ex) {
err << "Error setting packet queue controls after server reconfiguration: "
<< ex.what();
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str());
status_code = CONTROL_RESULT_ERROR;
}
}
}
} else {
// disable multi-threading (it will be applied by new configuration)
Expand Down Expand Up @@ -1044,6 +1024,25 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
" parsing error");
status_code = CONTROL_RESULT_ERROR;
}

if (extra_checks && status_code == CONTROL_RESULT_SUCCESS) {
// Re-open lease and host database with new parameters.
try {
// Get the staging configuration.
srv_config = CfgMgr::instance().getStagingCfg();

CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
string params = "universe=6 persist=false";
if (cfg_db->getExtendedInfoTablesEnabled()) {
params += " extended-info-tables=true";
}
cfg_db->setAppendedParameters(params);
cfg_db->createManagers();
} catch (const std::exception& ex) {
answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
status_code = CONTROL_RESULT_ERROR;
}
}
}

// Log the list of known backends.
Expand Down

0 comments on commit f08c5d6

Please sign in to comment.