Add Acct-Session-Id into Access-Request messages

This optional attribute may make it easier to bind together the
Access-Request and Accounting-Request messages. The accounting session
identifier is now generated when the STA associates instead of waiting
for the actual session to start after successfull authentication.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2012-12-18 18:13:31 +02:00
parent 2ec535fd37
commit 8b24861154
4 changed files with 18 additions and 4 deletions

View file

@ -26,8 +26,6 @@
* input/output octets and updates Acct-{Input,Output}-Gigawords. */ * input/output octets and updates Acct-{Input,Output}-Gigawords. */
#define ACCT_DEFAULT_UPDATE_INTERVAL 300 #define ACCT_DEFAULT_UPDATE_INTERVAL 300
static void accounting_sta_get_id(struct hostapd_data *hapd,
struct sta_info *sta);
static void accounting_sta_interim(struct hostapd_data *hapd, static void accounting_sta_interim(struct hostapd_data *hapd,
struct sta_info *sta); struct sta_info *sta);
@ -210,7 +208,6 @@ void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta)
if (sta->acct_session_started) if (sta->acct_session_started)
return; return;
accounting_sta_get_id(hapd, sta);
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
HOSTAPD_LEVEL_INFO, HOSTAPD_LEVEL_INFO,
"starting accounting session %08X-%08X", "starting accounting session %08X-%08X",
@ -377,7 +374,7 @@ void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta)
} }
static void accounting_sta_get_id(struct hostapd_data *hapd, void accounting_sta_get_id(struct hostapd_data *hapd,
struct sta_info *sta) struct sta_info *sta)
{ {
sta->acct_session_id_lo = hapd->acct_session_id_lo++; sta->acct_session_id_lo = hapd->acct_session_id_lo++;

View file

@ -10,6 +10,11 @@
#define ACCOUNTING_H #define ACCOUNTING_H
#ifdef CONFIG_NO_ACCOUNTING #ifdef CONFIG_NO_ACCOUNTING
static inline void accounting_sta_get_id(struct hostapd_data *hapd,
struct sta_info *sta)
{
}
static inline void accounting_sta_start(struct hostapd_data *hapd, static inline void accounting_sta_start(struct hostapd_data *hapd,
struct sta_info *sta) struct sta_info *sta)
{ {
@ -29,6 +34,7 @@ static inline void accounting_deinit(struct hostapd_data *hapd)
{ {
} }
#else /* CONFIG_NO_ACCOUNTING */ #else /* CONFIG_NO_ACCOUNTING */
void accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta);
void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta); void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta);
void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta); void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta);
int accounting_init(struct hostapd_data *hapd); int accounting_init(struct hostapd_data *hapd);

View file

@ -454,6 +454,16 @@ static int add_common_radius_sta_attr(struct hostapd_data *hapd,
return -1; return -1;
} }
if (sta->acct_session_id_hi || sta->acct_session_id_lo) {
os_snprintf(buf, sizeof(buf), "%08X-%08X",
sta->acct_session_id_hi, sta->acct_session_id_lo);
if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
(u8 *) buf, os_strlen(buf))) {
wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
return -1;
}
}
return 0; return 0;
} }

View file

@ -493,6 +493,7 @@ struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
return NULL; return NULL;
} }
sta->acct_interim_interval = hapd->conf->acct_interim_interval; sta->acct_interim_interval = hapd->conf->acct_interim_interval;
accounting_sta_get_id(hapd, sta);
/* initialize STA info data */ /* initialize STA info data */
wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "