Go to the documentation of this file.
41 #define FLOW_QUIET true
49 #define FLOW_TO_SRC_SEEN BIT_U32(0)
51 #define FLOW_TO_DST_SEEN BIT_U32(1)
56 #define FLOW_TOSERVER_IPONLY_SET BIT_U32(3)
58 #define FLOW_TOCLIENT_IPONLY_SET BIT_U32(4)
61 #define FLOW_NOPACKET_INSPECTION BIT_U32(5)
63 #define FLOW_NOPAYLOAD_INSPECTION BIT_U32(6)
66 #define FLOW_ACTION_DROP BIT_U32(7)
69 #define FLOW_SGH_TOSERVER BIT_U32(8)
71 #define FLOW_SGH_TOCLIENT BIT_U32(9)
74 #define FLOW_TOSERVER_DROP_LOGGED BIT_U32(10)
76 #define FLOW_TOCLIENT_DROP_LOGGED BIT_U32(11)
79 #define FLOW_HAS_ALERTS BIT_U32(12)
82 #define FLOW_TS_PM_ALPROTO_DETECT_DONE BIT_U32(13)
84 #define FLOW_TS_PP_ALPROTO_DETECT_DONE BIT_U32(14)
86 #define FLOW_TS_PE_ALPROTO_DETECT_DONE BIT_U32(15)
88 #define FLOW_TC_PM_ALPROTO_DETECT_DONE BIT_U32(16)
90 #define FLOW_TC_PP_ALPROTO_DETECT_DONE BIT_U32(17)
92 #define FLOW_TC_PE_ALPROTO_DETECT_DONE BIT_U32(18)
93 #define FLOW_TIMEOUT_REASSEMBLY_DONE BIT_U32(19)
96 #define FLOW_IPV4 BIT_U32(20)
98 #define FLOW_IPV6 BIT_U32(21)
100 #define FLOW_PROTO_DETECT_TS_DONE BIT_U32(22)
101 #define FLOW_PROTO_DETECT_TC_DONE BIT_U32(23)
104 #define FLOW_CHANGE_PROTO BIT_U32(24)
106 #define FLOW_WRONG_THREAD BIT_U32(25)
108 #define FLOW_DIR_REVERSED BIT_U32(26)
110 #define FLOW_HAS_EXPECTATION BIT_U32(27)
113 #define FLOW_ACTION_PASS BIT_U32(28)
115 #define FLOW_TS_APP_UPDATED BIT_U32(29)
116 #define FLOW_TC_APP_UPDATED BIT_U32(30)
120 #define FLOWFILE_INIT 0
123 #define FLOWFILE_NO_MAGIC_TS BIT_U16(0)
124 #define FLOWFILE_NO_MAGIC_TC BIT_U16(1)
127 #define FLOWFILE_NO_STORE_TS BIT_U16(2)
128 #define FLOWFILE_NO_STORE_TC BIT_U16(3)
130 #define FLOWFILE_NO_MD5_TS BIT_U16(4)
131 #define FLOWFILE_NO_MD5_TC BIT_U16(5)
134 #define FLOWFILE_NO_SHA1_TS BIT_U16(6)
135 #define FLOWFILE_NO_SHA1_TC BIT_U16(7)
138 #define FLOWFILE_NO_SHA256_TS BIT_U16(8)
139 #define FLOWFILE_NO_SHA256_TC BIT_U16(9)
142 #define FLOWFILE_NO_SIZE_TS BIT_U16(10)
143 #define FLOWFILE_NO_SIZE_TC BIT_U16(11)
146 #define FLOWFILE_STORE BIT_U16(12)
148 #define FLOWFILE_NONE_TS (FLOWFILE_NO_MAGIC_TS | \
149 FLOWFILE_NO_STORE_TS | \
150 FLOWFILE_NO_MD5_TS | \
151 FLOWFILE_NO_SHA1_TS | \
152 FLOWFILE_NO_SHA256_TS| \
154 #define FLOWFILE_NONE_TC (FLOWFILE_NO_MAGIC_TC | \
155 FLOWFILE_NO_STORE_TC | \
156 FLOWFILE_NO_MD5_TC | \
157 FLOWFILE_NO_SHA1_TC | \
158 FLOWFILE_NO_SHA256_TC| \
160 #define FLOWFILE_NONE (FLOWFILE_NONE_TS|FLOWFILE_NONE_TC)
162 #define FLOW_IS_IPV4(f) \
163 (((f)->flags & FLOW_IPV4) == FLOW_IPV4)
164 #define FLOW_IS_IPV6(f) \
165 (((f)->flags & FLOW_IPV6) == FLOW_IPV6)
167 #define FLOW_GET_SP(f) \
168 ((f)->flags & FLOW_DIR_REVERSED) ? (f)->dp : (f)->sp;
169 #define FLOW_GET_DP(f) \
170 ((f)->flags & FLOW_DIR_REVERSED) ? (f)->sp : (f)->dp;
172 #define FLOW_COPY_IPV4_ADDR_TO_PACKET(fa, pa) do { \
173 (pa)->family = AF_INET; \
174 (pa)->addr_data32[0] = (fa)->addr_data32[0]; \
177 #define FLOW_COPY_IPV6_ADDR_TO_PACKET(fa, pa) do { \
178 (pa)->family = AF_INET6; \
179 (pa)->addr_data32[0] = (fa)->addr_data32[0]; \
180 (pa)->addr_data32[1] = (fa)->addr_data32[1]; \
181 (pa)->addr_data32[2] = (fa)->addr_data32[2]; \
182 (pa)->addr_data32[3] = (fa)->addr_data32[3]; \
190 #define FLOW_SET_IPV4_SRC_ADDR_FROM_PACKET(p, a) do { \
191 (a)->addr_data32[0] = (uint32_t)(p)->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(p, a) do { \
198 (a)->addr_data32[0] = (uint32_t)(p)->ip4h->s_ip_dst.s_addr; \
199 (a)->addr_data32[1] = 0; \
200 (a)->addr_data32[2] = 0; \
201 (a)->addr_data32[3] = 0; \
206 #define FLOW_SET_IPV6_SRC_ADDR_FROM_PACKET(p, a) do { \
207 (a)->addr_data32[0] = (p)->ip6h->s_ip6_src[0]; \
208 (a)->addr_data32[1] = (p)->ip6h->s_ip6_src[1]; \
209 (a)->addr_data32[2] = (p)->ip6h->s_ip6_src[2]; \
210 (a)->addr_data32[3] = (p)->ip6h->s_ip6_src[3]; \
213 #define FLOW_SET_IPV6_DST_ADDR_FROM_PACKET(p, a) do { \
214 (a)->addr_data32[0] = (p)->ip6h->s_ip6_dst[0]; \
215 (a)->addr_data32[1] = (p)->ip6h->s_ip6_dst[1]; \
216 (a)->addr_data32[2] = (p)->ip6h->s_ip6_dst[2]; \
217 (a)->addr_data32[3] = (p)->ip6h->s_ip6_dst[3]; \
221 #define FLOW_PKT_TOSERVER 0x01
222 #define FLOW_PKT_TOCLIENT 0x02
223 #define FLOW_PKT_ESTABLISHED 0x04
224 #define FLOW_PKT_TOSERVER_IPONLY_SET 0x08
225 #define FLOW_PKT_TOCLIENT_IPONLY_SET 0x10
226 #define FLOW_PKT_TOSERVER_FIRST 0x20
227 #define FLOW_PKT_TOCLIENT_FIRST 0x40
230 #define FLOW_PKT_LAST_PSEUDO 0x80
232 #define FLOW_END_FLAG_STATE_NEW 0x01
233 #define FLOW_END_FLAG_STATE_ESTABLISHED 0x02
234 #define FLOW_END_FLAG_STATE_CLOSED 0x04
235 #define FLOW_END_FLAG_EMERGENCY 0x08
236 #define FLOW_END_FLAG_TIMEOUT 0x10
237 #define FLOW_END_FLAG_FORCED 0x20
238 #define FLOW_END_FLAG_SHUTDOWN 0x40
239 #define FLOW_END_FLAG_STATE_BYPASSED 0x80
243 #define FLOWLOCK_MUTEX
245 #ifdef FLOWLOCK_RWLOCK
246 #ifdef FLOWLOCK_MUTEX
247 #error Cannot enable both FLOWLOCK_RWLOCK and FLOWLOCK_MUTEX
251 #ifdef FLOWLOCK_RWLOCK
252 #define FLOWLOCK_INIT(fb) SCRWLockInit(&(fb)->r, NULL)
253 #define FLOWLOCK_DESTROY(fb) SCRWLockDestroy(&(fb)->r)
254 #define FLOWLOCK_RDLOCK(fb) SCRWLockRDLock(&(fb)->r)
255 #define FLOWLOCK_WRLOCK(fb) SCRWLockWRLock(&(fb)->r)
256 #define FLOWLOCK_TRYRDLOCK(fb) SCRWLockTryRDLock(&(fb)->r)
257 #define FLOWLOCK_TRYWRLOCK(fb) SCRWLockTryWRLock(&(fb)->r)
258 #define FLOWLOCK_UNLOCK(fb) SCRWLockUnlock(&(fb)->r)
259 #elif defined FLOWLOCK_MUTEX
260 #define FLOWLOCK_INIT(fb) SCMutexInit(&(fb)->m, NULL)
261 #define FLOWLOCK_DESTROY(fb) SCMutexDestroy(&(fb)->m)
262 #define FLOWLOCK_RDLOCK(fb) SCMutexLock(&(fb)->m)
263 #define FLOWLOCK_WRLOCK(fb) SCMutexLock(&(fb)->m)
264 #define FLOWLOCK_TRYRDLOCK(fb) SCMutexTrylock(&(fb)->m)
265 #define FLOWLOCK_TRYWRLOCK(fb) SCMutexTrylock(&(fb)->m)
266 #define FLOWLOCK_UNLOCK(fb) SCMutexUnlock(&(fb)->m)
268 #error Enable FLOWLOCK_RWLOCK or FLOWLOCK_MUTEX
271 #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))
272 #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))
273 #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))
275 #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))
276 #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))
277 #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))
279 #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))
280 #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))
281 #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))
319 #define addr_data32 address.address_un_data32
320 #define addr_data16 address.address_un_data16
321 #define addr_data8 address.address_un_data8
428 #ifdef FLOWLOCK_RWLOCK
430 #elif defined FLOWLOCK_MUTEX
433 #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
562 static inline void FlowSetNoPacketInspectionFlag(
Flow *);
563 static inline void FlowSetNoPayloadInspectionFlag(
Flow *);
585 static inline AppProto FlowGetAppProtocol(
const Flow *f)
590 static inline void *FlowGetAppState(
const Flow *f)
599 static inline void FlowSetNoPacketInspectionFlag(
Flow *f)
613 static inline void FlowSetNoPayloadInspectionFlag(
Flow *f)
626 static inline void FlowReference(
Flow **d,
Flow *f)
629 #ifdef DEBUG_VALIDATION
639 static inline void FlowDeReference(
Flow **d)
651 static inline int64_t FlowGetId(
const Flow *f)
657 id &= 0x7ffffffffffffLL;
661 static inline void FlowSetEndFlags(
Flow *f)
672 #ifdef CAPTURE_OFFLOAD
673 else if (state == FLOW_STATE_CAPTURE_BYPASSED)
678 static inline bool FlowIsBypassed(
const Flow *f)
681 #ifdef CAPTURE_OFFLOAD
682 f->
flow_state == FLOW_STATE_CAPTURE_BYPASSED ||
693 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.
#define FLOW_END_FLAG_STATE_NEW
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_END_FLAG_STATE_ESTABLISHED
#define FLOW_NOPAYLOAD_INSPECTION
struct Flow_ Flow
Flow data structure.
#define FLOW_END_FLAG_STATE_BYPASSED
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.
struct Flow_::@115::@121 icmp_s
const struct SigGroupHead_ * sgh_toserver
uint32_t emerg_spare_sync_stamp
struct FlowCnf_ FlowConfig
AppLayerParserState * alparser
struct FlowProtoFreeFunc_ FlowProtoFreeFunc
@ FLOW_STATE_LOCAL_BYPASSED
bool FlowHasGaps(const Flow *, uint8_t way)
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'.
struct Flow_::@117::@123 icmp_d
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
struct Flow_::@115::@122 esp
int FlowChangeProto(Flow *)
Check if change proto flag is set for flow.
void FlowRegisterTests(void)
Function to register the Flow Unitests.
union FlowAddress_::@114 address
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
#define FLOW_END_FLAG_STATE_CLOSED
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)
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.
uint16_t FlowGetSourcePort(Flow *flow)
Get flow source port.
FlowThreadId thread_id[2]
int FlowHasAlerts(const Flow *)
Check if flow has alerts.