ike: Keep track of send keepalive jobs to avoid scheduling more than one per IKE_SA

This commit is contained in:
Tobias Brunner
2016-03-03 17:15:37 +01:00
parent 34f7d3b7ae
commit efd7fa7be1
3 changed files with 24 additions and 11 deletions
@@ -54,7 +54,7 @@ METHOD(job_t, execute, job_requeue_t,
this->ike_sa_id); this->ike_sa_id);
if (ike_sa) if (ike_sa)
{ {
ike_sa->send_keepalive(ike_sa); ike_sa->send_keepalive(ike_sa, TRUE);
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa); charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
} }
return JOB_REQUEUE_NONE; return JOB_REQUEUE_NONE;
+19 -8
View File
@@ -238,6 +238,11 @@ struct private_ike_sa_t {
*/ */
u_int32_t keepalive_interval; u_int32_t keepalive_interval;
/**
* The schedueld keep alive job, if any
*/
send_keepalive_job_t *keepalive_job;
/** /**
* interval for retries during initiation (e.g. if DNS resolution failed), * interval for retries during initiation (e.g. if DNS resolution failed),
* 0 to disable (default) * 0 to disable (default)
@@ -482,11 +487,14 @@ METHOD(ike_sa_t, set_message_id, void,
} }
METHOD(ike_sa_t, send_keepalive, void, METHOD(ike_sa_t, send_keepalive, void,
private_ike_sa_t *this) private_ike_sa_t *this, bool scheduled)
{ {
send_keepalive_job_t *job;
time_t last_out, now, diff; time_t last_out, now, diff;
if (scheduled)
{
this->keepalive_job = NULL;
}
if (!this->keepalive_interval || this->state == IKE_PASSIVE) if (!this->keepalive_interval || this->state == IKE_PASSIVE)
{ /* keepalives disabled either by configuration or for passive IKE_SAs */ { /* keepalives disabled either by configuration or for passive IKE_SAs */
return; return;
@@ -517,10 +525,13 @@ METHOD(ike_sa_t, send_keepalive, void,
charon->sender->send_no_marker(charon->sender, packet); charon->sender->send_no_marker(charon->sender, packet);
diff = 0; diff = 0;
} }
job = send_keepalive_job_create(this->ike_sa_id); if (!this->keepalive_job)
lib->scheduler->schedule_job(lib->scheduler, (job_t*)job, {
this->keepalive_job = send_keepalive_job_create(this->ike_sa_id);
lib->scheduler->schedule_job(lib->scheduler, (job_t*)this->keepalive_job,
this->keepalive_interval - diff); this->keepalive_interval - diff);
} }
}
METHOD(ike_sa_t, get_ike_cfg, ike_cfg_t*, METHOD(ike_sa_t, get_ike_cfg, ike_cfg_t*,
private_ike_sa_t *this) private_ike_sa_t *this)
@@ -566,7 +577,7 @@ METHOD(ike_sa_t, set_condition, void,
case COND_NAT_HERE: case COND_NAT_HERE:
DBG1(DBG_IKE, "local host is behind NAT, sending keep alives"); DBG1(DBG_IKE, "local host is behind NAT, sending keep alives");
this->conditions |= COND_NAT_ANY; this->conditions |= COND_NAT_ANY;
send_keepalive(this); send_keepalive(this, FALSE);
break; break;
case COND_NAT_THERE: case COND_NAT_THERE:
DBG1(DBG_IKE, "remote host is behind NAT"); DBG1(DBG_IKE, "remote host is behind NAT");
@@ -594,7 +605,7 @@ METHOD(ike_sa_t, set_condition, void,
has_condition(this, COND_NAT_FAKE)); has_condition(this, COND_NAT_FAKE));
break; break;
case COND_STALE: case COND_STALE:
send_keepalive(this); send_keepalive(this, FALSE);
break; break;
default: default:
break; break;
@@ -755,7 +766,7 @@ METHOD(ike_sa_t, set_state, void,
} }
if (keepalives) if (keepalives)
{ {
send_keepalive(this); send_keepalive(this, FALSE);
} }
} }
@@ -2329,7 +2340,7 @@ METHOD(ike_sa_t, inherit_post, void,
this->conditions = other->conditions; this->conditions = other->conditions;
if (this->conditions & COND_NAT_HERE) if (this->conditions & COND_NAT_HERE)
{ {
send_keepalive(this); send_keepalive(this, FALSE);
} }
#ifdef ME #ifdef ME
+3 -1
View File
@@ -837,8 +837,10 @@ struct ike_sa_t {
* *
* To refresh NAT tables in a NAT router between the peers, periodic empty * To refresh NAT tables in a NAT router between the peers, periodic empty
* UDP packets are sent if no other traffic was sent. * UDP packets are sent if no other traffic was sent.
*
* @param scheduled if this is a scheduled keepalive
*/ */
void (*send_keepalive) (ike_sa_t *this); void (*send_keepalive) (ike_sa_t *this, bool scheduled);
/** /**
* Get the keying material of this IKE_SA. * Get the keying material of this IKE_SA.