Unlang operations with IP addresses

Ľudovít Mikula ludovit.mikula at mikori.sk
Tue Dec 10 21:29:15 UTC 2024


Thank you, was trying to wrap my head around it in unlang.

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;}"

Ludo

On 10. 12. 2024 21:51, Alan DeKok wrote:
> On Dec 10, 2024, at 1:44 PM, Ľudovít Mikula <ludovit.mikula at mikori.sk> wrote:
>>
>> Ok, I've got the question wrong.
>>
>> What I want to do:  based on assigned IP address and subnet mask, compute first IP address from the range from which the IP address was assigned.
>>
>> Example:
>>
>> given:
>>   DHCP-Your-IP-Address: 192.168.10.20
>>   DHCP-Subnet-Mask: 255.255.255.0
>>
>> would produce:
>>   DHCP-Router-Address: 192.168.10.1
> 
>   Hmm... I'm not sure that's easy to do in v3.  In v4 it's easy:
> 
> ip-address thing = (DHCP-Your-IP-Address & ((uint32) DHCP-Subnet-Mask)) + 1
> 
>   In v3, I think this is about the only situation where you'd have to use something other than unlang.  :(
> 
>   Alan DeKok.
> -
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html



More information about the Freeradius-Users mailing list