Commit 97f854cd authored by Mikio Hara's avatar Mikio Hara

net: make use of IPv4 for parsing routing information on windows

In general the package net deals IPv4 addresses as IPv6 IPv4-mapped
addresses internally for the dual stack era, when we need to support
various techniques on IPv4/IPv6 translation.

This change makes windows implementation follow the same pattern which
BSD variants and Linux do.

Updates #13544.

Also fixes an unintentionally formatted line by accident by gofmt.

Change-Id: I4953796e751fd8050c73094468a0d7b0d33f5516
Reviewed-on: https://go-review.googlesource.com/17992Reviewed-by: 's avatarAlex Brainman <alex.brainman@gmail.com>
parent 2cf5f04f
...@@ -185,6 +185,10 @@ func testAddrs(t *testing.T, ifat []Addr) (naf4, naf6 int) { ...@@ -185,6 +185,10 @@ func testAddrs(t *testing.T, ifat []Addr) (naf4, naf6 int) {
t.Errorf("unexpected value: %#v", ifa) t.Errorf("unexpected value: %#v", ifa)
continue continue
} }
if len(ifa.IP) != IPv6len {
t.Errorf("should be internal representation either IPv6 or IPv6 IPv4-mapped address: %#v", ifa)
continue
}
prefixLen, maxPrefixLen := ifa.Mask.Size() prefixLen, maxPrefixLen := ifa.Mask.Size()
if ifa.IP.To4() != nil { if ifa.IP.To4() != nil {
if 0 >= prefixLen || prefixLen > 8*IPv4len || maxPrefixLen != 8*IPv4len { if 0 >= prefixLen || prefixLen > 8*IPv4len || maxPrefixLen != 8*IPv4len {
...@@ -211,7 +215,11 @@ func testAddrs(t *testing.T, ifat []Addr) (naf4, naf6 int) { ...@@ -211,7 +215,11 @@ func testAddrs(t *testing.T, ifat []Addr) (naf4, naf6 int) {
t.Logf("interface address %q", ifa.String()) t.Logf("interface address %q", ifa.String())
case *IPAddr: case *IPAddr:
if ifa == nil || ifa.IP == nil || ifa.IP.IsUnspecified() || ifa.IP.IsMulticast() { if ifa == nil || ifa.IP == nil || ifa.IP.IsUnspecified() || ifa.IP.IsMulticast() {
t.Errorf("unexpected value: %+v", ifa) t.Errorf("unexpected value: %#v", ifa)
continue
}
if len(ifa.IP) != IPv6len {
t.Errorf("should be internal representation either IPv6 or IPv6 IPv4-mapped address: %#v", ifa)
continue continue
} }
if ifa.IP.To4() != nil { if ifa.IP.To4() != nil {
...@@ -233,7 +241,11 @@ func testMulticastAddrs(t *testing.T, ifmat []Addr) (nmaf4, nmaf6 int) { ...@@ -233,7 +241,11 @@ func testMulticastAddrs(t *testing.T, ifmat []Addr) (nmaf4, nmaf6 int) {
switch ifma := ifma.(type) { switch ifma := ifma.(type) {
case *IPAddr: case *IPAddr:
if ifma == nil || ifma.IP == nil || ifma.IP.IsUnspecified() || !ifma.IP.IsMulticast() { if ifma == nil || ifma.IP == nil || ifma.IP.IsUnspecified() || !ifma.IP.IsMulticast() {
t.Errorf("unexpected value: %#v", ifma) t.Errorf("unexpected value: %+v", ifma)
continue
}
if len(ifma.IP) != IPv6len {
t.Errorf("should be internal representation either IPv6 or IPv6 IPv4-mapped address: %#v", ifma)
continue continue
} }
if ifma.IP.To4() != nil { if ifma.IP.To4() != nil {
......
...@@ -95,9 +95,7 @@ func interfaceTable(ifindex int) ([]Interface, error) { ...@@ -95,9 +95,7 @@ func interfaceTable(ifindex int) ([]Interface, error) {
case windows.IF_TYPE_SOFTWARE_LOOPBACK: case windows.IF_TYPE_SOFTWARE_LOOPBACK:
ifi.Flags |= FlagLoopback | FlagMulticast ifi.Flags |= FlagLoopback | FlagMulticast
case windows.IF_TYPE_ATM: case windows.IF_TYPE_ATM:
ifi.Flags |= FlagBroadcast | ifi.Flags |= FlagBroadcast | FlagPointToPoint | FlagMulticast // assume all services available; LANE, point-to-point and point-to-multipoint
FlagPointToPoint |
FlagMulticast // assume all services available; LANE, point-to-point and point-to-multipoint
} }
if aa.Mtu == 0xffffffff { if aa.Mtu == 0xffffffff {
ifi.MTU = -1 ifi.MTU = -1
...@@ -152,9 +150,7 @@ func interfaceAddrTable(ifi *Interface) ([]Addr, error) { ...@@ -152,9 +150,7 @@ func interfaceAddrTable(ifi *Interface) ([]Addr, error) {
} else { } else {
l = addrPrefixLen(pfx4, IP(sa.Addr[:])) l = addrPrefixLen(pfx4, IP(sa.Addr[:]))
} }
ifa := &IPNet{IP: make(IP, IPv4len), Mask: CIDRMask(l, 8*IPv4len)} ifat = append(ifat, &IPNet{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3]), Mask: CIDRMask(l, 8*IPv4len)})
copy(ifa.IP, sa.Addr[:])
ifat = append(ifat, ifa)
case *syscall.SockaddrInet6: case *syscall.SockaddrInet6:
if supportsVistaIP { if supportsVistaIP {
l = int(puni.OnLinkPrefixLength) l = int(puni.OnLinkPrefixLength)
...@@ -173,9 +169,7 @@ func interfaceAddrTable(ifi *Interface) ([]Addr, error) { ...@@ -173,9 +169,7 @@ func interfaceAddrTable(ifi *Interface) ([]Addr, error) {
} }
switch sa := sa.(type) { switch sa := sa.(type) {
case *syscall.SockaddrInet4: case *syscall.SockaddrInet4:
ifa := &IPAddr{IP: make(IP, IPv4len)} ifat = append(ifat, &IPAddr{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])})
copy(ifa.IP, sa.Addr[:])
ifat = append(ifat, ifa)
case *syscall.SockaddrInet6: case *syscall.SockaddrInet6:
ifa := &IPAddr{IP: make(IP, IPv6len)} ifa := &IPAddr{IP: make(IP, IPv6len)}
copy(ifa.IP, sa.Addr[:]) copy(ifa.IP, sa.Addr[:])
...@@ -261,9 +255,7 @@ func interfaceMulticastAddrTable(ifi *Interface) ([]Addr, error) { ...@@ -261,9 +255,7 @@ func interfaceMulticastAddrTable(ifi *Interface) ([]Addr, error) {
} }
switch sa := sa.(type) { switch sa := sa.(type) {
case *syscall.SockaddrInet4: case *syscall.SockaddrInet4:
ifa := &IPAddr{IP: make(IP, IPv4len)} ifat = append(ifat, &IPAddr{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])})
copy(ifa.IP, sa.Addr[:])
ifat = append(ifat, ifa)
case *syscall.SockaddrInet6: case *syscall.SockaddrInet6:
ifa := &IPAddr{IP: make(IP, IPv6len)} ifa := &IPAddr{IP: make(IP, IPv6len)}
copy(ifa.IP, sa.Addr[:]) copy(ifa.IP, sa.Addr[:])
......
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