WireGuard outbound: Fix UDP FullCone NAT on Linux (#5858)

Fixes https://github.com/XTLS/Xray-core/issues/5848
This commit is contained in:
LjhAUMEM
2026-04-05 20:57:08 +08:00
committed by GitHub
parent 08301e272c
commit ba88aa173c
6 changed files with 116 additions and 38 deletions

View File

@@ -5,7 +5,6 @@ import (
"syscall"
"time"
"github.com/sagernet/sing/common/control"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/features/dns"
@@ -20,7 +19,7 @@ type SystemDialer interface {
}
type DefaultSystemDialer struct {
controllers []control.Func
controllers []func(network, address string, c syscall.RawConn) error
dns dns.Client
obm outbound.Manager
}
@@ -204,7 +203,7 @@ func UseAlternativeSystemDialer(dialer SystemDialer) {
// It only works when effective dialer is the default dialer.
//
// xray:api:beta
func RegisterDialerController(ctl control.Func) error {
func RegisterDialerController(ctl func(network, address string, c syscall.RawConn) error) error {
if ctl == nil {
return errors.New("nil listener controller")
}

View File

@@ -10,7 +10,6 @@ import (
"time"
"github.com/pires/go-proxyproto"
"github.com/sagernet/sing/common/control"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
)
@@ -18,10 +17,10 @@ import (
var effectiveListener = DefaultListener{}
type DefaultListener struct {
controllers []control.Func
controllers []func(network, address string, c syscall.RawConn) error
}
func getControlFunc(ctx context.Context, sockopt *SocketConfig, controllers []control.Func) func(network, address string, c syscall.RawConn) error {
func getControlFunc(ctx context.Context, sockopt *SocketConfig, controllers []func(network, address string, c syscall.RawConn) error) func(network, address string, c syscall.RawConn) error {
return func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
for _, controller := range controllers {
@@ -186,7 +185,7 @@ func (dl *DefaultListener) ListenPacket(ctx context.Context, addr net.Addr, sock
// The controller can be used to operate on file descriptors before they are put into use.
//
// xray:api:beta
func RegisterListenerController(controller control.Func) error {
func RegisterListenerController(controller func(network, address string, c syscall.RawConn) error) error {
if controller == nil {
return errors.New("nil listener controller")
}

View File

@@ -6,7 +6,6 @@ import (
"syscall"
"testing"
"github.com/sagernet/sing/common/control"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/transport/internet"
)
@@ -14,10 +13,9 @@ import (
func TestRegisterListenerController(t *testing.T) {
var gotFd uintptr
common.Must(internet.RegisterListenerController(func(network, address string, conn syscall.RawConn) error {
return control.Raw(conn, func(fd uintptr) error {
common.Must(internet.RegisterListenerController(func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
gotFd = fd
return nil
})
}))