stp

package
v0.331.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package stp decodes Spanning Tree Protocol BPDUs per IEEE 802.1D-2004 (STP / RSTP) and IEEE 802.1Q-2014 §13 (MSTP).

Wrap-vs-native judgement

Native. IEEE 802.1D is fully public; the BPDU wire
format is a tight bit-packed binary header — Protocol
ID + Version + BPDU Type + per-type body (Configuration
or Topology Change Notification). RSTP and MSTP extend
the Configuration BPDU with additional flags and a
Version 1 / Version 3 trailing block. No crypto, no
compression, no varints. Operators paste BPDU bytes
(after the LLC header strip — DSAP/SSAP 0x42, Control
0x03, sent to the STP-bridge multicast MAC
01:80:C2:00:00:00) from a `tcpdump -X ether dst host
01:80:c2:00:00:00` line, a Wireshark Follow-Frame view,
or any STP-emitting switch and get the documented
bridge / root / cost / port / timer breakdown.

What this package covers

  • **3-byte common header**:

  • Protocol ID (2 bytes BE) — must be 0x0000.

  • Version (1 byte) — 0 = STP (IEEE 802.1D), 2 = RSTP (IEEE 802.1D-2004), 3 = MSTP (IEEE 802.1Q-2014 §13).

  • **BPDU Type** (1 byte):

  • 0x00 Configuration BPDU

  • 0x80 Topology Change Notification (TCN) BPDU

  • 0x02 RSTP/MSTP BPDU (carries the extended flags)

  • **Configuration BPDU body** (35 bytes):

  • Flags (1 byte) with **8-bit name table** (TC bit 0 / Proposal bit 1 / Port Role bits 2-3 / Learning bit 4 / Forwarding bit 5 / Agreement bit 6 / TC Ack bit 7). Port Role: 0 Unknown / 1 Alternate-or-Backup / 2 Root / 3 Designated.

  • Root Bridge ID (8 bytes) — 4-bit priority + 12-bit system ID extension + 6-byte MAC. Priority must be a multiple of 4096 per IEEE 802.1D §17.13.7.

  • Root Path Cost (4 bytes BE).

  • Bridge ID (8 bytes) — same split as Root Bridge ID.

  • Port ID (2 bytes BE) — 4-bit Port Priority + 12-bit Port Number.

  • Message Age (2 bytes BE; units of 1/256 second).

  • Max Age (2 bytes BE; same units).

  • Hello Time (2 bytes BE; same units).

  • Forward Delay (2 bytes BE; same units).

  • **TCN BPDU body** — empty (the 4-byte common header is the entire frame).

  • **Bridge ID decoding** — splits the leading 2 bytes into the 4-bit System Priority (multiple of 4096) and the 12-bit System ID Extension (typically the VLAN ID for PVST+ or 0 for classic STP), then formats the trailing 6 bytes as a MAC.

  • **Timer formatting** — all 4 timer fields are converted from IEEE 1/256-second units to milliseconds for readability.

  • **MSTP trailer** (Version=3) — the 64-byte MSTI configuration block isn't deeply decoded; it's surfaced as a raw hex blob with a length prefix.

What this package does NOT cover (deliberately out of scope)

  • LLC header (DSAP/SSAP/Control) — feed the BPDU bytes starting at the Protocol ID field (after the 3-byte LLC strip).

  • PVST+ / per-VLAN STP — Cisco proprietary uses standard BPDUs with SNAP encapsulation and embeds the VLAN ID in the System ID Extension; the decoder handles the extension but the SNAP wrapper is the operator's responsibility.

  • Convergence-time simulation — the timers are surfaced; reasoning about how long convergence takes belongs to a higher-level analysis.

  • MSTP MSTI configuration block beyond the raw hex surface — IEEE 802.1Q §13 layout is documented but deep dissection is a future Spec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BridgeID

type BridgeID struct {
	Priority             int    `json:"priority"`
	SystemIDExtension    int    `json:"system_id_extension"`
	SystemIDExtensionHex string `json:"system_id_extension_hex"`
	MAC                  string `json:"mac"`
}

BridgeID is the Root Bridge ID and Bridge ID 8-byte structure (priority + system ID extension + MAC). Per IEEE 802.1t the original 16-bit priority field was split into a 4-bit Priority (in multiples of 4096) plus a 12-bit System ID Extension — typically the VLAN ID for PVST+ or 0 for classic STP.

type Config

type Config struct {
	Flags          int       `json:"flags"`
	FlagsHex       string    `json:"flags_hex"`
	FlagsDecoded   []string  `json:"flags_decoded,omitempty"`
	PortRole       int       `json:"port_role"`
	PortRoleName   string    `json:"port_role_name"`
	RootBridgeID   *BridgeID `json:"root_bridge_id"`
	RootPathCost   uint32    `json:"root_path_cost"`
	BridgeID       *BridgeID `json:"bridge_id"`
	PortPriority   int       `json:"port_priority"`
	PortNumber     int       `json:"port_number"`
	MessageAgeMs   int       `json:"message_age_ms"`
	MaxAgeMs       int       `json:"max_age_ms"`
	HelloTimeMs    int       `json:"hello_time_ms"`
	ForwardDelayMs int       `json:"forward_delay_ms"`
}

Config is the body of Configuration / RSTP / MSTP BPDUs.

type Result

type Result struct {
	ProtocolID   int    `json:"protocol_id"`
	Version      int    `json:"version"`
	VersionName  string `json:"version_name"`
	BPDUType     int    `json:"bpdu_type"`
	BPDUTypeHex  string `json:"bpdu_type_hex"`
	BPDUTypeName string `json:"bpdu_type_name"`
	TotalBytes   int    `json:"total_bytes"`

	Configuration  *Config `json:"configuration_bpdu,omitempty"`
	TCN            *TCN    `json:"tcn_bpdu,omitempty"`
	MSTITrailerHex string  `json:"msti_trailer_hex,omitempty"`

	Notes []string `json:"notes,omitempty"`
}

Result is the top-level decoded view.

func Decode

func Decode(hexStr string) (*Result, error)

Decode parses an STP BPDU from hex.

type TCN

type TCN struct{}

TCN is the body of a Topology Change Notification BPDU (which is actually empty; the struct exists to surface the type in the JSON output).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL