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