suricata
flow-worker.c
Go to the documentation of this file.
1 /* Copyright (C) 2016-2020 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  * Flow Workers are single thread modules taking care of (almost)
24  * everything related to packets with flows:
25  *
26  * - Lookup/creation
27  * - Stream tracking, reassembly
28  * - Applayer update
29  * - Detection
30  *
31  * This all while holding the flow lock.
32  */
33 
34 #include "suricata-common.h"
35 #include "suricata.h"
36 
37 #include "decode.h"
38 #include "detect.h"
39 #include "stream-tcp.h"
40 #include "app-layer.h"
41 #include "detect-engine.h"
42 #include "output.h"
43 #include "app-layer-parser.h"
44 
45 #include "util-validate.h"
46 
47 #include "flow-util.h"
48 #include "flow-manager.h"
49 #include "flow-timeout.h"
50 #include "flow-spare-pool.h"
51 
53 
54 typedef struct FlowTimeoutCounters {
58 
59 typedef struct FlowWorkerThreadData_ {
61 
62  union {
65  };
66 
68 
69  void *output_thread; /* Output thread data. */
70  void *output_thread_flow; /* Output thread data. */
71 
74  uint16_t both_bypass_pkts;
76 
79 
80  struct {
81  uint16_t flows_injected;
82  uint16_t flows_removed;
85  } cnt;
87 
89 
90 static void FlowWorkerFlowTimeout(ThreadVars *tv, Packet *p, FlowWorkerThreadData *fw, void *detect_thread);
92 
93 /**
94  * \internal
95  * \brief Forces reassembly for flow if it needs it.
96  *
97  * The function requires flow to be locked beforehand.
98  *
99  * \param f Pointer to the flow.
100  *
101  * \retval cnt number of packets injected
102  */
103 static int FlowFinish(ThreadVars *tv, Flow *f, FlowWorkerThreadData *fw, void *detect_thread)
104 {
105  Packet *p1 = NULL, *p2 = NULL;
106  const int server = f->ffr_tc;
107  const int client = f->ffr_ts;
108 
109  /* Get the tcp session for the flow */
110  TcpSession *ssn = (TcpSession *)f->protoctx;
111 
112  /* The packets we use are based on what segments in what direction are
113  * unprocessed.
114  * p1 if we have client segments for reassembly purpose only. If we
115  * have no server segments p2 can be a toserver packet with dummy
116  * seq/ack, and if we have server segments p2 has to carry out reassembly
117  * for server segment as well, in which case we will also need a p3 in the
118  * toclient which is now dummy since all we need it for is detection */
119 
120  /* insert a pseudo packet in the toserver direction */
122  p1 = FlowForceReassemblyPseudoPacketGet(0, f, ssn);
123  if (p1 == NULL) {
124  return 0;
125  }
127 
129  p2 = FlowForceReassemblyPseudoPacketGet(1, f, ssn);
130  if (p2 == NULL) {
131  FlowDeReference(&p1->flow);
132  TmqhOutputPacketpool(NULL, p1);
133  return 0;
134  }
136  p2->flowflags |= FLOW_PKT_LAST_PSEUDO;
137  } else {
139  }
140  } else {
142  p1 = FlowForceReassemblyPseudoPacketGet(1, f, ssn);
143  if (p1 == NULL) {
144  return 0;
145  }
148  } else {
149  /* impossible */
150  BUG_ON(1);
151  }
152  }
154 
155  FlowWorkerFlowTimeout(tv, p1, fw, detect_thread);
157  if (p2) {
158  FlowWorkerFlowTimeout(tv, p2, fw, detect_thread);
160  return 2;
161  }
162  return 1;
163 }
164 
165 static void CheckWorkQueue(ThreadVars *tv, FlowWorkerThreadData *fw,
166  void *detect_thread, // TODO proper type?
167  FlowTimeoutCounters *counters,
168  FlowQueuePrivate *fq)
169 {
170  Flow *f;
171  while ((f = FlowQueuePrivateGetFromTop(fq)) != NULL) {
172  FLOWLOCK_WRLOCK(f);
173  f->flow_end_flags |= FLOW_END_FLAG_TIMEOUT; //TODO emerg
174 
175  if (f->proto == IPPROTO_TCP) {
176  if (!(f->flags & FLOW_TIMEOUT_REASSEMBLY_DONE) && !FlowIsBypassed(f) &&
177  FlowForceReassemblyNeedReassembly(f) == 1 && f->ffr != 0) {
178  int cnt = FlowFinish(tv, f, fw, detect_thread);
179  counters->flows_aside_pkt_inject += cnt;
180  counters->flows_aside_needs_work++;
181  }
182  }
183 
184  /* this should not be possible */
185  BUG_ON(f->use_cnt > 0);
186 
187  /* no one is referring to this flow, use_cnt 0, removed from hash
188  * so we can unlock it and pass it to the flow recycler */
189 
190  if (fw->output_thread_flow != NULL)
191  (void)OutputFlowLog(tv, fw->output_thread_flow, f);
192 
193  FlowEndCountersUpdate(tv, &fw->fec, f);
194  if (f->proto == IPPROTO_TCP && f->protoctx != NULL) {
196  }
198 
199  FlowClearMemory (f, f->protomap);
200  FLOWLOCK_UNLOCK(f);
201  if (fw->fls.spare_queue.len >= 200) { // TODO match to API? 200 = 2 * block size
203  } else {
205  }
206  }
207 }
208 
209 /** \brief handle flow for packet
210  *
211  * Handle flow creation/lookup
212  */
213 static inline TmEcode FlowUpdate(ThreadVars *tv, FlowWorkerThreadData *fw, Packet *p)
214 {
215  FlowHandlePacketUpdate(p->flow, p, tv, fw->dtv);
216 
217  int state = p->flow->flow_state;
218  switch (state) {
219 #ifdef CAPTURE_OFFLOAD
220  case FLOW_STATE_CAPTURE_BYPASSED: {
223  Flow *f = p->flow;
224  FlowDeReference(&p->flow);
225  FLOWLOCK_UNLOCK(f);
226  return TM_ECODE_DONE;
227  }
228 #endif
232  Flow *f = p->flow;
233  FlowDeReference(&p->flow);
234  FLOWLOCK_UNLOCK(f);
235  return TM_ECODE_DONE;
236  }
237  default:
238  return TM_ECODE_OK;
239  }
240 }
241 
242 static TmEcode FlowWorkerThreadDeinit(ThreadVars *tv, void *data);
243 
244 static TmEcode FlowWorkerThreadInit(ThreadVars *tv, const void *initdata, void **data)
245 {
246  FlowWorkerThreadData *fw = SCCalloc(1, sizeof(*fw));
247  if (fw == NULL)
248  return TM_ECODE_FAILED;
249 
250  SC_ATOMIC_INITPTR(fw->detect_thread);
251  SC_ATOMIC_SET(fw->detect_thread, NULL);
252 
253  fw->local_bypass_pkts = StatsRegisterCounter("flow_bypassed.local_pkts", tv);
254  fw->local_bypass_bytes = StatsRegisterCounter("flow_bypassed.local_bytes", tv);
255  fw->both_bypass_pkts = StatsRegisterCounter("flow_bypassed.local_capture_pkts", tv);
256  fw->both_bypass_bytes = StatsRegisterCounter("flow_bypassed.local_capture_bytes", tv);
257 
258  fw->cnt.flows_aside_needs_work = StatsRegisterCounter("flow.wrk.flows_evicted_needs_work", tv);
259  fw->cnt.flows_aside_pkt_inject = StatsRegisterCounter("flow.wrk.flows_evicted_pkt_inject", tv);
260  fw->cnt.flows_removed = StatsRegisterCounter("flow.wrk.flows_evicted", tv);
261  fw->cnt.flows_injected = StatsRegisterCounter("flow.wrk.flows_injected", tv);
262 
263  fw->fls.dtv = fw->dtv = DecodeThreadVarsAlloc(tv);
264  if (fw->dtv == NULL) {
265  FlowWorkerThreadDeinit(tv, fw);
266  return TM_ECODE_FAILED;
267  }
268 
269  /* setup TCP */
270  if (StreamTcpThreadInit(tv, NULL, &fw->stream_thread_ptr) != TM_ECODE_OK) {
271  FlowWorkerThreadDeinit(tv, fw);
272  return TM_ECODE_FAILED;
273  }
274 
275  if (DetectEngineEnabled()) {
276  /* setup DETECT */
277  void *detect_thread = NULL;
278  if (DetectEngineThreadCtxInit(tv, NULL, &detect_thread) != TM_ECODE_OK) {
279  FlowWorkerThreadDeinit(tv, fw);
280  return TM_ECODE_FAILED;
281  }
282  SC_ATOMIC_SET(fw->detect_thread, detect_thread);
283  }
284 
285  /* Setup outputs for this thread. */
286  if (OutputLoggerThreadInit(tv, initdata, &fw->output_thread) != TM_ECODE_OK) {
287  FlowWorkerThreadDeinit(tv, fw);
288  return TM_ECODE_FAILED;
289  }
291  SCLogError(SC_ERR_THREAD_INIT, "initializing flow log API for thread failed");
292  FlowWorkerThreadDeinit(tv, fw);
293  return TM_ECODE_FAILED;
294  }
295 
299 
300  /* setup pq for stream end pkts */
301  memset(&fw->pq, 0, sizeof(PacketQueueNoLock));
302  *data = fw;
303  return TM_ECODE_OK;
304 }
305 
306 static TmEcode FlowWorkerThreadDeinit(ThreadVars *tv, void *data)
307 {
308  FlowWorkerThreadData *fw = data;
309 
311 
312  /* free TCP */
313  StreamTcpThreadDeinit(tv, (void *)fw->stream_thread);
314 
315  /* free DETECT */
316  void *detect_thread = SC_ATOMIC_GET(fw->detect_thread);
317  if (detect_thread != NULL) {
318  DetectEngineThreadCtxDeinit(tv, detect_thread);
319  SC_ATOMIC_SET(fw->detect_thread, NULL);
320  }
321 
322  /* Free output. */
325 
326  /* free pq */
327  BUG_ON(fw->pq.len);
328 
329  Flow *f;
330  while ((f = FlowQueuePrivateGetFromTop(&fw->fls.spare_queue)) != NULL) {
331  FlowFree(f);
332  }
333 
334  SCFree(fw);
335  return TM_ECODE_OK;
336 }
337 
338 TmEcode Detect(ThreadVars *tv, Packet *p, void *data);
340 
341 static inline void UpdateCounters(ThreadVars *tv,
342  FlowWorkerThreadData *fw, const FlowTimeoutCounters *counters)
343 {
344  if (counters->flows_aside_needs_work) {
346  (uint64_t)counters->flows_aside_needs_work);
347  }
348  if (counters->flows_aside_pkt_inject) {
350  (uint64_t)counters->flows_aside_pkt_inject);
351  }
352 }
353 
354 static void FlowPruneFiles(Packet *p)
355 {
356  if (p->flow && p->flow->alstate) {
357  Flow *f = p->flow;
359  PKT_IS_TOSERVER(p) ? STREAM_TOSERVER : STREAM_TOCLIENT);
360  if (fc != NULL) {
361  FilePrune(fc);
362  }
363  }
364 }
365 
366 /** \brief update stream engine
367  *
368  * We can be called from both the flow timeout path as well as from the
369  * "real" traffic path. If in the timeout path any additional packets we
370  * forge for flushing pipelines should not leave our scope. If the original
371  * packet is real (or related to a real packet) we need to push the packets
372  * on, so IPS logic stays valid.
373  */
374 static inline void FlowWorkerStreamTCPUpdate(ThreadVars *tv, FlowWorkerThreadData *fw, Packet *p,
375  void *detect_thread, const bool timeout)
376 {
378  StreamTcp(tv, p, fw->stream_thread, &fw->pq);
380 
381  if (FlowChangeProto(p->flow)) {
382  StreamTcpDetectLogFlush(tv, fw->stream_thread, p->flow, p, &fw->pq);
385  }
386 
387  /* Packets here can safely access p->flow as it's locked */
388  SCLogDebug("packet %"PRIu64": extra packets %u", p->pcap_cnt, fw->pq.len);
389  Packet *x;
390  while ((x = PacketDequeueNoLock(&fw->pq))) {
391  SCLogDebug("packet %"PRIu64" extra packet %p", p->pcap_cnt, x);
392 
393  if (detect_thread != NULL) {
395  Detect(tv, x, detect_thread);
397  }
398 
400 
401  if (timeout) {
403  } else {
404  /* put these packets in the preq queue so that they are
405  * by the other thread modules before packet 'p'. */
407  }
408  }
409 }
410 
411 static void FlowWorkerFlowTimeout(ThreadVars *tv, Packet *p, FlowWorkerThreadData *fw,
412  void *detect_thread)
413 {
415 
416  SCLogDebug("packet %"PRIu64" is TCP. Direction %s", p->pcap_cnt, PKT_IS_TOSERVER(p) ? "TOSERVER" : "TOCLIENT");
419 
420  /* handle TCP and app layer */
421  FlowWorkerStreamTCPUpdate(tv, fw, p, detect_thread, true);
422 
424 
425  /* handle Detect */
426  SCLogDebug("packet %"PRIu64" calling Detect", p->pcap_cnt);
427  if (detect_thread != NULL) {
429  Detect(tv, p, detect_thread);
431  }
432 
433  // Outputs.
435 
436  /* Prune any stored files. */
437  FlowPruneFiles(p);
438 
439  FramesPrune(p->flow, p);
440  /* Release tcp segments. Done here after alerting can use them. */
443  STREAM_TOSERVER : STREAM_TOCLIENT);
445 
446  /* run tx cleanup last */
448 
449  FlowDeReference(&p->flow);
450  /* flow is unlocked later in FlowFinish() */
451 }
452 
453 /** \internal
454  * \brief process flows injected into our queue by other threads
455  */
456 static inline void FlowWorkerProcessInjectedFlows(ThreadVars *tv,
457  FlowWorkerThreadData *fw, Packet *p, void *detect_thread)
458 {
459  /* take injected flows and append to our work queue */
461  FlowQueuePrivate injected = { NULL, NULL, 0 };
462  if (SC_ATOMIC_GET(tv->flow_queue->non_empty) == true)
464  if (injected.len > 0) {
465  StatsAddUI64(tv, fw->cnt.flows_injected, (uint64_t)injected.len);
466 
467  FlowTimeoutCounters counters = { 0, 0, };
468  CheckWorkQueue(tv, fw, detect_thread, &counters, &injected);
469  UpdateCounters(tv, fw, &counters);
470  }
472 }
473 
474 /** \internal
475  * \brief process flows set aside locally during flow lookup
476  */
477 static inline void FlowWorkerProcessLocalFlows(ThreadVars *tv,
478  FlowWorkerThreadData *fw, Packet *p, void *detect_thread)
479 {
481  if (fw->fls.work_queue.len) {
482  StatsAddUI64(tv, fw->cnt.flows_removed, (uint64_t)fw->fls.work_queue.len);
483 
484  FlowTimeoutCounters counters = { 0, 0, };
485  CheckWorkQueue(tv, fw, detect_thread, &counters, &fw->fls.work_queue);
486  UpdateCounters(tv, fw, &counters);
487  }
489 }
490 
491 static TmEcode FlowWorker(ThreadVars *tv, Packet *p, void *data)
492 {
493  FlowWorkerThreadData *fw = data;
494  void *detect_thread = SC_ATOMIC_GET(fw->detect_thread);
495 
496  DEBUG_VALIDATE_BUG_ON(p == NULL);
498 
499  SCLogDebug("packet %"PRIu64, p->pcap_cnt);
500 
501  /* update time */
502  if (!(PKT_IS_PSEUDOPKT(p))) {
503  TimeSetByThread(tv->id, &p->ts);
504  }
505 
506  /* handle Flow */
507  if (p->flags & PKT_WANTS_FLOW) {
509 
510  FlowHandlePacket(tv, &fw->fls, p);
511  if (likely(p->flow != NULL)) {
513  if (FlowUpdate(tv, fw, p) == TM_ECODE_DONE) {
514  goto housekeeping;
515  }
516  }
517  /* Flow is now LOCKED */
518 
520 
521  /* if PKT_WANTS_FLOW is not set, but PKT_HAS_FLOW is, then this is a
522  * pseudo packet created by the flow manager. */
523  } else if (p->flags & PKT_HAS_FLOW) {
524  FLOWLOCK_WRLOCK(p->flow);
526  }
527 
528  SCLogDebug("packet %"PRIu64" has flow? %s", p->pcap_cnt, p->flow ? "yes" : "no");
529 
530  /* handle TCP and app layer */
531  if (p->flow && PKT_IS_TCP(p)) {
532  SCLogDebug("packet %"PRIu64" is TCP. Direction %s", p->pcap_cnt, PKT_IS_TOSERVER(p) ? "TOSERVER" : "TOCLIENT");
534 
535  /* if detect is disabled, we need to apply file flags to the flow
536  * here on the first packet. */
537  if (detect_thread == NULL &&
540  {
542  }
543 
544  FlowWorkerStreamTCPUpdate(tv, fw, p, detect_thread, false);
545 
546  /* handle the app layer part of the UDP packet payload */
547  } else if (p->flow && p->proto == IPPROTO_UDP) {
551  }
552 
554 
555  /* handle Detect */
557  SCLogDebug("packet %"PRIu64" calling Detect", p->pcap_cnt);
558  if (detect_thread != NULL) {
560  Detect(tv, p, detect_thread);
562  }
563 
564  // Outputs.
566 
567  /* Prune any stored files. */
568  FlowPruneFiles(p);
569 
570  /* Release tcp segments. Done here after alerting can use them. */
571  if (p->flow != NULL) {
573 
574  if (FlowIsBypassed(p->flow)) {
576  if (p->proto == IPPROTO_TCP) {
578  }
579  } else if (p->proto == IPPROTO_TCP && p->flow->protoctx) {
580  FramesPrune(p->flow, p);
583  STREAM_TOSERVER : STREAM_TOCLIENT);
585  } else if (p->proto == IPPROTO_UDP) {
586  FramesPrune(p->flow, p);
587  }
588 
589  /* run tx cleanup last */
591 
592  Flow *f = p->flow;
593  FlowDeReference(&p->flow);
594  FLOWLOCK_UNLOCK(f);
595  }
596 
597 housekeeping:
598 
599  /* take injected flows and process them */
600  FlowWorkerProcessInjectedFlows(tv, fw, p, detect_thread);
601 
602  /* process local work queue */
603  FlowWorkerProcessLocalFlows(tv, fw, p, detect_thread);
604 
605  return TM_ECODE_OK;
606 }
607 
608 void FlowWorkerReplaceDetectCtx(void *flow_worker, void *detect_ctx)
609 {
610  FlowWorkerThreadData *fw = flow_worker;
611 
612  SC_ATOMIC_SET(fw->detect_thread, detect_ctx);
613 }
614 
615 void *FlowWorkerGetDetectCtxPtr(void *flow_worker)
616 {
617  FlowWorkerThreadData *fw = flow_worker;
618 
619  return SC_ATOMIC_GET(fw->detect_thread);
620 }
621 
623 {
624  switch (fwi) {
626  return "flow";
628  return "stream";
630  return "app-layer";
632  return "detect";
634  return "tcp-prune";
636  return "flow-inject";
638  return "flow-evict";
640  return "size";
641  }
642  return "error";
643 }
644 
645 static void FlowWorkerExitPrintStats(ThreadVars *tv, void *data)
646 {
647  FlowWorkerThreadData *fw = data;
649 }
650 
652 {
653  tmm_modules[TMM_FLOWWORKER].name = "FlowWorker";
654  tmm_modules[TMM_FLOWWORKER].ThreadInit = FlowWorkerThreadInit;
655  tmm_modules[TMM_FLOWWORKER].Func = FlowWorker;
656  tmm_modules[TMM_FLOWWORKER].ThreadDeinit = FlowWorkerThreadDeinit;
657  tmm_modules[TMM_FLOWWORKER].ThreadExitPrintStats = FlowWorkerExitPrintStats;
660 }
PKT_IS_TOCLIENT
#define PKT_IS_TOCLIENT(p)
Definition: decode.h:269
TmModule_::cap_flags
uint8_t cap_flags
Definition: tm-modules.h:67
Flow_::ffr_tc
uint8_t ffr_tc
Definition: flow.h:394
FlowLookupStruct_::work_queue
FlowQueuePrivate work_queue
Definition: flow.h:554
ThreadVars_::flow_queue
struct FlowQueue_ * flow_queue
Definition: threadvars.h:133
OutputFlowLog
TmEcode OutputFlowLog(ThreadVars *tv, void *thread_data, Flow *f)
Run flow logger(s)
Definition: output-flow.c:87
Packet_::proto
uint8_t proto
Definition: decode.h:464
FileContainer_
Definition: util-file.h:110
TimeSetByThread
void TimeSetByThread(const int thread_id, const struct timeval *tv)
Definition: util-time.c:114
FlowCleanupAppLayer
void FlowCleanupAppLayer(Flow *f)
Definition: flow.c:142
FlowTimeoutCounters
Definition: flow-worker.c:54
detect-engine.h
Flow_::ffr_ts
uint8_t ffr_ts
Definition: flow.h:393
PROFILE_FLOWWORKER_DETECT
@ PROFILE_FLOWWORKER_DETECT
Definition: flow-worker.h:25
DecodeThreadVars_::counter_flow_active
uint16_t counter_flow_active
Definition: decode.h:729
PKT_HAS_FLOW
#define PKT_HAS_FLOW
Definition: decode.h:1185
FlowSparePoolReturnFlow
void FlowSparePoolReturnFlow(Flow *f)
Definition: flow-spare-pool.c:101
PROFILE_FLOWWORKER_FLOW_INJECTED
@ PROFILE_FLOWWORKER_FLOW_INJECTED
Definition: flow-worker.h:27
flow-util.h
FlowWorkerThreadData
struct FlowWorkerThreadData_ FlowWorkerThreadData
FlowLookupStruct_::dtv
DecodeThreadVars * dtv
Definition: flow.h:553
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1238
stream-tcp.h
PacketPoolReturnPacket
void PacketPoolReturnPacket(Packet *p)
Return packet to Packet pool.
Definition: tmqh-packetpool.c:225
FLOW_PKT_LAST_PSEUDO
#define FLOW_PKT_LAST_PSEUDO
Definition: flow.h:235
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:387
PROFILE_FLOWWORKER_FLOW_EVICTED
@ PROFILE_FLOWWORKER_FLOW_EVICTED
Definition: flow-worker.h:28
ProfileFlowWorkerIdToString
const char * ProfileFlowWorkerIdToString(enum ProfileFlowWorkerId fwi)
Definition: flow-worker.c:622
OutputLoggerExitPrintStats
void OutputLoggerExitPrintStats(ThreadVars *tv, void *thread_data)
Definition: output.c:951
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
Packet_::pcap_cnt
uint64_t pcap_cnt
Definition: decode.h:603
StreamTcpThread_
Definition: stream-tcp.h:73
PROFILE_FLOWWORKER_TCPPRUNE
@ PROFILE_FLOWWORKER_TCPPRUNE
Definition: flow-worker.h:26
TM_FLAG_DETECT_TM
#define TM_FLAG_DETECT_TM
Definition: tm-modules.h:34
Flow_::proto
uint8_t proto
Definition: flow.h:378
TM_ECODE_DONE
@ TM_ECODE_DONE
Definition: tm-threads-common.h:84
TcpReassemblyThreadCtx_::app_tctx
void * app_tctx
Definition: stream-tcp-reassemble.h:61
Packet_::flags
uint32_t flags
Definition: decode.h:477
Flow_
Flow data structure.
Definition: flow.h:356
Flow_::protomap
uint8_t protomap
Definition: flow.h:458
PKT_WANTS_FLOW
#define PKT_WANTS_FLOW
Definition: decode.h:1215
FlowTimeoutCounters::flows_aside_pkt_inject
uint32_t flows_aside_pkt_inject
Definition: flow-worker.c:56
AppLayerRegisterThreadCounters
void AppLayerRegisterThreadCounters(ThreadVars *tv)
Registers per flow counters for all protocols.
Definition: app-layer.c:1124
FlowLookupStruct_
Definition: flow.h:550
FlowWorkerThreadData_::dtv
DecodeThreadVars * dtv
Definition: flow-worker.c:60
Flow_::use_cnt
FlowRefCount use_cnt
Definition: flow.h:386
StreamTcpThreadInit
TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
Definition: stream-tcp.c:5364
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:226
AppLayerParserGetFiles
FileContainer * AppLayerParserGetFiles(const Flow *f, const uint8_t direction)
Definition: app-layer-parser.c:894
FlowHandlePacket
void FlowHandlePacket(ThreadVars *tv, FlowLookupStruct *fls, Packet *p)
Entry point for packet flow handling.
Definition: flow.c:507
FlowQueuePrivatePrependFlow
void FlowQueuePrivatePrependFlow(FlowQueuePrivate *fqc, Flow *f)
Definition: flow-queue.c:79
FlowWorkerThreadData_::flows_aside_needs_work
uint16_t flows_aside_needs_work
Definition: flow-worker.c:83
FlowWorkerThreadData_::stream_thread
StreamTcpThread * stream_thread
Definition: flow-worker.c:63
DecodeThreadVars_::counter_tcp_active_sessions
uint16_t counter_tcp_active_sessions
Definition: decode.h:727
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:473
FlowWorkerThreadData_::cnt
struct FlowWorkerThreadData_::@114 cnt
TmqhOutputPacketpool
void TmqhOutputPacketpool(ThreadVars *t, Packet *p)
Definition: tmqh-packetpool.c:375
PROFILE_FLOWWORKER_STREAM
@ PROFILE_FLOWWORKER_STREAM
Definition: flow-worker.h:23
APP_LAYER_PARSER_EOF_TS
#define APP_LAYER_PARSER_EOF_TS
Definition: app-layer-parser.h:42
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:83
FlowQueuePrivate_::len
uint32_t len
Definition: flow-queue.h:44
Flow_::protoctx
void * protoctx
Definition: flow.h:454
OutputLoggerThreadDeinit
TmEcode OutputLoggerThreadDeinit(ThreadVars *tv, void *thread_data)
Definition: output.c:925
DisableDetectFlowFileFlags
void DisableDetectFlowFileFlags(Flow *f)
disable file features we don't need Called if we have no detection engine.
Definition: detect.c:1772
PacketQueueNoLock_
simple fifo queue for packets
Definition: packet-queue.h:32
FLOW_TIMEOUT_REASSEMBLY_DONE
#define FLOW_TIMEOUT_REASSEMBLY_DONE
Definition: flow.h:96
FLOWWORKER_PROFILING_START
#define FLOWWORKER_PROFILING_START(p, id)
Definition: util-profiling.h:166
FLOWLOCK_UNLOCK
#define FLOWLOCK_UNLOCK(fb)
Definition: flow.h:271
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:82
Flow_::flow_state
FlowStateType flow_state
Definition: flow.h:425
TmModule_::ThreadDeinit
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition: tm-modules.h:49
PKT_SET_SRC
#define PKT_SET_SRC(p, src_val)
Definition: decode.h:1241
SC_ERR_THREAD_INIT
@ SC_ERR_THREAD_INIT
Definition: util-error.h:79
PKT_IS_TCP
#define PKT_IS_TCP(p)
Definition: decode.h:264
flow-spare-pool.h
Flow_::alparser
AppLayerParserState * alparser
Definition: flow.h:488
DecodeRegisterPerfCounters
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
Definition: decode.c:523
DetectEngineThreadCtxPtr
DetectEngineThreadCtx * DetectEngineThreadCtxPtr
Definition: flow-worker.c:52
StatsDecr
void StatsDecr(ThreadVars *tv, uint16_t id)
Decrements the local counter.
Definition: counters.c:190
FilePrune
void FilePrune(FileContainer *ffc)
Definition: util-file.c:391
FlowWorkerThreadData_::flows_aside_pkt_inject
uint16_t flows_aside_pkt_inject
Definition: flow-worker.c:84
FLOW_STATE_LOCAL_BYPASSED
@ FLOW_STATE_LOCAL_BYPASSED
Definition: flow.h:515
decode.h
PKT_IS_TOSERVER
#define PKT_IS_TOSERVER(p)
Definition: decode.h:268
DetectEngineThreadCtx_
Definition: detect.h:1043
FlowWorkerThreadData_::flows_injected
uint16_t flows_injected
Definition: flow-worker.c:81
OutputFlowLogThreadInit
TmEcode OutputFlowLogThreadInit(ThreadVars *tv, void *initdata, void **data)
thread init for the flow logger This will run the thread init functions for the individual registered...
Definition: output-flow.c:125
PacketDequeueNoLock
Packet * PacketDequeueNoLock(PacketQueueNoLock *qnl)
Definition: packet-queue.c:206
ProfileFlowWorkerId
ProfileFlowWorkerId
Definition: flow-worker.h:21
FlowWorkerThreadData_::local_bypass_bytes
uint16_t local_bypass_bytes
Definition: flow-worker.c:73
FlowTimeoutCounters
struct FlowTimeoutCounters FlowTimeoutCounters
FlowHandlePacketUpdate
void FlowHandlePacketUpdate(Flow *f, Packet *p, ThreadVars *tv, DecodeThreadVars *dtv)
Update Packet and Flow.
Definition: flow.c:390
FLOWLOCK_WRLOCK
#define FLOWLOCK_WRLOCK(fb)
Definition: flow.h:268
FlowForceReassemblyNeedReassembly
int FlowForceReassemblyNeedReassembly(Flow *f)
Check if a flow needs forced reassembly, or any other processing.
Definition: flow-timeout.c:296
StreamTcp
TmEcode StreamTcp(ThreadVars *, Packet *, void *, PacketQueueNoLock *pq)
Definition: stream-tcp.c:5325
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
DetectEngineEnabled
int DetectEngineEnabled(void)
Check if detection is enabled.
Definition: detect-engine.c:3568
Flow_::flow_end_flags
uint8_t flow_end_flags
Definition: flow.h:460
TmModule_::Func
TmEcode(* Func)(ThreadVars *, Packet *, void *)
Definition: tm-modules.h:52
FLOW_PKT_TOCLIENT_FIRST
#define FLOW_PKT_TOCLIENT_FIRST
Definition: flow.h:232
FlowWorkerThreadData_::local_bypass_pkts
uint16_t local_bypass_pkts
Definition: flow-worker.c:72
PROFILE_FLOWWORKER_APPLAYERUDP
@ PROFILE_FLOWWORKER_APPLAYERUDP
Definition: flow-worker.h:24
FlowQueuePrivateGetFromTop
Flow * FlowQueuePrivateGetFromTop(FlowQueuePrivate *fqc)
Definition: flow-queue.c:152
FLOWWORKER_PROFILING_END
#define FLOWWORKER_PROFILING_END(p, id)
Definition: util-profiling.h:173
StreamTcpPruneSession
void StreamTcpPruneSession(Flow *f, uint8_t flags)
Remove idle TcpSegments from TcpSession.
Definition: stream-tcp-list.c:894
OutputLoggerThreadInit
TmEcode OutputLoggerThreadInit(ThreadVars *tv, const void *initdata, void **data)
Definition: output.c:894
app-layer-parser.h
ThreadVars_::id
int id
Definition: threadvars.h:87
STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION
@ STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION
Definition: stream-tcp.h:183
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:281
Packet_
Definition: decode.h:442
tmm_modules
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.c:33
GET_PKT_LEN
#define GET_PKT_LEN(p)
Definition: decode.h:235
APP_LAYER_PARSER_EOF_TC
#define APP_LAYER_PARSER_EOF_TC
Definition: app-layer-parser.h:43
AppLayerHandleUdp
int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *tctx, Packet *p, Flow *f)
Handle a app layer UDP message.
Definition: app-layer.c:800
DEBUG_ASSERT_FLOW_LOCKED
#define DEBUG_ASSERT_FLOW_LOCKED(f)
Definition: util-validate.h:108
TmEcode
TmEcode
Definition: tm-threads-common.h:81
FlowClearMemory
int FlowClearMemory(Flow *f, uint8_t proto_map)
Function clear the flow memory before queueing it to spare flow queue.
Definition: flow.c:1086
TmModuleFlowWorkerRegister
void TmModuleFlowWorkerRegister(void)
Definition: flow-worker.c:651
flow-timeout.h
TmModule_::name
const char * name
Definition: tm-modules.h:44
FlowLookupStruct_::spare_queue
FlowQueuePrivate spare_queue
Definition: flow.h:552
TMM_FLOWWORKER
@ TMM_FLOWWORKER
Definition: tm-threads-common.h:34
Flow_::ffr
uint8_t ffr
Definition: flow.h:396
FlowWorkerGetDetectCtxPtr
void * FlowWorkerGetDetectCtxPtr(void *flow_worker)
Definition: flow-worker.c:615
PacketEnqueueNoLock
void PacketEnqueueNoLock(PacketQueueNoLock *qnl, Packet *p)
Definition: packet-queue.c:167
FlowWorkerThreadData_::stream_thread_ptr
void * stream_thread_ptr
Definition: flow-worker.c:64
FlowQueueExtractPrivate
FlowQueuePrivate FlowQueueExtractPrivate(FlowQueue *fq)
Definition: flow-queue.c:141
FlowWorkerThreadData_::pq
PacketQueueNoLock pq
Definition: flow-worker.c:77
FlowWorkerThreadData_::flows_removed
uint16_t flows_removed
Definition: flow-worker.c:82
Packet_::flow
struct Flow_ * flow
Definition: decode.h:479
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3146
AppLayerParserTransactionsCleanup
void AppLayerParserTransactionsCleanup(Flow *f)
remove obsolete (inspected and logged) transactions
Definition: app-layer-parser.c:918
DecodeThreadVarsFree
void DecodeThreadVarsFree(ThreadVars *tv, DecodeThreadVars *dtv)
Definition: decode.c:703
Packet_::ts
struct timeval ts
Definition: decode.h:485
flow-manager.h
suricata-common.h
PKT_SRC_FFR
@ PKT_SRC_FFR
Definition: decode.h:57
FlowFree
void FlowFree(Flow *f)
cleanup & free the memory of a flow
Definition: flow-util.c:80
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3358
PROFILE_FLOWWORKER_SIZE
@ PROFILE_FLOWWORKER_SIZE
Definition: flow-worker.h:29
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
FlowWorkerThreadData_::both_bypass_bytes
uint16_t both_bypass_bytes
Definition: flow-worker.c:75
TmModule_::ThreadInit
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:47
PacketUpdateEngineEventCounters
void PacketUpdateEngineEventCounters(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Definition: decode.c:154
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
TmModule_::ThreadExitPrintStats
void(* ThreadExitPrintStats)(ThreadVars *, void *)
Definition: tm-modules.h:48
Detect
TmEcode Detect(ThreadVars *tv, Packet *p, void *data)
Detection engine thread wrapper.
Definition: detect.c:1714
util-validate.h
FlowQueuePrivate_
Definition: flow-queue.h:41
StreamTcpDetectLogFlush
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....
Definition: stream-tcp.c:6353
PacketQueueNoLock_::len
uint32_t len
Definition: packet-queue.h:35
StatsAddUI64
void StatsAddUI64(ThreadVars *tv, uint16_t id, uint64_t x)
Adds a value of type uint64_t to the local counter.
Definition: counters.c:148
FlowWorkerThreadData_::output_thread_flow
void * output_thread_flow
Definition: flow-worker.c:70
OutputFlowLogThreadDeinit
TmEcode OutputFlowLogThreadDeinit(ThreadVars *tv, void *thread_data)
Definition: output-flow.c:167
FramesPrune
void FramesPrune(Flow *f, Packet *p)
Definition: app-layer-frames.c:745
OutputLoggerLog
TmEcode OutputLoggerLog(ThreadVars *tv, Packet *p, void *thread_data)
Definition: output.c:879
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Packet_::pkt_src
uint8_t pkt_src
Definition: decode.h:588
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:672
Flow_::alstate
void * alstate
Definition: flow.h:489
Flow_::flags
uint32_t flags
Definition: flow.h:434
StreamTcpSessionCleanup
void StreamTcpSessionCleanup(TcpSession *ssn)
Session cleanup function. Does not free the ssn.
Definition: stream-tcp.c:209
FlowWorkerThreadData_::fls
FlowLookupStruct fls
Definition: flow-worker.c:78
SC_ATOMIC_INITPTR
#define SC_ATOMIC_INITPTR(name)
Definition: util-atomic.h:318
DecodeThreadVarsAlloc
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
Definition: decode.c:684
ThreadVars_::decode_pq
PacketQueueNoLock decode_pq
Definition: threadvars.h:110
PROFILE_FLOWWORKER_FLOW
@ PROFILE_FLOWWORKER_FLOW
Definition: flow-worker.h:22
StreamTcpThread_::ra_ctx
TcpReassemblyThreadCtx * ra_ctx
Definition: stream-tcp.h:107
suricata.h
FLOW_END_FLAG_TIMEOUT
#define FLOW_END_FLAG_TIMEOUT
Definition: flow.h:241
FlowWorkerThreadData_::fec
FlowEndCounters fec
Definition: flow-worker.c:86
AppLayerParserStateSetFlag
void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint8_t flag)
Definition: app-layer-parser.c:1718
likely
#define likely(expr)
Definition: util-optimize.h:32
FlowWorkerThreadData_::output_thread
void * output_thread
Definition: flow-worker.c:69
FlowChangeProto
int FlowChangeProto(Flow *f)
Check if change proto flag is set for flow.
Definition: flow.c:212
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:376
TcpSession_
Definition: stream-tcp-private.h:274
FlowEndCountersRegister
void FlowEndCountersRegister(ThreadVars *t, FlowEndCounters *fec)
Definition: flow-util.c:244
FlowWorkerThreadData_::SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(DetectEngineThreadCtxPtr, detect_thread)
StatsRegisterCounter
uint16_t StatsRegisterCounter(const char *name, struct ThreadVars_ *tv)
Registers a normal, unqualified counter.
Definition: counters.c:956
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
FlowEndCounters_
Definition: flow-util.h:157
FLOW_PKT_TOSERVER_FIRST
#define FLOW_PKT_TOSERVER_FIRST
Definition: flow.h:231
FlowWorkerThreadData_::both_bypass_pkts
uint16_t both_bypass_pkts
Definition: flow-worker.c:74
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:111
TM_FLAG_STREAM_TM
#define TM_FLAG_STREAM_TM
Definition: tm-modules.h:33
TmModule_::flags
uint8_t flags
Definition: tm-modules.h:70
FlowWorkerThreadData_
Definition: flow-worker.c:59
StreamTcpThreadDeinit
TmEcode StreamTcpThreadDeinit(ThreadVars *tv, void *data)
Definition: stream-tcp.c:5430
output.h
FlowWorkerReplaceDetectCtx
void FlowWorkerReplaceDetectCtx(void *flow_worker, void *detect_ctx)
Definition: flow-worker.c:608
app-layer.h
FlowForceReassemblyPseudoPacketGet
Packet * FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, TcpSession *ssn)
Definition: flow-timeout.c:273
FlowTimeoutCounters::flows_aside_needs_work
uint32_t flows_aside_needs_work
Definition: flow-worker.c:55