Skip to content

feat(foundation)!: start a new TCP flow when a SYN without ACK reuses a flow's endpoints (#2962) - #3211

Open
JarryShaw wants to merge 1 commit into
developfrom
feat/2962-tcp-flow-reuse
Open

JarryShaw wants to merge 1 commit into
developfrom
feat/2962-tcp-flow-reuse

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

Closes #2962.

  • A SYN or SYN-ACK opens a new TCP flow where Wireshark's dissect_tcp (epan/dissectors/packet-tcp.c) opens a new conversation, as ruled on feat(foundation): start a new TCP flow when a SYN without ACK reuses a flow's endpoints #2962: its direction has a base sequence number and its seq differs, or the flow has seen a FIN-ACK or a RST. A direction's base is its first segment's seq, less one unless a SYN, or the peer's ack - 1 if a segment with ACK set comes first.
  • So a capture that starts mid-connection splits on reuse with no teardown seen, while a retransmitted SYN and a simultaneous open (RFC 9293 §3.5) stay one flow. It applies with bidirectional=False too.
  • ACK is read from Packet.header[13] & 0x10, so Packet is unchanged; a header with no flags octet, as PyShark's b'', keeps the teardown rule. With flags readable, a FIN counts only with ACK set, as Wireshark counts it and RFC 9293 §3.10.7.4 reads it.
  • Buffer gains base_seq, before reassembly, and TCP._supersedes holds the rule; the TCP flow tracing page's glossary and state diagram follow.

Tests: tests/foundation/traceflow/test_tcp_flow_reuse_2962_unit.py and the updated data/test_models.py fail on an origin/develop export; the tracer's branch coverage rises (97.9% to 98.2%). tests/project (its Sphinx-gated modules in a docs venv), tests/protocols/*.py, tests/*.py and every module touching flow tracing pass, but test_conda_dev_release_gate_2458.py, which fails the same on develop here.

Pins moved: NOT_A_COPY in tests/project/test_rfc_constants_one_home_1739_unit.py records the ACK bit's 0x10, and data/test_models.py builds Buffer with base_seq. The PEP's "undecided" sentence on #2962 is left to the docs sweep.

@JarryShaw JarryShaw added feat Pull requests that add a new capability (feat: subject prefix) 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
@read-the-docs-community

read-the-docs-community Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

@JarryShaw

Copy link
Copy Markdown
Owner Author

Needs changes at 9f6d87cbb, from a Sonnet cross-review. The code is faithful to Wireshark; only the breaking mark is missing.

  • Verified against packet-tcp.c master:
    • SYN and SYN/ACK supersede on seq != base_seq or a recorded FIN-ACK/RST (~9487, ~9555).
    • An unseen peer's base is ack - 1 (~9702).
    • FIN completeness needs ACK (~9915).
    • 14 edge cases split or stay as Wireshark does, including simultaneous open with a missed SYN, and wrap at 2**32.
  • Breaking. Captures that start mid-connection now trace to more flows. Buffer(...) with the old positional arguments raises TypeError, and Info generates __init__ without defaults, so reordering can't avoid it.
  • I set the title to feat(foundation)!: and added breaking. The commit subject gets the same !.

@JarryShaw JarryShaw removed the review: running A cross-review is in flight against the current head - no verdict yet label Nov 29, 2026
@JarryShaw JarryShaw changed the title feat(foundation): start a new TCP flow when a SYN without ACK reuses a flow's endpoints (#2962) feat(foundation)!: start a new TCP flow when a SYN without ACK reuses a flow's endpoints (#2962) Nov 29, 2026
@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment breaking Breaks public-facing behaviour or API (apply alongside the type label) labels Nov 29, 2026
… a flow's endpoints (#2962)

- A SYN or SYN-ACK opens a new TCP flow where Wireshark's dissect_tcp
  opens a new TCP conversation, as ruled on #2962: its direction has a
  base sequence number and its own differs, or the flow has seen a
  FIN-ACK or a RST. A direction's base is its first segment's sequence
  number, less one unless a SYN, or the peer's acknowledgement number
  less one if that comes first. A capture that starts mid-connection
  needs no teardown; a retransmitted SYN and a simultaneous open stay
  one flow. Both modes.
- ACK is read from the header's flags octet, so Packet keeps its fields;
  a header with none, as PyShark's, keeps the teardown rule.
- Buffer gains base_seq; TCP._supersedes holds the rule.
- The #1739 sweep records the ACK bit's 0x10 as no pcap record length.

New tests fail on origin/develop; tests/project, tests/protocols/*.py,
tests/*.py and every flow-tracing module pass.
@JarryShaw
JarryShaw force-pushed the feat/2962-tcp-flow-reuse branch from 9f6d87c to 3e1829b Compare November 29, 2026 04:32
@JarryShaw

Copy link
Copy Markdown
Owner Author

Good to go at 3e1829be2.

  • The commit subject now carries !. The tree is identical to 9f6d87cbb, which I checked with an empty git diff, so the code the cross-review verified is unchanged.
  • Both checks the review had left open pass: util/member_sections.py --check is clean, and the top-level tests/protocols/*.py plus root tests/*.py give 1008 passed with no failures.
  • Its red CI was from the runs I cancelled while it was needs-changes. The new head is running fresh.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Nov 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 94.93% (unit tier, Python 3.15, 3e1829be2, 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 4351 24 1368 26 99.13%
pcapkit/interface 112 4 40 3 95.39%
pcapkit/protocols 28624 153 7558 128 99.21%
pcapkit/toolkit 1136 35 406 9 96.24%
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) feat Pull requests that add a new capability (feat: subject prefix) 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