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 
274 /**
275  * \brief determine the direction of the packet compared to the flow
276  * \retval 0 to_server
277  * \retval 1 to_client
278  */
279 int FlowGetPacketDirection(const Flow *f, const Packet *p)
280 {
281  const int reverse = (f->flags & FLOW_DIR_REVERSED) != 0;
282 
283  if (p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP || p->proto == IPPROTO_SCTP) {
284  if (!(CMP_PORT(p->sp,p->dp))) {
285  /* update flags and counters */
286  if (CMP_PORT(f->sp,p->sp)) {
287  return TOSERVER ^ reverse;
288  } else {
289  return TOCLIENT ^ reverse;
290  }
291  } else {
292  if (CMP_ADDR(&f->src,&p->src)) {
293  return TOSERVER ^ reverse;
294  } else {
295  return TOCLIENT ^ reverse;
296  }
297  }
298  } else if (p->proto == IPPROTO_ICMP || p->proto == IPPROTO_ICMPV6) {
299  if (CMP_ADDR(&f->src,&p->src)) {
300  return TOSERVER ^ reverse;
301  } else {
302  return TOCLIENT ^ reverse;
303  }
304  }
305 
306  /* default to toserver */
307  return TOSERVER;
308 }
309 
310 /**
311  * \brief Check to update "seen" flags
312  *
313  * \param p packet
314  *
315  * \retval 1 true
316  * \retval 0 false
317  */
318 static inline int FlowUpdateSeenFlag(const Packet *p)
319 {
320  if (PacketIsICMPv4(p)) {
321  if (ICMPV4_IS_ERROR_MSG(p->icmp_s.type)) {
322  return 0;
323  }
324  }
325 
326  return 1;
327 }
328 
329 static inline void FlowUpdateTtlTS(Flow *f, uint8_t ttl)
330 {
331  if (f->min_ttl_toserver == 0) {
332  f->min_ttl_toserver = ttl;
333  } else {
334  f->min_ttl_toserver = MIN(f->min_ttl_toserver, ttl);
335  }
336  f->max_ttl_toserver = MAX(f->max_ttl_toserver, ttl);
337 }
338 
339 static inline void FlowUpdateTtlTC(Flow *f, uint8_t ttl)
340 {
341  if (f->min_ttl_toclient == 0) {
342  f->min_ttl_toclient = ttl;
343  } else {
344  f->min_ttl_toclient = MIN(f->min_ttl_toclient, ttl);
345  }
346  f->max_ttl_toclient = MAX(f->max_ttl_toclient, ttl);
347 }
348 
349 static inline void FlowUpdateFlowRate(
350  ThreadVars *tv, DecodeThreadVars *dtv, Flow *f, const Packet *p, int dir)
351 {
352  if (FlowRateStorageEnabled()) {
353  /* No need to update the struct if flow is already marked as elephant flow */
354  if (f->flags & FLOW_IS_ELEPHANT)
355  return;
357  if (frs != NULL) {
358  FlowRateStoreUpdate(frs, p->ts, GET_PKT_LEN(p), dir);
359  bool fr_exceeds = FlowRateIsExceeding(frs, dir);
360  if (fr_exceeds) {
361  SCLogDebug("Flow rate for flow %p exceeds the configured values, marking it as an "
362  "elephant flow",
363  f);
364  f->flags |= FLOW_IS_ELEPHANT;
365  if (tv != NULL) {
367  }
368  }
369  }
370  }
371 }
372 
373 static inline void FlowUpdateEthernet(
374  ThreadVars *tv, DecodeThreadVars *dtv, Flow *f, const Packet *p, bool toserver)
375 {
376  if (PacketIsEthernet(p) && MacSetFlowStorageEnabled()) {
377  const EthernetHdr *ethh = PacketGetEthernet(p);
379  if (ms != NULL) {
380  if (toserver) {
381  MacSetAddWithCtr(ms, ethh->eth_src, ethh->eth_dst, tv,
384  } else {
385  MacSetAddWithCtr(ms, ethh->eth_dst, ethh->eth_src, tv,
388  }
389  }
390  }
391 }
392 
393 /** \brief Update Packet and Flow
394  *
395  * Updates packet and flow based on the new packet.
396  *
397  * \param f locked flow
398  * \param p packet
399  *
400  * \note overwrites p::flowflags
401  */
403 {
404  SCLogDebug("packet %"PRIu64" -- flow %p", p->pcap_cnt, f);
405 
406  const int pkt_dir = FlowGetPacketDirection(f, p);
407 #ifdef CAPTURE_OFFLOAD
408  int state = f->flow_state;
409 
410  if (state != FLOW_STATE_CAPTURE_BYPASSED) {
411 #endif
412  /* update the last seen timestamp of this flow */
413  if (SCTIME_CMP_GT(p->ts, f->lastts)) {
414  f->lastts = p->ts;
415  }
416 #ifdef CAPTURE_OFFLOAD
417  } else {
418  FlowProtoTimeoutPtr flow_timeouts = SC_ATOMIC_GET(flow_timeouts);
419  /* still seeing packet, we downgrade to local bypass */
420  if (SCTIME_SECS(p->ts) - SCTIME_SECS(f->lastts) >
421  flow_timeouts[f->protomap].bypassed_timeout / 2) {
422  SCLogDebug("Downgrading flow to local bypass");
423  f->lastts = p->ts;
425  } else {
426  /* In IPS mode the packet could come from the other interface so it would
427  * need to be bypassed */
428  if (EngineModeIsIPS()) {
429  BypassedFlowUpdate(f, p);
430  }
431  }
432  }
433 #endif
434  /* update flags and counters */
435  if (pkt_dir == TOSERVER) {
436  f->todstpktcnt++;
437  f->todstbytecnt += GET_PKT_LEN(p);
438  FlowUpdateFlowRate(tv, dtv, f, p, TOSERVER);
440  if (!(f->flags & FLOW_TO_DST_SEEN)) {
441  if (FlowUpdateSeenFlag(p)) {
442  f->flags |= FLOW_TO_DST_SEEN;
445  }
446  }
447  /* xfer proto detect ts flag to first packet in ts dir */
448  if (f->flags & FLOW_PROTO_DETECT_TS_DONE) {
451  }
452  FlowUpdateEthernet(tv, dtv, f, p, true);
453  /* update flow's ttl fields if needed */
454  if (PacketIsIPv4(p)) {
455  const IPV4Hdr *ip4h = PacketGetIPv4(p);
456  FlowUpdateTtlTS(f, IPV4_GET_RAW_IPTTL(ip4h));
457  } else if (PacketIsIPv6(p)) {
458  const IPV6Hdr *ip6h = PacketGetIPv6(p);
459  FlowUpdateTtlTS(f, IPV6_GET_RAW_HLIM(ip6h));
460  }
461  } else {
462  f->tosrcpktcnt++;
463  f->tosrcbytecnt += GET_PKT_LEN(p);
464  FlowUpdateFlowRate(tv, dtv, f, p, TOCLIENT);
466  if (!(f->flags & FLOW_TO_SRC_SEEN)) {
467  if (FlowUpdateSeenFlag(p)) {
468  f->flags |= FLOW_TO_SRC_SEEN;
471  }
472  }
473  /* xfer proto detect tc flag to first packet in tc dir */
474  if (f->flags & FLOW_PROTO_DETECT_TC_DONE) {
477  }
478  FlowUpdateEthernet(tv, dtv, f, p, false);
479  /* update flow's ttl fields if needed */
480  if (PacketIsIPv4(p)) {
481  const IPV4Hdr *ip4h = PacketGetIPv4(p);
482  FlowUpdateTtlTC(f, IPV4_GET_RAW_IPTTL(ip4h));
483  } else if (PacketIsIPv6(p)) {
484  const IPV6Hdr *ip6h = PacketGetIPv6(p);
485  FlowUpdateTtlTC(f, IPV6_GET_RAW_HLIM(ip6h));
486  }
487  }
488  if (f->thread_id[pkt_dir] == 0) {
489  f->thread_id[pkt_dir] = (FlowThreadId)tv->id;
490  }
491 
493  SCLogDebug("pkt %p FLOW_PKT_ESTABLISHED", p);
495 
496  } else if (f->proto == IPPROTO_TCP) {
497  TcpSession *ssn = (TcpSession *)f->protoctx;
498  if (ssn != NULL && ssn->state >= TCP_ESTABLISHED) {
500  }
501  } else if ((f->flags & (FLOW_TO_DST_SEEN|FLOW_TO_SRC_SEEN)) ==
503  SCLogDebug("pkt %p FLOW_PKT_ESTABLISHED", p);
505 
506  if (
507 #ifdef CAPTURE_OFFLOAD
508  (f->flow_state != FLOW_STATE_CAPTURE_BYPASSED) &&
509 #endif
512  }
513  }
514 
515  if (f->flags & FLOW_ACTION_DROP) {
517  }
518 
519  if (f->flags & FLOW_NOPAYLOAD_INSPECTION) {
520  SCLogDebug("setting FLOW_NOPAYLOAD_INSPECTION flag on flow %p", f);
521  DecodeSetNoPayloadInspectionFlag(p);
522  }
523 
525 }
526 
527 /** \brief Entry point for packet flow handling
528  *
529  * This is called for every packet.
530  *
531  * \param tv threadvars
532  * \param dtv decode thread vars (for flow output api thread data)
533  * \param p packet to handle flow for
534  */
536 {
537  /* Get this packet's flow from the hash. FlowHandlePacket() will setup
538  * a new flow if necessary. If we get NULL, we're out of flow memory.
539  * The returned flow is locked. */
540  Flow *f = FlowGetFlowFromHash(tv, fls, p, &p->flow);
541  if (f != NULL) {
542  /* set the flow in the packet */
543  p->flags |= PKT_HAS_FLOW;
544  }
545 }
546 
547 /** \brief initialize the configuration
548  * \warning Not thread safe */
549 void FlowInitConfig(bool quiet)
550 {
551  SCLogDebug("initializing flow engine...");
552 
553  memset(&flow_config, 0, sizeof(flow_config));
554  SC_ATOMIC_INIT(flow_flags);
555  SC_ATOMIC_INIT(flow_memuse);
556  SC_ATOMIC_INIT(flow_prune_idx);
557  SC_ATOMIC_INIT(flow_config.memcap);
559 
560  /* set defaults */
561  flow_config.hash_rand = (uint32_t)RandomGet();
565 
566  /* If we have specific config, overwrite the defaults with them,
567  * otherwise, leave the default values */
568  intmax_t val = 0;
569  if (SCConfGetInt("flow.emergency-recovery", &val) == 1) {
570  if (val <= 100 && val >= 1) {
571  flow_config.emergency_recovery = (uint8_t)val;
572  } else {
573  SCLogError("flow.emergency-recovery must be in the range of "
574  "1 and 100 (as percentage)");
576  }
577  } else {
578  SCLogDebug("flow.emergency-recovery, using default value");
580  }
581 
582  /* Check if we have memcap and hash_size defined at config */
583  const char *conf_val;
584  uint32_t configval = 0;
585 
586  /** set config values for memcap, prealloc and hash_size */
587  uint64_t flow_memcap_copy = 0;
588  if ((SCConfGet("flow.memcap", &conf_val)) == 1) {
589  if (conf_val == NULL) {
590  FatalError("Invalid value for flow.memcap: NULL");
591  }
592 
593  if (ParseSizeStringU64(conf_val, &flow_memcap_copy) < 0) {
594  SCLogError("Error parsing flow.memcap "
595  "from conf file - %s. Killing engine",
596  conf_val);
597  exit(EXIT_FAILURE);
598  } else {
599  SC_ATOMIC_SET(flow_config.memcap, flow_memcap_copy);
600  }
601  }
602  if ((SCConfGet("flow.hash-size", &conf_val)) == 1) {
603  if (conf_val == NULL) {
604  FatalError("Invalid value for flow.hash-size: NULL");
605  }
606 
607  if (StringParseUint32(&configval, 10, strlen(conf_val), conf_val) && configval != 0) {
608  flow_config.hash_size = configval;
609  } else {
610  FatalError("Invalid value for flow.hash-size. Must be a numeric value in the range "
611  "1-4294967295");
612  }
613  }
614  if ((SCConfGet("flow.prealloc", &conf_val)) == 1) {
615  if (conf_val == NULL) {
616  FatalError("Invalid value for flow.prealloc: NULL");
617  }
618 
619  if (StringParseUint32(&configval, 10, strlen(conf_val),
620  conf_val) > 0) {
621  flow_config.prealloc = configval;
622  }
623  }
624 
625  flow_config.memcap_policy = ExceptionPolicyParse("flow.memcap-policy", false);
626 
627  SCLogDebug("Flow config from suricata.yaml: memcap: %"PRIu64", hash-size: "
628  "%"PRIu32", prealloc: %"PRIu32, SC_ATOMIC_GET(flow_config.memcap),
630 
631  /* alloc hash memory */
632  uint64_t hash_size = flow_config.hash_size * sizeof(FlowBucket);
633  if (!(FLOW_CHECK_MEMCAP(hash_size))) {
634  SCLogError("allocating flow hash failed: "
635  "max flow memcap is smaller than projected hash size. "
636  "Memcap: %" PRIu64 ", Hash table size %" PRIu64 ". Calculate "
637  "total hash size by multiplying \"flow.hash-size\" with %" PRIuMAX ", "
638  "which is the hash bucket size.",
639  SC_ATOMIC_GET(flow_config.memcap), hash_size, (uintmax_t)sizeof(FlowBucket));
640  exit(EXIT_FAILURE);
641  }
642  flow_hash = SCMallocAligned(flow_config.hash_size * sizeof(FlowBucket), CLS);
643  if (unlikely(flow_hash == NULL)) {
644  FatalError("Fatal error encountered in FlowInitConfig. Exiting...");
645  }
646  memset(flow_hash, 0, flow_config.hash_size * sizeof(FlowBucket));
647 
648  uint32_t i = 0;
649  for (i = 0; i < flow_config.hash_size; i++) {
650  FBLOCK_INIT(&flow_hash[i]);
651  SC_ATOMIC_INIT(flow_hash[i].next_ts);
652  }
653  (void) SC_ATOMIC_ADD(flow_memuse, (flow_config.hash_size * sizeof(FlowBucket)));
654 
655  if (!quiet) {
656  SCLogConfig("allocated %"PRIu64" bytes of memory for the flow hash... "
657  "%" PRIu32 " buckets of size %" PRIuMAX "",
658  SC_ATOMIC_GET(flow_memuse), flow_config.hash_size,
659  (uintmax_t)sizeof(FlowBucket));
660  }
662  if (!quiet) {
663  SCLogConfig("flow memory usage: %"PRIu64" bytes, maximum: %"PRIu64,
664  SC_ATOMIC_GET(flow_memuse), SC_ATOMIC_GET(flow_config.memcap));
665  }
666 
668 
669  uint32_t sz = sizeof(Flow) + FlowStorageSize();
670  SCLogConfig("flow size %u, memcap allows for %" PRIu64 " flows. Per hash row in perfect "
671  "conditions %" PRIu64,
672  sz, flow_memcap_copy / sz, (flow_memcap_copy / sz) / flow_config.hash_size);
673 }
674 
675 void FlowReset(void)
676 {
677  // resets the flows (for reuse by fuzzing)
678  for (uint32_t u = 0; u < flow_config.hash_size; u++) {
679  Flow *f = flow_hash[u].head;
680  while (f) {
681  Flow *n = f->next;
682  uint8_t proto_map = FlowGetProtoMapping(f->proto);
683  FlowClearMemory(f, proto_map);
684  FlowFree(f);
685  f = n;
686  }
687  flow_hash[u].head = NULL;
688  }
689 }
690 
691 /** \brief shutdown the flow engine
692  * \warning Not thread safe */
693 void FlowShutdown(void)
694 {
695  Flow *f;
696  while ((f = FlowDequeue(&flow_recycle_q))) {
697  FlowFree(f);
698  }
699 
700  /* clear and free the hash */
701  if (flow_hash != NULL) {
702  /* clean up flow mutexes */
703  for (uint32_t u = 0; u < flow_config.hash_size; u++) {
704  f = flow_hash[u].head;
705  while (f) {
706  Flow *n = f->next;
707  uint8_t proto_map = FlowGetProtoMapping(f->proto);
708  FlowClearMemory(f, proto_map);
709  FlowFree(f);
710  f = n;
711  }
712  f = flow_hash[u].evicted;
713  while (f) {
714  Flow *n = f->next;
715  uint8_t proto_map = FlowGetProtoMapping(f->proto);
716  FlowClearMemory(f, proto_map);
717  FlowFree(f);
718  f = n;
719  }
720 
722  }
724  flow_hash = NULL;
725  }
726  (void) SC_ATOMIC_SUB(flow_memuse, flow_config.hash_size * sizeof(FlowBucket));
729  DEBUG_VALIDATE_BUG_ON(SC_ATOMIC_GET(flow_memuse) != 0);
730 }
731 
732 /**
733  * \brief Function to set the default timeout, free function and flow state
734  * function for all supported flow_proto.
735  */
736 
738 {
740 
741 #define SET_DEFAULTS(p, n, e, c, b, ne, ee, ce, be) \
742  flow_timeouts_normal[(p)].new_timeout = (n); \
743  flow_timeouts_normal[(p)].est_timeout = (e); \
744  flow_timeouts_normal[(p)].closed_timeout = (c); \
745  flow_timeouts_normal[(p)].bypassed_timeout = (b); \
746  flow_timeouts_emerg[(p)].new_timeout = (ne); \
747  flow_timeouts_emerg[(p)].est_timeout = (ee); \
748  flow_timeouts_emerg[(p)].closed_timeout = (ce); \
749  flow_timeouts_emerg[(p)].bypassed_timeout = (be); \
750 
771 
776 
777  /* Let's see if we have custom timeouts defined from config */
778  const char *new = NULL;
779  const char *established = NULL;
780  const char *closed = NULL;
781  const char *bypassed = NULL;
782  const char *emergency_new = NULL;
783  const char *emergency_established = NULL;
784  const char *emergency_closed = NULL;
785  const char *emergency_bypassed = NULL;
786 
787  SCConfNode *flow_timeouts = SCConfGetNode("flow-timeouts");
788  if (flow_timeouts != NULL) {
789  SCConfNode *proto = NULL;
790  uint32_t configval = 0;
791 
792  /* Defaults. */
793  proto = SCConfNodeLookupChild(flow_timeouts, "default");
794  if (proto != NULL) {
795  new = SCConfNodeLookupChildValue(proto, "new");
796  established = SCConfNodeLookupChildValue(proto, "established");
797  closed = SCConfNodeLookupChildValue(proto, "closed");
798  bypassed = SCConfNodeLookupChildValue(proto, "bypassed");
799  emergency_new = SCConfNodeLookupChildValue(proto, "emergency-new");
800  emergency_established = SCConfNodeLookupChildValue(proto, "emergency-established");
801  emergency_closed = SCConfNodeLookupChildValue(proto, "emergency-closed");
802  emergency_bypassed = SCConfNodeLookupChildValue(proto, "emergency-bypassed");
803 
804  if (new != NULL &&
805  StringParseUint32(&configval, 10, strlen(new), new) > 0) {
806 
808  }
809  if (established != NULL &&
810  StringParseUint32(&configval, 10, strlen(established),
811  established) > 0) {
812 
814  }
815  if (closed != NULL &&
816  StringParseUint32(&configval, 10, strlen(closed),
817  closed) > 0) {
818 
820  }
821  if (bypassed != NULL &&
822  StringParseUint32(&configval, 10,
823  strlen(bypassed),
824  bypassed) > 0) {
825 
827  }
828  if (emergency_new != NULL &&
829  StringParseUint32(&configval, 10, strlen(emergency_new),
830  emergency_new) > 0) {
831 
833  }
834  if (emergency_established != NULL &&
835  StringParseUint32(&configval, 10,
836  strlen(emergency_established),
837  emergency_established) > 0) {
838 
840  }
841  if (emergency_closed != NULL &&
842  StringParseUint32(&configval, 10,
843  strlen(emergency_closed),
844  emergency_closed) > 0) {
845 
847  }
848  if (emergency_bypassed != NULL &&
849  StringParseUint32(&configval, 10,
850  strlen(emergency_bypassed),
851  emergency_bypassed) > 0) {
852 
854  }
855  }
856 
857  /* TCP. */
858  proto = SCConfNodeLookupChild(flow_timeouts, "tcp");
859  if (proto != NULL) {
860  new = SCConfNodeLookupChildValue(proto, "new");
861  established = SCConfNodeLookupChildValue(proto, "established");
862  closed = SCConfNodeLookupChildValue(proto, "closed");
863  bypassed = SCConfNodeLookupChildValue(proto, "bypassed");
864  emergency_new = SCConfNodeLookupChildValue(proto, "emergency-new");
865  emergency_established = SCConfNodeLookupChildValue(proto, "emergency-established");
866  emergency_closed = SCConfNodeLookupChildValue(proto, "emergency-closed");
867  emergency_bypassed = SCConfNodeLookupChildValue(proto, "emergency-bypassed");
868 
869  if (new != NULL &&
870  StringParseUint32(&configval, 10, strlen(new), new) > 0) {
871 
873  }
874  if (established != NULL &&
875  StringParseUint32(&configval, 10, strlen(established),
876  established) > 0) {
877 
879  }
880  if (closed != NULL &&
881  StringParseUint32(&configval, 10, strlen(closed),
882  closed) > 0) {
883 
885  }
886  if (bypassed != NULL &&
887  StringParseUint32(&configval, 10,
888  strlen(bypassed),
889  bypassed) > 0) {
890 
892  }
893  if (emergency_new != NULL &&
894  StringParseUint32(&configval, 10, strlen(emergency_new),
895  emergency_new) > 0) {
896 
898  }
899  if (emergency_established != NULL &&
900  StringParseUint32(&configval, 10,
901  strlen(emergency_established),
902  emergency_established) > 0) {
903 
905  }
906  if (emergency_closed != NULL &&
907  StringParseUint32(&configval, 10,
908  strlen(emergency_closed),
909  emergency_closed) > 0) {
910 
912  }
913  if (emergency_bypassed != NULL &&
914  StringParseUint32(&configval, 10,
915  strlen(emergency_bypassed),
916  emergency_bypassed) > 0) {
917 
919  }
920  }
921 
922  /* UDP. */
923  proto = SCConfNodeLookupChild(flow_timeouts, "udp");
924  if (proto != NULL) {
925  new = SCConfNodeLookupChildValue(proto, "new");
926  established = SCConfNodeLookupChildValue(proto, "established");
927  bypassed = SCConfNodeLookupChildValue(proto, "bypassed");
928  emergency_new = SCConfNodeLookupChildValue(proto, "emergency-new");
929  emergency_established = SCConfNodeLookupChildValue(proto, "emergency-established");
930  emergency_bypassed = SCConfNodeLookupChildValue(proto, "emergency-bypassed");
931 
932  if (new != NULL &&
933  StringParseUint32(&configval, 10, strlen(new), new) > 0) {
934 
936  }
937  if (established != NULL &&
938  StringParseUint32(&configval, 10, strlen(established),
939  established) > 0) {
940 
942  }
943  if (bypassed != NULL &&
944  StringParseUint32(&configval, 10,
945  strlen(bypassed),
946  bypassed) > 0) {
947 
949  }
950  if (emergency_new != NULL &&
951  StringParseUint32(&configval, 10, strlen(emergency_new),
952  emergency_new) > 0) {
953 
955  }
956  if (emergency_established != NULL &&
957  StringParseUint32(&configval, 10,
958  strlen(emergency_established),
959  emergency_established) > 0) {
960 
962  }
963  if (emergency_bypassed != NULL &&
964  StringParseUint32(&configval, 10,
965  strlen(emergency_bypassed),
966  emergency_bypassed) > 0) {
967 
969  }
970  }
971 
972  /* ICMP. */
973  proto = SCConfNodeLookupChild(flow_timeouts, "icmp");
974  if (proto != NULL) {
975  new = SCConfNodeLookupChildValue(proto, "new");
976  established = SCConfNodeLookupChildValue(proto, "established");
977  bypassed = SCConfNodeLookupChildValue(proto, "bypassed");
978  emergency_new = SCConfNodeLookupChildValue(proto, "emergency-new");
979  emergency_established = SCConfNodeLookupChildValue(proto, "emergency-established");
980  emergency_bypassed = SCConfNodeLookupChildValue(proto, "emergency-bypassed");
981 
982  if (new != NULL &&
983  StringParseUint32(&configval, 10, strlen(new), new) > 0) {
984 
986  }
987  if (established != NULL &&
988  StringParseUint32(&configval, 10, strlen(established),
989  established) > 0) {
990 
992  }
993  if (bypassed != NULL &&
994  StringParseUint32(&configval, 10,
995  strlen(bypassed),
996  bypassed) > 0) {
997 
999  }
1000  if (emergency_new != NULL &&
1001  StringParseUint32(&configval, 10, strlen(emergency_new),
1002  emergency_new) > 0) {
1003 
1005  }
1006  if (emergency_established != NULL &&
1007  StringParseUint32(&configval, 10,
1008  strlen(emergency_established),
1009  emergency_established) > 0) {
1010 
1012  }
1013  if (emergency_bypassed != NULL &&
1014  StringParseUint32(&configval, 10,
1015  strlen(emergency_bypassed),
1016  emergency_bypassed) > 0) {
1017 
1019  }
1020  }
1021  }
1022 
1023  /* validate and if needed update emergency timeout values */
1024  for (uint8_t i = 0; i < FLOW_PROTO_MAX; i++) {
1025  const FlowProtoTimeout *n = &flow_timeouts_normal[i];
1027 
1028  if (e->est_timeout > n->est_timeout) {
1029  SCLogWarning("emergency timeout value %u for \'established\' "
1030  "must be below regular value %u",
1031  e->est_timeout, n->est_timeout);
1032  e->est_timeout = n->est_timeout / 10;
1033  }
1034 
1035  if (e->new_timeout > n->new_timeout) {
1036  SCLogWarning("emergency timeout value %u for \'new\' must be "
1037  "below regular value %u",
1038  e->new_timeout, n->new_timeout);
1039  e->new_timeout = n->new_timeout / 10;
1040  }
1041 
1042  if (e->closed_timeout > n->closed_timeout) {
1043  SCLogWarning("emergency timeout value %u for \'closed\' must "
1044  "be below regular value %u",
1046  e->closed_timeout = n->closed_timeout / 10;
1047  }
1048 
1049  if (e->bypassed_timeout > n->bypassed_timeout) {
1050  SCLogWarning("emergency timeout value %u for \'bypassed\' "
1051  "must be below regular value %u",
1053  e->bypassed_timeout = n->bypassed_timeout / 10;
1054  }
1055  }
1056 
1057  for (uint8_t i = 0; i < FLOW_PROTO_MAX; i++) {
1061 
1062  if (e->est_timeout > n->est_timeout) {
1063  SCLogWarning("emergency timeout value for \'established\' must be below normal value");
1064  e->est_timeout = n->est_timeout / 10;
1065  }
1066  d->est_timeout = n->est_timeout - e->est_timeout;
1067 
1068  if (e->new_timeout > n->new_timeout) {
1069  SCLogWarning("emergency timeout value for \'new\' must be below normal value");
1070  e->new_timeout = n->new_timeout / 10;
1071  }
1072  d->new_timeout = n->new_timeout - e->new_timeout;
1073 
1074  if (e->closed_timeout > n->closed_timeout) {
1075  SCLogWarning("emergency timeout value for \'closed\' must be below normal value");
1076  e->closed_timeout = n->closed_timeout / 10;
1077  }
1079 
1080  if (e->bypassed_timeout > n->bypassed_timeout) {
1081  SCLogWarning("emergency timeout value for \'bypassed\' must be below normal value");
1082  e->bypassed_timeout = n->bypassed_timeout / 10;
1083  }
1085 
1086  SCLogDebug("deltas: new: -%u est: -%u closed: -%u bypassed: -%u",
1088  }
1089 }
1090 
1091 /**
1092  * \brief Function clear the flow memory before queueing it to spare flow
1093  * queue.
1094  *
1095  * \param f pointer to the flow needed to be cleared.
1096  * \param proto_map mapped value of the protocol to FLOW_PROTO's.
1097  */
1098 
1099 int FlowClearMemory(Flow* f, uint8_t proto_map)
1100 {
1101  SCEnter();
1102 
1103  if (unlikely(f->flags & FLOW_HAS_EXPECTATION)) {
1105  }
1106 
1107  /* call the protocol specific free function if we have one */
1108  if (flow_freefuncs[proto_map].Freefunc != NULL) {
1109  flow_freefuncs[proto_map].Freefunc(f->protoctx);
1110  }
1111 
1112  FlowFreeStorage(f);
1113 
1114  FLOW_RECYCLE(f);
1115 
1116  SCReturnInt(1);
1117 }
1118 
1119 /**
1120  * \brief Function to set the function to get protocol specific flow state.
1121  *
1122  * \param proto protocol of which function is needed to be set.
1123  * \param Free Function pointer which will be called to free the protocol
1124  * specific memory.
1125  */
1126 
1127 int FlowSetProtoFreeFunc (uint8_t proto, void (*Free)(void *))
1128 {
1129  uint8_t proto_map;
1130  proto_map = FlowGetProtoMapping(proto);
1131 
1132  flow_freefuncs[proto_map].Freefunc = Free;
1133  return 1;
1134 }
1135 
1136 /**
1137  * \brief get 'disruption' flags: GAP/DEPTH/PASS
1138  * \param f locked flow
1139  * \param flags existing flags to be amended
1140  * \retval flags original flags + disrupt flags (if any)
1141  * \TODO handle UDP
1142  */
1143 uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
1144 {
1145  if (f->proto != IPPROTO_TCP) {
1146  return flags;
1147  }
1148  if (f->protoctx == NULL) {
1149  return flags;
1150  }
1151 
1152  uint8_t newflags = flags;
1153  TcpSession *ssn = f->protoctx;
1154  TcpStream *stream = flags & STREAM_TOSERVER ? &ssn->client : &ssn->server;
1155 
1157  newflags |= STREAM_DEPTH;
1158  }
1159  /* todo: handle pass case (also for UDP!) */
1160 
1161  return newflags;
1162 }
1163 
1164 void FlowUpdateState(Flow *f, const enum FlowState s)
1165 {
1166  if (s != f->flow_state) {
1167  /* set the state */
1168  // Explicit cast from the enum type to the compact version
1169  f->flow_state = (FlowStateType)s;
1170 
1171  /* update timeout policy and value */
1172  const uint32_t timeout_policy = FlowGetTimeoutPolicy(f);
1173  if (timeout_policy != f->timeout_policy) {
1174  f->timeout_policy = timeout_policy;
1175  }
1176  }
1177 #ifdef UNITTESTS
1178  if (f->fb != NULL) {
1179 #endif
1180  /* and reset the flow bucket next_ts value so that the flow manager
1181  * has to revisit this row */
1182  SC_ATOMIC_SET(f->fb->next_ts, 0);
1183 #ifdef UNITTESTS
1184  }
1185 #endif
1186 }
1187 
1188 /**
1189  * \brief Get flow last time as individual values.
1190  *
1191  * Instead of returning a pointer to the timeval copy the timeval
1192  * parts into output pointers to make it simpler to call from Rust
1193  * over FFI using only basic data types.
1194  */
1195 void SCFlowGetLastTimeAsParts(const Flow *flow, uint64_t *secs, uint64_t *usecs)
1196 {
1197  *secs = (uint64_t)SCTIME_SECS(flow->lastts);
1198  *usecs = (uint64_t)SCTIME_USECS(flow->lastts);
1199 }
1200 
1201 /**
1202  * \brief Get flow source port.
1203  *
1204  * A function to get the flow sport useful when the caller only has an
1205  * opaque pointer to the flow structure.
1206  */
1207 uint16_t SCFlowGetSourcePort(const Flow *flow)
1208 {
1209  return flow->sp;
1210 }
1211 
1212 /**
1213  * \brief Get flow destination port.
1214  *
1215  * A function to get the flow dport useful when the caller only has an
1216  * opaque pointer to the flow structure.
1217  */
1218 
1219 uint16_t SCFlowGetDestinationPort(const Flow *flow)
1220 {
1221  return flow->dp;
1222 }
1223 /**
1224  * \brief Get flow flags.
1225  *
1226  * A function to get the flow flags useful when the caller only has an
1227  * opaque pointer to the flow structure.
1228  */
1229 
1230 uint32_t SCFlowGetFlags(const Flow *flow)
1231 {
1232  return flow->flags;
1233 }
1234 /************************************Unittests*******************************/
1235 
1236 #ifdef UNITTESTS
1237 #include "threads.h"
1238 
1239 /**
1240  * \test Test the setting of the per protocol timeouts.
1241  *
1242  * \retval On success it returns 1 and on failure 0.
1243  */
1244 
1245 static int FlowTest01 (void)
1246 {
1247  uint8_t proto_map;
1248 
1250  proto_map = FlowGetProtoMapping(IPPROTO_TCP);
1251  FAIL_IF(flow_timeouts_normal[proto_map].new_timeout != FLOW_IPPROTO_TCP_NEW_TIMEOUT);
1252  FAIL_IF(flow_timeouts_normal[proto_map].est_timeout != FLOW_IPPROTO_TCP_EST_TIMEOUT);
1255 
1256  proto_map = FlowGetProtoMapping(IPPROTO_UDP);
1257  FAIL_IF(flow_timeouts_normal[proto_map].new_timeout != FLOW_IPPROTO_UDP_NEW_TIMEOUT);
1258  FAIL_IF(flow_timeouts_normal[proto_map].est_timeout != FLOW_IPPROTO_UDP_EST_TIMEOUT);
1261 
1262  proto_map = FlowGetProtoMapping(IPPROTO_ICMP);
1263  FAIL_IF(flow_timeouts_normal[proto_map].new_timeout != FLOW_IPPROTO_ICMP_NEW_TIMEOUT);
1264  FAIL_IF(flow_timeouts_normal[proto_map].est_timeout != FLOW_IPPROTO_ICMP_EST_TIMEOUT);
1267 
1268  proto_map = FlowGetProtoMapping(IPPROTO_DCCP);
1269  FAIL_IF(flow_timeouts_normal[proto_map].new_timeout != FLOW_DEFAULT_NEW_TIMEOUT);
1270  FAIL_IF(flow_timeouts_normal[proto_map].est_timeout != FLOW_DEFAULT_EST_TIMEOUT);
1271  FAIL_IF(flow_timeouts_emerg[proto_map].new_timeout != FLOW_DEFAULT_EMERG_NEW_TIMEOUT);
1272  FAIL_IF(flow_timeouts_emerg[proto_map].est_timeout != FLOW_DEFAULT_EMERG_EST_TIMEOUT);
1273 
1274  PASS;
1275 }
1276 
1277 /*Test function for the unit test FlowTest02*/
1278 
1279 static void test(void *f) {}
1280 
1281 /**
1282  * \test Test the setting of the per protocol free function to free the
1283  * protocol specific memory.
1284  *
1285  * \retval On success it returns 1 and on failure 0.
1286  */
1287 
1288 static int FlowTest02 (void)
1289 {
1291  FlowSetProtoFreeFunc(IPPROTO_TCP, test);
1292  FlowSetProtoFreeFunc(IPPROTO_UDP, test);
1293  FlowSetProtoFreeFunc(IPPROTO_ICMP, test);
1294 
1295  FAIL_IF(flow_freefuncs[FLOW_PROTO_DEFAULT].Freefunc != test);
1296  FAIL_IF(flow_freefuncs[FLOW_PROTO_TCP].Freefunc != test);
1297  FAIL_IF(flow_freefuncs[FLOW_PROTO_UDP].Freefunc != test);
1298  FAIL_IF(flow_freefuncs[FLOW_PROTO_ICMP].Freefunc != test);
1299 
1300  PASS;
1301 }
1302 
1303 /**
1304  * \test Test flow allocations when it reach memcap
1305  *
1306  *
1307  * \retval On success it returns 1 and on failure 0.
1308  */
1309 
1310 static int FlowTest07 (void)
1311 {
1312  int result = 0;
1314  FlowConfig backup;
1315  memcpy(&backup, &flow_config, sizeof(FlowConfig));
1316 
1317  uint32_t ini = 0;
1318  uint32_t end = FlowSpareGetPoolSize();
1319  SC_ATOMIC_SET(flow_config.memcap, 10000);
1320  flow_config.prealloc = 100;
1321 
1322  /* Let's get the flow spare pool empty */
1323  UTHBuildPacketOfFlows(ini, end, 0);
1324 
1325  /* And now let's try to reach the memcap val */
1326  while (FLOW_CHECK_MEMCAP(sizeof(Flow))) {
1327  ini = end + 1;
1328  end = end + 2;
1329  UTHBuildPacketOfFlows(ini, end, 0);
1330  }
1331 
1332  /* should time out normal */
1333  TimeSetIncrementTime(2000);
1334  ini = end + 1;
1335  end = end + 2;
1336  UTHBuildPacketOfFlows(ini, end, 0);
1337 
1338  /* This means that the engine entered emerg mode: should happen as easy
1339  * with flow mgr activated */
1340  if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY)
1341  result = 1;
1342 
1343  FlowShutdown();
1344  memcpy(&flow_config, &backup, sizeof(FlowConfig));
1345 
1346  return result;
1347 }
1348 
1349 /**
1350  * \test Test flow allocations when it reach memcap
1351  *
1352  *
1353  * \retval On success it returns 1 and on failure 0.
1354  */
1355 
1356 static int FlowTest08 (void)
1357 {
1358  int result = 0;
1359 
1361  FlowConfig backup;
1362  memcpy(&backup, &flow_config, sizeof(FlowConfig));
1363 
1364  uint32_t ini = 0;
1365  uint32_t end = FlowSpareGetPoolSize();
1366  SC_ATOMIC_SET(flow_config.memcap, 10000);
1367  flow_config.prealloc = 100;
1368 
1369  /* Let's get the flow spare pool empty */
1370  UTHBuildPacketOfFlows(ini, end, 0);
1371 
1372  /* And now let's try to reach the memcap val */
1373  while (FLOW_CHECK_MEMCAP(sizeof(Flow))) {
1374  ini = end + 1;
1375  end = end + 2;
1376  UTHBuildPacketOfFlows(ini, end, 0);
1377  }
1378 
1379  /* By default we use 30 for timing out new flows. This means
1380  * that the Emergency mode should be set */
1382  ini = end + 1;
1383  end = end + 2;
1384  UTHBuildPacketOfFlows(ini, end, 0);
1385 
1386  /* This means that the engine released 5 flows by emergency timeout */
1387  if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY)
1388  result = 1;
1389 
1390  memcpy(&flow_config, &backup, sizeof(FlowConfig));
1391  FlowShutdown();
1392 
1393  return result;
1394 }
1395 
1396 /**
1397  * \test Test flow allocations when it reach memcap
1398  *
1399  *
1400  * \retval On success it returns 1 and on failure 0.
1401  */
1402 
1403 static int FlowTest09 (void)
1404 {
1405  int result = 0;
1406 
1408  FlowConfig backup;
1409  memcpy(&backup, &flow_config, sizeof(FlowConfig));
1410 
1411  uint32_t ini = 0;
1412  uint32_t end = FlowSpareGetPoolSize();
1413  SC_ATOMIC_SET(flow_config.memcap, 10000);
1414  flow_config.prealloc = 100;
1415 
1416  /* Let's get the flow spare pool empty */
1417  UTHBuildPacketOfFlows(ini, end, 0);
1418 
1419  /* And now let's try to reach the memcap val */
1420  while (FLOW_CHECK_MEMCAP(sizeof(Flow))) {
1421  ini = end + 1;
1422  end = end + 2;
1423  UTHBuildPacketOfFlows(ini, end, 0);
1424  }
1425 
1426  /* No timeout will work */
1428  ini = end + 1;
1429  end = end + 2;
1430  UTHBuildPacketOfFlows(ini, end, 0);
1431 
1432  /* engine in emerg mode */
1433  if (SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY)
1434  result = 1;
1435 
1436  memcpy(&flow_config, &backup, sizeof(FlowConfig));
1437  FlowShutdown();
1438 
1439  return result;
1440 }
1441 
1442 #endif /* UNITTESTS */
1443 
1444 /**
1445  * \brief Function to register the Flow Unitests.
1446  */
1448 {
1449 #ifdef UNITTESTS
1450  UtRegisterTest("FlowTest01 -- Protocol Specific Timeouts", FlowTest01);
1451  UtRegisterTest("FlowTest02 -- Setting Protocol Specific Free Function",
1452  FlowTest02);
1453  UtRegisterTest("FlowTest07 -- Test flow Allocations when it reach memcap",
1454  FlowTest07);
1455  UtRegisterTest("FlowTest08 -- Test flow Allocations when it reach memcap",
1456  FlowTest08);
1457  UtRegisterTest("FlowTest09 -- Test flow Allocations when it reach memcap",
1458  FlowTest09);
1459 
1461 #endif /* UNITTESTS */
1462 }
FLOWFILE_NO_MD5_TS
#define FLOWFILE_NO_MD5_TS
Definition: flow.h:137
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:138
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
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:114
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
StatsIncr
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
Definition: counters.c:166
PKT_HAS_FLOW
#define PKT_HAS_FLOW
Definition: decode.h:1268
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:279
FLOW_STATE_ESTABLISHED
@ FLOW_STATE_ESTABLISHED
Definition: flow.h:497
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:292
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:286
BIT_U16
#define BIT_U16(n)
Definition: suricata-common.h:416
FlowRegisterTests
void FlowRegisterTests(void)
Function to register the Flow Unitests.
Definition: flow.c:1447
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:279
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:75
Packet_::pcap_cnt
uint64_t pcap_cnt
Definition: decode.h:626
ParseSizeStringU64
int ParseSizeStringU64(const char *size, uint64_t *res)
Definition: util-misc.c:191
Flow_::proto
uint8_t proto
Definition: flow.h:370
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:130
Packet_::flags
uint32_t flags
Definition: decode.h:544
threads.h
util-macset.h
flow-private.h
Flow_
Flow data structure.
Definition: flow.h:348
Flow_::protomap
uint8_t protomap
Definition: flow.h:437
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:510
SCConfGet
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
Definition: conf.c:350
flow-hash.h
FLOW_NOPAYLOAD_INSPECTION
#define FLOW_NOPAYLOAD_INSPECTION
Definition: flow.h:67
FLOW_TS_PM_ALPROTO_DETECT_DONE
#define FLOW_TS_PM_ALPROTO_DETECT_DONE
Definition: flow.h:86
FlowReset
void FlowReset(void)
Definition: flow.c:675
FlowLookupStruct_
Definition: flow.h:534
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:207
FlowProtoTimeout_::bypassed_timeout
uint32_t bypassed_timeout
Definition: flow.h:514
FLOW_DEFAULT_EST_TIMEOUT
#define FLOW_DEFAULT_EST_TIMEOUT
Definition: flow-private.h:41
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:225
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:1222
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:535
FLOW_ACTION_DROP
#define FLOW_ACTION_DROP
Definition: flow.h:70
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:78
Flow_::max_ttl_toserver
uint8_t max_ttl_toserver
Definition: flow.h:460
proto
uint8_t proto
Definition: decode-template.h:0
Flow_::dp
Port dp
Definition: flow.h:364
SCConfNodeLookupChildValue
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:824
FLOW_TC_PE_ALPROTO_DETECT_DONE
#define FLOW_TC_PE_ALPROTO_DETECT_DONE
Definition: flow.h:96
Packet_::icmp_s
struct Packet_::@33::@40 icmp_s
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:1230
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:433
FLOW_PROTO_UDP
@ FLOW_PROTO_UDP
Definition: flow-private.h:67
DecodeThreadVars_::counter_max_mac_addrs_src
uint16_t counter_max_mac_addrs_src
Definition: decode.h:972
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:287
UTHBuildPacketOfFlows
uint32_t UTHBuildPacketOfFlows(uint32_t start, uint32_t end, uint8_t dir)
Definition: util-unittest-helper.c:874
AppLayerExpectationClean
void AppLayerExpectationClean(Flow *f)
Definition: app-layer-expectation.c:361
Flow_::flow_state
FlowStateType flow_state
Definition: flow.h:404
PKT_PROTO_DETECT_TS_DONE
#define PKT_PROTO_DETECT_TS_DONE
Definition: decode.h:1301
Flow_::sgh_toserver
const struct SigGroupHead_ * sgh_toserver
Definition: flow.h:478
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:490
flow-spare-pool.h
Flow_::alparser
AppLayerParserState * alparser
Definition: flow.h:470
FlowRateStoreUpdate
void FlowRateStoreUpdate(FlowRateStore *frs, SCTime_t p_ts, uint32_t pkt_len, int direction)
Definition: util-flow-rate.c:193
FLOWFILE_NO_SHA1_TC
#define FLOWFILE_NO_SHA1_TC
Definition: flow.h:142
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:549
Flow_::fb
struct FlowBucket_ * fb
Definition: flow.h:483
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:499
Flow_::min_ttl_toserver
uint8_t min_ttl_toserver
Definition: flow.h:459
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:487
FLOWFILE_NO_STORE_TS
#define FLOWFILE_NO_STORE_TS
Definition: flow.h:134
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:402
Flow_::lastts
SCTime_t lastts
Definition: flow.h:402
SCConfGetInt
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
Definition: conf.c:414
SCEnter
#define SCEnter(...)
Definition: util-debug.h:281
MacSetAddWithCtr
void MacSetAddWithCtr(MacSet *ms, const uint8_t *src_addr, const uint8_t *dst_addr, ThreadVars *tv, uint16_t ctr_src, uint16_t ctr_dst)
Definition: util-macset.c:182
FLOW_CHANGE_PROTO
#define FLOW_CHANGE_PROTO
Definition: flow.h:108
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:284
FLOWFILE_NO_SHA256_TS
#define FLOWFILE_NO_SHA256_TS
Definition: flow.h:145
FLOW_PKT_TOCLIENT_FIRST
#define FLOW_PKT_TOCLIENT_FIRST
Definition: flow.h:229
FlowQueueInit
FlowQueue * FlowQueueInit(FlowQueue *q)
Definition: flow-queue.c:46
FlowState
FlowState
Definition: flow.h:495
TcpSession_::state
uint8_t state
Definition: stream-tcp-private.h:285
FlowProtoTimeout_::new_timeout
uint32_t new_timeout
Definition: flow.h:511
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:513
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:259
app-layer-parser.h
AppLayerParserStateCleanup
void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate)
Definition: app-layer-parser.c:1650
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:105
Packet_::pkt_hooks
uint16_t pkt_hooks
Definition: decode.h:541
Flow_::todstbytecnt
uint64_t todstbytecnt
Definition: flow.h:489
ThreadVars_::id
int id
Definition: threadvars.h:87
FLOW_TC_PP_ALPROTO_DETECT_DONE
#define FLOW_TC_PP_ALPROTO_DETECT_DONE
Definition: flow.h:94
Flow_::sgh_toclient
const struct SigGroupHead_ * sgh_toclient
Definition: flow.h:475
MacSetFlowStorageEnabled
bool MacSetFlowStorageEnabled(void)
Definition: util-macset.c:86
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:325
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:518
FlowClearMemory
int FlowClearMemory(Flow *f, uint8_t proto_map)
Function clear the flow memory before queueing it to spare flow queue.
Definition: flow.c:1099
flow_timeouts_delta
FlowProtoTimeout flow_timeouts_delta[FLOW_PROTO_MAX]
Definition: flow.c:91
FlowCnf_::hash_rand
uint32_t hash_rand
Definition: flow.h:285
SCFlowGetLastTimeAsParts
void SCFlowGetLastTimeAsParts(const Flow *flow, uint64_t *secs, uint64_t *usecs)
Get flow last time as individual values.
Definition: flow.c:1195
Flow_::min_ttl_toclient
uint8_t min_ttl_toclient
Definition: flow.h:461
FLOW_IS_ELEPHANT
#define FLOW_IS_ELEPHANT
Definition: flow.h:59
MacSetGetFlowStorageID
FlowStorageId MacSetGetFlowStorageID(void)
Definition: util-macset.c:115
flow-queue.h
Flow_::probing_parser_toclient_alproto_masks
uint32_t probing_parser_toclient_alproto_masks
Definition: flow.h:411
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:226
SCFlowGetDestinationPort
uint16_t SCFlowGetDestinationPort(const Flow *flow)
Get flow destination port.
Definition: flow.c:1219
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:1164
Flow_::src
FlowAddress src
Definition: flow.h:351
Flow_::next
struct Flow_ * next
Definition: flow.h:388
Flow_::probing_parser_toserver_alproto_masks
uint32_t probing_parser_toserver_alproto_masks
Definition: flow.h:410
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:33
FLOWFILE_NO_SHA256_TC
#define FLOWFILE_NO_SHA256_TC
Definition: flow.h:146
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:796
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:90
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:1127
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:322
FLOWFILE_NO_MAGIC_TC
#define FLOWFILE_NO_MAGIC_TC
Definition: flow.h:131
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:1207
FLOW_HAS_ALERTS
#define FLOW_HAS_ALERTS
Definition: flow.h:83
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:693
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:104
FlowRateIsExceeding
bool FlowRateIsExceeding(FlowRateStore *frs, int direction)
Definition: util-flow-rate.c:228
FatalError
#define FatalError(...)
Definition: util-debug.h:514
Flow_::max_ttl_toclient
uint8_t max_ttl_toclient
Definition: flow.h:462
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:88
PKT_PROTO_DETECT_TC_DONE
#define PKT_PROTO_DETECT_TC_DONE
Definition: decode.h:1302
FLOWFILE_NO_STORE_TC
#define FLOWFILE_NO_STORE_TC
Definition: flow.h:135
FlowGetFlowFromHash
Flow * FlowGetFlowFromHash(ThreadVars *tv, FlowLookupStruct *fls, Packet *p, Flow **dest)
Get Flow for packet.
Definition: flow-hash.c:907
Flow_::timeout_policy
uint32_t timeout_policy
Definition: flow.h:397
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:32
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:294
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:737
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:141
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:296
SCConfGetNode
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
Definition: conf.c:181
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:271
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:73
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:963
Flow_::alproto_ts
AppProto alproto_ts
Definition: flow.h:443
Flow_::alstate
void * alstate
Definition: flow.h:471
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
DecodeThreadVars_::counter_flow_elephant
uint16_t counter_flow_elephant
Definition: decode.h:1041
Flow_::flags
uint32_t flags
Definition: flow.h:413
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
DecodeThreadVars_::counter_max_mac_addrs_dst
uint16_t counter_max_mac_addrs_dst
Definition: decode.h:973
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:80
util-random.h
FLOW_PKT_ESTABLISHED
#define FLOW_PKT_ESTABLISHED
Definition: flow.h:227
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:242
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:92
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:1230
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:512
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:353
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375
FlowGetDisruptionFlags
uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
get 'disruption' flags: GAP/DEPTH/PASS
Definition: flow.c:1143
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:444
Flow_::file_flags
uint16_t file_flags
Definition: flow.h:415
Packet_::dp
Port dp
Definition: decode.h:516
ExceptionPolicy
ExceptionPolicy
Definition: util-exception-policy-types.h:25
FLOW_DIR_REVERSED
#define FLOW_DIR_REVERSED
Definition: flow.h:112
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
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:285
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:228
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:488
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:386
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:517