Closed kasparjarek closed 1 year ago
Change https://go.dev/cl/414275 mentions this issue: net: fix LookupNetIP to return IPv4 addresses instead of IPv4 in IPv6
It seems that the original IP is converted to IPv6 here:
Maybe it's better to remove the conversion?
func copyIP(x IP) IP {
- if len(x) < 16 {
- return x.To16()
- }
y := make(IP, len(x))
copy(y, x)
return y
}
I run ./all.bash
after this change and all tests passed (on Linux). But I'm not sure whether this func is covered by the tests.
BTW, the 3 lines were added as part of the commit to fix #6465. I have tested on tip with the 3 lines removed and can not reproduce #6465.
You are right. It seems quite weird to me that the copyIP
function converts it to 16 bytes. If it's not actually necessary I can change the pull request to rather remove the three lines. I guess I will wait for reviewers to know what they think about it.
CC @bradfitz @josharian
@kasparjarek I'm sorry that my suggested approach turns out to need more changes than that. So I will send a CL myself.
Change https://go.dev/cl/415580 mentions this issue: net: store IPv4 returned from cgo resolver as 4-byte slice net.IP
Hi @kasparjarek, how about the implementation in PR#56406? Let's just change the calling from netip.AddrFromSlice
to netip.ParseAddr
which already do the IPv4/6 separation in LookupNetIP
. Does it make sense?
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?
What did you expect to see?
What did you see instead?
The method LookupNetIP is currently just a wrapper around the old way. But the old way represents IPv4 in 16 bytes slice, so when this wrapper parses the slice it will always create an IPv6 address. For IPv4 addresses, it's IPv4 in IPv6. It makes it harder to manipulate with a new address representation. For example I cannot just simply compare result of
netip.MustParseAddr("142.251.36.142")
with the same address returned byLookupNetIP()
. The comparison results in non-zero value.I would propose converting the old address into 4 bytes slice (if it's IPv4 address) before parsing https://github.com/golang/go/pull/53555 . What do you think?