Skip to content

Commit ee4ab58

Browse files
authored
Check for local ip6 addresses with more flexbility
Currently IsIPLoopback returns true for any multiaddr starting ip4/127, but only returns true on ip6 addresses that exactly equal ip6/::1. So /ip6/::1/tcp/4001 for example does not return true. Instead we should check whether ip6/::1 is contained in the multiaddr, and to do that I simply decapsulated and checked to see if the result is different. It seems this was not caught by tests as none are present specifically for this function.
1 parent 6c6b26b commit ee4ab58

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func IsIPLoopback(m ma.Multiaddr) bool {
6363
}
6464

6565
// /ip6/::1
66-
if IP6Loopback.Equal(m) || IP6LinkLocalLoopback.Equal(m) {
66+
if !m.Decapsulate(IP6Loopback).Equal(m) || !m.Decapsulate(IP6LinkLocalLoopback).Equal(m) {
6767
return true
6868
}
6969

0 commit comments

Comments
 (0)