Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
dff7fed6
Commit
dff7fed6
authored
Dec 21, 2021
by
Marten Seemann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove wrong (and redundant) IsIpv6LinkLocal
parent
114704e8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
32 deletions
+19
-32
net/ip.go
net/ip.go
+0
-12
net/net_test.go
net/net_test.go
+18
-1
net/resolve.go
net/resolve.go
+1
-1
net/resolve_test.go
net/resolve_test.go
+0
-18
No files found.
net/ip.go
View file @
dff7fed6
...
...
@@ -95,18 +95,6 @@ func IsIPUnspecified(m ma.Multiaddr) bool {
return
net
.
IP
(
c
.
RawValue
())
.
IsUnspecified
()
}
// IsIpv6LinkLocal returns whether the addr uses a non-local ip link
func
IsIpv6LinkLocal
(
a
ma
.
Multiaddr
)
bool
{
split
:=
ma
.
Split
(
a
)
if
len
(
split
)
<
1
{
return
false
}
if
IsIP6LinkLocal
(
split
[
0
])
{
return
false
}
return
true
}
// If m matches [zone,ip6,...], return [ip6,...]
// else if m matches [], [zone], or [zone,...], return nil
// else return m
...
...
net/net_test.go
View file @
dff7fed6
...
...
@@ -12,6 +12,7 @@ import (
"time"
ma
"github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
)
func
newMultiaddr
(
t
*
testing
.
T
,
m
string
)
ma
.
Multiaddr
{
...
...
@@ -449,7 +450,7 @@ func TestIPUnspecified(t *testing.T) {
func
TestIP6LinkLocal
(
t
*
testing
.
T
)
{
for
a
:=
0
;
a
<
65536
;
a
++
{
isLinkLocal
:=
(
a
&
0xffc0
==
0xfe80
||
a
&
0xff0f
==
0xff02
)
isLinkLocal
:=
a
&
0xffc0
==
0xfe80
||
a
&
0xff0f
==
0xff02
m
:=
newMultiaddr
(
t
,
fmt
.
Sprintf
(
"/ip6/%x::1"
,
a
))
if
IsIP6LinkLocal
(
m
)
!=
isLinkLocal
{
t
.
Errorf
(
"IsIP6LinkLocal failed (%s != %v)"
,
m
,
isLinkLocal
)
...
...
@@ -459,6 +460,22 @@ func TestIP6LinkLocal(t *testing.T) {
if
!
IsIP6LinkLocal
(
newMultiaddr
(
t
,
"/ip6zone/hello/ip6/fe80::9999"
))
{
t
.
Error
(
"IsIP6LinkLocal failed (/ip6/fe80::9999)"
)
}
bad
:=
[]
ma
.
Multiaddr
{
newMultiaddr
(
t
,
"/ip6/fe80::1/tcp/1234"
),
// link local
newMultiaddr
(
t
,
"/ip6/fe80::100/tcp/1234"
),
// link local
}
good
:=
[]
ma
.
Multiaddr
{
newMultiaddr
(
t
,
"/ip4/127.0.0.1/tcp/1234"
),
newMultiaddr
(
t
,
"/ip6/::1/tcp/1234"
),
newMultiaddr
(
t
,
"/ip4/1.2.3.4/udp/1234/utp"
),
}
for
_
,
addr
:=
range
bad
{
require
.
True
(
t
,
IsIP6LinkLocal
(
addr
),
"%s is a link local addr"
,
addr
)
}
for
_
,
addr
:=
range
good
{
require
.
False
(
t
,
IsIP6LinkLocal
(
addr
),
"%s is not a link local addr"
,
addr
)
}
}
func
TestConvertNetAddr
(
t
*
testing
.
T
)
{
...
...
net/resolve.go
View file @
dff7fed6
...
...
@@ -74,7 +74,7 @@ func interfaceAddresses() ([]ma.Multiaddr, error) {
var
out
[]
ma
.
Multiaddr
for
_
,
a
:=
range
maddrs
{
if
!
IsI
pv
6LinkLocal
(
a
)
{
if
IsI
P
6LinkLocal
(
a
)
{
continue
}
out
=
append
(
out
,
a
)
...
...
net/resolve_test.go
View file @
dff7fed6
...
...
@@ -55,21 +55,3 @@ func TestResolvingAddrs(t *testing.T) {
t
.
Fatal
(
"should have failed"
)
}
}
func
TestAddrOverNonLocalIP
(
t
*
testing
.
T
)
{
bad
:=
[]
ma
.
Multiaddr
{
newMultiaddr
(
t
,
"/ip6/fe80::1/tcp/1234"
),
// link local
newMultiaddr
(
t
,
"/ip6/fe80::100/tcp/1234"
),
// link local
}
good
:=
[]
ma
.
Multiaddr
{
newMultiaddr
(
t
,
"/ip4/127.0.0.1/tcp/1234"
),
newMultiaddr
(
t
,
"/ip6/::1/tcp/1234"
),
newMultiaddr
(
t
,
"/ip4/1.2.3.4/udp/1234/utp"
),
}
for
_
,
addr
:=
range
bad
{
require
.
Falsef
(
t
,
IsIpv6LinkLocal
(
addr
),
"%s is a link local addr"
,
addr
)
}
for
_
,
addr
:=
range
good
{
require
.
Truef
(
t
,
IsIpv6LinkLocal
(
addr
),
"%s is not a link local addr"
,
addr
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment