]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Make resync/monitoring functionality optional
authorMartin Willi <martin@strongswan.org>
Wed, 30 Sep 2009 14:23:58 +0000 (16:23 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 7 Apr 2010 11:55:16 +0000 (13:55 +0200)
src/charon/plugins/ha/ha_plugin.c
src/charon/plugins/ha/ha_segments.c
src/charon/plugins/ha/ha_segments.h

index fb780cab28b7a0dac816fbb0390bda49a042a96b..661db8af8c6babf54f8e7baf8c024d77097d3d5d 100644 (file)
@@ -105,7 +105,7 @@ plugin_t *plugin_create()
        private_ha_plugin_t *this;
        char *local, *remote, *secret;
        u_int count;
-       bool fifo;
+       bool fifo, monitor, resync;
 
        local = lib->settings->get_str(lib->settings,
                                                                "charon.plugins.ha.local", NULL);
@@ -114,7 +114,11 @@ plugin_t *plugin_create()
        secret = lib->settings->get_str(lib->settings,
                                                                "charon.plugins.ha.secret", NULL);
        fifo = lib->settings->get_bool(lib->settings,
-                                                               "charon.plugins.ha.fifo_interface", FALSE);
+                                                               "charon.plugins.ha.fifo_interface", TRUE);
+       monitor = lib->settings->get_bool(lib->settings,
+                                                               "charon.plugins.ha.monitor", TRUE);
+       resync = lib->settings->get_bool(lib->settings,
+                                                               "charon.plugins.ha.resync", TRUE);
        count = min(SEGMENTS_MAX, lib->settings->get_int(lib->settings,
                                                                "charon.plugins.ha.segment_count", 1));
        if (!local || !remote)
@@ -129,26 +133,20 @@ plugin_t *plugin_create()
        this->tunnel = NULL;
        this->ctl = NULL;
 
+       if (secret)
+       {
+               this->tunnel = ha_tunnel_create(local, remote, secret);
+       }
        this->socket = ha_socket_create(local, remote);
        if (!this->socket)
        {
+               DESTROY_IF(this->tunnel);
                free(this);
                return NULL;
        }
        this->kernel = ha_kernel_create(count);
-       if (!this->kernel)
-       {
-               this->socket->destroy(this->socket);
-               free(this);
-               return NULL;
-       }
-
-       if (secret)
-       {
-               this->tunnel = ha_tunnel_create(local, remote, secret);
-       }
-       this->segments = ha_segments_create(this->socket, this->kernel,
-                                                                               this->tunnel, local, remote, count);
+       this->segments = ha_segments_create(this->socket, this->kernel, this->tunnel,
+                                                       count, strcmp(local, remote) > 0, monitor, resync);
        if (fifo)
        {
                this->ctl = ha_ctl_create(this->segments);
index c82bd072300d2f4432769c88c8acaf88d8446126..3575d05b80306ac27a42fd95c05e01d5c2691a08 100644 (file)
@@ -77,9 +77,9 @@ struct private_ha_segments_t {
        segment_mask_t active;
 
        /**
-        * Are we the master node handling segment assignement?
+        * Node number
         */
-       bool master;
+       u_int node;
 };
 
 /**
@@ -388,7 +388,7 @@ static void handle_status(private_ha_segments_t *this, segment_mask_t mask)
        {
                if (missing & SEGMENTS_BIT(i))
                {
-                       if (this->master != i % 2)
+                       if (this->node == i % 2)
                        {
                                DBG1(DBG_CFG, "HA segment %d was not handled, taking", i);
                                enable_disable(this, i, TRUE, TRUE);
@@ -458,7 +458,8 @@ static void destroy(private_ha_segments_t *this)
  * See header
  */
 ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
-                                       ha_tunnel_t *tunnel, char *local, char *remote, u_int count)
+                                                                 ha_tunnel_t *tunnel, u_int count, u_int node,
+                                                                 bool monitor, bool sync)
 {
        private_ha_segments_t *this = malloc_thing(private_ha_segments_t);
 
@@ -476,20 +477,25 @@ ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
        this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
        this->condvar = condvar_create(CONDVAR_TYPE_DEFAULT);
        this->count = count;
-       this->master = strcmp(local, remote) > 0;
+       this->node = node;
        this->job = NULL;
 
        /* initially all segments are deactivated */
        this->active = 0;
 
-       send_status(this);
-
-       start_watchdog(this);
+       if (monitor)
+       {
+               send_status(this);
+               start_watchdog(this);
+       }
 
-       /* request a resync as soon as we are up */
-       charon->processor->queue_job(charon->processor, (job_t*)
+       if (sync)
+       {
+               /* 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;
 }
index 6e5a0dbc897a857312161077ac3ce6e0caf54fd8..6d1cd544114d12fd9ac1514b93181d2d86686a3f 100644 (file)
@@ -97,11 +97,15 @@ struct ha_segments_t {
  *
  * @param socket               socket to communicate segment (de-)activation
  * @param kernel               interface to control segments at kernel level
+ * @param tunnel               HA tunnel
  * @param count                        number of segments the cluster uses
- * @param active               bit mask of initially active segments
+ * @param node                 node, currently 1 or 0
+ * @param monitor              should we use monitoring functionality
+ * @param resync               request a complete resync on startup
  * @return                             segment object
  */
 ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
-                                       ha_tunnel_t *tunnel, char *local, char *remote, u_int count);
+                                                                 ha_tunnel_t *tunnel, u_int count, u_int node,
+                                                                 bool monitor, bool resync);
 
 #endif /* HA_SEGMENTS_ @}*/