diff --git a/src/decode-geneve.c b/src/decode-geneve.c index 21ac947caf79..c9e5933010a1 100644 --- a/src/decode-geneve.c +++ b/src/decode-geneve.c @@ -257,7 +257,7 @@ int DecodeGeneve(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_GENEVE); - PacketEnqueueNoLock(&tv->decode_pq, tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } } @@ -306,9 +306,9 @@ static int DecodeGeneveTest01(void) DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); FAIL_IF_NOT(PacketIsUDP(p)); - FAIL_IF(tv.decode_pq.top == NULL); + FAIL_IF(dtv.decode_pq.top == NULL); - Packet *tp = PacketDequeueNoLock(&tv.decode_pq); + Packet *tp = PacketDequeueNoLock(&dtv.decode_pq); FAIL_IF_NOT(PacketIsUDP(tp)); FAIL_IF_NOT(tp->sp == 546); @@ -348,9 +348,9 @@ static int DecodeGeneveTest02(void) DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); FAIL_IF_NOT(PacketIsUDP(p)); - FAIL_IF(tv.decode_pq.top == NULL); + FAIL_IF(dtv.decode_pq.top == NULL); - Packet *tp = PacketDequeueNoLock(&tv.decode_pq); + Packet *tp = PacketDequeueNoLock(&dtv.decode_pq); FAIL_IF_NOT(PacketIsUDP(tp)); FAIL_IF_NOT(tp->sp == 53); @@ -395,9 +395,9 @@ static int DecodeGeneveTest03(void) DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); FAIL_IF_NOT(PacketIsUDP(p)); - FAIL_IF(tv.decode_pq.top == NULL); + FAIL_IF(dtv.decode_pq.top == NULL); - Packet *tp = PacketDequeueNoLock(&tv.decode_pq); + Packet *tp = PacketDequeueNoLock(&dtv.decode_pq); FAIL_IF_NOT(PacketIsUDP(tp)); FAIL_IF_NOT(tp->sp == 53); @@ -439,7 +439,7 @@ static int DecodeGeneveTest04(void) DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); FAIL_IF_NOT(PacketIsUDP(p)); - FAIL_IF(tv.decode_pq.top != NULL); /* Geneve packet should not have been processed */ + FAIL_IF(dtv.decode_pq.top != NULL); /* Geneve packet should not have been processed */ DecodeGeneveConfigPorts(GENEVE_DEFAULT_PORT_S); /* Reset Geneve port list for future calls */ FlowShutdown(); @@ -479,7 +479,7 @@ static int DecodeGeneveTest05(void) DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); FAIL_IF_NOT(PacketIsUDP(p)); - FAIL_IF(tv.decode_pq.top != NULL); /* Geneve packet should not have been processed */ + FAIL_IF(dtv.decode_pq.top != NULL); /* Geneve packet should not have been processed */ FlowShutdown(); PacketFree(p); diff --git a/src/decode-gre.c b/src/decode-gre.c index a383c815c2cf..b33dcb728876 100644 --- a/src/decode-gre.c +++ b/src/decode-gre.c @@ -207,7 +207,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *p len - header_len, DECODE_TUNNEL_IPV4); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } break; } @@ -221,7 +221,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *p len - header_len, DECODE_TUNNEL_PPP); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } break; } @@ -232,7 +232,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *p len - header_len, DECODE_TUNNEL_IPV6); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } break; } @@ -243,7 +243,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *p len - header_len, DECODE_TUNNEL_VLAN); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } break; } @@ -258,7 +258,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *p GRE_FLAG_ISSET_SQ(greh) == 0 ? DECODE_TUNNEL_ERSPANI : DECODE_TUNNEL_ERSPANII); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } break; } @@ -269,7 +269,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *p len - header_len, DECODE_TUNNEL_ETHERNET); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } break; } @@ -279,7 +279,7 @@ int DecodeGRE(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *p tv, dtv, p, pkt + header_len, len - header_len, DECODE_TUNNEL_ARP); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_GRE); - PacketEnqueueNoLock(&tv->decode_pq, tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } break; } diff --git a/src/decode-ipv4.c b/src/decode-ipv4.c index 094d9ed72928..905403544e31 100644 --- a/src/decode-ipv4.c +++ b/src/decode-ipv4.c @@ -540,7 +540,7 @@ int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, if (unlikely(IPV4_GET_RAW_FRAGOFFSET(ip4h) > 0 || IPV4_GET_RAW_FLAG_MF(ip4h))) { Packet *rp = Defrag(tv, dtv, p); if (rp != NULL) { - PacketEnqueueNoLock(&tv->decode_pq, rp); + PacketEnqueueNoLock(&dtv->decode_pq, rp); } p->flags |= PKT_IS_FRAGMENT; return TM_ECODE_OK; @@ -591,7 +591,7 @@ int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, Packet *tp = PacketTunnelPktSetup(tv, dtv, p, data, data_len, DECODE_TUNNEL_IPV6); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV4); - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } FlowSetupPacket(p); break; @@ -1307,7 +1307,7 @@ static int DecodeIPV4DefragTest01(void) DecodeIPV4(&tv, &dtv, p, GET_PKT_DATA(p) + ETHERNET_HEADER_LEN, GET_PKT_LEN(p) - ETHERNET_HEADER_LEN); FAIL_IF(PacketIsTCP(p)); - Packet *tp = PacketDequeueNoLock(&tv.decode_pq); + Packet *tp = PacketDequeueNoLock(&dtv.decode_pq); FAIL_IF_NULL(tp); FAIL_IF(tp->recursion_level != p->recursion_level); FAIL_IF_NOT(PacketIsIPv4(tp)); @@ -1404,7 +1404,7 @@ static int DecodeIPV4DefragTest02(void) DecodeIPV4(&tv, &dtv, p, GET_PKT_DATA(p) + ETHERNET_HEADER_LEN, GET_PKT_LEN(p) - ETHERNET_HEADER_LEN); FAIL_IF(PacketIsTCP(p)); - Packet *tp = PacketDequeueNoLock(&tv.decode_pq); + Packet *tp = PacketDequeueNoLock(&dtv.decode_pq); FAIL_IF_NULL(tp); FAIL_IF(tp->recursion_level != p->recursion_level); FAIL_IF_NOT(PacketIsIPv4(tp)); @@ -1502,7 +1502,7 @@ static int DecodeIPV4DefragTest03(void) GET_PKT_LEN(p) - ETHERNET_HEADER_LEN); FAIL_IF(PacketIsTCP(p)); - Packet *tp = PacketDequeueNoLock(&tv.decode_pq); + Packet *tp = PacketDequeueNoLock(&dtv.decode_pq); FAIL_IF_NULL(tp); FAIL_IF(!(tp->flags & PKT_WANTS_FLOW)); FAIL_IF(tp->flow_hash != p->flow_hash); diff --git a/src/decode-ipv6.c b/src/decode-ipv6.c index c732d7938d3b..2c4e4e8ce403 100644 --- a/src/decode-ipv6.c +++ b/src/decode-ipv6.c @@ -52,7 +52,7 @@ static void DecodeIPv4inIPv6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, c Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt, plen, DECODE_TUNNEL_IPV4); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV6); - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); StatsIncr(tv, dtv->counter_ipv4inipv6); return; } @@ -77,7 +77,7 @@ static int DecodeIP6inIP6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, Packet *tp = PacketTunnelPktSetup(tv, dtv, p, pkt, plen, DECODE_TUNNEL_IPV6); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_IPV6); - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); StatsIncr(tv, dtv->counter_ipv6inipv6); } } else { @@ -642,7 +642,7 @@ int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t * if (IPV6_EXTHDR_ISSET_FH(p)) { Packet *rp = Defrag(tv, dtv, p); if (rp != NULL) { - PacketEnqueueNoLock(&tv->decode_pq,rp); + PacketEnqueueNoLock(&dtv->decode_pq, rp); } } @@ -797,7 +797,7 @@ static int DecodeIPV6FragTest01 (void) goto end; } - if (tv.decode_pq.len != 1) { + if (dtv.decode_pq.len != 1) { printf("no reassembled packet: "); goto end; } @@ -808,11 +808,11 @@ static int DecodeIPV6FragTest01 (void) PacketRecycle(p2); SCFree(p1); SCFree(p2); - pkt = PacketDequeueNoLock(&tv.decode_pq); + pkt = PacketDequeueNoLock(&dtv.decode_pq); while (pkt != NULL) { PacketRecycle(pkt); SCFree(pkt); - pkt = PacketDequeueNoLock(&tv.decode_pq); + pkt = PacketDequeueNoLock(&dtv.decode_pq); } DefragDestroy(); FlowShutdown(); diff --git a/src/decode-teredo.c b/src/decode-teredo.c index bbeda3efa398..8a83b7e50265 100644 --- a/src/decode-teredo.c +++ b/src/decode-teredo.c @@ -189,7 +189,7 @@ int DecodeTeredo(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_TEREDO); /* add the tp to the packet queue. */ - PacketEnqueueNoLock(&tv->decode_pq,tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); StatsIncr(tv, dtv->counter_teredo); return TM_ECODE_OK; } diff --git a/src/decode-vxlan.c b/src/decode-vxlan.c index a8473de052c6..7f8522ee3650 100644 --- a/src/decode-vxlan.c +++ b/src/decode-vxlan.c @@ -182,7 +182,7 @@ int DecodeVXLAN(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, len - (VXLAN_HEADER_LEN + ETHERNET_HEADER_LEN), decode_tunnel_proto); if (tp != NULL) { PKT_SET_SRC(tp, PKT_SRC_DECODER_VXLAN); - PacketEnqueueNoLock(&tv->decode_pq, tp); + PacketEnqueueNoLock(&dtv->decode_pq, tp); } } @@ -219,9 +219,9 @@ static int DecodeVXLANtest01 (void) DecodeUDP(&tv, &dtv, p, raw_vxlan, sizeof(raw_vxlan)); FAIL_IF_NOT(PacketIsUDP(p)); - FAIL_IF(tv.decode_pq.top == NULL); + FAIL_IF(dtv.decode_pq.top == NULL); - Packet *tp = PacketDequeueNoLock(&tv.decode_pq); + Packet *tp = PacketDequeueNoLock(&dtv.decode_pq); FAIL_IF_NOT(PacketIsUDP(tp)); FAIL_IF_NOT(tp->sp == 53); @@ -258,7 +258,7 @@ static int DecodeVXLANtest02 (void) DecodeUDP(&tv, &dtv, p, raw_vxlan, sizeof(raw_vxlan)); FAIL_IF_NOT(PacketIsUDP(p)); - FAIL_IF(tv.decode_pq.top != NULL); + FAIL_IF(dtv.decode_pq.top != NULL); DecodeVXLANConfigPorts(VXLAN_DEFAULT_PORT_S); /* reset */ FlowShutdown(); diff --git a/src/decode.h b/src/decode.h index eafdf35f4d5f..e4971a01cdff 100644 --- a/src/decode.h +++ b/src/decode.h @@ -944,6 +944,9 @@ static inline bool PacketIsARP(const Packet *p) /** \brief Structure to hold thread specific data for all decode modules */ typedef struct DecodeThreadVars_ { + /** packet queue for decoders to store tunnel packets. */ + PacketQueueNoLock decode_pq; + /** Specific context for udp protocol detection (here atm) */ AppLayerThreadCtx *app_tctx; diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index c7f61fb00c58..6c44eba94c42 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -754,8 +754,8 @@ int RunModeIdsAFPAutoFp(void) FatalError("Unable to init peers list."); } - ret = RunModeSetLiveCaptureAutoFp(ParseAFPConfig, AFPConfigGeThreadsCount, "ReceiveAFP", - "DecodeAFP", thread_name_autofp, live_dev); + ret = RunModeSetLiveCaptureAutoFp(ParseAFPConfig, AFPConfigGeThreadsCount, "ReceiveAFP", NULL, + thread_name_autofp, live_dev); if (ret != 0) { FatalError("Unable to start runmode"); } @@ -789,11 +789,8 @@ int RunModeIdsAFPSingle(void) FatalError("Unable to init peers list."); } - ret = RunModeSetLiveCaptureSingle(ParseAFPConfig, - AFPConfigGeThreadsCount, - "ReceiveAFP", - "DecodeAFP", thread_name_single, - live_dev); + ret = RunModeSetLiveCaptureSingle(ParseAFPConfig, AFPConfigGeThreadsCount, "ReceiveAFP", NULL, + thread_name_single, live_dev); if (ret != 0) { FatalError("Unable to start runmode"); } @@ -830,8 +827,8 @@ int RunModeIdsAFPWorkers(void) FatalError("Unable to init peers list."); } - ret = RunModeSetLiveCaptureWorkers(ParseAFPConfig, AFPConfigGeThreadsCount, "ReceiveAFP", - "DecodeAFP", thread_name_workers, live_dev); + ret = RunModeSetLiveCaptureWorkers(ParseAFPConfig, AFPConfigGeThreadsCount, "ReceiveAFP", NULL, + thread_name_workers, live_dev); if (ret != 0) { FatalError("Unable to start runmode"); } diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index 0e814cbec9c0..fad98e9766d3 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -1724,7 +1724,7 @@ int RunModeIdsDpdkWorkers(void) InitEal(); ret = RunModeSetLiveCaptureWorkers(ParseDpdkConfigAndConfigureDevice, DPDKConfigGetThreadsCount, - "ReceiveDPDK", "DecodeDPDK", thread_name_workers, NULL); + "ReceiveDPDK", NULL, thread_name_workers, NULL); if (ret != 0) { FatalError("Unable to start runmode"); } diff --git a/src/runmode-pcap-file.c b/src/runmode-pcap-file.c index e820eca10c6b..cb51d6759bb3 100644 --- a/src/runmode-pcap-file.c +++ b/src/runmode-pcap-file.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2023 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -80,12 +80,6 @@ int RunModeFilePcapSingle(void) } TmSlotSetFuncAppend(tv, tm_module, file); - tm_module = TmModuleGetByName("DecodePcapFile"); - if (tm_module == NULL) { - FatalError("TmModuleGetByName DecodePcap failed"); - } - TmSlotSetFuncAppend(tv, tm_module, NULL); - tm_module = TmModuleGetByName("FlowWorker"); if (tm_module == NULL) { FatalError("TmModuleGetByName for FlowWorker failed"); @@ -175,12 +169,6 @@ int RunModeFilePcapAutoFp(void) } TmSlotSetFuncAppend(tv_receivepcap, tm_module, file); - tm_module = TmModuleGetByName("DecodePcapFile"); - if (tm_module == NULL) { - FatalError("TmModuleGetByName DecodePcap failed"); - } - TmSlotSetFuncAppend(tv_receivepcap, tm_module, NULL); - TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET); if (TmThreadSpawn(tv_receivepcap) != TM_ECODE_OK) { diff --git a/src/runmode-pcap.c b/src/runmode-pcap.c index ec881ced4a87..0fae945ab858 100644 --- a/src/runmode-pcap.c +++ b/src/runmode-pcap.c @@ -234,11 +234,8 @@ int RunModeIdsPcapSingle(void) (void)ConfGet("pcap.single-pcap-dev", &live_dev); - ret = RunModeSetLiveCaptureSingle(ParsePcapConfig, - PcapConfigGeThreadsCount, - "ReceivePcap", - "DecodePcap", thread_name_single, - live_dev); + ret = RunModeSetLiveCaptureSingle(ParsePcapConfig, PcapConfigGeThreadsCount, "ReceivePcap", + NULL, thread_name_single, live_dev); if (ret != 0) { FatalError("Runmode start failed"); } @@ -274,7 +271,7 @@ int RunModeIdsPcapAutoFp(void) (void) ConfGet("pcap.single-pcap-dev", &live_dev); ret = RunModeSetLiveCaptureAutoFp(ParsePcapConfig, PcapConfigGeThreadsCount, "ReceivePcap", - "DecodePcap", thread_name_autofp, live_dev); + NULL, thread_name_autofp, live_dev); if (ret != 0) { FatalError("Runmode start failed"); } @@ -301,7 +298,7 @@ int RunModeIdsPcapWorkers(void) (void) ConfGet("pcap.single-pcap-dev", &live_dev); ret = RunModeSetLiveCaptureWorkers(ParsePcapConfig, PcapConfigGeThreadsCount, "ReceivePcap", - "DecodePcap", thread_name_workers, live_dev); + NULL, thread_name_workers, live_dev); if (ret != 0) { FatalError("Unable to start runmode"); } diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 1054aaead754..783868146af0 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011-2021 Open Information Security Foundation +/* Copyright (C) 2011-2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -135,19 +135,6 @@ void TmModuleReceiveAFPRegister (void) tmm_modules[TMM_RECEIVEAFP].flags = TM_FLAG_RECEIVE_TM; } -/** - * \brief Registration Function for DecodeAFP. - */ -void TmModuleDecodeAFPRegister (void) -{ - tmm_modules[TMM_DECODEAFP].name = "DecodeAFP"; - tmm_modules[TMM_DECODEAFP].ThreadInit = NoAFPSupportExit; - tmm_modules[TMM_DECODEAFP].Func = NULL; - tmm_modules[TMM_DECODEAFP].ThreadExitPrintStats = NULL; - tmm_modules[TMM_DECODEAFP].ThreadDeinit = NULL; - tmm_modules[TMM_DECODEAFP].cap_flags = 0; -} - /** * \brief this function prints an error message and exits. */ @@ -272,6 +259,7 @@ typedef struct AFPThreadVars_ ThreadVars *tv; TmSlot *slot; + DecodeThreadVars *dtv; LiveDevice *livedev; /* data link type for the thread */ uint32_t datalink; @@ -365,9 +353,7 @@ static void ReceiveAFPThreadExitStats(ThreadVars *, void *); static TmEcode ReceiveAFPThreadDeinit(ThreadVars *, void *); static TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot); -static TmEcode DecodeAFPThreadInit(ThreadVars *, const void *, void **); -static TmEcode DecodeAFPThreadDeinit(ThreadVars *tv, void *data); -static TmEcode DecodeAFP(ThreadVars *, Packet *, void *); +static void DecodeAFP(ThreadVars *, DecodeThreadVars *, Packet *); static TmEcode AFPSetBPFFilter(AFPThreadVars *ptv); static int AFPGetIfnumByDev(int fd, const char *ifname, int verbose); @@ -594,21 +580,6 @@ void AFPPeersListClean(void) * @} */ -/** - * \brief Registration Function for DecodeAFP. - * \todo Unit tests are needed for this module. - */ -void TmModuleDecodeAFPRegister (void) -{ - tmm_modules[TMM_DECODEAFP].name = "DecodeAFP"; - tmm_modules[TMM_DECODEAFP].ThreadInit = DecodeAFPThreadInit; - tmm_modules[TMM_DECODEAFP].Func = DecodeAFP; - tmm_modules[TMM_DECODEAFP].ThreadExitPrintStats = NULL; - tmm_modules[TMM_DECODEAFP].ThreadDeinit = DecodeAFPThreadDeinit; - tmm_modules[TMM_DECODEAFP].cap_flags = 0; -} - - static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose); static inline void AFPDumpCounters(AFPThreadVars *ptv) @@ -935,6 +906,7 @@ static int AFPReadFromRing(AFPThreadVars *ptv) } AFPReadFromRingSetupPacket(ptv, h, tp_status, p); + DecodeAFP(ptv->tv, ptv->dtv, p); if (TmThreadsSlotProcessPkt(ptv->tv, ptv->slot, p) != TM_ECODE_OK) { return AFPSuriFailure(ptv, h); } @@ -1008,6 +980,7 @@ static inline int AFPParsePacketV3(AFPThreadVars *ptv, struct tpacket_block_desc } } + DecodeAFP(ptv->tv, ptv->dtv, p); if (TmThreadsSlotProcessPkt(ptv->tv, ptv->slot, p) != TM_ECODE_OK) { SCReturnInt(AFP_SURI_FAILURE); } @@ -2498,6 +2471,13 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, const void *initdata, void **data) afpconfig->DerefFunc(afpconfig); SCReturnInt(TM_ECODE_FAILED); } + ptv->dtv = DecodeThreadVarsAlloc(tv); + if (ptv->dtv == NULL) { + ReceiveAFPThreadDeinit(tv, ptv); + afpconfig->DerefFunc(afpconfig); + SCReturnInt(TM_ECODE_FAILED); + } + DecodeRegisterPerfCounters(ptv->dtv, tv); ptv->tv = tv; @@ -2507,7 +2487,7 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, const void *initdata, void **data) ptv->livedev = LiveGetDevice(ptv->iface); if (ptv->livedev == NULL) { SCLogError("Unable to find Live device"); - SCFree(ptv); + ReceiveAFPThreadDeinit(tv, ptv); SCReturnInt(TM_ECODE_FAILED); } @@ -2592,7 +2572,7 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, const void *initdata, void **data) if (AFPPeersListAdd(ptv) == TM_ECODE_FAILED) { - SCFree(ptv); + ReceiveAFPThreadDeinit(tv, ptv); afpconfig->DerefFunc(afpconfig); SCReturnInt(TM_ECODE_FAILED); } @@ -2655,6 +2635,9 @@ TmEcode ReceiveAFPThreadDeinit(ThreadVars *tv, void *data) SCFree(ptv->ring.v2); } + if (ptv->dtv) { + DecodeThreadVarsFree(tv, ptv->dtv); + } SCFree(ptv); SCReturnInt(TM_ECODE_OK); } @@ -2693,16 +2676,14 @@ static void UpdateRawDataForVLANHdr(Packet *p) * DecodeAFP decodes packets from AF_PACKET and passes * them off to the proper link type decoder. * - * \param t pointer to ThreadVars + * \param tv pointer to ThreadVars + * \param dtv pointer to decoder thread vars * \param p pointer to the current packet * \param data pointer that gets cast into AFPThreadVars for ptv */ -TmEcode DecodeAFP(ThreadVars *tv, Packet *p, void *data) +static void DecodeAFP(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p) { - SCEnter(); - const bool afp_vlan_hdr = p->vlan_idx != 0; - DecodeThreadVars *dtv = (DecodeThreadVars *)data; DEBUG_VALIDATE_BUG_ON(PKT_IS_PSEUDOPKT(p)); @@ -2718,29 +2699,6 @@ TmEcode DecodeAFP(ThreadVars *tv, Packet *p, void *data) } PacketDecodeFinalize(tv, dtv, p); - - SCReturnInt(TM_ECODE_OK); -} - -TmEcode DecodeAFPThreadInit(ThreadVars *tv, const void *initdata, void **data) -{ - SCEnter(); - DecodeThreadVars *dtv = DecodeThreadVarsAlloc(tv); - if (dtv == NULL) - SCReturnInt(TM_ECODE_FAILED); - - DecodeRegisterPerfCounters(dtv, tv); - - *data = (void *)dtv; - - SCReturnInt(TM_ECODE_OK); -} - -TmEcode DecodeAFPThreadDeinit(ThreadVars *tv, void *data) -{ - if (data != NULL) - DecodeThreadVarsFree(tv, data); - SCReturnInt(TM_ECODE_OK); } #endif /* HAVE_AF_PACKET */ diff --git a/src/source-af-packet.h b/src/source-af-packet.h index 6785f2fb52d7..348bac4ab144 100644 --- a/src/source-af-packet.h +++ b/src/source-af-packet.h @@ -183,8 +183,7 @@ typedef struct AFPPacketVars_ * @} */ -void TmModuleReceiveAFPRegister (void); -void TmModuleDecodeAFPRegister (void); +void TmModuleReceiveAFPRegister(void); TmEcode AFPPeersListInit(void); TmEcode AFPPeersListCheck(void); diff --git a/src/source-dpdk.c b/src/source-dpdk.c index 93238b041473..c73d1d9c9c74 100644 --- a/src/source-dpdk.c +++ b/src/source-dpdk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2021-2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -58,19 +58,6 @@ void TmModuleReceiveDPDKRegister(void) tmm_modules[TMM_RECEIVEDPDK].flags = TM_FLAG_RECEIVE_TM; } -/** - * \brief Registration Function for DecodeDPDK. - */ -void TmModuleDecodeDPDKRegister(void) -{ - tmm_modules[TMM_DECODEDPDK].name = "DecodeDPDK"; - tmm_modules[TMM_DECODEDPDK].ThreadInit = NoDPDKSupportExit; - tmm_modules[TMM_DECODEDPDK].Func = NULL; - tmm_modules[TMM_DECODEDPDK].ThreadExitPrintStats = NULL; - tmm_modules[TMM_DECODEDPDK].ThreadDeinit = NULL; - tmm_modules[TMM_DECODEDPDK].cap_flags = 0; -} - /** * \brief this function prints an error message and exits. */ @@ -107,6 +94,7 @@ typedef struct DPDKThreadVars_ { /* counters */ uint64_t pkts; ThreadVars *tv; + DecodeThreadVars *dtv; TmSlot *slot; LiveDevice *livedev; ChecksumValidationMode checksum_mode; @@ -141,9 +129,7 @@ static void ReceiveDPDKThreadExitStats(ThreadVars *, void *); static TmEcode ReceiveDPDKThreadDeinit(ThreadVars *, void *); static TmEcode ReceiveDPDKLoop(ThreadVars *tv, void *data, void *slot); -static TmEcode DecodeDPDKThreadInit(ThreadVars *, const void *, void **); -static TmEcode DecodeDPDKThreadDeinit(ThreadVars *tv, void *data); -static TmEcode DecodeDPDK(ThreadVars *, Packet *, void *); +static void DecodeDPDK(ThreadVars *, Packet *, DecodeThreadVars *); static uint64_t CyclesToMicroseconds(uint64_t cycles); static uint64_t CyclesToSeconds(uint64_t cycles); @@ -310,20 +296,6 @@ void TmModuleReceiveDPDKRegister(void) tmm_modules[TMM_RECEIVEDPDK].flags = TM_FLAG_RECEIVE_TM; } -/** - * \brief Registration Function for DecodeDPDK. - * \todo Unit tests are needed for this module. - */ -void TmModuleDecodeDPDKRegister(void) -{ - tmm_modules[TMM_DECODEDPDK].name = "DecodeDPDK"; - tmm_modules[TMM_DECODEDPDK].ThreadInit = DecodeDPDKThreadInit; - tmm_modules[TMM_DECODEDPDK].Func = DecodeDPDK; - tmm_modules[TMM_DECODEDPDK].ThreadExitPrintStats = NULL; - tmm_modules[TMM_DECODEDPDK].ThreadDeinit = DecodeDPDKThreadDeinit; - tmm_modules[TMM_DECODEDPDK].cap_flags = 0; -} - static inline void DPDKDumpCounters(DPDKThreadVars *ptv) { /* Some NICs (e.g. Intel) do not support queue statistics and the drops can be fetched only on @@ -595,6 +567,7 @@ static TmEcode ReceiveDPDKLoop(ThreadVars *tv, void *data, void *slot) DPDKSegmentedMbufWarning(ptv->received_mbufs[i]); PacketSetData(p, rte_pktmbuf_mtod(p->dpdk_v.mbuf, uint8_t *), rte_pktmbuf_pkt_len(p->dpdk_v.mbuf)); + DecodeDPDK(tv, p, ptv->dtv); if (TmThreadsSlotProcessPkt(ptv->tv, ptv->slot, p) != TM_ECODE_OK) { TmqhOutputPacketpool(ptv->tv, p); DPDKFreeMbufArray(ptv->received_mbufs, nb_rx - i - 1, i + 1); @@ -634,6 +607,12 @@ static TmEcode ReceiveDPDKThreadInit(ThreadVars *tv, const void *initdata, void SCLogError("Unable to allocate memory"); goto fail; } + ptv->dtv = DecodeThreadVarsAlloc(tv); + if (unlikely(tv == NULL)) { + SCLogError("Unable to allocate memory"); + goto fail; + } + DecodeRegisterPerfCounters(ptv->dtv, tv); ptv->tv = tv; ptv->pkts = 0; @@ -712,8 +691,9 @@ static TmEcode ReceiveDPDKThreadInit(ThreadVars *tv, const void *initdata, void fail: if (dpdk_config != NULL) dpdk_config->DerefFunc(dpdk_config); - if (ptv != NULL) - SCFree(ptv); + if (ptv != NULL) { + ReceiveDPDKThreadDeinit(tv, ptv); + } SCReturnInt(TM_ECODE_FAILED); } @@ -819,6 +799,9 @@ static TmEcode ReceiveDPDKThreadDeinit(ThreadVars *tv, void *data) ptv->pkt_mempool = NULL; // MP is released when device is closed + if (ptv->dtv != NULL) { + DecodeThreadVarsFree(tv, ptv->dtv); + } SCFree(ptv); SCReturnInt(TM_ECODE_OK); } @@ -831,15 +814,10 @@ static TmEcode ReceiveDPDKThreadDeinit(ThreadVars *tv, void *data) * * \param t pointer to ThreadVars * \param p pointer to the current packet - * \param data pointer that gets cast into DPDKThreadVars for ptv + * \param dtv DecodeThreadVars */ -static TmEcode DecodeDPDK(ThreadVars *tv, Packet *p, void *data) +static void DecodeDPDK(ThreadVars *tv, Packet *p, DecodeThreadVars *dtv) { - SCEnter(); - DecodeThreadVars *dtv = (DecodeThreadVars *)data; - - BUG_ON(PKT_IS_PSEUDOPKT(p)); - /* update counters */ DecodeUpdatePacketCounters(tv, dtv, p); @@ -852,33 +830,6 @@ static TmEcode DecodeDPDK(ThreadVars *tv, Packet *p, void *data) DecodeLinkLayer(tv, dtv, p->datalink, p, GET_PKT_DATA(p), GET_PKT_LEN(p)); PacketDecodeFinalize(tv, dtv, p); - - SCReturnInt(TM_ECODE_OK); -} - -static TmEcode DecodeDPDKThreadInit(ThreadVars *tv, const void *initdata, void **data) -{ - SCEnter(); - DecodeThreadVars *dtv = NULL; - - dtv = DecodeThreadVarsAlloc(tv); - - if (dtv == NULL) - SCReturnInt(TM_ECODE_FAILED); - - DecodeRegisterPerfCounters(dtv, tv); - - *data = (void *)dtv; - - SCReturnInt(TM_ECODE_OK); -} - -static TmEcode DecodeDPDKThreadDeinit(ThreadVars *tv, void *data) -{ - SCEnter(); - if (data != NULL) - DecodeThreadVarsFree(tv, data); - SCReturnInt(TM_ECODE_OK); } #endif /* HAVE_DPDK */ diff --git a/src/source-dpdk.h b/src/source-dpdk.h index 36617134d6fd..36a347362f65 100644 --- a/src/source-dpdk.h +++ b/src/source-dpdk.h @@ -97,6 +97,5 @@ typedef struct DPDKPacketVars_ { } DPDKPacketVars; void TmModuleReceiveDPDKRegister(void); -void TmModuleDecodeDPDKRegister(void); #endif /* SURICATA_SOURCE_DPDK_H */ diff --git a/src/source-pcap-file-helper.c b/src/source-pcap-file-helper.c index 4984a44bff76..d947af7bc2e3 100644 --- a/src/source-pcap-file-helper.c +++ b/src/source-pcap-file-helper.c @@ -30,6 +30,7 @@ #include "util-profiling.h" #include "source-pcap-file.h" #include "util-exception-policy.h" +#include "tm-threads.h" extern uint16_t max_pending_packets; extern PcapFileGlobalVars pcap_g; @@ -105,6 +106,33 @@ void PcapFileCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt) PACKET_PROFILING_TMM_END(p, TMM_RECEIVEPCAPFILE); + /* update counters */ + DecodeUpdatePacketCounters(ptv->shared->tv, ptv->shared->dtv, p); + + DecoderFunc DecoderFn; + if (ValidateLinkType(p->datalink, &DecoderFn) == TM_ECODE_OK) { + + /* call the decoder */ + DecoderFn(ptv->shared->tv, ptv->shared->dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p)); + +#ifdef DEBUG + BUG_ON(p->pkt_src != PKT_SRC_WIRE && p->pkt_src != PKT_SRC_FFR); +#endif + + PacketDecodeFinalize(ptv->shared->tv, ptv->shared->dtv, p); + + if (TmThreadsProcessDecodePseudoPackets(ptv->shared->tv, &ptv->shared->dtv->decode_pq, + ptv->shared->slot) != TM_ECODE_OK) { + pcap_breakloop(ptv->pcap_handle); + ptv->shared->cb_result = TM_ECODE_FAILED; + SCReturn; + } + } else { + pcap_breakloop(ptv->pcap_handle); + ptv->shared->cb_result = TM_ECODE_FAILED; + SCReturn; + } + if (TmThreadsSlotProcessPkt(ptv->shared->tv, ptv->shared->slot, p) != TM_ECODE_OK) { pcap_breakloop(ptv->pcap_handle); ptv->shared->cb_result = TM_ECODE_FAILED; diff --git a/src/source-pcap-file-helper.h b/src/source-pcap-file-helper.h index ec5444887f81..4b74c4f38fc5 100644 --- a/src/source-pcap-file-helper.h +++ b/src/source-pcap-file-helper.h @@ -49,6 +49,7 @@ typedef struct PcapFileSharedVars_ ThreadVars *tv; TmSlot *slot; + DecodeThreadVars *dtv; /* counters */ uint64_t pkts; diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c index 611d07332f8e..72309c95b3db 100644 --- a/src/source-pcap-file.c +++ b/src/source-pcap-file.c @@ -61,10 +61,6 @@ static TmEcode ReceivePcapFileThreadInit(ThreadVars *, const void *, void **); static void ReceivePcapFileThreadExitStats(ThreadVars *, void *); static TmEcode ReceivePcapFileThreadDeinit(ThreadVars *, void *); -static TmEcode DecodePcapFile(ThreadVars *, Packet *, void *); -static TmEcode DecodePcapFileThreadInit(ThreadVars *, const void *, void **); -static TmEcode DecodePcapFileThreadDeinit(ThreadVars *tv, void *data); - static void CleanupPcapDirectoryFromThreadVars(PcapFileThreadVars *tv, PcapFileDirectoryVars *ptv); static void CleanupPcapFileFromThreadVars(PcapFileThreadVars *tv, PcapFileFileVars *pfv); @@ -104,6 +100,7 @@ static void CleanupPcapFileThreadVars(ThreadVars *tv, PcapFileThreadVars *ptv) SCFree(ptv->shared.bpf_string); ptv->shared.bpf_string = NULL; } + DecodeThreadVarsFree(tv, ptv->shared.dtv); SCFree(ptv); } } @@ -124,16 +121,6 @@ void TmModuleReceivePcapFileRegister (void) tmm_modules[TMM_RECEIVEPCAPFILE].flags = TM_FLAG_RECEIVE_TM; } -void TmModuleDecodePcapFileRegister (void) -{ - tmm_modules[TMM_DECODEPCAPFILE].name = "DecodePcapFile"; - tmm_modules[TMM_DECODEPCAPFILE].ThreadInit = DecodePcapFileThreadInit; - tmm_modules[TMM_DECODEPCAPFILE].Func = DecodePcapFile; - tmm_modules[TMM_DECODEPCAPFILE].ThreadExitPrintStats = NULL; - tmm_modules[TMM_DECODEPCAPFILE].ThreadDeinit = DecodePcapFileThreadDeinit; - tmm_modules[TMM_DECODEPCAPFILE].cap_flags = 0; -} - void PcapFileGlobalInit(void) { memset(&pcap_g, 0x00, sizeof(pcap_g)); @@ -210,6 +197,13 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, const void *initdata, void **d } memset(&ptv->shared.last_processed, 0, sizeof(struct timespec)); + ptv->shared.dtv = DecodeThreadVarsAlloc(tv); + if (ptv->shared.dtv == NULL) { + CleanupPcapFileThreadVars(tv, ptv); + SCReturnInt(TM_ECODE_FAILED); + } + DecodeRegisterPerfCounters(ptv->shared.dtv, tv); + intmax_t tenant = 0; if (ConfGetInt("pcap-file.tenant-id", &tenant) == 1) { if (tenant > 0 && tenant < UINT_MAX) { @@ -399,60 +393,7 @@ TmEcode ReceivePcapFileThreadDeinit(ThreadVars *tv, void *data) SCReturnInt(TM_ECODE_OK); } -static TmEcode DecodePcapFile(ThreadVars *tv, Packet *p, void *data) -{ - SCEnter(); - DecodeThreadVars *dtv = (DecodeThreadVars *)data; - - BUG_ON(PKT_IS_PSEUDOPKT(p)); - - /* update counters */ - DecodeUpdatePacketCounters(tv, dtv, p); - - DecoderFunc decoder; - if(ValidateLinkType(p->datalink, &decoder) == TM_ECODE_OK) { - - /* call the decoder */ - decoder(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p)); - -#ifdef DEBUG - BUG_ON(p->pkt_src != PKT_SRC_WIRE && p->pkt_src != PKT_SRC_FFR); -#endif - - PacketDecodeFinalize(tv, dtv, p); - - SCReturnInt(TM_ECODE_OK); - } else { - SCReturnInt(TM_ECODE_FAILED); - } -} - -TmEcode DecodePcapFileThreadInit(ThreadVars *tv, const void *initdata, void **data) -{ - SCEnter(); - DecodeThreadVars *dtv = NULL; - dtv = DecodeThreadVarsAlloc(tv); - - if (dtv == NULL) - SCReturnInt(TM_ECODE_FAILED); - - DecodeRegisterPerfCounters(dtv, tv); - - *data = (void *)dtv; - - SCReturnInt(TM_ECODE_OK); -} - -TmEcode DecodePcapFileThreadDeinit(ThreadVars *tv, void *data) -{ - if (data != NULL) - DecodeThreadVarsFree(tv, data); - SCReturnInt(TM_ECODE_OK); -} - void PcapIncreaseInvalidChecksum(void) { (void) SC_ATOMIC_ADD(pcap_g.invalid_checksums, 1); } - -/* eof */ diff --git a/src/source-pcap.c b/src/source-pcap.c index e8a232b8f3e3..fe422b1473f3 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -95,6 +95,7 @@ typedef struct PcapThreadVars_ ThreadVars *tv; TmSlot *slot; + DecodeThreadVars *dtv; /** callback result -- set if one of the thread module failed. */ int cb_result; @@ -117,10 +118,6 @@ static void ReceivePcapThreadExitStats(ThreadVars *, void *); static TmEcode ReceivePcapLoop(ThreadVars *tv, void *data, void *slot); static TmEcode ReceivePcapBreakLoop(ThreadVars *tv, void *data); -static TmEcode DecodePcapThreadInit(ThreadVars *, const void *, void **); -static TmEcode DecodePcapThreadDeinit(ThreadVars *tv, void *data); -static TmEcode DecodePcap(ThreadVars *, Packet *, void *); - #ifdef UNITTESTS static void SourcePcapRegisterTests(void); #endif @@ -147,17 +144,6 @@ void TmModuleReceivePcapRegister (void) #endif } -/** - * \brief Registration Function for DecodePcap. - */ -void TmModuleDecodePcapRegister (void) -{ - tmm_modules[TMM_DECODEPCAP].name = "DecodePcap"; - tmm_modules[TMM_DECODEPCAP].ThreadInit = DecodePcapThreadInit; - tmm_modules[TMM_DECODEPCAP].Func = DecodePcap; - tmm_modules[TMM_DECODEPCAP].ThreadDeinit = DecodePcapThreadDeinit; -} - /** * \brief Update 64 bit |last| value from |current32| value taking one * wrap-around into account. @@ -364,6 +350,20 @@ static void PcapCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt) break; } + /* update counters */ + DecodeUpdatePacketCounters(ptv->tv, ptv->dtv, p); + + DecodeLinkLayer(ptv->tv, ptv->dtv, p->datalink, p, GET_PKT_DATA(p), GET_PKT_LEN(p)); + + PacketDecodeFinalize(ptv->tv, ptv->dtv, p); + + if (TmThreadsProcessDecodePseudoPackets(ptv->tv, &ptv->dtv->decode_pq, ptv->slot) != + TM_ECODE_OK) { + pcap_breakloop(ptv->pcap_handle); + ptv->cb_result = TM_ECODE_FAILED; + SCReturn; + } + if (TmThreadsSlotProcessPkt(ptv->tv, ptv->slot, p) != TM_ECODE_OK) { pcap_breakloop(ptv->pcap_handle); ptv->cb_result = TM_ECODE_FAILED; @@ -491,6 +491,14 @@ static TmEcode ReceivePcapThreadInit(ThreadVars *tv, const void *initdata, void ptv->tv = tv; + ptv->dtv = DecodeThreadVarsAlloc(tv); + if (ptv->dtv == NULL) { + pcapconfig->DerefFunc(pcapconfig); + ReceivePcapThreadDeinit(tv, ptv); + SCReturnInt(TM_ECODE_FAILED); + } + DecodeRegisterPerfCounters(ptv->dtv, tv); + ptv->livedev = LiveGetDevice(pcapconfig->iface); if (ptv->livedev == NULL) { SCLogError("unable to find Live device"); @@ -598,60 +606,12 @@ static TmEcode ReceivePcapThreadDeinit(ThreadVars *tv, void *data) if (ptv->filter.bf_insns) { SCBPFFree(&ptv->filter); } + DecodeThreadVarsFree(tv, ptv->dtv); SCFree(ptv); } SCReturnInt(TM_ECODE_OK); } -/** - * \brief This function passes off to link type decoders. - * - * DecodePcap decodes packets from libpcap and passes - * them off to the proper link type decoder. - * - * \param t pointer to ThreadVars - * \param p pointer to the current packet - * \param data pointer that gets cast into PcapThreadVars for ptv - */ -static TmEcode DecodePcap(ThreadVars *tv, Packet *p, void *data) -{ - SCEnter(); - DecodeThreadVars *dtv = (DecodeThreadVars *)data; - - BUG_ON(PKT_IS_PSEUDOPKT(p)); - - /* update counters */ - DecodeUpdatePacketCounters(tv, dtv, p); - - DecodeLinkLayer(tv, dtv, p->datalink, p, GET_PKT_DATA(p), GET_PKT_LEN(p)); - - PacketDecodeFinalize(tv, dtv, p); - - SCReturnInt(TM_ECODE_OK); -} - -static TmEcode DecodePcapThreadInit(ThreadVars *tv, const void *initdata, void **data) -{ - SCEnter(); - - DecodeThreadVars *dtv = DecodeThreadVarsAlloc(tv); - if (dtv == NULL) - SCReturnInt(TM_ECODE_FAILED); - - DecodeRegisterPerfCounters(dtv, tv); - - *data = (void *)dtv; - - SCReturnInt(TM_ECODE_OK); -} - -static TmEcode DecodePcapThreadDeinit(ThreadVars *tv, void *data) -{ - if (data != NULL) - DecodeThreadVarsFree(tv, data); - SCReturnInt(TM_ECODE_OK); -} - void PcapTranslateIPToDevice(char *pcap_dev, size_t len) { char errbuf[PCAP_ERRBUF_SIZE]; diff --git a/src/source-pcap.h b/src/source-pcap.h index 51f68aa6b8b1..af239a41f783 100644 --- a/src/source-pcap.h +++ b/src/source-pcap.h @@ -24,8 +24,7 @@ #ifndef SURICATA_SOURCE_PCAP_H #define SURICATA_SOURCE_PCAP_H -void TmModuleReceivePcapRegister (void); -void TmModuleDecodePcapRegister (void); +void TmModuleReceivePcapRegister(void); void PcapTranslateIPToDevice(char *pcap_dev, size_t len); #define LIBPCAP_COPYWAIT 500 diff --git a/src/suricata.c b/src/suricata.c index 48a51b815f4b..06c04285ae56 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -905,13 +905,10 @@ void RegisterAllModules(void) TmModuleDecodeIPFWRegister(); /* pcap live */ TmModuleReceivePcapRegister(); - TmModuleDecodePcapRegister(); /* pcap file */ TmModuleReceivePcapFileRegister(); - TmModuleDecodePcapFileRegister(); /* af-packet */ TmModuleReceiveAFPRegister(); - TmModuleDecodeAFPRegister(); /* af-xdp */ TmModuleReceiveAFXDPRegister(); TmModuleDecodeAFXDPRegister(); @@ -952,7 +949,6 @@ void RegisterAllModules(void) /* Dpdk */ TmModuleReceiveDPDKRegister(); - TmModuleDecodeDPDKRegister(); } TmEcode SCLoadYamlConfig(void) diff --git a/src/tests/fuzz/fuzz_decodepcapfile.c b/src/tests/fuzz/fuzz_decodepcapfile.c index 2b616dd6906e..bc3345c26e75 100644 --- a/src/tests/fuzz/fuzz_decodepcapfile.c +++ b/src/tests/fuzz/fuzz_decodepcapfile.c @@ -30,7 +30,6 @@ pcap-file:\n\ "; ThreadVars *tv; -DecodeThreadVars *dtv; SC_ATOMIC_EXTERN(unsigned int, engine_stage); int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) @@ -70,13 +69,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) return 0; } TmSlotSetFuncAppend(tv, tm_module, "/tmp/fuzz.pcap"); - tm_module = TmModuleGetByName("DecodePcapFile"); - if (tm_module == NULL) { - return 0; - } - TmSlotSetFuncAppend(tv, tm_module, NULL); - tmm_modules[TMM_DECODEPCAPFILE].ThreadInit(tv, NULL, (void **) &dtv); - (void)SC_ATOMIC_SET(tv->tm_slots->slot_next->slot_data, dtv); extern uint16_t max_pending_packets; max_pending_packets = 128; diff --git a/src/threadvars.h b/src/threadvars.h index cebcdb4e3ac1..7addf3e5a39e 100644 --- a/src/threadvars.h +++ b/src/threadvars.h @@ -105,12 +105,6 @@ typedef struct ThreadVars_ { void *outctx; void (*tmqh_out)(struct ThreadVars_ *, struct Packet_ *); - /** Queue for decoders to temporarily store extra packets they - * generate. These packets are generated as part of the tunnel - * handling, and are processed directly after the "real" packet - * from the current position in the pipeline. */ - PacketQueueNoLock decode_pq; - /** Stream packet queue for flow time out injection. Either a pointer to the * workers input queue or to stream_pq_local */ struct PacketQueue_ *stream_pq; diff --git a/src/tm-modules.c b/src/tm-modules.c index b9542b48f083..d978e9abc4b4 100644 --- a/src/tm-modules.c +++ b/src/tm-modules.c @@ -200,9 +200,7 @@ const char * TmModuleTmmIdToString(TmmId id) CASE_CODE (TMM_VERDICTNFQ); CASE_CODE (TMM_RECEIVENFQ); CASE_CODE (TMM_RECEIVEPCAP); - CASE_CODE (TMM_RECEIVEPCAPFILE); - CASE_CODE (TMM_DECODEPCAP); - CASE_CODE (TMM_DECODEPCAPFILE); + CASE_CODE(TMM_RECEIVEPCAPFILE); CASE_CODE (TMM_RECEIVEPFRING); CASE_CODE (TMM_DECODEPFRING); CASE_CODE(TMM_RECEIVEDPDK); @@ -221,8 +219,7 @@ const char * TmModuleTmmIdToString(TmmId id) CASE_CODE (TMM_DECODENAPATECH); CASE_CODE (TMM_RECEIVEAFP); CASE_CODE(TMM_RECEIVEAFXDP); - CASE_CODE (TMM_ALERTPCAPINFO); - CASE_CODE (TMM_DECODEAFP); + CASE_CODE(TMM_ALERTPCAPINFO); CASE_CODE(TMM_DECODEAFXDP); CASE_CODE (TMM_STATSLOGGER); CASE_CODE (TMM_FLOWMANAGER); diff --git a/src/tm-threads-common.h b/src/tm-threads-common.h index fa9a731b0ddf..94c0fff28a61 100644 --- a/src/tm-threads-common.h +++ b/src/tm-threads-common.h @@ -53,7 +53,6 @@ typedef enum { TMM_DECODEERFDAG, TMM_RECEIVEAFP, TMM_RECEIVEAFXDP, - TMM_DECODEAFP, TMM_DECODEAFXDP, TMM_RECEIVEDPDK, TMM_DECODEDPDK, diff --git a/src/tm-threads.c b/src/tm-threads.c index 64c27a4235e6..266a85ea81a7 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -119,6 +119,7 @@ TmEcode TmThreadsProcessDecodePseudoPackets( DEBUG_VALIDATE_BUG_ON(extra_p->flow != NULL); if (TmThreadsSlotProcessPkt(tv, slot, extra_p) != TM_ECODE_OK) { + TmThreadsCleanDecodePQ(decode_pq); SCReturnInt(TM_ECODE_FAILED); } } @@ -142,12 +143,6 @@ TmEcode TmThreadsSlotVarRun(ThreadVars *tv, Packet *p, TmSlot *slot) TmThreadsSlotProcessPktFail(tv, NULL); return TM_ECODE_FAILED; } - if (s->tm_flags & TM_FLAG_DECODE_TM) { - if (TmThreadsProcessDecodePseudoPackets(tv, &tv->decode_pq, s->slot_next) != - TM_ECODE_OK) { - return TM_ECODE_FAILED; - } - } } return TM_ECODE_OK; @@ -2058,10 +2053,6 @@ static void TmThreadDumpThreads(void) tv, tv->stream_pq_local->len, PktSrcToString(xp->pkt_src)); } } - for (Packet *xp = tv->decode_pq.top; xp != NULL; xp = xp->next) { - SCLogNotice("tv %p: ==> decode_pq: decode_pq.len %u packet src %s", - tv, tv->decode_pq.len, PktSrcToString(xp->pkt_src)); - } TmThreadDoDumpSlots(tv); tv = tv->next; } diff --git a/src/tm-threads.h b/src/tm-threads.h index 67bea1411032..2629ace23214 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -146,7 +146,6 @@ static inline void TmThreadsSlotProcessPktFail(ThreadVars *tv, Packet *p) if (p != NULL) { TmqhOutputPacketpool(tv, p); } - TmThreadsCleanDecodePQ(&tv->decode_pq); if (tv->stream_pq_local) { SCMutexLock(&tv->stream_pq_local->mutex_q); TmqhReleasePacketsToPacketPool(tv->stream_pq_local);