summaryrefslogtreecommitdiffstats
path: root/src/bin/dhcp4
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2020-11-05 00:23:11 +0100
committerRazvan Becheriu <razvan@isc.org>2020-12-09 18:12:46 +0100
commit126579d1d4e534af57211ad08bf100a92351e72e (patch)
treea75e8c0716e56d92171b82295a57aefecb577be5 /src/bin/dhcp4
parent[#1375] fixed doxygen (diff)
downloadkea-126579d1d4e534af57211ad08bf100a92351e72e.tar.xz
kea-126579d1d4e534af57211ad08bf100a92351e72e.zip
[#1375] added IOService to mysql and postgresql connections
Diffstat (limited to 'src/bin/dhcp4')
-rw-r--r--src/bin/dhcp4/ctrl_dhcp4_srv.cc126
-rw-r--r--src/bin/dhcp4/ctrl_dhcp4_srv.h49
2 files changed, 77 insertions, 98 deletions
diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc
index 94c15496c9..094a65db46 100644
--- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc
+++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc
@@ -29,6 +29,7 @@
#include <sstream>
+using namespace isc::asiolink;
using namespace isc::config;
using namespace isc::data;
using namespace isc::db;
@@ -802,11 +803,18 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
// Re-open lease and host database with new parameters.
try {
- DatabaseConnection::db_lost_callback =
+ DatabaseConnection::db_lost_callback_ =
std::bind(&ControlledDhcpv4Srv::dbLostCallback, srv, ph::_1);
+
+ DatabaseConnection::db_recovered_callback_ =
+ std::bind(&ControlledDhcpv4Srv::dbRecoveredCallback, srv, ph::_1);
+
+ DatabaseConnection::db_failed_callback_ =
+ std::bind(&ControlledDhcpv4Srv::dbFailedCallback, srv, ph::_1);
+
CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess();
cfg_db->setAppendedParameters("universe=4");
- cfg_db->createManagers();
+ cfg_db->createManagers(server_->io_service_);
} catch (const std::exception& ex) {
err << "Unable to open database: " << ex.what();
return (isc::config::createAnswer(1, err.str()));
@@ -831,10 +839,10 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
return (isc::config::createAnswer(1, err.str()));
}
- // Configure DHCP packet queueing
+ // Configure DHCP packet queuing.
try {
data::ConstElementPtr qc;
- qc = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl();
+ 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());
@@ -959,7 +967,7 @@ ControlledDhcpv4Srv::checkConfig(isc::data::ConstElementPtr config) {
ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port /*= DHCP4_SERVER_PORT*/,
uint16_t client_port /*= 0*/)
- : Dhcpv4Srv(server_port, client_port), io_service_(),
+ : Dhcpv4Srv(server_port, client_port), io_service_(boost::make_shared<IOService>()),
timer_mgr_(TimerMgr::instance()) {
if (getInstance()) {
isc_throw(InvalidOperation,
@@ -1054,7 +1062,7 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port /*= DHCP4_SERVER_P
void ControlledDhcpv4Srv::shutdownServer(int exit_value) {
setExitValue(exit_value);
- io_service_.stop(); // Stop ASIO transmissions
+ io_service_->stop(); // Stop ASIO transmissions
shutdown(); // Initiate DHCPv4 shutdown procedure.
}
@@ -1064,7 +1072,8 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() {
// The closure captures either a shared pointer (memory leak)
// or a raw pointer (pointing to a deleted object).
- DatabaseConnection::db_lost_callback = 0;
+ DatabaseConnection::db_lost_callback_ = 0;
+ DatabaseConnection::db_recovered_callback_ = 0;
timer_mgr_->unregisterTimers();
@@ -1112,7 +1121,7 @@ void ControlledDhcpv4Srv::sessionReader(void) {
// Process one asio event. If there are more events, iface_mgr will call
// this callback more than once.
if (getInstance()) {
- getInstance()->io_service_.run_one();
+ getInstance()->io_service_->run_one();
}
}
@@ -1140,66 +1149,9 @@ ControlledDhcpv4Srv::deleteExpiredReclaimedLeases(const uint32_t secs) {
TimerMgr::instance()->setup(CfgExpiration::FLUSH_RECLAIMED_TIMER_NAME);
}
-void
-ControlledDhcpv4Srv::dbReconnect(ReconnectCtlPtr db_reconnect_ctl) {
- bool reopened = false;
-
- // We lost at least one of them. Reopen all of them (lease, host, and CB databases).
- try {
- CfgDbAccessPtr cfg_db = CfgMgr::instance().getCurrentCfg()->getCfgDbAccess();
- cfg_db->createManagers();
-
- auto ctl_info = CfgMgr::instance().getCurrentCfg()->getConfigControlInfo();
- if (ctl_info) {
- auto srv_cfg = CfgMgr::instance().getCurrentCfg();
- server_->getCBControl()->databaseConfigConnect(srv_cfg);
- }
-
- reopened = true;
- } catch (const std::exception& ex) {
- LOG_ERROR(dhcp4_logger, DHCP4_DB_RECONNECT_ATTEMPT_FAILED).arg(ex.what());
- }
-
- if (reopened) {
- // Cancel the timer.
- if (TimerMgr::instance()->isTimerRegistered("Dhcp4DbReconnectTimer")) {
- TimerMgr::instance()->cancel("Dhcp4DbReconnectTimer");
- }
-
- // Set network state to service enabled
- network_state_->enableService();
-
- // Toss the reconnect control, we're done with it
- db_reconnect_ctl.reset();
- } else {
- if (!db_reconnect_ctl->checkRetries()) {
- // We're out of retries, log it and initiate shutdown.
- LOG_ERROR(dhcp4_logger, DHCP4_DB_RECONNECT_RETRIES_EXHAUSTED)
- .arg(db_reconnect_ctl->maxRetries());
- shutdownServer(EXIT_FAILURE);
- return;
- }
-
- LOG_INFO(dhcp4_logger, DHCP4_DB_RECONNECT_ATTEMPT_SCHEDULE)
- .arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
- .arg(db_reconnect_ctl->maxRetries())
- .arg(db_reconnect_ctl->retryInterval());
-
- if (!TimerMgr::instance()->isTimerRegistered("Dhcp4DbReconnectTimer")) {
- TimerMgr::instance()->registerTimer("Dhcp4DbReconnectTimer",
- std::bind(&ControlledDhcpv4Srv::dbReconnect, this,
- db_reconnect_ctl),
- db_reconnect_ctl->retryInterval(),
- asiolink::IntervalTimer::ONE_SHOT);
- }
-
- TimerMgr::instance()->setup("Dhcp4DbReconnectTimer");
- }
-}
-
bool
ControlledDhcpv4Srv::dbLostCallback(ReconnectCtlPtr db_reconnect_ctl) {
- // Disable service until we recover
+ // Disable service until the connection is recovered.
network_state_->disableService();
if (!db_reconnect_ctl) {
@@ -1208,21 +1160,51 @@ ControlledDhcpv4Srv::dbLostCallback(ReconnectCtlPtr db_reconnect_ctl) {
return (false);
}
- // If reconnect isn't enabled log it,
- // initiate a shutdown and return false.
+ // If reconnect isn't enabled log it, initiate a shutdown and return false.
if (!db_reconnect_ctl->retriesLeft() ||
!db_reconnect_ctl->retryInterval()) {
LOG_INFO(dhcp4_logger, DHCP4_DB_RECONNECT_DISABLED)
.arg(db_reconnect_ctl->retriesLeft())
.arg(db_reconnect_ctl->retryInterval());
shutdownServer(EXIT_FAILURE);
- return(false);
+ return (false);
+ }
+
+ return (true);
+}
+
+bool
+ControlledDhcpv4Srv::dbRecoveredCallback(ReconnectCtlPtr db_reconnect_ctl) {
+ // Enable service after the connection is recovered.
+ network_state_->enableService();
+
+ if (!db_reconnect_ctl) {
+ // This shouldn't never happen
+ LOG_ERROR(dhcp4_logger, DHCP4_DB_RECONNECT_NO_DB_CTL);
+ return (false);
}
- // Invoke reconnect method
- dbReconnect(db_reconnect_ctl);
+ db_reconnect_ctl->resetRetries();
+
+ return (true);
+}
+
+bool
+ControlledDhcpv4Srv::dbFailedCallback(ReconnectCtlPtr db_reconnect_ctl) {
+ if (!db_reconnect_ctl) {
+ // This shouldn't never happen
+ LOG_ERROR(dhcp4_logger, DHCP4_DB_RECONNECT_NO_DB_CTL);
+ return (false);
+ }
+
+ //LOG_INFO(dhcp4_logger, DHCP4_DB_FAILED_RECONNECT)
+ // .arg(db_reconnect_ctl->maxRetries());
+
+ db_reconnect_ctl->resetRetries();
+
+ shutdownServer(EXIT_FAILURE);
- return(true);
+ return (true);
}
void
diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.h b/src/bin/dhcp4/ctrl_dhcp4_srv.h
index 1f0a862030..81c6ce6365 100644
--- a/src/bin/dhcp4/ctrl_dhcp4_srv.h
+++ b/src/bin/dhcp4/ctrl_dhcp4_srv.h
@@ -387,27 +387,7 @@ private:
/// deleted.
void deleteExpiredReclaimedLeases(const uint32_t secs);
- /// @brief Attempts to reconnect the server to the DB backend managers
- ///
- /// This is a self-rescheduling function that attempts to reconnect to the
- /// server's DB backends after connectivity to one or more have been
- /// lost. Upon entry it will attempt to reconnect via @ref CfgDdbAccess::
- /// createManagers. If this is succesful, DHCP servicing is re-enabled and
- /// server returns to normal operation.
- ///
- /// If reconnection fails and the maximum number of retries has not been
- /// exhausted, it will schedule a call to itself to occur at the
- /// configured retry interval. DHCP service remains disabled.
- ///
- /// If the maximum number of retries has been exhausted an error is logged
- /// and the server shuts down.
- ///
- /// @param db_reconnect_ctl pointer to the ReconnectCtl containing the
- /// configured reconnect parameters
- ///
- void dbReconnect(db::ReconnectCtlPtr db_reconnect_ctl);
-
- /// @brief Callback DB backends should invoke upon loss of connectivity
+ /// @brief Callback DB backends should invoke upon loss of the connectivity
///
/// This function is invoked by DB backends when they detect a loss of
/// connectivity. The parameter, db_reconnect_ctl, conveys the configured
@@ -416,10 +396,8 @@ private:
///
/// If either value is zero, reconnect is presumed to be disabled and
/// the function will schedule a shutdown and return false. This instructs
- /// the DB backend layer (the caller) to treat the connectivity loss as fatal.
- ///
- /// Otherwise, the function saves db_reconnect_ctl and invokes
- /// dbReconnect to initiate the reconnect process.
+ /// the DB backend layer (the caller) to treat the connectivity loss as
+ /// fatal. It stops the DHCP service until the connection is recovered.
///
/// @param db_reconnect_ctl pointer to the ReconnectCtl containing the
/// configured reconnect parameters
@@ -427,6 +405,25 @@ private:
/// @return false if reconnect is not configured, true otherwise
bool dbLostCallback(db::ReconnectCtlPtr db_reconnect_ctl);
+ /// @brief Callback DB backends should invoke upon restoration of the
+ /// connectivity
+ ///
+ /// This function is invoked by DB backends when they recover the
+ /// connectivity. It starts the DHCP service after the connection is
+ /// recovered.
+ ///
+ /// @return false if reconnect is not configured, true otherwise
+ bool dbRecoveredCallback(db::ReconnectCtlPtr db_reconnect_ctl);
+
+ /// @brief Callback DB backends should invoke upon failing to restore of the
+ /// connectivity
+ ///
+ /// This function is invoked by DB backends when they fail to recover the
+ /// connectivity. It stops the server.
+ ///
+ /// @return false if reconnect is not configured, true otherwise
+ bool dbFailedCallback(db::ReconnectCtlPtr db_reconnect_ctl);
+
/// @brief Callback invoked periodically to fetch configuration updates
/// from the Config Backends.
///
@@ -448,7 +445,7 @@ private:
static ControlledDhcpv4Srv* server_;
/// @brief IOService object, used for all ASIO operations.
- isc::asiolink::IOService io_service_;
+ isc::asiolink::IOServicePtr io_service_;
/// @brief Instance of the @c TimerMgr.
///