Skip to content

Commit eae412f

Browse files
PeykamiPeykami
authored andcommitted
feat(ip-filter): add CIDR overlap detection, normalization, and full XML docs
- Added `ContainsIp` method to check if a single IP belongs to any registered subnet - Added `ContainsCidr` method to detect CIDR membership and overlaps - Added `NormalizeCidr` to normalize IP/CIDR to the correct network address - Added `FindOverlaps` to collect all overlapping subnets for IPs or CIDRs - Implemented helper traversals for subtree searching in Patricia Trie - Added XML `<summary>` docs and inline comments for GitHub-ready documentation - Improved readability and maintainability for future contributors
1 parent 310b9bf commit eae412f

File tree

2 files changed

+429
-28
lines changed

2 files changed

+429
-28
lines changed

samples/Samples/Program.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
using Arad.TrieNet;
44

5+
(string cidr, string? username, bool isDeny)[] initial =
6+
[
7+
("91.199.9.60", "user1", false),
8+
("185.37.54.112/27", "user1", false),
9+
("180.31.2.5/29", "user2", false),
10+
("fe80::/10", "user2", false),
11+
("10.0.0.0/5", "user3", false),
12+
("2001:db8::/32", "user3", false),
13+
("192.168.1.0/24", null, true),
14+
("0.0.0.0/0", "admin", false),
15+
("192.168.1.1-192.168.1.10", "user1", false)
16+
];
17+
18+
foreach ((string cidrItem, string? username, bool isDeny) in initial)
19+
{
20+
if (isDeny)
21+
{
22+
IPFilter.AddDeny(cidrItem.AsSpan());
23+
}
24+
else
25+
{
26+
IPFilter.AddNetwork(cidrItem.AsSpan(), username!);
27+
}
28+
}
29+
530
Console.WriteLine("IPFilter tests:");
631
Console.WriteLine("IsAllowed:");
732
(bool allowed, string reason) = IPFilter.IsAllowed("user1", "185.37.54.116");

0 commit comments

Comments
 (0)