Skip to content

feat(application): dissect STP, RSTP and MSTP BPDUs behind LLC SAP 0x42 (#3115) - #3156

Merged
JarryShaw merged 1 commit into
developfrom
feat/3115-stp-bpdu
Nov 27, 2026
Merged

JarryShaw merged 1 commit into
developfrom
feat/3115-stp-bpdu

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Nov 27, 2026 •

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 #3115.

flowchart TD
    LLC["LLC: DSAP and SSAP both 0x42, paired"] --> STP["STP base: IEEE 802.1Q-2022 cl. 14.4"]
    STP -->|"type 0x00 (35+ octets) or 0x80 (4+), any version"| V0["STPv0"]
    STP -->|"type 0x02: version 2 (36+), or 3+ failing the MST checks"| RSTP
    STP -->|"type 0x02, version 3, 102+ octets, v1 len 0, v3 len 64 + 16n, n up to 64"| MSTP
    STP -->|"anything else, an SPT BPDU of version 4+ included"| RAW["Raw, with the refusal as error"]
Loading

version= 0, 2 or 3 names the member on parse and build; from_data reads the data model's class and refuses a dict, as a BPDU's version alone does not pick the member. The protocol_version field keeps the octet as captured. Fields follow IEEE 802.1D-2004 cl. 9 and 802.1Q-2022 cl. 14; with the texts paywalled, layouts are cross-checked against Wireshark packet-bpdu.c, tcpdump print-stp.c and mstpd, and the test BPDUs against tshark 4.6.10 and scapy 2.7.0. New pcapkit.const.stp, from DATA crawlers. SPT BPDUs are left raw, and MSTP reads and builds version 3 alone; PVST+ stays out.

@JarryShaw JarryShaw added the feat Pull requests that add a new capability (feat: subject prefix) label Nov 27, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.9 milestone Nov 27, 2026
@JarryShaw JarryShaw added the review: running A cross-review is in flight against the current head - no verdict yet label Nov 27, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Review verdict: needs changes at a0b1a5c5f, from a cross-review on Sonnet. One small fix is needed.

  1. MSTP.make(protocol_version=4) builds an SPT BPDU without its SPT fields. It round-trips, but that's not a BPDU 802.1Q defines. Either restrict make to version 3, or require the version 4 tail as payload. Add a test either way.

Confirmed, checked against Wireshark, tcpdump, scapy, tshark 4.6.10 and mstpd (the IEEE texts weren't reachable):

  • Every hand-built BPDU matches tshark field for field and rebuilds byte-exact, reserved bits included.
  • The cl. 14.4 matrix holds on every branch, with no superset decode. Mutating _classify or _is_mst fails the tests.
  • MSTI flag bit 8 is Master. Wireshark's "TC-Ack" comes from reusing the RST flag table, so the name stays.
  • The family dispatches on read and make. version= picks the member, and SAP pairing holds. The four packages follow the OSPF and IGMP families.
  • The const crawlers regenerate byte-identically, and every added table row is justified.

Notes, none blocking:

  • PortRole 0 means "Master" in MSTI flags but "Unknown" for the CIST role. A docstring line saying so would help.
  • _classify's version < 2 check is redundant.

The fix goes to the original worker, and this head's CI is cancelled.

@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 Nov 27, 2026
…42 (#3115)

- STP: the abstract base of the Spanning Tree Protocol family, bound in
  LLC.__proto__ at LSAP 0x42 and flagged in LLC.__paired__, so a PDU is
  handed on only with DSAP and SSAP both 0x42. It picks the member as
  IEEE 802.1Q-2022 clause 14.4 validates a BPDU; `version` (0, 2, 3)
  names the member on both paths, and from_data reads the data model.
- STPv0: Configuration and TCN BPDUs (IEEE 802.1D-2004 clause 9), read
  whatever their Protocol Version Identifier, as clause 14.4 does.
- RSTP: RST BPDUs of version 2, and of version 3 or more failing the MST
  checks, the 35-octet form without a Version 1 Length included.
- MSTP: version 3 MST BPDUs with the MST Configuration Identifier and
  their MSTI Configuration Messages; a later version holding one is the
  SPT BPDU, which no member reads or builds, so it is left raw.
- Shared Bridge and Port Identifier and flag data models; reserved bits
  kept, so parse -> rebuild and make -> parse are byte-exact.
- pcapkit.const.stp and its DATA crawlers: Protocol Version Identifiers,
  BPDU Types and Port Roles; docs pages, convention rows, the llc
  dispatch case, sweep table rows and unit tests.
@JarryShaw JarryShaw added review: pending No verdict for the current head - never reviewed, or the head moved since the last one and removed review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Nov 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Fix round pushed at f115e27. MSTP now reads and builds protocol version 3 only. A version 4+ BPDU that passes the MST checks stays Raw, because SPT is out of scope; one that fails them is still RSTP under 802.1Q 14.4 d. PortRole 0 is documented as Master (MSTI) and Unknown (CIST). _classify's version < 2 check stays, so −1 always means the clause discards the BPDU. A re-review of the delta is running.

@JarryShaw

Copy link
Copy Markdown
Owner Author

Good to go at f115e27. A Sonnet re-review checked the delta, and I checked the prose.

  • MSTP's reader and make() both take version 3 only (least = most = 3), so the round trip holds. The new tests fail 7 subtests on a0b1a5c and pass 19 on the head.
  • The PortRole 0 note matches what the crawler regenerates. version < 2 stays, so −1 always means the BPDU is discarded.
  • Open point, not blocking: neither of us could fetch the 802.1Q-2011/2022 clause 14.4 text. Wireshark and mstpd read a version 4+ MST-shaped BPDU as MST; Wireshark parses the SPT extension once the BPDU is 106 octets or longer. This PR leaves it Raw instead: the SPT BPDU is its own type, and decoding only its MST part would be superset decoding. If you would rather MSTP decode that MST part, say so and I'll send it back.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: pending No verdict for the current head - never reviewed, or the head moved since the last one labels Nov 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 94.79% (unit tier, Python 3.15, f115e27c2, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 108 4 20 2 95.31%
pcapkit/const 21854 213 3112 186 98.32%
pcapkit/corekit 3059 83 1004 40 96.73%
pcapkit/dumpkit 423 3 148 5 98.60%
pcapkit/foundation 3919 24 1252 26 99.03%
pcapkit/interface 103 4 34 3 94.89%
pcapkit/protocols 26913 158 7084 129 99.14%
pcapkit/toolkit 994 26 356 8 96.74%
pcapkit/utilities 591 7 162 5 98.41%
pcapkit/vendor 6285 2350 1424 248 59.29%

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

@JarryShaw
JarryShaw merged commit 59edc29 into develop Nov 27, 2026
75 checks passed
@JarryShaw
JarryShaw deleted the feat/3115-stp-bpdu branch November 27, 2026 22:17
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Asked in session: does the family have only STPv0? No. STP is the base, and it dispatches to three members:

  • STPv0, protocol version 0: Configuration and TCN BPDUs (IEEE 802.1D-2004).
  • RSTP, version 2: RST BPDUs (IEEE 802.1D-2004).
  • MSTP, version 3: MST BPDUs (IEEE 802.1Q-2022).
    No version 1 exists; the ProtocolVersion table lists 0, 2, 3 and 4. Version 4 (SPT) stays Raw, as above. Only version 0 gets a v0 suffix, because the standards and ProtocolVersion give the other two their own names. I recommend keeping those names, but say if you'd rather follow the family pattern (STPv2, STPv3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Pull requests that add a new capability (feat: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

feat(application): dissect STP, RSTP and MSTP BPDUs behind LLC SAP 0x42

1 participant