From: Martin Willi Date: Fri, 10 Apr 2015 12:17:55 +0000 (+0200) Subject: ha: Wait for configuration backend to complete loading before starting sync X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ee329960be61cde84b2872294fc16d93c2050a9;p=thirdparty%2Fstrongswan.git ha: Wait for configuration backend to complete loading before starting sync --- diff --git a/src/libcharon/plugins/ha/ha_cache.c b/src/libcharon/plugins/ha/ha_cache.c index 6c1b3471dd..7e8ab9de95 100644 --- a/src/libcharon/plugins/ha/ha_cache.c +++ b/src/libcharon/plugins/ha/ha_cache.c @@ -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; } diff --git a/src/libcharon/plugins/ha/ha_cache.h b/src/libcharon/plugins/ha/ha_cache.h index 5e3936a20b..3b02296662 100644 --- a/src/libcharon/plugins/ha/ha_cache.h +++ b/src/libcharon/plugins/ha/ha_cache.h @@ -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. * diff --git a/src/libcharon/plugins/ha/ha_plugin.c b/src/libcharon/plugins/ha/ha_plugin.c index a58377babb..ec3da0f2e9 100644 --- a/src/libcharon/plugins/ha/ha_plugin.c +++ b/src/libcharon/plugins/ha/ha_plugin.c @@ -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; }