mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-09-02 15:02:51 +08:00
stp: record the designated bridge, port and cost from received BPDUs
stp_dbridge, stp_dpid and stp_dcost were declared and read by the status page, but nothing ever wrote them, so they stayed zero for the life of the firmware. The page's validity test then always failed, and the Designated Bridge, Designated Port ID and Designated Cost columns reported our own values on every port, including the root port where the answer is the upstream neighbour. The three arrays reserved 140 bytes of xdata and never used any of it. They are filled now, right after the loop check, so a frame that came back from one of our own ports is not mistaken for a neighbour. The validity test moves from the last byte of the stored MAC to the stored Port ID. A Port ID is 1-based on the wire and cannot be zero, while a neighbour whose MAC happens to end in 0x00 would have failed the old test. The root path cost byte swap happens once now, and the root port branch reuses the value instead of repeating the shifts. BANK2 grows 148 bytes, BANK1 loses 9, and xdata does not move.
This commit is contained in:
+11
-7
@@ -451,6 +451,16 @@ void stp_in(void) __banked
|
||||
return;
|
||||
}
|
||||
|
||||
stp_dbridge[port].prio = STP_I->bridge.prio;
|
||||
stp_dbridge[port].ext = STP_I->bridge.ext;
|
||||
memcpy(stp_dbridge[port].mac, STP_I->bridge.mac, 6);
|
||||
stp_dpid[port] = ((uint16_t)STP_I->port_prio << 8) | STP_I->port_id;
|
||||
stp_cost_scratch = STP_I->root_path_cost;
|
||||
stp_dcost[port] = ((stp_cost_scratch & 0xff) << 24)
|
||||
| ((stp_cost_scratch & 0xff00) << 8)
|
||||
| ((stp_cost_scratch >> 8) & 0xff00)
|
||||
| (stp_cost_scratch >> 24);
|
||||
|
||||
/* Better root than the one we know? */
|
||||
if (STP_I->root.prio < root_bridge.prio
|
||||
|| ((STP_I->root.prio == root_bridge.prio) && cmpMAC(STP_I->root.mac, root_bridge.mac) < 0)) {
|
||||
@@ -480,13 +490,7 @@ void stp_in(void) __banked
|
||||
/* Age of the information we now hold (see the TX note on the wire
|
||||
* format); saturate rather than wrap on absurd input. */
|
||||
stp_msg_age = (STP_I->age > 254) ? 254 : (uint8_t)STP_I->age;
|
||||
stp_cost_scratch = STP_I->root_path_cost;
|
||||
/* big-endian on the wire */
|
||||
root_bridge_cost = ((stp_cost_scratch & 0xff) << 24)
|
||||
| ((stp_cost_scratch & 0xff00) << 8)
|
||||
| ((stp_cost_scratch >> 8) & 0xff00)
|
||||
| (stp_cost_scratch >> 24);
|
||||
root_bridge_cost += PCOST(port);
|
||||
root_bridge_cost = stp_dcost[port] + PCOST(port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user