From: Martin Willi Date: Tue, 22 Sep 2009 15:10:25 +0000 (+0200) Subject: Deactivate all active segments before shutting down X-Git-Tag: 4.4.0~80 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=310498f3deaa020a0f7e2b03fba0a5ba9d344da1;p=thirdparty%2Fstrongswan.git Deactivate all active segments before shutting down --- diff --git a/src/charon/plugins/ha_sync/ha_sync_plugin.c b/src/charon/plugins/ha_sync/ha_sync_plugin.c index 4fed2e3020..d6fa6be1f7 100644 --- a/src/charon/plugins/ha_sync/ha_sync_plugin.c +++ b/src/charon/plugins/ha_sync/ha_sync_plugin.c @@ -84,6 +84,7 @@ struct private_ha_sync_plugin_t { static void destroy(private_ha_sync_plugin_t *this) { DESTROY_IF(this->ctl); + 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); this->ike->destroy(this->ike); @@ -183,6 +184,7 @@ plugin_t *plugin_create() this->dispatcher = ha_sync_dispatcher_create(this->socket, this->segments); this->ike = ha_sync_ike_create(this->socket, this->tunnel); this->child = ha_sync_child_create(this->socket, this->tunnel); + 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); diff --git a/src/charon/plugins/ha_sync/ha_sync_segments.c b/src/charon/plugins/ha_sync/ha_sync_segments.c index f264904471..3bfc9592a1 100644 --- a/src/charon/plugins/ha_sync/ha_sync_segments.c +++ b/src/charon/plugins/ha_sync/ha_sync_segments.c @@ -264,6 +264,27 @@ static void resync(private_ha_sync_segments_t *this, u_int segment) list->destroy(list); } +/** + * Implementation of listener_t.alert + */ +static bool alert_hook(private_ha_sync_segments_t *this, ike_sa_t *ike_sa, + alert_t alert, va_list args) +{ + if (alert == ALERT_SHUTDOWN_SIGNAL) + { + int i; + + for (i = 0; i < SEGMENTS_MAX; i++) + { + if (this->active & SEGMENTS_BIT(i)) + { + deactivate(this, i, TRUE); + } + } + } + return TRUE; +} + /** * Implementation of ha_sync_segments_t.destroy. */ @@ -282,6 +303,8 @@ ha_sync_segments_t *ha_sync_segments_create(ha_sync_socket_t *socket, { private_ha_sync_segments_t *this = malloc_thing(private_ha_sync_segments_t); + memset(&this->public.listener, 0, sizeof(listener_t)); + this->public.listener.alert = (bool(*)(listener_t*, ike_sa_t *, alert_t, va_list))alert_hook; this->public.activate = (void(*)(ha_sync_segments_t*, u_int segment,bool))activate; this->public.deactivate = (void(*)(ha_sync_segments_t*, u_int segment,bool))deactivate; this->public.resync = (void(*)(ha_sync_segments_t*, u_int segment))resync; diff --git a/src/charon/plugins/ha_sync/ha_sync_segments.h b/src/charon/plugins/ha_sync/ha_sync_segments.h index d1f2fc01ac..98332a5f2a 100644 --- a/src/charon/plugins/ha_sync/ha_sync_segments.h +++ b/src/charon/plugins/ha_sync/ha_sync_segments.h @@ -45,6 +45,11 @@ typedef u_int16_t segment_mask_t; */ struct ha_sync_segments_t { + /** + * Implements listener interface to catch daemon shutdown. + */ + listener_t listener; + /** * Activate a set of IKE_SAs identified by a segment. *