Skip to content

Commit 5bf2242

Browse files
committed
fix: wireguard not working in CMFA
1 parent c17d7c0 commit 5bf2242

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

component/dialer/dialer.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ func GetTcpConcurrent() bool {
127127
}
128128

129129
func dialContext(ctx context.Context, network string, destination netip.Addr, port string, opt *option) (net.Conn, error) {
130-
if features.CMFA && DefaultSocketHook != nil {
131-
return dialContextHooked(ctx, network, destination, port)
132-
}
133-
134130
var address string
135131
if IP4PEnable {
136132
destination, port = lookupIP4P(destination, port)
@@ -149,6 +145,14 @@ func dialContext(ctx context.Context, network string, destination netip.Addr, po
149145
}
150146

151147
dialer := netDialer.(*net.Dialer)
148+
if opt.mpTcp {
149+
setMultiPathTCP(dialer)
150+
}
151+
152+
if features.CMFA && DefaultSocketHook != nil { // ignore interfaceName, routingMark and tfo in CMFA
153+
return dialContextHooked(ctx, dialer, network, address)
154+
}
155+
152156
if opt.interfaceName != "" {
153157
bind := bindIfaceToDialer
154158
if opt.fallbackBind {
@@ -161,9 +165,6 @@ func dialContext(ctx context.Context, network string, destination netip.Addr, po
161165
if opt.routingMark != 0 {
162166
bindMarkToDialer(opt.routingMark, dialer, network, destination)
163167
}
164-
if opt.mpTcp {
165-
setMultiPathTCP(dialer)
166-
}
167168
if opt.tfo && !DisableTFO {
168169
return dialTFO(ctx, *dialer, network, address)
169170
}

component/dialer/patch_android.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ package dialer
55
import (
66
"context"
77
"net"
8-
"net/netip"
98
"syscall"
109
)
1110

1211
type SocketControl func(network, address string, conn syscall.RawConn) error
1312

1413
var DefaultSocketHook SocketControl
1514

16-
func dialContextHooked(ctx context.Context, network string, destination netip.Addr, port string) (net.Conn, error) {
17-
dialer := &net.Dialer{
18-
Control: DefaultSocketHook,
19-
}
15+
func dialContextHooked(ctx context.Context, dialer *net.Dialer, network string, address string) (net.Conn, error) {
16+
addControlToDialer(dialer, func(ctx context.Context, network, address string, c syscall.RawConn) error {
17+
return DefaultSocketHook(network, address, c)
18+
})
2019

21-
conn, err := dialer.DialContext(ctx, network, net.JoinHostPort(destination.String(), port))
20+
conn, err := dialer.DialContext(ctx, network, address)
2221
if err != nil {
2322
return nil, err
2423
}

component/dialer/patch_common.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ package dialer
55
import (
66
"context"
77
"net"
8-
"net/netip"
98
"syscall"
109
)
1110

1211
type SocketControl func(network, address string, conn syscall.RawConn) error
1312

1413
var DefaultSocketHook SocketControl
1514

16-
func dialContextHooked(ctx context.Context, network string, destination netip.Addr, port string) (net.Conn, error) {
15+
func dialContextHooked(ctx context.Context, dialer *net.Dialer, network string, address string) (net.Conn, error) {
1716
return nil, nil
1817
}
1918

0 commit comments

Comments
 (0)