Skip to content

fix(const)!: give tcp.flags.Flags their wire masks (#2310) - #2340

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2310-tcp-flags-wire-masks
Oct 27, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2310-tcp-flags-wire-masks

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner
  • Searched for similar pull requests
  • Followed the coding style
  • make test passes, and a test case covers the change
  • Changelog entry: 1.5.0.rst (breaking change)

What is the purpose of your pull request?

  • fix — bug fix

Description

Closes #2310, per the ruling (take the recommendation). Breaking: every tcp.flags.Flags value changes.

  • Root cause: the crawler wrote each flag as 1 << offset, but IANA counts offsets from the high end of the 16-bit word. So FIN was 0x8000, and a parsed SYN/ACK gave int(connection) == 0x4800 where the header carries 0x12.
  • Fix: the crawler writes 1 << (15 - offset), so FIN is 0x001 and AE is 0x100. The range checks narrow to the 12-bit field (0xFFF), and pcapkit/const/tcp/flags.py is regenerated from the crawler. No library code depended on the old integers. The tests that pinned them, and the render_enum docstring examples, are updated.
  • Tests: test_const_tcp_flags_wire_masks_2310_unit.py checks every wire mask, rejects 0x1000, and covers a SYN/ACK whose int(connection) equals the header bits. It also checks that all 256 flag-octet values rebuild byte-exact and that make() agrees with what it writes.
  • Fail-without-fix: on origin/main, 302 failed, e.g. 18432 != 18. On the head, 139 passed.
  • Left out: connection is built from the 8-bit flags byte, so AE and the reserved bits never appear in it. That predates this change.

@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 2026
@JarryShaw JarryShaw added 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) const Regenerated IANA or vendor constant tables; members keep their numeric values fix Pull requests that fix a defect (fix: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 26, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Review: NEEDS CHANGES at b0d489722 (Sonnet). One stale comment; everything else checks out.

  • Change: the _flag = Enum_Flags(0) comment in TCP.read still says _missing_ accepts values from 0 to 0xFFFF. This PR narrows that to 0xFFF, so the comment now contradicts the code.
  • Confirmed:
    • IANA counts offsets from the high end and RFC 9293 §3.1 lays out the word the same way, so 1 << (15 - offset) gives FIN=0x001 and AE=0x100.
    • flags.py is identical to a fresh render from the live IANA CSV.
    • No library code reads the old integers.
    • All 256 flag octets rebuild byte-exact, and SYN/ACK gives 0x12.
    • The changelog entry is accurate, and --check passes.
  • Fail-without-fix: 274 failed with the new file alone (18432 != 18). On the head, tests/const, dumpkit, transport and vendor gave 1004 passed.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 26, 2026
Problem: the crawler generated each member as 1 << offset in IANA's
most-significant-first numbering, so FIN was 0x8000 and int() of a
parsed SYN/ACK's connection was 0x4800 where the header carries 0x012.

Fix: generate 1 << (15 - offset), each flag's mask in the 12-bit flags
field, and narrow the range guard to 0 <= value <= 0xFFF. The const
module is regenerated from the crawler. Tests and the dumpkit docstring
that pinned the old integers, or used Flags for undeclared bits it no
longer has, move to the new values or to BindingUpdateFlag.

Test: test_const_tcp_flags_wire_masks_2310_unit checks every member's
mask, composites, the guard, a parsed SYN/ACK, every flags octet
reading back as itself with a byte-exact rebuild, and the crawler's
output. Changelog entry under pcapkit.const, CHANGELOG.md regenerated.
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 26, 2026
@JarryShaw
JarryShaw force-pushed the fix/2310-tcp-flags-wire-masks branch from b0d4897 to 633ab11 Compare October 26, 2026 23:10
@JarryShaw

Copy link
Copy Markdown
Owner Author

Review: GOOD TO GO at 633ab111f. The amend answers the only NEEDS CHANGES item. git range-diff 2d8c8b516..b0d489722 bfe184bd6..633ab111f shows that, besides the rebase onto bfe184bd6, the commit changes only the TCP.read comment, which now gives the 12-bit range 0 to 0xFFF. No other living prose in pcapkit/ or docs/ quotes the old range. On the new head, tests/protocols/transport with the docstring contract gave 253 passed, tests/const gave 372 passed, and changelog_md.py --check passes.

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

Copy link
Copy Markdown
Contributor

Coverage: 91.56% (unit tier, Python 3.15, 633ab111f, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 19599 881 2618 867 92.11%
pcapkit/corekit 2589 74 816 37 96.51%
pcapkit/dumpkit 282 3 102 3 98.44%
pcapkit/foundation 3023 23 1044 25 98.82%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 17437 218 4586 185 98.15%
pcapkit/toolkit 869 36 298 10 95.20%
pcapkit/utilities 504 7 146 5 98.15%
pcapkit/vendor 4432 1988 1018 167 51.87%

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

@JarryShaw
JarryShaw merged commit 5df1238 into main Oct 27, 2026
63 checks passed
@JarryShaw
JarryShaw deleted the fix/2310-tcp-flags-wire-masks branch October 27, 2026 00:07
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 27, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 27, 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) bug Issues reporting a defect (set by the bug report template; a default, not an assessment) const Regenerated IANA or vendor constant tables; members keep their numeric values fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

design(const): tcp.flags.Flags values are IANA bit offsets, bit-reversed against the wire

1 participant