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_TOSERVER_IPONLY_SET BIT_U32(3)
61 #define FLOW_TOCLIENT_IPONLY_SET BIT_U32(4)
64 #define FLOW_NOPACKET_INSPECTION 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)
148 #define FLOWFILE_NO_SIZE_TS BIT_U16(10)
149 #define FLOWFILE_NO_SIZE_TC BIT_U16(11)
152 #define FLOWFILE_STORE_TS BIT_U16(12)
153 #define FLOWFILE_STORE_TC BIT_U16(13)
155 #define FLOWFILE_NONE_TS (FLOWFILE_NO_MAGIC_TS | \
156 FLOWFILE_NO_STORE_TS | \
157 FLOWFILE_NO_MD5_TS | \
158 FLOWFILE_NO_SHA1_TS | \
159 FLOWFILE_NO_SHA256_TS| \
161 #define FLOWFILE_NONE_TC (FLOWFILE_NO_MAGIC_TC | \
162 FLOWFILE_NO_STORE_TC | \
163 FLOWFILE_NO_MD5_TC | \
164 FLOWFILE_NO_SHA1_TC | \
165 FLOWFILE_NO_SHA256_TC| \
167 #define FLOWFILE_NONE (FLOWFILE_NONE_TS|FLOWFILE_NONE_TC)
169 #define FLOW_IS_IPV4(f) \
170 (((f)->flags & FLOW_IPV4) == FLOW_IPV4)
171 #define FLOW_IS_IPV6(f) \
172 (((f)->flags & FLOW_IPV6) == FLOW_IPV6)
174 #define FLOW_GET_SP(f) \
175 ((f)->flags & FLOW_DIR_REVERSED) ? (f)->dp : (f)->sp;
176 #define FLOW_GET_DP(f) \
177 ((f)->flags & FLOW_DIR_REVERSED) ? (f)->sp : (f)->dp;
179 #define FLOW_COPY_IPV4_ADDR_TO_PACKET(fa, pa) do { \
180 (pa)->family = AF_INET; \
181 (pa)->addr_data32[0] = (fa)->addr_data32[0]; \
184 #define FLOW_COPY_IPV6_ADDR_TO_PACKET(fa, pa) do { \
185 (pa)->family = AF_INET6; \
186 (pa)->addr_data32[0] = (fa)->addr_data32[0]; \
187 (pa)->addr_data32[1] = (fa)->addr_data32[1]; \
188 (pa)->addr_data32[2] = (fa)->addr_data32[2]; \
189 (pa)->addr_data32[3] = (fa)->addr_data32[3]; \
197 #define FLOW_SET_IPV4_SRC_ADDR_FROM_PACKET(ip4h, a) \
199 (a)->addr_data32[0] = (uint32_t)(ip4h)->s_ip_src.s_addr; \
200 (a)->addr_data32[1] = 0; \
201 (a)->addr_data32[2] = 0; \
202 (a)->addr_data32[3] = 0; \
205 #define FLOW_SET_IPV4_DST_ADDR_FROM_PACKET(ip4h, a) \
207 (a)->addr_data32[0] = (uint32_t)(ip4h)->s_ip_dst.s_addr; \
208 (a)->addr_data32[1] = 0; \
209 (a)->addr_data32[2] = 0; \
210 (a)->addr_data32[3] = 0; \
215 #define FLOW_SET_IPV6_SRC_ADDR_FROM_PACKET(ip6h, a) \
217 (a)->addr_data32[0] = (ip6h)->s_ip6_src[0]; \
218 (a)->addr_data32[1] = (ip6h)->s_ip6_src[1]; \
219 (a)->addr_data32[2] = (ip6h)->s_ip6_src[2]; \
220 (a)->addr_data32[3] = (ip6h)->s_ip6_src[3]; \
223 #define FLOW_SET_IPV6_DST_ADDR_FROM_PACKET(ip6h, a) \
225 (a)->addr_data32[0] = (ip6h)->s_ip6_dst[0]; \
226 (a)->addr_data32[1] = (ip6h)->s_ip6_dst[1]; \
227 (a)->addr_data32[2] = (ip6h)->s_ip6_dst[2]; \
228 (a)->addr_data32[3] = (ip6h)->s_ip6_dst[3]; \
232 #define FLOW_PKT_TOSERVER 0x01
233 #define FLOW_PKT_TOCLIENT 0x02
234 #define FLOW_PKT_ESTABLISHED 0x04
235 #define FLOW_PKT_TOSERVER_IPONLY_SET 0x08
236 #define FLOW_PKT_TOCLIENT_IPONLY_SET 0x10
237 #define FLOW_PKT_TOSERVER_FIRST 0x20
238 #define FLOW_PKT_TOCLIENT_FIRST 0x40
241 #define FLOW_PKT_LAST_PSEUDO 0x80
243 #define FLOW_END_FLAG_EMERGENCY 0x01
244 #define FLOW_END_FLAG_TIMEOUT 0x02
245 #define FLOW_END_FLAG_FORCED 0x04
246 #define FLOW_END_FLAG_SHUTDOWN 0x08
250 #define FLOWLOCK_MUTEX
252 #ifdef FLOWLOCK_RWLOCK
253 #ifdef FLOWLOCK_MUTEX
254 #error Cannot enable both FLOWLOCK_RWLOCK and FLOWLOCK_MUTEX
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)
275 #error Enable FLOWLOCK_RWLOCK or FLOWLOCK_MUTEX
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))
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))
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))
326 #define addr_data32 address.address_un_data32
327 #define addr_data16 address.address_un_data16
328 #define addr_data8 address.address_un_data8
437 #ifdef FLOWLOCK_RWLOCK
439 #elif defined FLOWLOCK_MUTEX
442 #error Enable FLOWLOCK_RWLOCK or FLOWLOCK_MUTEX
510 #ifdef CAPTURE_OFFLOAD
511 FLOW_STATE_CAPTURE_BYPASSED,
514 #ifdef CAPTURE_OFFLOAD
515 #define FLOW_STATE_SIZE 5
517 #define FLOW_STATE_SIZE 4
572 static inline void FlowSetNoPacketInspectionFlag(
Flow *);
573 static inline void FlowSetNoPayloadInspectionFlag(
Flow *);
596 static inline AppProto FlowGetAppProtocol(
const Flow *f)
601 static inline void *FlowGetAppState(
const Flow *f)
610 static inline void FlowSetNoPacketInspectionFlag(
Flow *f)
624 static inline void FlowSetNoPayloadInspectionFlag(
Flow *f)
637 static inline void FlowReference(
Flow **d,
Flow *f)
647 static inline void FlowDeReference(
Flow **d)
659 static inline int64_t FlowGetId(
const Flow *f)
665 id &= 0x7ffffffffffffLL;
669 static inline bool FlowIsBypassed(
const Flow *f)
672 #ifdef CAPTURE_OFFLOAD
673 f->
flow_state == FLOW_STATE_CAPTURE_BYPASSED ||
684 void *FlowGetAppState(
const Flow *f);
FlowQueuePrivate work_queue
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
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
struct Flow_::@116::@122 icmp_d
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.
struct Flow_::@114::@120 icmp_s
const struct SigGroupHead_ * sgh_toserver
uint32_t emerg_spare_sync_stamp
struct FlowCnf_ FlowConfig
AppLayerParserState * alparser
struct FlowProtoFreeFunc_ FlowProtoFreeFunc
struct Flow_::@114::@121 esp
@ FLOW_STATE_LOCAL_BYPASSED
uint16_t FlowGetDestinationPort(Flow *flow)
Get flow destination port.
void RegisterFlowBypassInfo(void)
bool(* BypassUpdate)(Flow *f, void *data, time_t tsec)
void(* BypassFree)(void *data)
void FlowSetIPOnlyFlag(Flow *, int)
Set the IPOnly scanned flag for 'direction'.
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
void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs)
Get flow last time as individual values.
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.
uint32_t FlowGetFlags(Flow *flow)
Get flow flags.
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
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]
#define FLOW_NOPACKET_INSPECTION
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)
#define DEBUG_VALIDATE_BUG_ON(exp)
int FlowSetProtoFreeFunc(uint8_t, void(*Free)(void *))
Function to set the function to get protocol specific flow state.
union FlowAddress_::@113 address
void FlowSetHasAlertsFlag(Flow *)
Set flag to indicate that flow has alerts.
uint16_t FlowGetSourcePort(Flow *flow)
Get flow source port.
FlowThreadId thread_id[2]
int FlowHasAlerts(const Flow *)
Check if flow has alerts.