Go to the documentation of this file.
24 #ifndef SURICATA_FLOW_H
25 #define SURICATA_FLOW_H
43 #define FLOW_QUIET true
51 #define FLOW_TO_SRC_SEEN BIT_U32(0)
53 #define FLOW_TO_DST_SEEN BIT_U32(1)
56 #define FLOW_TC_APP_UPDATE_NEXT BIT_U32(2)
59 #define FLOW_IS_ELEPHANT_TOSERVER BIT_U32(3)
60 #define FLOW_IS_ELEPHANT_TOCLIENT BIT_U32(4)
63 #define FLOW_ACTION_ACCEPT BIT_U32(5)
66 #define FLOW_NOPAYLOAD_INSPECTION BIT_U32(6)
69 #define FLOW_ACTION_DROP BIT_U32(7)
72 #define FLOW_SGH_TOSERVER BIT_U32(8)
74 #define FLOW_SGH_TOCLIENT BIT_U32(9)
77 #define FLOW_TOSERVER_DROP_LOGGED BIT_U32(10)
79 #define FLOW_TOCLIENT_DROP_LOGGED BIT_U32(11)
82 #define FLOW_HAS_ALERTS BIT_U32(12)
85 #define FLOW_TS_PM_ALPROTO_DETECT_DONE BIT_U32(13)
87 #define FLOW_TS_PP_ALPROTO_DETECT_DONE BIT_U32(14)
89 #define FLOW_TS_PE_ALPROTO_DETECT_DONE BIT_U32(15)
91 #define FLOW_TC_PM_ALPROTO_DETECT_DONE BIT_U32(16)
93 #define FLOW_TC_PP_ALPROTO_DETECT_DONE BIT_U32(17)
95 #define FLOW_TC_PE_ALPROTO_DETECT_DONE BIT_U32(18)
96 #define FLOW_TIMEOUT_REASSEMBLY_DONE BIT_U32(19)
99 #define FLOW_IPV4 BIT_U32(20)
101 #define FLOW_IPV6 BIT_U32(21)
103 #define FLOW_PROTO_DETECT_TS_DONE BIT_U32(22)
104 #define FLOW_PROTO_DETECT_TC_DONE BIT_U32(23)
107 #define FLOW_CHANGE_PROTO BIT_U32(24)
109 #define FLOW_WRONG_THREAD BIT_U32(25)
111 #define FLOW_DIR_REVERSED BIT_U32(26)
113 #define FLOW_HAS_EXPECTATION BIT_U32(27)
116 #define FLOW_ACTION_PASS BIT_U32(28)
118 #define FLOW_TS_APP_UPDATED BIT_U32(29)
119 #define FLOW_TC_APP_UPDATED BIT_U32(30)
122 #define FLOW_TS_APP_UPDATE_NEXT BIT_U32(31)
126 #define FLOWFILE_INIT 0
129 #define FLOWFILE_NO_MAGIC_TS BIT_U16(0)
130 #define FLOWFILE_NO_MAGIC_TC BIT_U16(1)
133 #define FLOWFILE_NO_STORE_TS BIT_U16(2)
134 #define FLOWFILE_NO_STORE_TC BIT_U16(3)
136 #define FLOWFILE_NO_MD5_TS BIT_U16(4)
137 #define FLOWFILE_NO_MD5_TC BIT_U16(5)
140 #define FLOWFILE_NO_SHA1_TS BIT_U16(6)
141 #define FLOWFILE_NO_SHA1_TC BIT_U16(7)
144 #define FLOWFILE_NO_SHA256_TS BIT_U16(8)
145 #define FLOWFILE_NO_SHA256_TC BIT_U16(9)
150 #define FLOWFILE_STORE_TS BIT_U16(12)
151 #define FLOWFILE_STORE_TC BIT_U16(13)
153 #define FLOWFILE_NONE_TS \
154 (FLOWFILE_NO_MAGIC_TS | FLOWFILE_NO_STORE_TS | FLOWFILE_NO_MD5_TS | FLOWFILE_NO_SHA1_TS | \
155 FLOWFILE_NO_SHA256_TS)
156 #define FLOWFILE_NONE_TC \
157 (FLOWFILE_NO_MAGIC_TC | FLOWFILE_NO_STORE_TC | FLOWFILE_NO_MD5_TC | FLOWFILE_NO_SHA1_TC | \
158 FLOWFILE_NO_SHA256_TC)
159 #define FLOWFILE_NONE (FLOWFILE_NONE_TS|FLOWFILE_NONE_TC)
161 #define FLOW_IS_IPV4(f) \
162 (((f)->flags & FLOW_IPV4) == FLOW_IPV4)
163 #define FLOW_IS_IPV6(f) \
164 (((f)->flags & FLOW_IPV6) == FLOW_IPV6)
166 #define FLOW_GET_SP(f) \
167 ((f)->flags & FLOW_DIR_REVERSED) ? (f)->dp : (f)->sp;
168 #define FLOW_GET_DP(f) \
169 ((f)->flags & FLOW_DIR_REVERSED) ? (f)->sp : (f)->dp;
171 #define FLOW_COPY_IPV4_ADDR_TO_PACKET(fa, pa) do { \
172 (pa)->family = AF_INET; \
173 (pa)->addr_data32[0] = (fa)->addr_data32[0]; \
176 #define FLOW_COPY_IPV6_ADDR_TO_PACKET(fa, pa) do { \
177 (pa)->family = AF_INET6; \
178 (pa)->addr_data32[0] = (fa)->addr_data32[0]; \
179 (pa)->addr_data32[1] = (fa)->addr_data32[1]; \
180 (pa)->addr_data32[2] = (fa)->addr_data32[2]; \
181 (pa)->addr_data32[3] = (fa)->addr_data32[3]; \
189 #define FLOW_SET_IPV4_SRC_ADDR_FROM_PACKET(ip4h, a) \
191 (a)->addr_data32[0] = (uint32_t)(ip4h)->s_ip_src.s_addr; \
192 (a)->addr_data32[1] = 0; \
193 (a)->addr_data32[2] = 0; \
194 (a)->addr_data32[3] = 0; \
197 #define FLOW_SET_IPV4_DST_ADDR_FROM_PACKET(ip4h, a) \
199 (a)->addr_data32[0] = (uint32_t)(ip4h)->s_ip_dst.s_addr; \
200 (a)->addr_data32[1] = 0; \
201 (a)->addr_data32[2] = 0; \
202 (a)->addr_data32[3] = 0; \
207 #define FLOW_SET_IPV6_SRC_ADDR_FROM_PACKET(ip6h, a) \
209 (a)->addr_data32[0] = (ip6h)->s_ip6_src[0]; \
210 (a)->addr_data32[1] = (ip6h)->s_ip6_src[1]; \
211 (a)->addr_data32[2] = (ip6h)->s_ip6_src[2]; \
212 (a)->addr_data32[3] = (ip6h)->s_ip6_src[3]; \
215 #define FLOW_SET_IPV6_DST_ADDR_FROM_PACKET(ip6h, a) \
217 (a)->addr_data32[0] = (ip6h)->s_ip6_dst[0]; \
218 (a)->addr_data32[1] = (ip6h)->s_ip6_dst[1]; \
219 (a)->addr_data32[2] = (ip6h)->s_ip6_dst[2]; \
220 (a)->addr_data32[3] = (ip6h)->s_ip6_dst[3]; \
224 #define FLOW_PKT_TOSERVER 0x01
225 #define FLOW_PKT_TOCLIENT 0x02
226 #define FLOW_PKT_ESTABLISHED 0x04
227 #define FLOW_PKT_TOSERVER_FIRST 0x08
228 #define FLOW_PKT_TOCLIENT_FIRST 0x10
231 #define FLOW_PKT_LAST_PSEUDO 0x20
233 #define FLOW_END_FLAG_EMERGENCY 0x01
234 #define FLOW_END_FLAG_TIMEOUT 0x02
235 #define FLOW_END_FLAG_FORCED 0x04
236 #define FLOW_END_FLAG_SHUTDOWN 0x08
237 #define FLOW_END_FLAG_TCPREUSE 0x10
241 #define FLOWLOCK_MUTEX
243 #ifdef FLOWLOCK_RWLOCK
244 #ifdef FLOWLOCK_MUTEX
245 #error Cannot enable both FLOWLOCK_RWLOCK and FLOWLOCK_MUTEX
249 #ifdef FLOWLOCK_RWLOCK
250 #define FLOWLOCK_INIT(fb) SCRWLockInit(&(fb)->r, NULL)
251 #define FLOWLOCK_DESTROY(fb) SCRWLockDestroy(&(fb)->r)
252 #define FLOWLOCK_RDLOCK(fb) SCRWLockRDLock(&(fb)->r)
253 #define FLOWLOCK_WRLOCK(fb) SCRWLockWRLock(&(fb)->r)
254 #define FLOWLOCK_TRYRDLOCK(fb) SCRWLockTryRDLock(&(fb)->r)
255 #define FLOWLOCK_TRYWRLOCK(fb) SCRWLockTryWRLock(&(fb)->r)
256 #define FLOWLOCK_UNLOCK(fb) SCRWLockUnlock(&(fb)->r)
257 #elif defined FLOWLOCK_MUTEX
258 #define FLOWLOCK_INIT(fb) SCMutexInit(&(fb)->m, NULL)
259 #define FLOWLOCK_DESTROY(fb) SCMutexDestroy(&(fb)->m)
260 #define FLOWLOCK_RDLOCK(fb) SCMutexLock(&(fb)->m)
261 #define FLOWLOCK_WRLOCK(fb) SCMutexLock(&(fb)->m)
262 #define FLOWLOCK_TRYRDLOCK(fb) SCMutexTrylock(&(fb)->m)
263 #define FLOWLOCK_TRYWRLOCK(fb) SCMutexTrylock(&(fb)->m)
264 #define FLOWLOCK_UNLOCK(fb) SCMutexUnlock(&(fb)->m)
266 #error Enable FLOWLOCK_RWLOCK or FLOWLOCK_MUTEX
269 #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))
270 #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))
271 #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))
273 #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))
274 #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))
275 #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))
277 #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))
278 #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))
279 #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))
317 #define addr_data32 address.address_un_data32
318 #define addr_data16 address.address_un_data16
319 #define addr_data8 address.address_un_data8
423 #ifdef FLOWLOCK_RWLOCK
425 #elif defined FLOWLOCK_MUTEX
428 #error Enable FLOWLOCK_RWLOCK or FLOWLOCK_MUTEX
499 #ifdef CAPTURE_OFFLOAD
500 FLOW_STATE_CAPTURE_BYPASSED,
503 #ifdef CAPTURE_OFFLOAD
504 #define FLOW_STATE_SIZE 5
506 #define FLOW_STATE_SIZE 4
560 static inline void FlowSetNoPayloadInspectionFlag(
Flow *);
578 static inline AppProto FlowGetAppProtocol(
const Flow *f)
583 static inline void *FlowGetAppState(
const Flow *f)
592 static inline void FlowSetNoPayloadInspectionFlag(
Flow *f)
605 static inline void FlowReference(
Flow **d,
Flow *f)
615 static inline void FlowDeReference(
Flow **d)
625 static inline uint64_t FlowGetId(
const Flow *f)
631 id &= 0x7ffffffffffffLL;
635 static inline bool FlowIsBypassed(
const Flow *f)
638 #ifdef CAPTURE_OFFLOAD
639 f->
flow_state == FLOW_STATE_CAPTURE_BYPASSED ||
650 void *FlowGetAppState(
const Flow *f);
FlowQueuePrivate work_queue
struct Flow_::@124::@130 icmp_d
int FlowSetMemcap(uint64_t size)
Update memcap value.
uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
get 'disruption' flags: GAP/DEPTH/PASS
Container for matching data for a signature group.
uint32_t emergency_recovery
struct Flow_::@122::@128 icmp_s
void FlowHandlePacket(ThreadVars *, FlowLookupStruct *, Packet *)
Entry point for packet flow handling.
uint32_t address_un_data32[4]
struct FlowLookupStruct_ FlowLookupStruct
void FlowInitConfig(bool)
initialize the configuration
int FlowGetPacketDirection(const Flow *, const Packet *)
determine the direction of the packet compared to the flow
int FlowClearMemory(Flow *, uint8_t)
Function clear the flow memory before queueing it to spare flow queue.
#define FLOW_NOPAYLOAD_INSPECTION
struct Flow_ Flow
Flow data structure.
uint32_t bypassed_timeout
void FlowSetupPacket(Packet *p)
prepare packet for a life with flow Set PKT_WANTS_FLOW flag to indicate workers should do a flow look...
void FlowUnsetChangeProtoFlag(Flow *)
Unset flag to indicate to change proto for the flow.
const struct SigGroupHead_ * sgh_toserver
uint32_t emerg_spare_sync_stamp
struct FlowCnf_ FlowConfig
AppLayerParserState * alparser
struct FlowProtoFreeFunc_ FlowProtoFreeFunc
@ FLOW_STATE_LOCAL_BYPASSED
struct Flow_::@122::@129 esp
void RegisterFlowBypassInfo(void)
bool(* BypassUpdate)(Flow *f, void *data, time_t tsec)
void(* BypassFree)(void *data)
void FlowSwap(Flow *)
swap the flow's direction
Per thread variable structure.
void FlowShutdown(void)
shutdown the flow engine
uint64_t FlowGetMemuse(void)
struct FlowBypassInfo_ FlowBypassInfo
const struct SigGroupHead_ * sgh_toclient
int FlowChangeProto(Flow *)
Check if change proto flag is set for flow.
void FlowRegisterTests(void)
Function to register the Flow Unitests.
uint16_t address_un_data16[8]
void FlowHandlePacketUpdate(Flow *f, Packet *p, ThreadVars *tv, DecodeThreadVars *dtv)
Update Packet and Flow.
void FlowCleanupAppLayer(Flow *)
uint32_t probing_parser_toclient_alproto_masks
SC_ATOMIC_DECLARE(uint64_t, memcap)
FlowStorageId GetFlowBypassInfoID(void)
uint32_t probing_parser_toserver_alproto_masks
FlowQueuePrivate spare_queue
struct FlowProtoTimeout_ FlowProtoTimeout
unsigned short FlowStateType
uint8_t applied_exception_policy
struct FlowAddress_ FlowAddress
enum ExceptionPolicy FlowGetMemcapExceptionPolicy(void)
struct LiveDevice_ * livedev
enum ExceptionPolicy memcap_policy
uint8_t address_un_data8[16]
Structure to hold thread specific data for all decode modules.
uint64_t FlowGetMemcap(void)
Return memcap value.
uint16_t vlan_id[VLAN_MAX_LAYERS]
uint16_t vlan_id[VLAN_MAX_LAYERS]
void FlowSetChangeProtoFlag(Flow *)
Set flag to indicate to change proto for the flow.
AppProto alproto
application level protocol
void FlowUpdateState(Flow *f, enum FlowState s)
union FlowAddress_::@121 address
#define DEBUG_VALIDATE_BUG_ON(exp)
int FlowSetProtoFreeFunc(uint8_t, void(*Free)(void *))
Function to set the function to get protocol specific flow state.
void FlowSetHasAlertsFlag(Flow *)
Set flag to indicate that flow has alerts.
FlowThreadId thread_id[2]
int FlowHasAlerts(const Flow *)
Check if flow has alerts.