// 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));
}
}
}
// 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) {
ConstElementPtr
ControlledDhcpv4Srv::commandDhcpEnableHandler(const std::string&, ConstElementPtr) {
- network_state_.enableService();
+ network_state_->enableService();
return (config::createAnswer(CONTROL_RESULT_SUCCESS, "DHCP service successfully enabled"));
}
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());
}
// 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();
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
@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>
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.
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 {
}
// 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());
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);
/// @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
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
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.
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
// 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();
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"));
}