If statement for two different sql queries
Hi, I need help to split it radreply to two different queries. I have a two different queries:DHCP message and ARP message For examples ARP query (1) Received Access-Request Id 93 from 10.10.10.2:64387 to 10.10.10.3:1812 (1) User-Name = "d4:ca:6d:0a:94:5b" (1) User-Password = "password" (1) NAS-IP-Address = 10.10.10.10 (1) ADSL-Agent-Circuit-Id = "192.168.0.100" (1) NAS-Port-Type = Ethernet (1) NAS-Port-Id = "lag-1:1000" DHCP query (2) Received Access-Request Id 94 from 10.10.10.2:54337 to 10.10.10.3:1812 (2) User-Name = "d4:ca:6d:0a:94:5b" (2) User-Password = "password" (2) NAS-IP-Address = 10.10.10.10 (2) ADSL-Agent-Remote-Id = "5888" (2) NAS-Port-Type = Ethernet (2) NAS-Port-Id = "lag-1:1000" I wrote IF statement in default file authorize section authorize { (...) if(ADSL-Agent-Circuit-Id) { if(ADSL-Agent-Circuit-Id =~ /.+\..+\..+\..+/) { update request { (???) } }else{ update request { (???) } } } sql I think I will use multiple instances for different rad_replay queries. Is this a bad idea? Is it possible to create just two queries.conf files with different queries? -- Pagarbiai, Giedrius
On Oct 10, 2021, at 5:15 PM, Giedrius Baronas <g.baronas@gmail.com> wrote:
I need help to split it radreply to two different queries.
To do... what?
I have a two different queries:DHCP message and ARP message For examples ARP query (1) Received Access-Request Id 93 from 10.10.10.2:64387 to 10.10.10.3:1812 (1) User-Name = "d4:ca:6d:0a:94:5b" (1) User-Password = "password"
That's not an ARP query. I don't know what it is, but it's something magic (and non-standard) created by the NAS.
DHCP query (2) Received Access-Request Id 94 from 10.10.10.2:54337 to 10.10.10.3:1812 (2) User-Name = "d4:ca:6d:0a:94:5b" (2) User-Password = "password"
That's not DHCP. That's just a normal RADIUS packet.
I wrote IF statement in default file authorize section
To do... what?
I think I will use multiple instances for different rad_replay queries. Is this a bad idea? Is it possible to create just two queries.conf files with different queries?
I have no idea what you're trying to do. Please explain in more detail. Alan DeKok.
Hi, I will try to describe it more precisely. If radius receives a packet with radius attribute "ADSL-Agent-Circuit-Id" then I need to use a sql1 instance. In the else statement I need it to use sql2 instance. How can I set sql instances ? /usr/local/etc/raddb/sites-enabled/default authorize { (...) if(ADSL-Agent-Circuit-Id) { if(ADSL-Agent-Circuit-Id =~ /.+\..+\..+\..+/) { update request { (instance sql1) } }else{ update request { (instance sql2) } } } sql sql1 { ... } sql sql2 { ... } Pagarbiai, Giedrius 2021-10-11, pr, 01:11 Alan DeKok <aland@deployingradius.com> rašė:
On Oct 10, 2021, at 5:15 PM, Giedrius Baronas <g.baronas@gmail.com> wrote:
I need help to split it radreply to two different queries.
To do... what?
I have a two different queries:DHCP message and ARP message For examples ARP query (1) Received Access-Request Id 93 from 10.10.10.2:64387 to 10.10.10.3:1812 (1) User-Name = "d4:ca:6d:0a:94:5b" (1) User-Password = "password"
That's not an ARP query. I don't know what it is, but it's something magic (and non-standard) created by the NAS.
DHCP query (2) Received Access-Request Id 94 from 10.10.10.2:54337 to 10.10.10.3:1812 (2) User-Name = "d4:ca:6d:0a:94:5b" (2) User-Password = "password"
That's not DHCP. That's just a normal RADIUS packet.
I wrote IF statement in default file authorize section
To do... what?
I think I will use multiple instances for different rad_replay queries. Is this a bad idea? Is it possible to create just two queries.conf files with different queries?
I have no idea what you're trying to do. Please explain in more detail.
Alan DeKok.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
On Oct 11, 2021, at 2:04 PM, Giedrius Baronas <g.baronas@gmail.com> wrote:
I will try to describe it more precisely. If radius receives a packet with radius attribute "ADSL-Agent-Circuit-Id" then I need to use a sql1 instance. In the else statement I need it to use sql2 instance. How can I set sql instances ?
Just refer to them by name. if (a) { sql1 } else { sql2 } Alan DeKok.
I described the new module but the goal was to describe an additional instance sql1 that would use the same rlm_sql module. I describe sql and sql1 modules in file /etc/freeradius/mods-enabled/sql and I'm getting an error for the non-existent file 'rlm_sql1'. # Loading module "sql" from file /etc/freeradius/mods-enabled/sql sql { driver = "rlm_sql_postgresql" server = "" port = 0 login = "" password = <<< secret >>> radius_db = "dbname=radius host=postgresql2 port=5432 user=radius password=radpass" ...... } sql1 { driver = "rlm_sql_postgresql" server = "" port = 0 login = "" password = <<< secret >>> radius_db = "dbname=radius host=postgresql3 port=5432 user=radius password=radpass"...... } rlm_sql (sql): Driver rlm_sql_postgresql (module rlm_sql_postgresql) loaded and linked Creating attribute SQL-Group /etc/freeradius/mods-enabled/sql[108]: Failed to link to module 'rlm_sql1': /usr/lib/freeradius/rlm_sql1.so: cannot open shared object file: No such file or directory I repeating read on manual https://wiki.freeradius.org/modules/Rlm_sql which sayed: You can create multiple named instances like so: sql sql_instance1 { ... } sql sql_instance2 { ... } I add word sql before both instances sql and sql1 # Loading module "sql" from file /etc/freeradius/mods-enabled/sql sql sql { driver = "rlm_sql_postgresql" server = "" port = 0 login = "" password = <<< secret >>> radius_db = "dbname=radius host=postgresql2 port=5432 user=radius password=radpass" ...... } sql sql1 { driver = "rlm_sql_postgresql" server = "" port = 0 login = "" password = <<< secret >>> radius_db = "dbname=radius host=postgresql3 port=5432 user=radius password=radpass"...... } Now this part works successfully. In file /etc/freeradius/sites-enabled/default I wrote group for both instances group { sql { fail = 1 notfound = return noop = 2 ok = return updated = 3 reject = return userlock = 4 invalid = 5 handled = 6 } sql1 { fail = 1 notfound = return noop = 2 ok = return updated = 3 reject = return userlock = 4 invalid = 5 handled = 6 } } Next my goal if statements. In file /etc/freeradius/sites-enabled/default I wrote if statements with update request if(ADSL-Agent-Circuit-Id){ if(ADSL-Agent-Circuit-Id =~ /.+\..+\..+\..+/){ update request { Tmp-String-2 := ADSL-Agent-Circuit-Id sql1 } }else{ update request { Tmp-String-2 := "127.0.0.1" } } # Loading authorize {...} /etc/freeradius/sites-enabled/default[122]: Missing attribute value /etc/freeradius/sites-enabled/default[120]: Failed to parse "update" subsection. /etc/freeradius/sites-enabled/default[119]: Failed to parse "if" subsection. /etc/freeradius/sites-enabled/default[71]: Errors parsing authorize section. I repeat read whitch Alan wrote: Just refer to them by name. if (a) { sql1 } else { sql2 } I replace sql1 place from update request {...} to if statement if(ADSL-Agent-Circuit-Id){ if(ADSL-Agent-Circuit-Id =~ /.+\..+\..+\..+/){ sql1 update request { Tmp-String-2 := ADSL-Agent-Circuit-Id } }else{ update request { Tmp-String-2 := "127.0.0.1" } } I tried sent packet to radius server ...... (0) if (ADSL-Agent-Circuit-Id){ (0) if (ADSL-Agent-Circuit-Id) -> TRUE (0) if (ADSL-Agent-Circuit-Id) { (0) if (ADSL-Agent-Circuit-Id =~ /.+\..+\..+\..+/){ (0) if (ADSL-Agent-Circuit-Id =~ /.+\..+\..+\..+/) -> TRUE (0) if (ADSL-Agent-Circuit-Id =~ /.+\..+\..+\..+/) { (0) sql1: EXPAND %{User-Name} (0) sql1: --> aa:bb:cc:dd:ee:ff (0) sql1: SQL-User-Name set to 'aa:bb:cc:dd:ee:ff' ...... Voila, I have two working instances. I hope I didn’t miss anything. Pagarbiai, Giedrius 2021-10-11, pr, 21:17 Alan DeKok <aland@deployingradius.com> rašė:
On Oct 11, 2021, at 2:04 PM, Giedrius Baronas <g.baronas@gmail.com> wrote:
I will try to describe it more precisely. If radius receives a packet with radius attribute "ADSL-Agent-Circuit-Id" then I need to use a sql1 instance. In the else statement I need it to use sql2 instance. How can I set sql instances ?
Just refer to them by name.
if (a) { sql1 } else { sql2 }
Alan DeKok.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Pagarbiai, Giedrius 861569551
On Oct 12, 2021, at 6:58 PM, Giedrius Baronas <g.baronas@gmail.com> wrote:
I described the new module but the goal was to describe an additional instance sql1 that would use the same rlm_sql module.
Your previous example was correct. I doin't understand why you changed it.
sql1 {
That's wrong.
I repeating read on manual https://wiki.freeradius.org/modules/Rlm_sql which sayed:
You can create multiple named instances like so:
sql sql_instance1 {
Did you do: sql sql1 { ... } ?
I add word sql before both instances sql and sql1
# Loading module "sql" from file /etc/freeradius/mods-enabled/sql sql sql {
Again, that's wrong. Don't do that. Your previous message had: sql sql1 { ... } sql sql2 { ... } That works. The documentation says to configure it this way. Alan DeKok.
participants (2)
-
Alan DeKok -
Giedrius Baronas