chore: dialer will consider the routing of the local interface when auto-detect-interface in tun is enabled

for #1881 #1819
This commit is contained in:
wwqgtxx
2025-03-10 10:45:07 +08:00
parent 00e6466153
commit 4bd3ae52bd
5 changed files with 65 additions and 31 deletions

View File

@@ -404,8 +404,14 @@ func Dial(network, address string) (*TCPConn, error) {
var lTcpAddr *net.TCPAddr
var lIpAddr *net.IPAddr
if ifaceName := dialer.DefaultInterface.Load(); len(ifaceName) > 0 {
rAddrPort := raddr.AddrPort()
rAddrPort := raddr.AddrPort()
ifaceName := dialer.DefaultInterface.Load()
if ifaceName == "" {
if finder := dialer.DefaultInterfaceFinder.Load(); finder != nil {
ifaceName = finder.FindInterfaceName(rAddrPort.Addr())
}
}
if len(ifaceName) > 0 {
addr, err := dialer.LookupLocalAddrFromIfaceName(ifaceName, network, rAddrPort.Addr(), int(rAddrPort.Port()))
if err != nil {
return nil, err