dhcpcd-discuss

Re: interface flag, lease expire

Matěj Grégr

Tue Jul 23 13:25:19 2019

On 22.07.2019 14:40, Roy Marples wrote:
> On 20/07/2019 20:02, Roy Marples wrote:
>> On 20/07/2019 14:50, Matěj Grégr wrote:
>>> 1) I would like to detect if an IPv4 address is assigned via dhcpcd or
>>> set up statically by an administrator. isc-dhclient sets dynamic flag
>>> for an ipv4 address. e.g.
>>>
>>> dhclient
>>> inet 192.168.1.202/24 brd 192.168.1.255 scope global dynamic tge3
>>>     valid_lft 26574sec preferred_lft 26574sec
>>>
>>> but it's not the case for dhcpcd
>>>
>>> dhcpcd
>>> inet 192.168.1.202/24 brd 192.168.1.255 scope global noprefixroute tge3
>>>     valid_lft forever preferred_lft forever
>>>
>>>  From iproute2 manpage it looks like, the dynamic flag should be
>>> probably
>>> used for IPv6 only, so I am not sure if dhclient behavior is correct,
>>> but it really helps to distinguish between static addresses and
>>> addresses assigned by dhcp. Would you accept a patch to enable setting
>>> the flag? Currently I compare the address listed in a lease file with
>>> the address configured on the interface, but it's not so nice.
>>
>> This isn't actually quite so trivial.
>> I need to give the address a lifetime and there currently isn't
>> infrastructure for it in dhcpcd - for IPv4 addresses anyway.
>>
>> I'll look at adding this over the next few days/weeks.
> 
> Added in a few patches:
> https://roy.marples.name/cgit/dhcpcd.git/commit/?id=d1468fbdad0e288b23c9e5181d1de4476691ae61
> 
> https://roy.marples.name/cgit/dhcpcd.git/commit/?id=ac7a941ecbd1a129d7857f724e10e32ad4fd5748
> 
> https://roy.marples.name/cgit/dhcpcd.git/commit/?id=54c45c961a0a86f9c100d6da97c9004c179cea63
> 

Just for the list archive. The patches work great. The dynamic flag is
set for the interface, together with valid/preferred timers. Awesome
work. Thanks!

>> 2) Is it possible to find out somewhere when a lease will expire? dhcpcd
>> -U doesn't list this information and I am puzzled where to find it.
>
> # This command works fine on NetBSD
> $ date -d @$(($(stat -f %m /var/db/dhcpcd/$interface.lease) + $(dhcpcd
> -U4 $interface | sed -ne 's/dhcp_lease_time=\(.*\)/\1/p')))
>
> Or basically take the lease file's modification time as when the lease
> was assgined and add the duration of the lease to it.
>

Thanks for the hint. Linux use slightly different syntax (e.g. stat -c
%Y), but that doesn't matter. With your latest patches it's also
possible to obtain the information from valid timer using ip command.

Thank you Roy!
M.

Follow-Ups:
Re: interface flag, lease expireRoy Marples
References:
interface flag, lease expireMatěj Grégr
Re: interface flag, lease expireRoy Marples
Re: interface flag, lease expireRoy Marples
Archive administrator: postmaster@marples.name