From 80615f7d43f500b6ca64324dcfd0b43cecea164f Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 28 May 2015 20:44:36 +0200 Subject: [PATCH] ips: move counters in common struct and funcs --- src/decode.c | 21 +++++++++++++++++++++ src/decode.h | 12 ++++++++++++ src/source-nfq.c | 16 +++------------- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/decode.c b/src/decode.c index b807038841..aa6068bbc0 100644 --- a/src/decode.c +++ b/src/decode.c @@ -544,6 +544,27 @@ const char *PktSrcToString(enum PktSrcEnum pkt_src) return pkt_src_str; } +void CaptureStatsUpdate(ThreadVars *tv, CaptureStats *s, const Packet *p) +{ + if (unlikely(PACKET_TEST_ACTION(p, (ACTION_REJECT|ACTION_REJECT_DST|ACTION_REJECT_BOTH)))) { + StatsIncr(tv, s->counter_ips_rejected); + } else if (unlikely(PACKET_TEST_ACTION(p, ACTION_DROP))) { + StatsIncr(tv, s->counter_ips_blocked); + } else if (unlikely(p->flags & PKT_STREAM_MODIFIED)) { + StatsIncr(tv, s->counter_ips_replaced); + } else { + StatsIncr(tv, s->counter_ips_accepted); + } +} + +void CaptureStatsSetup(ThreadVars *tv, CaptureStats *s) +{ + s->counter_ips_accepted = StatsRegisterCounter("ips.accepted", tv); + s->counter_ips_blocked = StatsRegisterCounter("ips.blocked", tv); + s->counter_ips_rejected = StatsRegisterCounter("ips.rejected", tv); + s->counter_ips_replaced = StatsRegisterCounter("ips.replaced", tv); +} + /** * @} */ diff --git a/src/decode.h b/src/decode.h index 3f77cd06da..1a510eec46 100644 --- a/src/decode.h +++ b/src/decode.h @@ -630,6 +630,18 @@ typedef struct DecodeThreadVars_ #endif } DecodeThreadVars; +typedef struct CaptureStats_ { + + uint16_t counter_ips_accepted; + uint16_t counter_ips_blocked; + uint16_t counter_ips_rejected; + uint16_t counter_ips_replaced; + +} CaptureStats; + +void CaptureStatsUpdate(ThreadVars *tv, CaptureStats *s, const Packet *p); +void CaptureStatsSetup(ThreadVars *tv, CaptureStats *s); + /** * \brief reset these to -1(indicates that the packet is fresh from the queue) */ diff --git a/src/source-nfq.c b/src/source-nfq.c index f2bfd7f0cb..38770cb970 100644 --- a/src/source-nfq.c +++ b/src/source-nfq.c @@ -131,9 +131,7 @@ typedef struct NFQThreadVars_ char *data; /** Per function and thread data */ int datalen; /** Length of per function and thread data */ - uint16_t counter_ips_accepted; - uint16_t counter_ips_blocked; - uint16_t counter_ips_rejected; + CaptureStats stats; } NFQThreadVars; /* shared vars for all for nfq queues and threads */ @@ -761,9 +759,7 @@ TmEcode VerdictNFQThreadInit(ThreadVars *tv, void *initdata, void **data) { NFQThreadVars *ntv = (NFQThreadVars *) initdata; - ntv->counter_ips_accepted = StatsRegisterCounter("ips.accepted", tv); - ntv->counter_ips_blocked = StatsRegisterCounter("ips.blocked", tv); - ntv->counter_ips_rejected = StatsRegisterCounter("ips.rejected", tv); + CaptureStatsSetup(tv, &ntv->stats); *data = (void *)ntv; return TM_ECODE_OK; @@ -1179,13 +1175,7 @@ TmEcode VerdictNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Packe { NFQThreadVars *ntv = (NFQThreadVars *)data; /* update counters */ - if (unlikely(PACKET_TEST_ACTION(p, (ACTION_REJECT|ACTION_REJECT_DST|ACTION_REJECT_BOTH)))) { - StatsIncr(tv, ntv->counter_ips_rejected); - } else if (unlikely(PACKET_TEST_ACTION(p, ACTION_DROP))) { - StatsIncr(tv, ntv->counter_ips_blocked); - } else { - StatsIncr(tv, ntv->counter_ips_accepted); - } + CaptureStatsUpdate(tv, &ntv->stats, p); int ret; /* if this is a tunnel packet we check if we are ready to verdict