]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
AP: Use monotonic time for STA accounting
authorJohannes Berg <johannes.berg@intel.com>
Mon, 16 Dec 2013 20:08:22 +0000 (21:08 +0100)
committerJouni Malinen <j@w1.fi>
Tue, 24 Dec 2013 04:57:53 +0000 (06:57 +0200)
For type-safety, make sta->acct_session_start a struct os_reltime
and then use monotonic time for accounting. For RADIUS reporting,
continue to use wall clock time as specified by RFC 2869, but for
the session time use monotonic time.

Interestingly, RFC 2869 doesn't specify a timezone, so the value
is somewhat arbitrary.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>

src/ap/accounting.c
src/ap/ieee802_1x.c
src/ap/sta_info.h

index a1f67f0cb1584e1080bb81a9268332b3e6fc3361..96bfce33ad0f7197ce437467d6262f2a6f74a65c 100644 (file)
@@ -202,7 +202,6 @@ static void accounting_interim_update(void *eloop_ctx, void *timeout_ctx)
 void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta)
 {
        struct radius_msg *msg;
-       struct os_time t;
        int interval;
 
        if (sta->acct_session_started)
@@ -213,8 +212,7 @@ void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta)
                       "starting accounting session %08X-%08X",
                       sta->acct_session_id_hi, sta->acct_session_id_lo);
 
-       os_get_time(&t);
-       sta->acct_session_start = t.sec;
+       os_get_reltime(&sta->acct_session_start);
        sta->last_rx_bytes = sta->last_tx_bytes = 0;
        sta->acct_input_gigawords = sta->acct_output_gigawords = 0;
        hostapd_drv_sta_clear_stats(hapd, sta->addr);
@@ -244,6 +242,7 @@ static void accounting_sta_report(struct hostapd_data *hapd,
        struct radius_msg *msg;
        int cause = sta->acct_terminate_cause;
        struct hostap_sta_driver_data data;
+       struct os_reltime now_r, diff;
        struct os_time now;
        u32 gigawords;
 
@@ -258,9 +257,11 @@ static void accounting_sta_report(struct hostapd_data *hapd,
                return;
        }
 
+       os_get_reltime(&now_r);
        os_get_time(&now);
+       os_reltime_sub(&now_r, &sta->acct_session_start, &diff);
        if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_SESSION_TIME,
-                                      now.sec - sta->acct_session_start)) {
+                                      diff.sec)) {
                wpa_printf(MSG_INFO, "Could not add Acct-Session-Time");
                goto fail;
        }
index 4465d12eac304c695b8f0f1cc9c945f6b6dec91a..2ce2ed994f4a936ba6d70ba7580eb2ec864797e2 100644 (file)
@@ -1951,7 +1951,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
 {
        int len = 0, ret;
        struct eapol_state_machine *sm = sta->eapol_sm;
-       struct os_time t;
+       struct os_reltime diff;
 
        if (sm == NULL)
                return 0;
@@ -2066,7 +2066,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
        len += ret;
 
        /* dot1xAuthSessionStatsTable */
-       os_get_time(&t);
+       os_reltime_age(&sta->acct_session_start, &diff);
        ret = os_snprintf(buf + len, buflen - len,
                          /* TODO: dot1xAuthSessionOctetsRx */
                          /* TODO: dot1xAuthSessionOctetsTx */
@@ -2081,7 +2081,7 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
                          (wpa_key_mgmt_wpa_ieee8021x(
                                   wpa_auth_sta_key_mgmt(sta->wpa_sm))) ?
                          1 : 2,
-                         (unsigned int) (t.sec - sta->acct_session_start),
+                         (unsigned int) diff.sec,
                          sm->identity);
        if (ret < 0 || (size_t) ret >= buflen - len)
                return len;
index ea3fe40731e1c6beb6c4c38e2b069ba2d418adb1..c696bd5e42084b95c71ffec57c247eaa58c37db1 100644 (file)
@@ -78,7 +78,7 @@ struct sta_info {
 
        u32 acct_session_id_hi;
        u32 acct_session_id_lo;
-       time_t acct_session_start;
+       struct os_reltime acct_session_start;
        int acct_session_started;
        int acct_terminate_cause; /* Acct-Terminate-Cause */
        int acct_interim_interval; /* Acct-Interim-Interval */