-
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: Unable to reliably distinguish IPv4-mapped-IPv6 addresses from regular IPv4 addresses #37921
Comments
cc @toothrot @mikioh @bradfitz @ianlancetaylor This one seems to have fallen between the cracks and hasn't been triaged yet, tagging you folks for visibility. |
I wouldn't say it fell through the cracks. Sometimes it takes us more than a couple days to triage issues when we're doing things like releasing Go 1.14.1! For the record, it was still in our triage queue. Thanks for filing. |
Would it be more accurate to do something like the guard close in Lines 189 to 200 in 20a838a
|
Hey @toothrot! Sorry for the late reply here :) Unfortunately, this will not work. Since under the hood, whenever you call Here's an example: https://play.golang.org/p/GlBb81pAPIB You can see there, that even though we have an IPv4 string, the internal representation is still 16 bytes - and then the reason we still get a non- Lines 193 to 198 in 20a838a
Does that makes sense? And now we wind up in a situation again where we can't distinguish after parsing whether we were given |
@andrewlouis93, I've addressed this issue in https://godoc.org/inet.af/netaddr (https://github.com/inetaf/netaddr). Perhaps that'll work for you in the meantime? |
Just had a look at this, I think this will work great. Looking forward to seeing that package evolve, thanks @bradfitz! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/gGY8VPwVm2J
What did you expect to see?
Some way to parse an IPv4 mapped IPv6 address (e.g.
0:0:0:0:0:ffff:ac15:0006
or::ffff:172.21.0.6
) and know that it is an IPv4 mapped IPv6 address.The
net
package is bit prohibitive here, given that theParseIP
method is pretty opinionated. See here:What did you see instead?
For any given IPv4-mapped-IPv6 address IP, all the IP parsing in the
net
package only indicate that the input is an IPv4 address.This is also perhaps, further complicated by the internal representation of IPv4 addresses being 16 bytes, bearing the
::ffff
prefix internally.However, if the user is using the
net
package for IP sanitization/validation, not being able to tell the difference seems to be a shortcoming. In order to be implement this on my own, I had to copy/paste theparseIPv6
method from thenet
package, and do something like the following:I would propose here to expose the
parseIPv6
andparseIPv6
methods. Exposing the Parse helpers would help multiple use-cases I'm sure, without increasing the API footprint significantly of the net packageFor more parsing fun related to IPv4-mapped-IPv6 addresses, here's another instance where things look weird: https://play.golang.org/p/lsVp472VG4E
Since
ip
at this point is the 16 byte form, it does have the prefix, but then again any other IPv4 address would have as we see. However, we get an IPv6 network, which will leave the onus on the user to make sense of this result.The text was updated successfully, but these errors were encountered: