From 0475d17e1ce34e6b2471d17a102b7c2a2d1427c7 Mon Sep 17 00:00:00 2001 From: james Date: Sat, 12 Nov 2005 10:59:41 +0000 Subject: Reduce sensitivity to system clock instability and backtracks. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@799 e7ae566f-a301-0410-adde-c780ea21d3b5 --- otime.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'otime.h') diff --git a/otime.h b/otime.h index 974d0af..6744c4d 100644 --- a/otime.h +++ b/otime.h @@ -54,7 +54,39 @@ const char* time_string (time_t t, int usec, bool show_usec, struct gc_arena *gc const char *tv_string (const struct timeval *tv, struct gc_arena *gc); const char *tv_string_abs (const struct timeval *tv, struct gc_arena *gc); -extern volatile time_t now; /* updated frequently to time(NULL) */ +extern time_t now; /* updated frequently to time(NULL) */ + +#if TIME_BACKTRACK_PROTECTION + +void update_now (const time_t system_time); + +static inline void +update_time (void) +{ + update_now (time (NULL)); +} + +#ifdef HAVE_GETTIMEOFDAY + +extern time_t now_usec; +void update_now_usec (struct timeval *tv); + +static inline int +openvpn_gettimeofday (struct timeval *tv, void *tz) +{ + const int status = gettimeofday (tv, tz); + if (!status) + { + update_now_usec (tv); + tv->tv_sec = now; + tv->tv_usec = now_usec; + } + return status; +} + +#endif + +#else static inline void update_time (void) @@ -64,6 +96,27 @@ update_time (void) now = real_time; } +#ifdef HAVE_GETTIMEOFDAY + +static inline int +openvpn_gettimeofday (struct timeval *tv, void *tz) +{ + return gettimeofday (tv, tz); +} + +#endif + +#endif + +static inline time_t +openvpn_time (time_t *t) +{ + update_time (); + if (t) + *t = now; + return now; +} + static inline void tv_clear (struct timeval *tv) { -- cgit v1.2.3