hex/integer value of ipaddr
Hi, I am trying to expand an ipaddr typed attribute to hex value. the man unlang page contains the following :
e.g. If a request contains "Framed-IP-Address = 127.0.0.1", the expansion of %{hex:Framed-IP-Address} will yeild "0x7f000001".
but when ever I do that I get empty expansion. I am configuring the dynamic-clients, and my clients IPs are defined in the db as signed int (well, ugly, but I can not change that at the moment), the database is mssql, so I do not have those fancy functions like INET_ATON() I can do a SQL stored procedure to handle the conversion, but the expansion is much neater and simplifies things a lot. below is the output of my radiusd -X when trying to make the expansion. (0) server dynamic_clients { (0) # Executing section authorize from file /etc/raddb/sites-enabled/dynamic-clients (0) authorize { (0) if ("%{mssql_rbs: SELECT NASIndex FROM NASConfig WHERE NASIP = convert(int, %{hex:Packet-Src-IP-Address}) }") { (0) EXPAND %{User-Name} (0) --> (0) SQL-User-Name set to '' rlm_sql (mssql_rbs): Reserved connection (0) (0) Executing select query: SELECT NASIndex FROM NASConfig WHERE NASIP = convert(int, ) rlm_sql_freetds: unexpected result type from query (0) ERROR: rlm_sql_freetds: Server msg from "WIN-39JGB9CGE5E\EARTHLINKMSSQL": severity(102), number(15), origin(1), layer(1), procedure "none": Incorrect syntax near ')'. (0) ERROR: SQL query failed: server error rlm_sql (mssql_rbs): Released connection (0) Need 5 more connections to reach 10 spares rlm_sql (mssql_rbs): Opening additional connection (5), 1 of 27 pending slots used (0) EXPAND %{mssql_rbs: SELECT NASIndex FROM NASConfig WHERE NASIP = convert(int, %{hex:Packet-Src-IP-Address}) } (0) --> (0) if ("%{mssql_rbs: SELECT NASIndex FROM NASConfig WHERE NASIP = convert(int, %{hex:Packet-Src-IP-Address}) }") -> FALSE (0) [ok] = ok (0) } # authorize = ok (0) } # server dynamic_clients (0) Converting control list to client fields (0) ERROR: Cannot add client 172.31.4.6: Required attribute "FreeRADIUS-Client-Secret" is missing Ignoring request to auth address * port 1812 bound to server ELProxy from unknown client 172.31.4.6 port 35221 proto udp Ready to process requests it is complaining about a syntax error where the "supposed" hex value would be (inside the convert function) I also tried integer instead of hex with the same results am I missing something here? I can not seam to find any other reference to the "hex" expansion online nor in the config/man. thanks Ali
On 20 Dec 2017, at 10:42, Linux Chips <linux.chips@gmail.com> wrote:
Hi,
I am trying to expand an ipaddr typed attribute to hex value. the man unlang page contains the following :
e.g. If a request contains "Framed-IP-Address = 127.0.0.1", the expansion of %{hex:Framed-IP-Address} will yeild "0x7f000001".
but when ever I do that I get empty expansion.
It's because Packet-Src-IP-Address is a virtual attribute. # Insert in the virtual server before you call rlm_sql update request { Tmp-IP-Address-0 := "%{Packet-Src-IP-Address}" } %{hex:Tmp-IP-Address-0} The xlat expansion code was built to work with C strings, this causes issues when working with binary data, which is why the hex expansion's input is an attribute reference. Attribute references only function with "real" attributes in the request. Some attributes never actually exist in the request, they're part of a set of attributes looked for especially in the xlat code so they're only accessible as expansions. Solution is to access Packet-Src-IP-Address via an expansion, copy that to a real attribute and then pass that attribute to the hex expansion. It'll be fixed in v4. In the reworked xlat code, it operates on sequences of boxed values instead of strings. -Arran
On 12/20/2017 02:10 PM, Arran Cudbard-Bell wrote:
On 20 Dec 2017, at 10:42, Linux Chips <linux.chips@gmail.com> wrote:
Hi,
I am trying to expand an ipaddr typed attribute to hex value. the man unlang page contains the following :
e.g. If a request contains "Framed-IP-Address = 127.0.0.1", the expansion of %{hex:Framed-IP-Address} will yeild "0x7f000001".
but when ever I do that I get empty expansion.
It's because Packet-Src-IP-Address is a virtual attribute.
# Insert in the virtual server before you call rlm_sql update request { Tmp-IP-Address-0 := "%{Packet-Src-IP-Address}" }
%{hex:Tmp-IP-Address-0}
The xlat expansion code was built to work with C strings, this causes issues when working with binary data, which is why the hex expansion's input is an attribute reference.
Attribute references only function with "real" attributes in the request.
Some attributes never actually exist in the request, they're part of a set of attributes looked for especially in the xlat code so they're only accessible as expansions.
Solution is to access Packet-Src-IP-Address via an expansion, copy that to a real attribute and then pass that attribute to the hex expansion.
It'll be fixed in v4. In the reworked xlat code, it operates on sequences of boxed values instead of strings.
-Arran
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
thanks for the quick reply, I totally forgot about the virtual attribute thing, my bad :D that tmp-ip trick solved it and all working now. cheers
participants (2)
-
Arran Cudbard-Bell -
Linux Chips