diff --git a/adapter/outbound/direct.go b/adapter/outbound/direct.go index 1b01a576..09b9696b 100644 --- a/adapter/outbound/direct.go +++ b/adapter/outbound/direct.go @@ -4,14 +4,19 @@ import ( "context" "errors" "net/netip" + "os" + "strconv" N "github.com/metacubex/mihomo/common/net" "github.com/metacubex/mihomo/component/dialer" "github.com/metacubex/mihomo/component/loopback" "github.com/metacubex/mihomo/component/resolver" C "github.com/metacubex/mihomo/constant" + "github.com/metacubex/mihomo/constant/features" ) +var DisableLoopBackDetector, _ = strconv.ParseBool(os.Getenv("DISABLE_LOOPBACK_DETECTOR")) + type Direct struct { *Base loopBack *loopback.Detector @@ -24,8 +29,10 @@ type DirectOption struct { // DialContext implements C.ProxyAdapter func (d *Direct) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) { - if err := d.loopBack.CheckConn(metadata); err != nil { - return nil, err + if !features.CMFA && !DisableLoopBackDetector { + if err := d.loopBack.CheckConn(metadata); err != nil { + return nil, err + } } opts = append(opts, dialer.WithResolver(resolver.DefaultResolver)) c, err := dialer.DialContext(ctx, "tcp", metadata.RemoteAddress(), d.Base.DialOptions(opts...)...) @@ -38,8 +45,10 @@ func (d *Direct) DialContext(ctx context.Context, metadata *C.Metadata, opts ... // ListenPacketContext implements C.ProxyAdapter func (d *Direct) ListenPacketContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.PacketConn, error) { - if err := d.loopBack.CheckPacketConn(metadata); err != nil { - return nil, err + if !features.CMFA && !DisableLoopBackDetector { + if err := d.loopBack.CheckPacketConn(metadata); err != nil { + return nil, err + } } // net.UDPConn.WriteTo only working with *net.UDPAddr, so we need a net.UDPAddr if !metadata.Resolved() {