Align CIDR containment and bounds with CIDRv4 and CIDRv6 - #827
Open
vyncint wants to merge 1 commit into
Open
Conversation
`CIDR` keeps the address exactly as parsed, so a block written from a host address keeps its host bits. `contains` compared that unmasked value against the masked probe, so the block reported that it excluded its own members. Mask both sides, as `CIDRv4` and `CIDRv6` already do. `lower` also dropped the IPv6 zone while `upper` kept it, which put a zoned block's lower bound outside the block because `contains` compares zones. The vmnet prefix helper rendered `lower` into `inet_pton`, which rejects a zone suffix, so it now renders the network address on its own.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #826.
What
CIDRkeeps the address exactly as parsed, so a block written from a host address keeps its host bits set.containscompared that unmasked stored value against the masked probe, so the wrapper reported that a block excluded its own members while the types it wraps answered the same query correctly.CIDRv4/CIDRv6192.168.1.100/24contains192.168.1.100falsetrue192.168.1.100/24contains192.168.1.0falsetrue10.1.2.3/16contains10.1.99.99falsetrue2001:db8::1234/64contains2001:db8::1falsetrueMasking both sides matches what
CIDRv4.containsandCIDRv6.containsalready do. A block written in network form was unaffected, which is why this went unnoticed: every containment case inTestCIDR.swiftused a network address.The same accessors carried a second defect.
lowerdropped the IPv6 zone whileupperkept it, and becausecontainscompares zones, a zoned block excluded its own lower bound:lowernow carries the address's zone the wayupperalready did, in both copies of the logic: theCIDRwrapper andCIDRv6.One caller needed a matching change.
VmnetNetwork.configurePrefixV6renderslowerintoinet_pton, which rejects a zone suffix, so it was relying onlowerstripping it. It now renders the network address on its own, leaving the vmnet path unchanged.Verification
TestCIDR.swift: containment across v4 and v6 host-address blocks, non-members still excluded, the wrapper agreeing withCIDRv4/CIDRv6over a probe set, zoned bounds contained in their own block, zone rendering, and unzoned bounds still carrying no zone.CIDR.swiftandCIDRv6.swiftwhile keeping the tests fails 7 of the 9, with the wrong values visible in the output, for example(block → 2001:db8::5%lo0/126).contains(block.lower → 2001:db8::4)and(wrapper.contains(.v4(ip)) → false) == (concrete.contains(ip) → true). The 2 that still pass are the controls written to pass either way: non-members stay excluded, and unzoned bounds are untouched.swift format lint --strict --recursive --configuration .swift-format-nolint Sources Testsexits 0, andswift formatleaves all four files unchanged.The public shape of
CIDR,CIDRv4andCIDRv6is untouched; only the values these accessors compute change.