ike: Implement adopt_child_tasks() outside task managers
authorTobias Brunner <tobias@strongswan.org>
Wed, 28 Nov 2018 14:21:44 +0000 (15:21 +0100)
committerTobias Brunner <tobias@strongswan.org>
Fri, 7 Dec 2018 09:32:12 +0000 (10:32 +0100)
src/libcharon/sa/ike_sa.c
src/libcharon/sa/ikev1/task_manager_v1.c
src/libcharon/sa/ikev2/task_manager_v2.c
src/libcharon/sa/task_manager.h

index cbd1703..3d576a0 100644 (file)
@@ -1996,8 +1996,7 @@ static status_t reestablish_children(private_ike_sa_t *this, ike_sa_t *new,
        /* adopt any active or queued CHILD-creating tasks */
        if (status != DESTROY_ME)
        {
-               task_manager_t *other_tasks = ((private_ike_sa_t*)new)->task_manager;
-               other_tasks->adopt_child_tasks(other_tasks, this->task_manager);
+               new->adopt_child_tasks(new, &this->public);
                if (new->get_state(new) == IKE_CREATED)
                {
                        status = new->initiate(new, NULL, 0, NULL, NULL);
@@ -2745,13 +2744,34 @@ METHOD(ike_sa_t, queue_task_delayed, void,
        this->task_manager->queue_task_delayed(this->task_manager, task, delay);
 }
 
-METHOD(ike_sa_t, adopt_child_tasks, void,
-       private_ike_sa_t *this, ike_sa_t *other_public)
+/**
+ * Migrate and queue child-creating tasks from another IKE_SA
+ */
+static void migrate_child_tasks(private_ike_sa_t *this, ike_sa_t *other,
+                                                               task_queue_t queue)
 {
-       private_ike_sa_t *other = (private_ike_sa_t*)other_public;
+       enumerator_t *enumerator;
+       task_t *task;
 
-       this->task_manager->adopt_child_tasks(this->task_manager,
-                                                                                 other->task_manager);
+       enumerator = other->create_task_enumerator(other, queue);
+       while (enumerator->enumerate(enumerator, &task))
+       {
+               if (task->get_type(task) == TASK_CHILD_CREATE ||
+                       task->get_type(task) == TASK_QUICK_MODE)
+               {
+                       other->remove_task(other, enumerator);
+                       task->migrate(task, &this->public);
+                       queue_task(this, task);
+               }
+       }
+       enumerator->destroy(enumerator);
+}
+
+METHOD(ike_sa_t, adopt_child_tasks, void,
+       private_ike_sa_t *this, ike_sa_t *other)
+{
+       migrate_child_tasks(this, other, TASK_QUEUE_ACTIVE);
+       migrate_child_tasks(this, other, TASK_QUEUE_QUEUED);
 }
 
 METHOD(ike_sa_t, inherit_pre, void,
index 90d623b..f76471e 100644 (file)
@@ -1891,39 +1891,6 @@ METHOD(task_manager_t, adopt_tasks, void,
        }
 }
 
-/**
- * Migrates child-creating tasks from src to dst
- */
-static void migrate_child_tasks(private_task_manager_t *this,
-                                                               linked_list_t *src, linked_list_t *dst)
-{
-       enumerator_t *enumerator;
-       task_t *task;
-
-       enumerator = src->create_enumerator(src);
-       while (enumerator->enumerate(enumerator, &task))
-       {
-               if (task->get_type(task) == TASK_QUICK_MODE)
-               {
-                       src->remove_at(src, enumerator);
-                       task->migrate(task, this->ike_sa);
-                       dst->insert_last(dst, task);
-               }
-       }
-       enumerator->destroy(enumerator);
-}
-
-METHOD(task_manager_t, adopt_child_tasks, void,
-       private_task_manager_t *this, task_manager_t *other_public)
-{
-       private_task_manager_t *other = (private_task_manager_t*)other_public;
-
-       /* move active child tasks from other to this */
-       migrate_child_tasks(this, other->active_tasks, this->queued_tasks);
-       /* do the same for queued tasks */
-       migrate_child_tasks(this, other->queued_tasks, this->queued_tasks);
-}
-
 METHOD(task_manager_t, busy, bool,
        private_task_manager_t *this)
 {
@@ -2114,7 +2081,6 @@ task_manager_v1_t *task_manager_v1_create(ike_sa_t *ike_sa)
                                .get_mid = _get_mid,
                                .reset = _reset,
                                .adopt_tasks = _adopt_tasks,
-                               .adopt_child_tasks = _adopt_child_tasks,
                                .busy = _busy,
                                .create_task_enumerator = _create_task_enumerator,
                                .remove_task = _remove_task,
index a050be6..e9142d7 100644 (file)
@@ -2076,61 +2076,6 @@ METHOD(task_manager_t, adopt_tasks, void,
        }
 }
 
-/**
- * Migrates child-creating tasks from other to this
- */
-static void migrate_child_tasks(private_task_manager_t *this,
-                                                               private_task_manager_t *other,
-                                                               task_queue_t queue)
-{
-       enumerator_t *enumerator;
-       array_t *array;
-       task_t *task;
-
-       switch (queue)
-       {
-               case TASK_QUEUE_ACTIVE:
-                       array = other->active_tasks;
-                       break;
-               case TASK_QUEUE_QUEUED:
-                       array = other->queued_tasks;
-                       break;
-               default:
-                       return;
-       }
-
-       enumerator = array_create_enumerator(array);
-       while (enumerator->enumerate(enumerator, &task))
-       {
-               queued_task_t *queued = NULL;
-
-               if (queue == TASK_QUEUE_QUEUED)
-               {
-                       queued = (queued_task_t*)task;
-                       task = queued->task;
-               }
-               if (task->get_type(task) == TASK_CHILD_CREATE)
-               {
-                       array_remove_at(array, enumerator);
-                       task->migrate(task, this->ike_sa);
-                       queue_task(this, task);
-                       free(queued);
-               }
-       }
-       enumerator->destroy(enumerator);
-}
-
-METHOD(task_manager_t, adopt_child_tasks, void,
-       private_task_manager_t *this, task_manager_t *other_public)
-{
-       private_task_manager_t *other = (private_task_manager_t*)other_public;
-
-       /* move active child tasks from other to this */
-       migrate_child_tasks(this, other, TASK_QUEUE_ACTIVE);
-       /* do the same for queued tasks */
-       migrate_child_tasks(this, other, TASK_QUEUE_QUEUED);
-}
-
 METHOD(task_manager_t, busy, bool,
        private_task_manager_t *this)
 {
@@ -2324,7 +2269,6 @@ task_manager_v2_t *task_manager_v2_create(ike_sa_t *ike_sa)
                                .get_mid = _get_mid,
                                .reset = _reset,
                                .adopt_tasks = _adopt_tasks,
-                               .adopt_child_tasks = _adopt_child_tasks,
                                .busy = _busy,
                                .create_task_enumerator = _create_task_enumerator,
                                .remove_task = _remove_task,
index 442eaa6..c357d50 100644 (file)
@@ -228,13 +228,6 @@ struct task_manager_t {
        void (*adopt_tasks) (task_manager_t *this, task_manager_t *other);
 
        /**
-        * Migrate all active or queued CHILD_SA-creating tasks from other to this.
-        *
-        * @param other                 manager which gives away its tasks
-        */
-       void (*adopt_child_tasks) (task_manager_t *this, task_manager_t *other);
-
-       /**
         * Increment a message ID counter, in- or outbound.
         *
         * If a message is processed outside of the manager, this call increments