dhclient uses clock_gettime(CLOCK_MONOTONIC...) to track lease validity. But CLOCK_MONOTONIC doesn't guarantee any relationship with wall clock. For example clock_monotic starts counting from zero on each reboot of my Freebsd 14.2 in proxmox venv. #> cat dhclient.leases.vtnet2 | tail -4 renew 4 1970/1/1 22:10:57; rebind 4 1970/1/1 22:10:52; expire 4 1970/1/1 22:11:57; } Because of this, saved leases (/var/db/dhclient.leases*) are incorrectly considered usable as backup after a reboot.
pretty sure this is broken from https://cgit.freebsd.org/src/commit/?id=d854b4b2aa2b8b60e7fbca07e9637d035318aad5 Seen in CURRENT obviously, and should be fixed soon. This causes problems for DHCP in some cases as Andrey has stated. Reported in OpnSense too.
Should be fixed by https://reviews.freebsd.org/D49720 . Please test!
thanks Colin, LGTM here during #BSDNL
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=43d19e6a4c42ade0f276ceca18a09e2e3829fce4 commit 43d19e6a4c42ade0f276ceca18a09e2e3829fce4 Author: Colin Percival <cperciva@FreeBSD.org> AuthorDate: 2025-04-08 22:50:01 +0000 Commit: Colin Percival <cperciva@FreeBSD.org> CommitDate: 2025-04-13 02:09:56 +0000 dhclient: Keep two clocks Until July 2024, dhclient kept track of time as seconds-since-epoch as a time_t. This was a problem because (a) we wanted sub-second timeouts and (b) timeouts didn't always do the right thing if the system clock changed. Switching to using CLOCK_MONOTONIC and struct timespec fixed those issues but introduced a new problem: CLOCK_MONOTONIC values were being intepreted as seconds-since-epoch and written to the dhclient.leases file, causing confusion with DHCP leases expiring in early 1970. Attempt to compromise between these by keeping track of both times; any type within dhclient which is a time_t now refers to seconds past the epoch, while any struct timespec value is a CLOCK_MONOTONIC time. PR: 283256 Reviewed by: dch Fixes: f0a38976b01e ("dhclient: Use clock_gettime() instead of time()") Sponsored by: Amazon Differential Revision: https://reviews.freebsd.org/D49720 sbin/dhclient/dhclient.c | 50 +++++++++++++++++++++--------------------------- sbin/dhclient/dhcpd.h | 4 ++-- sbin/dhclient/dispatch.c | 14 +++++++++----- 3 files changed, 33 insertions(+), 35 deletions(-)