dhcpcd-discuss

Re: interface flag, lease expire

Roy Marples

Sat Jul 20 19:02:38 2019

Hi Matěj

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.

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.

Roy

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