]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1375] add network state transition controller type
authorRazvan Becheriu <razvan@isc.org>
Fri, 27 Nov 2020 12:48:49 +0000 (14:48 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 22 Jan 2021 17:15:19 +0000 (17:15 +0000)
src/lib/dhcpsrv/network_state.cc
src/lib/dhcpsrv/network_state.h

index a86a3465b5a4d0c8df3c900d514943092c4f31dd..d3ca3a61429678dead3ab71dfa08ddfa0c4fe755 100644 (file)
@@ -29,8 +29,10 @@ public:
 
     /// @brief Constructor.
     NetworkStateImpl(const NetworkState::ServerType& server_type)
-        : server_type_(server_type), globally_disabled_(false), disabled_subnets_(),
-          disabled_networks_(), timer_mgr_(TimerMgr::instance()) {
+        : server_type_(server_type), globally_disabled_(false),
+          disabled_subnets_(), disabled_networks_(),
+          timer_mgr_(TimerMgr::instance()), disabled_by_command_(false),
+          disabled_by_connection_(0), disabled_by_ha_(false) {
     }
 
     /// @brief Destructor.
@@ -39,15 +41,44 @@ public:
     }
 
     /// @brief Globally disables or enables DHCP service.
-    void setDisableService(const bool disable) {
-        globally_disabled_ = disable;
+    void setDisableService(const bool disable, const ControllerType& type) {
+        if (disable) {
+            globally_disabled_ = true;
+            switch (type) {
+            case COMMAND:
+                disabled_by_command_ = true;
+                break;
+            case CONNECTION:
+                ++disabled_by_connection_;
+                break;
+            case COMMAND:
+                disabled_by_ha_ = true;
+                break;
+            }
+        } else {
+            switch (type) {
+            case COMMAND:
+                disabled_by_command_ = false;
+                break;
+            case CONNECTION:
+                --disabled_by_connection_;
+                break;
+            case COMMAND:
+                disabled_by_ha_ = false;
+                break;
+            }
+            if (!disabled_by_command_ && disabled_by_connection_ == 0 &&
+                !disabled_by_ha_) {
+                globally_disabled_ = false;
+            }
+        }
     }
 
     /// @brief Enables DHCP service globally and per scopes.
     ///
     /// If delayed enabling DHCP service has been scheduled, it cancels it.
     void enableAll() {
-        setDisableService(false);
+        setDisableService(false, NetworkState::COMMAND);
 
         /// @todo Enable service for all subnets and networks here.
 
@@ -96,6 +127,16 @@ public:
     /// This pointer is held here to make sure that the timer manager is not
     /// destroyed before an instance of this class is destroyed.
     TimerMgrPtr timer_mgr_;
+
+    /// @brief Flag which indicates the state has been disabled by a command.
+    bool disabled_by_command_;
+
+    /// @brief Flag which indicates the state has been disabled by a connection
+    /// loss.
+    uint32_t disabled_by_connection_;
+
+    /// @brief Flag which indicates the state has been disabled by the HA lib.
+    bool disabled_by_ha_;
 };
 
 NetworkState::NetworkState(const NetworkState::ServerType& server_type)
@@ -103,13 +144,13 @@ NetworkState::NetworkState(const NetworkState::ServerType& server_type)
 }
 
 void
-NetworkState::disableService() {
-    impl_->setDisableService(true);
+NetworkState::disableService(const ControllerType& type) {
+    impl_->setDisableService(true, type);
 }
 
 void
-NetworkState::enableService() {
-    impl_->setDisableService(false);
+NetworkState::enableService(const ControllerType& type) {
+    impl_->setDisableService(false, type);
 }
 
 void
@@ -152,6 +193,5 @@ NetworkState::selectiveEnable(const NetworkState::Networks&) {
     isc_throw(NotImplemented, "selectiveEnableService is not implemented");
 }
 
-
 } // end of namespace isc::dhcp
 } // end of namespace isc
index 137c29bbed81585c92b8bd848702d86fb6fa7c88..a006c2d4835ad881aae5de18e1a2ae7e4b1f4f56 100644 (file)
@@ -63,6 +63,13 @@ public:
         DHCPv6
     };
 
+    /// @brief Controller type.
+    enum ControllerType {
+        COMMAND,
+        CONNECTION,
+        HA
+    };
+
     /// @brief Type of the container holding collection of subnet identifiers.
     typedef std::set<SubnetID> Subnets;
 
@@ -76,14 +83,18 @@ public:
     ///
     /// The DHCP service becomes disabled for all subnets and networks,
     /// regardless of the per scope settings.
-    void disableService();
+    ///
+    /// @param type Controller type which issued the state transition.
+    void disableService(const ControllerType& type);
 
     /// @brief Globally enables DHCP service.
     ///
     /// The DHCP service becomes enabled but per scope settings are in effect.
     /// In order to enable the service for all scopes previously disabled with
     /// a control command, use @c enableAll.
-    void enableService();
+    ///
+    /// @param type Controller type which issued the state transition.
+    void enableService(const ControllerType& type);
 
     /// @brief Enables DHCP service globally and for scopes which have been
     /// disabled as a result of control command.