mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 07:11:40 +00:00
Fix source address selection
This commit is contained in:
parent
2219d96df1
commit
c839012580
@ -245,8 +245,21 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string, sintf string) {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if (src.To4() != nil) == (dst.IP.To4() != nil) {
|
||||
if addrindex == len(addrs)-1 || src.IsGlobalUnicast() {
|
||||
if src.Equal(dst.IP) {
|
||||
continue
|
||||
}
|
||||
if !src.IsGlobalUnicast() && !src.IsLinkLocalUnicast() {
|
||||
continue
|
||||
}
|
||||
bothglobal := src.IsGlobalUnicast() == dst.IP.IsGlobalUnicast()
|
||||
bothlinklocal := src.IsLinkLocalUnicast() == dst.IP.IsLinkLocalUnicast()
|
||||
if !bothglobal && !bothlinklocal {
|
||||
continue
|
||||
}
|
||||
if (src.To4() != nil) != (dst.IP.To4() != nil) {
|
||||
continue
|
||||
}
|
||||
if bothglobal || bothlinklocal || addrindex == len(addrs)-1 {
|
||||
dialer.LocalAddr = &net.TCPAddr{
|
||||
IP: src,
|
||||
Port: 0,
|
||||
@ -255,7 +268,6 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string, sintf string) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if dialer.LocalAddr == nil {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user