ike: Implement adopt_child_tasks() outside task managers

This commit is contained in:
Tobias Brunner 2018-11-28 15:21:44 +01:00
parent f536f6477d
commit 5e97a5e64b
4 changed files with 27 additions and 104 deletions

View 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,

View 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,

View 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,

View File

@ -227,13 +227,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.
*