From: Martin Willi Date: Tue, 11 Feb 2014 09:09:08 +0000 (+0100) Subject: bus: Add a handle_vips() hook invoked after handling configuration attributes X-Git-Tag: 5.2.0rc1~54^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eef7427b0fe9de11d6cf877aea267692426ee35b;p=thirdparty%2Fstrongswan.git bus: Add a handle_vips() hook invoked after handling configuration attributes 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. --- diff --git a/src/libcharon/bus/bus.c b/src/libcharon/bus/bus.c index bc080d1c0b..d467c3320f 100644 --- a/src/libcharon/bus/bus.c +++ b/src/libcharon/bus/bus.c @@ -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(), diff --git a/src/libcharon/bus/bus.h b/src/libcharon/bus/bus.h index 4a0ac68e36..1d708c5a51 100644 --- a/src/libcharon/bus/bus.h +++ b/src/libcharon/bus/bus.h @@ -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. */ diff --git a/src/libcharon/bus/listeners/listener.h b/src/libcharon/bus/listeners/listener.h index 9eee722641..abcc765e59 100644 --- a/src/libcharon/bus/listeners/listener.h +++ b/src/libcharon/bus/listeners/listener.h @@ -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_ @}*/ diff --git a/src/libcharon/sa/ike_sa.c b/src/libcharon/sa/ike_sa.c index 8c7817520a..c338cdaefa 100644 --- a/src/libcharon/sa/ike_sa.c +++ b/src/libcharon/sa/ike_sa.c @@ -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) diff --git a/src/libcharon/sa/ikev1/tasks/mode_config.c b/src/libcharon/sa/ikev1/tasks/mode_config.c index 9a33f49f6c..94026b9af3 100644 --- a/src/libcharon/sa/ikev1/tasks/mode_config.c +++ b/src/libcharon/sa/ikev1/tasks/mode_config.c @@ -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, diff --git a/src/libcharon/sa/ikev2/tasks/ike_config.c b/src/libcharon/sa/ikev2/tasks/ike_config.c index 89b15ea5f1..da06e2a367 100644 --- a/src/libcharon/sa/ikev2/tasks/ike_config.c +++ b/src/libcharon/sa/ikev2/tasks/ike_config.c @@ -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;