ips: fix wrong thread for bridge ips modes

pull/4188/head
Victor Julien 6 years ago
parent d5009c5d8c
commit 7cabb025ea

@ -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;
}

@ -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);

@ -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); \

@ -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;

@ -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;

Loading…
Cancel
Save