diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index f464e0a94c..8e7d785d87 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -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 diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 6c590940d1..3aeb22a83c 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -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; } @@ -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()) { diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index 89e50edea1..5ec39ef115 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -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) @@ -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. diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 635212eda5..580852f1b3 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -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 diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 392ca47133..62590a2a5e 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -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(); @@ -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()) { diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index ea132a12ac..bed71a4cb0 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -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) @@ -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.