suricata
flow.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2025 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
24#ifndef SURICATA_FLOW_H
25#define SURICATA_FLOW_H
26
27/* forward declaration for macset include */
29
30#include "decode.h"
31#include "util-time.h"
34#include "util-var.h"
35#include "util-optimize.h"
36#include "util-validate.h"
37#include "app-layer-protos.h"
38
39/* Part of the flow structure, so we declare it here.
40 * The actual declaration is in app-layer-parser.c */
42
43#define FLOW_QUIET true
44
45#define TOSERVER 0
46#define TOCLIENT 1
47
48/* per flow flags */
49
50/** At least one packet from the source address was seen */
51#define FLOW_TO_SRC_SEEN BIT_U32(0)
52/** At least one packet from the destination address was seen */
53#define FLOW_TO_DST_SEEN BIT_U32(1)
54
55/** next packet in toclient direction will act on updated app-layer state */
56#define FLOW_TC_APP_UPDATE_NEXT BIT_U32(2)
57
58/** Flow is marked an elephant flow */
59#define FLOW_IS_ELEPHANT BIT_U32(3)
60
61/** All packets in this flow should be accepted */
62#define FLOW_ACTION_ACCEPT BIT_U32(4)
63
64// vacancy bit 5
65
66/** Packet payloads belonging to this flow should not be inspected */
67#define FLOW_NOPAYLOAD_INSPECTION BIT_U32(6)
68
69/** All packets in this flow should be dropped */
70#define FLOW_ACTION_DROP BIT_U32(7)
71
72/** Sgh for toserver direction set (even if it's NULL) */
73#define FLOW_SGH_TOSERVER BIT_U32(8)
74/** Sgh for toclient direction set (even if it's NULL) */
75#define FLOW_SGH_TOCLIENT BIT_U32(9)
76
77/** packet to server direction has been logged in drop file (only in IPS mode) */
78#define FLOW_TOSERVER_DROP_LOGGED BIT_U32(10)
79/** packet to client direction has been logged in drop file (only in IPS mode) */
80#define FLOW_TOCLIENT_DROP_LOGGED BIT_U32(11)
81
82/** flow has alerts */
83#define FLOW_HAS_ALERTS BIT_U32(12)
84
85/** Pattern matcher alproto detection done */
86#define FLOW_TS_PM_ALPROTO_DETECT_DONE BIT_U32(13)
87/** Probing parser alproto detection done */
88#define FLOW_TS_PP_ALPROTO_DETECT_DONE BIT_U32(14)
89/** Expectation alproto detection done */
90#define FLOW_TS_PE_ALPROTO_DETECT_DONE BIT_U32(15)
91/** Pattern matcher alproto detection done */
92#define FLOW_TC_PM_ALPROTO_DETECT_DONE BIT_U32(16)
93/** Probing parser alproto detection done */
94#define FLOW_TC_PP_ALPROTO_DETECT_DONE BIT_U32(17)
95/** Expectation alproto detection done */
96#define FLOW_TC_PE_ALPROTO_DETECT_DONE BIT_U32(18)
97#define FLOW_TIMEOUT_REASSEMBLY_DONE BIT_U32(19)
98
99/** flow is ipv4 */
100#define FLOW_IPV4 BIT_U32(20)
101/** flow is ipv6 */
102#define FLOW_IPV6 BIT_U32(21)
103
104#define FLOW_PROTO_DETECT_TS_DONE BIT_U32(22)
105#define FLOW_PROTO_DETECT_TC_DONE BIT_U32(23)
106
107/** Indicate that alproto detection for flow should be done again */
108#define FLOW_CHANGE_PROTO BIT_U32(24)
109
110#define FLOW_WRONG_THREAD BIT_U32(25)
111/** Protocol detection told us flow is picked up in wrong direction (midstream) */
112#define FLOW_DIR_REVERSED BIT_U32(26)
113/** Indicate that the flow did trigger an expectation creation */
114#define FLOW_HAS_EXPECTATION BIT_U32(27)
115
116/** All packets in this flow should be passed */
117#define FLOW_ACTION_PASS BIT_U32(28)
118
119#define FLOW_TS_APP_UPDATED BIT_U32(29)
120#define FLOW_TC_APP_UPDATED BIT_U32(30)
121
122/** next packet in toserver direction will act on updated app-layer state */
123#define FLOW_TS_APP_UPDATE_NEXT BIT_U32(31)
124
125/* File flags */
126
127#define FLOWFILE_INIT 0
128
129/** no magic on files in this flow */
130#define FLOWFILE_NO_MAGIC_TS BIT_U16(0)
131#define FLOWFILE_NO_MAGIC_TC BIT_U16(1)
132
133/** even if the flow has files, don't store 'm */
134#define FLOWFILE_NO_STORE_TS BIT_U16(2)
135#define FLOWFILE_NO_STORE_TC BIT_U16(3)
136/** no md5 on files in this flow */
137#define FLOWFILE_NO_MD5_TS BIT_U16(4)
138#define FLOWFILE_NO_MD5_TC BIT_U16(5)
139
140/** no sha1 on files in this flow */
141#define FLOWFILE_NO_SHA1_TS BIT_U16(6)
142#define FLOWFILE_NO_SHA1_TC BIT_U16(7)
143
144/** no sha256 on files in this flow */
145#define FLOWFILE_NO_SHA256_TS BIT_U16(8)
146#define FLOWFILE_NO_SHA256_TC BIT_U16(9)
147
148/** no size tracking of files in this flow */
149#define FLOWFILE_NO_SIZE_TS BIT_U16(10)
150#define FLOWFILE_NO_SIZE_TC BIT_U16(11)
151
152/** store files in the flow */
153#define FLOWFILE_STORE_TS BIT_U16(12)
154#define FLOWFILE_STORE_TC BIT_U16(13)
155
156#define FLOWFILE_NONE_TS (FLOWFILE_NO_MAGIC_TS | \
157 FLOWFILE_NO_STORE_TS | \
158 FLOWFILE_NO_MD5_TS | \
159 FLOWFILE_NO_SHA1_TS | \
160 FLOWFILE_NO_SHA256_TS| \
161 FLOWFILE_NO_SIZE_TS)
162#define FLOWFILE_NONE_TC (FLOWFILE_NO_MAGIC_TC | \
163 FLOWFILE_NO_STORE_TC | \
164 FLOWFILE_NO_MD5_TC | \
165 FLOWFILE_NO_SHA1_TC | \
166 FLOWFILE_NO_SHA256_TC| \
167 FLOWFILE_NO_SIZE_TC)
168#define FLOWFILE_NONE (FLOWFILE_NONE_TS|FLOWFILE_NONE_TC)
169
170#define FLOW_IS_IPV4(f) \
171 (((f)->flags & FLOW_IPV4) == FLOW_IPV4)
172#define FLOW_IS_IPV6(f) \
173 (((f)->flags & FLOW_IPV6) == FLOW_IPV6)
174
175#define FLOW_GET_SP(f) \
176 ((f)->flags & FLOW_DIR_REVERSED) ? (f)->dp : (f)->sp;
177#define FLOW_GET_DP(f) \
178 ((f)->flags & FLOW_DIR_REVERSED) ? (f)->sp : (f)->dp;
179
180#define FLOW_COPY_IPV4_ADDR_TO_PACKET(fa, pa) do { \
181 (pa)->family = AF_INET; \
182 (pa)->addr_data32[0] = (fa)->addr_data32[0]; \
183 } while (0)
184
185#define FLOW_COPY_IPV6_ADDR_TO_PACKET(fa, pa) do { \
186 (pa)->family = AF_INET6; \
187 (pa)->addr_data32[0] = (fa)->addr_data32[0]; \
188 (pa)->addr_data32[1] = (fa)->addr_data32[1]; \
189 (pa)->addr_data32[2] = (fa)->addr_data32[2]; \
190 (pa)->addr_data32[3] = (fa)->addr_data32[3]; \
191 } while (0)
192
193/* Set the IPv4 addressesinto the Addrs of the Packet.
194 * Make sure p->ip4h is initialized and validated.
195 *
196 * We set the rest of the struct to 0 so we can
197 * prevent using memset. */
198#define FLOW_SET_IPV4_SRC_ADDR_FROM_PACKET(ip4h, a) \
199 do { \
200 (a)->addr_data32[0] = (uint32_t)(ip4h)->s_ip_src.s_addr; \
201 (a)->addr_data32[1] = 0; \
202 (a)->addr_data32[2] = 0; \
203 (a)->addr_data32[3] = 0; \
204 } while (0)
205
206#define FLOW_SET_IPV4_DST_ADDR_FROM_PACKET(ip4h, a) \
207 do { \
208 (a)->addr_data32[0] = (uint32_t)(ip4h)->s_ip_dst.s_addr; \
209 (a)->addr_data32[1] = 0; \
210 (a)->addr_data32[2] = 0; \
211 (a)->addr_data32[3] = 0; \
212 } while (0)
213
214/* Set the IPv6 addressesinto the Addrs of the Packet.
215 * Make sure p->ip6h is initialized and validated. */
216#define FLOW_SET_IPV6_SRC_ADDR_FROM_PACKET(ip6h, a) \
217 do { \
218 (a)->addr_data32[0] = (ip6h)->s_ip6_src[0]; \
219 (a)->addr_data32[1] = (ip6h)->s_ip6_src[1]; \
220 (a)->addr_data32[2] = (ip6h)->s_ip6_src[2]; \
221 (a)->addr_data32[3] = (ip6h)->s_ip6_src[3]; \
222 } while (0)
223
224#define FLOW_SET_IPV6_DST_ADDR_FROM_PACKET(ip6h, a) \
225 do { \
226 (a)->addr_data32[0] = (ip6h)->s_ip6_dst[0]; \
227 (a)->addr_data32[1] = (ip6h)->s_ip6_dst[1]; \
228 (a)->addr_data32[2] = (ip6h)->s_ip6_dst[2]; \
229 (a)->addr_data32[3] = (ip6h)->s_ip6_dst[3]; \
230 } while (0)
231
232/* pkt flow flags */
233#define FLOW_PKT_TOSERVER 0x01
234#define FLOW_PKT_TOCLIENT 0x02
235#define FLOW_PKT_ESTABLISHED 0x04
236#define FLOW_PKT_TOSERVER_FIRST 0x08
237#define FLOW_PKT_TOCLIENT_FIRST 0x10
238/** last pseudo packet in the flow. Can be used to trigger final clean,
239 * logging, etc. */
240#define FLOW_PKT_LAST_PSEUDO 0x20
241
242#define FLOW_END_FLAG_EMERGENCY 0x01
243#define FLOW_END_FLAG_TIMEOUT 0x02
244#define FLOW_END_FLAG_FORCED 0x04
245#define FLOW_END_FLAG_SHUTDOWN 0x08
246#define FLOW_END_FLAG_TCPREUSE 0x10
247
248/** Mutex or RWLocks for the flow. */
249//#define FLOWLOCK_RWLOCK
250#define FLOWLOCK_MUTEX
251
252#ifdef FLOWLOCK_RWLOCK
253 #ifdef FLOWLOCK_MUTEX
254 #error Cannot enable both FLOWLOCK_RWLOCK and FLOWLOCK_MUTEX
255 #endif
256#endif
257
258#ifdef FLOWLOCK_RWLOCK
259 #define FLOWLOCK_INIT(fb) SCRWLockInit(&(fb)->r, NULL)
260 #define FLOWLOCK_DESTROY(fb) SCRWLockDestroy(&(fb)->r)
261 #define FLOWLOCK_RDLOCK(fb) SCRWLockRDLock(&(fb)->r)
262 #define FLOWLOCK_WRLOCK(fb) SCRWLockWRLock(&(fb)->r)
263 #define FLOWLOCK_TRYRDLOCK(fb) SCRWLockTryRDLock(&(fb)->r)
264 #define FLOWLOCK_TRYWRLOCK(fb) SCRWLockTryWRLock(&(fb)->r)
265 #define FLOWLOCK_UNLOCK(fb) SCRWLockUnlock(&(fb)->r)
266#elif defined FLOWLOCK_MUTEX
267 #define FLOWLOCK_INIT(fb) SCMutexInit(&(fb)->m, NULL)
268 #define FLOWLOCK_DESTROY(fb) SCMutexDestroy(&(fb)->m)
269 #define FLOWLOCK_RDLOCK(fb) SCMutexLock(&(fb)->m)
270 #define FLOWLOCK_WRLOCK(fb) SCMutexLock(&(fb)->m)
271 #define FLOWLOCK_TRYRDLOCK(fb) SCMutexTrylock(&(fb)->m)
272 #define FLOWLOCK_TRYWRLOCK(fb) SCMutexTrylock(&(fb)->m)
273 #define FLOWLOCK_UNLOCK(fb) SCMutexUnlock(&(fb)->m)
274#else
275 #error Enable FLOWLOCK_RWLOCK or FLOWLOCK_MUTEX
276#endif
277
278#define FLOW_IS_PM_DONE(f, dir) (((dir) & STREAM_TOSERVER) ? ((f)->flags & FLOW_TS_PM_ALPROTO_DETECT_DONE) : ((f)->flags & FLOW_TC_PM_ALPROTO_DETECT_DONE))
279#define FLOW_IS_PP_DONE(f, dir) (((dir) & STREAM_TOSERVER) ? ((f)->flags & FLOW_TS_PP_ALPROTO_DETECT_DONE) : ((f)->flags & FLOW_TC_PP_ALPROTO_DETECT_DONE))
280#define FLOW_IS_PE_DONE(f, dir) (((dir) & STREAM_TOSERVER) ? ((f)->flags & FLOW_TS_PE_ALPROTO_DETECT_DONE) : ((f)->flags & FLOW_TC_PE_ALPROTO_DETECT_DONE))
281
282#define FLOW_SET_PM_DONE(f, dir) (((dir) & STREAM_TOSERVER) ? ((f)->flags |= FLOW_TS_PM_ALPROTO_DETECT_DONE) : ((f)->flags |= FLOW_TC_PM_ALPROTO_DETECT_DONE))
283#define FLOW_SET_PP_DONE(f, dir) (((dir) & STREAM_TOSERVER) ? ((f)->flags |= FLOW_TS_PP_ALPROTO_DETECT_DONE) : ((f)->flags |= FLOW_TC_PP_ALPROTO_DETECT_DONE))
284#define FLOW_SET_PE_DONE(f, dir) (((dir) & STREAM_TOSERVER) ? ((f)->flags |= FLOW_TS_PE_ALPROTO_DETECT_DONE) : ((f)->flags |= FLOW_TC_PE_ALPROTO_DETECT_DONE))
285
286#define FLOW_RESET_PM_DONE(f, dir) (((dir) & STREAM_TOSERVER) ? ((f)->flags &= ~FLOW_TS_PM_ALPROTO_DETECT_DONE) : ((f)->flags &= ~FLOW_TC_PM_ALPROTO_DETECT_DONE))
287#define FLOW_RESET_PP_DONE(f, dir) (((dir) & STREAM_TOSERVER) ? ((f)->flags &= ~FLOW_TS_PP_ALPROTO_DETECT_DONE) : ((f)->flags &= ~FLOW_TC_PP_ALPROTO_DETECT_DONE))
288#define FLOW_RESET_PE_DONE(f, dir) (((dir) & STREAM_TOSERVER) ? ((f)->flags &= ~FLOW_TS_PE_ALPROTO_DETECT_DONE) : ((f)->flags &= ~FLOW_TC_PE_ALPROTO_DETECT_DONE))
289
290/* global flow config */
291typedef struct FlowCnf_
292{
293 uint32_t hash_rand;
294 uint32_t hash_size;
295 uint32_t prealloc;
296
297 uint32_t timeout_new;
298 uint32_t timeout_est;
299
301
303
304 SC_ATOMIC_DECLARE(uint64_t, memcap);
306
307/* Hash key for the flow hash */
317
318typedef struct FlowAddress_ {
319 union {
320 uint32_t address_un_data32[4]; /* type-specific field */
321 uint16_t address_un_data16[8]; /* type-specific field */
322 uint8_t address_un_data8[16]; /* type-specific field */
325
326#define addr_data32 address.address_un_data32
327#define addr_data16 address.address_un_data16
328#define addr_data8 address.address_un_data8
329
330typedef unsigned short FlowStateType;
331
332/** Local Thread ID */
333typedef uint16_t FlowThreadId;
334
335#include "util-storage.h"
336
337/**
338 * \brief Flow data structure.
339 *
340 * The flow is a global data structure that is created for new packets of a
341 * flow and then looked up for the following packets of a flow.
342 *
343 * Locking
344 *
345 * The flow is updated/used by multiple packets at the same time. This is why
346 * there is a flow-mutex. It's a mutex and not a spinlock because some
347 * operations on the flow can be quite expensive, thus spinning would be
348 * too expensive.
349 *
350 * The flow "header" (addresses, ports, proto, recursion level) are static
351 * after the initialization and remain read-only throughout the entire live
352 * of a flow. This is why we can access those without protection of the lock.
353 */
354
355typedef struct Flow_
356{
357 /* flow "header", used for hashing and flow lookup. Static after init,
358 * so safe to look at without lock */
360 union {
361 Port sp; /**< tcp/udp source port */
362 struct {
363 uint8_t type; /**< icmp type */
364 uint8_t code; /**< icmp code */
366
367 struct {
368 uint32_t spi; /**< esp spi */
370 };
371 union {
372 Port dp; /**< tcp/udp destination port */
373 struct {
374 uint8_t type; /**< icmp type */
375 uint8_t code; /**< icmp code */
377 };
378 uint8_t proto;
381
382 uint8_t vlan_idx;
383
384 /* track toserver/toclient flow timeout needs */
385 union {
386 struct {
387 uint8_t ffr_ts:4;
388 uint8_t ffr_tc:4;
389 };
390 uint8_t ffr;
391 };
392
393 /** Thread ID for the stream/detect portion of this flow */
395
396 struct Flow_ *next; /* (hash) list next */
397 /** Incoming interface */
399
400 /** flow hash - the flow hash before hash table size mod. */
401 uint32_t flow_hash;
402
403 /** timeout in seconds by policy, add to Flow::lastts to get actual time this times out.
404 * Ignored in emergency mode. */
406
407 /* time stamp of last update (last packet). Set/updated under the
408 * flow and flow hash row locks, safe to read under either the
409 * flow lock or flow hash row lock. */
411
413
414 /** flow tenant id, used to setup flow timeout and stream pseudo
415 * packets with the correct tenant id set */
416 uint32_t tenant_id;
417
420
421 uint32_t flags; /**< generic flags */
422
423 uint16_t file_flags; /**< file tracking/extraction flags */
424
425 /** destination port to be used in protocol detection. This is meant
426 * for use with STARTTLS and HTTP CONNECT detection */
427 uint16_t protodetect_dp; /**< 0 if not used */
428
429 /* Parent flow id for protocol like ftp */
430 int64_t parent_id;
431
432#ifdef FLOWLOCK_RWLOCK
433 SCRWLock r;
434#elif defined FLOWLOCK_MUTEX
436#else
437 #error Enable FLOWLOCK_RWLOCK or FLOWLOCK_MUTEX
438#endif
439
440 /** protocol specific data pointer, e.g. for TcpSession */
441 void *protoctx;
442
443 /** mapping to Flow's protocol specific protocols for timeouts
444 and state and free functions. */
445 uint8_t protomap;
446
448 /* coccinelle: Flow:flow_end_flags:FLOW_END_FLAG_ */
449
450 AppProto alproto; /**< \brief application level protocol */
453
454 /** original application level protocol. Used to indicate the previous
455 protocol when changing to another protocol , e.g. with STARTTLS. */
457 /** expected app protocol: used in protocol change/upgrade like in
458 * STARTTLS. */
460
461 /** detection engine ctx version used to inspect this flow. Set at initial
462 * inspection. If it doesn't match the currently in use de_ctx, the
463 * stored sgh ptrs are reset. */
465
466 /** ttl tracking */
471
472 /** which exception policies were applied, if any */
474
475 /** application level storage ptrs.
476 *
477 */
478 AppLayerParserState *alparser; /**< parser internal state */
479 void *alstate; /**< application layer state */
480
481 /** toclient sgh for this flow. Only use when FLOW_SGH_TOCLIENT flow flag
482 * has been set. */
484 /** toserver sgh for this flow. Only use when FLOW_SGH_TOSERVER flow flag
485 * has been set. */
487
488 /* pointer to the var list */
490
492
494
495 uint32_t todstpktcnt;
496 uint32_t tosrcpktcnt;
497 uint64_t todstbytecnt;
498 uint64_t tosrcbytecnt;
499
502
508#ifdef CAPTURE_OFFLOAD
509 FLOW_STATE_CAPTURE_BYPASSED,
510#endif
511};
512#ifdef CAPTURE_OFFLOAD
513#define FLOW_STATE_SIZE 5
514#else
515#define FLOW_STATE_SIZE 4
516#endif
517
524
525typedef struct FlowProtoFreeFunc_ {
526 void (*Freefunc)(void *);
528
529typedef struct FlowBypassInfo_ {
530 bool (* BypassUpdate)(Flow *f, void *data, time_t tsec);
531 void (* BypassFree)(void *data);
533 uint64_t tosrcpktcnt;
534 uint64_t tosrcbytecnt;
535 uint64_t todstpktcnt;
536 uint64_t todstbytecnt;
538
539#include "flow-queue.h"
540
549
550/** \brief prepare packet for a life with flow
551 * Set PKT_WANTS_FLOW flag to indicate workers should do a flow lookup
552 * and calc the hash value to be used in the lookup and autofp flow
553 * balancing. */
554void FlowSetupPacket(Packet *p);
556void FlowInitConfig(bool);
557void FlowReset(void);
558void FlowShutdown(void);
560int FlowHasAlerts(const Flow *);
563int FlowChangeProto(Flow *);
564void FlowSwap(Flow *);
565
566void FlowRegisterTests(void);
567int FlowSetProtoFreeFunc(uint8_t, void (*Free)(void *));
568
569static inline void FlowSetNoPayloadInspectionFlag(Flow *);
570
571int FlowGetPacketDirection(const Flow *, const Packet *);
572
574
575void FlowUpdateState(Flow *f, enum FlowState s);
576
577int FlowSetMemcap(uint64_t size);
578uint64_t FlowGetMemcap(void);
579uint64_t FlowGetMemuse(void);
581
583void RegisterFlowBypassInfo(void);
584
585void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs);
586uint32_t FlowGetFlags(Flow *flow);
587uint16_t FlowGetSourcePort(Flow *flow);
588uint16_t FlowGetDestinationPort(Flow *flow);
589
590/** ----- Inline functions ----- */
591
592static inline AppProto FlowGetAppProtocol(const Flow *f)
593{
594 return f->alproto;
595}
596
597static inline void *FlowGetAppState(const Flow *f)
598{
599 return f->alstate;
600}
601
602/** \brief Set the No payload inspection Flag without locking the flow.
603 *
604 * \param f Flow to set the flag in
605 */
606static inline void FlowSetNoPayloadInspectionFlag(Flow *f)
607{
608 SCEnter();
609
610 SCLogDebug("flow %p", f);
612
613 SCReturn;
614}
615
616/** \brief Reference the flow
617 * \note This should only be called once for a destination
618 * pointer */
619static inline void FlowReference(Flow **d, Flow *f)
620{
621 if (likely(f != NULL)) {
622 DEBUG_VALIDATE_BUG_ON(*d == f);
623 if (*d == f)
624 return;
625 *d = f;
626 }
627}
628
629static inline void FlowDeReference(Flow **d)
630{
631 if (likely(*d != NULL)) {
632 *d = NULL;
633 }
634}
635
636/** \brief create a flow id that is as unique as possible
637 * \retval flow_id unsigned 64bit id
638 */
639static inline uint64_t FlowGetId(const Flow *f)
640{
641 uint64_t id = (uint64_t)(SCTIME_SECS(f->startts) & 0xFFFF) << 48 |
642 (uint64_t)(SCTIME_USECS(f->startts) & 0xFFFF) << 32 | (uint64_t)f->flow_hash;
643 /* reduce to 51 bits as JavaScript and even JSON often seem to
644 * max out there. */
645 id &= 0x7ffffffffffffLL;
646 return id;
647}
648
649static inline bool FlowIsBypassed(const Flow *f)
650{
651 if (
652#ifdef CAPTURE_OFFLOAD
653 f->flow_state == FLOW_STATE_CAPTURE_BYPASSED ||
654#endif
656 return true;
657 }
658 return false;
659}
660
661int FlowClearMemory(Flow *,uint8_t );
662
663AppProto FlowGetAppProtocol(const Flow *f);
664void *FlowGetAppState(const Flow *f);
665uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags);
666
668
669#endif /* SURICATA_FLOW_H */
uint16_t AppProto
uint8_t flags
Definition decode-gre.h:0
#define VLAN_MAX_LAYERS
Definition decode-vlan.h:51
uint16_t Port
Definition decode.h:218
uint32_t id
void FlowSetHasAlertsFlag(Flow *)
Set flag to indicate that flow has alerts.
Definition flow.c:153
void FlowHandlePacket(ThreadVars *, FlowLookupStruct *, Packet *)
Entry point for packet flow handling.
Definition flow.c:533
#define FLOW_NOPAYLOAD_INSPECTION
Definition flow.h:67
FlowState
Definition flow.h:503
@ FLOW_STATE_LOCAL_BYPASSED
Definition flow.h:507
@ FLOW_STATE_NEW
Definition flow.h:504
@ FLOW_STATE_CLOSED
Definition flow.h:506
@ FLOW_STATE_ESTABLISHED
Definition flow.h:505
void FlowSetupPacket(Packet *p)
prepare packet for a life with flow Set PKT_WANTS_FLOW flag to indicate workers should do a flow look...
Definition flow-hash.c:533
enum ExceptionPolicy FlowGetMemcapExceptionPolicy(void)
Definition flow.c:134
unsigned short FlowStateType
Definition flow.h:330
struct FlowLookupStruct_ FlowLookupStruct
int FlowHasAlerts(const Flow *)
Check if flow has alerts.
Definition flow.c:164
void FlowRegisterTests(void)
Function to register the Flow Unitests.
Definition flow.c:1445
void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs)
Get flow last time as individual values.
Definition flow.c:1193
struct FlowProtoTimeout_ FlowProtoTimeout
void FlowUnsetChangeProtoFlag(Flow *)
Unset flag to indicate to change proto for the flow.
Definition flow.c:186
void FlowCleanupAppLayer(Flow *)
Definition flow.c:139
int FlowGetPacketDirection(const Flow *, const Packet *)
determine the direction of the packet compared to the flow
Definition flow.c:279
int FlowSetMemcap(uint64_t size)
Update memcap value.
Definition flow.c:107
struct FlowBypassInfo_ FlowBypassInfo
uint64_t FlowGetMemuse(void)
Definition flow.c:128
uint16_t FlowGetSourcePort(Flow *flow)
Get flow source port.
Definition flow.c:1205
struct FlowCnf_ FlowConfig
struct FlowAddress_ FlowAddress
void FlowShutdown(void)
shutdown the flow engine
Definition flow.c:691
uint16_t FlowThreadId
Definition flow.h:333
uint32_t FlowGetFlags(Flow *flow)
Get flow flags.
Definition flow.c:1228
uint64_t FlowGetMemcap(void)
Return memcap value.
Definition flow.c:122
struct Flow_ Flow
Flow data structure.
int FlowChangeProto(Flow *)
Check if change proto flag is set for flow.
Definition flow.c:196
struct FlowKey_ FlowKey
void FlowSetChangeProtoFlag(Flow *)
Set flag to indicate to change proto for the flow.
Definition flow.c:177
struct FlowProtoFreeFunc_ FlowProtoFreeFunc
void RegisterFlowBypassInfo(void)
Definition flow-util.c:240
int FlowClearMemory(Flow *, uint8_t)
Function clear the flow memory before queueing it to spare flow queue.
Definition flow.c:1097
uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
get 'disruption' flags: GAP/DEPTH/PASS
Definition flow.c:1141
void FlowInitConfig(bool)
initialize the configuration
Definition flow.c:547
void FlowReset(void)
Definition flow.c:673
FlowStorageId GetFlowBypassInfoID(void)
Definition flow-util.c:222
void FlowUpdateState(Flow *f, enum FlowState s)
Definition flow.c:1162
void FlowHandlePacketUpdate(Flow *f, Packet *p, ThreadVars *tv, DecodeThreadVars *dtv)
Update Packet and Flow.
Definition flow.c:402
uint16_t FlowGetDestinationPort(Flow *flow)
Get flow destination port.
Definition flow.c:1217
int FlowSetProtoFreeFunc(uint8_t, void(*Free)(void *))
Function to set the function to get protocol specific flow state.
Definition flow.c:1125
void FlowSwap(Flow *)
swap the flow's direction
Definition flow.c:246
DecodeThreadVars * dtv
ThreadVars * tv
Structure to hold thread specific data for all decode modules.
Definition decode.h:963
uint8_t address_un_data8[16]
Definition flow.h:322
uint16_t address_un_data16[8]
Definition flow.h:321
uint32_t address_un_data32[4]
Definition flow.h:320
union FlowAddress_::@128 address
void(* BypassFree)(void *data)
Definition flow.h:531
void * bypass_data
Definition flow.h:532
uint64_t tosrcpktcnt
Definition flow.h:533
uint64_t tosrcbytecnt
Definition flow.h:534
uint64_t todstpktcnt
Definition flow.h:535
bool(* BypassUpdate)(Flow *f, void *data, time_t tsec)
Definition flow.h:530
uint64_t todstbytecnt
Definition flow.h:536
enum ExceptionPolicy memcap_policy
Definition flow.h:302
uint32_t hash_rand
Definition flow.h:293
uint32_t prealloc
Definition flow.h:295
uint32_t emergency_recovery
Definition flow.h:300
uint32_t hash_size
Definition flow.h:294
uint32_t timeout_new
Definition flow.h:297
uint32_t timeout_est
Definition flow.h:298
SC_ATOMIC_DECLARE(uint64_t, memcap)
Port sp
Definition flow.h:311
uint8_t recursion_level
Definition flow.h:313
uint16_t vlan_id[VLAN_MAX_LAYERS]
Definition flow.h:315
Address dst
Definition flow.h:310
Port dp
Definition flow.h:311
uint16_t livedev_id
Definition flow.h:314
uint8_t proto
Definition flow.h:312
Address src
Definition flow.h:310
FlowQueuePrivate spare_queue
Definition flow.h:544
DecodeThreadVars * dtv
Definition flow.h:545
FlowQueuePrivate work_queue
Definition flow.h:546
uint32_t emerg_spare_sync_stamp
Definition flow.h:547
void(* Freefunc)(void *)
Definition flow.h:526
uint32_t bypassed_timeout
Definition flow.h:522
uint32_t est_timeout
Definition flow.h:520
uint32_t closed_timeout
Definition flow.h:521
uint32_t new_timeout
Definition flow.h:519
Flow data structure.
Definition flow.h:356
uint8_t applied_exception_policy
Definition flow.h:473
struct Flow_::@129::@135 icmp_s
uint8_t ffr_tc
Definition flow.h:388
AppProto alproto_ts
Definition flow.h:451
const struct SigGroupHead_ * sgh_toclient
Definition flow.h:483
Port dp
Definition flow.h:372
uint8_t max_ttl_toclient
Definition flow.h:470
AppProto alproto_tc
Definition flow.h:452
uint8_t proto
Definition flow.h:378
uint32_t flow_hash
Definition flow.h:401
uint32_t flags
Definition flow.h:421
uint8_t min_ttl_toserver
Definition flow.h:467
GenericVar * flowvar
Definition flow.h:489
uint8_t ffr_ts
Definition flow.h:387
uint32_t de_ctx_version
Definition flow.h:464
uint8_t max_ttl_toserver
Definition flow.h:468
AppProto alproto_expect
Definition flow.h:459
uint8_t flow_end_flags
Definition flow.h:447
uint16_t file_flags
Definition flow.h:423
AppProto alproto
application level protocol
Definition flow.h:450
void * alstate
Definition flow.h:479
FlowStateType flow_state
Definition flow.h:412
uint32_t tenant_id
Definition flow.h:416
uint32_t probing_parser_toclient_alproto_masks
Definition flow.h:419
uint8_t min_ttl_toclient
Definition flow.h:469
uint32_t timeout_policy
Definition flow.h:405
uint64_t tosrcbytecnt
Definition flow.h:498
uint16_t protodetect_dp
Definition flow.h:427
const struct SigGroupHead_ * sgh_toserver
Definition flow.h:486
SCMutex m
Definition flow.h:435
AppProto alproto_orig
Definition flow.h:456
uint8_t vlan_idx
Definition flow.h:382
void * protoctx
Definition flow.h:441
uint16_t vlan_id[VLAN_MAX_LAYERS]
Definition flow.h:380
uint64_t todstbytecnt
Definition flow.h:497
AppLayerParserState * alparser
Definition flow.h:478
SCTime_t lastts
Definition flow.h:410
struct LiveDevice_ * livedev
Definition flow.h:398
uint8_t protomap
Definition flow.h:445
struct Flow_::@131::@137 icmp_d
uint8_t code
Definition flow.h:364
struct Flow_::@129::@136 esp
uint32_t todstpktcnt
Definition flow.h:495
uint32_t probing_parser_toserver_alproto_masks
Definition flow.h:418
struct FlowBucket_ * fb
Definition flow.h:491
FlowThreadId thread_id[2]
Definition flow.h:394
Storage storage[]
Definition flow.h:500
uint32_t spi
Definition flow.h:368
FlowAddress src
Definition flow.h:359
struct Flow_ * next
Definition flow.h:396
Port sp
Definition flow.h:361
uint8_t recursion_level
Definition flow.h:379
uint8_t ffr
Definition flow.h:390
int64_t parent_id
Definition flow.h:430
FlowAddress dst
Definition flow.h:359
uint32_t tosrcpktcnt
Definition flow.h:496
uint8_t type
Definition flow.h:363
SCTime_t startts
Definition flow.h:493
Container for matching data for a signature group.
Definition detect.h:1629
Per thread variable structure.
Definition threadvars.h:58
#define SCRWLock
#define SCMutex
#define SCEnter(...)
Definition util-debug.h:277
#define SCLogDebug(...)
Definition util-debug.h:275
#define SCReturn
Definition util-debug.h:279
#define likely(expr)
#define SCTIME_SECS(t)
Definition util-time.h:57
#define SCTIME_USECS(t)
Definition util-time.h:56
#define DEBUG_VALIDATE_BUG_ON(exp)