Moved IKE_SA initiate task creation to protocol specific task manager
authorMartin Willi <martin@revosec.ch>
Mon, 19 Dec 2011 13:15:02 +0000 (14:15 +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 da7ff43..8d52fdc 100644 (file)
@@ -1099,48 +1099,7 @@ METHOD(ike_sa_t, initiate, status_t,
                }
 
                set_condition(this, COND_ORIGINAL_INITIATOR, TRUE);
-
-               if (this->version == IKEV1)
-               {
-                       task = (task_t*)isakmp_vendor_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)isakmp_cert_pre_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)main_mode_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)isakmp_cert_post_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)isakmp_natd_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-               }
-               else
-               {
-                       task = (task_t*)ike_vendor_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)ike_init_create(&this->public, TRUE, NULL);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)ike_natd_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)ike_cert_pre_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)ike_auth_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)ike_cert_post_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)ike_config_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       task = (task_t*)ike_auth_lifetime_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-                       if (this->peer_cfg->use_mobike(this->peer_cfg))
-                       {
-                               task = (task_t*)ike_mobike_create(&this->public, TRUE);
-                               this->task_manager->queue_task(this->task_manager, task);
-                       }
-#ifdef ME
-                       task = (task_t*)ike_me_create(&this->public, TRUE);
-                       this->task_manager->queue_task(this->task_manager, task);
-#endif /* ME */
-               }
+               this->task_manager->queue_ike(this->task_manager);
        }
 
 #ifdef ME
index 5c1c727..e8399e4 100644 (file)
@@ -1011,6 +1011,16 @@ METHOD(task_manager_t, queue_task, void,
        this->queued_tasks->insert_last(this->queued_tasks, task);
 }
 
+METHOD(task_manager_t, queue_ike, void,
+       private_task_manager_t *this)
+{
+       queue_task(this, (task_t*)isakmp_vendor_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)isakmp_cert_pre_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)main_mode_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)isakmp_cert_post_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)isakmp_natd_create(this->ike_sa, TRUE));
+}
+
 METHOD(task_manager_t, queue_dpd, void,
        private_task_manager_t *this)
 {
@@ -1093,6 +1103,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_ike = _queue_ike,
                                .queue_dpd = _queue_dpd,
                                .initiate = _initiate,
                                .retransmit = _retransmit,
index aa0fb42..d28562b 100644 (file)
@@ -1176,6 +1176,30 @@ METHOD(task_manager_t, queue_task, void,
        this->queued_tasks->insert_last(this->queued_tasks, task);
 }
 
+METHOD(task_manager_t, queue_ike, void,
+       private_task_manager_t *this)
+{
+       peer_cfg_t *peer_cfg;
+
+       queue_task(this, (task_t*)ike_vendor_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)ike_init_create(this->ike_sa, TRUE, NULL));
+       queue_task(this, (task_t*)ike_natd_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)ike_cert_pre_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)ike_auth_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)ike_cert_post_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)ike_config_create(this->ike_sa, TRUE));
+       queue_task(this, (task_t*)ike_auth_lifetime_create(this->ike_sa, TRUE));
+
+       peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa);
+       if (peer_cfg->use_mobike(peer_cfg))
+       {
+               queue_task(this, (task_t*)ike_mobike_create(this->ike_sa, TRUE));
+       }
+#ifdef ME
+       queue_task(this, (task_t*)ike_me_create(this->ike_sa, TRUE));
+#endif /* ME */
+}
+
 METHOD(task_manager_t, queue_dpd, void,
        private_task_manager_t *this)
 {
@@ -1300,6 +1324,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_ike = _queue_ike,
                                .queue_dpd = _queue_dpd,
                                .initiate = _initiate,
                                .retransmit = _retransmit,
index 2ef9041..6a388e4 100644 (file)
@@ -125,6 +125,11 @@ struct task_manager_t {
        void (*queue_task) (task_manager_t *this, task_t *task);
 
        /**
+        * Queue IKE_SA establishing tasks.
+        */
+       void (*queue_ike)(task_manager_t *this);
+
+       /**
         * Queue liveness checking tasks.
         */
        void (*queue_dpd)(task_manager_t *this);