mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-09 17:49:56 +00:00
chore: force to disable mptcp for tproxy
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/component/keepalive"
|
"github.com/metacubex/mihomo/component/keepalive"
|
||||||
|
"github.com/metacubex/mihomo/component/mptcp"
|
||||||
|
|
||||||
"github.com/metacubex/tfo-go"
|
"github.com/metacubex/tfo-go"
|
||||||
)
|
)
|
||||||
@@ -34,13 +35,13 @@ func Tfo() bool {
|
|||||||
func SetMPTCP(open bool) {
|
func SetMPTCP(open bool) {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
setMultiPathTCP(&lc.ListenConfig, open)
|
mptcp.SetNetListenConfig(&lc.ListenConfig, open)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MPTCP() bool {
|
func MPTCP() bool {
|
||||||
mutex.RLock()
|
mutex.RLock()
|
||||||
defer mutex.RUnlock()
|
defer mutex.RUnlock()
|
||||||
return getMultiPathTCP(&lc.ListenConfig)
|
return mptcp.GetNetListenConfig(&lc.ListenConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func preResolve(network, address string) (string, error) {
|
func preResolve(network, address string) (string, error) {
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
//go:build !go1.21
|
|
||||||
|
|
||||||
package inbound
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
const multipathTCPAvailable = false
|
|
||||||
|
|
||||||
func setMultiPathTCP(listenConfig *net.ListenConfig, open bool) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMultiPathTCP(listenConfig *net.ListenConfig) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
//go:build go1.21
|
|
||||||
|
|
||||||
package inbound
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
const multipathTCPAvailable = true
|
|
||||||
|
|
||||||
func setMultiPathTCP(listenConfig *net.ListenConfig, open bool) {
|
|
||||||
listenConfig.SetMultipathTCP(open)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMultiPathTCP(listenConfig *net.ListenConfig) bool {
|
|
||||||
return listenConfig.MultipathTCP()
|
|
||||||
}
|
|
||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/component/keepalive"
|
"github.com/metacubex/mihomo/component/keepalive"
|
||||||
|
"github.com/metacubex/mihomo/component/mptcp"
|
||||||
"github.com/metacubex/mihomo/component/resolver"
|
"github.com/metacubex/mihomo/component/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -140,9 +141,7 @@ func dialContext(ctx context.Context, network string, destination netip.Addr, po
|
|||||||
|
|
||||||
dialer := netDialer.(*net.Dialer)
|
dialer := netDialer.(*net.Dialer)
|
||||||
keepalive.SetNetDialer(dialer)
|
keepalive.SetNetDialer(dialer)
|
||||||
if opt.mpTcp {
|
mptcp.SetNetDialer(dialer, opt.mpTcp)
|
||||||
setMultiPathTCP(dialer)
|
|
||||||
}
|
|
||||||
|
|
||||||
if DefaultSocketHook != nil { // ignore interfaceName, routingMark and tfo when DefaultSocketHook not null (in CMFA)
|
if DefaultSocketHook != nil { // ignore interfaceName, routingMark and tfo when DefaultSocketHook not null (in CMFA)
|
||||||
socketHookToToDialer(dialer)
|
socketHookToToDialer(dialer)
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
//go:build !go1.21
|
|
||||||
|
|
||||||
package dialer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
)
|
|
||||||
|
|
||||||
const multipathTCPAvailable = false
|
|
||||||
|
|
||||||
func setMultiPathTCP(dialer *net.Dialer) {
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//go:build go1.21
|
|
||||||
|
|
||||||
package dialer
|
|
||||||
|
|
||||||
import "net"
|
|
||||||
|
|
||||||
const multipathTCPAvailable = true
|
|
||||||
|
|
||||||
func setMultiPathTCP(dialer *net.Dialer) {
|
|
||||||
dialer.SetMultipathTCP(true)
|
|
||||||
}
|
|
||||||
23
component/mptcp/mptcp_go120.go
Normal file
23
component/mptcp/mptcp_go120.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//go:build !go1.21
|
||||||
|
|
||||||
|
package mptcp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
const MultipathTCPAvailable = false
|
||||||
|
|
||||||
|
func SetNetDialer(dialer *net.Dialer, open bool) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNetDialer(dialer *net.Dialer) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetNetListenConfig(listenConfig *net.ListenConfig, open bool) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNetListenConfig(listenConfig *net.ListenConfig) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
23
component/mptcp/mptcp_go121.go
Normal file
23
component/mptcp/mptcp_go121.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//go:build go1.21
|
||||||
|
|
||||||
|
package mptcp
|
||||||
|
|
||||||
|
import "net"
|
||||||
|
|
||||||
|
const MultipathTCPAvailable = true
|
||||||
|
|
||||||
|
func SetNetDialer(dialer *net.Dialer, open bool) {
|
||||||
|
dialer.SetMultipathTCP(open)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNetDialer(dialer *net.Dialer) bool {
|
||||||
|
return dialer.MultipathTCP()
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetNetListenConfig(listenConfig *net.ListenConfig, open bool) {
|
||||||
|
listenConfig.SetMultipathTCP(open)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNetListenConfig(listenConfig *net.ListenConfig) bool {
|
||||||
|
return listenConfig.MultipathTCP()
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
package tproxy
|
package tproxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/adapter/inbound"
|
"github.com/metacubex/mihomo/adapter/inbound"
|
||||||
"github.com/metacubex/mihomo/component/keepalive"
|
"github.com/metacubex/mihomo/component/keepalive"
|
||||||
|
"github.com/metacubex/mihomo/component/mptcp"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
C "github.com/metacubex/mihomo/constant"
|
||||||
"github.com/metacubex/mihomo/transport/socks5"
|
"github.com/metacubex/mihomo/transport/socks5"
|
||||||
)
|
)
|
||||||
@@ -46,10 +48,11 @@ func New(addr string, tunnel C.Tunnel, additions ...inbound.Addition) (*Listener
|
|||||||
inbound.WithSpecialRules(""),
|
inbound.WithSpecialRules(""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO: When we upgrade the major version of go.mod to 1.24 or higher, disable mptcp for tproxy.
|
// Golang will then enable mptcp support for listeners by default when the major version of go.mod is 1.24 or higher.
|
||||||
// Golang will then enable mptcp support for listeners by default.
|
// This can cause tproxy to malfunction on certain Linux kernel versions, so we force to disable mptcp for tproxy.
|
||||||
// This can cause tproxy to malfunction on certain Linux kernel versions.
|
lc := net.ListenConfig{}
|
||||||
l, err := net.Listen("tcp", addr)
|
mptcp.SetNetListenConfig(&lc, false)
|
||||||
|
l, err := lc.Listen(context.Background(), "tcp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user