Spanning tree counts shut ports as edges, and a ring with a shut port black-holes a switch #1274

Closed
opened 2026-11-09 21:03:22 +00:00 by jaylouisw · 1 comment
Owner

What happens

Four switches in a ring, a PC on s1 and a PC on s3. All links up: s3's Fa0/2 is blocked (root port
elected elsewhere) and a ping between the PCs works.

Now make the s2–s3 link unusable in the two ways a network operator does it:

change blocked ports ping
pull the cable none works
shutdown on s3 Fa0/1 (the same cable) s3 Fa0/2 still blocked fails

Same physical outcome, two different verdicts — and the second one black-holes a whole switch: s3's only
remaining ring port is Fa0/2, and spanning tree keeps it blocked because computeStp() still counts the
Fa0/1 edge as part of the tree. computeStp() asks only whether the link is up:

const ownLink = this._linkAt(dev.id, iface.name);
if (ownLink && !ownLink.isUp()) continue;

so a port someone shut, and a port whose far end someone shut, stay in the graph as usable edges.

Verified while filing this

Making the STP port filter use Device.ifaceStatus(iface, topo) (the rule every other table uses) makes the
blocked set agree with the cable-out case — nothing blocked — which is the correct tree for a ring with a
broken link. The ping still fails, with the tree now correct:

blocked: s1 [], s2 [], s3 [], s4 []
ping a -> b: false, reason "no ARP reply from 10.0.0.10"
a's ARP cache afterwards: 10.0.0.9 -> 02:00:00:00:04:00   (a's own address, a switch's bridge MAC)
s3 MAC table: 02:00:00:00:04:00 -> Fa0/1                  (a bridge MAC learned on the shut port's side)
s4 MAC table: 02:00:00:00:05:00 -> Fa0/1

So there are two defects here, and this issue covers both because they interlock:

  1. the tree counts ports that cannot carry a frame as edges (the fix above is correct and should land);
  2. the forwarding path breaks in a ring containing a shut port even when the tree is right: frames are
    replicated around the break, a MAC is learned on the wrong side, and a host's ARP cache ends up holding
    its own address. Broadcast storms and loop: egress equals ingress drops appear.

Expected

  • a shut port, and a port whose far end is shut, are not ports as far as spanning tree is concerned — the
    same way a pulled cable is not;
  • show spanning-tree says a port is not in the tree and why;
  • with the tree correct, traffic crosses the ring: no loop drops, no MAC learned on a port that cannot carry,
    and no host caching its own address.

Notes

This was found while auditing the flood path (#1273), which is fixed separately: floods now skip ports that
cannot carry a frame, so the storm above is no longer made worse by flooding into dead ports. That fix does
not remove this defect — it is measured on top of it.

## What happens Four switches in a ring, a PC on `s1` and a PC on `s3`. All links up: `s3`'s `Fa0/2` is blocked (root port elected elsewhere) and a ping between the PCs works. Now make the `s2`–`s3` link unusable in the two ways a network operator does it: | change | blocked ports | ping | |---|---|---| | pull the cable | none | **works** | | `shutdown` on `s3 Fa0/1` (the same cable) | `s3 Fa0/2` **still blocked** | **fails** | Same physical outcome, two different verdicts — and the second one black-holes a whole switch: `s3`'s only remaining ring port is `Fa0/2`, and spanning tree keeps it blocked because `computeStp()` still counts the `Fa0/1` edge as part of the tree. `computeStp()` asks only whether the *link* is up: ```js const ownLink = this._linkAt(dev.id, iface.name); if (ownLink && !ownLink.isUp()) continue; ``` so a port someone shut, and a port whose far end someone shut, stay in the graph as usable edges. ## Verified while filing this Making the STP port filter use `Device.ifaceStatus(iface, topo)` (the rule every other table uses) makes the blocked set agree with the cable-out case — nothing blocked — which is the correct tree for a ring with a broken link. **The ping still fails**, with the tree now correct: ``` blocked: s1 [], s2 [], s3 [], s4 [] ping a -> b: false, reason "no ARP reply from 10.0.0.10" a's ARP cache afterwards: 10.0.0.9 -> 02:00:00:00:04:00 (a's own address, a switch's bridge MAC) s3 MAC table: 02:00:00:00:04:00 -> Fa0/1 (a bridge MAC learned on the shut port's side) s4 MAC table: 02:00:00:00:05:00 -> Fa0/1 ``` So there are two defects here, and this issue covers both because they interlock: 1. **the tree** counts ports that cannot carry a frame as edges (the fix above is correct and should land); 2. **the forwarding path** breaks in a ring containing a shut port even when the tree is right: frames are replicated around the break, a MAC is learned on the wrong side, and a host's ARP cache ends up holding its own address. Broadcast storms and `loop: egress equals ingress` drops appear. ## Expected * a shut port, and a port whose far end is shut, are not ports as far as spanning tree is concerned — the same way a pulled cable is not; * `show spanning-tree` says a port is not in the tree and why; * with the tree correct, traffic crosses the ring: no loop drops, no MAC learned on a port that cannot carry, and no host caching its own address. ## Notes This was found while auditing the flood path (#1273), which is fixed separately: floods now skip ports that cannot carry a frame, so the storm above is no longer made worse by flooding into dead ports. That fix does not remove this defect — it is measured on top of it.
Author
Owner

Both halves are fixed and measured on top of #1273 (flood no longer enters dead ports).

Root cause of the second half: _deliver() checked the sending port — enabled, peer present, link up — and never the receiving one. A frame aimed at an administratively-down port was delivered, learned from and forwarded, so the ring never actually broke: frames were replicated around it, s3 learned the far host on the port it could not use, and that is why b's reply went out of a dead port and a's ARP cache ended up holding 10.0.0.9 -> 02:00:00:00:04:00 (its own address, a switch's bridge MAC).

Fixed:

  1. computeStp() asks Device.ifaceStatus(iface, topo) instead of only whether the cable is up, so a shut port and a port whose far end is shut are not edges;
  2. _deliver() refuses delivery into a port that is administratively down, counting one discard on the sender naming the far end: peer port shut (pc eth0). A packet waiting on the ARP that request carried is cleared rather than reported a second time, so one lost ping is one counted loss.

After:

change blocked ports ping
all up s3 Fa0/2 works
cable pulled none works
far port shut none works
local port shut none works

and in the ring with a shut port: s3 MAC table holds the far host on the live side only, nothing is learned on the shut port, zero loop: egress equals ingress drops, and both hosts' ARP caches hold only each other's real MACs.

test/stp-shut-port.test.js — 27 checks, 13 of which fail with engine/simulator.js reverted. One existing assertion in test/interface-drops.test.js pinned the weaker reason (no ARP reply from 10.0.0.9) that the old code could offer; it now asserts the sharper peer port shut (pc eth0) while keeping the invariant that the tally equals the event log and that the ping's sentence is the discard's sentence.

Both halves are fixed and measured on top of #1273 (flood no longer enters dead ports). **Root cause of the second half:** `_deliver()` checked the *sending* port — enabled, peer present, link up — and never the receiving one. A frame aimed at an administratively-down port was delivered, learned from and forwarded, so the ring never actually broke: frames were replicated around it, `s3` learned the far host on the port it could not use, and that is why `b`'s reply went out of a dead port and `a`'s ARP cache ended up holding `10.0.0.9 -> 02:00:00:00:04:00` (its own address, a switch's bridge MAC). **Fixed:** 1. `computeStp()` asks `Device.ifaceStatus(iface, topo)` instead of only whether the cable is up, so a shut port and a port whose far end is shut are not edges; 2. `_deliver()` refuses delivery into a port that is administratively down, counting one discard on the sender naming the far end: `peer port shut (pc eth0)`. A packet waiting on the ARP that request carried is cleared rather than reported a second time, so one lost ping is one counted loss. After: | change | blocked ports | ping | |---|---|---| | all up | `s3 Fa0/2` | works | | cable pulled | none | works | | **far port shut** | none | **works** | | **local port shut** | none | **works** | and in the ring with a shut port: `s3` MAC table holds the far host on the live side only, nothing is learned on the shut port, zero `loop: egress equals ingress` drops, and both hosts' ARP caches hold only each other's real MACs. `test/stp-shut-port.test.js` — 27 checks, 13 of which fail with `engine/simulator.js` reverted. One existing assertion in `test/interface-drops.test.js` pinned the weaker reason (`no ARP reply from 10.0.0.9`) that the old code could offer; it now asserts the sharper `peer port shut (pc eth0)` while keeping the invariant that the tally equals the event log and that the ping's sentence is the discard's sentence.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge#1274
No description provided.