Moved liveness checking task creation to protocol specific task manager
authorMartin Willi <martin@revosec.ch>
Mon, 19 Dec 2011 12:49:09 +0000 (13:49 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 20 Mar 2012 16:31:27 +0000 (17:31 +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 0ee4324..da7ff43 100644 (file)
@@ -603,26 +603,9 @@ METHOD(ike_sa_t, send_dpd, status_t,
                if (!delay || diff >= delay)
                {
                        /* to long ago, initiate dead peer detection */
-                       task_t *task;
-                       ike_mobike_t *mobike;
-
-                       if (supports_extension(this, EXT_MOBIKE) &&
-                               has_condition(this, COND_NAT_HERE))
-                       {
-                               /* use mobike enabled DPD to detect NAT mapping changes */
-                               mobike = ike_mobike_create(&this->public, TRUE);
-                               mobike->dpd(mobike);
-                               task = &mobike->task;
-                       }
-                       else
-                       {
-                               task = (task_t*)ike_dpd_create(TRUE);
-                       }
-                       diff = 0;
                        DBG1(DBG_IKE, "sending DPD request");
-
-                       this->task_manager->queue_task(this->task_manager, task);
-                       this->task_manager->initiate(this->task_manager);
+                       this->task_manager->queue_dpd(this->task_manager);
+                       diff = 0;
                }
        }
        /* recheck in "interval" seconds */
@@ -631,7 +614,7 @@ METHOD(ike_sa_t, send_dpd, status_t,
                job = (job_t*)send_dpd_job_create(this->ike_sa_id);
                lib->scheduler->schedule_job(lib->scheduler, job, delay - diff);
        }
-       return SUCCESS;
+       return this->task_manager->initiate(this->task_manager);
 }
 
 METHOD(ike_sa_t, get_state, ike_sa_state_t,
index 8e4aa74..5c1c727 100644 (file)
@@ -1011,6 +1011,12 @@ METHOD(task_manager_t, queue_task, void,
        this->queued_tasks->insert_last(this->queued_tasks, task);
 }
 
+METHOD(task_manager_t, queue_dpd, void,
+       private_task_manager_t *this)
+{
+       /* TODO-IKEv1: DPD checking */
+}
+
 METHOD(task_manager_t, adopt_tasks, void,
        private_task_manager_t *this, task_manager_t *other_public)
 {
@@ -1087,6 +1093,7 @@ task_manager_v1_t *task_manager_v1_create(ike_sa_t *ike_sa)
                        .task_manager = {
                                .process_message = _process_message,
                                .queue_task = _queue_task,
+                               .queue_dpd = _queue_dpd,
                                .initiate = _initiate,
                                .retransmit = _retransmit,
                                .incr_mid = _incr_mid,
index cce9551..aa0fb42 100644 (file)
@@ -1176,6 +1176,26 @@ METHOD(task_manager_t, queue_task, void,
        this->queued_tasks->insert_last(this->queued_tasks, task);
 }
 
+METHOD(task_manager_t, queue_dpd, void,
+       private_task_manager_t *this)
+{
+       ike_mobike_t *mobike;
+
+       if (this->ike_sa->supports_extension(this->ike_sa, EXT_MOBIKE) &&
+               this->ike_sa->has_condition(this->ike_sa, COND_NAT_HERE))
+       {
+               /* use mobike enabled DPD to detect NAT mapping changes */
+               mobike = ike_mobike_create(this->ike_sa, TRUE);
+               mobike->dpd(mobike);
+               queue_task(this, &mobike->task);
+       }
+       else
+       {
+               queue_task(this, (task_t*)ike_dpd_create(TRUE));
+       }
+}
+
+
 METHOD(task_manager_t, adopt_tasks, void,
        private_task_manager_t *this, task_manager_t *other_public)
 {
@@ -1280,6 +1300,7 @@ task_manager_v2_t *task_manager_v2_create(ike_sa_t *ike_sa)
                        .task_manager = {
                                .process_message = _process_message,
                                .queue_task = _queue_task,
+                               .queue_dpd = _queue_dpd,
                                .initiate = _initiate,
                                .retransmit = _retransmit,
                                .incr_mid = _incr_mid,
index 47b39a6..2ef9041 100644 (file)
@@ -125,6 +125,11 @@ struct task_manager_t {
        void (*queue_task) (task_manager_t *this, task_t *task);
 
        /**
+        * Queue liveness checking tasks.
+        */
+       void (*queue_dpd)(task_manager_t *this);
+
+       /**
         * Retransmit a request if it hasn't been acknowledged yet.
         *
         * A return value of INVALID_STATE means that the message was already