我使用freeradius 2.2.8和mysql在达到带宽配额时通过freeradius发送coa/disconnect消息。代码的那部分工作得很好。不幸的是,即使nas发出记帐停止,coa/disconnect消息也会被发送出去。为了防止这种情况发生,我设置了一个条件,在这个条件中,我从mysql radacct表中提取acct termination cause,并将其与一些字符串进行比较。
在会计方面,
update control {
....
Tmp-String-0 := "%{sql:SELECT acctterminatecause AS Terminate FROM radacct WHERE radacct.username='%{User-Name}' AND radacct.acctsessionid='%{Acct-Session-Id}'}}"
***if ("%{control:Tmp-String-0}" != "User-Request")***{
if (("%{control:Tmp-Integer-0}" > "%{control:Tmp-Integer-2}") || ("%{control:Tmp-Integer-1}" > "%{control:Tmp-Integer-3}")){
if ("%{control:coa_dm}" == "coa"){
update coa {
User-Name = "%{User-Name}"
Acct-Session-Id = "%{Acct-Session-Id}"
NAS-IP-Address = "%{NAS-IP-Address}"
#Filter-Id = "UN-AUTHORIZED-PROFILE"
Framed-IP-Address = "%{Framed-IP-Address}"
Session-Timeout = 10
}
}
if ("%{control:coa_dm}" == "dm"){
update disconnect {
User-Name = "%{User-Name}"
NAS-IP-Address = "%{NAS-IP-Address}"
}
}
}
}
根据freeradius调试日志,我们可以看到字符串应该是匹配的,程序应该避免内部if条件。不幸的是,情况并非如此,第一个if条件总是返回true。
***Thu May 17 17:43:41 2018 : Info: expand: SELECT acctterminatecause AS Terminate FROM radacct WHERE radacct.username='%{User-Name}' AND radacct.acctsessionid='%{Acct-Session-Id}' -> SELECT acctterminatecause AS Terminate FROM radacct WHERE radacct.username='kiranc' AND radacct.acctsessionid='5AFD71CB-3FE1C000'
Thu May 17 17:43:41 2018 : Debug: rlm_sql (sql): Reserving sql socket id: 16
Thu May 17 17:43:41 2018 : Info: sql_xlat finished
Thu May 17 17:43:41 2018 : Debug: rlm_sql (sql): Released sql socket id: 16
Thu May 17 17:43:41 2018 : Info: expand: %{sql:SELECT acctterminatecause AS Terminate FROM radacct WHERE radacct.username='%{User-Name}' AND radacct.acctsessionid='%{Acct-Session-Id}'}} -> User-Request}
Thu May 17 17:43:41 2018 : Info: ++} # update control = noop
Thu May 17 17:43:41 2018 : Info: ++? if ("%{control:Tmp-String-0}" != "User-Request")
Thu May 17 17:43:41 2018 : Info: expand: %{control:Tmp-String-0} -> User-Request}
Thu May 17 17:43:41 2018 : Info: ? Evaluating ("%{control:Tmp-String-0}" != "User-Request") -> TRUE***
Thu May 17 17:43:41 2018 : Info: ++? if ("%{control:Tmp-String-0}" != "User-Request") -> TRUE
Thu May 17 17:43:41 2018 : Info: ++if ("%{control:Tmp-String-0}" != "User-Request") {
Thu May 17 17:43:41 2018 : Info: +++? if (("%{control:Tmp-Integer-0}" > "%{control:Tmp-Integer-2}") || ("%{control:Tmp-Integer-1}" > "%{control:Tmp-Integer-3}"))
Thu May 17 17:43:41 2018 : Info: expand: %{control:Tmp-Integer-0} -> 3169
Thu May 17 17:43:41 2018 : Info: expand: %{control:Tmp-Integer-2} -> 25000000
Thu May 17 17:43:41 2018 : Info: ?? Evaluating ("%{control:Tmp-Integer-0}" > "%{control:Tmp-Integer-2}") -> FALSE
Thu May 17 17:43:41 2018 : Info: expand: %{control:Tmp-Integer-1} -> 13402
Thu May 17 17:43:41 2018 : Info: expand: %{control:Tmp-Integer-3} -> 50000000
我尝试了单引号,双引号,用&代替%,但没有用。其他条件在命中时正确满足,因为它们作为整数返回。
谢谢你的帮助。
1条答案
按热度按时间lxkprmvk1#
我忘了说我已经把它修好了。我没有使用tmp-string-0变量进行比较,而是使用了实际的radius属性名,并使其正常工作。
谢谢你的帮助。