101static void FlowWorkerFlowTimeout(
116 const int server = f->
ffr_tc;
117 const int client = f->
ffr_ts;
131 FlowWorkerFlowTimeout(
tv, p, fw, detect_thread);
143 FlowWorkerFlowTimeout(
tv, p, fw, detect_thread);
167 if (f->
proto == IPPROTO_TCP) {
172 int cnt = FlowFinish(
tv, f, fw, detect_thread);
184 FlowEndCountersUpdate(
tv, &fw->
fec, f);
202 if (max_work != 0 && ++i == max_work)
205 if (ret_queue.
len > 0) {
222#ifdef CAPTURE_OFFLOAD
223 case FLOW_STATE_CAPTURE_BYPASSED: {
227 FlowDeReference(&p->
flow);
236 FlowDeReference(&p->
flow);
268 if (fw->
dtv == NULL) {
269 FlowWorkerThreadDeinit(
tv, fw);
275 FlowWorkerThreadDeinit(
tv, fw);
281 void *detect_thread = NULL;
283 FlowWorkerThreadDeinit(
tv, fw);
291 FlowWorkerThreadDeinit(
tv, fw);
295 SCLogError(
"initializing flow log API for thread failed");
296 FlowWorkerThreadDeinit(
tv, fw);
321 if (detect_thread != NULL) {
382 bool setting_nopayload =
388 if (setting_nopayload) {
389 FlowSetNoPayloadInspectionFlag(p->
flow);
401 if (det_ctx != NULL) {
417 FlowDeReference(&x->
flow);
434static void FlowWorkerFlowTimeout(
444 FlowWorkerStreamTCPUpdate(
tv, fw, p, det_ctx,
true);
450 if (det_ctx != NULL) {
464 STREAM_TOSERVER : STREAM_TOCLIENT);
470 FlowDeReference(&p->
flow);
477static inline void FlowWorkerProcessInjectedFlows(
485 if (injected.
len > 0) {
501 uint32_t max_work = 2;
509 UpdateCounters(
tv, fw, &counters);
517static void PacketAppUpdate2FlowFlags(
Packet *p)
535 SCLogDebug(
"pcap_cnt %" PRIu64
", FLOW_TS_APP_UPDATED|FLOW_TC_APP_UPDATE_NEXT set",
539 SCLogDebug(
"pcap_cnt %" PRIu64
", FLOW_TC_APP_UPDATED|FLOW_TS_APP_UPDATE_NEXT set",
546 SCLogDebug(
"pcap_cnt %" PRIu64
", FLOW_TC_APP_UPDATED|FLOW_TS_APP_UPDATE_NEXT set",
550 SCLogDebug(
"pcap_cnt %" PRIu64
", FLOW_TS_APP_UPDATED|FLOW_TC_APP_UPDATE_NEXT set",
620 ": direction %s FLOW_TS_APP_UPDATE_NEXT %s FLOW_TC_APP_UPDATE_NEXT %s",
627 p->
flow->
flags &= ~FLOW_TS_APP_UPDATE_NEXT;
631 p->
flow->
flags &= ~FLOW_TC_APP_UPDATE_NEXT;
635 if (PacketIsTCP(p)) {
642 if (det_ctx == NULL &&
648 FlowWorkerStreamTCPUpdate(
tv, fw, p, det_ctx,
false);
649 PacketAppUpdate2FlowFlags(p);
656 PacketAppUpdate2FlowFlags(p);
665 if (det_ctx != NULL) {
676 if (p->
flow != NULL) {
679 if (FlowIsBypassed(p->
flow)) {
681 if (p->
proto == IPPROTO_TCP) {
692 STREAM_TOSERVER : STREAM_TOCLIENT);
694 }
else if (p->
proto == IPPROTO_UDP) {
716 SCLogDebug(
"not pseudo, no app update: skip");
720 SCLogDebug(
"flow drop in place: remove app update flags");
725 FlowDeReference(&p->
flow);
732 FlowWorkerProcessInjectedFlows(
tv, fw, p);
735 FlowWorkerProcessLocalFlows(
tv, fw, p);
785 return "flow-inject";
794static bool FlowWorkerIsBusy(
ThreadVars *
tv,
void *flow_worker)
void FramesPrune(Flow *f, Packet *p)
uint16_t SCAppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir)
remove obsolete (inspected and logged) transactions
void SCAppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag)
#define APP_LAYER_PARSER_NO_INSPECTION
#define APP_LAYER_PARSER_EOF_TC
#define APP_LAYER_PARSER_EOF_TS
void AppLayerRegisterThreadCounters(ThreadVars *tv)
Registers per flow counters for all protocols.
int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *tctx, Packet *p, Flow *f)
Handle a app layer UDP message.
void StatsDecr(ThreadVars *tv, uint16_t id)
Decrements the local counter.
uint16_t StatsRegisterMaxCounter(const char *name, struct ThreadVars_ *tv)
Registers a counter, whose value holds the maximum of all the values assigned to it.
uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
Registers a normal, unqualified counter.
void StatsSetUI64(ThreadVars *tv, uint16_t id, uint64_t x)
Sets a value of type double to the local counter.
void StatsAddUI64(ThreadVars *tv, uint16_t id, uint64_t x)
Adds a value of type uint64_t to the local counter.
@ PKT_DROP_REASON_FLOW_DROP
@ PKT_DROP_REASON_STREAM_PRE_HOOK
@ PKT_DROP_REASON_FLOW_PRE_HOOK
#define PKT_NOPAYLOAD_INSPECTION
#define PKT_SET_SRC(p, src_val)
#define PKT_IS_TOCLIENT(p)
#define PKT_IS_FLUSHPKT(p)
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
#define PKT_IS_TOSERVER(p)
@ PKT_SRC_CAPTURE_TIMEOUT
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
int DetectEngineEnabled(void)
Check if detection is enabled.
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
void DisableDetectFlowFileFlags(Flow *f)
disable file features we don't need Called if we have no detection engine.
void FlowQueuePrivatePrependFlow(FlowQueuePrivate *fqc, Flow *f)
Flow * FlowQueuePrivateGetFromTop(FlowQueuePrivate *fqc)
FlowQueuePrivate FlowQueueExtractPrivate(FlowQueue *fq)
void FlowQueuePrivateAppendPrivate(FlowQueuePrivate *dest, FlowQueuePrivate *src)
void FlowSparePoolReturnFlows(FlowQueuePrivate *fqp)
#define FLOW_SPARE_POOL_BLOCK_SIZE
Packet * FlowPseudoPacketGet(int direction, Flow *f, const TcpSession *ssn)
bool FlowNeedsReassembly(Flow *f)
Check if a flow needs forced reassembly, or any other processing.
void FlowEndCountersRegister(ThreadVars *t, FlowEndCounters *fec)
void FlowFree(Flow *f)
cleanup & free the memory of a flow
void FlowWorkerReplaceDetectCtx(void *flow_worker, void *detect_ctx)
TmEcode Detect(ThreadVars *tv, Packet *p, void *data)
Detection engine thread wrapper.
void * FlowWorkerGetThreadData(void *flow_worker)
void * FlowWorkerGetDetectCtxPtr(void *flow_worker)
struct FlowWorkerThreadData_ FlowWorkerThreadData
const char * ProfileFlowWorkerIdToString(enum ProfileFlowWorkerId fwi)
void FlowWorkerSetFlushAck(void *flow_worker)
TmEcode StreamTcp(ThreadVars *, Packet *, void *, PacketQueueNoLock *pq)
void TmModuleFlowWorkerRegister(void)
DetectEngineThreadCtx * DetectEngineThreadCtxPtr
bool FlowWorkerGetFlushAck(void *flow_worker)
@ PROFILE_FLOWWORKER_SIZE
@ PROFILE_FLOWWORKER_APPLAYERUDP
@ PROFILE_FLOWWORKER_FLOW_EVICTED
@ PROFILE_FLOWWORKER_DETECT
@ PROFILE_FLOWWORKER_FLOW
@ PROFILE_FLOWWORKER_STREAM
@ PROFILE_FLOWWORKER_TCPPRUNE
@ PROFILE_FLOWWORKER_FLOW_INJECTED
void FlowHandlePacket(ThreadVars *tv, FlowLookupStruct *fls, Packet *p)
Entry point for packet flow handling.
int FlowClearMemory(Flow *f, uint8_t proto_map)
Function clear the flow memory before queueing it to spare flow queue.
void FlowCleanupAppLayer(Flow *f)
int FlowChangeProto(Flow *f)
Check if change proto flag is set for flow.
void FlowHandlePacketUpdate(Flow *f, Packet *p, ThreadVars *tv, DecodeThreadVars *dtv)
Update Packet and Flow.
@ FLOW_STATE_LOCAL_BYPASSED
#define FLOW_PKT_TOSERVER
#define FLOW_TC_APP_UPDATED
#define FLOW_END_FLAG_TIMEOUT
#define FLOW_PKT_LAST_PSEUDO
#define FLOW_TIMEOUT_REASSEMBLY_DONE
#define FLOW_TS_APP_UPDATED
#define FLOW_TC_APP_UPDATE_NEXT
#define FLOW_PKT_TOCLIENT_FIRST
#define FLOW_TS_APP_UPDATE_NEXT
#define FLOW_PKT_TOSERVER_FIRST
#define FLOWLOCK_UNLOCK(fb)
#define FLOWLOCK_WRLOCK(fb)
void PacketUpdateEngineEventCounters(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
void DecodeThreadVarsFree(ThreadVars *tv, DecodeThreadVars *dtv)
TmEcode OutputFlowLogThreadDeinit(ThreadVars *tv, void *thread_data)
TmEcode OutputFlowLogThreadInit(ThreadVars *tv, void **data)
thread init for the flow logger This will run the thread init functions for the individual registered...
TmEcode OutputFlowLog(ThreadVars *tv, void *thread_data, Flow *f)
Run flow logger(s)
TmEcode OutputLoggerThreadDeinit(ThreadVars *tv, void *thread_data)
TmEcode OutputLoggerThreadInit(ThreadVars *tv, const void *initdata, void **data)
TmEcode OutputLoggerLog(ThreadVars *tv, Packet *p, void *thread_data)
TmEcode OutputLoggerFlush(ThreadVars *tv, Packet *p, void *thread_data)
Packet * PacketDequeueNoLock(PacketQueueNoLock *qnl)
void PacketDrop(Packet *p, const uint8_t action, enum PacketDropReason r)
issue drop action
bool PacketCheckAction(const Packet *p, const uint8_t a)
void StreamTcpPruneSession(Flow *f, uint8_t flags)
Remove idle TcpSegments from TcpSession.
TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
TmEcode StreamTcpThreadDeinit(ThreadVars *tv, void *data)
void StreamTcpSessionCleanup(TcpSession *ssn)
Session cleanup function. Does not free the ssn.
void StreamTcpDetectLogFlush(ThreadVars *tv, StreamTcpThread *stt, Flow *f, Packet *p, PacketQueueNoLock *pq)
create packets in both directions to flush out logging and detection before switching protocols....
@ STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION
@ STREAM_HAS_UNPROCESSED_SEGMENTS_NONE
#define STREAM_FLAGS_FOR_PACKET(p)
Structure to hold thread specific data for all decode modules.
uint16_t counter_flow_active
uint16_t counter_tcp_active_sessions
DetectPacketHookFunc PreFlowHook
DetectPacketHookFunc PreStreamHook
FlowQueuePrivate spare_queue
FlowQueuePrivate work_queue
uint32_t flows_aside_needs_work
uint32_t flows_aside_pkt_inject
uint16_t local_bypass_pkts
uint16_t flows_injected_max
uint16_t flows_aside_needs_work
uint16_t flows_aside_pkt_inject
SC_ATOMIC_DECLARE(bool, flush_ack)
SC_ATOMIC_DECLARE(DetectEngineThreadCtxPtr, detect_thread)
uint16_t both_bypass_pkts
struct FlowWorkerThreadData_::@127 cnt
uint16_t local_bypass_bytes
void * output_thread_flow
StreamTcpThread * stream_thread
uint16_t both_bypass_bytes
AppLayerParserState * alparser
simple fifo queue for packets
uint8_t app_update_direction
TcpReassemblyThreadCtx * ra_ctx
Per thread variable structure.
struct FlowQueue_ * flow_queue
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
bool(* ThreadBusy)(ThreadVars *tv, void *thread_data)
TmEcode(* Func)(ThreadVars *, Packet *, void *)
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
TmModule tmm_modules[TMM_SIZE]
#define TM_FLAG_FLOWWORKER_TM
void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
#define SC_ATOMIC_CAS(name, cmpval, newval)
atomic Compare and Switch
#define SC_ATOMIC_INITPTR(name)
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
#define SCLogError(...)
Macro used to log ERROR messages.
#define FLOWWORKER_PROFILING_END(p, id)
#define FLOWWORKER_PROFILING_START(p, id)
void TimeSetByThread(const int thread_id, SCTime_t tv)
#define DEBUG_VALIDATE_BUG_ON(exp)
#define DEBUG_ASSERT_FLOW_LOCKED(f)