Commit 262d6f58 authored by Mikio Hara's avatar Mikio Hara

syscall: fix IPv6 wrong network mask on latest FreeBSD

Looks like latest FreeBSD doesn't set address family identifer
for RTAX_NETMASK stuff; probably RTAX_GENMASK too, not confirmed.
This CL tries to identify address families by using the length of
each socket address if possible.

The issue is confirmed on FreeBSD 9.1.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12332043
parent 7583c14b
......@@ -108,12 +108,23 @@ func testInterfaceMulticastAddrs(t *testing.T, ifi *Interface) {
func testAddrs(t *testing.T, ifat []Addr) {
for _, ifa := range ifat {
switch ifa := ifa.(type) {
case *IPAddr, *IPNet:
case *IPAddr:
if ifa == nil {
t.Errorf("\tunexpected value: %v", ifa)
} else {
t.Logf("\tinterface address %q", ifa.String())
}
case *IPNet:
if ifa == nil {
t.Errorf("\tunexpected value: %v", ifa)
} else {
_, prefixLen := ifa.Mask.Size()
if ifa.IP.To4() != nil && prefixLen != 8*IPv4len || ifa.IP.To16() != nil && ifa.IP.To4() == nil && prefixLen != 8*IPv6len {
t.Errorf("\tunexpected value: %v, %v, %v, %v", ifa, ifa.IP, ifa.Mask, prefixLen)
} else {
t.Logf("\tinterface address %q", ifa.String())
}
}
default:
t.Errorf("\tunexpected type: %T", ifa)
}
......
......@@ -156,8 +156,15 @@ func (m *InterfaceAddrMessage) sockaddr() (sas []Sockaddr) {
sas = append(sas, sa)
case RTAX_NETMASK:
if rsa.Family == AF_UNSPEC {
switch rsa.Len {
case SizeofSockaddrInet4:
rsa.Family = AF_INET
case SizeofSockaddrInet6:
rsa.Family = AF_INET6
default:
rsa.Family = AF_INET // an old fasion, AF_UNSPEC means AF_INET
}
}
sa, err := anyToSockaddr((*RawSockaddrAny)(unsafe.Pointer(rsa)))
if err != nil {
return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment