From 86d7dddfabca51768c4056cf64ad6ea8649de847 Mon Sep 17 00:00:00 2001 From: Alexander Gozman Date: Sun, 3 Feb 2019 20:19:13 +0300 Subject: [PATCH] nfqueue: added received packets counter for 'iface-stat' command Previously nfqueue did not update received packets counter in a livedev so 'iface-stat' UNIX-socket command always showed zeros. --- src/source-nfq.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/source-nfq.c b/src/source-nfq.c index 32c2f3a74c..c802302b32 100644 --- a/src/source-nfq.c +++ b/src/source-nfq.c @@ -129,6 +129,8 @@ typedef struct NFQThreadVars_ ThreadVars *tv; TmSlot *slot; + LiveDevice *livedev; + char *data; /** Per function and thread data */ int datalen; /** Length of per function and thread data */ @@ -561,6 +563,8 @@ static int NFQCallBack(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, q->pkts++; q->bytes += GET_PKT_LEN(p); #endif /* COUNTERS */ + (void) SC_ATOMIC_ADD(ntv->livedev->pkts, 1); + /* NFQSetupPkt is issuing a verdict so we only recycle Packet and leave */ TmqhOutputPacketpool(tv, p); @@ -574,6 +578,7 @@ static int NFQCallBack(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, q->pkts++; q->bytes += GET_PKT_LEN(p); #endif /* COUNTERS */ + (void) SC_ATOMIC_ADD(ntv->livedev->pkts, 1); if (ntv->slot) { if (TmThreadsSlotProcessPkt(tv, ntv->slot, p) != TM_ECODE_OK) { @@ -839,7 +844,7 @@ int NFQRegisterQueue(const uint16_t number) { NFQThreadVars *ntv = NULL; NFQQueueVars *nq = NULL; - char queue[6] = { 0 }; + char queue[8] = { 0 }; static bool many_queues_warned = false; uint16_t num_cpus = UtilCpuGetNumProcessorsOnline(); @@ -872,7 +877,14 @@ int NFQRegisterQueue(const uint16_t number) receive_queue_num++; SCMutexUnlock(&nfq_init_lock); snprintf(queue, sizeof(queue) - 1, "%hu", number); - LiveRegisterDeviceName(queue); + LiveRegisterDevice(queue); + + ntv->livedev = LiveGetDevice(queue); + + if (ntv->livedev == NULL) { + SCLogError(SC_ERR_INVALID_VALUE, "Unable to find Live device"); + return -1; + } SCLogDebug("Queue %d registered.", number); return 0;