Check if for some reason we handle a HA segment on both nodes
authorMartin Willi <martin@revosec.ch>
Tue, 19 Mar 2013 15:48:53 +0000 (16:48 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 19 Mar 2013 15:50:39 +0000 (16:50 +0100)
src/libcharon/plugins/ha/ha_segments.c

index 45ffa87..a4ea9ef 100644 (file)
@@ -289,12 +289,13 @@ static void start_watchdog(private_ha_segments_t *this)
 METHOD(ha_segments_t, handle_status, void,
        private_ha_segments_t *this, segment_mask_t mask)
 {
-       segment_mask_t missing;
+       segment_mask_t missing, twice;
        int i;
 
        this->mutex->lock(this->mutex);
 
        missing = ~(this->active | mask);
+       twice = this->active & mask;
 
        for (i = 1; i <= this->count; i++)
        {
@@ -311,6 +312,19 @@ METHOD(ha_segments_t, handle_status, void,
                                enable_disable(this, i, FALSE, TRUE);
                        }
                }
+               if (twice & SEGMENTS_BIT(i))
+               {
+                       if (this->node == i % 2)
+                       {
+                               DBG1(DBG_CFG, "HA segment %d was handled twice, taking", i);
+                               enable_disable(this, i, TRUE, TRUE);
+                       }
+                       else
+                       {
+                               DBG1(DBG_CFG, "HA segment %d was handled twice, dropping", i);
+                               enable_disable(this, i, FALSE, TRUE);
+                       }
+               }
        }
 
        this->condvar->signal(this->condvar);