]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util-device: introduce bypassed stats sub function
authorEric Leblond <eric@regit.org>
Mon, 10 Jun 2019 10:11:43 +0000 (12:11 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 18 Jun 2019 05:07:02 +0000 (07:07 +0200)
src/flow-manager.c
src/util-device.c
src/util-device.h

index 868dcfeb4c95e4e43f869d4d4eab3e021e2d07e7..cef8f6263235fae9d13ef5b1fe92e7e2c72a4765 100644 (file)
@@ -291,9 +291,9 @@ static inline int FlowBypassedTimeout(Flow *f, struct timeval *ts,
             SCLogDebug("No new packet, dead flow %ld", FlowGetId(f));
             if (f->livedev) {
                 if (FLOW_IS_IPV4(f)) {
-                    LiveDevAddBypassStats(f->livedev, -1, AF_INET);
+                    LiveDevSubBypassStats(f->livedev, 1, AF_INET);
                 } else if (FLOW_IS_IPV6(f)) {
-                    LiveDevAddBypassStats(f->livedev, -1, AF_INET6);
+                    LiveDevSubBypassStats(f->livedev, 1, AF_INET6);
                 }
             }
             counters->bypassed_count++;
index 64506ef989d8601a29725d5b597a3f5c1cb67f5b..fd4b598a0745505600ab22ca93a3811903f117a1 100644 (file)
@@ -514,13 +514,13 @@ void LiveDevSetBypassStats(LiveDevice *dev, uint64_t cnt, int family)
 }
 
 /**
- * Modify number of currently bypassed flows for a protocol family
+ * Increase number of currently bypassed flows for a protocol family
  *
  * \param dev pointer to LiveDevice to set stats for
- * \param cnt number of currently bypassed flows
+ * \param cnt number of flows to add
  * \param family AF_INET to set IPv4 count or AF_INET6 to set IPv6 count
  */
-void LiveDevAddBypassStats(LiveDevice *dev, int64_t cnt, int family)
+void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family)
 {
     BypassInfo *bpfdata = LiveDevGetStorageById(dev, g_bypass_storage_id);
     if (bpfdata) {
@@ -532,6 +532,24 @@ void LiveDevAddBypassStats(LiveDevice *dev, int64_t cnt, int family)
     }
 }
 
+/**
+ * Decrease number of currently bypassed flows for a protocol family
+ *
+ * \param dev pointer to LiveDevice to set stats for
+ * \param cnt number of flows to remove
+ * \param family AF_INET to set IPv4 count or AF_INET6 to set IPv6 count
+ */
+void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family)
+{
+    BypassInfo *bpfdata = LiveDevGetStorageById(dev, g_bypass_storage_id);
+    if (bpfdata) {
+        if (family == AF_INET) {
+            SC_ATOMIC_SUB(bpfdata->ipv4_hash_count, cnt);
+        } else if (family == AF_INET6) {
+            SC_ATOMIC_SUB(bpfdata->ipv6_hash_count, cnt);
+        }
+    }
+}
 
 #ifdef BUILD_UNIX_SOCKET
 TmEcode LiveDeviceGetBypassedStats(json_t *cmd, json_t *answer, void *data)
index e2eebf47702977f1d1b545a272016d3753837f6e..9765ec224e063f1294d06e670f476a6f4b3edfac 100644 (file)
@@ -66,7 +66,8 @@ int LiveRegisterDeviceName(const char *dev);
 int LiveRegisterDevice(const char *dev);
 int LiveDevUseBypass(LiveDevice *dev);
 void LiveDevSetBypassStats(LiveDevice *dev, uint64_t cnt, int family);
-void LiveDevAddBypassStats(LiveDevice *dev, int64_t cnt, int family);
+void LiveDevAddBypassStats(LiveDevice *dev, uint64_t cnt, int family);
+void LiveDevSubBypassStats(LiveDevice *dev, uint64_t cnt, int family);
 int LiveGetDeviceCount(void);
 const char *LiveGetDeviceName(int number);
 LiveDevice *LiveGetDevice(const char *dev);