ips: move counters in common struct and funcs

pull/1558/head
Victor Julien 10 years ago
parent 813930f027
commit 80615f7d43

@ -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);
}
/**
* @}
*/

@ -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)
*/

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

Loading…
Cancel
Save