suricata
flow-manager.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2024 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 Anoop Saldanha <anoopsaldanha@gmail.com>
22  * \author Victor Julien <victor@inliniac.net>
23  */
24 
25 #include "suricata-common.h"
26 #include "suricata.h"
27 #include "conf.h"
28 #include "threadvars.h"
29 #include "tm-threads.h"
30 #include "runmodes.h"
31 
32 
33 #include "flow.h"
34 #include "flow-queue.h"
35 #include "flow-hash.h"
36 #include "flow-util.h"
37 #include "flow-private.h"
38 #include "flow-timeout.h"
39 #include "flow-manager.h"
40 #include "flow-storage.h"
41 #include "flow-spare-pool.h"
42 #include "flow-callbacks.h"
43 
44 #include "stream-tcp.h"
45 #include "stream-tcp-cache.h"
46 
47 #include "util-device-private.h"
48 
49 #include "util-debug.h"
50 
51 #include "threads.h"
53 
54 #include "host-timeout.h"
55 #include "defrag-hash.h"
56 #include "defrag-timeout.h"
57 #include "ippair-timeout.h"
58 #include "rust.h"
59 #include "app-layer-htp-range.h"
60 
61 #include "output-flow.h"
62 
63 #include "runmode-unix-socket.h"
64 
65 /** queue to pass flows to cleanup/log thread(s) */
67 
68 /* multi flow manager support */
69 static uint32_t flowmgr_number = 1;
70 /* atomic counter for flow managers, to assign instance id */
71 SC_ATOMIC_DECLARE(uint32_t, flowmgr_cnt);
72 
73 /* multi flow recycler support */
74 static uint32_t flowrec_number = 1;
75 /* atomic counter for flow recyclers, to assign instance id */
76 SC_ATOMIC_DECLARE(uint32_t, flowrec_cnt);
77 SC_ATOMIC_DECLARE(uint32_t, flowrec_busy);
78 SC_ATOMIC_EXTERN(unsigned int, flow_flags);
79 
80 static SCCtrlCondT flow_manager_ctrl_cond = PTHREAD_COND_INITIALIZER;
81 static SCCtrlMutex flow_manager_ctrl_mutex = PTHREAD_MUTEX_INITIALIZER;
82 static SCCtrlCondT flow_recycler_ctrl_cond = PTHREAD_COND_INITIALIZER;
83 static SCCtrlMutex flow_recycler_ctrl_mutex = PTHREAD_MUTEX_INITIALIZER;
84 
86 {
87  SCCtrlMutexLock(&flow_manager_ctrl_mutex);
88  SCCtrlCondSignal(&flow_manager_ctrl_cond);
89  SCCtrlMutexUnlock(&flow_manager_ctrl_mutex);
90 }
91 
93 {
94  SCCtrlMutexLock(&flow_recycler_ctrl_mutex);
95  SCCtrlCondSignal(&flow_recycler_ctrl_cond);
96  SCCtrlMutexUnlock(&flow_recycler_ctrl_mutex);
97 }
98 
99 void FlowTimeoutsInit(void)
100 {
101  SC_ATOMIC_SET(flow_timeouts, flow_timeouts_normal);
102 }
103 
105 {
106  SC_ATOMIC_SET(flow_timeouts, flow_timeouts_emerg);
107 }
108 
109 typedef struct FlowTimeoutCounters_ {
110  uint32_t rows_checked;
111  uint32_t rows_skipped;
112  uint32_t rows_empty;
113  uint32_t rows_maxlen;
114 
115  uint32_t flows_checked;
116  uint32_t flows_notimeout;
117  uint32_t flows_timeout;
118  uint32_t flows_removed;
119  uint32_t flows_aside;
121 
122  uint32_t bypassed_count;
123  uint64_t bypassed_pkts;
124  uint64_t bypassed_bytes;
126 
127 /**
128  * \brief Used to disable flow manager thread(s).
129  *
130  * \todo Kinda hackish since it uses the tv name to identify flow manager
131  * thread. We need an all weather identification scheme.
132  */
134 {
136  /* flow manager thread(s) is/are a part of mgmt threads */
137  for (ThreadVars *tv = tv_root[TVT_MGMT]; tv != NULL; tv = tv->next) {
138  if (strncasecmp(tv->name, thread_name_flow_mgr,
139  strlen(thread_name_flow_mgr)) == 0)
140  {
142  }
143  }
145 
146  struct timeval start_ts;
147  struct timeval cur_ts;
148  gettimeofday(&start_ts, NULL);
149 
150 again:
151  gettimeofday(&cur_ts, NULL);
152  if ((cur_ts.tv_sec - start_ts.tv_sec) > 60) {
153  FatalError("unable to get all flow manager "
154  "threads to shutdown in time");
155  }
156 
158  for (ThreadVars *tv = tv_root[TVT_MGMT]; tv != NULL; tv = tv->next) {
159  if (strncasecmp(tv->name, thread_name_flow_mgr,
160  strlen(thread_name_flow_mgr)) == 0)
161  {
164  /* sleep outside lock */
165  SleepMsec(1);
166  goto again;
167  }
168  }
169  }
171 
172  /* reset count, so we can kill and respawn (unix socket) */
173  SC_ATOMIC_SET(flowmgr_cnt, 0);
174 }
175 
176 /** \internal
177  * \brief check if a flow is timed out
178  *
179  * Takes lastts, adds the timeout policy to it, compared to current time `ts`.
180  * In case of emergency mode, timeout_policy is ignored and the emerg table
181  * is used.
182  *
183  * \param f flow
184  * \param ts timestamp - realtime or a minimum of active threads in offline mode
185  * \param next_ts tracking the next timeout ts, so FM can skip the row until that time
186  * \param emerg bool to indicate if emergency timeout settings should be used
187  *
188  * \retval false not timed out
189  * \retval true timed out
190  */
191 static bool FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const bool emerg)
192 {
193  SCTime_t timesout_at;
194 
195  if (emerg) {
197  timesout_at = SCTIME_ADD_SECS(f->lastts,
198  FlowGetFlowTimeoutDirect(flow_timeouts_emerg, f->flow_state, f->protomap));
199  } else {
200  timesout_at = SCTIME_ADD_SECS(f->lastts, f->timeout_policy);
201  }
202  /* update next_ts if needed */
203  if (*next_ts == 0 || (uint32_t)SCTIME_SECS(timesout_at) < *next_ts)
204  *next_ts = (uint32_t)SCTIME_SECS(timesout_at);
205 
206  /* if time is live, we just use the `ts` */
207  if (TimeModeIsLive() || f->thread_id[0] == 0) {
208  /* do the timeout check */
209  if (SCTIME_CMP_LT(ts, timesout_at)) {
210  return false;
211  }
212  } else {
213  /* offline: take last ts from "owning" thread */
215  /* do the timeout check */
216  if (SCTIME_CMP_LT(checkts, timesout_at)) {
217  return false;
218  }
219  }
220 
221  return true;
222 }
223 
224 #ifdef CAPTURE_OFFLOAD
225 /** \internal
226  * \brief check timeout of captured bypassed flow by querying capture method
227  *
228  * \param f Flow
229  * \param ts timestamp
230  * \param counters Flow timeout counters
231  *
232  * \retval false not timeout
233  * \retval true timeout (or not capture bypassed)
234  */
235 static inline bool FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters *counters)
236 {
237  if (f->flow_state != FLOW_STATE_CAPTURE_BYPASSED) {
238  return true;
239  }
240 
242  if (fc && fc->BypassUpdate) {
244  /* flow will be possibly updated */
245  uint64_t pkts_tosrc = fc->tosrcpktcnt;
246  uint64_t bytes_tosrc = fc->tosrcbytecnt;
247  uint64_t pkts_todst = fc->todstpktcnt;
248  uint64_t bytes_todst = fc->todstbytecnt;
249  bool update = fc->BypassUpdate(f, fc->bypass_data, SCTIME_SECS(ts));
250  if (update) {
251  SCLogDebug("Updated flow: %" PRIu64 "", FlowGetId(f));
252  pkts_tosrc = fc->tosrcpktcnt - pkts_tosrc;
253  bytes_tosrc = fc->tosrcbytecnt - bytes_tosrc;
254  pkts_todst = fc->todstpktcnt - pkts_todst;
255  bytes_todst = fc->todstbytecnt - bytes_todst;
256  if (dev) {
257  SC_ATOMIC_ADD(dev->bypassed, pkts_tosrc + pkts_todst);
258  }
259  counters->bypassed_pkts += pkts_tosrc + pkts_todst;
260  counters->bypassed_bytes += bytes_tosrc + bytes_todst;
261  return false;
262  }
263  SCLogDebug("No new packet, dead flow %" PRIu64 "", FlowGetId(f));
264  if (dev) {
265  if (FLOW_IS_IPV4(f)) {
266  LiveDevSubBypassStats(dev, 1, AF_INET);
267  } else if (FLOW_IS_IPV6(f)) {
268  LiveDevSubBypassStats(dev, 1, AF_INET6);
269  }
270  }
271  counters->bypassed_count++;
272  }
273  return true;
274 }
275 #endif /* CAPTURE_OFFLOAD */
276 
277 typedef struct FlowManagerTimeoutThread {
278  /* used to temporarily store flows that have timed out and are
279  * removed from the hash to reduce locking contention */
282 
283 /**
284  * \internal
285  *
286  * \brief Process the temporary Aside Queue
287  * This means that as long as a flow f is not waiting on detection
288  * engine to finish dealing with it, f will be put in the recycle
289  * queue for further processing later on.
290  *
291  * \param td FM Timeout Thread instance
292  * \param counters Flow Timeout counters to be updated
293  *
294  * \retval Number of flows that were recycled
295  */
296 static uint32_t ProcessAsideQueue(FlowManagerTimeoutThread *td, FlowTimeoutCounters *counters)
297 {
298  FlowQueuePrivate recycle = { NULL, NULL, 0 };
299  counters->flows_aside += td->aside_queue.len;
300 
301  uint32_t cnt = 0;
302  Flow *f;
303  while ((f = FlowQueuePrivateGetFromTop(&td->aside_queue)) != NULL) {
304  /* flow is still locked */
305 
306  /* An IPS drop ends the flow; an IDS drop is an alert and the app
307  * layer keeps running, so the final flush still applies. */
308  const bool drop_ends = (f->flags & FLOW_ACTION_DROP) != 0 && EngineModeIsIPS();
309  if (f->proto == IPPROTO_TCP && !(f->flags & FLOW_TIMEOUT_REASSEMBLY_DONE) && !drop_ends &&
310  !FlowIsBypassed(f) && FlowNeedsReassembly(f)) {
311  /* Send the flow to its thread */
314  /* flow ownership is already passed to the worker thread */
315 
316  counters->flows_aside_needs_work++;
317  continue;
318  }
320 
321  FlowQueuePrivateAppendFlow(&recycle, f);
322  if (recycle.len == 100) {
325  }
326  cnt++;
327  }
328  if (recycle.len) {
331  }
332  return cnt;
333 }
334 
335 /**
336  * \internal
337  *
338  * \brief check all flows in a hash row for timing out
339  *
340  * \param f last flow in the hash row
341  * \param ts timestamp
342  * \param emergency bool indicating emergency mode
343  * \param counters ptr to FlowTimeoutCounters structure
344  */
345 static void FlowManagerHashRowTimeout(FlowManagerTimeoutThread *td, Flow *f, SCTime_t ts,
346  int emergency, FlowTimeoutCounters *counters, uint32_t *next_ts)
347 {
348  uint32_t checked = 0;
349  Flow *prev_f = NULL;
350 
351  do {
352  checked++;
353 
355 
356  /* check flow timeout based on lastts and state. Both can be
357  * accessed w/o Flow lock as we do have the hash row lock (so flow
358  * can't disappear) and flow_state is atomic. lastts can only
359  * be modified when we have both the flow and hash row lock */
360 
361  /* timeout logic goes here */
362  if (!FlowManagerFlowTimeout(f, ts, next_ts, emergency)) {
364  counters->flows_notimeout++;
365 
366  prev_f = f;
367  f = f->next;
368  continue;
369  }
370 
371  Flow *next_flow = f->next;
372 
373 #ifdef CAPTURE_OFFLOAD
374  /* never prune a flow that is used by a packet we
375  * are currently processing in one of the threads */
376  if (!FlowBypassedTimeout(f, ts, counters)) {
378  prev_f = f;
379  f = f->next;
380  continue;
381  }
382 #endif
384 
385  counters->flows_timeout++;
386 
387  RemoveFromHash(f, prev_f);
388 
390  /* flow is still locked in the queue */
391 
392  f = next_flow;
393  } while (f != NULL);
394 
395  counters->flows_checked += checked;
396  if (checked > counters->rows_maxlen)
397  counters->rows_maxlen = checked;
398 }
399 
400 /**
401  * \internal
402  *
403  * \brief Clear evicted list from Flow Manager.
404  * All the evicted flows are removed from the Flow bucket and added
405  * to the temporary Aside Queue.
406  *
407  * \param td FM timeout thread instance
408  * \param f head of the evicted list
409  */
410 static void FlowManagerHashRowClearEvictedList(FlowManagerTimeoutThread *td, Flow *f)
411 {
412  do {
414  Flow *next_flow = f->next;
415  f->next = NULL;
416  f->fb = NULL;
417 
419  /* flow is still locked in the queue */
420 
421  f = next_flow;
422  } while (f != NULL);
423 }
424 
425 /**
426  * \brief time out flows from the hash
427  *
428  * \param ts timestamp
429  * \param hash_min min hash index to consider
430  * \param hash_max max hash index to consider
431  * \param counters ptr to FlowTimeoutCounters structure
432  *
433  * \retval cnt number of timed out flow
434  */
435 static uint32_t FlowTimeoutHash(FlowManagerTimeoutThread *td, SCTime_t ts, const uint32_t hash_min,
436  const uint32_t hash_max, FlowTimeoutCounters *counters)
437 {
438  uint32_t cnt = 0;
439  const int emergency = ((SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY));
440  const uint32_t rows_checked = hash_max - hash_min;
441  uint32_t rows_skipped = 0;
442  uint32_t rows_empty = 0;
443 
444 #if __WORDSIZE==64
445 #define BITS 64
446 #define TYPE uint64_t
447 #else
448 #define BITS 32
449 #define TYPE uint32_t
450 #endif
451 
452  const uint32_t ts_secs = (uint32_t)SCTIME_SECS(ts);
453  for (uint32_t idx = hash_min; idx < hash_max; idx+=BITS) {
454  TYPE check_bits = 0;
455  const uint32_t check = MIN(BITS, (hash_max - idx));
456  for (uint32_t i = 0; i < check; i++) {
457  FlowBucket *fb = &flow_hash[idx+i];
458  check_bits |= (TYPE)(SC_ATOMIC_LOAD_EXPLICIT(
459  fb->next_ts, SC_ATOMIC_MEMORY_ORDER_RELAXED) <= ts_secs)
460  << (TYPE)i;
461  }
462  if (check_bits == 0)
463  continue;
464 
465  for (uint32_t i = 0; i < check; i++) {
466  FlowBucket *fb = &flow_hash[idx+i];
467  if ((check_bits & ((TYPE)1 << (TYPE)i)) != 0 && SC_ATOMIC_GET(fb->next_ts) <= ts_secs) {
468  FBLOCK_LOCK(fb);
469  Flow *evicted = NULL;
470  if (fb->evicted != NULL || fb->head != NULL) {
471  if (fb->evicted != NULL) {
472  /* transfer out of bucket so we can do additional work outside
473  * of the bucket lock */
474  evicted = fb->evicted;
475  fb->evicted = NULL;
476  }
477  if (fb->head != NULL) {
478  uint32_t next_ts = 0;
479  FlowManagerHashRowTimeout(td, fb->head, ts, emergency, counters, &next_ts);
480 
481  if (SC_ATOMIC_GET(fb->next_ts) != next_ts)
482  SC_ATOMIC_SET(fb->next_ts, next_ts);
483  }
484  if (fb->evicted == NULL && fb->head == NULL) {
485  /* row is empty */
486  SC_ATOMIC_SET(fb->next_ts, UINT_MAX);
487  }
488  } else {
489  SC_ATOMIC_SET(fb->next_ts, UINT_MAX);
490  rows_empty++;
491  }
492  FBLOCK_UNLOCK(fb);
493  /* processed evicted list */
494  if (evicted) {
495  FlowManagerHashRowClearEvictedList(td, evicted);
496  }
497  } else {
498  rows_skipped++;
499  }
500  }
501  if (td->aside_queue.len) {
502  cnt += ProcessAsideQueue(td, counters);
503  }
504  }
505 
506  counters->rows_checked += rows_checked;
507  counters->rows_skipped += rows_skipped;
508  counters->rows_empty += rows_empty;
509 
510  if (td->aside_queue.len) {
511  cnt += ProcessAsideQueue(td, counters);
512  }
513  counters->flows_removed += cnt;
514  /* coverity[missing_unlock : FALSE] */
515  return cnt;
516 }
517 
518 /** \internal
519  *
520  * \brief handle timeout for a slice of hash rows
521  * If we wrap around we call FlowTimeoutHash twice
522  * \param td FM timeout thread
523  * \param ts timeout timestamp
524  * \param hash_min lower bound of the row slice
525  * \param hash_max upper bound of the row slice
526  * \param counters Flow timeout counters to be passed
527  * \param rows number of rows for this worker unit
528  * \param pos absolute position of the beginning of row slice in the hash table
529  * \param instance instance id of this FM
530  *
531  * \retval number of successfully timed out flows
532  */
533 static uint32_t FlowTimeoutHashInChunks(FlowManagerTimeoutThread *td, SCTime_t ts,
534  const uint32_t hash_min, const uint32_t hash_max, FlowTimeoutCounters *counters,
535  const uint32_t rows, uint32_t *pos, const uint32_t instance)
536 {
537  uint32_t start = 0;
538  uint32_t end = 0;
539  uint32_t cnt = 0;
540  uint32_t rows_left = rows;
541 
542 again:
543  start = (*pos);
544  if (start >= hash_max) {
545  start = hash_min;
546  }
547  end = start + rows_left;
548  if (end > hash_max) {
549  end = hash_max;
550  }
551  *pos = (end == hash_max) ? hash_min : end;
552  rows_left = rows_left - (end - start);
553 
554  SCLogDebug("instance %u: %u:%u (hash_min %u, hash_max %u *pos %u)", instance, start, end,
555  hash_min, hash_max, *pos);
556 
557  cnt += FlowTimeoutHash(td, ts, start, end, counters);
558  if (rows_left) {
559  goto again;
560  }
561  return cnt;
562 }
563 
564 /**
565  * \internal
566  *
567  * \brief move all flows out of a hash row
568  *
569  * \param f last flow in the hash row
570  * \param recycle_q Flow recycle queue
571  * \param mode emergency or not
572  *
573  * \retval cnt number of flows removed from the hash and added to the recycle queue
574  */
575 static uint32_t FlowManagerHashRowCleanup(Flow *f, FlowQueuePrivate *recycle_q, const int mode)
576 {
577  uint32_t cnt = 0;
578 
579  do {
581 
582  Flow *next_flow = f->next;
583 
584  /* remove from the hash */
585  if (mode == 0) {
586  RemoveFromHash(f, NULL);
587  } else {
588  FlowBucket *fb = f->fb;
589  fb->evicted = f->next;
590  f->next = NULL;
591  f->fb = NULL;
592  }
594 
595  /* no one is referring to this flow, removed from hash
596  * so we can unlock it and move it to the recycle queue. */
598  FlowQueuePrivateAppendFlow(recycle_q, f);
599 
600  cnt++;
601 
602  f = next_flow;
603  } while (f != NULL);
604 
605  return cnt;
606 }
607 
608 #define RECYCLE_MAX_QUEUE_ITEMS 25
609 /**
610  * \brief remove all flows from the hash
611  *
612  * \retval cnt number of removes out flows
613  */
614 static uint32_t FlowCleanupHash(void)
615 {
616  FlowQueuePrivate local_queue = { NULL, NULL, 0 };
617  uint32_t cnt = 0;
618 
619  for (uint32_t idx = 0; idx < flow_config.hash_size; idx++) {
620  FlowBucket *fb = &flow_hash[idx];
621 
622  FBLOCK_LOCK(fb);
623 
624  if (fb->head != NULL) {
625  /* we have a flow, or more than one */
626  cnt += FlowManagerHashRowCleanup(fb->head, &local_queue, 0);
627  }
628  if (fb->evicted != NULL) {
629  /* we have a flow, or more than one */
630  cnt += FlowManagerHashRowCleanup(fb->evicted, &local_queue, 1);
631  }
632 
633  FBLOCK_UNLOCK(fb);
634  if (local_queue.len >= RECYCLE_MAX_QUEUE_ITEMS) {
635  FlowQueueAppendPrivate(&flow_recycle_q, &local_queue);
637  }
638  }
640  FlowQueueAppendPrivate(&flow_recycle_q, &local_queue);
642 
643  return cnt;
644 }
645 
646 typedef struct FlowCounters_ {
649 
653 
659 
661 
665 
669 
670 typedef struct FlowManagerThreadData_ {
671  uint32_t instance;
672  uint32_t min;
673  uint32_t max;
674 
676 
681 
682 static void FlowCountersInit(ThreadVars *t, FlowCounters *fc)
683 {
684  fc->flow_mgr_full_pass = StatsRegisterCounter("flow.mgr.full_hash_pass", &t->stats);
685  fc->flow_mgr_rows_sec = StatsRegisterCounter("flow.mgr.rows_per_sec", &t->stats);
686 
687  fc->flow_mgr_spare = StatsRegisterCounter("flow.spare", &t->stats);
688  fc->flow_emerg_mode_enter = StatsRegisterCounter("flow.emerg_mode_entered", &t->stats);
689  fc->flow_emerg_mode_over = StatsRegisterCounter("flow.emerg_mode_over", &t->stats);
690 
691  fc->flow_mgr_rows_maxlen = StatsRegisterMaxCounter("flow.mgr.rows_maxlen", &t->stats);
692  fc->flow_mgr_flows_checked = StatsRegisterCounter("flow.mgr.flows_checked", &t->stats);
693  fc->flow_mgr_flows_notimeout = StatsRegisterCounter("flow.mgr.flows_notimeout", &t->stats);
694  fc->flow_mgr_flows_timeout = StatsRegisterCounter("flow.mgr.flows_timeout", &t->stats);
695  fc->flow_mgr_flows_aside = StatsRegisterCounter("flow.mgr.flows_evicted", &t->stats);
697  StatsRegisterCounter("flow.mgr.flows_evicted_needs_work", &t->stats);
698 
699  fc->flow_bypassed_cnt_clo = StatsRegisterCounter("flow_bypassed.closed", &t->stats);
700  fc->flow_bypassed_pkts = StatsRegisterCounter("flow_bypassed.pkts", &t->stats);
701  fc->flow_bypassed_bytes = StatsRegisterCounter("flow_bypassed.bytes", &t->stats);
702 
703  fc->memcap_pressure = StatsRegisterCounter("memcap.pressure", &t->stats);
704  fc->memcap_pressure_max = StatsRegisterMaxCounter("memcap.pressure_max", &t->stats);
705 }
706 
707 static void FlowCountersUpdate(
708  ThreadVars *th_v, const FlowManagerThreadData *ftd, const FlowTimeoutCounters *counters)
709 {
711  &th_v->stats, ftd->cnt.flow_mgr_flows_checked, (int64_t)counters->flows_checked);
713  &th_v->stats, ftd->cnt.flow_mgr_flows_notimeout, (int64_t)counters->flows_notimeout);
714 
716  &th_v->stats, ftd->cnt.flow_mgr_flows_timeout, (int64_t)counters->flows_timeout);
717  StatsCounterAddI64(&th_v->stats, ftd->cnt.flow_mgr_flows_aside, (int64_t)counters->flows_aside);
719  (int64_t)counters->flows_aside_needs_work);
720 
722  &th_v->stats, ftd->cnt.flow_bypassed_cnt_clo, (int64_t)counters->bypassed_count);
723  StatsCounterAddI64(&th_v->stats, ftd->cnt.flow_bypassed_pkts, (int64_t)counters->bypassed_pkts);
725  &th_v->stats, ftd->cnt.flow_bypassed_bytes, (int64_t)counters->bypassed_bytes);
726 
728  &th_v->stats, ftd->cnt.flow_mgr_rows_maxlen, (int64_t)counters->rows_maxlen);
729 }
730 
731 static TmEcode FlowManagerThreadInit(ThreadVars *t, const void *initdata, void **data)
732 {
734  if (ftd == NULL)
735  return TM_ECODE_FAILED;
736 
737  ftd->instance = SC_ATOMIC_ADD(flowmgr_cnt, 1);
738  SCLogDebug("flow manager instance %u", ftd->instance);
739 
740  /* set the min and max value used for hash row walking
741  * each thread has it's own section of the flow hash */
742  uint32_t range = flow_config.hash_size / flowmgr_number;
743 
744  ftd->min = ftd->instance * range;
745  ftd->max = (ftd->instance + 1) * range;
746 
747  /* last flow-manager takes on hash_size % flowmgr_number extra rows */
748  if ((ftd->instance + 1) == flowmgr_number) {
749  ftd->max = flow_config.hash_size;
750  }
752 
753  SCLogDebug("instance %u hash range %u %u", ftd->instance, ftd->min, ftd->max);
754 
755  /* pass thread data back to caller */
756  *data = ftd;
757 
758  FlowCountersInit(t, &ftd->cnt);
759  ftd->counter_defrag_timeout = StatsRegisterCounter("defrag.mgr.tracker_timeout", &t->stats);
760  ftd->counter_defrag_memuse = StatsRegisterCounter("defrag.memuse", &t->stats);
761 
762  PacketPoolInit();
763  return TM_ECODE_OK;
764 }
765 
766 static TmEcode FlowManagerThreadDeinit(ThreadVars *t, void *data)
767 {
770  SCFree(data);
771  return TM_ECODE_OK;
772 }
773 
774 /** \internal
775  * \brief calculate number of rows to scan and how much time to sleep
776  * based on the busy score `mp` (0 idle, 100 max busy).
777  *
778  * We try to to make sure we scan the hash once a second. The number size
779  * of the slice of the hash scanned is determined by our busy score 'mp'.
780  * We sleep for the remainder of the second after processing the slice,
781  * or at least an approximation of it.
782  * A minimum busy score of 10 is assumed to avoid a longer than 10 second
783  * full hash pass. This is to avoid burstiness in scanning when there is
784  * a rapid increase of the busy score, which could lead to the flow manager
785  * suddenly scanning a much larger slice of the hash leading to a burst
786  * in scan/eviction work.
787  *
788  * \param rows number of rows for the work unit
789  * \param mp current memcap pressure value
790  * \param emergency emergency mode is set or not
791  * \param wu_sleep holds value of sleep time per worker unit
792  * \param wu_rows holds value of calculated rows to be processed per second
793  * \param rows_sec same as wu_rows, only used for counter updates
794  */
795 static void GetWorkUnitSizing(const uint32_t rows, const uint32_t mp, const bool emergency,
796  uint64_t *wu_sleep, uint32_t *wu_rows, uint32_t *rows_sec)
797 {
798  if (emergency) {
799  *wu_rows = rows;
800  *wu_sleep = 250;
801  return;
802  }
803  /* minimum busy score is 10 */
804  const uint32_t emp = MAX(mp, 10);
805  /* ensure minimum rows_per_sec is at least 1 */
806  const uint32_t rows_per_sec =
807  MAX(1, (uint32_t)((float)rows * (float)((float)emp / (float)100)));
808  /* calc how much time we estimate the work will take, in ms. We assume
809  * each row takes an average of 1usec. Maxing out at 1sec. */
810  const uint32_t work_per_unit = MIN(rows_per_sec / 1000, 1000);
811  /* calc how much time we need to sleep to get to the per second cadence
812  * but sleeping for at least 250ms. */
813  const uint32_t sleep_per_unit = MAX(250, 1000 - work_per_unit);
814  SCLogDebug("mp %u emp %u rows %u rows_sec %u sleep %ums", mp, emp, rows, rows_per_sec,
815  sleep_per_unit);
816 
817  *wu_sleep = sleep_per_unit;
818  *wu_rows = rows_per_sec;
819  *rows_sec = rows_per_sec;
820 }
821 
822 /** \brief Thread that manages the flow table and times out flows.
823  *
824  * \param td ThreadVars cast to void ptr
825  *
826  * Keeps an eye on the spare list, alloc flows if needed...
827  */
828 static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
829 {
830  FlowManagerThreadData *ftd = thread_data;
831  const uint32_t rows = ftd->max - ftd->min;
832  const bool time_is_live = TimeModeIsLive();
833 
834  uint32_t emerg_over_cnt = 0;
835  uint64_t next_run_ms = 0;
836  uint32_t pos = ftd->min;
837  uint32_t rows_sec = 0;
838  uint32_t rows_per_wu = 0;
839  uint64_t sleep_per_wu = 0;
840  bool prev_emerg = false;
841  uint32_t other_last_sec = 0; /**< last sec stamp when defrag etc ran */
842 
843  uint32_t mp = MemcapsGetPressure() * 100;
844  if (ftd->instance == 0) {
847  }
848  GetWorkUnitSizing(rows, mp, false, &sleep_per_wu, &rows_per_wu, &rows_sec);
850 
852  /* don't start our activities until time is setup */
853  while (!TimeModeIsReady()) {
854  if (suricata_ctl_flags != 0)
855  return TM_ECODE_OK;
856  SleepUsec(10);
857  }
858  bool run = TmThreadsWaitForUnpause(th_v);
859 
860  while (run) {
861  bool emerg = ((SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) != 0);
862 
863  /* Get the time: real time in live mode, or a min() of the
864  * "active" threads in offline mode. See TmThreadsGetMinimalTimestamp */
865  SCTime_t ts = TimeGet();
866 
867  SCLogDebug("ts %" PRIdMAX "", (intmax_t)SCTIME_SECS(ts));
868  uint64_t ts_ms = SCTIME_MSECS(ts);
869  const bool emerge_p = (emerg && !prev_emerg);
870  if (emerge_p) {
871  next_run_ms = 0;
872  prev_emerg = true;
873  SCLogNotice("Flow emergency mode entered...");
875  }
876  if (ts_ms >= next_run_ms) {
877  if (ftd->instance == 0) {
878  const uint32_t sq_len = FlowSpareGetPoolSize();
879  const uint32_t spare_perc = sq_len * 100 / MAX(flow_config.prealloc, 1);
880  /* see if we still have enough spare flows */
881  if (spare_perc < 90 || spare_perc > 110) {
882  FlowSparePoolUpdate(sq_len);
883  }
884  }
885 
886  /* try to time out flows */
887  // clang-format off
888  FlowTimeoutCounters counters = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
889  // clang-format on
890 
891  if (emerg) {
892  /* in emergency mode, do a full pass of the hash table */
893  FlowTimeoutHash(&ftd->timeout, ts, ftd->min, ftd->max, &counters);
895  } else {
896  SCLogDebug("hash %u:%u slice starting at %u with %u rows", ftd->min, ftd->max, pos,
897  rows_per_wu);
898 
899  const uint32_t ppos = pos;
900  FlowTimeoutHashInChunks(&ftd->timeout, ts, ftd->min, ftd->max, &counters,
901  rows_per_wu, &pos, ftd->instance);
902  if (ppos > pos) {
904  }
905  }
906 
907  const uint32_t spare_pool_len = FlowSpareGetPoolSize();
908  StatsCounterSetI64(&th_v->stats, ftd->cnt.flow_mgr_spare, (uint64_t)spare_pool_len);
909 
910  FlowCountersUpdate(th_v, ftd, &counters);
911 
912  if (emerg) {
913  SCLogDebug("flow_sparse_q.len = %" PRIu32 " prealloc: %" PRIu32
914  "flow_spare_q status: %" PRIu32 "%% flows at the queue",
915  spare_pool_len, flow_config.prealloc,
916  spare_pool_len * 100 / MAX(flow_config.prealloc, 1));
917 
918  /* only if we have pruned this "emergency_recovery" percentage
919  * of flows, we will unset the emergency bit */
920  if ((spare_pool_len * 100 / MAX(flow_config.prealloc, 1)) >
922  emerg_over_cnt++;
923  } else {
924  emerg_over_cnt = 0;
925  }
926 
927  if (emerg_over_cnt >= 30) {
928  SC_ATOMIC_AND(flow_flags, ~FLOW_EMERGENCY);
930 
931  emerg = false;
932  prev_emerg = false;
933  emerg_over_cnt = 0;
934  SCLogNotice("Flow emergency mode over, back to normal... unsetting"
935  " FLOW_EMERGENCY bit (ts.tv_sec: %" PRIuMAX ", "
936  "ts.tv_usec:%" PRIuMAX ") flow_spare_q status(): %" PRIu32
937  "%% flows at the queue",
938  (uintmax_t)SCTIME_SECS(ts), (uintmax_t)SCTIME_USECS(ts),
939  spare_pool_len * 100 / MAX(flow_config.prealloc, 1));
940 
942  }
943  }
944 
945  /* update work units */
946  const uint32_t pmp = mp;
947  mp = MemcapsGetPressure() * 100;
948  if (ftd->instance == 0) {
951  }
952  GetWorkUnitSizing(rows, mp, emerg, &sleep_per_wu, &rows_per_wu, &rows_sec);
953  if (pmp != mp) {
955  }
956 
957  next_run_ms = ts_ms + sleep_per_wu;
958  }
959  if (other_last_sec == 0 || other_last_sec < (uint32_t)SCTIME_SECS(ts)) {
960  if (ftd->instance == 0) {
963  uint32_t defrag_cnt = DefragTimeoutHash(ts);
964  if (defrag_cnt) {
966  &th_v->stats, ftd->counter_defrag_timeout, (int64_t)defrag_cnt);
967  }
972  other_last_sec = (uint32_t)SCTIME_SECS(ts);
973  }
974  }
975 
978  break;
979  }
980 
981  if (emerg || !time_is_live) {
982  SleepUsec(250);
983  } else {
984  struct timeval cond_tv;
985  gettimeofday(&cond_tv, NULL);
986  struct timeval add_tv;
987  add_tv.tv_sec = sleep_per_wu / 1000;
988  add_tv.tv_usec = (sleep_per_wu % 1000) * 1000;
989  timeradd(&cond_tv, &add_tv, &cond_tv);
990 
991  struct timespec cond_time = FROM_TIMEVAL(cond_tv);
992  SCCtrlMutexLock(&flow_manager_ctrl_mutex);
993  while (1) {
994  if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) {
995  break;
996  }
997  int rc = SCCtrlCondTimedwait(
998  &flow_manager_ctrl_cond, &flow_manager_ctrl_mutex, &cond_time);
999  if (rc == ETIMEDOUT || rc < 0) {
1000  break;
1001  }
1002  }
1003  SCCtrlMutexUnlock(&flow_manager_ctrl_mutex);
1004  }
1005 
1006  SCLogDebug("woke up... %s", SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY ? "emergency":"");
1007 
1009  }
1010  return TM_ECODE_OK;
1011 }
1012 
1013 /** \brief spawn the flow manager thread */
1015 {
1016  intmax_t setting = 1;
1017  (void)SCConfGetInt("flow.managers", &setting);
1018 
1019  if (setting < 1 || setting > 1024) {
1020  FatalError("invalid flow.managers setting %" PRIdMAX, setting);
1021  }
1022  flowmgr_number = (uint32_t)setting;
1023 
1024  SCLogConfig("using %u flow manager threads", flowmgr_number);
1025  StatsRegisterGlobalCounter("flow.memuse", FlowGetMemuse);
1026 
1027  for (uint32_t u = 0; u < flowmgr_number; u++) {
1028  char name[TM_THREAD_NAME_MAX];
1029  snprintf(name, sizeof(name), "%s#%02u", thread_name_flow_mgr, u+1);
1030 
1032  "FlowManager", 0);
1033  BUG_ON(tv_flowmgr == NULL);
1034 
1035  if (tv_flowmgr == NULL) {
1036  FatalError("flow manager thread creation failed");
1037  }
1038  if (TmThreadSpawn(tv_flowmgr) != TM_ECODE_OK) {
1039  FatalError("flow manager thread spawn failed");
1040  }
1041  }
1042 }
1043 
1044 typedef struct FlowRecyclerThreadData_ {
1046 
1050 
1055 
1056 static TmEcode FlowRecyclerThreadInit(ThreadVars *t, const void *initdata, void **data)
1057 {
1059  if (ftd == NULL)
1060  return TM_ECODE_FAILED;
1062  SCLogError("initializing flow log API for thread failed");
1063  SCFree(ftd);
1064  return TM_ECODE_FAILED;
1065  }
1066  SCLogDebug("output_thread_data %p", ftd->output_thread_data);
1067 
1068  ftd->counter_flows = StatsRegisterCounter("flow.recycler.recycled", &t->stats);
1069  ftd->counter_queue_avg = StatsRegisterAvgCounter("flow.recycler.queue_avg", &t->stats);
1070  ftd->counter_queue_max = StatsRegisterMaxCounter("flow.recycler.queue_max", &t->stats);
1071 
1072  ftd->counter_flow_active = StatsRegisterCounter("flow.active", &t->stats);
1073  ftd->counter_tcp_active_sessions = StatsRegisterCounter("tcp.active_sessions", &t->stats);
1074 
1075  FlowEndCountersRegister(t, &ftd->fec);
1076 
1077  *data = ftd;
1078  return TM_ECODE_OK;
1079 }
1080 
1081 static TmEcode FlowRecyclerThreadDeinit(ThreadVars *t, void *data)
1082 {
1084 
1086  if (ftd->output_thread_data != NULL)
1088 
1089  SCFree(data);
1090  return TM_ECODE_OK;
1091 }
1092 
1093 static void Recycler(ThreadVars *tv, FlowRecyclerThreadData *ftd, Flow *f)
1094 {
1095  FLOWLOCK_WRLOCK(f);
1096 
1097  (void)OutputFlowLog(tv, ftd->output_thread_data, f);
1098 
1099  FlowEndCountersUpdate(tv, &ftd->fec, f);
1100  if (f->proto == IPPROTO_TCP && f->protoctx != NULL) {
1102  }
1106  FLOWLOCK_UNLOCK(f);
1107 }
1108 
1109 /** \brief Thread that manages timed out flows.
1110  *
1111  * \param td ThreadVars cast to void ptr
1112  */
1113 static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
1114 {
1115  FlowRecyclerThreadData *ftd = (FlowRecyclerThreadData *)thread_data;
1116  BUG_ON(ftd == NULL);
1117  const bool time_is_live = TimeModeIsLive();
1118  uint64_t recycled_cnt = 0;
1119  FlowQueuePrivate ret_queue = { NULL, NULL, 0 };
1120 
1122  bool run = TmThreadsWaitForUnpause(th_v);
1123 
1124  while (run) {
1125  SC_ATOMIC_ADD(flowrec_busy,1);
1127 
1128  StatsCounterAvgAddI64(&th_v->stats, ftd->counter_queue_avg, (int64_t)list.len);
1129  StatsCounterMaxUpdateI64(&th_v->stats, ftd->counter_queue_max, (int64_t)list.len);
1130 
1131  const int bail = (TmThreadsCheckFlag(th_v, THV_KILL));
1132 
1133  /* Get the time */
1134  SCLogDebug("ts %" PRIdMAX "", (intmax_t)SCTIME_SECS(TimeGet()));
1135 
1136  int64_t cnt = 0;
1137  Flow *f;
1138  while ((f = FlowQueuePrivateGetFromTop(&list)) != NULL) {
1139  Recycler(th_v, ftd, f);
1140  cnt++;
1141 
1142  /* for every full sized block, add it to the spare pool */
1143  FlowQueuePrivateAppendFlow(&ret_queue, f);
1144  if (ret_queue.len == FLOW_SPARE_POOL_BLOCK_SIZE) {
1145  FlowSparePoolReturnFlows(&ret_queue);
1146  }
1147  }
1148  if (ret_queue.len > 0) {
1149  FlowSparePoolReturnFlows(&ret_queue);
1150  }
1151  if (cnt > 0) {
1152  recycled_cnt += cnt;
1154  }
1155  SC_ATOMIC_SUB(flowrec_busy,1);
1156 
1157  if (bail) {
1158  break;
1159  }
1160 
1161  const bool emerg = (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY);
1162  if (emerg || !time_is_live) {
1163  SleepUsec(250);
1164  } else {
1165  struct timeval cond_tv;
1166  gettimeofday(&cond_tv, NULL);
1167  cond_tv.tv_sec += 1;
1168  struct timespec cond_time = FROM_TIMEVAL(cond_tv);
1169  SCCtrlMutexLock(&flow_recycler_ctrl_mutex);
1170  while (1) {
1171  if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY) {
1172  break;
1173  }
1174  if (SC_ATOMIC_GET(flow_recycle_q.non_empty)) {
1175  break;
1176  }
1177  int rc = SCCtrlCondTimedwait(
1178  &flow_recycler_ctrl_cond, &flow_recycler_ctrl_mutex, &cond_time);
1179  if (rc == ETIMEDOUT || rc < 0) {
1180  break;
1181  }
1182  }
1183  SCCtrlMutexUnlock(&flow_recycler_ctrl_mutex);
1184  }
1185 
1186  SCLogDebug("woke up...");
1187 
1189  }
1191  SCLogPerf("%"PRIu64" flows processed", recycled_cnt);
1192  return TM_ECODE_OK;
1193 }
1194 
1195 static bool FlowRecyclerReadyToShutdown(void)
1196 {
1197  if (SC_ATOMIC_GET(flowrec_busy) != 0) {
1198  return false;
1199  }
1200  uint32_t len = 0;
1202  len = flow_recycle_q.qlen;
1204 
1205  return ((len == 0));
1206 }
1207 
1208 /** \brief spawn the flow recycler thread */
1210 {
1211  intmax_t setting = 1;
1212  (void)SCConfGetInt("flow.recyclers", &setting);
1213 
1214  if (setting < 1 || setting > 1024) {
1215  FatalError("invalid flow.recyclers setting %" PRIdMAX, setting);
1216  }
1217  flowrec_number = (uint32_t)setting;
1218 
1219  SCLogConfig("using %u flow recycler threads", flowrec_number);
1220 
1221  for (uint32_t u = 0; u < flowrec_number; u++) {
1222  char name[TM_THREAD_NAME_MAX];
1223  snprintf(name, sizeof(name), "%s#%02u", thread_name_flow_rec, u+1);
1224 
1226  "FlowRecycler", 0);
1227 
1228  if (tv_flowrec == NULL) {
1229  FatalError("flow recycler thread creation failed");
1230  }
1231  if (TmThreadSpawn(tv_flowrec) != TM_ECODE_OK) {
1232  FatalError("flow recycler thread spawn failed");
1233  }
1234  }
1235 }
1236 
1237 /**
1238  * \brief Used to disable flow recycler thread(s).
1239  *
1240  * \note this should only be called when the flow manager is already gone
1241  *
1242  * \todo Kinda hackish since it uses the tv name to identify flow recycler
1243  * thread. We need an all weather identification scheme.
1244  */
1246 {
1247  /* move all flows still in the hash to the recycler queue */
1248 #ifndef DEBUG
1249  (void)FlowCleanupHash();
1250 #else
1251  uint32_t flows = FlowCleanupHash();
1252  SCLogDebug("flows to progress: %u", flows);
1253 #endif
1254 
1255  /* make sure all flows are processed */
1256  do {
1258  SleepUsec(10);
1259  } while (!FlowRecyclerReadyToShutdown());
1260 
1262  /* flow recycler thread(s) is/are a part of mgmt threads */
1263  for (ThreadVars *tv = tv_root[TVT_MGMT]; tv != NULL; tv = tv->next) {
1264  if (strncasecmp(tv->name, thread_name_flow_rec,
1265  strlen(thread_name_flow_rec)) == 0)
1266  {
1268  }
1269  }
1271 
1272  struct timeval start_ts;
1273  struct timeval cur_ts;
1274  gettimeofday(&start_ts, NULL);
1275 
1276 again:
1277  gettimeofday(&cur_ts, NULL);
1278  if ((cur_ts.tv_sec - start_ts.tv_sec) > 60) {
1279  FatalError("unable to get all flow recycler "
1280  "threads to shutdown in time");
1281  }
1282 
1284  for (ThreadVars *tv = tv_root[TVT_MGMT]; tv != NULL; tv = tv->next) {
1285  if (strncasecmp(tv->name, thread_name_flow_rec,
1286  strlen(thread_name_flow_rec)) == 0)
1287  {
1291  /* sleep outside lock */
1292  SleepMsec(1);
1293  goto again;
1294  }
1295  }
1296  }
1298 
1299  /* reset count, so we can kill and respawn (unix socket) */
1300  SC_ATOMIC_SET(flowrec_cnt, 0);
1301 }
1302 
1304 {
1305  tmm_modules[TMM_FLOWMANAGER].name = "FlowManager";
1306  tmm_modules[TMM_FLOWMANAGER].ThreadInit = FlowManagerThreadInit;
1307  tmm_modules[TMM_FLOWMANAGER].ThreadDeinit = FlowManagerThreadDeinit;
1308  tmm_modules[TMM_FLOWMANAGER].Management = FlowManager;
1311  SCLogDebug("%s registered", tmm_modules[TMM_FLOWMANAGER].name);
1312 
1313  SC_ATOMIC_INIT(flowmgr_cnt);
1314  SC_ATOMIC_INITPTR(flow_timeouts);
1315 }
1316 
1318 {
1319  tmm_modules[TMM_FLOWRECYCLER].name = "FlowRecycler";
1320  tmm_modules[TMM_FLOWRECYCLER].ThreadInit = FlowRecyclerThreadInit;
1321  tmm_modules[TMM_FLOWRECYCLER].ThreadDeinit = FlowRecyclerThreadDeinit;
1322  tmm_modules[TMM_FLOWRECYCLER].Management = FlowRecycler;
1325  SCLogDebug("%s registered", tmm_modules[TMM_FLOWRECYCLER].name);
1326 
1327  SC_ATOMIC_INIT(flowrec_cnt);
1328  SC_ATOMIC_INIT(flowrec_busy);
1329 }
TmModule_::cap_flags
uint8_t cap_flags
Definition: tm-modules.h:77
FlowTimeoutCounters_::rows_empty
uint32_t rows_empty
Definition: flow-manager.c:112
FlowSparePoolUpdate
void FlowSparePoolUpdate(uint32_t size)
Definition: flow-spare-pool.c:217
FlowManagerThreadSpawn
void FlowManagerThreadSpawn(void)
spawn the flow manager thread
Definition: flow-manager.c:1014
util-device-private.h
tm-threads.h
FROM_TIMEVAL
#define FROM_TIMEVAL(timev)
initialize a 'struct timespec' from a 'struct timeval'.
Definition: util-time.h:124
OutputFlowLog
TmEcode OutputFlowLog(ThreadVars *tv, void *thread_data, Flow *f)
Run flow logger(s)
Definition: output-flow.c:87
StatsRegisterGlobalCounter
StatsCounterGlobalId StatsRegisterGlobalCounter(const char *name, uint64_t(*Func)(void))
Registers a counter, which represents a global value.
Definition: counters.c:1093
FlowCounters_::flow_mgr_rows_maxlen
StatsCounterMaxId flow_mgr_rows_maxlen
Definition: flow-manager.c:660
FlowRecyclerThreadData_::fec
FlowEndCounters fec
Definition: flow-manager.c:1053
len
uint8_t len
Definition: app-layer-dnp3.h:2
ts
uint64_t ts
Definition: source-erf-file.c:68
StatsCounterMaxUpdateI64
void StatsCounterMaxUpdateI64(StatsThreadContext *stats, StatsCounterMaxId id, int64_t x)
update the value of the localmax counter
Definition: counters.c:222
TmThreadSpawn
TmEcode TmThreadSpawn(ThreadVars *tv)
Spawns a thread associated with the ThreadVars instance tv.
Definition: tm-threads.c:1710
app-layer-htp-range.h
FlowTimeoutCounters
Definition: flow-worker.c:60
TmThreadCreateMgmtThreadByName
ThreadVars * TmThreadCreateMgmtThreadByName(const char *name, const char *module, int mucond)
Creates and returns the TV instance for a Management thread(MGMT). This function supports only custom...
Definition: tm-threads.c:1131
FlowBucket_::evicted
Flow * evicted
Definition: flow-hash.h:48
OutputFlowLogThreadInit
TmEcode OutputFlowLogThreadInit(ThreadVars *tv, void **data)
thread init for the flow logger This will run the thread init functions for the individual registered...
Definition: output-flow.c:121
FLOW_IS_IPV6
#define FLOW_IS_IPV6(f)
Definition: flow.h:175
FlowManagerThreadData_::max
uint32_t max
Definition: flow-manager.c:673
FlowManagerTimeoutThread
Definition: flow-manager.c:277
Flow_::flags
uint64_t flags
Definition: flow.h:408
ThreadVars_::name
char name[16]
Definition: threadvars.h:64
thread_name_flow_mgr
const char * thread_name_flow_mgr
Definition: runmodes.c:69
StatsSyncCountersIfSignalled
void StatsSyncCountersIfSignalled(StatsThreadContext *stats)
Definition: counters.c:481
FlowSpareGetPoolSize
uint32_t FlowSpareGetPoolSize(void)
Definition: flow-spare-pool.c:46
flow-util.h
FlowCounters_::flow_mgr_flows_timeout
StatsCounterId flow_mgr_flows_timeout
Definition: flow-manager.c:656
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:314
FlowManagerThreadData_::cnt
FlowCounters cnt
Definition: flow-manager.c:675
FBLOCK_LOCK
#define FBLOCK_LOCK(fb)
Definition: flow-hash.h:73
SCTIME_MSECS
#define SCTIME_MSECS(t)
Definition: util-time.h:58
TMM_FLOWRECYCLER
@ TMM_FLOWRECYCLER
Definition: tm-threads-common.h:70
stream-tcp.h
FlowCounters_::memcap_pressure
StatsCounterId memcap_pressure
Definition: flow-manager.c:666
FlowBypassInfo_
Definition: flow.h:534
FlowCnf_::emergency_recovery
uint32_t emergency_recovery
Definition: flow.h:303
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:386
FlowCnf_::hash_size
uint32_t hash_size
Definition: flow.h:297
FlowManagerThreadData_::instance
uint32_t instance
Definition: flow-manager.c:671
SCFlowGetStorageById
void * SCFlowGetStorageById(const Flow *f, SCFlowStorageId id)
Definition: flow-storage.c:37
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
IPPairTimeoutHash
uint32_t IPPairTimeoutHash(SCTime_t ts)
time out ippairs from the hash
Definition: ippair-timeout.c:124
StatsRegisterCounter
StatsCounterId StatsRegisterCounter(const char *name, StatsThreadContext *stats)
Registers a normal, unqualified counter.
Definition: counters.c:1038
TmThreadsSetFlag
void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag)
Set a thread flag.
Definition: tm-threads.c:102
FLOW_PROTO_MAX
@ FLOW_PROTO_MAX
Definition: flow-private.h:70
name
const char * name
Definition: detect-engine-proto.c:47
Flow_::proto
uint8_t proto
Definition: flow.h:381
SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(uint32_t, flowmgr_cnt)
threads.h
FlowSendToLocalThread
void FlowSendToLocalThread(Flow *f)
Definition: flow-timeout.c:349
flow-private.h
Flow_
Flow data structure.
Definition: flow.h:359
TYPE
#define TYPE
Flow_::protomap
uint8_t protomap
Definition: flow.h:450
SC_ATOMIC_EXTERN
SC_ATOMIC_EXTERN(unsigned int, flow_flags)
LiveDevice_
Definition: util-device-private.h:32
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:332
thread_name_flow_rec
const char * thread_name_flow_rec
Definition: runmodes.c:70
FlowRecyclerThreadData_::counter_queue_avg
StatsCounterAvgId counter_queue_avg
Definition: flow-manager.c:1048
FlowProtoTimeout_
Definition: flow.h:523
THV_RUNNING
#define THV_RUNNING
Definition: threadvars.h:54
flow-hash.h
TmModuleFlowRecyclerRegister
void TmModuleFlowRecyclerRegister(void)
Definition: flow-manager.c:1317
FlowTimeoutCounters_::flows_removed
uint32_t flows_removed
Definition: flow-manager.c:118
LiveDeviceGetById
LiveDevice * LiveDeviceGetById(const int id)
Definition: util-device.c:460
FlowCounters_::flow_mgr_full_pass
StatsCounterId flow_mgr_full_pass
Definition: flow-manager.c:647
FlowBypassInfo_::tosrcbytecnt
uint64_t tosrcbytecnt
Definition: flow.h:539
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
FlowGetMemuse
uint64_t FlowGetMemuse(void)
Definition: flow.c:126
rust.h
MIN
#define MIN(x, y)
Definition: suricata-common.h:413
tv_root
ThreadVars * tv_root[TVT_MAX]
Definition: tm-threads.c:83
FlowTimeoutCounters_::flows_timeout
uint32_t flows_timeout
Definition: flow-manager.c:117
defrag-timeout.h
FLOW_ACTION_DROP
#define FLOW_ACTION_DROP
Definition: flow.h:69
StatsCounterId
Definition: counters.h:30
DefragTrackerGetMemuse
uint64_t DefragTrackerGetMemuse(void)
Return memuse value.
Definition: defrag-hash.c:74
Flow_::livedev_id
uint16_t livedev_id
Definition: flow.h:404
FlowCounters_::flow_bypassed_pkts
StatsCounterId flow_bypassed_pkts
Definition: flow-manager.c:663
LiveDevSubBypassStats
void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family)
Definition: util-device.c:582
SleepUsec
#define SleepUsec(usec)
Definition: tm-threads.h:44
FlowCounters_::memcap_pressure_max
StatsCounterMaxId memcap_pressure_max
Definition: flow-manager.c:667
MAX
#define MAX(x, y)
Definition: suricata-common.h:417
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:82
FlowQueuePrivate_::len
uint32_t len
Definition: flow-queue.h:43
Flow_::protoctx
void * protoctx
Definition: flow.h:438
FlowCounters_::flow_mgr_rows_sec
StatsCounterId flow_mgr_rows_sec
Definition: flow-manager.c:648
FlowCounters_
Definition: flow-manager.c:646
FlowManagerTimeoutThread
struct FlowManagerTimeoutThread FlowManagerTimeoutThread
SCCtrlCondSignal
#define SCCtrlCondSignal
Definition: threads-debug.h:385
GetFlowBypassInfoID
SCFlowStorageId GetFlowBypassInfoID(void)
Definition: flow-util.c:223
StatsRegisterAvgCounter
StatsCounterAvgId StatsRegisterAvgCounter(const char *name, StatsThreadContext *stats)
Registers a counter, whose value holds the average of all the values assigned to it.
Definition: counters.c:1057
StatsCounterDecr
void StatsCounterDecr(StatsThreadContext *stats, StatsCounterId id)
Decrements the local counter.
Definition: counters.c:182
FLOW_TIMEOUT_REASSEMBLY_DONE
#define FLOW_TIMEOUT_REASSEMBLY_DONE
Definition: flow.h:96
runmode-unix-socket.h
TVT_MGMT
@ TVT_MGMT
Definition: tm-threads-common.h:89
FlowTimeoutCounters_::bypassed_count
uint32_t bypassed_count
Definition: flow-manager.c:122
TmThreadsGetThreadTime
SCTime_t TmThreadsGetThreadTime(const int idx)
Definition: tm-threads.c:2349
FlowSparePoolReturnFlows
void FlowSparePoolReturnFlows(FlowQueuePrivate *fqp)
Definition: flow-spare-pool.c:120
TM_THREAD_NAME_MAX
#define TM_THREAD_NAME_MAX
Definition: tm-threads.h:49
FlowCnf_::prealloc
uint32_t prealloc
Definition: flow.h:298
FLOWLOCK_UNLOCK
#define FLOWLOCK_UNLOCK(fb)
Definition: flow.h:276
FlowCounters_::flow_bypassed_bytes
StatsCounterId flow_bypassed_bytes
Definition: flow-manager.c:664
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:81
PacketPoolInit
void PacketPoolInit(void)
Definition: tmqh-packetpool.c:235
Flow_::flow_state
FlowStateType flow_state
Definition: flow.h:425
FQLOCK_LOCK
#define FQLOCK_LOCK(q)
Definition: flow-queue.h:72
FlowWakeupFlowManagerThread
void FlowWakeupFlowManagerThread(void)
Definition: flow-manager.c:85
FlowDisableFlowRecyclerThread
void FlowDisableFlowRecyclerThread(void)
Used to disable flow recycler thread(s).
Definition: flow-manager.c:1245
TmModule_::ThreadDeinit
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition: tm-modules.h:53
FlowTimeoutCounters_::rows_maxlen
uint32_t rows_maxlen
Definition: flow-manager.c:113
FlowTimeoutCounters_::flows_checked
uint32_t flows_checked
Definition: flow-manager.c:115
THV_RUNNING_DONE
#define THV_RUNNING_DONE
Definition: threadvars.h:45
StatsCounterAvgAddI64
void StatsCounterAvgAddI64(StatsThreadContext *stats, StatsCounterAvgId id, int64_t x)
Definition: counters.c:238
flow-spare-pool.h
Flow_::fb
struct FlowBucket_ * fb
Definition: flow.h:496
SC_ATOMIC_MEMORY_ORDER_RELAXED
#define SC_ATOMIC_MEMORY_ORDER_RELAXED
Definition: util-atomic.h:165
util-debug.h
FlowWakeupFlowRecyclerThread
void FlowWakeupFlowRecyclerThread(void)
Definition: flow-manager.c:92
FlowBypassInfo_::todstbytecnt
uint64_t todstbytecnt
Definition: flow.h:541
SCFlowRunFinishCallbacks
void SCFlowRunFinishCallbacks(ThreadVars *tv, Flow *f)
Definition: flow-callbacks.c:122
FlowBypassInfo_::BypassUpdate
bool(* BypassUpdate)(Flow *f, void *data, time_t tsec)
Definition: flow.h:535
StatsCounterMaxId
Definition: counters.h:38
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:120
Flow_::lastts
SCTime_t lastts
Definition: flow.h:423
SCConfGetInt
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
Definition: conf.c:440
FLOWLOCK_WRLOCK
#define FLOWLOCK_WRLOCK(fb)
Definition: flow.h:273
FlowTimeoutsReset
#define FlowTimeoutsReset()
Definition: flow-manager.h:30
FlowDisableFlowManagerThread
void FlowDisableFlowManagerThread(void)
Used to disable flow manager thread(s).
Definition: flow-manager.c:133
SCCtrlCondT
#define SCCtrlCondT
Definition: threads-debug.h:383
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
TmModule_::Management
TmEcode(* Management)(ThreadVars *, void *)
Definition: tm-modules.h:69
TimeModeIsReady
bool TimeModeIsReady(void)
Definition: util-time.c:92
Flow_::flow_end_flags
uint8_t flow_end_flags
Definition: flow.h:452
THV_KILL
#define THV_KILL
Definition: threadvars.h:39
MemcapsGetPressure
float MemcapsGetPressure(void)
Definition: runmode-unix-socket.c:110
StatsCounterIncr
void StatsCounterIncr(StatsThreadContext *stats, StatsCounterId id)
Increments the local counter.
Definition: counters.c:163
FlowBypassInfo_::todstpktcnt
uint64_t todstpktcnt
Definition: flow.h:540
FlowQueuePrivateGetFromTop
Flow * FlowQueuePrivateGetFromTop(FlowQueuePrivate *fqc)
Definition: flow-queue.c:151
FlowBypassInfo_::bypass_data
void * bypass_data
Definition: flow.h:537
FlowQueueAppendPrivate
void FlowQueueAppendPrivate(FlowQueue *fq, FlowQueuePrivate *fqc)
Definition: flow-queue.c:119
ThreadVars_::next
struct ThreadVars_ * next
Definition: threadvars.h:123
FlowRecyclerThreadData_
Definition: flow-manager.c:1044
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:322
FLOW_IS_IPV4
#define FLOW_IS_IPV4(f)
Definition: flow.h:173
tv_root_lock
SCMutex tv_root_lock
Definition: tm-threads.c:86
SC_ATOMIC_SUB
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
Definition: util-atomic.h:341
flow_timeouts_emerg
FlowProtoTimeout flow_timeouts_emerg[FLOW_PROTO_MAX]
Definition: flow.c:87
TimeModeIsLive
bool TimeModeIsLive(void)
Definition: util-time.c:111
SCCtrlMutexLock
#define SCCtrlMutexLock(mut)
Definition: threads-debug.h:377
FlowTimeoutsEmergency
void FlowTimeoutsEmergency(void)
Definition: flow-manager.c:104
FlowTimeoutCounters
struct FlowTimeoutCounters_ FlowTimeoutCounters
tmm_modules
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.c:29
TimeGet
SCTime_t TimeGet(void)
Definition: util-time.c:152
conf.h
FlowRecyclerThreadData_::output_thread_data
void * output_thread_data
Definition: flow-manager.c:1045
FlowTimeoutCounters_::rows_checked
uint32_t rows_checked
Definition: flow-manager.c:110
FBLOCK_UNLOCK
#define FBLOCK_UNLOCK(fb)
Definition: flow-hash.h:75
SCTime_t
Definition: util-time.h:40
TmEcode
TmEcode
Definition: tm-threads-common.h:80
FlowClearMemory
int FlowClearMemory(Flow *f, uint8_t proto_map)
Function clear the flow memory before queueing it to spare flow queue.
Definition: flow.c:1124
FlowRecyclerThreadSpawn
void FlowRecyclerThreadSpawn(void)
spawn the flow recycler thread
Definition: flow-manager.c:1209
output-flow.h
flow-timeout.h
flow-queue.h
TmModule_::name
const char * name
Definition: tm-modules.h:48
FlowRecyclerThreadData
struct FlowRecyclerThreadData_ FlowRecyclerThreadData
FlowBypassInfo_::tosrcpktcnt
uint64_t tosrcpktcnt
Definition: flow.h:538
host-timeout.h
SCCtrlCondTimedwait
#define SCCtrlCondTimedwait
Definition: threads-debug.h:386
StreamTcpThreadCacheCleanup
void StreamTcpThreadCacheCleanup(void)
Definition: stream-tcp-cache.c:134
runmodes.h
FlowTimeoutCounters_::flows_aside_needs_work
uint32_t flows_aside_needs_work
Definition: flow-manager.c:120
FlowCounters_::flow_mgr_flows_aside_needs_work
StatsCounterId flow_mgr_flows_aside_needs_work
Definition: flow-manager.c:658
Flow_::next
struct Flow_ * next
Definition: flow.h:406
FlowQueue_
Definition: flow-queue.h:48
FlowCounters_::flow_bypassed_cnt_clo
StatsCounterId flow_bypassed_cnt_clo
Definition: flow-manager.c:662
TMM_FLOWMANAGER
@ TMM_FLOWMANAGER
Definition: tm-threads-common.h:69
SCTIME_CMP_LT
#define SCTIME_CMP_LT(a, b)
Definition: util-time.h:105
FlowCounters_::flow_mgr_flows_checked
StatsCounterId flow_mgr_flows_checked
Definition: flow-manager.c:654
RECYCLE_MAX_QUEUE_ITEMS
#define RECYCLE_MAX_QUEUE_ITEMS
Definition: flow-manager.c:608
flow_hash
FlowBucket * flow_hash
Definition: flow-hash.c:58
SCCtrlMutexUnlock
#define SCCtrlMutexUnlock(mut)
Definition: threads-debug.h:379
FlowCounters_::flow_mgr_spare
StatsCounterId flow_mgr_spare
Definition: flow-manager.c:650
th_v
ThreadVars * th_v
Definition: fuzz_dataset.c:29
FlowQueueExtractPrivate
FlowQueuePrivate FlowQueueExtractPrivate(FlowQueue *fq)
Definition: flow-queue.c:140
flow-storage.h
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
FlowCounters_::flow_emerg_mode_over
StatsCounterId flow_emerg_mode_over
Definition: flow-manager.c:652
FlowTimeoutCounters_
Definition: flow-manager.c:109
FlowManagerThreadData_
Definition: flow-manager.c:670
FlowCounters_::flow_mgr_flows_notimeout
StatsCounterId flow_mgr_flows_notimeout
Definition: flow-manager.c:655
SleepMsec
#define SleepMsec(msec)
Definition: tm-threads.h:45
FlowManagerThreadData_::counter_defrag_memuse
StatsCounterId counter_defrag_memuse
Definition: flow-manager.c:679
flow-manager.h
suricata-common.h
SCCtrlMutex
#define SCCtrlMutex
Definition: threads-debug.h:374
DefragTimeoutHash
uint32_t DefragTimeoutHash(SCTime_t ts)
time out tracker from the hash
Definition: defrag-timeout.c:122
FlowManagerThreadData
struct FlowManagerThreadData_ FlowManagerThreadData
flow_config
FlowConfig flow_config
Definition: flow.c:91
TmThreadsWaitForUnpause
bool TmThreadsWaitForUnpause(ThreadVars *tv)
Wait for a thread to become unpaused.
Definition: tm-threads.c:371
TmModuleFlowManagerRegister
void TmModuleFlowManagerRegister(void)
Definition: flow-manager.c:1303
SCLogPerf
#define SCLogPerf(...)
Definition: util-debug.h:241
FlowTimeoutsInit
void FlowTimeoutsInit(void)
Definition: flow-manager.c:99
StatsSyncCounters
void StatsSyncCounters(StatsThreadContext *stats)
Definition: counters.c:476
SCTIME_SECS
#define SCTIME_SECS(t)
Definition: util-time.h:57
SC_ATOMIC_LOAD_EXPLICIT
#define SC_ATOMIC_LOAD_EXPLICIT(name, order)
Definition: util-atomic.h:378
FlowCounters_::flow_emerg_mode_enter
StatsCounterId flow_emerg_mode_enter
Definition: flow-manager.c:651
FlowRecyclerThreadData_::counter_queue_max
StatsCounterMaxId counter_queue_max
Definition: flow-manager.c:1049
TmModule_::ThreadInit
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:51
FatalError
#define FatalError(...)
Definition: util-debug.h:517
FlowRecyclerThreadData_::counter_flows
StatsCounterId counter_flows
Definition: flow-manager.c:1047
Flow_::timeout_policy
uint32_t timeout_policy
Definition: flow.h:418
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:34
threadvars.h
FlowQueuePrivate_
Definition: flow-queue.h:40
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
StatsCounterSetI64
void StatsCounterSetI64(StatsThreadContext *stats, StatsCounterId id, int64_t x)
set, so overwrite, the value of the local counter
Definition: counters.c:202
FlowTimeoutCounters_::bypassed_bytes
uint64_t bypassed_bytes
Definition: flow-manager.c:124
FlowRecyclerThreadData_::counter_flow_active
StatsCounterId counter_flow_active
Definition: flow-manager.c:1051
FlowManagerThreadData_::min
uint32_t min
Definition: flow-manager.c:672
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
OutputFlowLogThreadDeinit
TmEcode OutputFlowLogThreadDeinit(ThreadVars *tv, void *thread_data)
Definition: output-flow.c:161
flow_recycle_q
FlowQueue flow_recycle_q
Definition: flow-manager.c:66
flow-callbacks.h
StatsCounterAvgId
Definition: counters.h:34
SCFree
#define SCFree(p)
Definition: util-mem.h:61
FlowTimeoutCounters_::bypassed_pkts
uint64_t bypassed_pkts
Definition: flow-manager.c:123
HostTimeoutHash
uint32_t HostTimeoutHash(SCTime_t ts)
time out hosts from the hash
Definition: host-timeout.c:126
FlowManagerThreadData_::counter_defrag_timeout
StatsCounterId counter_defrag_timeout
Definition: flow-manager.c:678
StatsRegisterMaxCounter
StatsCounterMaxId StatsRegisterMaxCounter(const char *name, StatsThreadContext *stats)
Registers a counter, whose value holds the maximum of all the values assigned to it.
Definition: counters.c:1076
SC_ATOMIC_INITPTR
#define SC_ATOMIC_INITPTR(name)
Definition: util-atomic.h:317
stream-tcp-cache.h
FlowManagerThreadData_::timeout
FlowManagerTimeoutThread timeout
Definition: flow-manager.c:677
FlowCounters
struct FlowCounters_ FlowCounters
FlowRecyclerThreadData_::counter_tcp_active_sessions
StatsCounterId counter_tcp_active_sessions
Definition: flow-manager.c:1052
FLOW_END_FLAG_SHUTDOWN
#define FLOW_END_FLAG_SHUTDOWN
Definition: flow.h:248
EngineModeIsIPS
int EngineModeIsIPS(void)
Definition: suricata.c:247
FLOW_EMERGENCY
#define FLOW_EMERGENCY
Definition: flow-private.h:35
suricata.h
defrag-hash.h
ippair-timeout.h
FlowManagerTimeoutThread::aside_queue
FlowQueuePrivate aside_queue
Definition: flow-manager.c:280
timeradd
#define timeradd(a, b, r)
Definition: util-time.h:127
FLOW_END_FLAG_TIMEOUT
#define FLOW_END_FLAG_TIMEOUT
Definition: flow.h:246
FlowTimeoutCounters_::flows_notimeout
uint32_t flows_notimeout
Definition: flow-manager.c:116
flow_timeouts_normal
FlowProtoTimeout flow_timeouts_normal[FLOW_PROTO_MAX]
Definition: flow.c:86
FlowNeedsReassembly
bool FlowNeedsReassembly(Flow *f)
Check if a flow needs forced reassembly, or any other processing.
Definition: flow-timeout.c:285
FlowTimeoutCounters_::flows_aside
uint32_t flows_aside
Definition: flow-manager.c:119
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375
PacketPoolDestroy
void PacketPoolDestroy(void)
Definition: tmqh-packetpool.c:265
flow.h
FlowQueuePrivateAppendFlow
void FlowQueuePrivateAppendFlow(FlowQueuePrivate *fqc, Flow *f)
Definition: flow-queue.c:65
FlowEndCountersRegister
void FlowEndCountersRegister(ThreadVars *t, FlowEndCounters *fec)
Definition: flow-util.c:246
TmThreadsCheckFlag
int TmThreadsCheckFlag(ThreadVars *tv, uint32_t flag)
Check if a thread flag is set.
Definition: tm-threads.c:94
SCLogNotice
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Definition: util-debug.h:250
SCTIME_ADD_SECS
#define SCTIME_ADD_SECS(ts, s)
Definition: util-time.h:64
FlowCounters_::flow_mgr_flows_aside
StatsCounterId flow_mgr_flows_aside
Definition: flow-manager.c:657
evicted
Flow * evicted
Definition: flow-hash.h:4
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
BITS
#define BITS
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:120
FlowEndCounters_
Definition: flow-util.h:146
FLOW_SPARE_POOL_BLOCK_SIZE
#define FLOW_SPARE_POOL_BLOCK_SIZE
Definition: flow-spare-pool.h:30
StatsCounterAddI64
void StatsCounterAddI64(StatsThreadContext *stats, StatsCounterId id, int64_t x)
Adds a value of type uint64_t to the local counter.
Definition: counters.c:144
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:109
TmModule_::flags
uint8_t flags
Definition: tm-modules.h:80
SC_ATOMIC_AND
#define SC_ATOMIC_AND(name, val)
Bitwise AND a value to our atomic variable.
Definition: util-atomic.h:359
TM_FLAG_MANAGEMENT_TM
#define TM_FLAG_MANAGEMENT_TM
Definition: tm-modules.h:36
suricata_ctl_flags
volatile uint8_t suricata_ctl_flags
Definition: suricata.c:177
detect-engine-threshold.h
FlowTimeoutCounters_::rows_skipped
uint32_t rows_skipped
Definition: flow-manager.c:111
Flow_::thread_id
FlowThreadId thread_id[2]
Definition: flow.h:397
ThresholdsExpire
uint32_t ThresholdsExpire(const SCTime_t ts)
Definition: detect-engine-threshold.c:390
SCTIME_USECS
#define SCTIME_USECS(t)
Definition: util-time.h:56
FlowTimeoutCounters::flows_aside_needs_work
uint32_t flows_aside_needs_work
Definition: flow-worker.c:61
FQLOCK_UNLOCK
#define FQLOCK_UNLOCK(q)
Definition: flow-queue.h:74
f
Flow f
Definition: fuzz_dataset.c:32
HttpRangeContainersTimeoutHash
uint32_t HttpRangeContainersTimeoutHash(const SCTime_t ts)
Definition: app-layer-htp-range.c:209