]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
ips: fix wrong thread for bridge ips modes
authorVictor Julien <victor@inliniac.net>
Mon, 9 Sep 2019 13:36:39 +0000 (15:36 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 9 Sep 2019 17:27:32 +0000 (19:27 +0200)
src/flow-hash.c
src/flow-timeout.c
src/flow-util.h
src/flow.h
src/stream-tcp.c

index 9a4280778f93a965980de78e771b93cd8f085fab..aa434ec69f07ed9a7cfba61d284f84efb3be2a2f 100644 (file)
@@ -555,7 +555,7 @@ static Flow *TcpReuseReplace(ThreadVars *tv, DecodeThreadVars *dtv,
     /* tag flow as reused so future lookups won't find it */
     old_f->flags |= FLOW_TCP_REUSED;
     /* get some settings that we move over to the new flow */
-    FlowThreadId thread_id = old_f->thread_id;
+    FlowThreadId thread_id[2] = { old_f->thread_id[0], old_f->thread_id[1] };
 
     /* since fb lock is still held this flow won't be found until we are done */
     FLOWLOCK_UNLOCK(old_f);
@@ -578,7 +578,8 @@ static Flow *TcpReuseReplace(ThreadVars *tv, DecodeThreadVars *dtv,
     f->flow_hash = hash;
     f->fb = fb;
 
-    f->thread_id = thread_id;
+    f->thread_id[0] = thread_id[0];
+    f->thread_id[1] = thread_id[1];
     return f;
 }
 
index 3e07ab5d117c8a863867a50e753a1239d54de14a..c5dafb06f8e6b175f71bc7be8f8ffbc789099c17 100644 (file)
@@ -387,7 +387,7 @@ int FlowForceReassemblyForFlow(Flow *f, int server, int client)
     }
 
     /* inject the packet(s) into the appropriate thread */
-    int thread_id = (int)f->thread_id;
+    int thread_id = (int)f->thread_id[0];
     Packet *packets[3] = { p1, p2 ? p2 : NULL, NULL }; /**< null terminated array of packets */
     if (unlikely(!(TmThreadsInjectPacketsById(packets, thread_id)))) {
         FlowDeReference(&p1->flow);
index 6707cd4831e6e7a9fc23c1f4499764537dbfcd13..33c465d005b86e8a29ecf8d7d8463e4e519ea75d 100644 (file)
@@ -62,7 +62,8 @@
         (f)->alproto_orig = 0; \
         (f)->alproto_expect = 0; \
         (f)->de_ctx_version = 0; \
-        (f)->thread_id = 0; \
+        (f)->thread_id[0] = 0; \
+        (f)->thread_id[1] = 0; \
         (f)->alparser = NULL; \
         (f)->alstate = NULL; \
         (f)->sgh_toserver = NULL; \
         (f)->alproto_orig = 0; \
         (f)->alproto_expect = 0; \
         (f)->de_ctx_version = 0; \
-        (f)->thread_id = 0; \
+        (f)->thread_id[0] = 0; \
+        (f)->thread_id[1] = 0; \
         (f)->sgh_toserver = NULL; \
         (f)->sgh_toclient = NULL; \
         GenericVarFree((f)->flowvar); \
index 62dcd67ea16681ee6ee32d1fb4d5a3687a72d0d0..cf6e729581cbfa80a60055769c64c7269e33bcff 100644 (file)
@@ -423,7 +423,7 @@ typedef struct Flow_
     uint32_t de_ctx_version;
 
     /** Thread ID for the stream/detect portion of this flow */
-    FlowThreadId thread_id;
+    FlowThreadId thread_id[2];
 
     /** ttl tracking */
     uint8_t min_ttl_toserver;
index 2f795bdc3939eb2c2167bfb38a4fc6d7e62f197a..e708fb6ad9dfd00f6b7f1720ea9d43f81ede254f 100644 (file)
@@ -4703,21 +4703,15 @@ static inline int StreamTcpStateDispatch(ThreadVars *tv, Packet *p,
     return 0;
 }
 
-/* flow is and stays locked */
-int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
-                     PacketQueue *pq)
+static inline void HandleThreadId(ThreadVars *tv, Packet *p, StreamTcpThread *stt)
 {
-    SCEnter();
-
-    DEBUG_ASSERT_FLOW_LOCKED(p->flow);
-
-    SCLogDebug("p->pcap_cnt %"PRIu64, p->pcap_cnt);
+    const int idx = (!(PKT_IS_TOSERVER(p)));
 
     /* assign the thread id to the flow */
-    if (unlikely(p->flow->thread_id == 0)) {
-        p->flow->thread_id = (FlowThreadId)tv->id;
-    } else if (unlikely((FlowThreadId)tv->id != p->flow->thread_id)) {
-        SCLogDebug("wrong thread: flow has %u, we are %d", p->flow->thread_id, tv->id);
+    if (unlikely(p->flow->thread_id[idx] == 0)) {
+        p->flow->thread_id[idx] = (FlowThreadId)tv->id;
+    } else if (unlikely((FlowThreadId)tv->id != p->flow->thread_id[idx])) {
+        SCLogDebug("wrong thread: flow has %u, we are %d", p->flow->thread_id[idx], tv->id);
         if (p->pkt_src == PKT_SRC_WIRE) {
             StatsIncr(tv, stt->counter_tcp_wrong_thread);
             if ((p->flow->flags & FLOW_WRONG_THREAD) == 0) {
@@ -4726,6 +4720,19 @@ int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
             }
         }
     }
+}
+
+/* flow is and stays locked */
+int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
+                     PacketQueue *pq)
+{
+    SCEnter();
+
+    DEBUG_ASSERT_FLOW_LOCKED(p->flow);
+
+    SCLogDebug("p->pcap_cnt %"PRIu64, p->pcap_cnt);
+
+    HandleThreadId(tv, p, stt);
 
     TcpSession *ssn = (TcpSession *)p->flow->protoctx;