Moved CHILD_SA initiate task creation to protocol specific task manager
authorMartin Willi <martin@revosec.ch>
Mon, 19 Dec 2011 13:15:21 +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 8d52fdc..c177a7d 100644 (file)
@@ -1080,8 +1080,6 @@ METHOD(ike_sa_t, initiate, status_t,
        private_ike_sa_t *this, child_cfg_t *child_cfg, u_int32_t reqid,
        traffic_selector_t *tsi, traffic_selector_t *tsr)
 {
-       task_t *task;
-
        if (this->state == IKE_CREATED)
        {
                resolve_hosts(this);
@@ -1118,23 +1116,8 @@ METHOD(ike_sa_t, initiate, status_t,
 #endif /* ME */
        {
                /* normal IKE_SA with CHILD_SA */
-               if (this->version == IKEV2)
-               {
-                       task = (task_t*)child_create_create(&this->public, child_cfg, FALSE,
-                                                                                               tsi, tsr);
-                       if (reqid)
-                       {
-                               child_create_t *child_create = (child_create_t*)task;
-                               child_create->use_reqid(child_create, reqid);
-                       }
-               }
-               else
-               {
-                       task = (task_t*)quick_mode_create(&this->public, child_cfg,
-                                                                                         tsi, tsr);
-               }
-               this->task_manager->queue_task(this->task_manager, task);
-
+               this->task_manager->queue_child(this->task_manager, child_cfg, reqid,
+                                                                               tsi, tsr);
 #ifdef ME
                if (this->peer_cfg->get_mediated_by(this->peer_cfg))
                {
index e8399e4..d42f63f 100644 (file)
@@ -1021,6 +1021,13 @@ METHOD(task_manager_t, queue_ike, void,
        queue_task(this, (task_t*)isakmp_natd_create(this->ike_sa, TRUE));
 }
 
+METHOD(task_manager_t, queue_child, void,
+       private_task_manager_t *this, child_cfg_t *cfg, u_int32_t reqid,
+       traffic_selector_t *tsi, traffic_selector_t *tsr)
+{
+       queue_task(this, (task_t*)quick_mode_create(this->ike_sa, cfg, tsi, tsr));
+}
+
 METHOD(task_manager_t, queue_dpd, void,
        private_task_manager_t *this)
 {
@@ -1104,6 +1111,7 @@ task_manager_v1_t *task_manager_v1_create(ike_sa_t *ike_sa)
                                .process_message = _process_message,
                                .queue_task = _queue_task,
                                .queue_ike = _queue_ike,
+                               .queue_child = _queue_child,
                                .queue_dpd = _queue_dpd,
                                .initiate = _initiate,
                                .retransmit = _retransmit,
index d28562b..cfc5454 100644 (file)
@@ -1200,6 +1200,20 @@ METHOD(task_manager_t, queue_ike, void,
 #endif /* ME */
 }
 
+METHOD(task_manager_t, queue_child, void,
+       private_task_manager_t *this, child_cfg_t *cfg, u_int32_t reqid,
+       traffic_selector_t *tsi, traffic_selector_t *tsr)
+{
+       child_create_t *task;
+
+       task = child_create_create(this->ike_sa, cfg, FALSE, tsi, tsr);
+       if (reqid)
+       {
+               task->use_reqid(task, reqid);
+       }
+       queue_task(this, &task->task);
+}
+
 METHOD(task_manager_t, queue_dpd, void,
        private_task_manager_t *this)
 {
@@ -1325,6 +1339,7 @@ task_manager_v2_t *task_manager_v2_create(ike_sa_t *ike_sa)
                                .process_message = _process_message,
                                .queue_task = _queue_task,
                                .queue_ike = _queue_ike,
+                               .queue_child = _queue_child,
                                .queue_dpd = _queue_dpd,
                                .initiate = _initiate,
                                .retransmit = _retransmit,
index 6a388e4..d4a8eeb 100644 (file)
@@ -130,6 +130,17 @@ struct task_manager_t {
        void (*queue_ike)(task_manager_t *this);
 
        /**
+        * Queue CHILD_SA establishing tasks.
+        *
+        * @param cfg                   CHILD_SA config to establish
+        * @param reqid                 reqid to use for CHILD_SA
+        * @param tsi                   initiator traffic selector, if packet-triggered
+        * @param tsr                   responder traffic selector, if packet-triggered
+        */
+       void (*queue_child)(task_manager_t *this, child_cfg_t *cfg, u_int32_t reqid,
+                                               traffic_selector_t *tsi, traffic_selector_t *tsr);
+
+       /**
         * Queue liveness checking tasks.
         */
        void (*queue_dpd)(task_manager_t *this);