Skip to content

fix(foundation)!: keep unfragmented IPv4 datagrams out of IPv4 reassembly's output (#2961) - #3210

Open
JarryShaw wants to merge 1 commit into
developfrom
fix/2961-ipv4-unfragmented-datagrams
Open

JarryShaw wants to merge 1 commit into
developfrom
fix/2961-ipv4-unfragmented-datagrams

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

Please follow the guide below

  • Put an x into every box [ ] that applies to your pull request (like this: [x])

  • Use the Preview tab to see how your pull request will look

  • Searched for similar pull requests

  • Followed the coding style (make pylint, make mypy, make isort)

  • make test passes, and a test case covers the change

  • Described the user-visible change below and left its changelog entry to the maintainer, keeping docs/source/changelog/ and CHANGELOG.md out of the diff, if the change is user-visible: N/A — centralised

What is the purpose of your pull request?

Tick the commit type your subject line carries.

  • fix — corrects a defect

  • feat — adds a feature

  • perf — changes performance, not behaviour

  • refactor — changes neither behaviour nor performance

  • test — tests only

  • docs — documentation only

  • ci — workflows or build tooling

  • release — bumps the version or rolls up a distribution

  • chore — anything else

  • Also tick if it regenerates constant or registry tables, members keeping their numeric values (the const label)


Description of your pull request and other information

IPv4 reassembly follows Wireshark, by the owner's ruling on #2961 (option C): only a fragment, MF set or a non-zero offset, enters it, and DF plays no part.

  • toolkit.pcap, toolkit.pcapng: both IPv4 adapters read the layer through a new _ipv4_fragment, which hands over fragments only, DF set or clear, rather than every datagram with DF clear.
  • IP.reassembly: a whole IPv4 datagram another engine hands over is ignored. It is not reported and flushes no buffer, its BUFID's included, replacing the RFC 791 flush of fix(reassembly): unfragmented datagram with a buffered BUFID is dropped and flushes IPv6 #2270. Its timestamp still advances the timeout, as each frame's does in an extraction. IPv6 atomic fragments are unchanged.
  • Breaking: a capture with no IPv4 fragment reassembles no IPv4 datagram. Tests that used a whole datagram as a one-fragment datagram now use two fragments or expect none.

Every test in the new test_ipv4_unfragmented_datagrams_2961_unit.py has subtests that fail on an untouched develop export. The DPKT and Scapy adapters, owned by #3188, still dismiss a fragment with DF set.

Closes #2961

…mbly's output (#2961)

IPv4 reassembly follows Wireshark, by the owner's ruling: only a fragment,
MF set or a non-zero fragment offset, enters it, whatever its DF flag.

- toolkit.pcap and toolkit.pcapng: both IPv4 adapters read the layer
  through a new _ipv4_fragment, which hands over fragments only, DF set or
  clear, rather than every datagram with DF clear.
- IP.reassembly: a whole IPv4 datagram handed over by another engine is
  ignored. It is not reported and flushes no buffer, its BUFID's included,
  which replaces the RFC 791 flush of #2270; its timestamp still advances
  the timeout. IPv6 atomic fragments are unchanged.
- Docs and tests that relied on a whole datagram coming out as a
  one-fragment datagram now use two fragments or expect none.
@JarryShaw JarryShaw added bug Issues reporting a defect (set by the bug report template; a default, not an assessment) breaking Breaks public-facing behaviour or API (apply alongside the type label) review: running A cross-review is in flight against the current head - no verdict yet labels Nov 29, 2026
@github-actions github-actions Bot added this to the PyPCAPKit v1.10 milestone Nov 29, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 29, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Good to go at 6b77c116a, from a Sonnet cross-review plus my own check of the guard.

  • Wireshark parity on the default engine:
    • A whole datagram between two fragments of one BUFID is neither reported nor flushed; the pair completes as (1,3).
    • DF-set fragments reassemble.
    • A lone first or last fragment stays PARTIAL.
  • reassembly.py returns early only for an isolated IPv4 datagram, so IPv6 atomic fragments still reassemble apart (RFC 6946 §4). The timeout still advances.
  • The rewritten tests keep what they asserted. The cut integration tests covered whole-datagram output, which is now gone by design.
  • Follow-up: the DPKT, Scapy and PyPCAPFile adapters still dismiss DF-set fragments, which is filed below as blocked behind this PR and feat(toolkit): reassemble SCTP on DPKT and Scapy (#3188) #3212.

@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 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 94.93% (unit tier, Python 3.15, 6b77c116a, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 116 4 20 2 95.59%
pcapkit/const 22308 224 3168 191 98.27%
pcapkit/corekit 3160 83 1058 40 96.85%
pcapkit/dumpkit 423 3 148 5 98.60%
pcapkit/foundation 4338 24 1358 26 99.12%
pcapkit/interface 112 4 40 3 95.39%
pcapkit/protocols 28624 153 7558 128 99.21%
pcapkit/toolkit 1136 35 404 9 96.23%
pcapkit/utilities 638 7 176 5 98.53%
pcapkit/vendor 6514 2394 1464 256 59.91%

Per-file detail: the coverage-html artifact of this run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaks public-facing behaviour or API (apply alongside the type label) bug Issues reporting a defect (set by the bug report template; a default, not an assessment) review: good-to-go Cross-review at the current head says ready; CI state is separate

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

1 participant