Skip to content

refactor(analysis): give IP and TCP reassembly their own foundation.analysis modules - #2619

Merged
JarryShaw merged 1 commit into
mainfrom
refactor/2581-ip-tcp-analysis
Nov 2, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
refactor/2581-ip-tcp-analysis

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • refactor — changes neither behaviour nor performance

Description of your pull request and other information

IP and TCP reassembly now have their own analysis modules, in the shape of DTLS's dtls_handshake. pcapkit.foundation.analysis.ip.ip_datagram parses a reassembled datagram's payload by its payload protocol. pcapkit.foundation.analysis.tcp.tcp_datagram parses it by its port pair. Both return None for a strict, incomplete datagram. The names follow the owner's choice on #2581. IP.submit and TCP.submit build their Deferred from the same private helper, bound to the engine's own __protocol_type__, so a custom engine still parses with its own protocol. The docs note that exception wherever they say what packet holds.

Behaviour is unchanged. The differential runs over every sample capture, on the default, dpkt and scapy engines, with strict on and off, and is byte-identical: 8,100 IPv4, 6 IPv6 and 1,458 TCP datagrams, including pickle round trips. A Sonnet cross-review reproduced it independently and returned GOOD TO GO. Its nits are folded in. The new tests fail without the change.

Closes #2581

…nalysis modules (#2581)

- analysis/ip.py: ip_datagram parses an IPv4/IPv6 datagram's payload through
  IPv4.analyze or IPv6.analyze, by its addresses.
- analysis/tcp.py: tcp_datagram parses a TCP datagram's payload through
  TCP.analyze by its ports. Both return None for strict=True's received runs.
- IP.submit, TCP.submit: the Deferred packet runs each module's parse, bound
  to the engine's own __protocol_type__. Exported as dtls_handshake is.
- docs: reassembly-integration point 3 holds for every engine; API pages;
  packet docs name the functions, with the __protocol_type__ exception.
- tests: functions called directly; Extractor over PCAP and PCAP-NG, default
  and custom __protocol_type__; pickle round trips of an unread packet.

Behaviour unchanged: a sample-capture differential matches main.
@JarryShaw JarryShaw added this to the PyPCAPKit v1.6 milestone Nov 2, 2026
@JarryShaw JarryShaw added refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix) review: good-to-go Cross-review at the current head says ready; CI state is separate labels Nov 2, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 7095786f8. A Sonnet cross-review of 276b09434 reproduced the byte-identical differential over all 138 engine and strict configurations, plus a synthetic fragmented case. It also confirmed that the unread packet pickles and that a custom engine's __protocol_type__ still dispatches. Its nits are folded in, and I checked the delta:

  • packet is documented with the custom-protocol exception;
  • the prose says "datagram" rather than "stream";
  • the tests assert behaviour rather than wiring, and none check analyze.func;
  • transport.py is untouched.

@JarryShaw
JarryShaw merged commit 240451f into main Nov 2, 2026
25 of 59 checks passed
@JarryShaw
JarryShaw deleted the refactor/2581-ip-tcp-analysis branch November 2, 2026 03:56
@github-project-automation github-project-automation Bot moved this to Done in PyPCAPKit Nov 2, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Owner request, given in session and paraphrased: now that foundation.analysis has IP and TCP modules, the protocols' own analyze methods should point at them.

Today ip_datagram and tcp_datagram call IPv4.analyze, IPv6.analyze and TCP.analyze, which are ProtocolBase.analyze and Transport.analyze. The fix round reverses that: the parsing logic moves into pcapkit.foundation.analysis.ip and .tcp, and the protocol classes' analyze delegates to them. Signatures stay the same. A custom engine's __protocol_type__ override still wins, and output stays byte-identical across every engine.

If "the protocol itself" meant the reassembly classes' submit/Deferred wiring instead, say so and the round will follow that. The PR moves to review: needs-changes, and its running CI is cancelled.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment and removed review: good-to-go Cross-review at the current head says ready; CI state is separate review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Nov 2, 2026
JarryShaw added a commit that referenced this pull request Nov 2, 2026
…nto 1.6.0 (#2449)

- Added: IEEE802_11, the 802.11 MAC header behind radiotap, with the
  pcapkit.const.ieee802_11 type and subtype registries (#2607); the
  Radiotap entry drops its stale "no dissector yet" note and names its
  own registry and register_radiotap.
- Added: ip_datagram and tcp_datagram beside dtls_handshake (#2619).
- The conventions entry records #2607's ruling on a paywalled registry's
  pinned secondary source.
- 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

refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

refactor(analysis): give IP and TCP reassembly their own foundation.analysis modules

1 participant