util-device: introduce bypassed stats sub function

pull/3952/head
Eric Leblond 6 years ago committed by Victor Julien
parent f29a4b8bee
commit 98e7d9d1c0

@ -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++;

@ -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)

@ -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);

Loading…
Cancel
Save