Added Radius acct fields in acct stop request (#8120)

This commit is contained in:
Matteo Biscosi 2023-12-19 13:48:56 +00:00
parent 8051475c9a
commit 16010e01e7
7 changed files with 65 additions and 26 deletions

View file

@ -30,7 +30,6 @@ function radius_handler.accountingStart(name, username, password)
if accounting_started then
local json = require("dkjson")
local key = string.format(redis_accounting_key, name)
local user_data = {
name = name,
@ -50,7 +49,7 @@ end
-- @brief Handles the Radius accounting stop request
---@param name string, used to check if name is an accounting going on
---@return boolean, true if the accounting went well, false otherwise and the stop was called
function radius_handler.accountingStop(name, bytes_sent, bytes_rcvd, packets_sent, packets_rcvd)
function radius_handler.accountingStop(name, terminate_cause, bytes_sent, bytes_rcvd, packets_sent, packets_rcvd)
if not radius_handler.isAccountingEnabled() then
return true
end
@ -58,7 +57,18 @@ function radius_handler.accountingStop(name, bytes_sent, bytes_rcvd, packets_sen
local is_accounting_on, user_data = radius_handler.isAccountingRequested(name)
if is_accounting_on then
interface.radiusAccountingStop(user_data.username --[[ Username ]] , user_data.session_id, bytes_sent, bytes_rcvd, packets_sent, packets_rcvd)
-- Get the first ip used by the mac
local first_host = {}
local mac_hosts = interface.getMacHosts(name) or {}
if table.len(mac_hosts) > 0 then
for _, h in pairsByKeys(mac_hosts, asc) do
first_host = h
break
end
end
interface.radiusAccountingStop(user_data.username --[[ Username ]], user_data.session_id, name --[[ MAC Address]],
first_host["ip"] --[[ First IP Address ]], bytes_sent, bytes_rcvd, packets_sent, packets_rcvd, terminate_cause)
ntop.delCache(string.format(redis_accounting_key, name))
end
end
@ -88,8 +98,8 @@ function radius_handler.accountingUpdate(name, info)
if not is_accounting_ok then
-- An accounting stop has to be sent, the allowed data for name
-- are expired, requesting stop
radius_handler.accountingStop(user_data.username, bytes_sent, bytes_rcvd, packets_sent, packets_rcvd)
local termination_cause = 3 -- Lost service
radius_handler.accountingStop(user_data.username, termination_cause, bytes_sent, bytes_rcvd, packets_sent, packets_rcvd)
res = false
end
end