Invert check to delete unestablished IKE_SAs to not delete them once established
[strongswan.git] / src / libcharon / processing / jobs / delete_ike_sa_job.c
index dffd08b..468c9ef 100644 (file)
@@ -41,19 +41,15 @@ struct private_delete_ike_sa_job_t {
 };
 
 
-/**
- * Implements job_t.destroy.
- */
-static void destroy(private_delete_ike_sa_job_t *this)
+METHOD(job_t, destroy, void,
+       private_delete_ike_sa_job_t *this)
 {
        this->ike_sa_id->destroy(this->ike_sa_id);
        free(this);
 }
 
-/**
- * Implementation of job_t.execute.
- */
-static void execute(private_delete_ike_sa_job_t *this)
+METHOD(job_t, execute, void,
+       private_delete_ike_sa_job_t *this)
 {
        ike_sa_t *ike_sa;
 
@@ -80,8 +76,8 @@ static void execute(private_delete_ike_sa_job_t *this)
                }
                else
                {
-                       /* destroy only if not ESTABLISHED */
-                       if (ike_sa->get_state(ike_sa) == IKE_ESTABLISHED)
+                       /* destroy IKE_SA did not complete connecting phase */
+                       if (ike_sa->get_state(ike_sa) != IKE_CONNECTING)
                        {
                                charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
                        }
@@ -102,15 +98,18 @@ static void execute(private_delete_ike_sa_job_t *this)
 delete_ike_sa_job_t *delete_ike_sa_job_create(ike_sa_id_t *ike_sa_id,
                                                                                          bool delete_if_established)
 {
-       private_delete_ike_sa_job_t *this = malloc_thing(private_delete_ike_sa_job_t);
-
-       /* interface functions */
-       this->public.job_interface.execute = (void (*) (job_t *)) execute;
-       this->public.job_interface.destroy = (void (*)(job_t *)) destroy;;
+       private_delete_ike_sa_job_t *this;
 
-       /* private variables */
-       this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
-       this->delete_if_established = delete_if_established;
+       INIT(this,
+               .public = {
+                       .job_interface = {
+                               .execute = _execute,
+                               .destroy = _destroy,
+                       },
+               },
+               .ike_sa_id = ike_sa_id->clone(ike_sa_id),
+               .delete_if_established = delete_if_established,
+       );
 
        return &(this->public);
 }