]> Cypherpunks repositories - gostls13.git/commitdiff
net: classify site-local unicast in address selection
authorMikio Hara <mikioh.mikioh@gmail.com>
Fri, 17 Jul 2015 08:31:49 +0000 (17:31 +0900)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 18 Jul 2015 01:35:25 +0000 (01:35 +0000)
This change adds site-local unicast classification for users still using
the deprecated addresses internally.

Change-Id: If50870c6d4a85fe471c002b161eec59efcebe2f4
Reviewed-on: https://go-review.googlesource.com/12344
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/net/addrselect.go
src/net/addrselect_test.go

index e7b2b48b46395d389b5a270fd24abddb61d56c4b..e22fbac5cee1a99ac0ae7fa7ff31e6e4036a15a0 100644 (file)
@@ -328,11 +328,15 @@ func classifyScope(ip IP) scope {
        if ip.IsLoopback() || ip.IsLinkLocalUnicast() {
                return scopeLinkLocal
        }
-       if len(ip) == IPv6len && ip.To4() == nil && ip.IsMulticast() {
+       ipv6 := len(ip) == IPv6len && ip.To4() == nil
+       if ipv6 && ip.IsMulticast() {
                return scope(ip[1] & 0xf)
        }
-       // TODO: are there unicast scopeAdminLocal, scopeSiteLocal,
-       // scopeOrgLocal? Better question: are those even used?
+       // Site-local addresses are defined in RFC 3513 section 2.5.6
+       // (and deprecated in RFC 3879).
+       if ipv6 && ip[0] == 0xfe && ip[1]&0xc0 == 0xc0 {
+               return scopeSiteLocal
+       }
        return scopeGlobal
 }
 
index 7f7cb1b82729377658da68dde5c7943caa6be4fc..562022772fa853c0e543d07b2502c91a117f5f1a 100644 (file)
@@ -169,6 +169,7 @@ func TestRFC6724ClassifyScope(t *testing.T) {
                {ParseIP("127.0.0.1"), scopeLinkLocal},   // rfc6724#section-3.2
                {ParseIP("::1"), scopeLinkLocal},         // rfc4007#section-4
                {ParseIP("169.254.1.2"), scopeLinkLocal}, // rfc6724#section-3.2
+               {ParseIP("fec0::1"), scopeSiteLocal},
                {ParseIP("8.8.8.8"), scopeGlobal},
 
                {ParseIP("ff02::"), scopeLinkLocal},  // IPv6 multicast