Aug 01 2007
Gigawords Support in Freeradius
Some people using Radius for accounting don’t know there are counters limits. Values defined in the protocol are stored in 32 bit fields meaning you will never go any higher than 4294967296 bits, that is fairly more than 4GB. If a session stays up for days, there are good chances that the counter resets to 0 and some traffic will go missing. Yet, some extensions have been added to the protocol to support bigger amount of traffic. Since Freeradius 1.1.7, Gigawords with a Mysql backend are supported by default. It is highly recommended to upgrade to the last version. While upgrading, do not forget to update your database schema as in mysql.sql changing AcctInputOctets and AcctOutputOctets from 32 to 64 bits. This article deals with those having Freeradius prior to 1.1.7.
Before You Start
We assume you have a working Freeradius setup with Mysql to store your data. We also assume that your Network Access Server (NAS) supports gigawords as defined in RFC2869. It is usually the case for Cisco routers but check the manual of your NAS to know how to activate it.
Enabling Gigawords on NAS
Again, this section relates to Cisco but a similar set of commands is usually available on most devices. Gigawords option is enable by default on Cisco gear hence it doesn’t appear in the configuration. If it does, simply run this command to activate it:
aaa accounting gigawords
You will be asked to reload the router to apply the new settings. This will activate Acct-Input-Gigawords and Acct-Output-Gigawords attributes which tell how many times the counters reset. Knowing this, we can then calculate the real values. Next step is to create extra column in the database.
Mysql Table Modification
AcctInputOctet and AcctOutputOctet fields need to be changed from 32 to 64 bits. You can make the change with any Mysql client or PhpMyAdmin
ALTER TABLE radacct CHANGE AcctInputOctets AcctInputOctets BIGINT(20) UNSIGNED;
ALTER TABLE radacct CHQNGE AcctOutputOctets AcctOutputOctets BIGINT(20) UNSIGNED;
Freeradius Update
The SQL code in sql.conf needs to be change for stop and update queries to log the new values into the database. Here’s what they look like after modification:
accounting_update_query = "
UPDATE ${acct_table1}
SET AcctInputOctets = '%{Acct-Input-Gigawords:-0}' << 32 | '%{Acct-Input-Octets:-0}',
AcctOutputOctets = '%{Acct-Output-Gigawords:-0}' << 32 | '%{Acct-Output-Octets:-0}',
FramedIPAddress = '%{Framed-IP-Address}'
WHERE AcctSessionId = '%{Acct-Session-Id}'
AND UserName = '%{SQL-User-Name}'
AND NASIPAddress= '%{NAS-IP-Address}'
AND NASIPAddress= '%{NAS-IP-Address}'
AND AcctStopTime = 0"
accounting_stop_query ="
UPDATE ${acct_table2}
SET AcctStopTime = '%S',
AcctSessionTime = '%{Acct-Session-Time}',
AcctInputOctets = '%{Acct-Input-Gigawords:-0}' << 32 | '%{Acct-Input-Octets:-0}',
AcctOutputOctets = '%{Acct-Output-Gigawords:-0}' << 32 | '%{Acct-Output-Octets:-0}',
AcctTerminateCause = '%{Acct-Terminate-Cause}',
AcctStopDelay = '%{Acct-Delay-Time}',
ConnectInfo_stop = '%{Connect-Info}'
WHERE AcctSessionId = '%{Acct-Session-Id}'
AND UserName = '%{SQL-User-Name}'
AND NASIPAddress = '%{NAS-IP-Address}'
AND AcctStopTime =0"
Restart Radius service, you’re done!
This concatenates the Gigawords and Octets values adding 32 null bits to the first and doing a logical OR on them.
If you have any comment or want to share some suggestions you may have, feel free to contact us.
This solution was provided on the Freeradius FAQ available at http://wiki.freeradius.org