Unlang operations with IP addresses
Ľudovít Mikula
ludovit.mikula at mikori.sk
Wed Dec 11 07:58:40 UTC 2024
Thank you Nick, that's perfect!
I was trying to do exactly the same, but couldn't find a way to cast the
IPs ... turns out I was overcomplicating it :)
Ludo
On 11. 12. 2024 8:54, Nick Porter wrote:
> 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
>
>
> -
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
More information about the Freeradius-Users
mailing list