]> Cypherpunks repositories - gostls13.git/commitdiff
net: use correct address family when testing for MPTCP support
authorIan Lance Taylor <iant@golang.org>
Fri, 27 Sep 2024 17:17:48 +0000 (10:17 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 30 Sep 2024 18:30:23 +0000 (18:30 +0000)
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 <bsiegert@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>

src/net/mptcpsock_linux.go

index b2ac3ee7182a09c27d8a3e6400f470e6419c4ee8..422309048543199646ea1944981a6273519efe08 100644 (file)
@@ -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)
        }