diff mbox

Event-Timestamp should be sent for all Accounting-Request packets

Message ID CAGnO3doQwO1dg6vNoZdOD9c1e7TNczCJq3mYDCWbSfHXGwD23Q@mail.gmail.com
State Accepted
Headers show

Commit Message

Nick Lowe Jan. 24, 2016, 11:38 a.m. UTC
Attached without the whitespace broken...

Comments

Jouni Malinen Feb. 5, 2016, 11:44 p.m. UTC | #1
On Sun, Jan 24, 2016 at 11:38:40AM +0000, Nick Lowe wrote:
> Subject: [PATCH 3/3] Event-Timestamp should be sent for all Accounting-Request
>  packets and only after the system clock has a sane value, not where there's a
>  value close to the Unix time epoch.

Thanks, applied.
diff mbox

Patch

From 4084657ef56246294f043855255e1479a5ca9f92 Mon Sep 17 00:00:00 2001
From: Nick Lowe <nick.lowe@lugatech.com>
Date: Sun, 24 Jan 2016 10:45:29 +0000
Subject: [PATCH 3/3] Event-Timestamp should be sent for all Accounting-Request
 packets and only after the system clock has a sane value, not where there's a
 value close to the Unix time epoch.

Signed-off-by: Nick Lowe <nick.lowe@lugatech.com>
---
 src/ap/accounting.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/ap/accounting.c b/src/ap/accounting.c
index e585b78..09cd431 100644
--- a/src/ap/accounting.c
+++ b/src/ap/accounting.c
@@ -41,6 +41,7 @@  static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
 	size_t len;
 	int i;
 	struct wpabuf *b;
+	struct os_time now;
 
 	msg = radius_msg_new(RADIUS_CODE_ACCOUNTING_REQUEST,
 			     radius_client_get_id(hapd->radius));
@@ -157,6 +158,15 @@  static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
 		}
 	}
 
+	os_get_time(&now);
+	if (now.sec > 1000000000) {
+		if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_EVENT_TIMESTAMP,
+						   now.sec)) {
+			wpa_printf(MSG_INFO, "Could not add Event-Timestamp");
+			goto fail;
+		}
+	}
+
 	return msg;
 
  fail:
@@ -259,7 +269,6 @@  static void accounting_sta_report(struct hostapd_data *hapd,
 	int cause = sta->acct_terminate_cause;
 	struct hostap_sta_driver_data data;
 	struct os_reltime now_r, diff;
-	struct os_time now;
 	u32 gigawords;
 
 	if (!hapd->conf->radius->acct_server)
@@ -274,7 +283,6 @@  static void accounting_sta_report(struct hostapd_data *hapd,
 	}
 
 	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,
 				       diff.sec)) {
@@ -331,12 +339,6 @@  static void accounting_sta_report(struct hostapd_data *hapd,
 		}
 	}
 
-	if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_EVENT_TIMESTAMP,
-				       now.sec)) {
-		wpa_printf(MSG_INFO, "Could not add Event-Timestamp");
-		goto fail;
-	}
-
 	if (eloop_terminated())
 		cause = RADIUS_ACCT_TERMINATE_CAUSE_ADMIN_REBOOT;
 
-- 
2.5.0