fix(ipset): count members when "Number of entries" is missing from ipset list#489
Merged
blotus merged 1 commit intoJun 2, 2026
Conversation
ipset list
IPSet.Len() parsed only the "Number of entries:" line of `ipset list` output. Kernels exposing the set protocol v6 (e.g. embedded routers such as Keenetic) do not emit that line, so Len() silently fell back to 0. This made the fw_bouncer_banned_ips gauge report 0 even when the ipsets held tens of thousands of entries. Add a fallback that counts the member lines after the "Members:" header when the "Number of entries:" line is missing. The parsing is extracted into a pure parseIPSetLen() helper, covered by a test exercising both output formats (with and without the header), an empty set and garbage.
b3c7ba8 to
fe79e6c
Compare
blotus
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
IPSet.Len()returns the correct entry count on kernels whoseipset listoutput omits the
Number of entries:header line, fixing thefw_bouncer_banned_ipsmetric reporting0on those systems.Why / root cause
IPSet.Len()parsed only theNumber of entries:line ofipset list:That line is only printed by the newer set protocol. On kernels that expose
set protocol v6 (common on embedded systems — e.g. Keenetic routers
running Entware), ipset list produces no such line:
Name: crowdsec-blacklists-0
Type: hash:net
Revision: 6
Header: family inet hashsize 8192 maxelem 131072 timeout 300
Size in memory: 760832
References: 1
Members:
5.11.143.72 timeout 590431
...
Len() never matches and falls through to return 0. Because the
fw_bouncer_banned_ips gauge is set directly from set.Len()
(pkg/iptables/metrics.go), the metric reports 0 even when the ipsets
hold tens of thousands of entries. The fw_bouncer_dropped_* and
lapi_requests_* metrics are parsed differently and were unaffected.
What changed
header when that line is absent.
Testing
modern (Number of entries:) output, a protocol-v6 output without that
line, an empty set, and garbage input.
v6): fw_bouncer_banned_ips now matches the real ipset sizes
(e.g. 19255 for the CAPI set) instead of 0.
Notes
No behaviour change on kernels that already emit Number of entries: — the
fast path is unchanged; the fallback only triggers when the line is absent.