Avoid queueing more than one retry initiate job.
authorTobias Brunner <tobias@strongswan.org>
Fri, 25 May 2012 14:09:31 +0000 (16:09 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 30 May 2012 13:32:52 +0000 (15:32 +0200)
src/libcharon/processing/jobs/retry_initiate_job.c
src/libcharon/sa/ike_sa.c
src/libcharon/sa/ike_sa.h

index 11e5739..e6da3e3 100644 (file)
@@ -54,7 +54,7 @@ METHOD(job_t, execute, void,
        }
        else
        {
-               if (ike_sa->initiate(ike_sa, NULL, 0, NULL, NULL) == DESTROY_ME)
+               if (ike_sa->retry_initiate(ike_sa) == DESTROY_ME)
                {
                        charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager,
                                                                                                                ike_sa);
index 93a8ad8..c104ff9 100644 (file)
@@ -223,6 +223,11 @@ struct private_ike_sa_t {
        u_int32_t retry_initiate_interval;
 
        /**
+        * TRUE if a retry_initiate_job has been queued
+        */
+       bool retry_initiate_queued;
+
+       /**
         * Timestamps for this IKE_SA
         */
        u_int32_t stats[STAT_MAX];
@@ -1162,14 +1167,30 @@ METHOD(ike_sa_t, initiate, status_t,
 
        if (defer_initiate)
        {
-               job_t *job = (job_t*)retry_initiate_job_create(this->ike_sa_id);
-               lib->scheduler->schedule_job(lib->scheduler, (job_t*)job,
-                                                                        this->retry_initiate_interval);
+               if (!this->retry_initiate_queued)
+               {
+                       job_t *job = (job_t*)retry_initiate_job_create(this->ike_sa_id);
+                       lib->scheduler->schedule_job(lib->scheduler, (job_t*)job,
+                                                                                this->retry_initiate_interval);
+                       this->retry_initiate_queued = TRUE;
+               }
                return SUCCESS;
        }
+       this->retry_initiate_queued = FALSE;
        return this->task_manager->initiate(this->task_manager);
 }
 
+METHOD(ike_sa_t, retry_initiate, status_t,
+       private_ike_sa_t *this)
+{
+       if (this->retry_initiate_queued)
+       {
+               this->retry_initiate_queued = FALSE;
+               return initiate(this, NULL, 0, NULL, NULL);
+       }
+       return SUCCESS;
+}
+
 METHOD(ike_sa_t, process_message, status_t,
        private_ike_sa_t *this, message_t *message)
 {
@@ -2089,6 +2110,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id, bool initiator,
                        .set_statistic = _set_statistic,
                        .process_message = _process_message,
                        .initiate = _initiate,
+                       .retry_initiate = _retry_initiate,
                        .get_ike_cfg = _get_ike_cfg,
                        .set_ike_cfg = _set_ike_cfg,
                        .get_peer_cfg = _get_peer_cfg,
index a3c3de8..5b2eb4e 100644 (file)
@@ -695,6 +695,15 @@ struct ike_sa_t {
                                                  traffic_selector_t *tsr);
 
        /**
+        * Retry initiation of this IKE_SA after it got deferred previously.
+        *
+        * @return
+        *                                              - SUCCESS if initiation deferred or started
+        *                                              - DESTROY_ME if initiation failed
+        */
+       status_t (*retry_initiate) (ike_sa_t *this);
+
+       /**
         * Initiates the deletion of an IKE_SA.
         *
         * Sends a delete message to the remote peer and waits for