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