feat: support CIDR ranges in imported IP blacklists - #1181
Merged
GyulyVGC merged 5 commits intoMay 7, 2026
Merged
Conversation
Owner
|
Cool! This sounds useful. Thanks a lot, will review when I have some time. |
GyulyVGC
approved these changes
May 7, 2026
Owner
|
Merged! I've just done some improvements to performance and parsing. Looks good. |
Owner
|
@all-contributors please add @TheMasterOfDisasters for code. |
Contributor
|
I've put up a pull request to add @TheMasterOfDisasters! 🎉 |
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.
Summary
This PR adds CIDR range support to imported IP blacklists.
Previously, imported blacklist files only supported exact IPv4/IPv6 addresses. This meant common blacklist sources that publish CIDR ranges, such as Spamhaus DROP-style lists, could not be used directly without manually expanding ranges into individual IP addresses.
With this change, imported blacklists can now include:
8.8.8.82001:db8::11.2.3.0/242001:db8::/32;or#Motivation
I started using Sniffnet's IP blacklist feature with public blacklist sources and noticed that many of them publish entries as CIDR ranges instead of individual IP addresses.
One example is Spamhaus DROP-style lists, where entries are commonly written like:
At first I considered expanding those ranges into individual IPs, but that quickly becomes impractical. Larger IPv4 ranges can expand into thousands or millions of addresses, and IPv6 ranges should not be expanded at all.
This change makes the blacklist import more useful for my use case while keeping the behavior general for other users who want to import common blacklist/range-based feeds.
Implementation
The blacklist now stores:
HashSet<IpAddr>IpNetentriesLookup checks exact IP matches first, then checks whether the IP belongs to any imported CIDR range.
CIDR ranges are not expanded into individual addresses.
Testing
Tested with:
cargo fmt --check cargo check cargo test cargo build --releaseAlso tested locally by importing a blacklist file containing CIDR ranges and verifying that matching traffic is marked as blacklisted.
Notes
I kept this PR focused on CIDR support for the existing text-based blacklist import. Some public blacklist providers also publish JSON feeds, but I did not include JSON import support here to keep the change small.