Skip to content

Commit

Permalink
fix: wireguard not working in CMFA
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Aug 13, 2024
1 parent c17d7c0 commit 5bf2242
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
15 changes: 8 additions & 7 deletions component/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ func GetTcpConcurrent() bool {
}

func dialContext(ctx context.Context, network string, destination netip.Addr, port string, opt *option) (net.Conn, error) {
if features.CMFA && DefaultSocketHook != nil {
return dialContextHooked(ctx, network, destination, port)
}

var address string
if IP4PEnable {
destination, port = lookupIP4P(destination, port)
Expand All @@ -149,6 +145,14 @@ func dialContext(ctx context.Context, network string, destination netip.Addr, po
}

dialer := netDialer.(*net.Dialer)
if opt.mpTcp {
setMultiPathTCP(dialer)
}

if features.CMFA && DefaultSocketHook != nil { // ignore interfaceName, routingMark and tfo in CMFA
return dialContextHooked(ctx, dialer, network, address)
}

if opt.interfaceName != "" {
bind := bindIfaceToDialer
if opt.fallbackBind {
Expand All @@ -161,9 +165,6 @@ func dialContext(ctx context.Context, network string, destination netip.Addr, po
if opt.routingMark != 0 {
bindMarkToDialer(opt.routingMark, dialer, network, destination)
}
if opt.mpTcp {
setMultiPathTCP(dialer)
}
if opt.tfo && !DisableTFO {
return dialTFO(ctx, *dialer, network, address)
}
Expand Down
11 changes: 5 additions & 6 deletions component/dialer/patch_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ package dialer
import (
"context"
"net"
"net/netip"
"syscall"
)

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

var DefaultSocketHook SocketControl

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

conn, err := dialer.DialContext(ctx, network, net.JoinHostPort(destination.String(), port))
conn, err := dialer.DialContext(ctx, network, address)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions component/dialer/patch_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ package dialer
import (
"context"
"net"
"net/netip"
"syscall"
)

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

var DefaultSocketHook SocketControl

func dialContextHooked(ctx context.Context, network string, destination netip.Addr, port string) (net.Conn, error) {
func dialContextHooked(ctx context.Context, dialer *net.Dialer, network string, address string) (net.Conn, error) {
return nil, nil
}

Expand Down

0 comments on commit 5bf2242

Please sign in to comment.