suricata
flow.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 Victor Julien <victor@inliniac.net>
22  *
23  * Flow implementation.
24  */
25 
26 #include "suricata-common.h"
27 #include "suricata.h"
28 
29 #include "action-globals.h"
30 #include "packet.h"
31 #include "decode.h"
32 #include "conf.h"
33 #include "threadvars.h"
34 
35 #include "util-random.h"
36 #include "util-time.h"
37 
38 #include "flow.h"
39 #include "flow-bindgen.h"
40 #include "flow-queue.h"
41 #include "flow-hash.h"
42 #include "flow-util.h"
43 #include "flow-private.h"
44 #include "flow-manager.h"
45 #include "flow-storage.h"
46 #include "flow-bypass.h"
47 #include "flow-spare-pool.h"
48 #include "flow-callbacks.h"
49 
50 #include "stream-tcp-private.h"
51 
52 #include "util-unittest.h"
53 #include "util-unittest-helper.h"
54 #include "util-byte.h"
55 #include "util-misc.h"
56 #include "util-macset.h"
57 #include "util-flow-rate.h"
58 
59 #include "util-debug.h"
60 
61 #include "rust.h"
62 #include "app-layer-parser.h"
63 #include "app-layer-expectation.h"
64 
65 #define FLOW_DEFAULT_EMERGENCY_RECOVERY 30
66 
67 //#define FLOW_DEFAULT_HASHSIZE 262144
68 #define FLOW_DEFAULT_HASHSIZE 65536
69 //#define FLOW_DEFAULT_MEMCAP 128 * 1024 * 1024 /* 128 MB */
70 #define FLOW_DEFAULT_MEMCAP (32 * 1024 * 1024) /* 32 MB */
71 
72 #define FLOW_DEFAULT_PREALLOC 10000
73 
75 
76 /** atomic int that is used when freeing a flow from the hash. In this
77  * case we walk the hash to find a flow to free. This var records where
78  * we left off in the hash. Without this only the top rows of the hash
79  * are freed. This isn't just about fairness. Under severe pressure, the
80  * hash rows on top would be all freed and the time to find a flow to
81  * free increased with every run. */
82 SC_ATOMIC_DECLARE(unsigned int, flow_prune_idx);
83 
84 /** atomic flags */
85 SC_ATOMIC_DECLARE(unsigned int, flow_flags);
86 
87 /** FlowProto specific timeouts and free/state functions */
88 
93 
95 
96 /** flow memuse counter (atomic), for enforcing memcap limit */
97 SC_ATOMIC_DECLARE(uint64_t, flow_memuse);
98 
99 void FlowRegisterTests(void);
100 void FlowInitFlowProto(void);
101 int FlowSetProtoFreeFunc(uint8_t, void (*Free)(void *));
102 
103 /**
104  * \brief Update memcap value
105  *
106  * \param size new memcap value
107  */
108 int FlowSetMemcap(uint64_t size)
109 {
110  if ((uint64_t)SC_ATOMIC_GET(flow_memuse) < size) {
111  SC_ATOMIC_SET(flow_config.memcap, size);
112  return 1;
113  }
114 
115  return 0;
116 }
117 
118 /**
119  * \brief Return memcap value
120  *
121  * \retval memcap value
122  */
123 uint64_t FlowGetMemcap(void)
124 {
125  uint64_t memcapcopy = SC_ATOMIC_GET(flow_config.memcap);
126  return memcapcopy;
127 }
128 
129 uint64_t FlowGetMemuse(void)
130 {
131  uint64_t memusecopy = SC_ATOMIC_GET(flow_memuse);
132  return memusecopy;
133 }
134 
136 {
137  return flow_config.memcap_policy;
138 }
139 
141 {
142  if (f == NULL || f->proto == 0)
143  return;
144 
146  f->alstate = NULL;
147  f->alparser = NULL;
148 }
149 
150 /** \brief Set flag to indicate that flow has alerts
151  *
152  * \param f flow
153  */
155 {
156  f->flags |= FLOW_HAS_ALERTS;
157 }
158 
159 /** \brief Check if flow has alerts
160  *
161  * \param f flow
162  * \retval 1 has alerts
163  * \retval 0 has not alerts
164  */
165 int FlowHasAlerts(const Flow *f)
166 {
167  if (f->flags & FLOW_HAS_ALERTS) {
168  return 1;
169  }
170 
171  return 0;
172 }
173 
174 /** \brief Set flag to indicate to change proto for the flow
175  *
176  * \param f flow
177  */
179 {
180  f->flags |= FLOW_CHANGE_PROTO;
181 }
182 
183 /** \brief Unset flag to indicate to change proto for the flow
184  *
185  * \param f flow
186  */
188 {
189  f->flags &= ~FLOW_CHANGE_PROTO;
190 }
191 
192 /** \brief Check if change proto flag is set for flow
193  * \param f flow
194  * \retval 1 change proto flag is set
195  * \retval 0 change proto flag is not set
196  */
198 {
199  if (f->flags & FLOW_CHANGE_PROTO) {
200  return 1;
201  }
202 
203  return 0;
204 }
205 
206 static inline void FlowSwapFlags(Flow *f)
207 {
210 
215 
217 }
218 
219 static inline void FlowSwapFileFlags(Flow *f)
220 {
226 }
227 
228 static inline void TcpStreamFlowSwap(Flow *f)
229 {
230  TcpSession *ssn = f->protoctx;
231  SWAP_VARS(TcpStream, ssn->server, ssn->client);
232  if (ssn->data_first_seen_dir & STREAM_TOSERVER) {
233  ssn->data_first_seen_dir = STREAM_TOCLIENT;
234  } else if (ssn->data_first_seen_dir & STREAM_TOCLIENT) {
235  ssn->data_first_seen_dir = STREAM_TOSERVER;
236  }
237 }
238 
239 /** \brief swap the flow's direction
240  * \note leaves the 'header' untouched. Interpret that based
241  * on FLOW_DIR_REVERSED flag.
242  * \warning: only valid before applayer parsing started. This
243  * function doesn't swap anything in Flow::alparser,
244  * Flow::alstate
245  */
246 void FlowSwap(Flow *f)
247 {
248  f->flags |= FLOW_DIR_REVERSED;
249 
252 
253  FlowSwapFlags(f);
254  FlowSwapFileFlags(f);
255 
256  SWAP_VARS(FlowThreadId, f->thread_id[0], f->thread_id[1]);
257 
258  if (f->proto == IPPROTO_TCP) {
259  TcpStreamFlowSwap(f);
260  }
261 
265 
266  /* not touching Flow::alparser and Flow::alstate */
267 
268  SWAP_VARS(const void *, f->sgh_toclient, f->sgh_toserver);
269 
270  SWAP_VARS(uint32_t, f->todstpktcnt, f->tosrcpktcnt);
271  SWAP_VARS(uint64_t, f->todstbytecnt, f->tosrcbytecnt);
272 
273  if (MacSetFlowStorageEnabled()) {
275  if (ms != NULL) {
276  MacSetSwap(ms);
277  }
278  }
279 }
280 
281 /**
282  * \brief determine the direction of the packet compared to the flow
283  * \retval 0 to_server
284  * \retval 1 to_client
285  */
286 int FlowGetPacketDirection(const Flow *f, const Packet *p)
287 {
288  const int reverse = (f->flags & FLOW_DIR_REVERSED) != 0;
289 
290  if (p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP || p->proto == IPPROTO_SCTP) {
291  if (!(CMP_PORT(p->sp,p->dp))) {
292  /* update flags and counters */
293  if (CMP_PORT(f->sp,p->sp)) {
294  return TOSERVER ^ reverse;
295  } else {
296  return TOCLIENT ^ reverse;
297  }
298  } else {
299  if (CMP_ADDR(&f->src,&p->src)) {
300  return TOSERVER ^ reverse;
301  } else {
302  return TOCLIENT ^ reverse;
303  }
304  }
305  } else if (p->proto == IPPROTO_ICMP || p->proto == IPPROTO_ICMPV6) {
306  if (CMP_ADDR(&f->src,&p->src)) {
307  return TOSERVER ^ reverse;
308  } else {
309  return TOCLIENT ^ reverse;
310  }
311  }
312 
313  /* default to toserver */
314  return TOSERVER;
315 }
316 
317 /**
318  * \brief Check to update "seen" flags
319  *
320  * \param p packet
321  *
322  * \retval 1 true
323  * \retval 0 false
324  */
325 static inline int FlowUpdateSeenFlag(const Packet *p)
326 {
327  if (PacketIsICMPv4(p)) {
328  if (ICMPV4_IS_ERROR_MSG(p->icmp_s.type)) {
329  return 0;
330  }
331  }
332 
333  return 1;
334 }
335 
336 static inline void FlowUpdateTtlTS(Flow *f, uint8_t ttl)
337 {
338  if (f->min_ttl_toserver == 0) {
339  f->min_ttl_toserver = ttl;
340  } else {
341  f->min_ttl_toserver = MIN(f->min_ttl_toserver, ttl);
342  }
343  f->max_ttl_toserver = MAX(f->max_ttl_toserver, ttl);
344 }
345 
346 static inline void FlowUpdateTtlTC(Flow *f, uint8_t ttl)
347 {
348  if (f->min_ttl_toclient == 0) {
349  f->min_ttl_toclient = ttl;
350  } else {
351  f->min_ttl_toclient = MIN(f->min_ttl_toclient, ttl);
352  }
353  f->max_ttl_toclient = MAX(f->max_ttl_toclient, ttl);
354 }
355 
356 static inline void FlowUpdateFlowRate(
357  ThreadVars *tv, DecodeThreadVars *dtv, Flow *f, const Packet *p, int dir)
358 {
359  if (FlowRateStorageEnabled()) {
360  /* No need to update the struct if flow is already marked as elephant flow */
361  if ((dir == TOSERVER) && (f->flags & FLOW_IS_ELEPHANT_TOSERVER))
362  return;
363  if ((dir == TOCLIENT) && (f->flags & FLOW_IS_ELEPHANT_TOCLIENT))
364  return;
366  if (frs != NULL) {
367  FlowRateStoreUpdate(frs, p->ts, GET_PKT_LEN(p), dir);
368  bool fr_exceeds = FlowRateIsExceeding(frs, dir);
369  if (fr_exceeds) {
370  SCLogDebug("Flow rate for flow %p exceeds the configured values, marking it as an "
371  "elephant flow",
372  f);
373  if (dir == TOSERVER) {
375  if (tv != NULL) {
376  if ((f->flags & FLOW_IS_ELEPHANT_TOCLIENT) == 0) {
378  }
380  }
381  } else {
383  if (tv != NULL) {
384  if ((f->flags & FLOW_IS_ELEPHANT_TOSERVER) == 0) {
386  }
388  }
389  }
390  }
391  }
392  }
393 }
394 
395 static inline void FlowUpdateEthernet(
396  ThreadVars *tv, DecodeThreadVars *dtv, Flow *f, const Packet *p, bool toserver)
397 {
398  if (PacketIsEthernet(p) && MacSetFlowStorageEnabled()) {
399  const EthernetHdr *ethh = PacketGetEthernet(p);
401  if (ms != NULL) {
402  if (toserver) {
403  MacSetAddWithCtr(ms, ethh->eth_src, ethh->eth_dst, tv,
406  } else {
407  MacSetAddWithCtr(ms, ethh->eth_dst, ethh->eth_src, tv,
410  }
411  }
412  }
413 }
414 
415 /** \brief Update Packet and Flow
416  *
417  * Updates packet and flow based on the new packet.
418  *
419  * \param f locked flow
420  * \param p packet
421  *
422  * \note overwrites p::flowflags
423  */
425 {
426  SCLogDebug("packet %" PRIu64 " -- flow %p", PcapPacketCntGet(p), f);
427 
428  const int pkt_dir = FlowGetPacketDirection(f, p);
429 #ifdef CAPTURE_OFFLOAD
430  int state = f->flow_state;
431 
432  if (state != FLOW_STATE_CAPTURE_BYPASSED) {
433 #endif
434  /* update the last seen timestamp of this flow */
435  if (SCTIME_CMP_GT(p->ts, f->lastts)) {
436  f->lastts = p->ts;
437  }
438 #ifdef CAPTURE_OFFLOAD
439  } else {
440  FlowProtoTimeoutPtr flow_timeouts = SC_ATOMIC_GET(flow_timeouts);
441  /* still seeing packet, we downgrade to local bypass */
442  if (SCTIME_SECS(p->ts) - SCTIME_SECS(f->lastts) >
443  flow_timeouts[f->protomap].bypassed_timeout / 2) {
444  SCLogDebug("Downgrading flow to local bypass");
445  f->lastts = p->ts;
447  } else {
448  /* In IPS mode the packet could come from the other interface so it would
449  * need to be bypassed */
450  if (EngineModeIsIPS()) {
451  BypassedFlowUpdate(f, p);
452  }
453  }
454  }
455 #endif
456  /* update flags and counters */
457  if (pkt_dir == TOSERVER) {
458  f->todstpktcnt++;
459  f->todstbytecnt += GET_PKT_LEN(p);
460  FlowUpdateFlowRate(tv, dtv, f, p, TOSERVER);
462  if (!(f->flags & FLOW_TO_DST_SEEN)) {
463  if (FlowUpdateSeenFlag(p)) {
464  f->flags |= FLOW_TO_DST_SEEN;
467  }
468  }
469  /* xfer proto detect ts flag to first packet in ts dir */
470  if (f->flags & FLOW_PROTO_DETECT_TS_DONE) {
473  }
474  FlowUpdateEthernet(tv, dtv, f, p, true);
475  /* update flow's ttl fields if needed */
476  if (PacketIsIPv4(p)) {
477  const IPV4Hdr *ip4h = PacketGetIPv4(p);
478  FlowUpdateTtlTS(f, IPV4_GET_RAW_IPTTL(ip4h));
479  } else if (PacketIsIPv6(p)) {
480  const IPV6Hdr *ip6h = PacketGetIPv6(p);
481  FlowUpdateTtlTS(f, IPV6_GET_RAW_HLIM(ip6h));
482  }
483  } else {
484  f->tosrcpktcnt++;
485  f->tosrcbytecnt += GET_PKT_LEN(p);
486  FlowUpdateFlowRate(tv, dtv, f, p, TOCLIENT);
488  if (!(f->flags & FLOW_TO_SRC_SEEN)) {
489  if (FlowUpdateSeenFlag(p)) {
490  f->flags |= FLOW_TO_SRC_SEEN;
493  }
494  }
495  /* xfer proto detect tc flag to first packet in tc dir */
496  if (f->flags & FLOW_PROTO_DETECT_TC_DONE) {
499  }
500  FlowUpdateEthernet(tv, dtv, f, p, false);
501  /* update flow's ttl fields if needed */
502  if (PacketIsIPv4(p)) {
503  const IPV4Hdr *ip4h = PacketGetIPv4(p);
504  FlowUpdateTtlTC(f, IPV4_GET_RAW_IPTTL(ip4h));
505  } else if (PacketIsIPv6(p)) {
506  const IPV6Hdr *ip6h = PacketGetIPv6(p);
507  FlowUpdateTtlTC(f, IPV6_GET_RAW_HLIM(ip6h));
508  }
509  }
510  if (f->thread_id[pkt_dir] == 0) {
511  f->thread_id[pkt_dir] = (FlowThreadId)tv->id;
512  }
513 
515  SCLogDebug("pkt %p FLOW_PKT_ESTABLISHED", p);
517 
518  } else if (f->proto == IPPROTO_TCP) {
519  TcpSession *ssn = (TcpSession *)f->protoctx;
520  if (ssn != NULL && ssn->state >= TCP_ESTABLISHED) {
522  }
523  } else if ((f->flags & (FLOW_TO_DST_SEEN|FLOW_TO_SRC_SEEN)) ==
525  SCLogDebug("pkt %p FLOW_PKT_ESTABLISHED", p);
527 
528  if (
529 #ifdef CAPTURE_OFFLOAD
530  (f->flow_state != FLOW_STATE_CAPTURE_BYPASSED) &&
531 #endif
534  }
535  }
536 
537  if (f->flags & FLOW_ACTION_DROP) {
539  }
540 
541  if (f->flags & FLOW_NOPAYLOAD_INSPECTION) {
542  SCLogDebug("setting FLOW_NOPAYLOAD_INSPECTION flag on flow %p", f);
543  DecodeSetNoPayloadInspectionFlag(p);
544  }
545 
547 }
548 
549 /** \brief Entry point for packet flow handling
550  *
551  * This is called for every packet.
552  *
553  * \param tv threadvars
554  * \param dtv decode thread vars (for flow output api thread data)
555  * \param p packet to handle flow for
556  */
558 {
559  /* Get this packet's flow from the hash. FlowHandlePacket() will setup
560  * a new flow if necessary. If we get NULL, we're out of flow memory.
561  * The returned flow is locked. */
562  Flow *f = FlowGetFlowFromHash(tv, fls, p, &p->flow);
563  if (f != NULL) {
564  /* set the flow in the packet */
565  p->flags |= PKT_HAS_FLOW;
566  }
567 }
568 
569 /** \brief initialize the configuration
570  * \warning Not thread safe */
571 void FlowInitConfig(bool quiet)
572 {
573  SCLogDebug("initializing flow engine...");
574 
575  memset(&flow_config, 0, sizeof(flow_config));
576  SC_ATOMIC_INIT(flow_flags);
577  SC_ATOMIC_INIT(flow_memuse);
578  SC_ATOMIC_INIT(flow_prune_idx);
579  SC_ATOMIC_INIT(flow_config.memcap);
581 
582  /* set defaults */
583  flow_config.hash_rand = (uint32_t)RandomGet();
587 
588  /* If we have specific config, overwrite the defaults with them,
589  * otherwise, leave the default values */
590  intmax_t val = 0;
591  if (SCConfGetInt("flow.emergency-recovery", &val) == 1) {
592  if (val <= 100 && val >= 1) {
593  flow_config.emergency_recovery = (uint8_t)val;
594  } else {
595  SCLogError("flow.emergency-recovery must be in the range of "
596  "1 and 100 (as percentage)");
598  }
599  } else {
600  SCLogDebug("flow.emergency-recovery, using default value");
602  }
603 
604  /* Check if we have memcap and hash_size defined at config */
605  const char *conf_val;
606  uint32_t configval = 0;
607 
608  /** set config values for memcap, prealloc and hash_size */
609  uint64_t flow_memcap_copy = 0;
610  if ((SCConfGet("flow.memcap", &conf_val)) == 1) {
611  if (conf_val == NULL) {
612  FatalError("Invalid value for flow.memcap: NULL");
613  }
614 
615  if (ParseSizeStringU64(conf_val, &flow_memcap_copy) < 0) {
616  SCLogError("Error parsing flow.memcap "
617  "from conf file - %s. Killing engine",
618  conf_val);
619  exit(EXIT_FAILURE);
620  } else {
621  SC_ATOMIC_SET(flow_config.memcap, flow_memcap_copy);
622  }
623  }
624  if ((SCConfGet("flow.hash-size", &conf_val)) == 1) {
625  if (conf_val == NULL) {
626  FatalError("Invalid value for flow.hash-size: NULL");
627  }
628 
629  if (StringParseUint32(&configval, 10, strlen(conf_val), conf_val) && configval != 0) {
630  flow_config.hash_size = configval;
631  } else {
632  FatalError("Invalid value for flow.hash-size. Must be a numeric value in the range "
633  "1-4294967295");
634  }
635  }
636  if ((SCConfGet("flow.prealloc", &conf_val)) == 1) {
637  if (conf_val == NULL) {
638  FatalError("Invalid value for flow.prealloc: NULL");
639  }
640 
641  if (StringParseUint32(&configval, 10, strlen(conf_val),
642  conf_val) > 0) {
643  flow_config.prealloc = configval;
644  }
645  }
646 
647  flow_config.memcap_policy = ExceptionPolicyParse("flow.memcap-policy", false);
648 
649  SCLogDebug("Flow config from suricata.yaml: memcap: %"PRIu64", hash-size: "
650  "%"PRIu32", prealloc: %"PRIu32, SC_ATOMIC_GET(flow_config.memcap),
652 
653  /* alloc hash memory */
654  uint64_t hash_size = flow_config.hash_size * sizeof(FlowBucket);
655  if (!(FLOW_CHECK_MEMCAP(hash_size))) {
656  SCLogError("allocating flow hash failed: "
657  "max flow memcap is smaller than projected hash size. "
658  "Memcap: %" PRIu64 ", Hash table size %" PRIu64 ". Calculate "
659  "total hash size by multiplying \"flow.hash-size\" with %" PRIuMAX ", "
660  "which is the hash bucket size.",
661  SC_ATOMIC_GET(flow_config.memcap), hash_size, (uintmax_t)sizeof(FlowBucket));
662  exit(EXIT_FAILURE);
663  }
664  flow_hash = SCMallocAligned(flow_config.hash_size * sizeof(FlowBucket), CLS);
665  if (unlikely(flow_hash == NULL)) {
666  FatalError("Fatal error encountered in FlowInitConfig. Exiting...");
667  }
668  memset(flow_hash, 0, flow_config.hash_size * sizeof(FlowBucket));
669 
670  uint32_t i = 0;
671  for (i = 0; i < flow_config.hash_size; i++) {
672  FBLOCK_INIT(&flow_hash[i]);
673  SC_ATOMIC_INIT(flow_hash[i].next_ts);
674  }
675  (void) SC_ATOMIC_ADD(flow_memuse, (flow_config.hash_size * sizeof(FlowBucket)));
676 
677  if (!quiet) {
678  SCLogConfig("allocated %"PRIu64" bytes of memory for the flow hash... "
679  "%" PRIu32 " buckets of size %" PRIuMAX "",
680  SC_ATOMIC_GET(flow_memuse), flow_config.hash_size,
681  (uintmax_t)sizeof(FlowBucket));
682  }
684  if (!quiet) {
685  SCLogConfig("flow memory usage: %"PRIu64" bytes, maximum: %"PRIu64,
686  SC_ATOMIC_GET(flow_memuse), SC_ATOMIC_GET(flow_config.memcap));
687  }
688 
690 
691  uint32_t sz = sizeof(Flow) + FlowStorageSize();
692  SCLogConfig("flow size %u, memcap allows for %" PRIu64 " flows. Per hash row in perfect "
693  "conditions %" PRIu64,
694  sz, flow_memcap_copy / sz, (flow_memcap_copy / sz) / flow_config.hash_size);
695 }
696 
697 void FlowReset(void)
698 {
699  // resets the flows (for reuse by fuzzing)
700  for (uint32_t u = 0; u < flow_config.hash_size; u++) {
701  Flow *f = flow_hash[u].head;
702  while (f) {
703  Flow *n = f->next;
704  uint8_t proto_map = FlowGetProtoMapping(f->proto);
705  FlowClearMemory(f, proto_map);
706  FlowFree(f);
707  f = n;
708  }
709  flow_hash[u].head = NULL;
710  }
711 }
712 
713 /** \brief shutdown the flow engine
714  * \warning Not thread safe */
715 void FlowShutdown(void)
716 {
717  Flow *f;
718  while ((f = FlowDequeue(&flow_recycle_q))) {
719  FlowFree(f);
720  }
721 
722  /* clear and free the hash */
723  if (flow_hash != NULL) {
724  /* clean up flow mutexes */
725  for (uint32_t u = 0; u < flow_config.hash_size; u++) {
726  f = flow_hash[u].head;
727  while (f) {
728  Flow *n = f->next;
729  uint8_t proto_map = FlowGetProtoMapping(f->proto);
730  FlowClearMemory(f, proto_map);
731  FlowFree(f);
732  f = n;
733  }
734  f = flow_hash[u].evicted;
735  while (f) {
736  Flow *n = f->next;
737  uint8_t proto_map = FlowGetProtoMapping(f->proto);
738  FlowClearMemory(f, proto_map);
739  FlowFree(f);
740  f = n;
741  }
742 
744  }
746  flow_hash = NULL;
747  }
748  (void) SC_ATOMIC_SUB(flow_memuse, flow_config.hash_size * sizeof(FlowBucket));
751  DEBUG_VALIDATE_BUG_ON(SC_ATOMIC_GET(flow_memuse) != 0);
752 }
753 
754 /**
755  * \brief Function to set the default timeout, free function and flow state
756  * function for all supported flow_proto.
757  */
758 
760 {
762 
763 #define SET_DEFAULTS(p, n, e, c, b, ne, ee, ce, be) \
764  flow_timeouts_normal[(p)].new_timeout = (n); \
765  flow_timeouts_normal[(p)].est_timeout = (e); \
766  flow_timeouts_normal[(p)].closed_timeout = (c); \
767  flow_timeouts_normal[(p)].bypassed_timeout = (b); \
768  flow_timeouts_emerg[(p)].new_timeout = (ne); \
769  flow_timeouts_emerg[(p)].est_timeout = (ee); \
770  flow_timeouts_emerg[(p)].closed_timeout = (ce); \
771  flow_timeouts_emerg[(p)].bypassed_timeout = (be); \
772 
793 
798 
799  /* Let's see if we have custom timeouts defined from config */
800  const char *new = NULL;
801  const char *established = NULL;
802  const char *closed = NULL;
803  const char *bypassed = NULL;
804  const char *emergency_new = NULL;
805  const char *emergency_established = NULL;
806  const char *emergency_closed = NULL;
807  const char *emergency_bypassed = NULL;
808 
809  SCConfNode *flow_timeouts = SCConfGetNode("flow-timeouts");
810  if (flow_timeouts != NULL) {
811  SCConfNode *proto = NULL;
812  uint32_t configval = 0;
813 
814  /* Defaults. */
815  proto = SCConfNodeLookupChild(flow_timeouts, "default");
816  if (proto != NULL) {
817  new = SCConfNodeLookupChildValue(proto, "new");
818  established = SCConfNodeLookupChildValue(proto, "established");
819  closed = SCConfNodeLookupChildValue(proto, "closed");
820  bypassed = SCConfNodeLookupChildValue(proto, "bypassed");
821  emergency_new = SCConfNodeLookupChildValue(proto, "emergency-new");
822  emergency_established = SCConfNodeLookupChildValue(proto, "emergency-established");
823  emergency_closed = SCConfNodeLookupChildValue(proto, "emergency-closed");
824  emergency_bypassed = SCConfNodeLookupChildValue(proto, "emergency-bypassed");
825 
826  if (new != NULL &&
827  StringParseUint32(&configval, 10, strlen(new), new) > 0) {
828 
830  }
831  if (established != NULL &&
832  StringParseUint32(&configval, 10, strlen(established),
833  established) > 0) {
834 
836  }
837  if (closed != NULL &&
838  StringParseUint32(&configval, 10, strlen(closed),
839  closed) > 0) {
840 
842  }
843  if (bypassed != NULL &&
844  StringParseUint32(&configval, 10,
845  strlen(bypassed),
846  bypassed) > 0) {
847 
849  }
850  if (emergency_new != NULL &&
851  StringParseUint32(&configval, 10, strlen(emergency_new),
852  emergency_new) > 0) {
853 
855  }
856  if (emergency_established != NULL &&
857  StringParseUint32(&configval, 10,
858  strlen(emergency_established),
859  emergency_established) > 0) {
860 
862  }
863  if (emergency_closed != NULL &&
864  StringParseUint32(&configval, 10,
865  strlen(emergency_closed),
866  emergency_closed) > 0) {
867 
869  }
870  if (emergency_bypassed != NULL &&
871  StringParseUint32(&configval, 10,
872  strlen(emergency_bypassed),
873  emergency_bypassed) > 0) {
874 
876  }
877  }
878 
879  /* TCP. */
880  proto = SCConfNodeLookupChild(flow_timeouts, "tcp");
881  if (proto != NULL) {
882  new = SCConfNodeLookupChildValue(proto, "new");
883  established = SCConfNodeLookupChildValue(proto, "established");
884  closed = SCConfNodeLookupChildValue(proto, "closed");
885  bypassed = SCConfNodeLookupChildValue(proto, "bypassed");
886  emergency_new = SCConfNodeLookupChildValue(proto, "emergency-new");
887  emergency_established = SCConfNodeLookupChildValue(proto, "emergency-established");
888  emergency_closed = SCConfNodeLookupChildValue(proto, "emergency-closed");
889  emergency_bypassed = SCConfNodeLookupChildValue(proto, "emergency-bypassed");
890 
891  if (new != NULL &&
892  StringParseUint32(&configval, 10, strlen(new), new) > 0) {
893 
895  }
896  if (established != NULL &&
897  StringParseUint32(&configval, 10, strlen(established),
898  established) > 0) {
899 
901  }
902  if (closed != NULL &&
903  StringParseUint32(&configval, 10, strlen(closed),
904  closed) > 0) {
905 
907  }
908  if (bypassed != NULL &&
909  StringParseUint32(&configval, 10,
910  strlen(bypassed),
911  bypassed) > 0) {
912 
914  }
915  if (emergency_new != NULL &&
916  StringParseUint32(&configval, 10, strlen(emergency_new),
917  emergency_new) > 0) {
918 
920  }
921  if (emergency_established != NULL &&
922  StringParseUint32(&configval, 10,
923  strlen(emergency_established),
924  emergency_established) > 0) {
925 
927  }
928  if (emergency_closed != NULL &&
929  StringParseUint32(&configval, 10,
930  strlen(emergency_closed),
931  emergency_closed) > 0) {
932 
934  }
935  if (emergency_bypassed != NULL &&
936  StringParseUint32(&configval, 10,
937  strlen(emergency_bypassed),
938  emergency_bypassed) > 0) {
939 
941  }
942  }
943 
944  /* UDP. */
945  proto = SCConfNodeLookupChild(flow_timeouts, "udp");
946  if (proto != NULL) {
947  new = SCConfNodeLookupChildValue(proto, "new");
948  established = SCConfNodeLookupChildValue(proto, "established");
949  bypassed = SCConfNodeLookupChildValue(proto, "bypassed");
950  emergency_new = SCConfNodeLookupChildValue(proto, "emergency-new");
951  emergency_established = SCConfNodeLookupChildValue(proto, "emergency-established");
952  emergency_bypassed = SCConfNodeLookupChildValue(proto, "emergency-bypassed");
953 
954  if (new != NULL &&
955  StringParseUint32(&configval, 10, strlen(new), new) > 0) {
956 
958  }
959  if (established != NULL &&
960  StringParseUint32(&configval, 10, strlen(established),
961  established) > 0) {
962 
964  }
965  if (bypassed != NULL &&
966  StringParseUint32(&configval, 10,
967  strlen(bypassed),
968  bypassed) > 0) {
969 
971  }
972  if (emergency_new != NULL &&
973  StringParseUint32(&configval, 10, strlen(emergency_new),
974  emergency_new) > 0) {
975 
977  }
978  if (emergency_established != NULL &&
979  StringParseUint32(&configval, 10,
980  strlen(emergency_established),
981  emergency_established) > 0) {
982 
984  }
985  if (emergency_bypassed != NULL &&
986  StringParseUint32(&configval, 10,
987  strlen(emergency_bypassed),
988  emergency_bypassed) > 0) {
989 
991  }
992  }
993 
994  /* ICMP. */
995  proto = SCConfNodeLookupChild(flow_timeouts, "icmp");
996  if (proto != NULL) {
997  new = SCConfNodeLookupChildValue(proto, "new");
998  established = SCConfNodeLookupChildValue(proto, "established");
999  bypassed = SCConfNodeLookupChildValue(proto, "bypassed");
1000  emergency_new = SCConfNodeLookupChildValue(proto, "emergency-new");
1001  emergency_established = SCConfNodeLookupChildValue(proto, "emergency-established");
1002  emergency_bypassed = SCConfNodeLookupChildValue(proto, "emergency-bypassed");
1003 
1004  if (new != NULL &&
1005  StringParseUint32(&configval, 10, strlen(new), new) > 0) {
1006 
1008  }
1009  if (established != NULL &&
1010  StringParseUint32(&configval, 10, strlen(established),
1011  established) > 0) {
1012 
1014  }
1015  if (bypassed != NULL &&
1016  StringParseUint32(&configval, 10,
1017  strlen(bypassed),
1018  bypassed) > 0) {
1019 
1021  }
1022  if (emergency_new != NULL &&
1023  StringParseUint32(&configval, 10, strlen(emergency_new),
1024  emergency_new) > 0) {
1025 
1027  }
1028  if (emergency_established != NULL &&
1029  StringParseUint32(&configval, 10,
1030  strlen(emergency_established),
1031  emergency_established) > 0) {
1032 
1034  }
1035  if (emergency_bypassed != NULL &&
1036  StringParseUint32(&configval, 10,
1037  strlen(emergency_bypassed),
1038  emergency_bypassed) > 0) {
1039 
1041  }
1042  }
1043  }
1044 
1045  /* validate and if needed update emergency timeout values */
1046  for (uint8_t i = 0; i < FLOW_PROTO_MAX; i++) {
1047  const FlowProtoTimeout *n = &flow_timeouts_normal[i];
1049 
1050  if (e->est_timeout > n->est_timeout) {
1051  SCLogWarning("emergency timeout value %u for \'established\' "
1052  "must be below regular value %u",
1053  e->est_timeout, n->est_timeout);
1054  e->est_timeout = n->est_timeout / 10;
1055  }
1056 
1057  if (e->new_timeout > n->new_timeout) {
1058  SCLogWarning("emergency timeout value %u for \'new\' must be "
1059  "below regular value %u",
1060  e->new_timeout, n->new_timeout);
1061  e->new_timeout = n->new_timeout / 10;
1062  }
1063 
1064  if (e->closed_timeout > n->closed_timeout) {
1065  SCLogWarning("emergency timeout value %u for \'closed\' must "
1066  "be below regular value %u",
1068  e->closed_timeout = n->closed_timeout / 10;
1069  }
1070 
1071  if (e->bypassed_timeout > n->bypassed_timeout) {
1072  SCLogWarning("emergency timeout value %u for \'bypassed\' "
1073  "must be below regular value %u",
1075  e->bypassed_timeout = n->bypassed_timeout / 10;
1076  }
1077  }
1078 
1079  for (uint8_t i = 0; i < FLOW_PROTO_MAX; i++) {
1083 
1084  if (e->est_timeout > n->est_timeout) {
1085  SCLogWarning("emergency timeout value for \'established\' must be below normal value");
1086  e->est_timeout = n->est_timeout / 10;
1087  }
1088  d->est_timeout = n->est_timeout - e->est_timeout;
1089 
1090  if (e->new_timeout > n->new_timeout) {
1091  SCLogWarning("emergency timeout value for \'new\' must be below normal value");
1092  e->new_timeout = n->new_timeout / 10;
1093  }
1094  d->new_timeout = n->new_timeout - e->new_timeout;
1095 
1096  if (e->closed_timeout > n->closed_timeout) {
1097  SCLogWarning("emergency timeout value for \'closed\' must be below normal value");
1098  e->closed_timeout = n->closed_timeout / 10;
1099  }
1101 
1102  if (e->bypassed_timeout > n->bypassed_timeout) {
1103  SCLogWarning("emergency timeout value for \'bypassed\' must be below normal value");
1104  e->bypassed_timeout = n->bypassed_timeout / 10;
1105  }
1107 
1108  SCLogDebug("deltas: new: -%u est: -%u closed: -%u bypassed: -%u",
1110  }
1111 }
1112 
1113 /**
1114  * \brief Function clear the flow memory before queueing it to spare flow
1115  * queue.
1116  *
1117  * \param f pointer to the flow needed to be cleared.
1118  * \param proto_map mapped value of the protocol to FLOW_PROTO's.
1119  */
1120 
1121 int FlowClearMemory(Flow* f, uint8_t proto_map)
1122 {
1123  SCEnter();
1124 
1125  if (unlikely(f->flags & FLOW_HAS_EXPECTATION)) {
1127  }
1128 
1129  /* call the protocol specific free function if we have one */
1130  if (flow_freefuncs[proto_map].Freefunc != NULL) {
1131  flow_freefuncs[proto_map].Freefunc(f->protoctx);
1132  }
1133 
1134  FlowFreeStorage(f);
1135 
1136  FLOW_RECYCLE(f);
1137 
1138  SCReturnInt(1);
1139 }
1140 
1141 /**
1142  * \brief Function to set the function to get protocol specific flow state.
1143  *
1144  * \param proto protocol of which function is needed to be set.
1145  * \param Free Function pointer which will be called to free the protocol
1146  * specific memory.
1147  */
1148 
1149 int FlowSetProtoFreeFunc (uint8_t proto, void (*Free)(void *))
1150 {
1151  uint8_t proto_map;
1152  proto_map = FlowGetProtoMapping(proto);
1153 
1154  flow_freefuncs[proto_map].Freefunc = Free;
1155  return 1;
1156 }
1157 
1158 /**
1159  * \brief get 'disruption' flags: GAP/DEPTH/PASS
1160  * \param f locked flow
1161  * \param flags existing flags to be amended
1162  * \retval flags original flags + disrupt flags (if any)
1163  * \TODO handle UDP
1164  */
1165 uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
1166 {
1167  if (f->proto != IPPROTO_TCP) {
1168  return flags;
1169  }
1170  if (f->protoctx == NULL) {
1171  return flags;
1172  }
1173 
1174  uint8_t newflags = flags;
1175  TcpSession *ssn = f->protoctx;
1176  TcpStream *stream = flags & STREAM_TOSERVER ? &ssn->client : &ssn->server;
1177 
1179  newflags |= STREAM_DEPTH;
1180  }
1181  /* todo: handle pass case (also for UDP!) */
1182 
1183  return newflags;
1184 }
1185 
1186 void FlowUpdateState(Flow *f, const enum FlowState s)
1187 {
1188  if (s != f->flow_state) {
1189  /* set the state */
1190  // Explicit cast from the enum type to the compact version
1191  f->flow_state = (FlowStateType)s;
1192 
1193  /* update timeout policy and value */
1194  const uint32_t timeout_policy = FlowGetTimeoutPolicy(f);
1195  if (timeout_policy != f->timeout_policy) {
1196  f->timeout_policy = timeout_policy;
1197  }
1198  }
1199 #ifdef UNITTESTS
1200  if (f->fb != NULL) {
1201 #endif
1202  /* and reset the flow bucket next_ts value so that the flow manager
1203  * has to revisit this row */
1204  SC_ATOMIC_SET(f->fb->next_ts, 0);
1205 #ifdef UNITTESTS
1206  }
1207 #endif
1208 }
1209 
1210 /**
1211  * \brief Get flow last time as individual values.
1212  *
1213  * Instead of returning a pointer to the timeval copy the timeval
1214  * parts into output pointers to make it simpler to call from Rust
1215  * over FFI using only basic data types.
1216  */
1217 void SCFlowGetLastTimeAsParts(const Flow *flow, uint64_t *secs, uint64_t *usecs)
1218 {
1219  *secs = (uint64_t)SCTIME_SECS(flow->lastts);
1220  *usecs = (uint64_t)SCTIME_USECS(flow->lastts);
1221 }
1222 
1223 /**
1224  * \brief Get flow source port.
1225  *
1226  * A function to get the flow sport useful when the caller only has an
1227  * opaque pointer to the flow structure.
1228  */
1229 uint16_t SCFlowGetSourcePort(const Flow *flow)
1230 {
1231  return flow->sp;
1232 }
1233 
1234 /**
1235  * \brief Get flow destination port.
1236  *
1237  * A function to get the flow dport useful when the caller only has an
1238  * opaque pointer to the flow structure.
1239  */
1240 
1241 uint16_t SCFlowGetDestinationPort(const Flow *flow)
1242 {
1243  return flow->dp;
1244 }
1245 /**
1246  * \brief Get flow flags.
1247  *
1248  * A function to get the flow flags useful when the caller only has an
1249  * opaque pointer to the flow structure.
1250  */
1251 
1252 uint32_t SCFlowGetFlags(const Flow *flow)
1253 {
1254  return flow->flags;
1255 }
1256 /************************************Unittests*******************************/
1257 
1258 #ifdef UNITTESTS
1259 #include "threads.h"
1260 
1261 /**
1262  * \test Test the setting of the per protocol timeouts.
1263  *
1264  * \retval On success it returns 1 and on failure 0.
1265  */
1266 
1267 static int FlowTest01 (void)
1268 {
1269  uint8_t proto_map;
1270 
1272  proto_map = FlowGetProtoMapping(IPPROTO_TCP);
1273  FAIL_IF(flow_timeouts_normal[proto_map].new_timeout != FLOW_IPPROTO_TCP_NEW_TIMEOUT);
1274  FAIL_IF(flow_timeouts_normal[proto_map].est_timeout != FLOW_IPPROTO_TCP_EST_TIMEOUT);
1277 
1278  proto_map = FlowGetProtoMapping(IPPROTO_UDP);
1279  FAIL_IF(flow_timeouts_normal[proto_map].new_timeout != FLOW_IPPROTO_UDP_NEW_TIMEOUT);
1280  FAIL_IF(flow_timeouts_normal[proto_map].est_timeout != FLOW_IPPROTO_UDP_EST_TIMEOUT);
1283 
1284  proto_map = FlowGetProtoMapping(IPPROTO_ICMP);
1285  FAIL_IF(flow_timeouts_normal[proto_map].new_timeout != FLOW_IPPROTO_ICMP_NEW_TIMEOUT);
1286  FAIL_IF(flow_timeouts_normal[proto_map].est_timeout != FLOW_IPPROTO_ICMP_EST_TIMEOUT);
1289 
1290  proto_map = FlowGetProtoMapping(IPPROTO_DCCP);
1291  FAIL_IF(flow_timeouts_normal[proto_map].new_timeout != FLOW_DEFAULT_NEW_TIMEOUT);
1292  FAIL_IF(flow_timeouts_normal[proto_map].est_timeout != FLOW_DEFAULT_EST_TIMEOUT);
1293  FAIL_IF(flow_timeouts_emerg[proto_map].new_timeout != FLOW_DEFAULT_EMERG_NEW_TIMEOUT);
1294  FAIL_IF(flow_timeouts_emerg[proto_map].est_timeout != FLOW_DEFAULT_EMERG_EST_TIMEOUT);
1295 
1296  PASS;
1297 }
1298 
1299 /*Test function for the unit test FlowTest02*/
1300 
1301 static void test(void *f) {}
1302 
1303 /**
1304  * \test Test the setting of the per protocol free function to free the
1305  * protocol specific memory.
1306  *
1307  * \retval On success it returns 1 and on failure 0.
1308  */
1309 
1310 static int FlowTest02 (void)
1311 {
1313  FlowSetProtoFreeFunc(IPPROTO_TCP, test);
1314  FlowSetProtoFreeFunc(IPPROTO_UDP, test);
1315  FlowSetProtoFreeFunc(IPPROTO_ICMP, test);
1316 
1317  FAIL_IF(flow_freefuncs[FLOW_PROTO_DEFAULT].Freefunc != test);
1318  FAIL_IF(flow_freefuncs[FLOW_PROTO_TCP].Freefunc != test);
1319  FAIL_IF(flow_freefuncs[FLOW_PROTO_UDP].Freefunc != test);
1320  FAIL_IF(flow_freefuncs[FLOW_PROTO_ICMP].Freefunc != test);
1321 
1322  PASS;
1323 }
1324 
1325 /**
1326  * \test Test flow allocations when it reach memcap
1327  *
1328  *
1329  * \retval On success it returns 1 and on failure 0.
1330  */
1331 
1332 static int FlowTest07 (void)
1333 {
1334  int result = 0;
1336  FlowConfig backup;
1337  memcpy(&backup, &flow_config, sizeof(FlowConfig));
1338 
1339  uint32_t ini = 0;
1340  uint32_t end = FlowSpareGetPoolSize();
1341  SC_ATOMIC_SET(flow_config.memcap, 10000);
1342  flow_config.prealloc = 100;
1343 
1344  /* Let's get the flow spare pool empty */
1345  UTHBuildPacketOfFlows(ini, end, 0);
1346 
1347  /* And now let's try to reach the memcap val */
1348  while (FLOW_CHECK_MEMCAP(sizeof(Flow))) {
1349  ini = end + 1;
1350  end = end + 2;
1351  UTHBuildPacketOfFlows(ini, end, 0);
1352  }
1353 
1354  /* should time out normal */
1355  TimeSetIncrementTime(2000);
1356  ini = end + 1;
1357  end = end + 2;
1358  UTHBuildPacketOfFlows(ini, end, 0);
1359 
1360  /* This means that the engine entered emerg mode: should happen as easy
1361  * with flow mgr activated */
1362  if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY)
1363  result = 1;
1364 
1365  FlowShutdown();
1366  memcpy(&flow_config, &backup, sizeof(FlowConfig));
1367 
1368  return result;
1369 }
1370 
1371 /**
1372  * \test Test flow allocations when it reach memcap
1373  *
1374  *
1375  * \retval On success it returns 1 and on failure 0.
1376  */
1377 
1378 static int FlowTest08 (void)
1379 {
1380  int result = 0;
1381 
1383  FlowConfig backup;
1384  memcpy(&backup, &flow_config, sizeof(FlowConfig));
1385 
1386  uint32_t ini = 0;
1387  uint32_t end = FlowSpareGetPoolSize();
1388  SC_ATOMIC_SET(flow_config.memcap, 10000);
1389  flow_config.prealloc = 100;
1390 
1391  /* Let's get the flow spare pool empty */
1392  UTHBuildPacketOfFlows(ini, end, 0);
1393 
1394  /* And now let's try to reach the memcap val */
1395  while (FLOW_CHECK_MEMCAP(sizeof(Flow))) {
1396  ini = end + 1;
1397  end = end + 2;
1398  UTHBuildPacketOfFlows(ini, end, 0);
1399  }
1400 
1401  /* By default we use 30 for timing out new flows. This means
1402  * that the Emergency mode should be set */
1404  ini = end + 1;
1405  end = end + 2;
1406  UTHBuildPacketOfFlows(ini, end, 0);
1407 
1408  /* This means that the engine released 5 flows by emergency timeout */
1409  if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY)
1410  result = 1;
1411 
1412  memcpy(&flow_config, &backup, sizeof(FlowConfig));
1413  FlowShutdown();
1414 
1415  return result;
1416 }
1417 
1418 /**
1419  * \test Test flow allocations when it reach memcap
1420  *
1421  *
1422  * \retval On success it returns 1 and on failure 0.
1423  */
1424 
1425 static int FlowTest09 (void)
1426 {
1427  int result = 0;
1428 
1430  FlowConfig backup;
1431  memcpy(&backup, &flow_config, sizeof(FlowConfig));
1432 
1433  uint32_t ini = 0;
1434  uint32_t end = FlowSpareGetPoolSize();
1435  SC_ATOMIC_SET(flow_config.memcap, 10000);
1436  flow_config.prealloc = 100;
1437 
1438  /* Let's get the flow spare pool empty */
1439  UTHBuildPacketOfFlows(ini, end, 0);
1440 
1441  /* And now let's try to reach the memcap val */
1442  while (FLOW_CHECK_MEMCAP(sizeof(Flow))) {
1443  ini = end + 1;
1444  end = end + 2;
1445  UTHBuildPacketOfFlows(ini, end, 0);
1446  }
1447 
1448  /* No timeout will work */
1450  ini = end + 1;
1451  end = end + 2;
1452  UTHBuildPacketOfFlows(ini, end, 0);
1453 
1454  /* engine in emerg mode */
1455  if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY)
1456  result = 1;
1457 
1458  memcpy(&flow_config, &backup, sizeof(FlowConfig));
1459  FlowShutdown();
1460 
1461  return result;
1462 }
1463 
1464 #endif /* UNITTESTS */
1465 
1466 /**
1467  * \brief Function to register the Flow Unitests.
1468  */
1470 {
1471 #ifdef UNITTESTS
1472  UtRegisterTest("FlowTest01 -- Protocol Specific Timeouts", FlowTest01);
1473  UtRegisterTest("FlowTest02 -- Setting Protocol Specific Free Function",
1474  FlowTest02);
1475  UtRegisterTest("FlowTest07 -- Test flow Allocations when it reach memcap",
1476  FlowTest07);
1477  UtRegisterTest("FlowTest08 -- Test flow Allocations when it reach memcap",
1478  FlowTest08);
1479  UtRegisterTest("FlowTest09 -- Test flow Allocations when it reach memcap",
1480  FlowTest09);
1481 
1483 #endif /* UNITTESTS */
1484 }
FLOWFILE_NO_MD5_TS
#define FLOWFILE_NO_MD5_TS
Definition: flow.h:136
util-byte.h
FlowUnsetChangeProtoFlag
void FlowUnsetChangeProtoFlag(Flow *f)
Unset flag to indicate to change proto for the flow.
Definition: flow.c:187
FLOWFILE_NO_MD5_TC
#define FLOWFILE_NO_MD5_TC
Definition: flow.h:137
FBLOCK_DESTROY
#define FBLOCK_DESTROY(fb)
Definition: flow-hash.h:72
FLOW_DEFAULT_NEW_TIMEOUT
#define FLOW_DEFAULT_NEW_TIMEOUT
Definition: flow-private.h:40
MacSetAddWithCtr
void MacSetAddWithCtr(MacSet *ms, const uint8_t *src_addr, const uint8_t *dst_addr, ThreadVars *tv, StatsCounterMaxId ctr_src, StatsCounterMaxId ctr_dst)
Definition: util-macset.c:180
Packet_::proto
uint8_t proto
Definition: decode.h:523
FLOW_DEFAULT_EMERG_BYPASSED_TIMEOUT
#define FLOW_DEFAULT_EMERG_BYPASSED_TIMEOUT
Definition: flow-private.h:56
TcpStream_
Definition: stream-tcp-private.h:106
flow-bypass.h
FLOW_HAS_EXPECTATION
#define FLOW_HAS_EXPECTATION
Definition: flow.h:113
FlowSetHasAlertsFlag
void FlowSetHasAlertsFlag(Flow *f)
Set flag to indicate that flow has alerts.
Definition: flow.c:154
FlowCleanupAppLayer
void FlowCleanupAppLayer(Flow *f)
Definition: flow.c:140
FlowSetChangeProtoFlag
void FlowSetChangeProtoFlag(Flow *f)
Set flag to indicate to change proto for the flow.
Definition: flow.c:178
PKT_HAS_FLOW
#define PKT_HAS_FLOW
Definition: decode.h:1267
IPV6_GET_RAW_HLIM
#define IPV6_GET_RAW_HLIM(ip6h)
Definition: decode-ipv6.h:67
FlowSpareGetPoolSize
uint32_t FlowSpareGetPoolSize(void)
Definition: flow-spare-pool.c:46
FlowGetPacketDirection
int FlowGetPacketDirection(const Flow *f, const Packet *p)
determine the direction of the packet compared to the flow
Definition: flow.c:286
FLOW_STATE_ESTABLISHED
@ FLOW_STATE_ESTABLISHED
Definition: flow.h:496
flow-util.h
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:314
FBLOCK_INIT
#define FBLOCK_INIT(fb)
Definition: flow-hash.h:71
CLS
#define CLS
Definition: suricata-common.h:69
FLOW_DEFAULT_HASHSIZE
#define FLOW_DEFAULT_HASHSIZE
Definition: flow.c:68
SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(FlowProtoTimeoutPtr, flow_timeouts)
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
FlowCnf_::emergency_recovery
uint32_t emergency_recovery
Definition: flow.h:291
FLOW_DEFAULT_PREALLOC
#define FLOW_DEFAULT_PREALLOC
Definition: flow.c:72
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:386
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
FlowCnf_::hash_size
uint32_t hash_size
Definition: flow.h:285
BIT_U16
#define BIT_U16(n)
Definition: suricata-common.h:416
PcapPacketCntGet
uint64_t PcapPacketCntGet(const Packet *p)
Definition: decode.c:1104
FLOW_IS_ELEPHANT_TOCLIENT
#define FLOW_IS_ELEPHANT_TOCLIENT
Definition: flow.h:60
FlowRegisterTests
void FlowRegisterTests(void)
Function to register the Flow Unitests.
Definition: flow.c:1469
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
FLOW_IPPROTO_UDP_EMERG_NEW_TIMEOUT
#define FLOW_IPPROTO_UDP_EMERG_NEW_TIMEOUT
Definition: flow-private.h:60
FLOW_SGH_TOCLIENT
#define FLOW_SGH_TOCLIENT
Definition: flow.h:74
ParseSizeStringU64
int ParseSizeStringU64(const char *size, uint64_t *res)
Definition: util-misc.c:191
Flow_::proto
uint8_t proto
Definition: flow.h:369
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
action-globals.h
FLOWFILE_NO_MAGIC_TS
#define FLOWFILE_NO_MAGIC_TS
Definition: flow.h:129
Packet_::flags
uint32_t flags
Definition: decode.h:544
threads.h
util-macset.h
flow-private.h
Flow_
Flow data structure.
Definition: flow.h:347
Flow_::protomap
uint8_t protomap
Definition: flow.h:436
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:332
FlowProtoTimeout_
Definition: flow.h:509
SCConfGet
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:351
flow-hash.h
FLOW_NOPAYLOAD_INSPECTION
#define FLOW_NOPAYLOAD_INSPECTION
Definition: flow.h:66
FLOW_TS_PM_ALPROTO_DETECT_DONE
#define FLOW_TS_PM_ALPROTO_DETECT_DONE
Definition: flow.h:85
FlowReset
void FlowReset(void)
Definition: flow.c:697
FlowLookupStruct_
Definition: flow.h:533
FlowRateGetStorageID
FlowStorageId FlowRateGetStorageID(void)
Definition: util-flow-rate.c:134
FLOW_DEFAULT_EMERG_NEW_TIMEOUT
#define FLOW_DEFAULT_EMERG_NEW_TIMEOUT
Definition: flow-private.h:54
FLOW_IPPROTO_TCP_EMERG_NEW_TIMEOUT
#define FLOW_IPPROTO_TCP_EMERG_NEW_TIMEOUT
Definition: flow-private.h:57
BypassedFlowUpdate
void BypassedFlowUpdate(Flow *f, Packet *p)
Definition: flow-bypass.c:209
FlowProtoTimeout_::bypassed_timeout
uint32_t bypassed_timeout
Definition: flow.h:513
FLOW_DEFAULT_EST_TIMEOUT
#define FLOW_DEFAULT_EST_TIMEOUT
Definition: flow-private.h:41
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:224
TCP_ESTABLISHED
@ TCP_ESTABLISHED
Definition: stream-tcp-private.h:155
FlowGetMemuse
uint64_t FlowGetMemuse(void)
Definition: flow.c:129
rust.h
MIN
#define MIN(x, y)
Definition: suricata-common.h:408
IPPROTO_DCCP
#define IPPROTO_DCCP
Definition: decode.h:1221
FlowGetMemcap
uint64_t FlowGetMemcap(void)
Return memcap value.
Definition: flow.c:123
FlowQueueDestroy
void FlowQueueDestroy(FlowQueue *q)
Destroy a flow queue.
Definition: flow-queue.c:60
FlowHandlePacket
void FlowHandlePacket(ThreadVars *tv, FlowLookupStruct *fls, Packet *p)
Entry point for packet flow handling.
Definition: flow.c:557
FLOW_ACTION_DROP
#define FLOW_ACTION_DROP
Definition: flow.h:69
TcpStream_::flags
uint16_t flags
Definition: stream-tcp-private.h:107
SCFlowRunUpdateCallbacks
void SCFlowRunUpdateCallbacks(ThreadVars *tv, Flow *f, Packet *p)
Definition: flow-callbacks.c:93
RandomGet
long int RandomGet(void)
Definition: util-random.c:130
FLOW_TOSERVER_DROP_LOGGED
#define FLOW_TOSERVER_DROP_LOGGED
Definition: flow.h:77
Flow_::max_ttl_toserver
uint8_t max_ttl_toserver
Definition: flow.h:459
proto
uint8_t proto
Definition: decode-template.h:0
Flow_::dp
Port dp
Definition: flow.h:363
SCConfNodeLookupChildValue
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:855
FLOW_TC_PE_ALPROTO_DETECT_DONE
#define FLOW_TC_PE_ALPROTO_DETECT_DONE
Definition: flow.h:95
FLOW_DEFAULT_BYPASSED_TIMEOUT
#define FLOW_DEFAULT_BYPASSED_TIMEOUT
Definition: flow-private.h:42
SCFlowGetFlags
uint32_t SCFlowGetFlags(const Flow *flow)
Get flow flags.
Definition: flow.c:1252
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:532
MAX
#define MAX(x, y)
Definition: suricata-common.h:412
Flow_::protoctx
void * protoctx
Definition: flow.h:432
FLOW_PROTO_UDP
@ FLOW_PROTO_UDP
Definition: flow-private.h:67
ExceptionPolicyParse
enum ExceptionPolicy ExceptionPolicyParse(const char *option, bool support_flow)
Definition: util-exception-policy.c:311
FLOW_IPPROTO_UDP_BYPASSED_TIMEOUT
#define FLOW_IPPROTO_UDP_BYPASSED_TIMEOUT
Definition: flow-private.h:49
STREAMTCP_STREAM_FLAG_DEPTH_REACHED
#define STREAMTCP_STREAM_FLAG_DEPTH_REACHED
Definition: stream-tcp-private.h:223
util-unittest.h
util-unittest-helper.h
FLOW_IPPROTO_TCP_EMERG_CLOSED_TIMEOUT
#define FLOW_IPPROTO_TCP_EMERG_CLOSED_TIMEOUT
Definition: flow-private.h:59
FLOW_IPPROTO_ICMP_EST_TIMEOUT
#define FLOW_IPPROTO_ICMP_EST_TIMEOUT
Definition: flow-private.h:51
FlowCnf_::prealloc
uint32_t prealloc
Definition: flow.h:286
UTHBuildPacketOfFlows
uint32_t UTHBuildPacketOfFlows(uint32_t start, uint32_t end, uint8_t dir)
Definition: util-unittest-helper.c:878
AppLayerExpectationClean
void AppLayerExpectationClean(Flow *f)
Definition: app-layer-expectation.c:361
Flow_::flow_state
FlowStateType flow_state
Definition: flow.h:403
PKT_PROTO_DETECT_TS_DONE
#define PKT_PROTO_DETECT_TS_DONE
Definition: decode.h:1300
Packet_::icmp_s
struct Packet_::@32::@39 icmp_s
Flow_::sgh_toserver
const struct SigGroupHead_ * sgh_toserver
Definition: flow.h:477
FLOW_CHECK_MEMCAP
#define FLOW_CHECK_MEMCAP(size)
check if a memory alloc would fit in the memcap
Definition: flow-util.h:134
FLOW_RECYCLE
#define FLOW_RECYCLE(f)
macro to recycle a flow before it goes into the spare queue for reuse.
Definition: flow-util.h:80
Flow_::tosrcbytecnt
uint64_t tosrcbytecnt
Definition: flow.h:489
flow-spare-pool.h
Flow_::alparser
AppLayerParserState * alparser
Definition: flow.h:469
FlowRateStoreUpdate
void FlowRateStoreUpdate(FlowRateStore *frs, SCTime_t p_ts, uint32_t pkt_len, int direction)
Definition: util-flow-rate.c:193
DecodeThreadVars_::counter_flow_elephant
StatsCounterId counter_flow_elephant
Definition: decode.h:1038
FLOWFILE_NO_SHA1_TC
#define FLOWFILE_NO_SHA1_TC
Definition: flow.h:141
FLOW_IPPROTO_ICMP_EMERG_EST_TIMEOUT
#define FLOW_IPPROTO_ICMP_EMERG_EST_TIMEOUT
Definition: flow-private.h:63
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:571
Flow_::fb
struct FlowBucket_ * fb
Definition: flow.h:482
app-layer-expectation.h
FLOW_IPPROTO_UDP_EST_TIMEOUT
#define FLOW_IPPROTO_UDP_EST_TIMEOUT
Definition: flow-private.h:48
util-flow-rate.h
FLOW_STATE_LOCAL_BYPASSED
@ FLOW_STATE_LOCAL_BYPASSED
Definition: flow.h:498
Flow_::min_ttl_toserver
uint8_t min_ttl_toserver
Definition: flow.h:458
decode.h
util-debug.h
TOSERVER
#define TOSERVER
Definition: flow.h:45
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
Packet_::ts
SCTime_t ts
Definition: decode.h:555
Flow_::todstpktcnt
uint32_t todstpktcnt
Definition: flow.h:486
FLOWFILE_NO_STORE_TS
#define FLOWFILE_NO_STORE_TS
Definition: flow.h:133
FLOW_IPPROTO_TCP_CLOSED_TIMEOUT
#define FLOW_IPPROTO_TCP_CLOSED_TIMEOUT
Definition: flow-private.h:45
FlowHandlePacketUpdate
void FlowHandlePacketUpdate(Flow *f, Packet *p, ThreadVars *tv, DecodeThreadVars *dtv)
Update Packet and Flow.
Definition: flow.c:424
Flow_::lastts
SCTime_t lastts
Definition: flow.h:401
SCConfGetInt
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
Definition: conf.c:415
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
FLOW_CHANGE_PROTO
#define FLOW_CHANGE_PROTO
Definition: flow.h:107
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
FlowStorageSize
unsigned int FlowStorageSize(void)
Definition: flow-storage.c:35
Packet_::sp
Port sp
Definition: decode.h:508
FlowCnf_
Definition: flow.h:283
FLOWFILE_NO_SHA256_TS
#define FLOWFILE_NO_SHA256_TS
Definition: flow.h:144
FLOW_PKT_TOCLIENT_FIRST
#define FLOW_PKT_TOCLIENT_FIRST
Definition: flow.h:228
StatsCounterIncr
void StatsCounterIncr(StatsThreadContext *stats, StatsCounterId id)
Increments the local counter.
Definition: counters.c:166
FlowQueueInit
FlowQueue * FlowQueueInit(FlowQueue *q)
Definition: flow-queue.c:46
FlowState
FlowState
Definition: flow.h:494
TcpSession_::state
uint8_t state
Definition: stream-tcp-private.h:285
FlowProtoTimeout_::new_timeout
uint32_t new_timeout
Definition: flow.h:510
StringParseUint32
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:269
FlowProtoTimeout_::closed_timeout
uint32_t closed_timeout
Definition: flow.h:512
util-time.h
FLOW_PROTO_DEFAULT
@ FLOW_PROTO_DEFAULT
Definition: flow-private.h:69
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:262
app-layer-parser.h
AppLayerParserStateCleanup
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
Definition: app-layer-parser.c:1657
FLOW_PROTO_ICMP
@ FLOW_PROTO_ICMP
Definition: flow-private.h:68
FLOW_PROTO_DETECT_TC_DONE
#define FLOW_PROTO_DETECT_TC_DONE
Definition: flow.h:104
Packet_::pkt_hooks
uint16_t pkt_hooks
Definition: decode.h:541
Flow_::todstbytecnt
uint64_t todstbytecnt
Definition: flow.h:488
ThreadVars_::id
int id
Definition: threadvars.h:86
FLOW_TC_PP_ALPROTO_DETECT_DONE
#define FLOW_TC_PP_ALPROTO_DETECT_DONE
Definition: flow.h:93
Flow_::sgh_toclient
const struct SigGroupHead_ * sgh_toclient
Definition: flow.h:474
MacSetFlowStorageEnabled
bool MacSetFlowStorageEnabled(void)
Definition: util-macset.c:85
SC_ATOMIC_SUB
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
Definition: util-atomic.h:341
FlowThreadId
uint16_t FlowThreadId
Definition: flow.h:324
TimeSetIncrementTime
void TimeSetIncrementTime(uint32_t tv_sec)
increment the time in the engine
Definition: util-time.c:180
IPV6Hdr_
Definition: decode-ipv6.h:32
FlowGetProtoMapping
uint8_t FlowGetProtoMapping(uint8_t proto)
Function to map the protocol to the defined FLOW_PROTO_* enumeration.
Definition: flow-util.c:99
Packet_
Definition: decode.h:501
SCFreeAligned
#define SCFreeAligned(p)
Definition: util-mem.h:77
IPV4_GET_RAW_IPTTL
#define IPV4_GET_RAW_IPTTL(ip4h)
Definition: decode-ipv4.h:102
FLOW_DEFAULT_MEMCAP
#define FLOW_DEFAULT_MEMCAP
Definition: flow.c:70
GET_PKT_LEN
#define GET_PKT_LEN(p)
Definition: decode.h:208
stream-tcp-private.h
MacSet_
Definition: util-macset.c:45
conf.h
FLOW_IPPROTO_TCP_NEW_TIMEOUT
#define FLOW_IPPROTO_TCP_NEW_TIMEOUT
Definition: flow-private.h:43
FlowProtoFreeFunc_::Freefunc
void(* Freefunc)(void *)
Definition: flow.h:517
FlowClearMemory
int FlowClearMemory(Flow *f, uint8_t proto_map)
Function clear the flow memory before queueing it to spare flow queue.
Definition: flow.c:1121
flow_timeouts_delta
FlowProtoTimeout flow_timeouts_delta[FLOW_PROTO_MAX]
Definition: flow.c:91
FlowCnf_::hash_rand
uint32_t hash_rand
Definition: flow.h:284
SCFlowGetLastTimeAsParts
void SCFlowGetLastTimeAsParts(const Flow *flow, uint64_t *secs, uint64_t *usecs)
Get flow last time as individual values.
Definition: flow.c:1217
Flow_::min_ttl_toclient
uint8_t min_ttl_toclient
Definition: flow.h:460
MacSetGetFlowStorageID
FlowStorageId MacSetGetFlowStorageID(void)
Definition: util-macset.c:113
flow-queue.h
Flow_::probing_parser_toclient_alproto_masks
uint32_t probing_parser_toclient_alproto_masks
Definition: flow.h:410
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:225
SCFlowGetDestinationPort
uint16_t SCFlowGetDestinationPort(const Flow *flow)
Get flow destination port.
Definition: flow.c:1241
FLOW_TO_DST_SEEN
#define FLOW_TO_DST_SEEN
Definition: flow.h:53
FlowGetStorageById
void * FlowGetStorageById(const Flow *f, FlowStorageId id)
Definition: flow-storage.c:40
FlowUpdateState
void FlowUpdateState(Flow *f, const enum FlowState s)
Definition: flow.c:1186
DecodeThreadVars_::counter_max_mac_addrs_dst
StatsCounterMaxId counter_max_mac_addrs_dst
Definition: decode.h:969
Flow_::src
FlowAddress src
Definition: flow.h:350
Flow_::next
struct Flow_ * next
Definition: flow.h:387
Flow_::probing_parser_toserver_alproto_masks
uint32_t probing_parser_toserver_alproto_masks
Definition: flow.h:409
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:34
FLOWFILE_NO_SHA256_TC
#define FLOWFILE_NO_SHA256_TC
Definition: flow.h:145
DecodeThreadVars_::counter_max_mac_addrs_src
StatsCounterMaxId counter_max_mac_addrs_src
Definition: decode.h:968
IPV4Hdr_
Definition: decode-ipv4.h:72
SCConfNodeLookupChild
SCConfNode * SCConfNodeLookupChild(const SCConfNode *node, const char *name)
Lookup a child configuration node by name.
Definition: conf.c:827
flow_hash
FlowBucket * flow_hash
Definition: flow-hash.c:59
FlowDequeue
Flow * FlowDequeue(FlowQueue *q)
remove a flow from the queue
Definition: flow-queue.c:191
FLOW_TO_SRC_SEEN
#define FLOW_TO_SRC_SEEN
Definition: flow.h:51
flow-storage.h
FLOW_TS_PE_ALPROTO_DETECT_DONE
#define FLOW_TS_PE_ALPROTO_DETECT_DONE
Definition: flow.h:89
Packet_::flow
struct Flow_ * flow
Definition: decode.h:546
FLOW_IPPROTO_UDP_NEW_TIMEOUT
#define FLOW_IPPROTO_UDP_NEW_TIMEOUT
Definition: flow-private.h:47
FlowSetProtoFreeFunc
int FlowSetProtoFreeFunc(uint8_t, void(*Free)(void *))
Function to set the function to get protocol specific flow state.
Definition: flow.c:1149
FLOW_IPPROTO_ICMP_NEW_TIMEOUT
#define FLOW_IPPROTO_ICMP_NEW_TIMEOUT
Definition: flow-private.h:50
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
flow_timeouts_normal
FlowProtoTimeout flow_timeouts_normal[FLOW_PROTO_MAX]
Definition: flow.c:89
CMP_ADDR
#define CMP_ADDR(a1, a2)
Definition: decode.h:222
FlowStateType
unsigned short FlowStateType
Definition: flow.h:321
FLOWFILE_NO_MAGIC_TC
#define FLOWFILE_NO_MAGIC_TC
Definition: flow.h:130
flags
uint8_t flags
Definition: decode-gre.h:0
FlowGetMemcapExceptionPolicy
enum ExceptionPolicy FlowGetMemcapExceptionPolicy(void)
Definition: flow.c:135
flow-manager.h
suricata-common.h
FlowFree
void FlowFree(Flow *f)
cleanup & free the memory of a flow
Definition: flow-util.c:84
flow_config
FlowConfig flow_config
Definition: flow.c:94
FLOW_IPPROTO_TCP_BYPASSED_TIMEOUT
#define FLOW_IPPROTO_TCP_BYPASSED_TIMEOUT
Definition: flow-private.h:46
SCFlowGetSourcePort
uint16_t SCFlowGetSourcePort(const Flow *flow)
Get flow source port.
Definition: flow.c:1229
FLOW_HAS_ALERTS
#define FLOW_HAS_ALERTS
Definition: flow.h:82
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:715
FlowSparePoolDestroy
void FlowSparePoolDestroy(void)
Definition: flow-spare-pool.c:310
packet.h
SCMallocAligned
#define SCMallocAligned(size, align)
Definition: util-mem.h:68
ACTION_DROP
#define ACTION_DROP
Definition: action-globals.h:30
SWAP_VARS
#define SWAP_VARS(type, a, b)
Definition: suricata-common.h:445
FlowTimeoutsInit
void FlowTimeoutsInit(void)
Definition: flow-manager.c:99
SCTIME_SECS
#define SCTIME_SECS(t)
Definition: util-time.h:57
Flow
struct Flow_ Flow
Definition: app-layer-detect-proto.h:29
FLOW_PROTO_DETECT_TS_DONE
#define FLOW_PROTO_DETECT_TS_DONE
Definition: flow.h:103
FlowRateIsExceeding
bool FlowRateIsExceeding(FlowRateStore *frs, int direction)
Definition: util-flow-rate.c:228
FatalError
#define FatalError(...)
Definition: util-debug.h:517
Flow_::max_ttl_toclient
uint8_t max_ttl_toclient
Definition: flow.h:461
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:297
FLOW_TS_PP_ALPROTO_DETECT_DONE
#define FLOW_TS_PP_ALPROTO_DETECT_DONE
Definition: flow.h:87
PKT_PROTO_DETECT_TC_DONE
#define PKT_PROTO_DETECT_TC_DONE
Definition: decode.h:1301
FLOWFILE_NO_STORE_TC
#define FLOWFILE_NO_STORE_TC
Definition: flow.h:134
FlowGetFlowFromHash
Flow * FlowGetFlowFromHash(ThreadVars *tv, FlowLookupStruct *fls, Packet *p, Flow **dest)
Get Flow for packet.
Definition: flow-hash.c:908
Flow_::timeout_policy
uint32_t timeout_policy
Definition: flow.h:396
FLOW_IPPROTO_TCP_EMERG_EST_TIMEOUT
#define FLOW_IPPROTO_TCP_EMERG_EST_TIMEOUT
Definition: flow-private.h:58
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:33
threadvars.h
FlowSwap
void FlowSwap(Flow *f)
swap the flow's direction
Definition: flow.c:246
FlowCnf_::memcap_policy
enum ExceptionPolicy memcap_policy
Definition: flow.h:293
MacSetSwap
void MacSetSwap(MacSet *ms)
Definition: util-macset.c:295
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
FlowInitFlowProto
void FlowInitFlowProto(void)
Function to set the default timeout, free function and flow state function for all supported flow_pro...
Definition: flow.c:759
SCTIME_CMP_GT
#define SCTIME_CMP_GT(a, b)
Definition: util-time.h:104
FLOWFILE_NO_SHA1_TS
#define FLOWFILE_NO_SHA1_TS
Definition: flow.h:140
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:296
SCConfGetNode
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
Definition: conf.c:182
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
flow_recycle_q
FlowQueue flow_recycle_q
Definition: flow-manager.c:66
flow-callbacks.h
SWAP_FLAGS
#define SWAP_FLAGS(flags, a, b)
Definition: suricata-common.h:434
FLOW_SGH_TOSERVER
#define FLOW_SGH_TOSERVER
Definition: flow.h:72
CMP_PORT
#define CMP_PORT(p1, p2)
Definition: decode.h:227
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:959
Flow_::alproto_ts
AppProto alproto_ts
Definition: flow.h:442
Flow_::alstate
void * alstate
Definition: flow.h:470
flow_freefuncs
FlowProtoFreeFunc flow_freefuncs[FLOW_PROTO_MAX]
Definition: flow.c:92
flow_timeouts_emerg
FlowProtoTimeout flow_timeouts_emerg[FLOW_PROTO_MAX]
Definition: flow.c:90
Flow_::flags
uint32_t flags
Definition: flow.h:412
FLOW_IPPROTO_UDP_EMERG_EST_TIMEOUT
#define FLOW_IPPROTO_UDP_EMERG_EST_TIMEOUT
Definition: flow-private.h:61
FlowFreeStorage
void FlowFreeStorage(Flow *f)
Definition: flow-storage.c:60
flow-bindgen.h
FLOW_IPPROTO_ICMP_EMERG_NEW_TIMEOUT
#define FLOW_IPPROTO_ICMP_EMERG_NEW_TIMEOUT
Definition: flow-private.h:62
FLOW_TOCLIENT_DROP_LOGGED
#define FLOW_TOCLIENT_DROP_LOGGED
Definition: flow.h:79
util-random.h
FLOW_PKT_ESTABLISHED
#define FLOW_PKT_ESTABLISHED
Definition: flow.h:226
FlowRateStorageEnabled
bool FlowRateStorageEnabled(void)
Definition: util-flow-rate.c:97
PacketDrop
void PacketDrop(Packet *p, const uint8_t action, enum PacketDropReason r)
issue drop action
Definition: packet.c:34
EngineModeIsIPS
int EngineModeIsIPS(void)
Definition: suricata.c:246
SIGNATURE_HOOK_PKT_FLOW_START
@ SIGNATURE_HOOK_PKT_FLOW_START
Definition: detect.h:540
FLOW_EMERGENCY
#define FLOW_EMERGENCY
Definition: flow-private.h:37
suricata.h
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:43
FLOW_TC_PM_ALPROTO_DETECT_DONE
#define FLOW_TC_PM_ALPROTO_DETECT_DONE
Definition: flow.h:91
FLOW_DEFAULT_EMERGENCY_RECOVERY
#define FLOW_DEFAULT_EMERGENCY_RECOVERY
Definition: flow.c:65
FlowHasAlerts
int FlowHasAlerts(const Flow *f)
Check if flow has alerts.
Definition: flow.c:165
FlowSparePoolInit
void FlowSparePoolInit(void)
Definition: flow-spare-pool.c:291
IPPROTO_SCTP
#define IPPROTO_SCTP
Definition: decode.h:1229
FLOW_DEFAULT_EMERG_EST_TIMEOUT
#define FLOW_DEFAULT_EMERG_EST_TIMEOUT
Definition: flow-private.h:55
FLOW_IPPROTO_ICMP_BYPASSED_TIMEOUT
#define FLOW_IPPROTO_ICMP_BYPASSED_TIMEOUT
Definition: flow-private.h:52
FlowProtoTimeout_::est_timeout
uint32_t est_timeout
Definition: flow.h:511
FlowChangeProto
int FlowChangeProto(Flow *f)
Check if change proto flag is set for flow.
Definition: flow.c:197
Flow_::sp
Port sp
Definition: flow.h:352
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375
DecodeThreadVars_::counter_flow_elephant_toclient
StatsCounterId counter_flow_elephant_toclient
Definition: decode.h:1040
DecodeThreadVars_::counter_flow_elephant_toserver
StatsCounterId counter_flow_elephant_toserver
Definition: decode.h:1039
FlowGetDisruptionFlags
uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
get 'disruption' flags: GAP/DEPTH/PASS
Definition: flow.c:1165
TcpSession_
Definition: stream-tcp-private.h:283
util-misc.h
TcpSession_::data_first_seen_dir
int8_t data_first_seen_dir
Definition: stream-tcp-private.h:288
flow.h
Flow_::alproto_tc
AppProto alproto_tc
Definition: flow.h:443
Flow_::file_flags
uint16_t file_flags
Definition: flow.h:414
Packet_::dp
Port dp
Definition: decode.h:516
ExceptionPolicy
ExceptionPolicy
Definition: util-exception-policy-types.h:26
FLOW_DIR_REVERSED
#define FLOW_DIR_REVERSED
Definition: flow.h:111
FLOW_PROTO_TCP
@ FLOW_PROTO_TCP
Definition: flow-private.h:66
ICMPV4_IS_ERROR_MSG
#define ICMPV4_IS_ERROR_MSG(type)
Definition: decode-icmpv4.h:267
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:121
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:288
SCConfNode_
Definition: conf.h:37
FLOW_IPPROTO_TCP_EST_TIMEOUT
#define FLOW_IPPROTO_TCP_EST_TIMEOUT
Definition: flow-private.h:44
RegisterFlowStorageTests
void RegisterFlowStorageTests(void)
Definition: flow-storage.c:298
SET_DEFAULTS
#define SET_DEFAULTS(p, n, e, c, b, ne, ee, ce, be)
TOCLIENT
#define TOCLIENT
Definition: flow.h:46
FLOW_PKT_TOSERVER_FIRST
#define FLOW_PKT_TOSERVER_FIRST
Definition: flow.h:227
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
PKT_DROP_REASON_FLOW_DROP
@ PKT_DROP_REASON_FLOW_DROP
Definition: decode.h:386
Packet_::src
Address src
Definition: decode.h:505
Flow_::tosrcpktcnt
uint32_t tosrcpktcnt
Definition: flow.h:487
FLOW_IS_ELEPHANT_TOSERVER
#define FLOW_IS_ELEPHANT_TOSERVER
Definition: flow.h:59
FLOW_PROTO_MAX
@ FLOW_PROTO_MAX
Definition: flow-private.h:72
FlowRateStore_
Definition: util-flow-rate.h:47
Flow_::thread_id
FlowThreadId thread_id[2]
Definition: flow.h:385
SCTIME_USECS
#define SCTIME_USECS(t)
Definition: util-time.h:56
FlowSetMemcap
int FlowSetMemcap(uint64_t size)
Update memcap value.
Definition: flow.c:108
FlowProtoFreeFunc_
Definition: flow.h:516