diff options
author | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2005-11-12 10:59:41 +0000 |
---|---|---|
committer | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2005-11-12 10:59:41 +0000 |
commit | 0475d17e1ce34e6b2471d17a102b7c2a2d1427c7 (patch) | |
tree | 33e9d066a65da9025ecabd2f42f1612c1fd11e7d /otime.h | |
parent | Fixed minor typos in --remote-cert-* documentation. (diff) | |
download | openvpn-0475d17e1ce34e6b2471d17a102b7c2a2d1427c7.tar.xz |
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
Diffstat (limited to '')
-rw-r--r-- | otime.h | 55 |
1 files changed, 54 insertions, 1 deletions
@@ -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) { |