Fixing CIDR matching to use floor of provided range #89
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.
Description of changes:
Previously, we would treat CIDR (of the form IP/bits) as a range from IP to maxBytes(IP, bits). But from my understanding of CIDR, the floor of the range should be a floored version of the provided IP, where the number of specified leading bits are fixed and the rest of the bits are set to 0's. So 255.255.255.127/24 means the whole last 8 bits, or last byte, or "127", is variable, so the CIDR range should be 255.255.255.0 to 255.255.255.255, not 255.255.255.127 to 255.255.255.255.
As a consequence of the current implementation, it is possible to create a CIDR that translates into a numeric range where the floor equals the ceiling. For example, 255.255.255.255/31. This violates assumptions built into numeric ranges in Ruler and leads to an ArrayIndexOutOfBoundsException. But if CIDRs get floored as described above, then it is no longer possible for the bottom to equal the top in the numeric range.
The gotchya with this change is that, by definition, we will now match a greater range of IP addresses to a CIDR. So this isn't entirely backwards compatible. However, looking internally at a (very large) usage of Ruler, CIDR is lightly used, and all but two uses of it specify the floor of the range as the provided IP anyway. Thus, I think it's sane to merge this change, as it is a more correct/expected handling of CIDR, and there is a very small potential of impact.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.