Skip to content

fix(autonat): only check multicast scope for multicast addresses - #6646

Open
Bruce039 wants to merge 4 commits into
libp2p:masterfrom
Bruce039:autonat-ipv6-global-check
Open

Bruce039 wants to merge 4 commits into
libp2p:masterfrom
Bruce039:autonat-ipv6-global-check

Conversation

@Bruce039

Copy link
Copy Markdown

GlobalIp for Ipv6Addr in autonat v1 has a local copy of the unstable Ipv6Addr::multicast_scope, but it leaves out the is_multicast() check that std does first. Because of that the scope nibble is read from every address, not only from ff00::/8. A unicast address whose first segment ends in 1-5 or 8 (2001:4860::, 2a01:4f8::, 2003:e0::, 2601::, ...) is reported as local scope, so with only_global_ips (on by default) the server refuses such clients and the client ignores such servers. It also goes the other way: a ULA like fd0e::1 ends in e and is treated as global.

The fix returns None for non-multicast addresses so they fall through to is_unicast_global, which is what the std version does. I added a small test with a few real global addresses and the usual non-global ranges; on master it fails on 2001:4860:4860::8888.

autonat 0.16.0 is already released, so this bumps the crate to 0.16.1.

The copy of `Ipv6Addr::multicast_scope` used by `only_global_ips` misses
the `is_multicast()` check that std has, so it looked at the low nibble of
the first segment of every IPv6 address. Unicast addresses like 2001:4860::
or 2a01:4f8:: were classified as local scope and dropped, and ULAs like
fd0e:: were classified as global.
@mergify

mergify Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts. Could you please resolve them @Bruce039? 🙏

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant