From f3041fd8a9992d89cd4256327bc2a7084df5c4bf Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 7 Jun 2018 19:42:11 -0700 Subject: [PATCH 1/3] fix loopback addresses * fe80::1 is not a loopback address * ::ffff:127.* probably is (IPv4-mapped IPv6) --- ip.go | 8 ++++---- net_test.go | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ip.go b/ip.go index d188957..421dddf 100644 --- a/ip.go +++ b/ip.go @@ -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. diff --git a/net_test.go b/net_test.go index 9454fe2..553dcba 100644 --- a/net_test.go +++ b/net_test.go @@ -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)) From fe3aa6e2cf8c3de0135eac21af65794c21ae8363 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sun, 30 Sep 2018 17:06:00 -0700 Subject: [PATCH 2/3] ci: update to go 1.11 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e7b6fda..c0c4fb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ sudo: true language: go go: - - 1.9.x + - 1.11 install: - make deps From 5d0dbe0fb971e6fb178bfc56de08235bfbb40f6f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sun, 30 Sep 2018 17:16:44 -0700 Subject: [PATCH 3/3] fix IsIPLoopback comment --- ip.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip.go b/ip.go index 421dddf..e5054dc 100644 --- a/ip.go +++ b/ip.go @@ -60,7 +60,7 @@ func IsThinWaist(m ma.Multiaddr) bool { } // IsIPLoopback returns whether a Multiaddr is a "Loopback" IP address -// This means either /ip4/127.*.*.*, /ip6/::1, or /ip6/fe80::1 +// This means either /ip4/127.*.*.*, /ip6/::1, or /ip6/::ffff:127.*.*.*.* func IsIPLoopback(m ma.Multiaddr) bool { b := m.Bytes() for _, prefix := range loopbackPrefixes {