]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
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 4fed2e302084d056f7400d5f5d59cf43dc1d07e9..d6fa6be1f7b9c0ced1f577bd382ec1ffa5772065 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 f264904471f1eddb73f114f8516975cf7b0e49f8..3bfc9592a10d224a3de030e51169210ff1cb1767 100644 (file)
@@ -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;
index d1f2fc01ac33c2ba51e60fea13247685b85b8a6f..98332a5f2a072c5b189522117cf71c9d06a9a62e 100644 (file)
@@ -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.
         *