ikev1: Don't queue more than one mode config or XAuth task
authorTobias Brunner <tobias@strongswan.org>
Thu, 2 Oct 2014 10:28:37 +0000 (12:28 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 7 Oct 2014 11:45:01 +0000 (13:45 +0200)
At the time we reset an IKE_SA (e.g. when re-authenticating a not yet
established SA due to a roaming event) such tasks might already be queued
by one of the phase 1 tasks.  If the SA is initiated again another task will
get queued by the phase 1 task.  This results in e.g. multiple mode config
requests, which most gateways will have problems with.

src/libcharon/sa/ikev1/task_manager_v1.c

index 97812a5..2dd393b 100644 (file)
@@ -1593,13 +1593,6 @@ METHOD(task_manager_t, process_message, status_t,
        return SUCCESS;
 }
 
-METHOD(task_manager_t, queue_task, void,
-       private_task_manager_t *this, task_t *task)
-{
-       DBG2(DBG_IKE, "queueing %N task", task_type_names, task->get_type(task));
-       this->queued_tasks->insert_last(this->queued_tasks, task);
-}
-
 /**
  * Check if a given task has been queued already
  */
@@ -1622,6 +1615,28 @@ static bool has_queued(private_task_manager_t *this, task_type_t type)
        return found;
 }
 
+METHOD(task_manager_t, queue_task, void,
+       private_task_manager_t *this, task_t *task)
+{
+       task_type_t type = task->get_type(task);
+
+       switch (type)
+       {
+               case TASK_MODE_CONFIG:
+               case TASK_XAUTH:
+                       if (has_queued(this, type))
+                       {
+                               task->destroy(task);
+                               return;
+                       }
+                       break;
+               default:
+                       break;
+       }
+       DBG2(DBG_IKE, "queueing %N task", task_type_names, task->get_type(task));
+       this->queued_tasks->insert_last(this->queued_tasks, task);
+}
+
 METHOD(task_manager_t, queue_ike, void,
        private_task_manager_t *this)
 {