stats: simplify ips capture stats logic

Since many implementations use the ReleasePacket callback to issue
their verdict, no thread ctx is available. To work around this
just register the stats in a `thread_local` variable instead.
pull/9288/head
Victor Julien 3 years ago
parent 8b018818a6
commit ece1cb3e94

@ -822,9 +822,19 @@ const char *PacketDropReasonToString(enum PacketDropReason r)
return NULL;
}
typedef struct CaptureStats_ {
uint16_t counter_ips_accepted;
uint16_t counter_ips_blocked;
uint16_t counter_ips_rejected;
uint16_t counter_ips_replaced;
} CaptureStats;
thread_local CaptureStats t_capture_stats;
/* TODO drop reason stats! */
void CaptureStatsUpdate(ThreadVars *tv, CaptureStats *s, const Packet *p)
void CaptureStatsUpdate(ThreadVars *tv, const Packet *p)
{
CaptureStats *s = &t_capture_stats;
if (unlikely(PacketCheckAction(p, ACTION_REJECT_ANY))) {
StatsIncr(tv, s->counter_ips_rejected);
} else if (unlikely(PacketCheckAction(p, ACTION_DROP))) {
@ -836,8 +846,9 @@ void CaptureStatsUpdate(ThreadVars *tv, CaptureStats *s, const Packet *p)
}
}
void CaptureStatsSetup(ThreadVars *tv, CaptureStats *s)
void CaptureStatsSetup(ThreadVars *tv)
{
CaptureStats *s = &t_capture_stats;
s->counter_ips_accepted = StatsRegisterCounter("ips.accepted", tv);
s->counter_ips_blocked = StatsRegisterCounter("ips.blocked", tv);
s->counter_ips_rejected = StatsRegisterCounter("ips.rejected", tv);

@ -749,17 +749,8 @@ typedef struct DecodeThreadVars_
} 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);
void CaptureStatsUpdate(ThreadVars *tv, const Packet *p);
void CaptureStatsSetup(ThreadVars *tv);
#define PACKET_CLEAR_L4VARS(p) do { \
memset(&(p)->l4vars, 0x00, sizeof((p)->l4vars)); \

@ -120,8 +120,6 @@ typedef struct NFQThreadVars_
char *data; /** Per function and thread data */
int datalen; /** Length of per function and thread data */
CaptureStats stats;
} NFQThreadVars;
/* shared vars for all for nfq queues and threads */
static NFQGlobalVars nfq_g;
@ -779,7 +777,7 @@ TmEcode VerdictNFQThreadInit(ThreadVars *tv, const void *initdata, void **data)
{
NFQThreadVars *ntv = (NFQThreadVars *) initdata;
CaptureStatsSetup(tv, &ntv->stats);
CaptureStatsSetup(tv);
*data = (void *)ntv;
return TM_ECODE_OK;
@ -1191,9 +1189,8 @@ TmEcode NFQSetVerdict(Packet *p)
*/
TmEcode VerdictNFQ(ThreadVars *tv, Packet *p, void *data)
{
NFQThreadVars *ntv = (NFQThreadVars *)data;
/* update counters */
CaptureStatsUpdate(tv, &ntv->stats, p);
CaptureStatsUpdate(tv, p);
/* if this is a tunnel packet we check if we are ready to verdict
* already. */

@ -95,7 +95,6 @@ typedef struct WinDivertThreadVars_ {
WinDivertHandle filter_handle;
int thread_num;
CaptureStats stats;
int64_t qpc_start_time;
int64_t qpc_start_count;
int64_t qpc_freq_usec;
@ -750,7 +749,7 @@ static TmEcode WinDivertVerdictHelper(ThreadVars *tv, Packet *p)
WinDivertThreadVars *wd_tv = WinDivertGetThread(p->windivert_v.thread_num);
/* update counters */
CaptureStatsUpdate(tv, &wd_tv->stats, p);
CaptureStatsUpdate(tv, p);
#ifdef COUNTERS
WinDivertQueueVars *wd_qv = WinDivertGetQueue(wd_tv->thread_num);
@ -823,7 +822,7 @@ TmEcode VerdictWinDivertThreadInit(ThreadVars *tv, const void *initdata,
WinDivertThreadVars *wd_tv = (WinDivertThreadVars *)initdata;
CaptureStatsSetup(tv, &wd_tv->stats);
CaptureStatsSetup(tv);
*data = wd_tv;

Loading…
Cancel
Save