From 245b062db88254ab0ee230b2fc886d403bf44547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= Date: Tue, 23 May 2023 15:13:22 +0200 Subject: [PATCH] uspot: accounting: fix loop logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When looping through known clients: - removal of client in spotfilter list is checked first - checks for known client existence are redundant by construction Also format the max_total check similarly to the timeout one Signed-off-by: Thibaut VARĂˆNE --- .../uspot/files/usr/share/uspot/accounting.uc | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/feeds/ucentral/uspot/files/usr/share/uspot/accounting.uc b/feeds/ucentral/uspot/files/usr/share/uspot/accounting.uc index 84847b1eb..6cb955dd1 100755 --- a/feeds/ucentral/uspot/files/usr/share/uspot/accounting.uc +++ b/feeds/ucentral/uspot/files/usr/share/uspot/accounting.uc @@ -231,37 +231,33 @@ function accounting(interface) { client_add(interface, mac, payload); for (let mac in clients[interface]) { - if (list[mac].data?.logoff) { - radius_logoff(interface, mac); - client_flush(interface, mac, 'logoff event'); - continue; - } - if (!list[mac] || !list[mac].state) { radius_disconnect(interface, mac); client_remove(interface, mac, 'disconnect event'); continue; } + if (list[mac].data.logoff) { + radius_logoff(interface, mac); + client_flush(interface, mac, 'logoff event'); + continue; + } + if (list[mac].idle > get_idle_timeout(interface, mac)) { - if (clients[interface][mac]) - radius_idle_time(interface, mac); + radius_idle_time(interface, mac); client_remove(interface, mac, 'idle event'); continue; } let timeout = get_session_timeout(interface, mac); if (timeout && ((t - list[mac].data.connect) > timeout)) { - if (clients[interface][mac]) - radius_session_time(interface, mac); + radius_session_time(interface, mac); client_flush(interface, mac, 'session timeout'); continue; } - if (clients[interface][mac].max_total) { - let total = list[mac].bytes_ul + list[mac].bytes_dl; - if (total >= clients[interface][mac].max_total) { - radius_session_time(interface, mac); - client_flush(interface, mac, 'max octets reached'); - } + let maxtotal = +clients[interface][mac].max_total; + if (maxtotal && ((list[mac].bytes_ul + list[mac].bytes_dl) >= maxtotal)) { + radius_session_time(interface, mac); + client_flush(interface, mac, 'max octets reached'); } } }