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

Open
database64128 opened this issue Apr 10, 2022 · 3 comments · May be fixed by #52265
Open

net: WriteMsgUDPAddrPort should accept IPv4 destination addresses on IPv6 UDP sockets #52264

database64128 opened this issue Apr 10, 2022 · 3 comments · May be fixed by #52265
Labels
NeedsInvestigation
Milestone

Comments

@database64128
Copy link

@database64128 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.
@database64128 database64128 linked a pull request Apr 10, 2022 that will close this issue
@gopherbot
Copy link

@gopherbot gopherbot commented Apr 10, 2022

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

@moredure moredure commented Apr 10, 2022

@database64128 maybe !addr.IsValid() ?

@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Apr 11, 2022

@dmitshur dmitshur added this to the Backlog milestone Apr 11, 2022
@dmitshur dmitshur added the NeedsInvestigation 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants