]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Request a complete resync after daemon startup
authorMartin Willi <martin@strongswan.org>
Wed, 30 Sep 2009 09:04:22 +0000 (11:04 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 7 Apr 2010 11:55:16 +0000 (13:55 +0200)
src/charon/plugins/ha/ha_dispatcher.c
src/charon/plugins/ha/ha_message.h
src/charon/plugins/ha/ha_segments.c

index f2eabc67217b374c30cd2a1d93f9c238885ea991..4acf7477a96b9cd78247aef34d2ba19ef62c253a 100644 (file)
@@ -635,6 +635,31 @@ static void process_status(private_ha_dispatcher_t *this,
        this->segments->handle_status(this->segments, mask);
 }
 
+/**
+ * Process messages of type RESYNC
+ */
+static void process_resync(private_ha_dispatcher_t *this,
+                                                  ha_message_t *message)
+{
+       ha_message_attribute_t attribute;
+       ha_message_value_t value;
+       enumerator_t *enumerator;
+
+       enumerator = message->create_attribute_enumerator(message);
+       while (enumerator->enumerate(enumerator, &attribute, &value))
+       {
+               switch (attribute)
+               {
+                       case HA_SEGMENT:
+                               this->segments->resync(this->segments, value.u16);
+                               break;
+                       default:
+                               break;
+               }
+       }
+       enumerator->destroy(enumerator);
+}
+
 /**
  * Dispatcher job function
  */
@@ -669,6 +694,9 @@ static job_requeue_t dispatch(private_ha_dispatcher_t *this)
                case HA_STATUS:
                        process_status(this, message);
                        break;
+               case HA_RESYNC:
+                       process_resync(this, message);
+                       break;
                default:
                        DBG1(DBG_CFG, "received unknown HA message type %d",
                                 message->get_type(message));
index 76f1fefbd5baf42614e036f6f3396ff706adcd0c..62041328809c58cb998ea65ce6e816083d32259f 100644 (file)
@@ -57,6 +57,8 @@ enum ha_message_type_t {
        HA_SEGMENT_TAKE,
        /** status with the segments the sending node is currently serving */
        HA_STATUS,
+       /** segments the receiving node is requested to resync */
+       HA_RESYNC,
 };
 
 /**
index 9b7490c94a9fc29b8440ac75d131482219674a0f..c82bd072300d2f4432769c88c8acaf88d8446126 100644 (file)
@@ -257,15 +257,12 @@ static void resync(private_ha_segments_t *this, u_int segment)
        enumerator_t *enumerator;
        linked_list_t *list;
        ike_sa_id_t *id;
-       u_int16_t mask = SEGMENTS_BIT(segment);
 
        list = linked_list_create();
        this->mutex->lock(this->mutex);
 
-       if (segment > 0 && segment <= this->count && (this->active & mask))
+       if (segment > 0 && segment <= this->count)
        {
-               this->active &= ~mask;
-
                DBG1(DBG_CFG, "resyncing HA segment %d", segment);
 
                /* we do the actual rekeying in a seperate loop to avoid rekeying
@@ -322,6 +319,23 @@ static bool alert_hook(private_ha_segments_t *this, ike_sa_t *ike_sa,
        return TRUE;
 }
 
+/**
+ * Request a resync of all segments
+ */
+static job_requeue_t request_resync(private_ha_segments_t *this)
+{
+       ha_message_t *message;
+       int i;
+
+       message = ha_message_create(HA_RESYNC);
+       for (i = 1; i <= this->count; i++)
+       {
+               message->add_attribute(message, HA_SEGMENT, i);
+       }
+       this->socket->push(this->socket, message);
+       return JOB_REQUEUE_NONE;
+}
+
 /**
  * Monitor heartbeat activity of remote node
  */
@@ -463,6 +477,7 @@ ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
        this->condvar = condvar_create(CONDVAR_TYPE_DEFAULT);
        this->count = count;
        this->master = strcmp(local, remote) > 0;
+       this->job = NULL;
 
        /* initially all segments are deactivated */
        this->active = 0;
@@ -471,6 +486,11 @@ ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
 
        start_watchdog(this);
 
+       /* request a resync as soon as we are up */
+       charon->processor->queue_job(charon->processor, (job_t*)
+                                               callback_job_create((callback_job_cb_t)request_resync,
+                                                                                       this, NULL, NULL));
+
        return &this->public;
 }