Howto provide free airtime or no accounting in night for quota base user

Alan DeKok aland at
Thu Jan 25 17:17:09 CET 2018

> On Jan 25, 2018, at 3:04 AM, JAHANZAIB SYED <aacable at> wrote:
> Ok my understanding is once a user is connected to the NAS, all accounting will transfer to the FR radacct table via interim update and we cannot exclude specific sites accounting. Ok for specific users (group) we have to create some magical code in FR that should check for specific user details and if the user service allows free airtime, then donot update the radacct table or less the data ? I dont need exact codes but still i am looking for some more directions if possible.

  The problem is that the sessions span the "free" time.  So you need a way to:

1) log all session data
2) log *only* session data for the "free" time.
3) subtract one from the other

  This isn't a trivial thing to do, unfortunately.  It's all DB manipulation.

  My $0.02 is to write all accounting packets as normal.  This addresses (1).

  You will need to record the data usage for the users session at the *start* of the free time, and again at the *end* of the free time.  If the session lasts more than a day, then you will need to track free time for each day.

  Or, if you only care about the total free time per session, you could probably come up with a simpler approach.  Just extend the radacct table with another column or two "freeinputoctets" and "freeoutputoctets".  These should be the same data types as "acctinputoctets" and "acctoutputoctets".

  Edit raddb/dictionary, and add:

ATTRIBUTE My-Free-Input-Octets 3000 integer64
ATTRIBUTE My-Free-Output-Octets 3001 integer64
ATTRIBUTE My-Acct-Input-Octets 3002 integer64
ATTRIBUTE My-Acct-Output-Octets 3003 integer64
ATTRIBUTE My-Acct-Packet-Input-Octets 3004 integer64
ATTRIBUTE My-Acct-Packet-Output-Octets 3005 integer64

  The first 4 attributes will mirror what's in the SQL database.  And let you do math with named attributes, which is always useful.

  The last 2 attribute are needed only because RADIUS doesn't define 64-bit counters...

  Then when a packet is received, do:

* if it's during the free time, do something like:

update request {
   My-Free-Input-Octets := "%{SELECT "freeinputoctets" from the table}
   My-Free-Output-Octets := "%{SELECT "freeoutputoctets" from the table}
   My-Acct-Input-Octets := "%{SELECT "acctinputoctets" from the table}
   My-Acct-Output-Octets := "%{SELECT "acctinputoctets" from the table}
   My-Acct-Packet-Input-Octets  := "%{expr:%{Acct-Input-Octets} + %{Acct-Input-Gigawords} << 32}"
   My-Acct-Packet-Output-Octets  := "%{expr:%{Acct-Output-Octets} + %{Acct-Output-Gigawords} << 32}"

  That gets you the *current* state of what's going on.  Then, figure out the difference between the various quantities:

update request {
   My-Free-Input-Octets := %{expr:%{My-Free-Input-Octets} + %{My-Acct-Packet-Input-Octets} - %{My-Acct-Input-Octets}}
   My-Free-Output-Octets := %{expr:%{My-Free-Output-Octets} + %{My-Acct-Packet-Output-Octets} - %{My-Acct-Output-Octets}}

  And then update the various SQL queries to write the My-Free-Input-Octets to the "freeinputoctets" column.

  It's not pretty, but it should work.

  Alan DeKok.

More information about the Freeradius-Users mailing list