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