suricata
util-time.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2020 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 #ifdef OS_WIN32
195 /** \internal
196  * \brief wrapper around strftime on Windows to provide output
197  * compatible with posix %z
198  */
199 static inline void WinStrftime(const struct timeval *ts, const struct tm *t, char *str, size_t size)
200 {
201  char time_fmt[64] = { 0 };
202  char tz[6] = { 0 };
203  const long int tzdiff = -_timezone;
204  const int h = abs(_timezone) / 3600 + _daylight;
205  const int m = (abs(_timezone) % 3600) / 60;
206  snprintf(tz, sizeof(tz), "%c%02d%02d", tzdiff < 0 ? '-' : '+', h, m);
207  strftime(time_fmt, sizeof(time_fmt), "%Y-%m-%dT%H:%M:%S.%%06u", t);
208  snprintf(str, size, time_fmt, ts->tv_usec);
209  strlcat(str, tz, size); // append our timezone
210 }
211 #endif
212 
213 void CreateIsoTimeString (const struct timeval *ts, char *str, size_t size)
214 {
215  time_t time = ts->tv_sec;
216  struct tm local_tm;
217  memset(&local_tm, 0, sizeof(local_tm));
218  struct tm *t = (struct tm*)SCLocalTime(time, &local_tm);
219 
220  if (likely(t != NULL)) {
221 #ifdef OS_WIN32
222  WinStrftime(ts, t, str, size);
223 #else
224  char time_fmt[64] = { 0 };
225  int64_t usec = ts->tv_usec;
226  strftime(time_fmt, sizeof(time_fmt), "%Y-%m-%dT%H:%M:%S.%%06" PRIi64 "%z", t);
227  snprintf(str, size, time_fmt, usec);
228 #endif
229  } else {
230  snprintf(str, size, "ts-error");
231  }
232 }
233 
234 void CreateUtcIsoTimeString (const struct timeval *ts, char *str, size_t size)
235 {
236  time_t time = ts->tv_sec;
237  struct tm local_tm;
238  memset(&local_tm, 0, sizeof(local_tm));
239  struct tm *t = (struct tm*)SCUtcTime(time, &local_tm);
240 
241  if (likely(t != NULL)) {
242  char time_fmt[64] = { 0 };
243  strftime(time_fmt, sizeof(time_fmt), "%Y-%m-%dT%H:%M:%S", t);
244  snprintf(str, size, time_fmt, ts->tv_usec);
245  } else {
246  snprintf(str, size, "ts-error");
247  }
248 }
249 
250 void CreateFormattedTimeString (const struct tm *t, const char *fmt, char *str, size_t size)
251 {
252  if (likely(t != NULL)) {
253  strftime(str, size, fmt, t);
254  } else {
255  snprintf(str, size, "ts-error");
256  }
257 }
258 
259 struct tm *SCUtcTime(time_t timep, struct tm *result)
260 {
261  return gmtime_r(&timep, result);
262 }
263 
264 /*
265  * Time Caching code
266  */
267 
268 #ifndef TLS
269 /* OpenBSD does not support thread_local, so don't use time caching on BSD
270  */
271 struct tm *SCLocalTime(time_t timep, struct tm *result)
272 {
273  return localtime_r(&timep, result);
274 }
275 
276 void CreateTimeString (const struct timeval *ts, char *str, size_t size)
277 {
278  time_t time = ts->tv_sec;
279  struct tm local_tm;
280  struct tm *t = (struct tm*)SCLocalTime(time, &local_tm);
281 
282  if (likely(t != NULL)) {
283  snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u",
284  t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour,
285  t->tm_min, t->tm_sec, (uint32_t) ts->tv_usec);
286  } else {
287  snprintf(str, size, "ts-error");
288  }
289 }
290 
291 #else
292 
293 /* On systems supporting thread_local, use Per-thread values for caching
294  * in CreateTimeString */
295 
296 /* The maximum possible length of the time string.
297  * "%02d/%02d/%02d-%02d:%02d:%02d.%06u"
298  * Or "01/01/2013-15:42:21.123456", which is 26, so round up to 32. */
299 #define MAX_LOCAL_TIME_STRING 32
300 
301 static thread_local int mru_time_slot; /* Most recently used cached value */
302 static thread_local time_t last_local_time[2];
303 static thread_local short int cached_local_time_len[2];
304 static thread_local char cached_local_time[2][MAX_LOCAL_TIME_STRING];
305 
306 /* Per-thread values for caching SCLocalTime() These cached values are
307  * independent from the CreateTimeString cached values. */
308 static thread_local int mru_tm_slot; /* Most recently used local tm */
309 static thread_local time_t cached_minute_start[2];
310 static thread_local struct tm cached_local_tm[2];
311 
312 /** \brief Convert time_t into Year, month, day, hour and minutes.
313  * \param timep Time in seconds since defined date.
314  * \param result The structure into which the broken down time it put.
315  *
316  * To convert a time in seconds into year, month, day, hours, minutes
317  * and seconds, call localtime_r(), which uses the current time zone
318  * to compute these values. Note, glibc's localtime_r() aquires a lock
319  * each time it is called, which limits parallelism. To call
320  * localtime_r() less often, the values returned are cached for the
321  * current and previous minute and then seconds are adjusted to
322  * compute the returned result. This is valid as long as the
323  * difference between the start of the current minute and the current
324  * time is less than 60 seconds. Once the minute value changes, all
325  * the other values could change.
326  *
327  * Two values are cached to prevent thrashing when changing from one
328  * minute to the next. The two cached minutes are independent and are
329  * not required to be M and M+1. If more than two minutes are
330  * requested, the least-recently-used cached value is updated more
331  * often, the results are still correct, but performance will be closer
332  * to previous performance.
333  */
334 struct tm *SCLocalTime(time_t timep, struct tm *result)
335 {
336  /* Only get a new local time when the time crosses into a new
337  * minute. */
338  int mru = mru_tm_slot;
339  int lru = 1 - mru;
340  int mru_seconds = timep - cached_minute_start[mru];
341  int lru_seconds = timep - cached_minute_start[lru];
342  int new_seconds;
343  if (cached_minute_start[mru]==0 && cached_minute_start[lru]==0) {
344  localtime_r(&timep, &cached_local_tm[lru]);
345  /* Subtract seconds to get back to the start of the minute. */
346  new_seconds = cached_local_tm[lru].tm_sec;
347  cached_minute_start[lru] = timep - new_seconds;
348  mru = lru;
349  mru_tm_slot = mru;
350  } else if (lru_seconds > 0 && (mru_seconds >= 0 && mru_seconds <= 59)) {
351  /* Use most-recently cached time, adjusting the seconds. */
352  new_seconds = mru_seconds;
353  } else if (mru_seconds > 0 && (lru_seconds >= 0 && lru_seconds <= 59)) {
354  /* Use least-recently cached time, update to most recently used. */
355  new_seconds = lru_seconds;
356  mru = lru;
357  mru_tm_slot = mru;
358  } else {
359  /* Update least-recent cached time. */
360  if (localtime_r(&timep, &cached_local_tm[lru]) == NULL)
361  return NULL;
362  /* Subtract seconds to get back to the start of the minute. */
363  new_seconds = cached_local_tm[lru].tm_sec;
364  cached_minute_start[lru] = timep - new_seconds;
365  mru = lru;
366  mru_tm_slot = mru;
367  }
368  memcpy(result, &cached_local_tm[mru], sizeof(struct tm));
369  result->tm_sec = new_seconds;
370 
371  return result;
372 }
373 
374 /* Update the cached time string in cache index N, for the current minute. */
375 static int UpdateCachedTime(int n, time_t time)
376 {
377  struct tm local_tm;
378  struct tm *t = (struct tm *)SCLocalTime(time, &local_tm);
379  int cached_len = snprintf(cached_local_time[n], MAX_LOCAL_TIME_STRING,
380  "%02d/%02d/%02d-%02d:%02d:",
381  t->tm_mon + 1, t->tm_mday, t->tm_year + 1900,
382  t->tm_hour, t->tm_min);
383  cached_local_time_len[n] = cached_len;
384  /* Store the time of the beginning of the minute. */
385  last_local_time[n] = time - t->tm_sec;
386  mru_time_slot = n;
387 
388  return t->tm_sec;
389 }
390 
391 /** \brief Return a formatted string for the provided time.
392  *
393  * Cache the Month/Day/Year - Hours:Min part of the time string for
394  * the current minute. Copy that result into the the return string and
395  * then only print the seconds for each call.
396  */
397 void CreateTimeString (const struct timeval *ts, char *str, size_t size)
398 {
399  time_t time = ts->tv_sec;
400  int seconds;
401 
402  /* Only get a new local time when the time crosses into a new
403  * minute */
404  int mru = mru_time_slot;
405  int lru = 1 - mru;
406  int mru_seconds = time - last_local_time[mru];
407  int lru_seconds = time - last_local_time[lru];
408  if (last_local_time[mru]==0 && last_local_time[lru]==0) {
409  /* First time here, update both caches */
410  UpdateCachedTime(mru, time);
411  seconds = UpdateCachedTime(lru, time);
412  } else if (mru_seconds >= 0 && mru_seconds <= 59) {
413  /* Use most-recently cached time. */
414  seconds = mru_seconds;
415  } else if (lru_seconds >= 0 && lru_seconds <= 59) {
416  /* Use least-recently cached time. Change this slot to Most-recent */
417  seconds = lru_seconds;
418  mru_time_slot = lru;
419  } else {
420  /* Update least-recent cached time. Lock accessing local time
421  * function because it keeps any internal non-spin lock. */
422  seconds = UpdateCachedTime(lru, time);
423  }
424 
425  /* Copy the string up to the current minute then print the seconds
426  into the return string buffer. */
427  char *cached_str = cached_local_time[mru_time_slot];
428  int cached_len = cached_local_time_len[mru_time_slot];
429  if (cached_len >= (int)size)
430  cached_len = size;
431  memcpy(str, cached_str, cached_len);
432  snprintf(str + cached_len, size - cached_len,
433  "%02d.%06u",
434  seconds, (uint32_t) ts->tv_usec);
435 }
436 
437 #endif /* defined(__OpenBSD__) */
438 
439 /**
440  * \brief Convert broken-down time to seconds since Unix epoch.
441  *
442  * This function is based on: http://www.catb.org/esr/time-programming
443  * (released to the public domain).
444  *
445  * \param tp Pointer to broken-down time.
446  *
447  * \retval Seconds since Unix epoch.
448  */
449 time_t SCMkTimeUtc (struct tm *tp)
450 {
451  time_t result;
452  long year;
453 #define MONTHSPERYEAR 12
454  static const int mdays[MONTHSPERYEAR] =
455  { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
456 
457  year = 1900 + tp->tm_year + tp->tm_mon / MONTHSPERYEAR;
458  result = (year - 1970) * 365 + mdays[tp->tm_mon % MONTHSPERYEAR];
459  result += (year - 1968) / 4;
460  result -= (year - 1900) / 100;
461  result += (year - 1600) / 400;
462  if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0) &&
463  (tp->tm_mon % MONTHSPERYEAR) < 2)
464  result--;
465  result += tp->tm_mday - 1;
466  result *= 24;
467  result += tp->tm_hour;
468  result *= 60;
469  result += tp->tm_min;
470  result *= 60;
471  result += tp->tm_sec;
472 #ifndef OS_WIN32
473  if (tp->tm_gmtoff)
474  result -= tp->tm_gmtoff;
475 #endif
476  return result;
477 }
478 
479 /**
480  * \brief Parse a date string based on specified patterns.
481  *
482  * This function is based on GNU C library getdate.
483  *
484  * \param string Date string to parse.
485  * \param patterns String array containing patterns.
486  * \param num_patterns Number of patterns to check.
487  * \param tp Pointer to broken-down time.
488  *
489  * \retval 0 on success.
490  * \retval 1 on failure.
491  */
492 int SCStringPatternToTime (char *string, const char **patterns, int num_patterns,
493  struct tm *tp)
494 {
495  char *result = NULL;
496  int i = 0;
497 
498  /* Do the pattern matching */
499  for (i = 0; i < num_patterns; i++)
500  {
501  if (patterns[i] == NULL)
502  continue;
503 
504  tp->tm_hour = tp->tm_min = tp->tm_sec = 0;
505  tp->tm_year = tp->tm_mon = tp->tm_mday = tp->tm_wday = INT_MIN;
506  tp->tm_isdst = -1;
507 #ifndef OS_WIN32
508  tp->tm_gmtoff = 0;
509  tp->tm_zone = NULL;
510 #endif
511  result = strptime(string, patterns[i], tp);
512 
513  if (result && *result == '\0')
514  break;
515  }
516 
517  /* Return if no patterns matched */
518  if (result == NULL || *result != '\0')
519  return 1;
520 
521  /* Return if no date is given */
522  if (tp->tm_year == INT_MIN && tp->tm_mon == INT_MIN &&
523  tp->tm_mday == INT_MIN)
524  return 1;
525 
526  /* The first of the month is assumed, if only year and
527  month is given */
528  if (tp->tm_year != INT_MIN && tp->tm_mon != INT_MIN &&
529  tp->tm_mday <= 0)
530  tp->tm_mday = 1;
531 
532  return 0;
533 }
534 
535 /**
536  * \brief Convert epoch time to string pattern.
537  *
538  * This function converts epoch time to a string based on a pattern.
539  *
540  * \param epoch Epoch time.
541  * \param pattern String pattern.
542  * \param str Formated string.
543  * \param size Size of allocated string.
544  *
545  * \retval 0 on success.
546  * \retval 1 on failure.
547  */
548 int SCTimeToStringPattern (time_t epoch, const char *pattern, char *str, size_t size)
549 {
550  struct tm tm;
551  memset(&tm, 0, sizeof(tm));
552  struct tm *tp = (struct tm *)SCLocalTime(epoch, &tm);
553  char buffer[PATH_MAX] = { 0 };
554 
555  if (unlikely(tp == NULL)) {
556  return 1;
557  }
558 
559  int r = strftime(buffer, sizeof(buffer), pattern, tp);
560  if (r == 0) {
561  return 1;
562  }
563 
564  strlcpy(str, buffer, size);
565 
566  return 0;
567 }
568 
569 /**
570  * \brief Parse string containing time size (1m, 1h, etc).
571  *
572  * \param str String to parse.
573  *
574  * \retval size on success.
575  * \retval 0 on failure.
576  */
577 uint64_t SCParseTimeSizeString (const char *str)
578 {
579  uint64_t size = 0;
580  uint64_t modifier = 1;
581  char last = str[strlen(str)-1];
582 
583  switch (last)
584  {
585  case '0' ... '9':
586  break;
587  /* seconds */
588  case 's':
589  break;
590  /* minutes */
591  case 'm':
592  modifier = 60;
593  break;
594  /* hours */
595  case 'h':
596  modifier = 60 * 60;
597  break;
598  /* days */
599  case 'd':
600  modifier = 60 * 60 * 24;
601  break;
602  /* weeks */
603  case 'w':
604  modifier = 60 * 60 * 24 * 7;
605  break;
606  /* invalid */
607  default:
608  return 0;
609  }
610 
611  errno = 0;
612  size = strtoumax(str, NULL, 10);
613  if (errno) {
614  return 0;
615  }
616 
617  return (size * modifier);
618 }
619 
620 /**
621  * \brief Get seconds until a time unit changes.
622  *
623  * \param str String containing time type (minute, hour, etc).
624  * \param epoch Epoch time.
625  *
626  * \retval seconds.
627  */
628 uint64_t SCGetSecondsUntil (const char *str, time_t epoch)
629 {
630  uint64_t seconds = 0;
631  struct tm tm;
632  memset(&tm, 0, sizeof(tm));
633  struct tm *tp = (struct tm *)SCLocalTime(epoch, &tm);
634 
635  if (strcmp(str, "minute") == 0)
636  seconds = 60 - tp->tm_sec;
637  else if (strcmp(str, "hour") == 0)
638  seconds = (60 * (60 - tp->tm_min)) + (60 - tp->tm_sec);
639  else if (strcmp(str, "day") == 0)
640  seconds = (3600 * (24 - tp->tm_hour)) + (60 * (60 - tp->tm_min)) +
641  (60 - tp->tm_sec);
642 
643  return seconds;
644 }
645 
646 uint64_t SCTimespecAsEpochMillis(const struct timespec* ts)
647 {
648  return ts->tv_sec * 1000L + ts->tv_nsec / 1000000L;
649 }
SCParseTimeSizeString
uint64_t SCParseTimeSizeString(const char *str)
Parse string containing time size (1m, 1h, etc).
Definition: util-time.c:577
TmThreadsTimeSubsysIsReady
bool TmThreadsTimeSubsysIsReady(void)
Definition: tm-threads.c:2129
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:54
SCSpinDestroy
#define SCSpinDestroy
Definition: threads-debug.h:239
CreateIsoTimeString
void CreateIsoTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:213
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:628
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
CreateFormattedTimeString
void CreateFormattedTimeString(const struct tm *t, const char *fmt, char *str, size_t size)
Definition: util-time.c:250
threads.h
SCMkTimeUtc
time_t SCMkTimeUtc(struct tm *tp)
Convert broken-down time to seconds since Unix epoch.
Definition: util-time.c:449
SCSpinLock
#define SCSpinLock
Definition: threads-debug.h:235
m
SCMutex m
Definition: flow-hash.h:6
TmThreadsGetMinimalTimestamp
void TmThreadsGetMinimalTimestamp(struct timeval *ts)
Definition: tm-threads.c:2161
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:548
SCUtcTime
struct tm * SCUtcTime(time_t timep, struct tm *result)
Definition: util-time.c:259
util-debug.h
strptime
char * strptime(const char *__restrict, const char *__restrict, struct tm *__restrict)
Definition: util-strptime.c:97
strlcat
size_t strlcat(char *, const char *src, size_t siz)
Definition: util-strlcatu.c:45
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:646
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:271
CreateTimeString
void CreateTimeString(const struct timeval *ts, char *str, size_t size)
Definition: util-time.c:276
RunmodeIsUnittests
int RunmodeIsUnittests(void)
Definition: suricata.c:271
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:2112
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
SCSpinInit
#define SCSpinInit
Definition: threads-debug.h:238
str
#define str(s)
Definition: suricata-common.h:272
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:492
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:234
TimeInit
void TimeInit(void)
Definition: util-time.c:77