Unlang operations with IP addresses
Nick Porter
nick at portercomputing.co.uk
Wed Dec 11 07:54:56 UTC 2024
On 10/12/2024 21:29, Ľudovít Mikula wrote:
> Ended up using sql since I already use it and the overhead is probably
> quite small.
>
> Just for reference this is what I used: &DHCP-Router-Address = "%{sql:
> SELECT INET_NTOA((INET_ATON('%{DHCP-Your-IP-Address}') &
> INET_ATON('%{%{DHCP-Subnet-Mask}:-255.255.255.0}')) +1) AS ip;}"
I had to work out something similar recently - and you can do it in
unlang by casting IP addresses to integers, doing the maths and then
casting back to IP.
For what you're doing the following would work:
update {
&Tmp-Integer-0 := &DHCP-Your-IP-Address
&Tmp-Integer-1 := &DHCP-Subnet-Mask
&Tmp-Integer-2 := "%{expr: (&Tmp-Integer-0 &
&Tmp-Integer-1) + 1}"
&DHCP-Router-Address := &Tmp-Integer-2
}
It's not pretty, but it works - and avoids any external calls.
Nick
--
Nick Porter
Porter Computing Ltd
Registered in England No 12659380
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freeradius.org/pipermail/freeradius-users/attachments/20241211/59e51f2a/attachment-0001.sig>
More information about the Freeradius-Users
mailing list