Problem with Local variable especially when its negative

Mrinal K sinha.mrinal at gmail.com
Thu May 5 12:14:19 CEST 2016


Hello members of the freeradius email list,

I have added some unlang code in the authorize section of my configuration,
however I am having some trouble with the values in my variables. My server
is running Version 2.1.12.

The snippet is as follows and is intended to check how much of data user
has downloaded till now, My-Local-Int-2 has the maximum data allowed to the
user and My-Local-Int-1 is the start timestamp. The idea is to get the
difference of maximum allowed octets and octets used till now and if comes
out to be less than zero we reject the user else user is allowed.


#### Section 1 Start
                        update control {
                                My-Local-Int-3 = "%{sql: select
('%{control:My-Local-Int-2}' - ifnull(sum(acctinputoctets) +
sum(acctoutputoctets),0)) from radacct where
calledstationid='%{Called-Station-Id}' and
callingstationid='%{Calling-Station-Id}' and sessionstarttimestamp >
'%{control:My-Local-Int-1}'}"
                        }
#### Section 1 End

#### Section 2 Start
                        if("%{control:My-Local-Int-3}" > 0){
                                update reply {
                               ChilliSpot-Max-Total-Octets :=
"%{control:My-Local-Int-3}"
                               Idle-Timeout = 600
                               Acct-Interim-Interval = 180
                                }
                        }
                        else{
                                update control {
                                        Auth-Type := reject
                                }
                        }
#### Section 2 End


Its pretty straight forward and work well till My-Local-Int-3 has value
which is greater than 0. However when value of My-Local_Int-3 is in
negative "if("%{control:My-Local-Int-3}" > 0) " still returns true and
ChilliSpot-Max-Total-Octets is assigned an unknown positive value.


Concerned debug output is as follows,

expand: %{sql: select ('%{control:My-Local-Int-2}' -
ifnull(sum(acctinputoctets) + sum(acctoutputoctets),0)) from radacct where
calledstationid='%{Called-Station-Id}' and
callingstationid='%{Calling-Station-Id}' and sessionstarttime >
'%{control:My-Local-Int-1}'} -> -500017


expand: %{sql: select ('%{control:My-Local-Int-2}' -
ifnull(sum(acctinputoctets) + sum(acctoutputoctets),0)) from radacct where
calledstationid='%{Called-Station-Id}' and
callingstationid='%{Calling-Station-Id}' and sessionstarttime >
'%{control:My-Local-Int-1}'} -> -500017
+++[control] returns noop
+++? if ("%{control:My-Local-Int-3}" > 0)
expand: %{control:My-Local-Int-3} -> 4294467279
? Evaluating ("%{control:My-Local-Int-3}" > 0) -> TRUE
+++? if ("%{control:My-Local-Int-3}" > 0) -> TRUE
+++- entering if ("%{control:My-Local-Int-3}" > 0) {...}

At first when sql query is expanded the value is -500017 but later same
My-Local-Int-3 expands to 4294467279.



Regards,

Kumar Mrinal

Splash Networks
http://splashwifi.net


More information about the Freeradius-Users mailing list