Spanning Tree (STP / RSTP)
The Spanning Tree Protocol stops loops in switched networks by electing a root bridge and blocking redundant links. Rogue BPDUs can take over the topology.
- OSI layer
- 2 Data link
- Carried in
- Ethernet 802.3 + LLC (DSAP/SSAP 0x42)
- Identified by
- Destination MAC 01:80:c2:00:00:00 (PVST+: 01:00:0c:cc:cc:cd)
- Specs
- IEEE 802.1D, IEEE 802.1w, IEEE 802.1s
- Wireshark filter
stp- Encrypted
- no
Packet structure
Select a field to see what it does.
Switches exchange these Bridge Protocol Data Units (BPDUs) every hello time (2 s) on every port where STP runs. Topology Change Notifications are only 4 bytes (Protocol ID, Version, Type).
How it works
Redundant links between switches would make broadcasts circle forever (a broadcast storm). STP builds a loop-free tree:
- Elect the root bridge: lowest Bridge ID (priority, then MAC) wins. Leaving all priorities at 32768 means the oldest switch (lowest MAC) often becomes root.
- Each other switch picks its root port: the port with the lowest cost to the root.
- Each segment picks a designated port: the one closest to the root.
- All other ports block. They still listen to BPDUs and take over if a link fails.
| Version | Convergence | Notes |
|---|---|---|
| STP (802.1D) | 30–50 s | States: blocking → listening → learning → forwarding |
| RSTP (802.1w) | About 1 s | Proposal/agreement handshake, edge ports forward at once |
| MSTP (802.1s) | Like RSTP | Several VLANs per tree instance |
| PVST+ / Rapid PVST+ | Like STP / RSTP | Cisco, one tree per VLAN, own destination MAC |
Edge ports (PortFast): ports to end devices skip the listening and learning states. They should never receive BPDUs.
In Wireshark
| Filter | Shows |
|---|---|
stp | All BPDUs |
stp.flags.tc == 1 | Topology changes (MAC tables get flushed) |
stp.root.prio < 32768 | Roots with a lowered priority |
stp.root.hw != 00:11:22:33:44:55 | BPDUs naming another root than the expected one |
stp.type == 0x80 | Topology Change Notifications (classic STP) |
What normal looks like: one BPDU every 2 s per port from the same root ID, few topology changes. BPDUs arriving on a port that leads to a PC are not normal.
Security notes
- Root bridge takeover: an attacker sends BPDUs with priority 0 and becomes root, so traffic between switches flows through them (man-in-the-middle) or the network keeps reconverging (DoS). Tools:
yersinia,scapy. Fix: Root Guard on ports where the root must never appear. - BPDUs from access ports: BPDU Guard shuts down an edge port as soon as it receives a BPDU. Turn it on for all PortFast ports.
- TCN flooding: constant topology changes flush MAC tables and cause flooding, which helps sniffing. Watch for
stp.flags.tc. - Loops without STP: disabling STP or filtering BPDUs (BPDU Filter) on the wrong port can cause a broadcast storm that takes down the segment.
- Reconnaissance: BPDUs reveal switch MACs, priorities and the VLAN layout (PVST+).
Versions and related
- Ethernet: BPDUs use 802.3 frames with an LLC header, not Ethernet II.
- VLAN (802.1Q): PVST+ and MSTP map trees to VLANs.
- TRILL / SPB / EVPN: loop-free fabrics that avoid blocking links altogether.
References
- IEEE 802.1D-2004: MAC Bridges (STP, RSTP)
- IEEE 802.1Q: now includes MSTP