From: Marcin Siodelski Date: Thu, 22 Mar 2018 11:26:58 +0000 (+0100) Subject: [5470] Added network_state parameter to the dhcp4_srv_configured hook. X-Git-Tag: trac5458a_base~32^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=975d8d6aff9f0d6c28175e0edd436e6b1d0c576d;p=thirdparty%2Fkea.git [5470] Added network_state parameter to the dhcp4_srv_configured hook. --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 8321799d90..a1a577ddca 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -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(max_period)); + network_state_->delayedEnableAll(static_cast(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 diff --git a/src/bin/dhcp4/dhcp4_hooks.dox b/src/bin/dhcp4/dhcp4_hooks.dox index 2ae0289aa0..a152b88f0a 100644 --- a/src/bin/dhcp4/dhcp4_hooks.dox +++ b/src/bin/dhcp4/dhcp4_hooks.dox @@ -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: in + - name: @b network_state, type: isc::dhcp::NetworkStatePtr, direction: in - name: @b json_config, type: isc::data::ConstElementPtr, direction: in - name: @b server_config, type: isc::dhcp::SrvConfigPtr, direction: in @@ -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. - Next step status: Status codes retured by the callouts installed on this hook point are ignored. diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index ec44daabf0..7db295a483 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -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()); diff --git a/src/bin/dhcp4/dhcp4_srv.h b/src/bin/dhcp4/dhcp4_srv.h index cb10c420ea..72169e6967 100644 --- a/src/bin/dhcp4/dhcp4_srv.h +++ b/src/bin/dhcp4/dhcp4_srv.h @@ -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 diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 1ac0981a51..d46489ef40 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -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 diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc index b43d813425..1e0898776c 100644 --- a/src/bin/dhcp4/tests/hooks_unittest.cc +++ b/src/bin/dhcp4/tests/hooks_unittest.cc @@ -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")); }