@@ -19,33 +19,16 @@ private static IPNetwork[] CleanAllowedIPs(IPNetwork[] values, IPNetwork[] allow
19
19
{
20
20
List < IPNetwork > result = new ( values ) ;
21
21
22
- // Remove all entries which conflict with one ore more disallowed ips
22
+ // Remove all entries which conflict with one or more disallowed ips
23
23
result . RemoveAll ( x => disallowed . Any ( y => x . Overlaps ( y ) ) ) ;
24
24
25
- // Remove all entires which are outside of the underlying AllowedIPs-Ranges
25
+ // Remove all entries which are outside of the underlying AllowedIPs-Ranges
26
26
// Nothing happens here if the underlying range is the entire address space (e.g. 0.0.0.0/0 or ::/0)
27
27
result . RemoveAll ( x => allowed . Any ( y => ! y . Contains ( x ) ) ) ;
28
28
29
29
// Add the networks which did not conflict with any disallowed ips
30
30
result . AddRange ( allowed . Where ( x => ! disallowed . Any ( y => y . Overlaps ( x ) ) ) ) ;
31
31
32
- /*List<int> rIndices = new();
33
- for(int i = 0; i < result.Count; i++)
34
- {
35
- for(int j = 0; j < result.Count; j++)
36
- {
37
- if(j == i)
38
- continue;
39
- if(result[i] == result[j])
40
- {
41
- rIndices.Add(j);
42
- }
43
- }
44
- }
45
-
46
- foreach(int i in rIndices.OrderByDescending(x => x))
47
- result.RemoveAt(i);*/
48
-
49
32
// Remove duplicates and return
50
33
return result . Distinct ( ) . ToArray ( ) ;
51
34
}
@@ -61,7 +44,7 @@ public static IPv4Network[] CalculateAllowedIPv4s(IPv4Network[] allowed, IPv4Net
61
44
IPv4Network last = new ( 0 , 32 ) ;
62
45
63
46
// Treat the entire address space as a continous numeric range (which it is)
64
- // and find the sections which are not inside a disallowed range
47
+ // and find the sections which are not inside a disallowed range.
65
48
// This can be done sequentially because we sorted the disallowed ranges by ascending address value
66
49
foreach ( IPv4Network dis in sortedDisallowed )
67
50
{
0 commit comments