Skip to content
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: WriteMsgUDPAddrPort should accept IPv4 destination addresses on IPv6 UDP sockets #52264

Closed
database64128 opened this issue Apr 10, 2022 · 10 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@database64128
Copy link
Contributor

database64128 commented Apr 10, 2022

What version of Go are you using (go version)?

$ go version
go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/database64128/.cache/go-build"
GOENV="/home/database64128/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/database64128/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/database64128/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1725863524=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create an IPv6 UDP socket listening on ::. Call WriteMsgUDPAddrPort with an IPv4 target address.

What did you expect to see?

The write succeeds, just like WriteMsgUDP.

What did you see instead?

write udp [::]:52794->12.34.56.78:12345: address 12.34.56.78: non-IPv6 address

go/src/net/ipsock_posix.go

Lines 215 to 228 in db7183c

func addrPortToSockaddrInet6(ap netip.AddrPort) (syscall.SockaddrInet6, error) {
// ipToSockaddrInet6 has special handling here for zero length slices.
// We do not, because netip has no concept of a generic zero IP address.
addr := ap.Addr()
if !addr.Is6() {
return syscall.SockaddrInet6{}, &AddrError{Err: "non-IPv6 address", Addr: addr.String()}
}
sa := syscall.SockaddrInet6{
Addr: addr.As16(),
Port: int(ap.Port()),
ZoneId: uint32(zoneCache.index(addr.Zone())),
}
return sa, nil
}

The check performed here should allow IPv4 as well.

database64128 added a commit to database64128/go that referenced this issue Apr 10, 2022
WriteMsgUDPAddrPort should accept IPv4 target addresses on IPv6 UDP sockets. An IPv4 target address will be converted to an IPv4-mapped IPv6 address. Fixes golang#52264.
@gopherbot
Copy link

Change https://go.dev/cl/399454 mentions this issue: net: fix WriteMsgUDPAddrPort addr handling

database64128 added a commit to database64128/swgp-go that referenced this issue Apr 10, 2022
@moredure
Copy link
Contributor

@database64128 maybe !addr.IsValid() ?

@dmitshur
Copy link
Contributor

CC @ianlancetaylor, @neild.

@dmitshur dmitshur added this to the Backlog milestone Apr 11, 2022
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 11, 2022
database64128 added a commit to database64128/go that referenced this issue Apr 12, 2022
WriteMsgUDPAddrPort should accept IPv4 target addresses on IPv6 UDP sockets.
An IPv4 target address will be converted to an IPv4-mapped IPv6 address.

Fixes golang#52264.
database64128 added a commit to database64128/gibberish-sender-go that referenced this issue Apr 12, 2022
database64128 added a commit to database64128/go that referenced this issue Apr 12, 2022
WriteMsgUDPAddrPort should accept IPv4 target addresses on IPv6 UDP sockets.
An IPv4 target address will be converted to an IPv4-mapped IPv6 address.

Fixes golang#52264.
database64128 added a commit to database64128/go that referenced this issue Apr 29, 2022
WriteMsgUDPAddrPort should accept IPv4 target addresses on IPv6 UDP sockets.
An IPv4 target address will be converted to an IPv4-mapped IPv6 address.

Fixes golang#52264.
database64128 added a commit to database64128/go that referenced this issue Apr 29, 2022
WriteMsgUDPAddrPort should accept IPv4 target addresses on IPv6 UDP sockets.
An IPv4 target address will be converted to an IPv4-mapped IPv6 address.

Fixes golang#52264.
@bradfitz
Copy link
Contributor

@ianlancetaylor @neild, now that we're moving more stuff over to net/netip, this is pretty painful.

Candidate for Go 1.19 + backport to Go 1.18?

@bradfitz
Copy link
Contributor

@gopherbot, please backport to Go 1.18.

@gopherbot
Copy link

Backport issue(s) opened: #54074 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@dmitshur dmitshur modified the milestones: Backlog, Go1.19 Aug 1, 2022
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 1, 2022
@gopherbot
Copy link

Change https://go.dev/cl/420775 mentions this issue: net: disable TestIPv6WriteMsgUDPAddrPortTargetAddrIPVersion [sic] on DragonflyBSD

gopherbot pushed a commit that referenced this issue Aug 3, 2022
…DragonflyBSD

Like OpenBSD, DragonflyBSD does not do IPv4-in-IPv6 mapping.

For #52264.

Change-Id: Id41606e75652e684f2e0e98c6459156641aec9b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/420775
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
database64128 added a commit to database64128/gibberish-sender-go that referenced this issue Aug 4, 2022
Workaround for golang/go#52264 is no longer needed in 1.19.
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
WriteMsgUDPAddrPort should accept IPv4 target addresses on IPv6 UDP sockets.
An IPv4 target address will be converted to an IPv4-mapped IPv6 address.

Fixes golang#52264.

Change-Id: Ib9ed4c61fa1289ae7bbc8c4c9de1a9951b647ec0
GitHub-Last-Rev: 6776fdb
GitHub-Pull-Request: golang#52265
Reviewed-on: https://go-review.googlesource.com/c/go/+/399454
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
…DragonflyBSD

Like OpenBSD, DragonflyBSD does not do IPv4-in-IPv6 mapping.

For golang#52264.

Change-Id: Id41606e75652e684f2e0e98c6459156641aec9b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/420775
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
@dr2chase
Copy link
Contributor

With respect to backports, what's the status of this bug/fix?
#54074 (1.18 backport) is still open.

@gopherbot
Copy link

Change https://go.dev/cl/425488 mentions this issue: [release-branch.go1.18] net: fix WriteMsgUDPAddrPort addr handling

@dmitshur
Copy link
Contributor

The status of #54074 is that it's approved, but a cherry-pick CL hasn't been made yet. I made CL 425488 following https://go.dev/wiki/MinorReleases#making-cherry-pick-cls.

gopherbot pushed a commit that referenced this issue Aug 26, 2022
WriteMsgUDPAddrPort should accept IPv4 target addresses on IPv6 UDP sockets.
An IPv4 target address will be converted to an IPv4-mapped IPv6 address.

Include the change in CL 420775 to also skip the test on DragonflyBSD.

Updates #52264.
Fixes #54074.

Change-Id: Ib9ed4c61fa1289ae7bbc8c4c9de1a9951b647ec0
GitHub-Last-Rev: 6776fdb
GitHub-Pull-Request: #52265
Reviewed-on: https://go-review.googlesource.com/c/go/+/399454
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/425488
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
@golang golang locked and limited conversation to collaborators Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants