Deactivate all active segments before shutting down
authorMartin Willi <martin@strongswan.org>
Tue, 22 Sep 2009 15:10:25 +0000 (17:10 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 7 Apr 2010 11:55:14 +0000 (13:55 +0200)
src/charon/plugins/ha_sync/ha_sync_plugin.c
src/charon/plugins/ha_sync/ha_sync_segments.c
src/charon/plugins/ha_sync/ha_sync_segments.h

index 4fed2e3..d6fa6be 100644 (file)
@@ -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);
 
index f264904..3bfc959 100644 (file)
@@ -265,6 +265,27 @@ static void resync(private_ha_sync_segments_t *this, u_int segment)
 }
 
 /**
+ * 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.
  */
 static void destroy(private_ha_sync_segments_t *this)
@@ -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;
index d1f2fc0..98332a5 100644 (file)
@@ -46,6 +46,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.
         *
         * @param segment       numerical segment to takeover, 0 for all