From: Victor Julien Date: Mon, 9 Sep 2019 13:36:39 +0000 (+0200) Subject: ips: fix wrong thread for bridge ips modes X-Git-Tag: suricata-5.0.0-rc1~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cabb025ea530cc97b033cbca55e87053a32fd00;p=thirdparty%2Fsuricata.git ips: fix wrong thread for bridge ips modes --- diff --git a/src/flow-hash.c b/src/flow-hash.c index 9a4280778f..aa434ec69f 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -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; } diff --git a/src/flow-timeout.c b/src/flow-timeout.c index 3e07ab5d11..c5dafb06f8 100644 --- a/src/flow-timeout.c +++ b/src/flow-timeout.c @@ -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); diff --git a/src/flow-util.h b/src/flow-util.h index 6707cd4831..33c465d005 100644 --- a/src/flow-util.h +++ b/src/flow-util.h @@ -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; \ @@ -108,7 +109,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)->sgh_toserver = NULL; \ (f)->sgh_toclient = NULL; \ GenericVarFree((f)->flowvar); \ diff --git a/src/flow.h b/src/flow.h index 62dcd67ea1..cf6e729581 100644 --- a/src/flow.h +++ b/src/flow.h @@ -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; diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 2f795bdc39..e708fb6ad9 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -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;