]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5470] Added network_state parameter to the dhcp4_srv_configured hook.
authorMarcin Siodelski <marcin@isc.org>
Thu, 22 Mar 2018 11:26:58 +0000 (12:26 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 22 Mar 2018 11:26:58 +0000 (12:26 +0100)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/dhcp4_hooks.dox
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.h
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/hooks_unittest.cc

index 8321799d908bd5170e61a907bfd7288cae04f20a..a1a577ddca30b4f2dc2d03c7e0655075cae087d9 100644 (file)
@@ -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
index 2ae0289aa09802ee2647f6c7a3a9c75fbe191c5d..a152b88f0acf55e411be316012c05f02f088c78b 100644 (file)
@@ -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.
index ec44daabf076818bf74dc8a4a229c5cbce4608c7..7db295a48326c570ea8b546d42b94b89985e0f1d 100644 (file)
@@ -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());
index cb10c420ea05ae351f83df1ccb8d1acd2c758f7d..72169e696779e5fba453a3a888baa06fb92da9a5 100644 (file)
@@ -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
index 1ac0981a514a9d0a153bea8e973c8a1b561a5cc3..d46489ef40334d3b99ec9f7f0bc9dca0a27b1da5 100644 (file)
@@ -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
index b43d813425d8c9efc727a5344660cf8c259dfed3..1e0898776c632e41b77b6f24cbb5c6ebb541d9e4 100644 (file)
@@ -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"));
 }