mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-15 21:00:27 +00:00
Fix duplicate interface binding for UDP connections
This commit is contained in:
@@ -120,7 +120,6 @@ func NewDefault(ctx context.Context, options option.DialerOptions) (*DefaultDial
|
|||||||
} else {
|
} else {
|
||||||
bindFunc := networkManager.AutoDetectInterfaceFunc()
|
bindFunc := networkManager.AutoDetectInterfaceFunc()
|
||||||
dialer.Control = control.Append(dialer.Control, bindFunc)
|
dialer.Control = control.Append(dialer.Control, bindFunc)
|
||||||
listener.Control = control.Append(listener.Control, bindFunc)
|
|
||||||
autoDetectBindFunc = bindFunc
|
autoDetectBindFunc = bindFunc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,9 +334,12 @@ func (d *DefaultDialer) ListenPacket(ctx context.Context, destination M.Socksadd
|
|||||||
if d.networkStrategy == nil {
|
if d.networkStrategy == nil {
|
||||||
return d.trackPacketConn(listener.ListenNetworkNamespace[net.PacketConn](ctx, d.netns, func() (net.PacketConn, error) {
|
return d.trackPacketConn(listener.ListenNetworkNamespace[net.PacketConn](ctx, d.netns, func() (net.PacketConn, error) {
|
||||||
listenConfig := d.udpListener
|
listenConfig := d.udpListener
|
||||||
if d.autoDetectBindFunc != nil && destination.Addr.IsValid() {
|
if d.autoDetectBindFunc != nil {
|
||||||
listenConfig.Control = control.Append(listenConfig.Control, func(network, address string, conn syscall.RawConn) error {
|
listenConfig.Control = control.Append(listenConfig.Control, func(network, address string, conn syscall.RawConn) error {
|
||||||
return d.autoDetectBindFunc(network, destination.String(), conn)
|
if destination.Addr.IsValid() {
|
||||||
|
return d.autoDetectBindFunc(network, destination.String(), conn)
|
||||||
|
}
|
||||||
|
return d.autoDetectBindFunc(network, address, conn)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if destination.IsIPv6() {
|
if destination.IsIPv6() {
|
||||||
@@ -397,8 +399,8 @@ func (d *DefaultDialer) ListenSerialInterfacePacket(ctx context.Context, destina
|
|||||||
func (d *DefaultDialer) UDPListenerControl() (control.Func, bool) {
|
func (d *DefaultDialer) UDPListenerControl() (control.Func, bool) {
|
||||||
egressEnabled := d.autoDetectBindFunc != nil && d.netns == ""
|
egressEnabled := d.autoDetectBindFunc != nil && d.netns == ""
|
||||||
listenerControl := d.udpListener.Control
|
listenerControl := d.udpListener.Control
|
||||||
if egressEnabled && d.networkManager.AutoRedirectOutputMark() != 0 {
|
if egressEnabled && d.networkManager.AutoRedirectOutputMark() == 0 {
|
||||||
listenerControl = control.Append(listenerControl, control.UnbindFromInterface())
|
listenerControl = control.Append(listenerControl, d.autoDetectBindFunc)
|
||||||
}
|
}
|
||||||
return listenerControl, egressEnabled
|
return listenerControl, egressEnabled
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user