diff --git a/src/core/link_tcp.go b/src/core/link_tcp.go index 889051b98..7b8410540 100644 --- a/src/core/link_tcp.go +++ b/src/core/link_tcp.go @@ -27,6 +27,7 @@ func (l *links) newLinkTCP() *linkTCP { _listeners: map[*Listener]context.CancelFunc{}, } lt.listenconfig.Control = lt.tcpContext + setMPTCPForListener(lt.listenconfig) return lt } @@ -118,6 +119,7 @@ func (l *linkTCP) dialerFor(dst *net.TCPAddr, sintf string) (*net.Dialer, error) KeepAlive: -1, Control: l.tcpContext, } + setMPTCPForDialer(dialer) if sintf != "" { dialer.Control = l.getControl(sintf) ief, err := net.InterfaceByName(sintf) diff --git a/src/core/link_tcp_mptcp_go121.go b/src/core/link_tcp_mptcp_go121.go new file mode 100644 index 000000000..545273625 --- /dev/null +++ b/src/core/link_tcp_mptcp_go121.go @@ -0,0 +1,14 @@ +//go:build go1.21 +// +build go1.21 + +package core + +import "net" + +func setMPTCPForDialer(d *net.Dialer) { + d.SetMultipathTCP(true) +} + +func setMPTCPForListener(lc *net.ListenConfig) { + lc.SetMultipathTCP(true) +} diff --git a/src/core/link_tcp_mptcp_other.go b/src/core/link_tcp_mptcp_other.go new file mode 100644 index 000000000..28bc46c58 --- /dev/null +++ b/src/core/link_tcp_mptcp_other.go @@ -0,0 +1,14 @@ +//go:build !go1.21 +// +build !go1.21 + +package core + +import "net" + +func setMPTCPForDialer(d *net.Dialer) { + // Not supported on versions under Go 1.21 +} + +func setMPTCPForListener(lc *net.ListenConfig) { + // Not supported on versions under Go 1.21 +} diff --git a/src/core/link_tls.go b/src/core/link_tls.go index a93227f62..9648477ec 100644 --- a/src/core/link_tls.go +++ b/src/core/link_tls.go @@ -30,6 +30,7 @@ func (l *links) newLinkTLS(tcp *linkTCP) *linkTLS { config: l.core.config.tls.Clone(), _listeners: map[*Listener]context.CancelFunc{}, } + setMPTCPForListener(lt.listener) return lt }