Skip to content
Protocol Encyclopedia | | 6 min read

STP and RSTP - spanning trees in Ethernet networks. How it works and how it is attacked

Spanning Tree Protocol (IEEE 802.1D) and Rapid STP (IEEE 802.1w) - the loop prevention mechanism in layer 2 networks. BPDU, port roles, attacks and BPDU Guard.

J
Józef Sulwiński
STPRSTPIEEE 802.1Dlayer 2

Spanning Tree Protocol (STP) solves one of the fundamental problems of Ethernet networks - loops. Switches learn MAC addresses based on the ports on which frames arrive. In a topology with a loop a broadcast frame returns on a different port, the switch changes its MAC assignment, and the result is a broadcast storm that paralyses the network within seconds.

STP was developed by Radia Perlman at Digital Equipment Corporation and standardised as IEEE 802.1D (1990). Rapid STP (RSTP, IEEE 802.1w from 2001) replaced classic STP in most deployments thanks to much faster convergence. Since the 2004 edition RSTP is part of the 802.1D standard itself.

How it works

The STP algorithm selects from any layer 2 topology a spanning tree in which exactly one active path exists between every two switches. The remaining links are blocked but remain ready to activate if a failure occurs.

The selection process:

  1. Root Bridge election - the switch with the lowest Bridge ID (16-bit priority + 48-bit MAC). The default priority is 32,768, adjustable in steps of 4,096.
  2. Root Port selection - on each non-root switch the port with the lowest path cost to the Root Bridge is chosen.
  3. Designated Port selection - on each segment one port is chosen as responsible for forwarding traffic.
  4. Blocking of remaining ports - all other ports move to the blocking state.

BPDU - Bridge Protocol Data Unit

Switches exchange information using BPDUs sent to the reserved multicast address 01:80:C2:00:00:00. A typical Configuration BPDU contains:

FieldPurpose
Root Bridge IDID of the switch currently considered Root
Root Path CostCost of the path to the Root Bridge
Sender Bridge IDID of the switch sending the BPDU
Port IDPort from which the BPDU was sent
Message AgeTime elapsed since generated by the Root
Max AgeMaximum validity period (default 20 s)
Hello TimeBPDU interval (default 2 s)
Forward DelayTime in Listening/Learning state (default 15 s)

Port states and roles

In classic STP a port can be in one of these states: Disabled, Blocking, Listening, Learning or Forwarding. The transition from Blocking to Forwarding takes 30-50 seconds - unacceptable in modern networks.

RSTP simplifies this to three states - Discarding, Learning, Forwarding - and introduces port roles:

RoleFunction
Root PortBest path to the Root Bridge (active)
Designated PortPort responsible for the segment (active)
Alternate PortAlternative path to the Root (blocked, standby)
Backup PortRedundancy on the same segment (blocked)
Edge PortAccess port (to hosts, immediately Forwarding)

RSTP typically converges in 1-2 seconds thanks to direct negotiation between switches instead of waiting for Max Age.

STP variants

StandardNamePurpose
IEEE 802.1DSTP / RSTPSingle tree for the entire network
IEEE 802.1s / 802.1Q-2005MSTPMultiple trees for different VLANs
Cisco PVST+Per-VLAN Spanning TreeSeparate tree per VLAN (proprietary)
Cisco Rapid PVST+RPVST+PVST+ with RSTP speed

MSTP allows VLANs to be grouped into instances (MSTI) - different VLANs can use different links as active, enabling load balancing in a redundant topology.

Attacks on STP

WARNING

STP was designed in the era of trusted corporate networks. BPDUs are not authenticated - any device connected to the network can send BPDUs and attempt to become the Root Bridge.

Root Bridge takeover - the attacker sends BPDUs with a priority lower than the current Root (e.g. 0). Switches accept the new Root and the topology reconverges. Result: all inter-segment traffic flows through the attacker’s device - an ideal MITM.

BPDU flooding / DoS - massive BPDUs cause topology instability. Every change triggers a Topology Change Notification, clearing of MAC tables and waves of flooding.

TCN injection - a single BPDU with the TCN (Topology Change Notification) flag causes CAM tables to be flushed, making MAC flooding easier.

Dual-homed attack - a device with two interfaces connected to two switches can propagate BPDUs and manipulate the topology.

Yersinia - an open source tool implementing all of the above attacks against STP, DTP, CDP, HSRP and other layer 2 protocols.

Defensive mechanisms

MechanismFunction
BPDU GuardPort moves to err-disable on receiving a BPDU (protects edge ports)
Root GuardBlocks BPDUs announcing a better Root than the current one
Loop GuardBlocks a port that has stopped receiving BPDUs, protecting against loops
TCN Guard / FilterFilters spurious TCNs on edge ports
PortFast / EdgePortImmediate Forwarding on access ports, skipping Listening/Learning
UDLDDetects unidirectional links (Cisco proprietary)

For critical networks (SCADA, electrical substations) the recommendation is radical: do not use STP on the OT backbone. Instead, use layer 2 redundancy protocols designed for zero recovery time - PRP or HSR according to IEC 62439-3.

TIP

On every access port (to a laptop, VoIP phone, printer) enable BPDU Guard and PortFast. It takes five minutes of configuration and blocks the entire STP attack vector. Missing BPDU Guard in 2026 is not a trade-off - it is negligence.

Analysis in practice

# Cisco - show STP topology
show spanning-tree
show spanning-tree vlan 10 detail

# Wireshark filter
stp

# Yersinia - layer 2 penetration testing
yersinia -G

STP and L2 attack traffic samples:

Summary

STP/RSTP solves the loop problem in redundant networks, but in its default configuration it is an attack vector. In a modern enterprise network the administrator’s duty is to enable BPDU Guard on access ports and Root Guard on ports facing trusted switches. In OT networks with a requirement for deterministic redundancy, STP should be replaced by PRP/HSR.

Sources

Need help in this area?

Our experts will help you assess the risk and plan next steps.

Talk to an expert

We'll discuss scope, methodology, and timeline.

+48 22 292 32 23 Talk to an expert