-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
net: inconsistent behaviour with IPv4-mapped IPv6 CIDRs #51906
Comments
Is this new in 1.18? Thanks for the reproducer. CC @neild |
@mknyszek I tested with 1.13, 1.15, and 1.17 with identical results. |
The problem is that the Two possible fixes:
|
That sounds like it would mimic the behaviour of netip.Prefix.Contains, which is probably a good thing. "An IPv4 address will not match an IPv6 prefix. A v6-mapped IPv6 address will not match an IPv4 prefix." (godoc) This is annoying and convoluted enough that simplicity and consistency counts for a lot. (Wait, does that godoc quote have a typo? "v6-mapped IPv6 address" should be "v4-mapped IPv6 address"?)
Small typo: I think you mean I'm having trouble with the word "suffix". What does it mean for a range to be a suffix of another range? In case this is helpful...
|
Yes, too many "net"s and "ip"s.
A simpler and hopefully clearer thought: We could say that |
That seems reasonable. It does mean that |
Hey folks, I'm not sure if this has been silently abandoned, but I just want to add 5 cents here...
This behaviour is mildly confusing. I am working a lot with code which gets user input into In some cases I can overcome it by never looking at
Now we have a mask But the very last part is only an implementation detail and from what I can read it's length is not guaranteed, just like
are both valid representations of IPv4 address because of how they are created (i.e. |
What version of Go are you using (
go version
)?Same behaviour on playground.
Does this issue reproduce with the latest release?
Yes.
What did you do?
https://go.dev/play/p/tohTC3rXoZt
What did you expect to see?
That
::ffff:4.4.4.4/64
would contain::ffff:4.4.4.4
and4.4.4.4
(or at least one of them, likenetip.Prefix
).What did you see instead?
It doesn't.
My guess is that the problem is that
::ffff:4.4.4.4/64
is turning into the IPv6 CIDR::/64
, but::ffff:4.4.4.4
is turning into the IPv44.4.4.4
. And the v4 IP will never be contained in the v6 CIDR. In contrast,::ffff:4.4.4.4/124
turns into a v4 CIDR and contains the IPs.The text was updated successfully, but these errors were encountered: