summaryrefslogtreecommitdiffstats
path: root/otime.h
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2005-11-12 10:59:41 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2005-11-12 10:59:41 +0000
commit0475d17e1ce34e6b2471d17a102b7c2a2d1427c7 (patch)
tree33e9d066a65da9025ecabd2f42f1612c1fd11e7d /otime.h
parentf19f12c8b90bfefc716c6e359bc10ab1a53c74d8 (diff)
downloadopenvpn-0475d17e1ce34e6b2471d17a102b7c2a2d1427c7.tar.gz
openvpn-0475d17e1ce34e6b2471d17a102b7c2a2d1427c7.tar.xz
openvpn-0475d17e1ce34e6b2471d17a102b7c2a2d1427c7.zip
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 'otime.h')
-rw-r--r--otime.h55
1 files changed, 54 insertions, 1 deletions
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)
{