Skip to content

Commit 59d7c69

Browse files
matttbegopherbot
authored andcommitted
net: add initial MPTCP support
This currently defines an internal function supportsMultipathTCP which reports whether MPTCP[1] is supported on the current platform. Only Linux is supported here. The check on Linux is performed once by attemting to create an MPTCP socket and look at the returned error: - If the protocol is not supported, EINVAL (kernel < 5.6) or EPROTONOSUPPORT (kernel >= 5.6) is returned and there is no point to try again. - Other errors can be returned: - ENOPROTOOPT: the sysctl knob net.mptcp.enabled is set to 0 - Unpredictable ones: if MPTCP is blocked using SELinux, eBPF, etc. These other errors are due to modifications that can be reverted during the session: MPTCP can be available again later. In this case, it is fine to always try to create an MPTCP socket and fallback to TCP in case of error. This work has been co-developped by Gregory Detal <[email protected]>. [1] https://www.rfc-editor.org/rfc/rfc8684.html Updates #56539 Change-Id: Ic84fe85aad887a2be4556a898e649bf6b6f12f03 Reviewed-on: https://go-review.googlesource.com/c/go/+/471135 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 16544b8 commit 59d7c69

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/net/mptcpsock_linux.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package net
6+
7+
import (
8+
"errors"
9+
"internal/poll"
10+
"sync"
11+
"syscall"
12+
)
13+
14+
var (
15+
mptcpOnce sync.Once
16+
mptcpAvailable bool
17+
)
18+
19+
// These constants aren't in the syscall package, which is frozen
20+
const (
21+
_IPPROTO_MPTCP = 0x106
22+
)
23+
24+
func supportsMultipathTCP() bool {
25+
mptcpOnce.Do(initMPTCPavailable)
26+
return mptcpAvailable
27+
}
28+
29+
// Check that MPTCP is supported by attemting to create an MPTCP socket and by
30+
// looking at the returned error if any.
31+
func initMPTCPavailable() {
32+
s, err := sysSocket(syscall.AF_INET, syscall.SOCK_STREAM, _IPPROTO_MPTCP)
33+
switch {
34+
case errors.Is(err, syscall.EPROTONOSUPPORT): // Not supported: >= v5.6
35+
case errors.Is(err, syscall.EINVAL): // Not supported: < v5.6
36+
case err == nil: // Supported and no error
37+
poll.CloseFunc(s)
38+
fallthrough
39+
default:
40+
// another error: MPTCP was not available but it might be later
41+
mptcpAvailable = true
42+
}
43+
}

src/net/mptcpsock_stub.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !linux
6+
7+
package net

0 commit comments

Comments
 (0)