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