Conditional statements in dialup.conf?
Hi All, I'm wondering if you can advise on the best way to deal with the below. On all NAS's apart from Mikrotik routers, when the radius accounting packets are sent, the correct figures are in the Acct-Input-Octets and Acct-Output-Octets respectively. When using Mikrotik, they switch those around (i.e. the download octets are upload and vice versa), and because I use an SQL DB, it means that the values are also stored the wrong way round, as the queries in dialup.conf are fixed to insert in to the same columns. So, I'm looking to detect a Mikrotik accounting request and then change the columns round so that the DB is always correct. I've tried doing this inside the dialup.conf but not sure it accepts conditional statements inside there. (I use other conditional statements in sites-enabled/default etc, so have an understanding on that in general). --------------------------------- if (Mikrotik-Host-IP) { accounting_start_query = " \ INSERT INTO ${acct_table1} \ (acctsessionid, acctuniqueid, username, \ realm, nasipaddress, nasportid, \ nasporttype, acctstarttime, acctstoptime, \ acctsessiontime, acctauthentic, connectinfo_start, \ connectinfo_stop, acctoutputoctets, acctinputoctets, \ calledstationid, callingstationid, acctterminatecause, \ servicetype, framedprotocol, framedipaddress, \ acctstartdelay, acctstopdelay, xascendsessionsvrkey) \ VALUES \ ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \ '%{SQL-User-Name}', \ '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \ '%{NAS-Port-Type}', '%S', NULL, \ '0', '%{Acct-Authentic}', '%{Connect-Info}', \ '', '0', '0', \ REPLACE(SUBSTRING('%{Called-Station-Id}',1,17),':','-'), \ REPLACE(SUBSTRING('%{Calling-Station-Id}',1,17),':','-'), '', \ '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', \ '%{%{Acct-Delay-Time}:-0}', '0', '%{X-Ascend-Session-Svr-Key}')" } else { accounting_start_query = " \ INSERT INTO ${acct_table1} \ (acctsessionid, acctuniqueid, username, \ realm, nasipaddress, nasportid, \ nasporttype, acctstarttime, acctstoptime, \ acctsessiontime, acctauthentic, connectinfo_start, \ connectinfo_stop, acctinputoctets, acctoutputoctets, \ calledstationid, callingstationid, acctterminatecause, \ servicetype, framedprotocol, framedipaddress, \ acctstartdelay, acctstopdelay, xascendsessionsvrkey) \ VALUES \ ('%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', \ '%{SQL-User-Name}', \ '%{Realm}', '%{NAS-IP-Address}', '%{NAS-Port}', \ '%{NAS-Port-Type}', '%S', NULL, \ '0', '%{Acct-Authentic}', '%{Connect-Info}', \ '', '0', '0', \ REPLACE(SUBSTRING('%{Called-Station-Id}',1,17),':','-'), \ REPLACE(SUBSTRING('%{Calling-Station-Id}',1,17),':','-'), '', \ '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}', \ '%{%{Acct-Delay-Time}:-0}', '0', '%{X-Ascend-Session-Svr-Key}')" } ------------------------------------- This doesn't work; it throws a config error strangely, which goes away if I comment out the if statement. [.] Wed Oct 22 07:59:28 2014 : Debug: including configuration file /usr/local/etc/raddb/sql.conf Wed Oct 22 07:59:28 2014 : Debug: including configuration file /usr/local/etc/raddb/sql/mysql/dialup.conf Wed Oct 22 07:59:28 2014 : Debug: WARNING: No such configuration item acct_table1 Wed Oct 22 07:59:28 2014 : Error: /usr/local/etc/raddb/sql/mysql/dialup.conf[165]: Reference " UPDATE ${acct_table1} SET framedipaddress = '%{Framed-IP-Address}', acctsessiontime = '%{Acct-Session-Time}', acctoutputoctets = '%{%{Acct-Input-Gigawords}:-0}' << 32 | '%{%{Acct-Input-Octets}:-0}', acctinputoctets = '%{%{Acct-Output-Gigawords}:-0}' << 32 | '%{%{Acct-Output-Octets}:-0}' WHERE acctsessionid = '%{Acct-Session-Id}' AND username = '%{SQL-User-Name}' AND nasipaddress = '%{NAS-IP-Address}'" not found Wed Oct 22 07:59:28 2014 : Error: Errors reading /usr/local/etc/raddb/radiusd.conf If I'm doing it wrong can you point me in the direction of how else to change the incoming request so that I can switch the download/upload values for Mikrotik? Thanks, James
James Wood wrote:
On all NAS’s apart from Mikrotik routers, when the radius accounting packets are sent, the correct figures are in the Acct-Input-Octets and Acct-Output-Octets respectively.
OK.
When using Mikrotik, they switch those around (i.e. the download octets are upload and vice versa), and because I use an SQL DB, it means that the values are also stored the wrong way round, as the queries in dialup.conf are fixed to insert in to the same columns.
So... fix the values *before* you put them into SQL.
So, I’m looking to detect a Mikrotik accounting request and then change the columns round so that the DB is always correct.
That is completely backwards. Don't fix the columns. Fix the accounting packet in the "preacct" section: if (Mikrotik-Host-IP) { update request { Tmp-Integer-0 := "%{Acct-Input-Octets} Tmp-Integer-1 := "%{Acct-Output-Octets} } update request { Acct-Input-Octets = "%{Tmp-Integer-0}" Acct-Output-Octets = "%{Tmp-Integer-01}" } }
I’ve tried doing this inside the dialup.conf but not sure it accepts conditional statements inside there.
It doesn't. See "man unlang". The documentation says where you can put conditions. Alan DeKok.
Thanks for the reply Alan. I understand the correct place to put it now. Is there a reason you are setting a new variable and then assigning that to the next update request? Would this not work? if (Mikrotik-Host-IP) { update request { Acct-Input-Octets = "%{Acct-Output-Octets}" Acct-Output-Octets = "%{Acct-Input-Octets}" } } Thanks, James -----Original Message----- From: freeradius-users-bounces+james.wood=purplewifi.com@lists.freeradius.org [mailto:freeradius-users-bounces+james.wood=purplewifi.com@lists.freeradius.org] On Behalf Of Alan DeKok Sent: 22 October 2014 15:34 To: FreeRadius users mailing list Subject: Re: Conditional statements in dialup.conf? James Wood wrote:
On all NAS’s apart from Mikrotik routers, when the radius accounting packets are sent, the correct figures are in the Acct-Input-Octets and Acct-Output-Octets respectively.
OK.
When using Mikrotik, they switch those around (i.e. the download octets are upload and vice versa), and because I use an SQL DB, it means that the values are also stored the wrong way round, as the queries in dialup.conf are fixed to insert in to the same columns.
So... fix the values *before* you put them into SQL.
So, I’m looking to detect a Mikrotik accounting request and then change the columns round so that the DB is always correct.
That is completely backwards. Don't fix the columns. Fix the accounting packet in the "preacct" section: if (Mikrotik-Host-IP) { update request { Tmp-Integer-0 := "%{Acct-Input-Octets} Tmp-Integer-1 := "%{Acct-Output-Octets} } update request { Acct-Input-Octets = "%{Tmp-Integer-0}" Acct-Output-Octets = "%{Tmp-Integer-01}" } }
I’ve tried doing this inside the dialup.conf but not sure it accepts conditional statements inside there.
It doesn't. See "man unlang". The documentation says where you can put conditions. Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
James Wood wrote:
Thanks for the reply Alan. I understand the correct place to put it now.
Is there a reason you are setting a new variable and then assigning that to the next update request?
Because that's how swapping variables works.
Would this not work?
If it worked, I would have suggested using it. Alan DeKok.
Thanks, Should the second update reply block not be this: update request { Acct-Input-Octets = "%{Tmp-Integer-1}" Acct-Output-Octets = "%{Tmp-Integer-0}" } Else we are setting the same values and not switching them? Thanks James -----Original Message----- From: freeradius-users-bounces+james.wood=purplewifi.com@lists.freeradius.org [mailto:freeradius-users-bounces+james.wood=purplewifi.com@lists.freeradius. org] On Behalf Of Alan DeKok Sent: 22 October 2014 16:56 To: FreeRadius users mailing list Subject: Re: Conditional statements in dialup.conf? James Wood wrote:
Thanks for the reply Alan. I understand the correct place to put it now.
Is there a reason you are setting a new variable and then assigning that to the next update request?
Because that's how swapping variables works.
Would this not work?
If it worked, I would have suggested using it. Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
participants (2)
-
Alan DeKok -
James Wood