This page will attempt to be a quick guide to using CIDR patterns. These are widely supported in InspIRCd and can be very useful.
Why use CIDR matching
CIDR patterns are a quick and easy way of matching a range of IP addresses. This can be particularly useful when dealing with ISPs which allocate dynamic IP addresses to their users. Users can easily change IP address by restarting their routers, but the addresses they get are typically within a relatively small range. CIDR may allow a troublesome user to be banned with a few patterns rather than a large number of individual zlines.
How to use CIDR
A CIDR pattern looks something like this:
The first part, a.b.c.d, is simply a normal IPv4 IP address. The interesting part is the 'e'. This number specifies how many bits of the first part -- a.b.c.d -- are significant when it comes to matching an IP against the pattern. Right, that last part needs a little more explanation (if that made sense to you then you can stop reading now: you know CIDR, that's it). An IPv4 address is simply a 32 bit number, which happens to be written (by convention) as four 8 bit (0-255) numbers: the 'a', 'b', 'c' and 'd' above. We could also write an IPv4 address in binary:
00111100 10010001 00111000 11110110 (18.104.22.168)
Now when it comes to matching a CIDR pattern against an actual address, what the number after the / in the pattern ('e') specifies is how many bits (counting left to right) have to be the same for the address to match the pattern.
Let's look at an example.
Does 22.214.171.124 match the pattern 126.96.36.199/24?
00111100 10010001 00111000 11110110 (188.8.131.52) 00111100 10010001 00111000 00000000 (184.108.40.206)
Because the 'e' value is 24, this means we only have to check the first 24 bits of the address. These are highlighted in bold above, and as you can see the first 24 bits are identical: the address matches the pattern.
You should be able to see that when 'e' is a multiple of 8 then a CIDR pattern behaves a little like a glob pattern would. 220.127.116.11/24 is equivalent to 60.145.56.*, 18.104.22.168/16 is equivalent to 60.145.*.* and so on. However, CIDR is more flexible than glob matching (not to mention faster) because the 'e' value does not have to be a multiple of 8. Take the pattern 22.214.171.124/27, or in binary form:
00111100 10010001 00111000 11100000
This pattern also matches our example IP address 126.96.36.199 because, as we can see:
00111100 10010001 00111000 11110110 (188.8.131.52) 00111100 10010001 00111000 11100000 (184.108.40.206)
The first 27 bits of the address and of the pattern are identical.
Examples may be added at a later date, but CIDR is fundamentally the same for IPv6 as it is for IPv4. The only differences are that, obviously, IPv6 addresses are longer (128 bits rather than 32 for IPv4) and they are written in a different form.
Warnings and Notes
If you've read the above properly then it should be obvious that a /0 pattern ('e' = 0) is very rarely something you want. Such a pattern specifies that no bits have to be checked, hence all addresses will match a /0 pattern: akin to '*' as a mask. Very unlikely to be the intended result.
/32 patterns and /128 patterns
Again, this should be obvious from the above. A /32 pattern (For IPv4, 'e' = 32) or a /128 pattern (For IPv6, 'e' = 128) means that the entire address (32/128 bits for IPv4/6) will be matched. Therefore one of these patterns will only match exactly.