5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-29 22:31:37 +00:00

Merge pull request #313 from neilalexander/sourcefix

Fix source address selection
This commit is contained in:
Neil Alexander 2019-01-17 23:10:54 +00:00 committed by GitHub
commit f6cb194d5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -245,8 +245,21 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string, sintf string) {
if err != nil { if err != nil {
continue continue
} }
if (src.To4() != nil) == (dst.IP.To4() != nil) { if src.Equal(dst.IP) {
if addrindex == len(addrs)-1 || src.IsGlobalUnicast() { 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{ dialer.LocalAddr = &net.TCPAddr{
IP: src, IP: src,
Port: 0, Port: 0,
@ -255,7 +268,6 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string, sintf string) {
break break
} }
} }
}
if dialer.LocalAddr == nil { if dialer.LocalAddr == nil {
return return
} }