]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
nfqueue: added received packets counter for 'iface-stat' command
authorAlexander Gozman <a.gozman@securitycode.ru>
Sun, 3 Feb 2019 17:19:13 +0000 (20:19 +0300)
committerVictor Julien <victor@inliniac.net>
Wed, 20 Feb 2019 13:45:18 +0000 (14:45 +0100)
Previously nfqueue did not update received packets counter in a
livedev so 'iface-stat' UNIX-socket command always showed zeros.

src/source-nfq.c

index 32c2f3a74cbc1979e507666e8e1bc7e0460308b3..c802302b3246c1b63ce245d4e63d5398f249898e 100644 (file)
@@ -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;