Commit 975d8d6a authored by Marcin Siodelski's avatar Marcin Siodelski

[5470] Added network_state parameter to the dhcp4_srv_configured hook.

parent cdbffcec
......@@ -432,7 +432,7 @@ ControlledDhcpv4Srv::commandDhcpDisableHandler(const std::string&,
// The user specified that the DHCP service should resume not
// later than in max-period seconds. If the 'dhcp-enable' command
// is not sent, the DHCP service will resume automatically.
network_state_.delayedEnableAll(static_cast<unsigned>(max_period));
network_state_->delayedEnableAll(static_cast<unsigned>(max_period));
}
}
}
......@@ -440,7 +440,7 @@ ControlledDhcpv4Srv::commandDhcpDisableHandler(const std::string&,
// No error occurred, so let's disable the service.
if (message.tellp() == 0) {
network_state_.disableService();
network_state_->disableService();
message << "DHCPv4 service disabled";
if (max_period > 0) {
......@@ -456,7 +456,7 @@ ControlledDhcpv4Srv::commandDhcpDisableHandler(const std::string&,
ConstElementPtr
ControlledDhcpv4Srv::commandDhcpEnableHandler(const std::string&, ConstElementPtr) {
network_state_.enableService();
network_state_->enableService();
return (config::createAnswer(CONTROL_RESULT_SUCCESS, "DHCP service successfully enabled"));
}
......@@ -663,6 +663,7 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
callout_handle->setArgument("io_context", srv->getIOService());
callout_handle->setArgument("network_state", srv->getNetworkState());
callout_handle->setArgument("json_config", config);
callout_handle->setArgument("server_config", CfgMgr::instance().getStagingCfg());
......@@ -859,7 +860,7 @@ ControlledDhcpv4Srv::dbReconnect(ReconnectCtlPtr db_reconnect_ctl) {
}
// Set network state to service enabled
network_state_.enableService();
network_state_->enableService();
// Toss the reconnect control, we're done with it
db_reconnect_ctl.reset();
......@@ -891,7 +892,7 @@ ControlledDhcpv4Srv::dbReconnect(ReconnectCtlPtr db_reconnect_ctl) {
bool
ControlledDhcpv4Srv::dbLostCallback(ReconnectCtlPtr db_reconnect_ctl) {
// Disable service until we recover
network_state_.disableService();
network_state_->disableService();
if (!db_reconnect_ctl) {
// This shouldn't never happen
......
......@@ -49,6 +49,7 @@ to the end of this list.
@subsection dhcp4HooksDhcpv4SrvConfigured dhcp4_srv_configured
- @b Arguments:
- name: @b io_context, type: isc::asiolink::IOServicePtr, direction: <b>in</b>
- name: @b network_state, type: isc::dhcp::NetworkStatePtr, direction: <b>in</b>
- name: @b json_config, type: isc::data::ConstElementPtr, direction: <b>in</b>
- name: @b server_config, type: isc::dhcp::SrvConfigPtr, direction: <b>in</b>
......@@ -58,7 +59,9 @@ to the end of this list.
object which is used by the server to run asynchronous operations. The hooks
libraries can use this IOService object to schedule asynchronous tasks which
are triggered by the DHCP server's main loop. The hook library should hold the
provided pointer until the library is unloaded.
provided pointer until the library is unloaded. The NetworkState object
provides access to the DHCP service state of the server and allows for
enabling and disabling the DHCP service from the hooks libraries.
- <b>Next step status</b>: Status codes retured by the callouts installed on
this hook point are ignored.
......
......@@ -422,7 +422,7 @@ const std::string Dhcpv4Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
Dhcpv4Srv::Dhcpv4Srv(uint16_t port, const bool use_bcast,
const bool direct_response_desired)
: io_service_(new IOService()), shutdown_(true), alloc_engine_(), port_(port),
use_bcast_(use_bcast), network_state_(NetworkState::DHCPv4) {
use_bcast_(use_bcast), network_state_(new NetworkState(NetworkState::DHCPv4)) {
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_OPEN_SOCKET).arg(port);
try {
......@@ -827,7 +827,7 @@ Dhcpv4Srv::run_one() {
}
// If the DHCP service has been globally disabled, drop the packet.
if (!network_state_.isServiceEnabled()) {
if (!network_state_->isServiceEnabled()) {
LOG_DEBUG(bad_packet4_logger, DBG_DHCP4_BASIC,
DHCP4_PACKET_DROP_0008)
.arg(query->getLabel());
......
......@@ -235,6 +235,11 @@ public:
return (io_service_);
}
/// @brief Returns pointer to the network state used by the server.
NetworkStatePtr& getNetworkState() {
return (network_state_);
}
/// @brief returns Kea version on stdout and exit.
/// redeclaration/redefinition. @ref Daemon::getVersion()
static std::string getVersion(bool extended);
......@@ -877,7 +882,7 @@ protected:
/// @brief Holds information about disabled DHCP service and/or
/// disabled subnet/network scopes.
NetworkState network_state_;
NetworkStatePtr network_state_;
public:
/// Class methods for DHCPv4-over-DHCPv6 handler
......
......@@ -1171,7 +1171,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, dhcpDisable) {
ConstElementPtr cfg = parseAnswer(status, rsp);
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status);
EXPECT_FALSE(server_->network_state_.isServiceEnabled());
EXPECT_FALSE(server_->network_state_->isServiceEnabled());
}
// This test verifies that it is possible to disable DHCP service for a short
......@@ -1198,10 +1198,10 @@ TEST_F(CtrlChannelDhcpv4SrvTest, dhcpDisableTemporarily) {
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status);
// The service should be disabled.
EXPECT_FALSE(server_->network_state_.isServiceEnabled());
EXPECT_FALSE(server_->network_state_->isServiceEnabled());
// And the timer should be scheduled which counts the time to automatic
// enabling of the service.
EXPECT_TRUE(server_->network_state_.isDelayedEnableAll());
EXPECT_TRUE(server_->network_state_->isDelayedEnableAll());
}
// This test verifies if it is possible to enable DHCP service via command.
......@@ -1220,7 +1220,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, dhcpEnable) {
ConstElementPtr cfg = parseAnswer(status, rsp);
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status);
EXPECT_TRUE(server_->network_state_.isServiceEnabled());
EXPECT_TRUE(server_->network_state_->isServiceEnabled());
}
/// Verify that concurrent connections over the control channel can be
......
......@@ -2688,7 +2688,7 @@ TEST_F(LoadUnloadDhcpv4SrvTest, Dhcpv4SrvConfigured) {
// The dhcp4_srv_configured should have been invoked and the provided
// parameters should be recorded.
EXPECT_TRUE(checkMarkerFile(SRV_CONFIG_MARKER_FILE,
"3io_contextjson_configserver_config"));
"3io_contextjson_confignetwork_stateserver_config"));
// Destroy the server, instance which should unload the libraries.
srv.reset();
......@@ -2698,5 +2698,5 @@ TEST_F(LoadUnloadDhcpv4SrvTest, Dhcpv4SrvConfigured) {
EXPECT_TRUE(checkMarkerFile(LOAD_MARKER_FILE, "3"));
EXPECT_TRUE(checkMarkerFile(UNLOAD_MARKER_FILE, "3"));
EXPECT_TRUE(checkMarkerFile(SRV_CONFIG_MARKER_FILE,
"3io_contextjson_configserver_config"));
"3io_contextjson_confignetwork_stateserver_config"));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment