hex/integer value of ipaddr

Arran Cudbard-Bell a.cudbardb at freeradius.org
Wed Dec 20 12:10:24 CET 2017



> On 20 Dec 2017, at 10:42, Linux Chips <linux.chips at 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 874 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.freeradius.org/pipermail/freeradius-devel/attachments/20171220/6048ed85/attachment.sig>


More information about the Freeradius-Devel mailing list