Skip to content

Add Teredo (RFC4380) embedding strategy#109

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

Add Teredo (RFC4380) embedding strategy#109
zanbaldwin wants to merge 1 commit into
6.xfrom
z/teredo

Conversation

@zanbaldwin
Copy link
Copy Markdown
Member

No description provided.

@zanbaldwin zanbaldwin self-assigned this Jun 4, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 5, 2026

Greptile Summary

This PR adds a new Teredo embedding strategy class implementing RFC 4380 §4, allowing the Multi version to extract and pack IPv4 addresses embedded in the 2001:0000::/32 (Teredo) prefix via XOR obfuscation of the last 4 bytes.

  • Teredo::isEmbedded() accepts any address whose first 32 bits match 2001:0000:: (the full Teredo prefix range), and extract()/pack() correctly apply the 0xFFFFFFFF XOR mask; the deliberate asymmetry (non-canonical Teredo addresses decode to the canonical form when round-tripped) is clearly documented in the class PHPDoc.
  • Test coverage includes extraction, packing, isEmbedded for both Teredo and non-Teredo 16-byte binaries, the well-known RFC 4380 worked example (192.0.2.45), and an integration test in MultiTest confirming that a Teredo address embedding 127.0.0.1 is classified as loopback.

Confidence Score: 4/5

Safe to merge; the implementation is correct and the XOR obfuscation follows RFC 4380 §4 exactly.

The Teredo strategy, test vectors (including the well-known RFC 4380 example), and Multi integration test are all correct. The only notable issue is a prose inconsistency in the documentation — the sentence still says "main three" after a fourth strategy was added to the table, and the deprecated strategy is not named. No production logic or test correctness is affected.

docs/05-strategies.md — the strategy-count and deprecation wording should be updated to match the four-entry table.

Important Files Changed

Filename Overview
src/Strategy/Teredo.php New Teredo embedding strategy; prefix check, XOR extraction, and canonical pack are all correct per RFC 4380 §4.
tests/DataProvider/Strategy/Teredo.php Data provider with valid RFC 4380 test vectors, correct invalid-prefix sequences, and well-verified pack/extract pairs.
tests/Strategy/TeredoTest.php Covers isEmbedded, extract, and pack for both valid Teredo inputs and length-invalid edge cases; test names and data providers are consistent.
tests/DataProvider/IpDataProviderInterface.php Inserts TEREDO and LOOPBACK_TEREDO constants, shifting existing LOOPBACK_MAPPED/COMPATIBLE/DERIVED bit positions; low risk for test-only constants used symbolically.
docs/05-strategies.md Table updated correctly, but the prose "main three (and one deprecated)" is inconsistent with a four-strategy table and doesn't identify which strategy is deprecated.

Reviews (1): Last reviewed commit: "feature(strategy): ✨ add Teredo (RFC4380..." | Re-trigger Greptile

Comment thread docs/05-strategies.md
Unfortunately there are several different strategies for embedding a version 4
address into version 6, so this library offers various strategy implementations
for the main three:
for the main three (and one deprecated):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The prose says "the main three (and one deprecated)" but the table now has four entries. The parenthetical also never identifies which strategy is deprecated (IPv4-compatible, per RFC 4291 §2.5.5.1). Consider updating the sentence to count accurately and name the deprecated strategy.

Suggested change
for the main three (and one deprecated):
for four strategies (the IPv4-compatible strategy is deprecated per RFC 4291):

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