kernel-interface: Raise mapping event with a proto/SPI/dst tuple
[strongswan.git] / src / libcharon / processing / jobs / delete_child_sa_job.c
index ca55721..0d85883 100644 (file)
@@ -31,11 +31,6 @@ struct private_delete_child_sa_job_t {
        delete_child_sa_job_t public;
 
        /**
-        * reqid of the CHILD_SA
-        */
-       u_int32_t reqid;
-
-       /**
         * protocol of the CHILD_SA (ESP/AH)
         */
        protocol_id_t protocol;
@@ -44,57 +39,73 @@ struct private_delete_child_sa_job_t {
         * inbound SPI of the CHILD_SA
         */
        u_int32_t spi;
+
+       /**
+        * SA destination address
+        */
+       host_t *dst;
+
+       /**
+        * Delete for an expired CHILD_SA
+        */
+       bool expired;
 };
 
-/**
- * Implementation of job_t.destroy.
- */
-static void destroy(private_delete_child_sa_job_t *this)
+METHOD(job_t, destroy, void,
+       private_delete_child_sa_job_t *this)
 {
+       this->dst->destroy(this->dst);
        free(this);
 }
 
-/**
- * Implementation of job_t.execute.
- */
-static void execute(private_delete_child_sa_job_t *this)
+METHOD(job_t, execute, job_requeue_t,
+       private_delete_child_sa_job_t *this)
 {
        ike_sa_t *ike_sa;
 
-       ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
-                                                                                                       this->reqid, TRUE);
+       ike_sa = charon->child_sa_manager->checkout(charon->child_sa_manager,
+                                                                       this->protocol, this->spi, this->dst, NULL);
        if (ike_sa == NULL)
        {
-               DBG1(DBG_JOB, "CHILD_SA with reqid %d not found for delete",
-                        this->reqid);
+               DBG1(DBG_JOB, "CHILD_SA %N/0x%08x/%H not found for delete",
+                        protocol_id_names, this->protocol, htonl(this->spi), this->dst);
        }
        else
        {
-               ike_sa->delete_child_sa(ike_sa, this->protocol, this->spi);
+               ike_sa->delete_child_sa(ike_sa, this->protocol, this->spi, this->expired);
 
                charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
        }
-       destroy(this);
+       return JOB_REQUEUE_NONE;
+}
+
+METHOD(job_t, get_priority, job_priority_t,
+       private_delete_child_sa_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
 }
 
 /*
  * Described in header
  */
-delete_child_sa_job_t *delete_child_sa_job_create(u_int32_t reqid,
-                                                                                                 protocol_id_t protocol,
-                                                                                                 u_int32_t spi)
+delete_child_sa_job_t *delete_child_sa_job_create(protocol_id_t protocol,
+                                                                       u_int32_t spi, host_t *dst, bool expired)
 {
-       private_delete_child_sa_job_t *this = malloc_thing(private_delete_child_sa_job_t);
-
-       /* interface functions */
-       this->public.job_interface.execute = (void (*) (job_t *)) execute;
-       this->public.job_interface.destroy = (void (*)(job_t*)) destroy;
-
-       /* private variables */
-       this->reqid = reqid;
-       this->protocol = protocol;
-       this->spi = spi;
+       private_delete_child_sa_job_t *this;
+
+       INIT(this,
+               .public = {
+                       .job_interface = {
+                               .execute = _execute,
+                               .get_priority = _get_priority,
+                               .destroy = _destroy,
+                       },
+               },
+               .protocol = protocol,
+               .spi = spi,
+               .dst = dst->clone(dst),
+               .expired = expired,
+       );
 
        return &this->public;
 }
-