]> Cypherpunks repositories - gostls13.git/commitdiff
net: check for MPTCP in DialTCP and ListenTCP
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Thu, 21 Nov 2024 20:21:18 +0000 (20:21 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 21 Nov 2024 22:53:35 +0000 (22:53 +0000)
Setting GODEBUG=multipathtcp= [1] has no effects on apps using
ListenTCP or DialTCP directly.

According to the documentation, these functions are supposed to act like
Listen and Dial respectively:

    ListenTCP acts like Listen for TCP networks.
    DialTCP acts like Dial for TCP networks.

So when reading this, I think we should expect GODEBUG=multipathtcp= to
act on these functions as well.

Also, since #69016, MPTCP is used by default (if supported) with TCP
listeners. Similarly, when ListenTCP is used directly, MPTCP is
unexpectedly not used. It is strange to have a different behaviour.

So now, ListenTCP and DialTCP also check for MPTCP. Those are the exact
same checks that are done in dial.go, see Listen and dialSingle.

[1] https://pkg.go.dev/net#Dialer.SetMultipathTCP

Fixes #70500

Change-Id: I646431a74571668e505493fa8c1b2206bf30ed09
GitHub-Last-Rev: 69a31a1b033497fa219309410f16c4524aa6bba9
GitHub-Pull-Request: golang/go#70501
Reviewed-on: https://go-review.googlesource.com/c/go/+/630715
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/net/tcpsock.go

index f5df502f0fd000cc40bc6b5ffe2930922f2684d4..92966b705be4a84563c97381f0519f3900167739 100644 (file)
@@ -324,7 +324,15 @@ func DialTCP(network string, laddr, raddr *TCPAddr) (*TCPConn, error) {
                return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: nil, Err: errMissingAddress}
        }
        sd := &sysDialer{network: network, address: raddr.String()}
-       c, err := sd.dialTCP(context.Background(), laddr, raddr)
+       var (
+               c   *TCPConn
+               err error
+       )
+       if sd.MultipathTCP() {
+               c, err = sd.dialMPTCP(context.Background(), laddr, raddr)
+       } else {
+               c, err = sd.dialTCP(context.Background(), laddr, raddr)
+       }
        if err != nil {
                return nil, &OpError{Op: "dial", Net: network, Source: laddr.opAddr(), Addr: raddr.opAddr(), Err: err}
        }
@@ -439,7 +447,15 @@ func ListenTCP(network string, laddr *TCPAddr) (*TCPListener, error) {
                laddr = &TCPAddr{}
        }
        sl := &sysListener{network: network, address: laddr.String()}
-       ln, err := sl.listenTCP(context.Background(), laddr)
+       var (
+               ln  *TCPListener
+               err error
+       )
+       if sl.MultipathTCP() {
+               ln, err = sl.listenMPTCP(context.Background(), laddr)
+       } else {
+               ln, err = sl.listenTCP(context.Background(), laddr)
+       }
        if err != nil {
                return nil, &OpError{Op: "listen", Net: network, Source: nil, Addr: laddr.opAddr(), Err: err}
        }