mirror of
https://github.com/golang/go
synced 2024-11-25 12:47:56 -07:00
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 <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>
This commit is contained in:
parent
ba10a38ed0
commit
aec9b916a2
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user