Skip to content

fix(internet): rebuild a whole extension header in the extension mode its parse used (#2768) - #2774

Merged
JarryShaw merged 2 commits into
mainfrom
fix/2768-ext-header-extension-mode
Nov 4, 2026
Merged

JarryShaw merged 2 commits into
mainfrom
fix/2768-ext-header-extension-mode

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

A whole extension header parsed with extension=True returns before it decodes a next layer, so its info has no __next_type__. from_data didn't pass extension on to the rebuild, so the rebuild decoded a next layer and gained __next_type__, __next_name__ and nopayload.

  • Internet.from_data, which every extension header inherits, now sets extension=True for an IPv6_Ext subclass whose data model has no __next_type__, unless the caller passes it. This is the same way from_data already reads _short_of_header from the data model. Only a method body changes.
  • Fixed: HOPOPT, IPv6-Route, IPv6-Frag, IPv6-Opts, MH, AH and HIP, both standalone and through IPv6's __exthdr__, from info and from to_dict(). ESP was already exact.
  • The new module fails on main with 30 failures and passes here.
  • Shim6 (follow-up commit, per the fix(internet): a whole IPv6 extension header rebuilt from its info gains next-layer keys and loses Shim6's protocol #2768 ruling): IPv6_Ext declares __keywords__ = frozenset({'alias'}) and _make_data hands alias back, so a rebuilt Shim6 keeps its protocol standalone and in IPv6. Subclasses accept and drop alias.

Closes #2768

… its parse used (#2768)

Parsed with extension=True, as IPv6 parses each header of its chain, every
extension header but ESP holds no next layer, yet from_data(info) rebuilt it
without extension, so its info gained __next_type__, __next_name__ and
nopayload. Internet.from_data now rebuilds an IPv6_Ext subclass whose data
model holds no next layer with extension, unless the caller passes it.

Shim6's protocol, which IPv6_Ext.read takes from the parse-only alias
keyword, is left for a decision on how a rebuild may pass that keyword.

Tests: test_ipv6_exthdr_extension_rebuild_2768_unit covers every member,
standalone and from IPv6's __exthdr__, through info and to_dict().
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Nov 4, 2026
@github-actions github-actions Bot added this to the PyPCAPKit v1.6 milestone Nov 4, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 4, 2026
…as keyword (#2768)

IPv6_Ext.read takes Shim6's protocol from the alias keyword, which a
from_data rebuild never passed, so the rebuilt protocol was None.
IPv6_Ext._make_data now returns alias=data.protocol, and IPv6_Ext lists
alias in __keywords__ so the construction check lets it through. Every
member accepts and drops alias, as it does while parsing.

Tests: the #2768 module adds the Shim6 alias and in-IPv6 cases, asserts no
construction-keyword warning on rebuild, and pins a member dropping alias.
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at ea6b7e564: two Sonnet cross-reviews, one per commit, plus my own run of the new test.

  • Extension mode: a whole extension header parsed with extension=True rebuilds without next-layer keys. That covers HOPOPT, Route, Frag, Opts, MH, AH and HIP, standalone and through IPv6's __exthdr__, from both info and to_dict(). The signal is sound: every extension=False parse carries __next_type__, cut or not, so it can never rebuild in extension mode. ICMP is unaffected. Main has 39 broken rows here and this head has none.
  • Shim6: per option (a), IPv6_Ext declares alias and _make_data hands it back. Shim6 keeps protocol both standalone and inside IPv6, with no warnings. Subclasses accept alias and it has no effect, because each defines its own _make_data. Unknown keywords still raise.
  • Tests: the new module fails on main. The 2717, 2761, ipv6-extension, reassembly, capture round-trip and keyword suites pass. Project tests, Lint and deploy-pages pass.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 4, 2026
@JarryShaw
JarryShaw merged commit d1aaffe into main Nov 4, 2026
63 checks passed
@JarryShaw
JarryShaw deleted the fix/2768-ext-header-extension-mode branch November 4, 2026 18:28
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 4, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 4, 2026
JarryShaw added a commit that referenced this pull request Nov 4, 2026
- Fixed, a new entry beside the cut-header one: a whole header rebuilt
  through from_data reads back what its parse read. An extension header
  parsed with extension=True rebuilds in that mode, where 1.5.x's rebuild
  gained next-layer keys, and a rebuilt Shim6 header keeps its protocol, where
  1.5.x's was None (#2774); a rebuilt or made TCP header reads its padding past
  the End of Option List, where 1.5.x read it as empty (#2775). Both measured
  on a v1.5.1 export.
- CHANGELOG.md regenerated; util/changelog_md.py --check passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(internet): a whole IPv6 extension header rebuilt from its info gains next-layer keys and loses Shim6's protocol

1 participant