cleaned up and fixed DPD handling code
[strongswan.git] / src / charon / sa / task_manager.c
index 061b023..be35cea 100644 (file)
@@ -207,6 +207,13 @@ static status_t build_request(private_task_manager_t *this)
        status_t status;
        exchange_type_t exchange = 0;
        
+       if (this->initiating.type != EXCHANGE_TYPE_UNDEFINED)
+       {
+               DBG2(DBG_IKE, "delaying task initiation, exchange in progress");
+               /* do not initiate if we already have a message in the air */
+               return SUCCESS;
+       }
+       
        if (this->active_tasks->get_count(this->active_tasks) == 0)
        {
                DBG2(DBG_IKE, "activating new tasks");
@@ -379,6 +386,7 @@ static status_t process_response(private_task_manager_t *this,
        iterator->destroy(iterator);
        
        this->initiating.mid++;
+       this->initiating.type = EXCHANGE_TYPE_UNDEFINED;
 
        return build_request(this);
 }
@@ -425,6 +433,13 @@ static status_t build_response(private_task_manager_t *this,
            }
        }
        iterator->destroy(iterator);
+       
+       /* remove resonder SPI if IKE_SA_INIT failed */
+       if (delete && exchange == IKE_SA_INIT)
+       {
+               ike_sa_id_t *id = this->ike_sa->get_id(this->ike_sa);
+               id->set_responder_spi(id, 0);
+       }
 
        /* message complete, send it */
        DESTROY_IF(this->responding.packet);
@@ -470,10 +485,10 @@ static status_t process_request(private_task_manager_t *this,
                        this->passive_tasks->insert_last(this->passive_tasks, task);
                        task = (task_t*)ike_cert_create(this->ike_sa, FALSE);
                        this->passive_tasks->insert_last(this->passive_tasks, task);
-                       task = (task_t*)ike_config_create(this->ike_sa, NULL);
-                       this->passive_tasks->insert_last(this->passive_tasks, task);
                        task = (task_t*)ike_auth_create(this->ike_sa, FALSE);
                        this->passive_tasks->insert_last(this->passive_tasks, task);
+                       task = (task_t*)ike_config_create(this->ike_sa, NULL);
+                       this->passive_tasks->insert_last(this->passive_tasks, task);
                        task = (task_t*)child_create_create(this->ike_sa, NULL);
                        this->passive_tasks->insert_last(this->passive_tasks, task);
                        break;
@@ -724,7 +739,7 @@ static void destroy(private_task_manager_t *this)
                                SIG(IKE_UP_FAILED, "establishing IKE_SA failed");
                                break;
                        case IKE_DELETE:
-                               SIG(IKE_DOWN_FAILED, "deleteing IKE_SA properly failed");
+                               SIG(IKE_DOWN_FAILED, "IKE_SA deleted");
                                break;
                        case IKE_REKEY:
                                SIG(IKE_REKEY_FAILED, "rekeying IKE_SA failed");
@@ -771,6 +786,7 @@ task_manager_t *task_manager_create(ike_sa_t *ike_sa)
        this->initiating.packet = NULL;
        this->responding.mid = 0;
        this->initiating.mid = 0;
+       this->initiating.type = EXCHANGE_TYPE_UNDEFINED;
        this->queued_tasks = linked_list_create();
        this->active_tasks = linked_list_create();
        this->passive_tasks = linked_list_create();