fix(net): reject IPv4-compatible addresses in is_advertisable_ipv6 (#1955) - #144
Merged
Conversation
IPv6 addresses derived from IPv4 (both IPv4-mapped ::ffff:a.b.c.d and IPv4-compatible ::a.b.c.d forms) are not routable global addresses and must not be advertised as peer candidates. Previously only the mapped form was filtered; now both forms are rejected via to_ipv4().is_some(), which matches both the ::/96 IPv4-compatible block and the ::ffff:0:0/96 IPv4-mapped block. Adds three unit tests: IPv4-compatible rejection, regression guard for IPv4-mapped, and guard against over-rejecting real global addresses. Fixes #1955. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Closes DIG-Network/dig_ecosystem#1955.
is_advertisable_ipv6(crates/dig-node-core/src/seams/dig_peer/net.rs) decides whether anIpv6Addris a global-unicast address worth advertising to peers. It folded out IPv4-mapped addresses (::ffff:a.b.c.d) viato_ipv4_mapped().is_some(), but missed the IPv4-compatible form (::a.b.c.d, the::/96block). An IPv4-compatible address is an IPv4 address in disguise — not a dialable global IPv6 — so advertising it as a routable IPv6 candidate is wrong (§5.2 IPv6-first: IPv4-in-any-form must not masquerade as a global IPv6 peer address).Fix:
ip.to_ipv4_mapped().is_some()→ip.to_ipv4().is_some().to_ipv4()returnsSomefor both the mapped and the compatible forms, so both are now rejected.::(unspecified) and::1(loopback) remain caught by the earlieris_unspecified()/is_loopback()checks in the same expression, so the change adds only the compatible-form rejection — it never over-rejects a genuine global address (to_ipv4()returnsNonefor e.g.2001:db8::1). The doc comment is updated to say "not an IPv4-mapped OR IPv4-compatible address".Verification
ipv4_compatible_is_not_advertisable—::1.2.3.4(::0102:0304) →false(RED underto_ipv4_mapped, GREEN after the fix).ipv4_mapped_is_still_not_advertisable—::ffff:1.2.3.4→false(regression guard).a_real_global_unicast_ipv6_is_advertisable—2001:db8::1→true(no over-rejection).local_ipv6_addr→advertised_socket_addrs).cargo fmt --all -- --check→ 0 ·cargo clippy -p dig-node-core --all-targets --all-features -- -D warnings→ 0 ·cargo test -p dig-node-coregreen (the only failure being the known env-limiteddual_stackport-bind test, #1961).Version
fix:(correctness — a more-restrictive address filter; no public-API/behaviour break for legitimate addresses) →[workspace.package].version0.75.2 → 0.75.3.Cargo.lockupdated + committed.Generated by Claude Code