implemented ike_up() bus hook
authorMartin Willi <martin@strongswan.org>
Thu, 9 Jul 2009 11:44:06 +0000 (13:44 +0200)
committerMartin Willi <martin@strongswan.org>
Thu, 9 Jul 2009 13:25:16 +0000 (15:25 +0200)
src/charon/bus/bus.c
src/charon/bus/bus.h
src/charon/sa/tasks/ike_auth.c

index 71b120a..d54aa18 100644 (file)
@@ -514,6 +514,35 @@ static void child_keys(private_bus_t *this, child_sa_t *child_sa,
 }
 
 /**
+ * Implementation of bus_t.ike_updown
+ */
+static void ike_updown(private_bus_t *this, ike_sa_t *ike_sa, bool up)
+{
+       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->ike_updown)
+               {
+                       continue;
+               }
+               entry->calling++;
+               keep = entry->listener->ike_updown(entry->listener, ike_sa, up);
+               entry->calling--;
+               if (!keep)
+               {
+                       unregister_listener(this, entry, enumerator);
+               }
+       }
+       enumerator->destroy(enumerator);
+       this->mutex->unlock(this->mutex);
+}
+
+/**
  * Implementation of bus_t.ike_rekey
  */
 static void ike_rekey(private_bus_t *this, ike_sa_t *old, ike_sa_t *new)
@@ -673,6 +702,7 @@ bus_t *bus_create()
        this->public.message = (void(*)(bus_t*, message_t *message, bool incoming))message;
        this->public.ike_keys = (void(*)(bus_t*, ike_sa_t *ike_sa, diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r, ike_sa_t *rekey))ike_keys;
        this->public.child_keys = (void(*)(bus_t*, child_sa_t *child_sa, diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r))child_keys;
+       this->public.ike_updown = (void(*)(bus_t*, ike_sa_t *ike_sa, bool up))ike_updown;
        this->public.ike_rekey = (void(*)(bus_t*, ike_sa_t *old, ike_sa_t *new))ike_rekey;
        this->public.child_updown = (void(*)(bus_t*, child_sa_t *child_sa, bool up))child_updown;
        this->public.child_rekey = (void(*)(bus_t*, child_sa_t *old, child_sa_t *new))child_rekey;
index 53437f9..67603bf 100644 (file)
@@ -262,6 +262,14 @@ struct bus_t {
                                           chunk_t nonce_i, chunk_t nonce_r);
        
        /**
+        * IKE_SA up/down hook.
+        *
+        * @param ike_sa        IKE_SA coming up/going down
+        * @param up            TRUE for an up event, FALSE for a down event
+        */
+       void (*ike_updown)(bus_t *this, ike_sa_t *ike_sa, bool up);
+       
+       /**
         * IKE_SA rekeying hook.
         *
         * @param old           rekeyed and obsolete IKE_SA
index 8d6cd56..d0b2a7e 100644 (file)
@@ -738,6 +738,7 @@ static status_t build_r(private_ike_auth_t *this, message_t *message)
                         this->ike_sa->get_my_id(this->ike_sa), 
                         this->ike_sa->get_other_host(this->ike_sa),
                         this->ike_sa->get_other_id(this->ike_sa));
+               charon->bus->ike_updown(charon->bus, this->ike_sa, TRUE);
                return SUCCESS;
        }
        return NEED_MORE;
@@ -916,6 +917,7 @@ static status_t process_i(private_ike_auth_t *this, message_t *message)
                         this->ike_sa->get_my_id(this->ike_sa), 
                         this->ike_sa->get_other_host(this->ike_sa),
                         this->ike_sa->get_other_id(this->ike_sa));
+               charon->bus->ike_updown(charon->bus, this->ike_sa, TRUE);
                return SUCCESS;
        }
        return NEED_MORE;