Skip to content

fix(sctp): chunk flags, reserved fields and final padding round-trip - #1253

Merged
JarryShaw merged 1 commit into
mainfrom
fix/sctp-chunk-flags-length
Oct 7, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/sctp-chunk-flags-length

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner
  • Searched for similar pull requests
  • Followed the coding style (make pylint, make mypy, make isort) — ran mypy and pylint directly on the three SCTP files: they report nothing new on changed lines. I did not run the make targets.
  • make test passes, and a test case covers the change — only the modules listed below
  • Added a changelog entry under docs/source/changelog/ and regenerated CHANGELOG.md, if the change is user-visible — N/A, added centrally

What is the purpose of your pull request?

  • 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

Description of your pull request and other information

Closes #1221
Closes #1222

  • fix(sctp): chunk flags and reserved fields are written back as zero #1221. Ten chunk data models gain a raw flags field, and their makers gain a flags keyword: INIT, INIT ACK, SACK, HEARTBEAT, HEARTBEAT ACK, SHUTDOWN, SHUTDOWN ACK, ERROR, COOKIE ECHO and COOKIE ACK. DATAChunkFlags and TBitFlags gain a reserved subfield. InvalidStreamIdentifierCause gains reserved.
  • fix(sctp): chunk length always counts the last parameter's padding #1222. Six chunks carry a nested list: INIT, INIT ACK, HEARTBEAT, HEARTBEAT ACK, ABORT and ERROR. Their length now excludes the last item's padding, as RFC 9260 §3.2 requires. A parsed length that counts the padding, which the RFC lets receivers accept, is kept as received.
  • Breaking change. These are new required data-class fields. make() output changes for an unpadded final parameter: for example, an ABORT with bye is now 11 bytes, not 12. test_sctp_unit.py pinned the old lengths (INIT ACK 32, ABORT 12) and is updated.

Probe. Each input is rebuilt with SCTP.from_data(SCTP(raw).info).

  • Before: INIT 01a50014 → 01000014; 0100001b → 0100001c.
  • After: both rebuild byte-exactly, as do the DATA f3, ABORT fe and cause beef cases.
  • All 34 SCTP frames in examples/captures/* round-trip.

Tests. The new test_sctp_roundtrip_unit.py fails without the fix (20 failed, 5 passed) and passes with it (7 passed, 18 subtests). Results of the other runs:

  • test_sctp_unit 37 passed
  • test_transport_unit 11 passed
  • test_ngap_unit 23 passed
  • test_option_roundtrip_unit 6 passed
  • tests/project 389 passed, 1 skipped
  • run_unittest_leg.py protocols --exclude protocols/internet: 857 tests, 0 failures

- #1221: INIT, INIT ACK, SACK, HEARTBEAT, HEARTBEAT ACK, SHUTDOWN,
  SHUTDOWN ACK, ERROR, COOKIE ECHO and COOKIE ACK carry their raw flags
  octet (new `flags` data field and maker keyword); DATA and T-bit flags
  expose a `reserved` subfield; the Invalid Stream Identifier cause keeps
  its reserved field.
- #1222: chunks with nested parameters or causes declare the RFC 9260
  section 3.2 length, which excludes the final item's padding; a parsed
  chunk whose length counts that padding keeps it.
- test_sctp_unit pinned the old padded lengths (INIT ACK 32, ABORT 12);
  updated to 29 and 11.
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) 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 Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Coverage: 88.89% (unit tier, Python 3.14, 3351bd690, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18757 1034 2342 845 90.24%
pcapkit/corekit 1878 91 580 22 94.34%
pcapkit/dumpkit 142 0 42 0 100.00%
pcapkit/foundation 2442 102 852 39 94.38%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 15821 200 4064 175 98.08%
pcapkit/toolkit 487 65 144 1 85.42%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2359 1006 158 42.84%

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

@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review verdict on 3351bd690: GOOD TO GO (Sonnet reviewed; the author ran on Opus).

  • Repros: the INIT flags a5 and length 1b repros now rebuild exactly; I re-ran both myself. DATA f3, ABORT fe, SHUTDOWN COMPLETE ff and the beef cause also rebuild exactly. All of these fail on main.
  • RFC 9260 §3.2: the Chunk Length counts the padding of non-final parameters but not the final one, and receivers should accept either form. The helper implements both rules for every chunk type that carries a nested list (INIT, INIT ACK, HEARTBEAT, HEARTBEAT ACK, ABORT, ERROR). COOKIE ECHO is opaque bytes and needs no change.
  • Pinned lengths: the two edited pins in test_sctp_unit.py (INIT ACK 29, ABORT 11) are the RFC-canonical lengths; the old pins (32 and 12) encoded padded output.
  • Fixtures: all 34 SCTP frames rebuild byte-exactly. NGAP and the generators build only DATA chunks, whose length is unchanged.
  • Tests: the new module fails 20 cases on main. run_unittest_leg.py protocols --exclude protocols/internet: 857 tests, 0 failures.
  • Breaking change: the new required flags and reserved fields break any code that constructs these data classes directly.
  • Nit: flags is bytes on ten chunk types, while reserved is an int on DATA, ABORT and SHUTDOWN COMPLETE.

@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 Oct 7, 2026
@JarryShaw
JarryShaw merged commit 47a0be0 into main Oct 7, 2026
64 of 66 checks passed
@JarryShaw
JarryShaw deleted the fix/sctp-chunk-flags-length branch October 7, 2026 19:06
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 7, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 25, 2026
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) fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(sctp): chunk length always counts the last parameter's padding fix(sctp): chunk flags and reserved fields are written back as zero

1 participant