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