Skip to content

Detect embedded IPv4 in non-canonical 6to4 addresses#110

Open
zanbaldwin wants to merge 1 commit into
6.xfrom
z/derived
Open

Detect embedded IPv4 in non-canonical 6to4 addresses#110
zanbaldwin wants to merge 1 commit into
6.xfrom
z/derived

Conversation

@zanbaldwin
Copy link
Copy Markdown
Member

Derived::isEmbedded() only matched canonical 6to4 addresses with the trailing 80 bits zeroed, even though every address within 2002::/16 carries an IPv4 address in bits 16-47, as per RFC 3056. Widen detection to the whole 6to4 block; extraction keeps only the embedded IPv4 address, so an extract-pack round-trip reconstructs the canonical form (2002:XXXX:XXXX::) rather than the original.

`Derived::isEmbedded()` only matched canonical 6to4 addresses with the trailing 80 bits zeroed, even though every address within `2002::/16` carries an IPv4 address in bits 16-47, as per RFC 3056.
Widen detection to the whole 6to4 block; extraction keeps only the embedded IPv4 address, so an extract-pack round-trip reconstructs the canonical form (`2002:XXXX:XXXX::`) rather than the original.
@zanbaldwin zanbaldwin self-assigned this Jun 5, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 5, 2026

Greptile Summary

This PR widens Derived::isEmbedded() to detect any address in the 2002::/16 block (not just canonical forms with zeroed bits 48–127), aligning with RFC 3056 § 2 which embeds the IPv4 address in bits 16–47 regardless of the remaining fields. The companion docblocks explicitly document that extractpack is a one-way canonicalisation for non-canonical addresses.

  • Derived::isEmbedded() now returns true for the entire 2002::/16 range; the trailing-zero guard is removed. Any Multi IP built from a non-canonical 6to4 address will now report getVersion() === 4 and expose the embedded IPv4 via getDotAddress() / getProtocolAppropriateAddress().
  • Compatible and Mapped receive doc-comment additions with RFC references; no logic changes.
  • The documentation table is updated to use ???? for the variable bits of the 6to4 format.

Confidence Score: 4/5

The core logic change is small, well-reasoned against RFC 3056, and the docblocks clearly warn about the non-roundtrip extraction. The only gap is that the new non-canonical detection path has no test coverage.

The implementation correctly drops a guard that made detection too narrow, and pack/extract behaviour is unchanged. The sole concern is that the test data only contains canonical 6to4 forms, so no test actually exercises the newly-widened isEmbedded() path with a non-zero SLA or interface ID.

tests/DataProvider/Strategy/Derived.php — getValidSequences() and getInvalidSequences() should include at least one non-canonical 6to4 address to cover the new detection logic.

Important Files Changed

Filename Overview
src/Strategy/Derived.php Drops the trailing-zero guard from isEmbedded() so any 2002::/16 address is detected; adds docblocks clarifying the canonical-only roundtrip semantics. Logic is correct per RFC 3056.
src/Strategy/Compatible.php Doc-comment addition only; no logic changes.
src/Strategy/Mapped.php Doc-comment addition only; no logic changes.
docs/05-strategies.md Table updated to show wildcard bits (????) in the 6to4 format column, accurately reflecting the relaxed detection.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[16-byte binary input] --> B{First 2 bytes == 0x2002?}
    B -- No --> C[isEmbedded = false]
    B -- Yes --> D[isEmbedded = true]
    D --> E[extract: return bytes 2-5 as IPv4]
    E --> F{Canonical?\nbytes 6-15 == 0x00...?}
    F -- Yes --> G[roundtrip safe:\npack extract = original]
    F -- No --> H[lossy: SLA ID + Interface ID\ndiscarded by pack]
    H --> I[pack produces canonical\n2002:XXXX:XXXX::]
Loading

Reviews (1): Last reviewed commit: "bugfix(strategy): 🐛 detect embedded IPv..." | Re-trigger Greptile

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