64-bit time_t safe lease time

Joerg Wunsch j at ida.interface-business.de
Sun Jun 27 07:00:44 PDT 2004

[Cc to sparc64 at freebsd.org, since that's probably the group of users
currently most interested in the matter.]

As Joerg Wunsch wrote:

> Ad Martin Blapp wrote:
> > Does it help if you define TIME as int32_t ?

> Yes, that helps quite a bit.  Well, now it starts to send requests quickly,
> but it sends the requests to a random dst port so the DHCP server never
> responds:
> 11:57:57.075934 >  (request) xid:0x4f353b0d vend-rfc1048 DHCP:DISCOVER PR:SM+BR+TZ+DG+DN+NS+HN [tos 0x10] 
> ^C

The problem was that GET_TIME() (first called in script_go())
clobbered part of sockaddr_broadcast.  The memory area it clobbers
looks a bit surprising to me, but the actual error became obvious
then: calling time() on a TIME* object, when sizeof(time_t) !=
sizeof(TIME) is just an error.

As a workaround, I added the following inline function:

Index: includes/cf/freebsd.h
RCS file: /home/ncvs/src/contrib/isc-dhcp/includes/cf/freebsd.h,v
retrieving revision 1.7
diff -u -r1.7 freebsd.h
--- includes/cf/freebsd.h	26 Jun 2004 10:37:42 -0000	1.7
+++ includes/cf/freebsd.h	27 Jun 2004 13:47:48 -0000
@@ -79,8 +79,14 @@
 /* Time stuff... */
 #include <sys/time.h>
-#define TIME time_t
-#define GET_TIME(x)	time ((x))
+#define TIME int32_t
+static __inline void
+freebsd_get_time(TIME *tp) {
+	time_t now;
+	time(&now);
+	*tp = (TIME)now;
+#define GET_TIME(x)	freebsd_get_time ((x))
 #define HAVE_SA_LEN
That suffices as a workaround, though I think the code should be fixed
to not assume a particular integer width for time_t.  OK, year 2038 is
still somewhat ahead. ;-)

# dhclient -v gem0
Internet Systems Consortium DHCP Client V3.0.1rc14
Copyright 2004 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/products/DHCP

Listening on BPF/gem0/08:00:20:fe:a2:6e
Sending on   BPF/gem0/08:00:20:fe:a2:6e
Sending on   Socket/fallback
DHCPDISCOVER on gem0 to port 67 interval 7
DHCPREQUEST on gem0 to port 67
bound to -- renewal in 40644 seconds.

Btw., that's without Dag-Erling's patch.  I cannot fully verifiy the
validity of the 40644 seconds above, but the default lease time here
is 86400, and the same lease has been given to that machine before.

As a note to the sparc64 at freebsd.org listeners, the above assumes you
upgraded src/contrib/isc-dhcp and src/sbin/dhclient to Martin's
yesterday's import of V3.0.1rc14.  There seem to be no further side
effects from this, i. e. you don't necessarily need to upgrade the
entire world right now.

J"org Wunsch					       Unix support engineer
joerg_wunsch at interface-systems.de        http://www.interface-systems.de/~j/

More information about the freebsd-sparc64 mailing list