From: Ian Lance Taylor Date: Fri, 27 Sep 2024 17:17:48 +0000 (-0700) Subject: net: use correct address family when testing for MPTCP support X-Git-Tag: go1.24rc1~789 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=aec9b916a2d54a3248553b920cf3a29b52f54998;p=gostls13.git net: use correct address family when testing for MPTCP support Before this patch, on a system that only supports IPv6, we would get EAFNOSUPPORT and decide that MPTCP might be available later. The effect is that every socket tries to get MPTCP. If the system does not support MPTCP, every socket call turns into two system calls. Also avoid the uname if MPTCP is not supported. For #56539 Change-Id: I628b44eda83b455f5493a9dd59076f1acea2f65b Reviewed-on: https://go-review.googlesource.com/c/go/+/616335 Reviewed-by: Benny Siegert Reviewed-by: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Damien Neil Reviewed-by: Matthieu Baerts Auto-Submit: Ian Lance Taylor --- diff --git a/src/net/mptcpsock_linux.go b/src/net/mptcpsock_linux.go index b2ac3ee718..4223090485 100644 --- a/src/net/mptcpsock_linux.go +++ b/src/net/mptcpsock_linux.go @@ -16,7 +16,7 @@ import ( var ( mptcpOnce sync.Once mptcpAvailable bool - hasSOLMPTCP bool + hasSOLMPTCP bool // only valid if mptcpAvailable is true ) // These constants aren't in the syscall package, which is frozen @@ -34,10 +34,17 @@ func supportsMultipathTCP() bool { // Check that MPTCP is supported by attempting to create an MPTCP socket and by // looking at the returned error if any. func initMPTCPavailable() { - s, err := sysSocket(syscall.AF_INET, syscall.SOCK_STREAM, _IPPROTO_MPTCP) + family := syscall.AF_INET + if !supportsIPv4() { + family = syscall.AF_INET6 + } + s, err := sysSocket(family, syscall.SOCK_STREAM, _IPPROTO_MPTCP) + switch { case errors.Is(err, syscall.EPROTONOSUPPORT): // Not supported: >= v5.6 + return case errors.Is(err, syscall.EINVAL): // Not supported: < v5.6 + return case err == nil: // Supported and no error poll.CloseFunc(s) fallthrough @@ -119,6 +126,10 @@ func isUsingMPTCPProto(fd *netFD) bool { // Please look at the description of hasFallenBack (kernel >=5.16) and // isUsingMPTCPProto methods for more details about what is being checked here. func isUsingMultipathTCP(fd *netFD) bool { + if !supportsMultipathTCP() { + return false + } + if hasSOLMPTCP { return !hasFallenBack(fd) }