mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-15 21:00:27 +00:00
Fix wg detour
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/sagernet/sing-box/common/dialer"
|
||||
"github.com/sagernet/sing-tun"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
@@ -35,6 +36,7 @@ type Endpoint struct {
|
||||
returnDevice *returnDeviceWrapper
|
||||
device *device.Device
|
||||
allowedIPs *device.AllowedIPs
|
||||
egressPool *tun.UDPEgressPool
|
||||
pause pause.Manager
|
||||
pauseCallback *list.Element[pause.Callback]
|
||||
}
|
||||
@@ -154,13 +156,16 @@ func (e *Endpoint) Start(resolve bool) error {
|
||||
var bind conn.Bind
|
||||
udpListener, isUDPListener := common.Cast[dialer.UDPListener](e.options.Dialer)
|
||||
if isUDPListener {
|
||||
listenerControl, _ := udpListener.UDPListenerControl()
|
||||
listenerControl, egressEnabled := udpListener.UDPListenerControl()
|
||||
standardBind := conn.NewStdNetBind(listenerControl).(*conn.StdNetBind)
|
||||
if e.options.ListenPort == 0 && len(e.peers) == 1 && e.peers[0].endpoint.IsValid() {
|
||||
standardBind.SetSinglePeerMode()
|
||||
}
|
||||
if e.options.EgressPool != nil {
|
||||
standardBind.SetEgressProvider(e.options.EgressPool)
|
||||
if egressEnabled {
|
||||
egressPoolOptions := e.options.EgressPoolOptions
|
||||
egressPoolOptions.Control = listenerControl
|
||||
e.egressPool = tun.NewUDPEgressPool(egressPoolOptions)
|
||||
standardBind.SetEgressProvider(e.egressPool)
|
||||
}
|
||||
bind = standardBind
|
||||
} else {
|
||||
@@ -235,8 +240,9 @@ func (e *Endpoint) Close() error {
|
||||
e.pause.UnregisterCallback(e.pauseCallback)
|
||||
e.pauseCallback = nil
|
||||
}
|
||||
if e.options.EgressPool != nil {
|
||||
e.options.EgressPool.Close()
|
||||
if e.egressPool != nil {
|
||||
e.egressPool.Close()
|
||||
e.egressPool = nil
|
||||
}
|
||||
if e.device != nil {
|
||||
e.device.Down()
|
||||
|
||||
@@ -23,18 +23,18 @@ type EndpointOptions struct {
|
||||
UDPFiltering tun.NATFiltering
|
||||
UDPNATMax uint32
|
||||
|
||||
InterfaceFinder control.InterfaceFinder
|
||||
EgressPool *tun.UDPEgressPool
|
||||
Dialer N.Dialer
|
||||
CreateDialer func(interfaceName string) N.Dialer
|
||||
Name string
|
||||
MTU uint32
|
||||
Address []netip.Prefix
|
||||
PrivateKey string
|
||||
ListenPort uint16
|
||||
ResolvePeer func(domain string) (netip.Addr, error)
|
||||
Peers []PeerOptions
|
||||
Workers int
|
||||
InterfaceFinder control.InterfaceFinder
|
||||
EgressPoolOptions tun.UDPEgressPoolOptions
|
||||
Dialer N.Dialer
|
||||
CreateDialer func(interfaceName string) N.Dialer
|
||||
Name string
|
||||
MTU uint32
|
||||
Address []netip.Prefix
|
||||
PrivateKey string
|
||||
ListenPort uint16
|
||||
ResolvePeer func(domain string) (netip.Addr, error)
|
||||
Peers []PeerOptions
|
||||
Workers int
|
||||
}
|
||||
|
||||
type PeerOptions struct {
|
||||
|
||||
Reference in New Issue
Block a user