Fix source address selection

This commit is contained in:
Neil Alexander 2019-01-17 23:06:59 +00:00
parent 2219d96df1
commit c839012580
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -245,15 +245,27 @@ 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
dialer.LocalAddr = &net.TCPAddr{ }
IP: src, if !src.IsGlobalUnicast() && !src.IsLinkLocalUnicast() {
Port: 0, continue
Zone: sintf, }
} bothglobal := src.IsGlobalUnicast() == dst.IP.IsGlobalUnicast()
break 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,
Zone: sintf,
} }
break
} }
} }
if dialer.LocalAddr == nil { if dialer.LocalAddr == nil {