AP: Use monotonic time for PMKSA cache

Since the PMKSA cache only uses relative time, use the monotonic time
functions instead of wall time to be correct when the clock jumps.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2013-12-16 21:08:23 +01:00 committed by Jouni Malinen
parent 0fc545aee5
commit dd4e32bae4

View file

@ -91,9 +91,9 @@ void pmksa_cache_free_entry(struct rsn_pmksa_cache *pmksa,
static void pmksa_cache_expire(void *eloop_ctx, void *timeout_ctx) static void pmksa_cache_expire(void *eloop_ctx, void *timeout_ctx)
{ {
struct rsn_pmksa_cache *pmksa = eloop_ctx; struct rsn_pmksa_cache *pmksa = eloop_ctx;
struct os_time now; struct os_reltime now;
os_get_time(&now); os_get_reltime(&now);
while (pmksa->pmksa && pmksa->pmksa->expiration <= now.sec) { while (pmksa->pmksa && pmksa->pmksa->expiration <= now.sec) {
wpa_printf(MSG_DEBUG, "RSN: expired PMKSA cache entry for " wpa_printf(MSG_DEBUG, "RSN: expired PMKSA cache entry for "
MACSTR, MAC2STR(pmksa->pmksa->spa)); MACSTR, MAC2STR(pmksa->pmksa->spa));
@ -107,12 +107,12 @@ static void pmksa_cache_expire(void *eloop_ctx, void *timeout_ctx)
static void pmksa_cache_set_expiration(struct rsn_pmksa_cache *pmksa) static void pmksa_cache_set_expiration(struct rsn_pmksa_cache *pmksa)
{ {
int sec; int sec;
struct os_time now; struct os_reltime now;
eloop_cancel_timeout(pmksa_cache_expire, pmksa, NULL); eloop_cancel_timeout(pmksa_cache_expire, pmksa, NULL);
if (pmksa->pmksa == NULL) if (pmksa->pmksa == NULL)
return; return;
os_get_time(&now); os_get_reltime(&now);
sec = pmksa->pmksa->expiration - now.sec; sec = pmksa->pmksa->expiration - now.sec;
if (sec < 0) if (sec < 0)
sec = 0; sec = 0;
@ -241,7 +241,7 @@ pmksa_cache_auth_add(struct rsn_pmksa_cache *pmksa,
struct eapol_state_machine *eapol, int akmp) struct eapol_state_machine *eapol, int akmp)
{ {
struct rsn_pmksa_cache_entry *entry, *pos; struct rsn_pmksa_cache_entry *entry, *pos;
struct os_time now; struct os_reltime now;
if (pmk_len > PMK_LEN) if (pmk_len > PMK_LEN)
return NULL; return NULL;
@ -253,7 +253,7 @@ pmksa_cache_auth_add(struct rsn_pmksa_cache *pmksa,
entry->pmk_len = pmk_len; entry->pmk_len = pmk_len;
rsn_pmkid(pmk, pmk_len, aa, spa, entry->pmkid, rsn_pmkid(pmk, pmk_len, aa, spa, entry->pmkid,
wpa_key_mgmt_sha256(akmp)); wpa_key_mgmt_sha256(akmp));
os_get_time(&now); os_get_reltime(&now);
entry->expiration = now.sec; entry->expiration = now.sec;
if (session_timeout > 0) if (session_timeout > 0)
entry->expiration += session_timeout; entry->expiration += session_timeout;