use time_monotonic() instead of time() for statistics and time difference calculations

This commit is contained in:
Martin Willi
2009-08-31 18:00:28 +02:00
parent de5784452b
commit 6180a55852
13 changed files with 65 additions and 42 deletions
+1 -1
View File
@@ -593,7 +593,7 @@ static status_t install(private_child_sa_t *this, chunk_t encr, chunk_t integ,
inbound ? soft : 0, hard, enc_alg, encr, int_alg, integ,
this->mode, this->ipcomp, cpi, this->encap, update);
now = time(NULL);
now = time_monotonic(NULL);
if (soft)
{
this->rekey_time = now + soft;
+13 -12
View File
@@ -428,7 +428,7 @@ static void send_keepalive(private_ike_sa_t *this)
}
last_out = get_use_time(this, FALSE);
now = time(NULL);
now = time_monotonic(NULL);
diff = now - last_out;
@@ -570,7 +570,7 @@ static status_t send_dpd(private_ike_sa_t *this)
/* check if there was any inbound traffic */
time_t last_in, now;
last_in = get_use_time(this, TRUE);
now = time(NULL);
now = time_monotonic(NULL);
diff = now - last_in;
if (diff >= delay)
{
@@ -632,7 +632,7 @@ static void set_state(private_ike_sa_t *this, ike_sa_state_t state)
u_int32_t t;
/* calculate rekey, reauth and lifetime */
this->stats[STAT_ESTABLISHED] = time(NULL);
this->stats[STAT_ESTABLISHED] = time_monotonic(NULL);
/* schedule rekeying if we have a time which is smaller than
* an already scheduled rekeying */
@@ -895,7 +895,7 @@ static void update_hosts(private_ike_sa_t *this, host_t *me, host_t *other)
static status_t generate_message(private_ike_sa_t *this, message_t *message,
packet_t **packet)
{
this->stats[STAT_OUTBOUND] = time(NULL);
this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
message->set_ike_sa_id(message, this->ike_sa_id);
return message->generate(message,
this->keymat->get_crypter(this->keymat, FALSE),
@@ -1290,7 +1290,7 @@ static status_t process_message(private_ike_sa_t *this, message_t *message)
charon->scheduler->schedule_job(charon->scheduler, job,
HALF_OPEN_IKE_SA_TIMEOUT);
}
this->stats[STAT_INBOUND] = time(NULL);
this->stats[STAT_INBOUND] = time_monotonic(NULL);
/* check if message is trustworthy, and update host information */
if (this->state == IKE_CREATED || this->state == IKE_CONNECTING ||
message->get_exchange_type(message) != IKE_SA_INIT)
@@ -1514,7 +1514,7 @@ static status_t reauth(private_ike_sa_t *this)
#endif /* ME */
)
{
time_t now = time(NULL);
time_t now = time_monotonic(NULL);
DBG1(DBG_IKE, "IKE_SA will timeout in %V",
&now, &this->stats[STAT_DELETE]);
@@ -1668,7 +1668,7 @@ static status_t reestablish(private_ike_sa_t *this)
*/
static status_t retransmit(private_ike_sa_t *this, u_int32_t message_id)
{
this->stats[STAT_OUTBOUND] = time(NULL);
this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
if (this->task_manager->retransmit(this->task_manager, message_id) != SUCCESS)
{
/* send a proper signal to brief interested bus listeners */
@@ -1710,7 +1710,7 @@ static status_t retransmit(private_ike_sa_t *this, u_int32_t message_id)
static void set_auth_lifetime(private_ike_sa_t *this, u_int32_t lifetime)
{
u_int32_t reduction = this->peer_cfg->get_over_time(this->peer_cfg);
u_int32_t reauth_time = time(NULL) + lifetime - reduction;
u_int32_t reauth_time = time_monotonic(NULL) + lifetime - reduction;
if (lifetime < reduction)
{
@@ -1731,8 +1731,9 @@ static void set_auth_lifetime(private_ike_sa_t *this, u_int32_t lifetime)
}
else
{
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, reauthentication already "
"scheduled in %ds", lifetime, this->stats[STAT_REAUTH] - time(NULL));
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, "
"reauthentication already scheduled in %ds", lifetime,
this->stats[STAT_REAUTH] - time_monotonic(NULL));
}
}
@@ -1923,7 +1924,7 @@ static status_t inherit(private_ike_sa_t *this, private_ike_sa_t *other)
/* reauthentication timeout survives a rekeying */
if (other->stats[STAT_REAUTH])
{
time_t reauth, delete, now = time(NULL);
time_t reauth, delete, now = time_monotonic(NULL);
this->stats[STAT_REAUTH] = other->stats[STAT_REAUTH];
reauth = this->stats[STAT_REAUTH] - now;
@@ -2113,7 +2114,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
this->keepalive_interval = lib->settings->get_time(lib->settings,
"charon.keep_alive", KEEPALIVE_INTERVAL);
memset(this->stats, 0, sizeof(this->stats));
this->stats[STAT_INBOUND] = this->stats[STAT_OUTBOUND] = time(NULL);
this->stats[STAT_INBOUND] = this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
this->ike_cfg = NULL;
this->peer_cfg = NULL;
this->my_auth = auth_cfg_create();
+1 -1
View File
@@ -50,7 +50,7 @@ static void add_auth_lifetime(private_ike_auth_lifetime_t *this, message_t *mess
lifetime = this->ike_sa->get_statistic(this->ike_sa, STAT_REAUTH);
if (lifetime)
{
lifetime -= time(NULL);
lifetime -= time_monotonic(NULL);
chunk = chunk_from_thing(lifetime);
*(u_int32_t*)chunk.ptr = htonl(lifetime);
message->add_notify(message, FALSE, AUTH_LIFETIME, chunk);