Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identify: filter nat64 well-known prefix ipv6 addresses #2392

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions p2p/protocol/identify/obsaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ func shouldRecordObservation(host addrsProvider, network listenAddrsProvider, co
return false
}

// Provided by NAT64 peers, these addresses are specific to the peer and not publicly routable
if manet.IsNAT64IPv4ConvertedIPv6Addr(observed) {
return false
}

// we should only use ObservedAddr when our connection's LocalAddr is one
// of our ListenAddrs. If we Dial out using an ephemeral addr, knowing that
// address's external mapping is not very useful because the port will not be
Expand Down
48 changes: 48 additions & 0 deletions p2p/protocol/identify/obsaddr_glass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package identify
// can access internal types.

import (
"fmt"
"testing"

ma "github.com/multiformats/go-multiaddr"
Expand Down Expand Up @@ -103,3 +104,50 @@ func TestShouldRecordObservationWithWebTransport(t *testing.T) {

require.True(t, shouldRecordObservation(h, h, c, observedAddr))
}

func TestShouldRecordObservationWithNAT64Addr(t *testing.T) {
listenAddr1 := ma.StringCast("/ip4/0.0.0.0/tcp/1234")
ifaceAddr1 := ma.StringCast("/ip4/10.0.0.2/tcp/4321")
listenAddr2 := ma.StringCast("/ip6/::/tcp/1234")
ifaceAddr2 := ma.StringCast("/ip6/1::1/tcp/4321")

h := &mockHost{
listenAddrs: []ma.Multiaddr{listenAddr1, listenAddr2},
ifaceListenAddrs: []ma.Multiaddr{ifaceAddr1, ifaceAddr2},
addrs: []ma.Multiaddr{listenAddr1, listenAddr2},
}
c := &mockConn{
local: listenAddr1,
remote: ma.StringCast("/ip4/1.2.3.6/tcp/4321"),
}

cases := []struct {
addr ma.Multiaddr
want bool
failureReason string
}{
{
addr: ma.StringCast("/ip4/1.2.3.4/tcp/1234"),
want: true,
failureReason: "IPv4 should be observed",
},
{
addr: ma.StringCast("/ip6/1::4/tcp/1234"),
want: true,
failureReason: "public IPv6 address should be observed",
},
{
addr: ma.StringCast("/ip6/64:ff9b::192.0.1.2/tcp/1234"),
want: false,
failureReason: "NAT64 IPv6 address shouldn't be observed",
},
}
for i, tc := range cases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {

if shouldRecordObservation(h, h, c, tc.addr) != tc.want {
t.Fatalf("%s %s", tc.addr, tc.failureReason)
}
})
}
}