ike: Maintain per-IKE_SA CHILD_SAs in the global CHILD_SA manager
[strongswan.git] / src / libcharon / processing / jobs / inactivity_job.c
index 55fc009..1977339 100644 (file)
@@ -51,11 +51,11 @@ METHOD(job_t, destroy, void,
        free(this);
 }
 
        free(this);
 }
 
-METHOD(job_t, execute, void,
+METHOD(job_t, execute, job_requeue_t,
        private_inactivity_job_t *this)
 {
        ike_sa_t *ike_sa;
        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->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
                                                                                                        this->reqid, TRUE);
@@ -73,12 +73,13 @@ METHOD(job_t, execute, void,
                {
                        if (child_sa->get_reqid(child_sa) == this->reqid)
                        {
                {
                        if (child_sa->get_reqid(child_sa) == this->reqid)
                        {
-                               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)
                                {
 
                                if (diff >= this->timeout)
                                {
@@ -87,9 +88,7 @@ METHOD(job_t, execute, void,
                                }
                                else
                                {
                                }
                                else
                                {
-                                       lib->scheduler->schedule_job(lib->scheduler,
-                                                       &this->public.job_interface, this->timeout - diff);
-                                       rescheduled = TRUE;
+                                       reschedule = this->timeout - diff;
                                }
                        }
                        children++;
                                }
                        }
                        children++;
@@ -121,10 +120,11 @@ METHOD(job_t, execute, void,
                        charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
                }
        }
                        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,
 }
 
 METHOD(job_t, get_priority, job_priority_t,
@@ -156,4 +156,3 @@ inactivity_job_t *inactivity_job_create(u_int32_t reqid, u_int32_t timeout,
 
        return &this->public;
 }
 
        return &this->public;
 }
-