Skip to content

refactor(protocols)!: finish the PCAP-NG and ARP value helpers (#2614) - #2671

Merged
JarryShaw merged 1 commit into
mainfrom
refactor/2614-pcapng-arp-helpers
Nov 2, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
refactor/2614-pcapng-arp-helpers

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • refactor — changes neither behaviour nor performance

Description of your pull request and other information

The PCAP-NG and ARP group of #2614: these makers take the shared value helpers on Protocol, and every signed or sentinel PCAP-NG field has a recorded per-field decision.

  • section_length follows the owner's option 2. -1 and 0xFFFFFFFFFFFFFFFF write the same octets, and anything outside -2**63 to 2**64 - 1, or any bool, raises ProtocolError. _make_sint gains allow_unsigned for a field spelled both ways.
  • drop_count (obsolete Packet Block) is checked by _make_uint. Its "not available" value 0xFFFF is in range and has no signed spelling, so it is grouped with snaplen, not section_length.
  • if_tzone and if_tsoffset are signed with no sentinel, so they stay signed-only to keep the round trip exact.
  • Padding: PCAP-NG's block makers and the PCAP-NG and Scapy engines pad with pad_length.
  • ARP's Ethernet addresses and PCAP-NG's EUI-64 use the shared MAC pair.

Breaking: these released makers stop writing masked values. For example, drop_count=-1 used to write 0xFFFF and now raises, and section_length=2**64 used to write 0.

A Sonnet cross-review checked the per-field record against draft-ietf-opsawg-pcapng. The drop_count record it asked for, and the owner's later section_length ruling, are both in this head.

Part of #2614.

- Signed and sentinel PCAP-NG fields, reviewed one by one against
  draft-ietf-opsawg-pcapng: if_tsoffset is a 64-bit signed integer with no
  sentinel, so make() checks it with _make_sint rather than masking.
  if_tzone gets the same 32-bit check by pcapkit's choice, so it
  round-trips (#2617): the spec fixes only its length, and it is signed
  because this schema's Int32Field reads it so (#1340). The IDB snaplen
  check moves to _make_uint, its sentinel 0 (no limit) in range, and so does
  the obsolete Packet Block's drop_count over 16 bits: Appendix A reserves
  0xFFFF for "not available", which is in range and which the reader returns
  as 65535, so -1 was only ever a masked spelling. SHB section_length is
  signed and the spec spells its -1 as 0xFFFFFFFFFFFFFFFF too, so make()
  takes -2**63 to 2**64 - 1 through _make_sint(allow_unsigned=True) and
  refuses the rest (#2617): -1 and 0xFFFFFFFFFFFFFFFF write the same octets,
  the field's own packing the only masking left. A note at each field says so.
- _make_sint takes alias=, as _make_uint does, for the PCAP-NG prefix, and
  allow_unsigned= to accept the unsigned spelling of the same bits.
- Padding: the unknown, systemd, DSB, CB, EPB, SPB and PB makers, the SPB
  original-length warning, the engine's DSB read-ahead and the Scapy
  engine's option walk use pad_length.
- ARP's Ethernet address, and if_EUIaddr with size=8, use the base
  _read_mac_addr/_make_mac_addr; PAT_MAC_ADDR, PAT_EUI_ADDR,
  _read_eui_addr and _make_eui_addr go. Their messages are unchanged.
- Breaking: an out-of-range or bool if_tzone, an out-of-range, bool or
  non-int if_tsoffset (None included, which was written as zeros), a bool
  or non-int snaplen, a bool, non-int, negative (-1 was written as 0xFFFF)
  or above-0xFFFF (written as its low 16 bits) drop_count, and a bool,
  non-int or out-of-range section_length (2**64 was written as 0, True as
  1, None as -1) raise ProtocolError; the messages read 'PCAP-NG: invalid
  [IDB] snaplen: <value>', '... [PB] drop_count: <value>' and
  '... [SHB] section_length: <value>'.

Parsed output byte-identical on every sample capture; tests pass.
@JarryShaw JarryShaw added this to the PyPCAPKit v1.6 milestone Nov 2, 2026
@JarryShaw JarryShaw added breaking Breaks public-facing behaviour or API (apply alongside the type label) refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix) review: good-to-go Cross-review at the current head says ready; CI state is separate labels Nov 2, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 0c2b9173b. The review recorded a per-field decision for every signed and sentinel PCAP-NG field, checked against the draft spec. The owner's section_length ruling (option 2) is in this head, and a test pins each refused case and each edge. I checked the final interdiff directly: it contains the drop_count record, the section_length check and the allow_unsigned keyword on _make_sint.

@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 2, 2026
@JarryShaw
JarryShaw merged commit 8474c04 into main Nov 2, 2026
62 checks passed
@JarryShaw
JarryShaw deleted the refactor/2614-pcapng-arp-helpers branch November 2, 2026 18:27
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 2, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 2, 2026
JarryShaw added a commit that referenced this pull request Nov 2, 2026
…he cut-frame fixes and GRE's bindings into 1.6.0 (#2449)

- Breaking: TCP, UDP and SCTP makers (#2670) and PCAP-NG's (#2671) raise
  on a value a field cannot hold, where 1.5.x wrote it masked; each entry
  gives the old and new values. The TTL Diff wraps as before.
- Changed: __index__ returns the LinkType, EtherType, TransType or AppType
  value, ports as ints (#2652); only Create Release waits for a deployment
  approval (#2658). The conventions entry records the index rule.
- Fixed: a cut HTTP/2 SETTINGS frame parses and rebuilds; HTTPv2.make
  takes frame_length (#2666).
- Folded into unreleased entries: FRAD at LinkType 107 and GRE at IP
  protocol 47 (#2667); cut IGMPv3 messages and num_group_records (#2662,
  #2672); Linux_ARPHRD (#2663); DCCP's range checks (#2670); a cut GRE
  frame is TRUNCATED, replacing fold-12's INVALID note, and frame_length
  in pcapkit.utilities.contextvars (#2668).
- No entry for _make_sint's private allow_unsigned, ARP's private
  PAT_MAC_ADDR, or the test- and docs-only d728873, 326a6cf,
  fc80fb1, a37edf1 and 2766707.
- CHANGELOG.md regenerated; util/changelog_md.py --check passes.
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) refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant