suricata
util-time.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2016 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  * \author Ken Steele <suricata@tilera.com>
23  *
24  * Time keeping for offline (non-live) packet handling (pcap files).
25  * And time string generation for alerts.
26  */
27 
28 /* Real time vs offline time
29  *
30  * When we run on live traffic, time handling is simple. Packets have a
31  * timestamp set by the capture method. Management threads can simply
32  * use 'gettimeofday' to know the current time. There should never be
33  * any serious gap between the two.
34  *
35  * In offline mode, things are dramatically different. Here we try to keep
36  * the time from the pcap, which means that if the packets are in 2011 the
37  * log output should also reflect this. Multiple issues:
38  * 1. merged pcaps might have huge time jumps or time going backward
39  * 2. slowly recorded pcaps may be processed much faster than their 'realtime'
40  * 3. management threads need a concept of what the 'current' time is for
41  * enforcing timeouts
42  * 4. due to (1) individual threads may have very different views on what
43  * the current time is. E.g. T1 processed packet 1 with TS X, while T2
44  * at the very same time processes packet 2 with TS X+100000s.
45  *
46  * In offline mode we keep the timestamp per thread. If a management thread
47  * needs current time, it will get the minimum of the threads' values. This
48  * is to avoid the problem that T2s time value might already trigger a flow
49  * timeout as the flow lastts + 100000s is almost certainly meaning the flow
50  * would be considered timed out.
51  */
52 
53 #ifdef OS_WIN32
54 /* for MinGW we need to set _POSIX_C_SOURCE before including
55  * sys/time.h. */
56 #ifndef _POSIX_C_SOURCE
57 #define _POSIX_C_SOURCE 200809L
58 #endif
59 #endif
60 
61 #include "suricata-common.h"
62 #include "detect.h"
63 #include "threads.h"
64 #include "tm-threads.h"
65 #include "util-debug.h"
66 
67 #ifdef UNITTESTS
68 static struct timeval current_time = { 0, 0 };
69 #endif
70 //static SCMutex current_time_mutex = SCMUTEX_INITIALIZER;
71 static SCSpinlock current_time_spinlock;
72 static bool live_time_tracking = true;
73 
74 struct tm *SCLocalTime(time_t timep, struct tm *result);
75 struct tm *SCUtcTime(time_t timep, struct tm *result);
76 
77 void TimeInit(void)
78 {
79  SCSpinInit(&current_time_spinlock, 0);
80 
81  /* Initialize Time Zone settings. */
82  tzset();
83 }
84 
85 void TimeDeinit(void)
86 {
87  SCSpinDestroy(&current_time_spinlock);
88 }
89 
90 bool TimeModeIsReady(void)
91 {
92  if (live_time_tracking)
93  return true;
95 }
96 
97 void TimeModeSetLive(void)
98 {
99  live_time_tracking = true;
100  SCLogDebug("live time mode enabled");
101 }
102 
104 {
105  live_time_tracking = false;
106  SCLogDebug("offline time mode enabled");
107 }
108 
109 bool TimeModeIsLive(void)
110 {
111  return live_time_tracking;
112 }
113 
114 void TimeSetByThread(const int thread_id, const struct timeval *tv)
115 {
116  if (live_time_tracking)
117  return;
118 
119  TmThreadsSetThreadTimestamp(thread_id, tv);
120 }
121 
122 #ifdef UNITTESTS
123 void TimeSet(struct timeval *tv)
124 {
125  if (live_time_tracking)
126  return;
127 
128  if (tv == NULL)
129  return;
130 
131  SCSpinLock(&current_time_spinlock);
132  current_time.tv_sec = tv->tv_sec;
133  current_time.tv_usec = tv->tv_usec;
134 
135  SCLogDebug("time set to %" PRIuMAX " sec, %" PRIuMAX " usec",
136  (uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec);
137 
138  SCSpinUnlock(&current_time_spinlock);
139 }
140 
141 /** \brief set the time to "gettimeofday" meant for testing */
143 {
144  struct timeval tv;
145  memset(&tv, 0x00, sizeof(tv));
146 
147  gettimeofday(&tv, NULL);
148 
149  TimeSet(&tv);
150 }
151 #endif
152 
153 void TimeGet(struct timeval *tv)
154 {
155  if (tv == NULL)
156  return;
157 
158  if (live_time_tracking) {
159  gettimeofday(tv, NULL);
160  } else {
161 #ifdef UNITTESTS
162  if (unlikely(RunmodeIsUnittests())) {
163  SCSpinLock(&current_time_spinlock);
164  tv->tv_sec = current_time.tv_sec;
165  tv->tv_usec = current_time.tv_usec;
166  SCSpinUnlock(&current_time_spinlock);
167  } else {
168 #endif
170 #ifdef UNITTESTS
171  }
172 #endif
173  }
174 
175  SCLogDebug("time we got is %" PRIuMAX " sec, %" PRIuMAX " usec",
176  (uintmax_t)tv->tv_sec, (uintmax_t)tv->tv_usec);
177 }
178 
179 #ifdef UNITTESTS
180 /** \brief increment the time in the engine
181  * \param tv_sec seconds to increment the time with */
182 void TimeSetIncrementTime(uint32_t tv_sec)
183 {
184  struct timeval tv;
185  memset(&tv, 0x00, sizeof(tv));
186  TimeGet(&tv);
187 
188  tv.tv_sec += tv_sec;
189 
190  TimeSet(&tv);
191 }
192 #endif
193 
194 void CreateIsoTimeString (const struct timeval *ts, char *str, size_t size)
195 {
196  time_t time = ts->tv_sec;
197  struct tm local_tm;
198  memset(&local_tm, 0, sizeof(local_tm));
199  struct tm *t = (struct tm*)SCLocalTime(time, &local_tm);
200  char time_fmt[64] = { 0 };
201 
202  if (likely(t != NULL)) {
203  strftime(time_fmt, sizeof(time_fmt), "%Y-%m-%dT%H:%M:%S.%%06u%z", t);
204  snprintf(str, size, time_fmt, ts->tv_usec);
205  } else {
206  snprintf(str, size, "ts-error");
207  }
208 }
209 
210 void CreateUtcIsoTimeString (const struct timeval *ts, char *str, size_t size)
211 {
212  time_t time = ts->tv_sec;
213  struct tm local_tm;
214  memset(&local_tm, 0, sizeof(local_tm));
215  struct tm *t = (struct tm*)SCUtcTime(time, &local_tm);
216  char time_fmt[64] = { 0 };
217 
218  if (likely(t != NULL)) {
219  strftime(time_fmt, sizeof(time_fmt), "%Y-%m-%dT%H:%M:%S", t);
220  snprintf(str, size, time_fmt, ts->tv_usec);
221  } else {
222  snprintf(str, size, "ts-error");
223  }
224 }
225 
226 void CreateFormattedTimeString (const struct tm *t, const char *fmt, char *str, size_t size)
227 {
228  if (likely(t != NULL && fmt != NULL && str != NULL)) {
229  strftime(str, size, fmt, t);
230  } else {
231  snprintf(str, size, "ts-error");
232  }
233 }
234 
235 struct tm *SCUtcTime(time_t timep, struct tm *result)
236 {
237  return gmtime_r(&timep, result);
238 }
239 
240 /*
241  * Time Caching code
242  */
243 
244 #ifndef TLS
245 /* OpenBSD does not support __thread, so don't use time caching on BSD
246  */
247 struct tm *SCLocalTime(time_t timep, struct tm *result)
248 {
249  return localtime_r(&timep, result);
250 }
251 
252 void CreateTimeString (const struct timeval *ts, char *str, size_t size)
253 {
254  time_t time = ts->tv_sec;
255  struct tm local_tm;
256  struct tm *t = (struct tm*)SCLocalTime(time, &local_tm);
257 
258  if (likely(t != NULL)) {
259  snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
260  t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,
261  t->tm_min, t->tm_sec, (uint32_t) ts->tv_usec);
262  } else {
263  snprintf(str, size, "ts-error");
264  }
265 }
266 
267 #else
268 
269 /* On systems supporting __thread, use Per-thread values for caching
270  * in CreateTimeString */
271 
272 /* The maximum possible length of the time string.
273  * "%02d/%02d/%02d-%02d:%02d:%02d.%06u"
274  * Or "01/01/2013-15:42:21.123456", which is 26, so round up to 32. */
275 #define MAX_LOCAL_TIME_STRING 32
276 
277 static __thread int mru_time_slot; /* Most recently used cached value */
278 static __thread time_t last_local_time[2];
279 static __thread short int cached_local_time_len[2];
280 static __thread char cached_local_time[2][MAX_LOCAL_TIME_STRING];
281 
282 /* Per-thread values for caching SCLocalTime() These cached values are
283  * independent from the CreateTimeString cached values. */
284 static __thread int mru_tm_slot; /* Most recently used local tm */
285 static __thread time_t cached_minute_start[2];
286 static __thread struct tm cached_local_tm[2];
287 
288 /** \brief Convert time_t into Year, month, day, hour and minutes.
289  * \param timep Time in seconds since defined date.
290  * \param result The structure into which the broken down time it put.
291  *
292  * To convert a time in seconds into year, month, day, hours, minutes
293  * and seconds, call localtime_r(), which uses the current time zone
294  * to compute these values. Note, glibc's localtime_r() aquires a lock
295  * each time it is called, which limits parallelism. To call
296  * localtime_r() less often, the values returned are cached for the
297  * current and previous minute and then seconds are adjusted to
298  * compute the returned result. This is valid as long as the
299  * difference between the start of the current minute and the current
300  * time is less than 60 seconds. Once the minute value changes, all
301  * the other values could change.
302  *
303  * Two values are cached to prevent thrashing when changing from one
304  * minute to the next. The two cached minutes are independent and are
305  * not required to be M and M+1. If more than two minutes are
306  * requested, the least-recently-used cached value is updated more
307  * often, the results are still correct, but performance will be closer
308  * to previous performance.
309  */
310 struct tm *SCLocalTime(time_t timep, struct tm *result)
311 {
312  /* Only get a new local time when the time crosses into a new
313  * minute. */
314  int mru = mru_tm_slot;
315  int lru = 1 - mru;
316  int mru_seconds = timep - cached_minute_start[mru];
317  int lru_seconds = timep - cached_minute_start[lru];
318  int new_seconds;
319  if (cached_minute_start[mru]==0 && cached_minute_start[lru]==0) {
320  localtime_r(&timep, &cached_local_tm[lru]);
321  /* Subtract seconds to get back to the start of the minute. */
322  new_seconds = cached_local_tm[lru].tm_sec;
323  cached_minute_start[lru] = timep - new_seconds;
324  mru = lru;
325  mru_tm_slot = mru;
326  } else if (lru_seconds > 0 && (mru_seconds >= 0 && mru_seconds <= 59)) {
327  /* Use most-recently cached time, adjusting the seconds. */
328  new_seconds = mru_seconds;
329  } else if (mru_seconds > 0 && (lru_seconds >= 0 && lru_seconds <= 59)) {
330  /* Use least-recently cached time, update to most recently used. */
331  new_seconds = lru_seconds;
332  mru = lru;
333  mru_tm_slot = mru;
334  } else {
335  /* Update least-recent cached time. */
336  if (localtime_r(&timep, &cached_local_tm[lru]) == NULL)
337  return NULL;
338  /* Subtract seconds to get back to the start of the minute. */
339  new_seconds = cached_local_tm[lru].tm_sec;
340  cached_minute_start[lru] = timep - new_seconds;
341  mru = lru;
342  mru_tm_slot = mru;
343  }
344  memcpy(result, &cached_local_tm[mru], sizeof(struct tm));
345  result->tm_sec = new_seconds;
346 
347  return result;
348 }
349 
350 /* Update the cached time string in cache index N, for the current minute. */
351 static int UpdateCachedTime(int n, time_t time)
352 {
353  struct tm local_tm;
354  struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
355  int cached_len = snprintf(cached_local_time[n], MAX_LOCAL_TIME_STRING,
356  "%02d/%02d/%02d-%02d:%02d:",
357  t->tm_mon + 1, t->tm_mday, t->tm_year + 1900,
358  t->tm_hour, t->tm_min);
359  cached_local_time_len[n] = cached_len;
360  /* Store the time of the beginning of the minute. */
361  last_local_time[n] = time - t->tm_sec;
362  mru_time_slot = n;
363 
364  return t->tm_sec;
365 }
366 
367 /** \brief Return a formatted string for the provided time.
368  *
369  * Cache the Month/Day/Year - Hours:Min part of the time string for
370  * the current minute. Copy that result into the the return string and
371  * then only print the seconds for each call.
372  */
373 void CreateTimeString (const struct timeval *ts, char *str, size_t size)
374 {
375  time_t time = ts->tv_sec;
376  int seconds;
377 
378  /* Only get a new local time when the time crosses into a new
379  * minute */
380  int mru = mru_time_slot;
381  int lru = 1 - mru;
382  int mru_seconds = time - last_local_time[mru];
383  int lru_seconds = time - last_local_time[lru];
384  if (last_local_time[mru]==0 && last_local_time[lru]==0) {
385  /* First time here, update both caches */
386  UpdateCachedTime(mru, time);
387  seconds = UpdateCachedTime(lru, time);
388  } else if (mru_seconds >= 0 && mru_seconds <= 59) {
389  /* Use most-recently cached time. */
390  seconds = mru_seconds;
391  } else if (lru_seconds >= 0 && lru_seconds <= 59) {
392  /* Use least-recently cached time. Change this slot to Most-recent */
393  seconds = lru_seconds;
394  mru_time_slot = lru;
395  } else {
396  /* Update least-recent cached time. Lock accessing local time
397  * function because it keeps any internal non-spin lock. */
398  seconds = UpdateCachedTime(lru, time);
399  }
400 
401  /* Copy the string up to the current minute then print the seconds
402  into the return string buffer. */
403  char *cached_str = cached_local_time[mru_time_slot];
404  int cached_len = cached_local_time_len[mru_time_slot];
405  if (cached_len >= (int)size)
406  cached_len = size;
407  memcpy(str, cached_str, cached_len);
408  snprintf(str + cached_len, size - cached_len,
409  "%02d.%06u",
410  seconds, (uint32_t) ts->tv_usec);
411 }
412 
413 #endif /* defined(__OpenBSD__) */
414 
415 /**
416  * \brief Convert broken-down time to seconds since Unix epoch.
417  *
418  * This function is based on: http://www.catb.org/esr/time-programming
419  * (released to the public domain).
420  *
421  * \param tp Pointer to broken-down time.
422  *
423  * \retval Seconds since Unix epoch.
424  */
425 time_t SCMkTimeUtc (struct tm *tp)
426 {
427  time_t result;
428  long year;
429 #define MONTHSPERYEAR 12
430  static const int mdays[MONTHSPERYEAR] =
431  { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
432 
433  year = 1900 + tp->tm_year + tp->tm_mon / MONTHSPERYEAR;
434  result = (year - 1970) * 365 + mdays[tp->tm_mon % MONTHSPERYEAR];
435  result += (year - 1968) / 4;
436  result -= (year - 1900) / 100;
437  result += (year - 1600) / 400;
438  if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0) &&
439  (tp->tm_mon % MONTHSPERYEAR) < 2)
440  result--;
441  result += tp->tm_mday - 1;
442  result *= 24;
443  result += tp->tm_hour;
444  result *= 60;
445  result += tp->tm_min;
446  result *= 60;
447  result += tp->tm_sec;
448 #ifndef OS_WIN32
449  if (tp->tm_gmtoff)
450  result -= tp->tm_gmtoff;
451 #endif
452  return result;
453 }
454 
455 /**
456  * \brief Parse a date string based on specified patterns.
457  *
458  * This function is based on GNU C library getdate.
459  *
460  * \param string Date string to parse.
461  * \param patterns String array containing patterns.
462  * \param num_patterns Number of patterns to check.
463  * \param tp Pointer to broken-down time.
464  *
465  * \retval 0 on success.
466  * \retval 1 on failure.
467  */
468 int SCStringPatternToTime (char *string, const char **patterns, int num_patterns,
469  struct tm *tp)
470 {
471  char *result = NULL;
472  int i = 0;
473 
474  /* Do the pattern matching */
475  for (i = 0; i < num_patterns; i++)
476  {
477  if (patterns[i] == NULL)
478  continue;
479 
480  tp->tm_hour = tp->tm_min = tp->tm_sec = 0;
481  tp->tm_year = tp->tm_mon = tp->tm_mday = tp->tm_wday = INT_MIN;
482  tp->tm_isdst = -1;
483 #ifndef OS_WIN32
484  tp->tm_gmtoff = 0;
485  tp->tm_zone = NULL;
486 #endif
487  result = strptime(string, patterns[i], tp);
488 
489  if (result && *result == '\0')
490  break;
491  }
492 
493  /* Return if no patterns matched */
494  if (result == NULL || *result != '\0')
495  return 1;
496 
497  /* Return if no date is given */
498  if (tp->tm_year == INT_MIN && tp->tm_mon == INT_MIN &&
499  tp->tm_mday == INT_MIN)
500  return 1;
501 
502  /* The first of the month is assumed, if only year and
503  month is given */
504  if (tp->tm_year != INT_MIN && tp->tm_mon != INT_MIN &&
505  tp->tm_mday <= 0)
506  tp->tm_mday = 1;
507 
508  return 0;
509 }
510 
511 /**
512  * \brief Convert epoch time to string pattern.
513  *
514  * This function converts epoch time to a string based on a pattern.
515  *
516  * \param epoch Epoch time.
517  * \param pattern String pattern.
518  * \param str Formated string.
519  * \param size Size of allocated string.
520  *
521  * \retval 0 on success.
522  * \retval 1 on failure.
523  */
524 int SCTimeToStringPattern (time_t epoch, const char *pattern, char *str, size_t size)
525 {
526  struct tm tm;
527  memset(&tm, 0, sizeof(tm));
528  struct tm *tp = (struct tm *)SCLocalTime(epoch, &tm);
529  char buffer[PATH_MAX] = { 0 };
530 
531  if (unlikely(tp == NULL)) {
532  return 1;
533  }
534 
535  int r = strftime(buffer, sizeof(buffer), pattern, tp);
536  if (r == 0) {
537  return 1;
538  }
539 
540  strlcpy(str, buffer, size);
541 
542  return 0;
543 }
544 
545 /**
546  * \brief Parse string containing time size (1m, 1h, etc).
547  *
548  * \param str String to parse.
549  *
550  * \retval size on success.
551  * \retval 0 on failure.
552  */
553 uint64_t SCParseTimeSizeString (const char *str)
554 {
555  uint64_t size = 0;
556  uint64_t modifier = 1;
557  char last = str[strlen(str)-1];
558 
559  switch (last)
560  {
561  case '0' ... '9':
562  break;
563  /* seconds */
564  case 's':
565  break;
566  /* minutes */
567  case 'm':
568  modifier = 60;
569  break;
570  /* hours */
571  case 'h':
572  modifier = 60 * 60;
573  break;
574  /* days */
575  case 'd':
576  modifier = 60 * 60 * 24;
577  break;
578  /* weeks */
579  case 'w':
580  modifier = 60 * 60 * 24 * 7;
581  break;
582  /* invalid */
583  default:
584  return 0;
585  }
586 
587  errno = 0;
588  size = strtoumax(str, NULL, 10);
589  if (errno) {
590  return 0;
591  }
592 
593  return (size * modifier);
594 }
595 
596 /**
597  * \brief Get seconds until a time unit changes.
598  *
599  * \param str String containing time type (minute, hour, etc).
600  * \param epoch Epoch time.
601  *
602  * \retval seconds.
603  */
604 uint64_t SCGetSecondsUntil (const char *str, time_t epoch)
605 {
606  uint64_t seconds = 0;
607  struct tm tm;
608  memset(&tm, 0, sizeof(tm));
609  struct tm *tp = (struct tm *)SCLocalTime(epoch, &tm);
610 
611  if (strcmp(str, "minute") == 0)
612  seconds = 60 - tp->tm_sec;
613  else if (strcmp(str, "hour") == 0)
614  seconds = (60 * (60 - tp->tm_min)) + (60 - tp->tm_sec);
615  else if (strcmp(str, "day") == 0)
616  seconds = (3600 * (24 - tp->tm_hour)) + (60 * (60 - tp->tm_min)) +
617  (60 - tp->tm_sec);
618 
619  return seconds;
620 }
621 
622 uint64_t SCTimespecAsEpochMillis(const struct timespec* ts)
623 {
624  return ts->tv_sec * 1000L + ts->tv_nsec / 1000000L;
625 }
SCParseTimeSizeString
uint64_t SCParseTimeSizeString(const char *str)
Parse string containing time size (1m, 1h, etc).
Definition: util-time.c:553
TmThreadsTimeSubsysIsReady
bool TmThreadsTimeSubsysIsReady(void)
Definition: tm-threads.c:2114
tm-threads.h
TimeSetByThread
void TimeSetByThread(const int thread_id, const struct timeval *tv)
Definition: util-time.c:114
ts
uint64_t ts
Definition: source-erf-file.c:2
SCSpinDestroy
#define SCSpinDestroy
Definition: threads-debug.h:239
CreateIsoTimeString
void CreateIsoTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:194
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SCGetSecondsUntil
uint64_t SCGetSecondsUntil(const char *str, time_t epoch)
Get seconds until a time unit changes.
Definition: util-time.c:604
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:335
CreateFormattedTimeString
void CreateFormattedTimeString(const struct tm *t, const char *fmt, char *str, size_t size)
Definition: util-time.c:226
threads.h
SCMkTimeUtc
time_t SCMkTimeUtc(struct tm *tp)
Convert broken-down time to seconds since Unix epoch.
Definition: util-time.c:425
SCSpinLock
#define SCSpinLock
Definition: threads-debug.h:235
TmThreadsGetMinimalTimestamp
void TmThreadsGetMinimalTimestamp(struct timeval *ts)
Definition: tm-threads.c:2146
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
SCTimeToStringPattern
int SCTimeToStringPattern(time_t epoch, const char *pattern, char *str, size_t size)
Convert epoch time to string pattern.
Definition: util-time.c:524
SCUtcTime
struct tm * SCUtcTime(time_t timep, struct tm *result)
Definition: util-time.c:235
util-debug.h
strptime
char * strptime(const char *__restrict, const char *__restrict, struct tm *__restrict)
Definition: util-strptime.c:97
TimeSetToCurrentTime
void TimeSetToCurrentTime(void)
set the time to "gettimeofday" meant for testing
Definition: util-time.c:142
SCTimespecAsEpochMillis
uint64_t SCTimespecAsEpochMillis(const struct timespec *ts)
Definition: util-time.c:622
detect.h
TimeModeIsReady
bool TimeModeIsReady(void)
Definition: util-time.c:90
SCSpinUnlock
#define SCSpinUnlock
Definition: threads-debug.h:237
TimeModeIsLive
bool TimeModeIsLive(void)
Definition: util-time.c:109
TimeSetIncrementTime
void TimeSetIncrementTime(uint32_t tv_sec)
increment the time in the engine
Definition: util-time.c:182
SCLocalTime
struct tm * SCLocalTime(time_t timep, struct tm *result)
Definition: util-time.c:247
CreateTimeString
void CreateTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:252
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:264
TimeModeSetLive
void TimeModeSetLive(void)
Definition: util-time.c:97
MONTHSPERYEAR
#define MONTHSPERYEAR
TimeModeSetOffline
void TimeModeSetOffline(void)
Definition: util-time.c:103
suricata-common.h
TmThreadsSetThreadTimestamp
void TmThreadsSetThreadTimestamp(const int id, const struct timeval *ts)
Definition: tm-threads.c:2097
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
SCSpinInit
#define SCSpinInit
Definition: threads-debug.h:238
str
#define str(s)
Definition: suricata-common.h:256
TimeDeinit
void TimeDeinit(void)
Definition: util-time.c:85
SCSpinlock
#define SCSpinlock
Definition: threads-debug.h:234
TimeGet
void TimeGet(struct timeval *tv)
Definition: util-time.c:153
likely
#define likely(expr)
Definition: util-optimize.h:32
SCStringPatternToTime
int SCStringPatternToTime(char *string, const char **patterns, int num_patterns, struct tm *tp)
Parse a date string based on specified patterns.
Definition: util-time.c:468
TimeSet
void TimeSet(struct timeval *tv)
Definition: util-time.c:123
CreateUtcIsoTimeString
void CreateUtcIsoTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:210
TimeInit
void TimeInit(void)
Definition: util-time.c:77