]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3106] Fix network state for ha-sync-complete-notify
authorMarcin Siodelski <marcin@isc.org>
Wed, 6 Dec 2023 10:35:38 +0000 (11:35 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 6 Dec 2023 10:35:38 +0000 (11:35 +0100)
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc

index 2aaff5dc131d2fc12620e0886c2c265a7d436c86..b6f9b96f70b3100df0b4ac94db13467fc8932a9f 100644 (file)
@@ -3011,9 +3011,14 @@ ConstElementPtr
 HAService::processSyncCompleteNotify(const unsigned int origin) {
     if (getCurrState() == HA_PARTNER_DOWN_ST) {
         sync_complete_notified_ = true;
-    } else {
-        network_state_->enableService(origin);
+        // We're in the partner-down state, so we don't want to enable the
+        // service until we confirm that the partner is really available.
+        // Let's disable the service locally until we confirm.
+        network_state_->disableService(getLocalOrigin());
     }
+    // Release the network state lock for the remote origin because we
+    // now have the service disabled locally.
+    network_state_->enableService(origin);
     return (createAnswer(CONTROL_RESULT_SUCCESS,
                          "Server successfully notified about the synchronization completion."));
 }
index 32626bf79665336caa3c00a7d3ac6255833f887e..d094cb4d46b9f7c147a10eeb9d2ea7bf11be7c1a 100644 (file)
@@ -5176,9 +5176,7 @@ TEST_F(HAServiceTest, processSyncCompleteNotify) {
     EXPECT_NO_THROW(service.transition(HA_PARTNER_DOWN_ST, HAService::NOP_EVT));
 
     // Simulate disabling the DHCP service for synchronization.
-    if (service.network_state_->isServiceEnabled()) {
-        EXPECT_NO_THROW(service.network_state_->disableService(NetworkState::HA_REMOTE_COMMAND+1));
-    }
+    EXPECT_NO_THROW(service.network_state_->disableService(NetworkState::HA_REMOTE_COMMAND+1));
 
     ConstElementPtr rsp;
     EXPECT_NO_THROW(rsp = service.processSyncCompleteNotify(NetworkState::HA_REMOTE_COMMAND+1));
@@ -5200,10 +5198,15 @@ TEST_F(HAServiceTest, processSyncCompleteNotify) {
     // serving the clients in the partner-down state.
     EXPECT_NO_THROW(service.postNextEvent(HAService::HA_SYNCED_PARTNER_UNAVAILABLE_EVT));
     EXPECT_NO_THROW(service.runModel(HAService::NOP_EVT));
+    EXPECT_EQ(HA_PARTNER_DOWN_ST, service.getCurrState());
     EXPECT_TRUE(service.network_state_->isServiceEnabled());
 
     // Transition the server to the load-balancing state.
     EXPECT_NO_THROW(service.transition(HA_LOAD_BALANCING_ST, HAService::NOP_EVT));
+    EXPECT_NO_THROW(service.runModel(HAService::NOP_EVT));
+
+    // It should unlock the network service.
+    EXPECT_TRUE(service.network_state_->isServiceEnabled());
 
     // Disable the service again.
     EXPECT_NO_THROW(service.network_state_->disableService(NetworkState::HA_REMOTE_COMMAND+1));