From: Eric Leblond Date: Tue, 5 Mar 2019 22:28:26 +0000 (+0100) Subject: util-ebpf: fix IPv6 deletion loop X-Git-Tag: suricata-5.0.0-rc1~353 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07d0bd3a0fe1e31fd80c52f312a4d75a11400355;p=thirdparty%2Fsuricata.git util-ebpf: fix IPv6 deletion loop --- diff --git a/src/util-ebpf.c b/src/util-ebpf.c index 011c9be1a0..7774b25163 100644 --- a/src/util-ebpf.c +++ b/src/util-ebpf.c @@ -645,10 +645,15 @@ static int EBPFForEachFlowV6Table(LiveDevice *dev, const char *name, return 0; } + uint64_t pkts_cnt = 0; while (bpf_map_get_next_key(mapfd, &key, &next_key) == 0) { - uint64_t pkts_cnt = 0; uint64_t bytes_cnt = 0; hash_cnt++; + if (pkts_cnt > 0) { + SC_ATOMIC_ADD(dev->bypassed, pkts_cnt); + EBPFDeleteKey(mapfd, &key); + } + pkts_cnt = 0; /* We use a per CPU structure so we will get a array of values. But if nr_cpus * is 1 then we have a global hash. */ struct pair values_array[tcfg->cpus_count]; @@ -693,12 +698,15 @@ static int EBPFForEachFlowV6Table(LiveDevice *dev, const char *name, pkts_cnt = EBPFOpFlowForKey(flowstats, &flow_key, values_array[0].hash, ctime, pkts_cnt, bytes_cnt); if (pkts_cnt > 0) { - SC_ATOMIC_ADD(dev->bypassed, pkts_cnt); - EBPFDeleteKey(mapfd, &next_key); found = 1; } key = next_key; } + if (pkts_cnt > 0) { + SC_ATOMIC_ADD(dev->bypassed, pkts_cnt); + EBPFDeleteKey(mapfd, &key); + found = 1; + } struct bpf_maps_info *bpfdata = LiveDevGetStorageById(dev, g_livedev_storage_id); if (bpfdata) {