Commit f3041fd8 authored by Steven Allen's avatar Steven Allen

fix loopback addresses

* fe80::1 is not a loopback address
* ::ffff:127.* probably is (IPv4-mapped IPv6)
parent ceed2dc9
......@@ -14,8 +14,8 @@ var (
// IP6Loopback is the ip6 loopback multiaddr
IP6Loopback = ma.StringCast("/ip6/::1")
// IP6LinkLocalLoopback is the ip6 link-local loopback multiaddr
IP6LinkLocalLoopback = ma.StringCast("/ip6/fe80::1")
// IP4MappedIP6Loopback is the IPv4 Mapped IPv6 loopback address.
IP4MappedIP6Loopback = ma.StringCast("/ip6/::ffff:127.0.0.1")
)
// Unspecified Addresses (used for )
......@@ -28,8 +28,8 @@ var (
// following byte sequences is considered a loopback multiaddr.
var loopbackPrefixes = [][]byte{
{ma.P_IP4, 127}, // 127.*
IP6LinkLocalLoopback.Bytes(),
IP6Loopback.Bytes(),
{ma.P_IP6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 127}, // ::ffff:127.*
IP6Loopback.Bytes(), // ::1
}
// IsThinWaist returns whether a Multiaddr starts with "Thin Waist" Protocols.
......
......@@ -306,8 +306,8 @@ func TestIPLoopback(t *testing.T) {
t.Error("IP6Loopback incorrect:", IP6Loopback)
}
if IP6LinkLocalLoopback.String() != "/ip6/fe80::1" {
t.Error("IP6LinkLocalLoopback incorrect:", IP6Loopback)
if IP4MappedIP6Loopback.String() != "/ip6/127.0.0.1" {
t.Error("IP4MappedIP6Loopback incorrect:", IP4MappedIP6Loopback)
}
if !IsIPLoopback(IP4Loopback) {
......@@ -330,8 +330,16 @@ func TestIPLoopback(t *testing.T) {
t.Error("IsIPLoopback failed (IP6Loopback)")
}
if !IsIPLoopback(IP6LinkLocalLoopback) {
t.Error("IsIPLoopback failed (IP6LinkLocalLoopback)")
if !IsIPLoopback(newMultiaddr(t, "/ip6/127.0.0.1")) {
t.Error("IsIPLoopback failed (/ip6/127.0.0.1)")
}
if !IsIPLoopback(newMultiaddr(t, "/ip6/127.99.3.2")) {
t.Error("IsIPLoopback failed (/ip6/127.99.3.2)")
}
if IsIPLoopback(newMultiaddr(t, "/ip6/::fffa:127.99.3.2")) {
t.Error("IsIPLoopback false positive (/ip6/::fffa:127.99.3.2)")
}
}
......@@ -354,10 +362,6 @@ func TestIPUnspecified(t *testing.T) {
}
func TestIP6LinkLocal(t *testing.T) {
if !IsIP6LinkLocal(IP6LinkLocalLoopback) {
t.Error("IsIP6LinkLocal failed (IP6LinkLocalLoopback)")
}
for a := 0; a < 65536; a++ {
isLinkLocal := (a == 0xfe80)
m := newMultiaddr(t, fmt.Sprintf("/ip6/%x::1", a))
......
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