From 98e7d9d1c0ee4d2392698ea3ef2381f214de51cd Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Mon, 10 Jun 2019 12:11:43 +0200 Subject: [PATCH] util-device: introduce bypassed stats sub function --- src/flow-manager.c | 4 ++-- src/util-device.c | 24 +++++++++++++++++++++--- src/util-device.h | 3 ++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/flow-manager.c b/src/flow-manager.c index 868dcfeb4c..cef8f62632 100644 --- a/src/flow-manager.c +++ b/src/flow-manager.c @@ -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++; diff --git a/src/util-device.c b/src/util-device.c index 64506ef989..fd4b598a07 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -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) diff --git a/src/util-device.h b/src/util-device.h index e2eebf4770..9765ec224e 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -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);