]> Cypherpunks repositories - gostls13.git/commitdiff
net: make use of IPv4 for parsing routing information on windows
authorMikio Hara <mikioh.mikioh@gmail.com>
Fri, 18 Dec 2015 03:39:57 +0000 (12:39 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Sat, 19 Dec 2015 10:00:04 +0000 (10:00 +0000)
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/17992
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/net/interface_test.go
src/net/interface_windows.go

index c5e7c432cd51ba38d1254af029150484993bec76..7bdd924150371e9c6d369929dbb9389c9ce840ad 100644 (file)
@@ -185,6 +185,10 @@ func testAddrs(t *testing.T, ifat []Addr) (naf4, naf6 int) {
                                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
+                       }
                        prefixLen, maxPrefixLen := ifa.Mask.Size()
                        if ifa.IP.To4() != nil {
                                if 0 >= prefixLen || prefixLen > 8*IPv4len || maxPrefixLen != 8*IPv4len {
@@ -211,7 +215,11 @@ func testAddrs(t *testing.T, ifat []Addr) (naf4, naf6 int) {
                        t.Logf("interface address %q", ifa.String())
                case *IPAddr:
                        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
                        }
                        if ifa.IP.To4() != nil {
@@ -233,7 +241,11 @@ func testMulticastAddrs(t *testing.T, ifmat []Addr) (nmaf4, nmaf6 int) {
                switch ifma := ifma.(type) {
                case *IPAddr:
                        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
                        }
                        if ifma.IP.To4() != nil {
index d14b60f283e12ef9070ff9f1caccc1abbd2f5a97..4d6bcdf4c76a04bccce89bd589f1de21d0a8c3ca 100644 (file)
@@ -95,9 +95,7 @@ func interfaceTable(ifindex int) ([]Interface, error) {
                        case windows.IF_TYPE_SOFTWARE_LOOPBACK:
                                ifi.Flags |= FlagLoopback | FlagMulticast
                        case windows.IF_TYPE_ATM:
-                               ifi.Flags |= FlagBroadcast |
-                                       FlagPointToPoint |
-                                       FlagMulticast // assume all services available; LANE, point-to-point and point-to-multipoint
+                               ifi.Flags |= FlagBroadcast | FlagPointToPoint | FlagMulticast // assume all services available; LANE, point-to-point and point-to-multipoint
                        }
                        if aa.Mtu == 0xffffffff {
                                ifi.MTU = -1
@@ -152,9 +150,7 @@ func interfaceAddrTable(ifi *Interface) ([]Addr, error) {
                                        } else {
                                                l = addrPrefixLen(pfx4, IP(sa.Addr[:]))
                                        }
-                                       ifa := &IPNet{IP: make(IP, IPv4len), Mask: CIDRMask(l, 8*IPv4len)}
-                                       copy(ifa.IP, sa.Addr[:])
-                                       ifat = append(ifat, ifa)
+                                       ifat = append(ifat, &IPNet{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3]), Mask: CIDRMask(l, 8*IPv4len)})
                                case *syscall.SockaddrInet6:
                                        if supportsVistaIP {
                                                l = int(puni.OnLinkPrefixLength)
@@ -173,9 +169,7 @@ func interfaceAddrTable(ifi *Interface) ([]Addr, error) {
                                }
                                switch sa := sa.(type) {
                                case *syscall.SockaddrInet4:
-                                       ifa := &IPAddr{IP: make(IP, IPv4len)}
-                                       copy(ifa.IP, sa.Addr[:])
-                                       ifat = append(ifat, ifa)
+                                       ifat = append(ifat, &IPAddr{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])})
                                case *syscall.SockaddrInet6:
                                        ifa := &IPAddr{IP: make(IP, IPv6len)}
                                        copy(ifa.IP, sa.Addr[:])
@@ -261,9 +255,7 @@ func interfaceMulticastAddrTable(ifi *Interface) ([]Addr, error) {
                                }
                                switch sa := sa.(type) {
                                case *syscall.SockaddrInet4:
-                                       ifa := &IPAddr{IP: make(IP, IPv4len)}
-                                       copy(ifa.IP, sa.Addr[:])
-                                       ifat = append(ifat, ifa)
+                                       ifat = append(ifat, &IPAddr{IP: IPv4(sa.Addr[0], sa.Addr[1], sa.Addr[2], sa.Addr[3])})
                                case *syscall.SockaddrInet6:
                                        ifa := &IPAddr{IP: make(IP, IPv6len)}
                                        copy(ifa.IP, sa.Addr[:])