-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fixes: #17358 - Ensure correct comparison of overlapping IPRanges #17391
Fixes: #17358 - Ensure correct comparison of overlapping IPRanges #17391
Conversation
…ive of subnet inclusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good, just wondering if it makes sense to make the code a bit more DRY.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than introduce new lookups for these specific comparisons, we should be able to leverage Postgres' HOST()
function. Unfortunately, the NetHost()
lookup won't support this, but we can instead register the Host()
transform on IPAddressField
:
>>> from ipam.fields import IPAddressField
>>> from ipam import lookups
>>> IPAddressField.register_lookup(lookups.Host)
<class 'ipam.lookups.Host'>
>>> IPRange.objects.filter(start_address__host__gte="1.2.3.100", start_address__host__lte="1.2.3.200")
<RestrictedQuerySet [<IPRange: 1.2.3.123-124/26>]>
(Ultimately, it probably makes sense to retire some of these lookups in favor of the transforms, but that's a separate discussion.)
I don't think that works actually; the At any rate the comparisons in my unit test fail and it throws an overlapping exception when trying to add That's why I created the four specific comparison lookups in the first place, because using ... (30 minutes later) ... After some more digging into the |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken. |
Fixes: #17358
Adds new Lookup classes for
lt/gt/lte/gte
comparisons with INET objects, ignoring the mask. This enables correct comparison of adjacent IPRanges when looking for overlaps, and prevents acceptance of an invalid new IPRange where the entered start_address and end_address masks do not match the existing ranges.