Accounting Bugs

Gunter Burchardt gbur
Thu Jan 29 04:02:14 PST 2004


Hello,

The third patch for today is for accouting. There are several bugs
sending accouting information sent to a radius accouting server in
hostapd.

1. Accouting-Reguests with Status-Type=Start were send more than one
times during one session. (Reauth of a station)

2. Accouting-Requests with Status-Type=Stop were send with wrong
connection data in some cases, for example if a station disassociates.
When a idle timeout accurs everything works fine. 

3. Accouting-Stop will send without a previous start packed. assoc ->
auth failed -> disassoc

I wrote a patch which correct all the things. This patch is for the cvs
version 0.2.0. It would be nice if somebody could commit it and/or give
me write access to the cvs :).

regard
gunter
-------------- next part --------------
diff -urN hostap-0.2.0.old/hostapd/accounting.c hostap-0.2.0/hostapd/accounting.c
--- hostap-0.2.0.old/hostapd/accounting.c	2003-11-09 06:14:06.000000000 +0100
+++ hostap-0.2.0/hostapd/accounting.c	2004-01-29 12:32:03.000000000 +0100
@@ -149,20 +149,27 @@
 void accounting_sta_start(hostapd *hapd, struct sta_info *sta)
 {
 	struct radius_msg *msg;
+	
+	/* don't start a session already started */
+	if(sta->session_started == 0)
+	{
+		time(&sta->acct_session_start);
 
-	time(&sta->acct_session_start);
+		if (!hapd->conf->acct_server)
+			return;
 
-	if (!hapd->conf->acct_server)
-		return;
+		if (sta->acct_interim_interval) {
+			eloop_register_timeout(sta->acct_interim_interval, 0,
+					       accounting_interim_update, hapd, sta);
+		}
 
-	if (sta->acct_interim_interval) {
-		eloop_register_timeout(sta->acct_interim_interval, 0,
-				       accounting_interim_update, hapd, sta);
-	}
+		msg = accounting_msg(hapd, sta, RADIUS_ACCT_STATUS_TYPE_START);
+		if (msg)
+			radius_client_send(hapd, msg, RADIUS_ACCT);
 
-	msg = accounting_msg(hapd, sta, RADIUS_ACCT_STATUS_TYPE_START);
-	if (msg)
-		radius_client_send(hapd, msg, RADIUS_ACCT);
+		/* mark session as started */
+		sta->session_started = 1;
+	}
 }
 
 
@@ -237,14 +244,20 @@
 
 void accounting_sta_interim(hostapd *hapd, struct sta_info *sta)
 {
-	accounting_sta_report(hapd, sta, 0);
+        if(sta->session_started)
+        {
+		accounting_sta_report(hapd, sta, 0);
+	}
 }
 
 
 void accounting_sta_stop(hostapd *hapd, struct sta_info *sta)
 {
-	accounting_sta_report(hapd, sta, 1);
-	eloop_cancel_timeout(accounting_interim_update, hapd, sta);
+        if(sta->session_started)
+        {
+		accounting_sta_report(hapd, sta, 1);
+		eloop_cancel_timeout(accounting_interim_update, hapd, sta);
+	}
 }
 
 
diff -urN hostap-0.2.0.old/hostapd/ap.h hostap-0.2.0/hostapd/ap.h
--- hostap-0.2.0.old/hostapd/ap.h	2003-11-09 06:14:06.000000000 +0100
+++ hostap-0.2.0/hostapd/ap.h	2004-01-29 12:31:54.000000000 +0100
@@ -58,6 +58,7 @@
 
 	u32 acct_session_id_lo;
 	time_t acct_session_start;
+	int session_started;
 	int acct_terminate_cause; /* Acct-Terminate-Cause */
 	int acct_interim_interval; /* Acct-Interim-Interval */
 
diff -urN hostap-0.2.0.old/hostapd/ieee802_11.c hostap-0.2.0/hostapd/ieee802_11.c
--- hostap-0.2.0.old/hostapd/ieee802_11.c	2003-11-30 03:43:55.000000000 +0100
+++ hostap-0.2.0/hostapd/ieee802_11.c	2004-01-29 12:31:39.000000000 +0100
@@ -785,8 +785,8 @@
 		       HOSTAPD_LEVEL_INFO, "disassociated");
 	sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
 	ieee802_1x_set_port_enabled(hapd, sta, 0);
-	ieee802_1x_free_station(sta);
-	remove_sta(hapd, sta);
+//	ieee802_1x_free_station(sta);
+	ap_free_sta(hapd, sta);
 }
 
 
@@ -829,8 +829,8 @@
 		       HOSTAPD_LEVEL_DEBUG, "deauthenticated");
 	sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
 	ieee802_1x_set_port_enabled(hapd, sta, 0);
-	ieee802_1x_free_station(sta);
-	remove_sta(hapd, sta);
+//	ieee802_1x_free_station(sta);
+	ap_free_sta(hapd, sta);
 }
 
 
diff -urN hostap-0.2.0.old/hostapd/sta_info.c hostap-0.2.0/hostapd/sta_info.c
--- hostap-0.2.0.old/hostapd/sta_info.c	2003-09-28 19:25:45.000000000 +0200
+++ hostap-0.2.0/hostapd/sta_info.c	2004-01-29 12:31:39.000000000 +0100
@@ -243,7 +243,7 @@
 	case STA_DISASSOC:
 		sta->flags &= ~WLAN_STA_ASSOC;
 		ieee802_1x_set_port_enabled(hapd, sta, 0);
-		ieee802_1x_free_station(sta);
+//		ieee802_1x_free_station(sta);
 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
 			       HOSTAPD_LEVEL_INFO, "disassociated due to "
 			       "inactivity");



More information about the Hostap mailing list