diff options
author | Razvan Becheriu <razvan@isc.org> | 2020-12-10 16:39:00 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2021-01-22 18:15:19 +0100 |
commit | d7ea6fcac06c36dda70c87db57db39faab127d23 (patch) | |
tree | 80ee23edfa32dd6321c286be206dbe3e4c20afdd /src/bin/dhcp4 | |
parent | [#1375] fixed rebase (diff) | |
download | kea-d7ea6fcac06c36dda70c87db57db39faab127d23.tar.xz kea-d7ea6fcac06c36dda70c87db57db39faab127d23.zip |
[#1601] use internal state to differentiate between actors affecting the network state
Diffstat (limited to 'src/bin/dhcp4')
-rw-r--r-- | src/bin/dhcp4/ctrl_dhcp4_srv.cc | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 96ebb585ef..af15fbbe23 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -259,7 +259,7 @@ ControlledDhcpv4Srv::commandConfigReloadHandler(const string&, } catch (const std::exception& ex) { // Log the unsuccessful reconfiguration. The reason for failure // should be already logged. Don't rethrow an exception so as - // the control channel perhaps keeps working. + // the server keeps working. LOG_FATAL(dhcp4_logger, DHCP4_DYNAMIC_RECONFIGURATION_FAIL) .arg(file); return (createAnswer(CONTROL_RESULT_ERROR, @@ -405,7 +405,7 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&, // the logging first in case there's a configuration failure. int rcode = 0; isc::config::parseAnswer(rcode, result); - if (rcode == 0) { + if (rcode == CONTROL_RESULT_SUCCESS) { CfgMgr::instance().getStagingCfg()->applyLoggingCfg(); // Use new configuration. @@ -490,6 +490,9 @@ ControlledDhcpv4Srv::commandDhcpDisableHandler(const std::string&, ConstElementPtr args) { std::ostringstream message; int64_t max_period = 0; + int64_t handle_id = 0; + + NetworkState::ControllerType type = NetworkState::COMMAND; // Parse arguments to see if the 'max-period' parameter has been specified. if (args) { @@ -518,12 +521,28 @@ ControlledDhcpv4Srv::commandDhcpDisableHandler(const std::string&, network_state_->delayedEnableAll(static_cast<unsigned>(max_period)); } } + ConstElementPtr handle_id_element = args->get("handle-id"); + // handle-id is optional. + if (handle_id_element) { + // It must be an integer, if specified. + if (handle_id_element->getType() != Element::integer) { + message << "'handle-id' argument must be a number"; + + } else { + // It must be positive integer. + handle_id = handle_id_element->intValue(); + if (handle_id <= 0) { + message << "'handle-id' must be positive integer"; + } + type = NetworkState::HA; + } + } } } // No error occurred, so let's disable the service. if (message.tellp() == 0) { - network_state_->disableService(NetworkState::COMMAND); + network_state_->disableService(type); message << "DHCPv4 service disabled"; if (max_period > 0) { @@ -538,9 +557,49 @@ ControlledDhcpv4Srv::commandDhcpDisableHandler(const std::string&, } ConstElementPtr -ControlledDhcpv4Srv::commandDhcpEnableHandler(const std::string&, ConstElementPtr) { - network_state_->enableService(NetworkState::COMMAND); - return (config::createAnswer(CONTROL_RESULT_SUCCESS, "DHCP service successfully enabled")); +ControlledDhcpv4Srv::commandDhcpEnableHandler(const std::string&, + ConstElementPtr args) { + std::ostringstream message; + int64_t handle_id = 0; + + NetworkState::ControllerType type = NetworkState::COMMAND; + + // Parse arguments to see if the 'max-period' parameter has been specified. + if (args) { + // Arguments must be a map. + if (args->getType() != Element::map) { + message << "arguments for the 'dhcp-enable' command must be a map"; + + } else { + ConstElementPtr handle_id_element = args->get("handle-id"); + // handle-id is optional. + if (handle_id_element) { + // It must be an integer, if specified. + if (handle_id_element->getType() != Element::integer) { + message << "'handle-id' argument must be a number"; + + } else { + // It must be positive integer. + handle_id = handle_id_element->intValue(); + if (handle_id <= 0) { + message << "'handle-id' must be positive integer"; + } + type = NetworkState::HA; + } + } + } + } + + // No error occurred, so let's disable the service. + if (message.tellp() == 0) { + network_state_->enableService(type); + + // Success. + return (config::createAnswer(CONTROL_RESULT_SUCCESS, "DHCP service successfully enabled")); + } + + // Failure. + return (config::createAnswer(CONTROL_RESULT_ERROR, message.str())); } ConstElementPtr @@ -817,6 +876,8 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) { CfgDbAccessPtr cfg_db = CfgMgr::instance().getStagingCfg()->getCfgDbAccess(); cfg_db->setAppendedParameters("universe=4"); cfg_db->createManagers(); + // Reset counters related to connections as all managers have been recreated. + srv->getNetworkState()->resetInternalCounters(); } catch (const std::exception& ex) { err << "Unable to open database: " << ex.what(); return (isc::config::createAnswer(1, err.str())); |