Dhclient and time change

Pavel Zhukov pzhukov at redhat.com
Wed Sep 6 10:14:58 UTC 2017

Hello DHCP hackers!

dhcp (as well as libisc) uses gettimeofday() to work with time
(timers). As the result we have easily reproducible bug:
1) Wait for ip address to be obtained.
2) Adjust time (via NTP or date command) few hours back
3) Once lease is expired dhclient doesn't renew it because it waits for
time before adjustment

The bug appears when system administrator tries to install OS on new HW,
if HW without RTC is used etc. So it's not cosmetic. 

In Fedora/RHEL/CentOS it's even worse once we have implemented lifetyme for all
addresses (not only for IPv6) as the result the address is dropped and
user ends up without any network connectivity [1][2][3]

I'm trying to fix it downstream and first attempt is using simple wrapper
around clock_gettime() if system has one [4] and use existed variable
epoch to keep "start time". The code change is trivial and fixes this
particular bug (dhclient renews IP in time) but "old" timestamps are
written into the leases file as the result. and I'm stuck now. From one
hand it's a display issue only but it's a regression from the users
point of view.  And this approach is not portable and Linux specific. 

What do you think? Does it make sense to screw timestamp in leases but
have proper (renewed) IP address? I'm not familiar with
Windows/MacOS/etc so not sure if something similar to CLOCK_BOOTTIME or
CLOCK_MONOTONIC exists there (but it should).
Are there changes in this area  planned for 4.4 release?

[1] https://bugzilla.redhat.com/show_bug.cgi?id=916116
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1093803
[3] https://bugzilla.redhat.com/show_bug.cgi?id=1205369


+gettimeofday_monotonic (struct timeval *tv, struct timezone *tz) {
+  struct timespec ts;
+  if (clock_gettime(CLOCK_BOOTTIME, &ts) != ISC_R_SUCCESS)
+     return ISC_R_UNEXPECTED;
+  tv->tv_sec = ts.tv_sec + epoch.seconds;   // epoch.seconds = tv.tv_sec - ts.tv_sec (static variable)
+  tv->tv_usec = (suseconds_t) ts.tv_nsec % 1000000 + epoch.nanosecs; // FIXME ?? 
+  return ISC_R_SUCCESS;

Red Hat 
pzhukov at redhat.com    IM: IRC: landgraf


More information about the dhcp-workers mailing list