Skip to content

Commit 15947f2

Browse files
committed
detect: inspect all packets in multi-layer tunneling
When the decoders encounter multiple layers of tunneling, multiple tunnel packets are created. These are then stored in ThreadVars::decode_pq, where they are processed after the current thread "slot" is done. However, due to a logic error, the tunnel packets after the first, where not called for the correct position in the packet pipeline. This would lead to these packets not going through the FlowWorker module, so skipping everything from flow tracking, detection and logging. This would only happen for single and workers, due to how the pipelines are constructed. The "slot" holding the decoder, would contain 2 packets in ThreadVars::decode_pq. Then it would call the pipeline on the first packet with the next slot of the pipeline through a indirect call to TmThreadsSlotVarRun(), so it would be called for the FlowWorker. However when that first (the most inner) packet was done, the call to TmThreadsSlotVarRun() would again service the ThreadVars::decode_pq and process it, again moving the slot pointer forward, so past the FlowWorker. This patch addresses the issue by making sure only a "decode" thread slot will service the ThreadVars::decode_pq, thus never moving the slot past the FlowWorker. Bug: OISF#6402.
1 parent e9c1ca2 commit 15947f2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/tm-threads.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ TmEcode TmThreadsSlotVarRun(ThreadVars *tv, Packet *p, TmSlot *slot)
142142
TmThreadsSlotProcessPktFail(tv, s, NULL);
143143
return TM_ECODE_FAILED;
144144
}
145-
146-
if (TmThreadsProcessDecodePseudoPackets(tv, &tv->decode_pq, s->slot_next) != TM_ECODE_OK) {
147-
return TM_ECODE_FAILED;
145+
if (s->tm_flags & TM_FLAG_DECODE_TM) {
146+
if (TmThreadsProcessDecodePseudoPackets(tv, &tv->decode_pq, s->slot_next) !=
147+
TM_ECODE_OK) {
148+
return TM_ECODE_FAILED;
149+
}
148150
}
149151
}
150152

@@ -661,6 +663,7 @@ void TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, const void *data)
661663
/* we don't have to check for the return value "-1". We wouldn't have
662664
* received a TM as arg, if it didn't exist */
663665
slot->tm_id = TmModuleGetIDForTM(tm);
666+
slot->tm_flags |= tm->flags;
664667

665668
tv->tmm_flags |= tm->flags;
666669
tv->cap_flags |= tm->cap_flags;

src/tm-threads.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,18 @@ typedef struct TmSlot_ {
6363

6464
SC_ATOMIC_DECLARE(void *, slot_data);
6565

66+
/** copy of the TmModule::flags */
67+
uint8_t tm_flags;
68+
69+
/* store the thread module id */
70+
int tm_id;
71+
6672
TmEcode (*SlotThreadInit)(ThreadVars *, const void *, void **);
6773
void (*SlotThreadExitPrintStats)(ThreadVars *, void *);
6874
TmEcode (*SlotThreadDeinit)(ThreadVars *, void *);
6975

7076
/* data storage */
7177
const void *slot_initdata;
72-
/* store the thread module id */
73-
int tm_id;
7478

7579
} TmSlot;
7680

0 commit comments

Comments
 (0)