net: filter destination addresses when source address is specified

This change filters out destination addresses by address family when
source address is specified to avoid running Dial operation with wrong
addressing scopes.

Fixes #11837.

Change-Id: I10b7a1fa325add2cd8ed58f105d527700a10d342
Reviewed-on: https://go-review.googlesource.com/20586
Reviewed-by: Paul Marks <pmarks@google.com>
This commit is contained in:
Mikio Hara 2016-03-15 10:00:12 +09:00
parent 76b724cc63
commit 790053b25e
6 changed files with 176 additions and 48 deletions

View file

@ -377,6 +377,10 @@ func bytesEqual(x, y []byte) bool {
return true
}
func (ip IP) matchAddrFamily(x IP) bool {
return ip.To4() != nil && x.To4() != nil || ip.To16() != nil && ip.To4() == nil && x.To16() != nil && x.To4() == nil
}
// If mask is a sequence of 1 bits followed by 0 bits,
// return the number of 1 bits.
func simpleMaskLength(mask IPMask) int {