Problem with Local variable especially when its negative
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
On 5 May 2016 at 11:14, Mrinal K <sinha.mrinal@gmail.com> wrote:
if("%{control:My-Local-Int-3}" > 0){
That looks to me like you're comparing a string to an integer. That's probably not what you wanted to do. Have you tried this instead? if(%{control:My-Local-Int-3} > 0){ -Paul -- ---------------------------------------------------------------------- Paul Seward, Senior Systems Administrator, University of Bristol Paul.Seward@bristol.ac.uk +44 (0)117 39 41148 GPG Key ID: E24DA8A2 GPG Fingerprint: 7210 4E4A B5FC 7D9C 39F8 5C3C 6759 3937 E24D A8A2
On May 5, 2016, at 6:14 AM, Mrinal K <sinha.mrinal@gmail.com> wrote:
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.
You should upgrade to a modern version of the server.
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
It cannot be negative. The "integer" type in RADIUS is an unsigned 32-bit number. This is documented in the dictionary file you edited to add "My-Local_Int-3". Fix your policies so that they don't require the use of negative integers. Alan DeKok.
@Paul I tried that, but it threw a parsing error @Alan : I modified the logic to avoid negative values and it works perfectly. Thank you, much appreciate the help. And yes I will update the server asap, I have been lazy about it for too long. On Thu, May 5, 2016 at 8:24 PM, Alan DeKok <aland@deployingradius.com> wrote:
On May 5, 2016, at 6:14 AM, Mrinal K <sinha.mrinal@gmail.com> wrote:
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.
You should upgrade to a modern version of the server.
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
It cannot be negative.
The "integer" type in RADIUS is an unsigned 32-bit number. This is documented in the dictionary file you edited to add "My-Local_Int-3".
Fix your policies so that they don't require the use of negative integers.
Alan DeKok.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
On 5 May 2016, at 13:02, Mrinal K <sinha.mrinal@gmail.com> wrote:
@Paul I tried that, but it threw a parsing error
@Alan : I modified the logic to avoid negative values and it works perfectly. Thank you, much appreciate the help.
And yes I will update the server asap, I have been lazy about it for too long.
There's a 32bit signed type in 3.0.x. -Arran Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS Development Team FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
participants (4)
-
Alan DeKok -
Arran Cudbard-Bell -
Mrinal K -
Paul Seward