Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing CIDR matching to use floor of provided range #89

Merged
merged 3 commits into from
May 1, 2023
Merged

Conversation

jonessha
Copy link
Contributor

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.

@baldawar baldawar merged commit 17099ce into main May 1, 2023
@jonessha jonessha deleted the cidr_fix branch May 1, 2023 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants