kernel-interface: Raise mapping event with a proto/SPI/dst tuple
[strongswan.git] / src / libcharon / processing / jobs / inactivity_job.c
index 251b9ab..f0f90ee 100644 (file)
@@ -30,9 +30,9 @@ struct private_inactivity_job_t {
        inactivity_job_t public;
 
        /**
-        * Reqid of CHILD_SA to check
+        * Unique CHILD_SA identifier to check
         */
-       u_int32_t reqid;
+       u_int32_t id;
 
        /**
         * Inactivity timeout
@@ -51,14 +51,14 @@ METHOD(job_t, destroy, void,
        free(this);
 }
 
-METHOD(job_t, execute, void,
+METHOD(job_t, execute, job_requeue_t,
        private_inactivity_job_t *this)
 {
        ike_sa_t *ike_sa;
-       bool rescheduled = FALSE;
+       u_int32_t reschedule = 0;
 
-       ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
-                                                                                                       this->reqid, TRUE);
+       ike_sa = charon->child_sa_manager->checkout_by_id(charon->child_sa_manager,
+                                                                                                         this->id, NULL);
        if (ike_sa)
        {
                enumerator_t *enumerator;
@@ -69,16 +69,17 @@ METHOD(job_t, execute, void,
                status_t status = SUCCESS;
 
                enumerator = ike_sa->create_child_sa_enumerator(ike_sa);
-               while (enumerator->enumerate(enumerator, (void**)&child_sa))
+               while (enumerator->enumerate(enumerator, &child_sa))
                {
-                       if (child_sa->get_reqid(child_sa) == this->reqid)
+                       if (child_sa->get_unique_id(child_sa) == this->id)
                        {
-                               time_t in, out, diff;
+                               time_t in, out, install, diff;
 
-                               child_sa->get_usestats(child_sa, TRUE, &in, NULL);
-                               child_sa->get_usestats(child_sa, FALSE, &out, NULL);
+                               child_sa->get_usestats(child_sa, TRUE, &in, NULL, NULL);
+                               child_sa->get_usestats(child_sa, FALSE, &out, NULL, NULL);
+                               install = child_sa->get_installtime(child_sa);
 
-                               diff = time_monotonic(NULL) - max(in, out);
+                               diff = time_monotonic(NULL) - max(max(in, out), install);
 
                                if (diff >= this->timeout)
                                {
@@ -87,9 +88,7 @@ METHOD(job_t, execute, void,
                                }
                                else
                                {
-                                       lib->scheduler->schedule_job(lib->scheduler,
-                                                       &this->public.job_interface, this->timeout - diff);
-                                       rescheduled = TRUE;
+                                       reschedule = this->timeout - diff;
                                }
                        }
                        children++;
@@ -108,7 +107,7 @@ METHOD(job_t, execute, void,
                        {
                                DBG1(DBG_JOB, "deleting CHILD_SA after %d seconds "
                                         "of inactivity", this->timeout);
-                               status = ike_sa->delete_child_sa(ike_sa, proto, delete);
+                               status = ike_sa->delete_child_sa(ike_sa, proto, delete, FALSE);
                        }
                }
                if (status == DESTROY_ME)
@@ -121,10 +120,11 @@ METHOD(job_t, execute, void,
                        charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
                }
        }
-       if (!rescheduled)
+       if (reschedule)
        {
-               destroy(this);
+               return JOB_RESCHEDULE(reschedule);
        }
+       return JOB_REQUEUE_NONE;
 }
 
 METHOD(job_t, get_priority, job_priority_t,
@@ -136,7 +136,7 @@ METHOD(job_t, get_priority, job_priority_t,
 /**
  * See header
  */
-inactivity_job_t *inactivity_job_create(u_int32_t reqid, u_int32_t timeout,
+inactivity_job_t *inactivity_job_create(u_int32_t unique_id, u_int32_t timeout,
                                                                                bool close_ike)
 {
        private_inactivity_job_t *this;
@@ -149,11 +149,10 @@ inactivity_job_t *inactivity_job_create(u_int32_t reqid, u_int32_t timeout,
                                .destroy = _destroy,
                        },
                },
-               .reqid = reqid,
+               .id = unique_id,
                .timeout = timeout,
                .close_ike = close_ike,
        );
 
        return &this->public;
 }
-