mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-08-19 00:27:38 +08:00
Fix bind_interface
not working with auto_redirect
This commit is contained in:
parent
354ece2bdf
commit
acda4ce985
@ -20,6 +20,7 @@ type NetworkManager interface {
|
|||||||
DefaultOptions() NetworkOptions
|
DefaultOptions() NetworkOptions
|
||||||
RegisterAutoRedirectOutputMark(mark uint32) error
|
RegisterAutoRedirectOutputMark(mark uint32) error
|
||||||
AutoRedirectOutputMark() uint32
|
AutoRedirectOutputMark() uint32
|
||||||
|
AutoRedirectOutputMarkFunc() control.Func
|
||||||
NetworkMonitor() tun.NetworkUpdateMonitor
|
NetworkMonitor() tun.NetworkUpdateMonitor
|
||||||
InterfaceMonitor() tun.DefaultInterfaceMonitor
|
InterfaceMonitor() tun.DefaultInterfaceMonitor
|
||||||
PackageManager() tun.PackageManager
|
PackageManager() tun.PackageManager
|
||||||
|
@ -121,11 +121,16 @@ func NewDefault(ctx context.Context, options option.DialerOptions) (*DefaultDial
|
|||||||
listener.Control = control.Append(listener.Control, bindFunc)
|
listener.Control = control.Append(listener.Control, bindFunc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if options.RoutingMark == 0 && defaultOptions.RoutingMark != 0 {
|
||||||
|
dialer.Control = control.Append(dialer.Control, setMarkWrapper(networkManager, defaultOptions.RoutingMark, true))
|
||||||
|
listener.Control = control.Append(listener.Control, setMarkWrapper(networkManager, defaultOptions.RoutingMark, true))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if options.RoutingMark == 0 && defaultOptions.RoutingMark != 0 {
|
}
|
||||||
dialer.Control = control.Append(dialer.Control, setMarkWrapper(networkManager, defaultOptions.RoutingMark, true))
|
if networkManager != nil {
|
||||||
listener.Control = control.Append(listener.Control, setMarkWrapper(networkManager, defaultOptions.RoutingMark, true))
|
markFunc := networkManager.AutoRedirectOutputMarkFunc()
|
||||||
}
|
dialer.Control = control.Append(dialer.Control, markFunc)
|
||||||
|
listener.Control = control.Append(listener.Control, markFunc)
|
||||||
}
|
}
|
||||||
if options.ReuseAddr {
|
if options.ReuseAddr {
|
||||||
listener.Control = control.Append(listener.Control, control.ReuseAddr())
|
listener.Control = control.Append(listener.Control, control.ReuseAddr())
|
||||||
|
@ -312,7 +312,7 @@ func (r *NetworkManager) AutoDetectInterfaceFunc() control.Func {
|
|||||||
if r.interfaceMonitor == nil {
|
if r.interfaceMonitor == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
bindFunc := control.BindToInterfaceFunc(r.interfaceFinder, func(network string, address string) (interfaceName string, interfaceIndex int, err error) {
|
return control.BindToInterfaceFunc(r.interfaceFinder, func(network string, address string) (interfaceName string, interfaceIndex int, err error) {
|
||||||
remoteAddr := M.ParseSocksaddr(address).Addr
|
remoteAddr := M.ParseSocksaddr(address).Addr
|
||||||
if remoteAddr.IsValid() {
|
if remoteAddr.IsValid() {
|
||||||
iif, err := r.interfaceFinder.ByAddr(remoteAddr)
|
iif, err := r.interfaceFinder.ByAddr(remoteAddr)
|
||||||
@ -326,16 +326,6 @@ func (r *NetworkManager) AutoDetectInterfaceFunc() control.Func {
|
|||||||
}
|
}
|
||||||
return defaultInterface.Name, defaultInterface.Index, nil
|
return defaultInterface.Name, defaultInterface.Index, nil
|
||||||
})
|
})
|
||||||
return func(network, address string, conn syscall.RawConn) error {
|
|
||||||
err := bindFunc(network, address, conn)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if r.autoRedirectOutputMark > 0 {
|
|
||||||
return control.RoutingMark(r.autoRedirectOutputMark)(network, address, conn)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,6 +356,15 @@ func (r *NetworkManager) AutoRedirectOutputMark() uint32 {
|
|||||||
return r.autoRedirectOutputMark
|
return r.autoRedirectOutputMark
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *NetworkManager) AutoRedirectOutputMarkFunc() control.Func {
|
||||||
|
return func(network, address string, conn syscall.RawConn) error {
|
||||||
|
if r.autoRedirectOutputMark == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return control.RoutingMark(r.autoRedirectOutputMark)(network, address, conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *NetworkManager) NetworkMonitor() tun.NetworkUpdateMonitor {
|
func (r *NetworkManager) NetworkMonitor() tun.NetworkUpdateMonitor {
|
||||||
return r.networkMonitor
|
return r.networkMonitor
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user