RADIUS: Share a single function for generating session IDs

There is no need to maintain three copies of this functionality even if
it is currently implemented as a single function call.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2016-02-06 16:27:52 +02:00
parent 2cbc6ffb3a
commit 1fc63fe299
4 changed files with 21 additions and 21 deletions

View File

@ -379,13 +379,8 @@ void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta)
int accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta)
{
/*
* Acct-Session-Id should be globally and temporarily unique.
* A high quality random number is required therefore.
* This could be be improved by switching to a GUID.
*/
return os_get_random((u8 *) &sta->acct_session_id,
sizeof(sta->acct_session_id));
return radius_gen_session_id((u8 *) &sta->acct_session_id,
sizeof(sta->acct_session_id));
}
@ -454,13 +449,8 @@ static void accounting_report_state(struct hostapd_data *hapd, int on)
*/
int accounting_init(struct hostapd_data *hapd)
{
/*
* Acct-Session-Id should be globally and temporarily unique.
* A high quality random number is required therefore.
* This could be be improved by switching to a GUID.
*/
if (os_get_random((u8 *) &hapd->acct_session_id,
sizeof(hapd->acct_session_id)) < 0)
if (radius_gen_session_id((u8 *) &hapd->acct_session_id,
sizeof(hapd->acct_session_id)) < 0)
return -1;
if (radius_client_register(hapd->radius, RADIUS_ACCT,

View File

@ -866,16 +866,13 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr,
sm->radius_cui = wpabuf_alloc_copy(radius_cui,
os_strlen(radius_cui));
/*
* Acct-Multi-Session-Id should be globally and temporarily unique.
* A high quality random number is required therefore.
* This could be be improved by switching to a GUID.
*/
if (os_get_random((u8 *) &sm->acct_multi_session_id,
sizeof(sm->acct_multi_session_id)) < 0) {
#ifndef CONFIG_NO_RADIUS
if (radius_gen_session_id((u8 *) &sm->acct_multi_session_id,
sizeof(sm->acct_multi_session_id)) < 0) {
eapol_auth_free(sm);
return NULL;
}
#endif /* CONFIG_NO_RADIUS */
return sm;
}

View File

@ -1656,3 +1656,14 @@ u8 radius_msg_find_unlisted_attr(struct radius_msg *msg, u8 *attrs)
return 0;
}
int radius_gen_session_id(u8 *id, size_t len)
{
/*
* Acct-Session-Id and Acct-Multi-Session-Id should be globally and
* temporarily unique. A high quality random number is required
* therefore. This could be be improved by switching to a GUID.
*/
return os_get_random(id, len);
}

View File

@ -319,4 +319,6 @@ int radius_copy_class(struct radius_class_data *dst,
u8 radius_msg_find_unlisted_attr(struct radius_msg *msg, u8 *attrs);
int radius_gen_session_id(u8 *id, size_t len);
#endif /* RADIUS_H */