]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow/inject: Ensure initialized thread value used
authorJeff Lucovsky <jeff.lucovsky@corelight.com>
Mon, 11 Mar 2024 18:57:16 +0000 (14:57 -0400)
committerVictor Julien <victor@inliniac.net>
Sat, 16 Mar 2024 08:29:38 +0000 (09:29 +0100)
Issue: 6835

When injecting a flow, ensure that the selected thread_id has been
initialized. When a flow is picked up midstream, the initialized thread
can be the second thread element.

src/flow-timeout.c

index 546fc35fe93d22065269a7d82ca83bda10928601..92632e68f619086859a4d1cce7090e914e57e5bf 100644 (file)
@@ -334,14 +334,21 @@ int FlowForceReassemblyNeedReassembly(Flow *f)
  *
  *        The function requires flow to be locked beforehand.
  *
+ * Normally, the first thread_id value should be used. This is when the flow is
+ * created on seeing the first packet to the server; sometimes, if the first
+ * packet is determined to be to the client, the second thread_id value should
+ * be used.
+ *
  * \param f Pointer to the flow.
  *
  * \retval 0 This flow doesn't need any reassembly processing; 1 otherwise.
  */
 void FlowForceReassemblyForFlow(Flow *f)
 {
-    const int thread_id = (int)f->thread_id[0];
-    TmThreadsInjectFlowById(f, thread_id);
+    // Have packets traveled to the server? If not,
+    // use the reverse direction
+    int idx = f->todstpktcnt > 0 ? 0 : 1;
+    TmThreadsInjectFlowById(f, (const int)f->thread_id[idx]);
 }
 
 /**