Browse Source

Simplified RADIUS accounting id usage

Changed accounting_sta_start() to call accounting_sta_get_id()
internally in accounting.c so that external callers do not need to do
anything to allocate unique accounting id. When starting a new session,
a unique identifier is needed anyway, so no need to keep these
operations separate.
Jouni Malinen 16 years ago
parent
commit
2fc98d02c1

+ 17 - 2
hostapd/accounting.c

@@ -1,6 +1,6 @@
 /*
  * hostapd / RADIUS Accounting
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -32,6 +32,9 @@
 const char *radius_mode_txt(struct hostapd_data *hapd);
 int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta);
 
+static void accounting_sta_get_id(struct hostapd_data *hapd,
+				  struct sta_info *sta);
+
 
 static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
 					  struct sta_info *sta,
@@ -234,6 +237,12 @@ void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta)
 	if (sta->acct_session_started)
 		return;
 
+	accounting_sta_get_id(hapd, sta);
+	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
+		       HOSTAPD_LEVEL_INFO,
+		       "starting accounting session %08X-%08X",
+		       sta->acct_session_id_hi, sta->acct_session_id_lo);
+
 	time(&sta->acct_session_start);
 	sta->last_rx_bytes = sta->last_tx_bytes = 0;
 	sta->acct_input_gigawords = sta->acct_output_gigawords = 0;
@@ -370,12 +379,18 @@ void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta)
 	if (sta->acct_session_started) {
 		accounting_sta_report(hapd, sta, 1);
 		eloop_cancel_timeout(accounting_interim_update, hapd, sta);
+		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
+			       HOSTAPD_LEVEL_INFO,
+			       "stopped accounting session %08X-%08X",
+			       sta->acct_session_id_hi,
+			       sta->acct_session_id_lo);
 		sta->acct_session_started = 0;
 	}
 }
 
 
-void accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta)
+static void accounting_sta_get_id(struct hostapd_data *hapd,
+				  struct sta_info *sta)
 {
 	sta->acct_session_id_lo = hapd->acct_session_id_lo++;
 	if (hapd->acct_session_id_lo == 0) {

+ 0 - 1
hostapd/accounting.h

@@ -18,7 +18,6 @@
 void accounting_sta_start(struct hostapd_data *hapd, struct sta_info *sta);
 void accounting_sta_interim(struct hostapd_data *hapd, struct sta_info *sta);
 void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta);
-void accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta);
 int accounting_init(struct hostapd_data *hapd);
 void accounting_deinit(struct hostapd_data *hapd);
 int accounting_reconfig(struct hostapd_data *hapd,

+ 0 - 1
hostapd/ctrl_iface.c

@@ -213,7 +213,6 @@ static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
 		return -1;
 
 	hostapd_new_assoc_sta(hapd, sta, 0);
-	accounting_sta_get_id(hapd, sta);
 	return 0;
 }
 

+ 0 - 1
hostapd/driver_madwifi.c

@@ -831,7 +831,6 @@ madwifi_new_sta(struct madwifi_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
 		memset(drv->acct_mac, 0, ETH_ALEN);
 		memset(&drv->acct_data, 0, sizeof(drv->acct_data));
 	}
-	accounting_sta_get_id(hapd, sta);
 
 	if (hapd->conf->wpa) {
 		if (madwifi_process_wpa_ie(drv, sta))

+ 0 - 1
hostapd/driver_test.c

@@ -410,7 +410,6 @@ static int test_driver_new_sta(struct test_driver_data *drv,
 		if (sta == NULL)
 			return -1;
 	}
-	accounting_sta_get_id(hapd, sta);
 
 	if (hapd->conf->wpa) {
 		if (ie == NULL || ielen == 0) {

+ 0 - 1
hostapd/driver_wired.c

@@ -85,7 +85,6 @@ static void wired_possible_new_sta(struct hostapd_data *hapd, u8 *addr)
 	sta = ap_sta_add(hapd, addr);
 	if (sta) {
 		hostapd_new_assoc_sta(hapd, sta, 0);
-		accounting_sta_get_id(hapd, sta);
 	} else {
 		wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
 			   MAC2STR(addr));

+ 2 - 4
hostapd/ieee802_11.c

@@ -1461,13 +1461,11 @@ static void handle_assoc_cb(struct hostapd_data *hapd,
 	/* Stop previous accounting session, if one is started, and allocate
 	 * new session id for the new session. */
 	accounting_sta_stop(hapd, sta);
-	accounting_sta_get_id(hapd, sta);
 
 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
 		       HOSTAPD_LEVEL_INFO,
-		       "associated (aid %d, accounting session %08X-%08X)",
-		       sta->aid, sta->acct_session_id_hi,
-		       sta->acct_session_id_lo);
+		       "associated (aid %d)",
+		       sta->aid);
 
 	if (sta->flags & WLAN_STA_ASSOC)
 		new_assoc = 0;

+ 0 - 1
hostapd/ieee802_1x.c

@@ -767,7 +767,6 @@ void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
 		sta->acct_terminate_cause =
 			RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
 		accounting_sta_stop(hapd, sta);
-		accounting_sta_get_id(hapd, sta);
 		sta->eapol_sm->eapolLogoff = TRUE;
 		sta->eapol_sm->dot1xAuthEapolLogoffFramesRx++;
 		break;