]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
bus: Add a handle_vips() hook invoked after handling configuration attributes
authorMartin Willi <martin@revosec.ch>
Tue, 11 Feb 2014 09:09:08 +0000 (10:09 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 17 Jun 2014 13:14:51 +0000 (15:14 +0200)
Similar to assign_vips() used by a peer assigning virtual IPs to the other peer,
the handle_vips() hook gets invoked on a peers after receiving attributes. On
release of the same attributes the hook gets invoked again.

This is useful to inspect handled attributes, as the ike_updown() hook is
invoked after authentication, when attributes have not been handled yet.

src/libcharon/bus/bus.c
src/libcharon/bus/bus.h
src/libcharon/bus/listeners/listener.h
src/libcharon/sa/ike_sa.c
src/libcharon/sa/ikev1/tasks/mode_config.c
src/libcharon/sa/ikev2/tasks/ike_config.c

index bc080d1c0b47cebd543e7eca99b14384d8b5dd4c..d467c3320fcc57c058d9ddb2dea20080dc45e5f2 100644 (file)
@@ -879,6 +879,33 @@ METHOD(bus_t, assign_vips, void,
        this->mutex->unlock(this->mutex);
 }
 
+METHOD(bus_t, handle_vips, void,
+       private_bus_t *this, ike_sa_t *ike_sa, bool handle)
+{
+       enumerator_t *enumerator;
+       entry_t *entry;
+       bool keep;
+
+       this->mutex->lock(this->mutex);
+       enumerator = this->listeners->create_enumerator(this->listeners);
+       while (enumerator->enumerate(enumerator, &entry))
+       {
+               if (entry->calling || !entry->listener->handle_vips)
+               {
+                       continue;
+               }
+               entry->calling++;
+               keep = entry->listener->handle_vips(entry->listener, ike_sa, handle);
+               entry->calling--;
+               if (!keep)
+               {
+                       unregister_listener(this, entry, enumerator);
+               }
+       }
+       enumerator->destroy(enumerator);
+       this->mutex->unlock(this->mutex);
+}
+
 /**
  * Credential manager hook function to forward bus alerts
  */
@@ -955,6 +982,7 @@ bus_t *bus_create()
                        .authorize = _authorize,
                        .narrow = _narrow,
                        .assign_vips = _assign_vips,
+                       .handle_vips = _handle_vips,
                        .destroy = _destroy,
                },
                .listeners = linked_list_create(),
index 4a0ac68e36a4adfcec40e327e81d83d8fbfff9e7..1d708c5a51222ec25d8f073a706bc1444ce53d8b 100644 (file)
@@ -411,6 +411,14 @@ struct bus_t {
         */
        void (*assign_vips)(bus_t *this, ike_sa_t *ike_sa, bool assign);
 
+       /**
+        * Virtual IP handler hook.
+        *
+        * @param ike_sa        IKE_SA the VIPs/attributes got handled on
+        * @param assign        TRUE after installing attributes, FALSE on release
+        */
+       void (*handle_vips)(bus_t *this, ike_sa_t *ike_sa, bool handle);
+
        /**
         * Destroy the event bus.
         */
index 9eee72264174919fe334384e215337b8b99314e0..abcc765e598151b8b359ed80907c8319f700291a 100644 (file)
@@ -203,6 +203,18 @@ struct listener_t {
         */
        bool (*assign_vips)(listener_t *this, ike_sa_t *ike_sa, bool assign);
 
+       /**
+        * Virtual IP and configuration attribute handler hook.
+        *
+        * This hook gets invoked after virtual IP and other configuration
+        * attributes just got installed or are about to get uninstalled on a peer
+        * receiving them.
+        *
+        * @param ike_sa        IKE_SA the VIPs/attributes are handled on
+        * @param handle        TRUE if handled by IKE_SA, FALSE on release
+        * @return                      TRUE to stay registered, FALSE to unregister
+        */
+       bool (*handle_vips)(listener_t *this, ike_sa_t *ike_sa, bool handle);
 };
 
 #endif /** LISTENER_H_ @}*/
index 8c7817520afa3d63a5d1debb8fa67ac9212c2b35..c338cdaefa7f2be21a2535ae880d6f2be9c623a3 100644 (file)
@@ -2168,6 +2168,7 @@ METHOD(ike_sa_t, destroy, void,
        }
 
        /* remove attributes first, as we pass the IKE_SA to the handler */
+       charon->bus->handle_vips(charon->bus, &this->public, FALSE);
        while (array_remove(this->attributes, ARRAY_TAIL, &entry))
        {
                if (entry.handler)
index 9a33f49f6c00bc26b619f8a6740b08cfe3f8d565..94026b9af34361d469f65b4ab1e8805bcca0b6ee 100644 (file)
@@ -441,6 +441,8 @@ static void install_vips(private_mode_config_t *this)
                }
        }
        enumerator->destroy(enumerator);
+
+       charon->bus->handle_vips(charon->bus, this->ike_sa, TRUE);
 }
 
 METHOD(task_t, process_r, status_t,
index 89b15ea5f10364acb3af587c48d6b1679dec486e..da06e2a36705da34db965475fdc525c7ff71341b 100644 (file)
@@ -446,6 +446,8 @@ METHOD(task_t, process_i, status_t,
                        }
                }
                enumerator->destroy(enumerator);
+
+               charon->bus->handle_vips(charon->bus, this->ike_sa, TRUE);
                return SUCCESS;
        }
        return NEED_MORE;