Repository navigation
fix(toolkit): trace and reassemble a TCP segment whose header the snapshot cut (#1518) - #1556
Merged
Merged
Conversation
Owner
Author
|
Verdict: NEEDS CHANGES at Confirmed:
To fix:
Not blocking:
|
…pshot cut (#1518) The TCP parser rejects a header whose Data Offset runs past the captured octets (#1404), so on a capture snapped inside the TCP header the segment is Raw and the default engine's PCAP and PCAP-NG adapters skipped it: tcp.pcap snapped by 4 octets traced (3,5) (6,) where dpkt, scapy and Wireshark trace (1,2,6,7) (3,4,5). - pcapkit/toolkit/pcap.py: a shared _tcp_segment helper reports the parsed TCP layer, or else reads the fixed 20-octet header of a Raw IP payload the TCP parser rejected (protocol TCP, not a later fragment, at least 20 octets, Data Offset >= 5), with the captured octets as header/payload. - tcp_reassembly and tcp_traceflow in pcap.py and pcapng.py use it. - tests: the snapped tcp.pcap as PCAP and PCAP-NG traces, reassembles and writes trace PCAPs as dpkt/scapy do; unit cases pin each gate.
JarryShaw
force-pushed
the
fix/1518-snapped-tcp-trace
branch
from
October 10, 2026 03:07
e63079a to
a1d732a
Compare
Owner
Author
|
Verdict: GOOD TO GO at
|
This was referenced Oct 10, 2026
Contributor
|
Coverage: 90.02% (unit tier, Python 3.14,
Per-file detail: the |
4 of 13 tasks
5 of 13 tasks
This was referenced Oct 10, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please follow the guide below
You will be asked some questions, please read them carefully and answer honestly
Put an
xinto all the boxes [ ] relevant to your pull request (like that [x])Use Preview tab to see how your pull request will actually look like
Searched for similar pull requests
Followed the coding style (
make pylint,make mypy,make isort) — on the two changed modules: mypy and isort clean, pylint adds no messagemake testpasses, and a test case covers the change — new tests cover it; narrow selections run locally, the full suite is left to CIAdded a changelog entry under
docs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible — N/A — centralised in docs(changelog): shared 1.5.0 changelog — long-lived, merges last (#610, #616, #617, #618, #620) #657What is the purpose of your pull request?
Tick the commit type your subject line carries.
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything elseDescription of your pull request and other information
Closes #1518 (root cause A; B is #1547).
On
tcp.pcapsnapped by 4 octets, the cut lands inside four TCP headers. The parser rejects them by design (#1404): frame 1 attcp.py:518, frames 2, 4 and 7 atcollections.py:511. TCP becomesRaw, so the default engine's PCAP and PCAP-NG adapters skipped those frames and traced(3,5) (6,). dpkt, scapy and Wireshark (tcp.stream, re-checked) trace(1,2,6,7) (3,4,5).A shared
_tcp_segmenthelper inpcapkit/toolkit/pcap.pynow feeds all four TCP adapters,tcp_traceflowandtcp_reassemblyin both modules. It returns the parsed TCP layer when there is one. Otherwise it reads the fixed 20-octet header of aRawIP payload, if all of these hold: TCP rejected it (Raw.info.erroris set), the protocol is TCP, the datagram is not a later fragment, at least 20 octets were captured, and the Data Offset is at least 5. Header and payload are the captured octets on either side of the Data Offset.Reassembly used the same
'TCP' in framegate, so it gets the same fix. Its datagrams now match dpkt's:(2,6) (3,) (4,5).Tests:
tests/foundation/traceflow/test_traceflow_snapped_capture_runtime.pybuilds the snapped capture as PCAP and PCAP-NG. It checks bidirectional and unidirectional flows, agreement with dpkt and scapy, trace PCAPs byte-equal to the captured records and to dpkt's, and reassembly. All 20 subtests fail onmain.tests/toolkit/test_pcap_tcp_segment_unit.pyuses frames built by hand. It covers the decoded cases (these fail onmain) and pins each gate; dropping any one gate fails its test.No
Gaprow cites #1518.