From 3088b6ac346400da62c101f1b5ba22b13a4973b4 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Tue, 19 Feb 2013 14:45:05 +0100 Subject: [PATCH] Add invalid pkt counter. This patch adds and increments a invalid packet counter. It does this by introducing PacketDecodeFinalize function This function is incrementing the invalid counter and is also signalling the packet to CUDA. --- src/decode.c | 24 ++++++++++++++++++++++++ src/decode.h | 10 ++++++++++ src/source-af-packet.c | 5 +---- src/source-erf-dag.c | 2 ++ src/source-erf-file.c | 2 ++ src/source-ipfw.c | 2 ++ src/source-mpipe.c | 4 +++- src/source-napatech.c | 3 +++ src/source-nfq.c | 2 ++ src/source-pcap-file.c | 5 +---- src/source-pcap.c | 5 +---- src/source-pfring.c | 5 +---- src/tmqh-packetpool.c | 1 + 13 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/decode.c b/src/decode.c index 4a0f80aebc..4aef9094b2 100644 --- a/src/decode.c +++ b/src/decode.c @@ -89,6 +89,27 @@ void PacketFree(Packet *p) SCFree(p); } +/** + * \brief Finalize decoding of a packet + * + * This function needs to be call at the end of decode + * functions when decoding has been succesful. + * + */ + +void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p) +{ + + if (p->flags & PKT_IS_INVALID) + SCPerfCounterIncr(dtv->counter_invalid, tv->sc_perf_pca); + +#ifdef __SC_CUDA_SUPPORT__ + if (dtv->cuda_vars.mpm_is_cuda) + CudaBufferPacket(&dtv->cuda_vars, p); +#endif + +} + /** * \brief Get a malloced packet. * @@ -338,6 +359,9 @@ void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv) #endif dtv->counter_bytes = SCPerfTVRegisterCounter("decoder.bytes", tv, SC_PERF_TYPE_UINT64, "NULL"); + + dtv->counter_invalid = SCPerfTVRegisterCounter("decoder.invalid", tv, + SC_PERF_TYPE_UINT64, "NULL"); #if 0 dtv->counter_bytes_per_sec = SCPerfTVRegisterIntervalCounter("decoder.bytes_per_sec", tv, SC_PERF_TYPE_DOUBLE, diff --git a/src/decode.h b/src/decode.h index 90846886f5..5011697d29 100644 --- a/src/decode.h +++ b/src/decode.h @@ -585,6 +585,7 @@ typedef struct DecodeThreadVars_ uint16_t counter_pkts; uint16_t counter_pkts_per_sec; uint16_t counter_bytes; + uint16_t counter_invalid; uint16_t counter_bytes_per_sec; uint16_t counter_mbit_per_sec; uint16_t counter_ipv4; @@ -818,6 +819,7 @@ Packet *PacketDefragPktSetup(Packet *parent, uint8_t *pkt, uint16_t len, uint8_t void PacketDefragPktSetupParent(Packet *parent); Packet *PacketGetFromQueueOrAlloc(void); Packet *PacketGetFromAlloc(void); +void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p); void PacketFree(Packet *p); void PacketFreeOrRelease(Packet *p); int PacketCopyData(Packet *p, uint8_t *pktdata, int pktlen); @@ -872,6 +874,13 @@ void AddressDebugPrint(Address *); } \ } while(0) +#define ENGINE_SET_INVALID_EVENT(p, e) do { \ + p->flags |= PKT_IS_INVALID; \ + ENGINE_SET_EVENT(p, e); \ +} while(0) + + + #define ENGINE_ISSET_EVENT(p, e) ({ \ int r = 0; \ uint8_t u; \ @@ -947,6 +956,7 @@ void AddressDebugPrint(Address *); #define PKT_HOST_DST_LOOKED_UP (1<<18) #define PKT_IS_FRAGMENT (1<<19) /**< Packet is a fragment */ +#define PKT_IS_INVALID (1<<20) /** \brief return 1 if the packet is a pseudo packet */ #define PKT_IS_PSEUDOPKT(p) ((p)->flags & PKT_PSEUDO_STREAM_END) diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 24837b3f38..befdb0ed33 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -1688,10 +1688,7 @@ TmEcode DecodeAFP(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packet break; } -#ifdef __SC_CUDA_SUPPORT__ - if (dtv->cuda_vars.mpm_is_cuda) - CudaBufferPacket(&dtv->cuda_vars, p); -#endif + PacketDecodeFinalize(tv, dtv, p); SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-erf-dag.c b/src/source-erf-dag.c index 97e2d4c6d5..fa020ff89c 100644 --- a/src/source-erf-dag.c +++ b/src/source-erf-dag.c @@ -617,6 +617,8 @@ TmEcode DecodeErfDag(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, break; } + PacketDecodeFinalize(tv, dtv, p); + SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-erf-file.c b/src/source-erf-file.c index 72c69e4e70..066ffe9298 100644 --- a/src/source-erf-file.c +++ b/src/source-erf-file.c @@ -292,6 +292,8 @@ DecodeErfFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQueu DecodeEthernet(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq); + PacketDecodeFinalize(tv, dtv, p); + SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-ipfw.c b/src/source-ipfw.c index 4df4c4ed43..b6d2278e94 100644 --- a/src/source-ipfw.c +++ b/src/source-ipfw.c @@ -461,6 +461,8 @@ TmEcode DecodeIPFW(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packe SCReturnInt(TM_ECODE_FAILED); } + PacketDecodeFinalize(tv, dtv, p); + SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-mpipe.c b/src/source-mpipe.c index 26244f3a86..b8f835ec8d 100644 --- a/src/source-mpipe.c +++ b/src/source-mpipe.c @@ -992,7 +992,9 @@ TmEcode DecodeMpipe(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, /* call the decoder */ DecodeEthernet(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq); - + + PacketDecodeFinalize(tv, dtv, p); + SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-napatech.c b/src/source-napatech.c index 593a4d5f32..172e7f95e5 100644 --- a/src/source-napatech.c +++ b/src/source-napatech.c @@ -372,6 +372,9 @@ TmEcode NapatechDecode(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, p->datalink); break; } + + PacketDecodeFinalize(tv, dtv, p); + SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-nfq.c b/src/source-nfq.c index 44fd8d9f63..b1deefc3c8 100644 --- a/src/source-nfq.c +++ b/src/source-nfq.c @@ -1220,6 +1220,8 @@ TmEcode DecodeNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packet SCLogDebug("packet unsupported by NFQ, first byte: %02x", *GET_PKT_DATA(p)); } + PacketDecodeFinalize(tv, dtv, p); + return TM_ECODE_OK; } diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c index 823be20c77..6c951a9a26 100644 --- a/src/source-pcap-file.c +++ b/src/source-pcap-file.c @@ -369,10 +369,7 @@ TmEcode DecodePcapFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, P BUG_ON(p->pkt_src != PKT_SRC_WIRE && p->pkt_src != PKT_SRC_FFR_V2); #endif -#ifdef __SC_CUDA_SUPPORT__ - if (dtv->cuda_vars.mpm_is_cuda) - CudaBufferPacket(&dtv->cuda_vars, p); -#endif + PacketDecodeFinalize(tv, dtv, p); SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-pcap.c b/src/source-pcap.c index 2d2f036573..27a4c2dfab 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -739,10 +739,7 @@ TmEcode DecodePcap(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packe break; } -#ifdef __SC_CUDA_SUPPORT__ - if (dtv->cuda_vars.mpm_is_cuda) - CudaBufferPacket(&dtv->cuda_vars, p); -#endif + PacketDecodeFinalize(tv, dtv, p); SCReturnInt(TM_ECODE_OK); } diff --git a/src/source-pfring.c b/src/source-pfring.c index addeb50abe..f095603116 100644 --- a/src/source-pfring.c +++ b/src/source-pfring.c @@ -563,10 +563,7 @@ TmEcode DecodePfring(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pac DecodeEthernet(tv, dtv, p, GET_PKT_DATA(p), GET_PKT_LEN(p), pq); -#ifdef __SC_CUDA_SUPPORT__ - if (dtv->cuda_vars.mpm_is_cuda) - CudaBufferPacket(&dtv->cuda_vars, p); -#endif + PacketDecodeFinalize(tv, dtv, p); return TM_ECODE_OK; } diff --git a/src/tmqh-packetpool.c b/src/tmqh-packetpool.c index 0b2b862940..1053d6be38 100644 --- a/src/tmqh-packetpool.c +++ b/src/tmqh-packetpool.c @@ -52,6 +52,7 @@ #include "util-debug.h" #include "util-error.h" #include "util-profiling.h" +#include "util-device.h" static RingBuffer16 *ringbuffer = NULL; /**