]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
ha: Wait for configuration backend to complete loading before starting sync ha-sync-delay
authorMartin Willi <martin@revosec.ch>
Fri, 10 Apr 2015 12:17:55 +0000 (14:17 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 10 Apr 2015 12:17:55 +0000 (14:17 +0200)
src/libcharon/plugins/ha/ha_cache.c
src/libcharon/plugins/ha/ha_cache.h
src/libcharon/plugins/ha/ha_plugin.c

index 6c1b3471dd3532b57a8875d2d5654efe455f0159..7e8ab9de9526cd60c796006b3a279e8764e5ca78 100644 (file)
@@ -56,6 +56,11 @@ struct private_ha_cache_t {
         * Mutex to lock cache
         */
        mutex_t *mutex;
+
+       /**
+        * Sync configuration on config reload
+        */
+       bool sync;
 };
 
 /**
@@ -353,6 +358,23 @@ static job_requeue_t request_resync(private_ha_cache_t *this)
        return JOB_REQUEUE_NONE;
 }
 
+METHOD(listener_t, alert_hook, bool,
+       private_ha_cache_t *this, ike_sa_t *ike_sa, alert_t alert, va_list args)
+{
+       if (alert == ALERT_CONF_RELOAD_FINISHED)
+       {
+               if (this->sync)
+               {
+                       lib->processor->queue_job(lib->processor, (job_t*)
+                               callback_job_create_with_prio((callback_job_cb_t)request_resync,
+                                                                               this, NULL, NULL, JOB_PRIO_CRITICAL));
+               }
+               /* Request sync only after the first configuration load */
+               return FALSE;
+       }
+       return TRUE;
+}
+
 METHOD(ha_cache_t, destroy, void,
        private_ha_cache_t *this)
 {
@@ -371,6 +393,9 @@ ha_cache_t *ha_cache_create(ha_kernel_t *kernel, ha_socket_t *socket,
 
        INIT(this,
                .public = {
+                       .listener = {
+                               .alert = _alert_hook,
+                       },
                        .cache = _cache,
                        .delete = _delete_,
                        .resync = _resync,
@@ -381,14 +406,8 @@ ha_cache_t *ha_cache_create(ha_kernel_t *kernel, ha_socket_t *socket,
                .socket = socket,
                .cache = hashtable_create(hashtable_hash_ptr, hashtable_equals_ptr, 8),
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
+               .sync = sync,
        );
 
-       if (sync)
-       {
-               /* request a resync as soon as we are up */
-               lib->scheduler->schedule_job(lib->scheduler, (job_t*)
-                       callback_job_create_with_prio((callback_job_cb_t)request_resync,
-                                                                       this, NULL, NULL, JOB_PRIO_CRITICAL), 1);
-       }
        return &this->public;
 }
index 5e3936a20b04b92fdfb9b284b688eb82f483a7e7..3b022966623c3556ecbbba6b03bccd791f4e2a86 100644 (file)
@@ -36,6 +36,11 @@ typedef struct ha_cache_t ha_cache_t;
  */
 struct ha_cache_t {
 
+       /**
+        * Implements listener interface to catch reload events
+        */
+       listener_t listener;
+
        /**
         * Cache an IKE specific message.
         *
index a58377babbbdfc2272defd7dad42b8ff5a52ba68..ec3da0f2e973a248b4c900a52d3149fbf5f4b534 100644 (file)
@@ -107,6 +107,7 @@ static bool plugin_cb(private_ha_plugin_t *this,
                charon->bus->add_listener(charon->bus, &this->segments->listener);
                charon->bus->add_listener(charon->bus, &this->ike->listener);
                charon->bus->add_listener(charon->bus, &this->child->listener);
+               charon->bus->add_listener(charon->bus, &this->cache->listener);
                charon->attributes->add_provider(charon->attributes,
                                                                                 &this->attr->provider);
        }
@@ -117,6 +118,7 @@ static bool plugin_cb(private_ha_plugin_t *this,
                charon->bus->remove_listener(charon->bus, &this->segments->listener);
                charon->bus->remove_listener(charon->bus, &this->ike->listener);
                charon->bus->remove_listener(charon->bus, &this->child->listener);
+               charon->bus->remove_listener(charon->bus, &this->cache->listener);
        }
        return TRUE;
 }