2 * mstp.c State machines from IEEE 802.1Q-2005
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Vitalii Demianets <vitas@nppfactor.kiev.ua>
12 /* NOTE: The standard messes up Hello_Time timer management.
13 * The portTimes and msgTimes structures have it, while
14 * designatedTimes, rootTimes and BridgeTimes do not!
15 * And there are places, where standard says:
16 * "portTimes = designatedTimes" (13.32)
17 * "rootTimes = portTimes" (13.26.23)
19 * For now I decide: All structures will hold Hello_Time,
20 * because in 802.1D they do.
21 * Maybe 802.1Q-2011 clarifies this, but I don't have the text.
24 /* 802.1Q-2005 does not define but widely use variable name newInfoXst.
25 * From the 802.1s I can guess that it means:
26 * - "newInfo" when tree is CIST;
27 * - "newInfoMsti" when tree is not CIST (is MSTI).
28 * But that is only a guess and I could be wrong here ;)
32 #include <linux/if_bridge.h>
33 #include <asm/byteorder.h>
38 static void PTSM_tick(port_t
*prt
);
39 static void TCSM_run(per_tree_port_t
*ptp
);
40 static void BDSM_begin(port_t
*prt
);
41 static void br_state_machines_begin(bridge_t
*br
);
42 static void prt_state_machines_begin(port_t
*prt
);
43 static void tree_state_machines_begin(tree_t
*tree
);
44 static void br_state_machines_run(bridge_t
*br
);
46 #define FOREACH_PORT_IN_BRIDGE(port, bridge) \
47 list_for_each_entry((port), &(bridge)->ports, br_list)
48 #define FOREACH_TREE_IN_BRIDGE(tree, bridge) \
49 list_for_each_entry((tree), &(bridge)->trees, bridge_list)
50 #define FOREACH_PTP_IN_TREE(ptp, tree) \
51 list_for_each_entry((ptp), &(tree)->ports, tree_list)
52 #define FOREACH_PTP_IN_PORT(ptp, port) \
53 list_for_each_entry((ptp), &(port)->trees, port_list)
55 /* 17.20.11 of 802.1D */
56 #define rstpVersion(br) ((br)->ForceProtocolVersion >= protoRSTP)
59 * Recalculate configuration digest. (13.7)
61 static void RecalcConfigDigest(bridge_t
*br
)
63 __be16 vid2mstid
[MAX_VID
+ 2];
64 unsigned char mstp_key
[] = HMAC_KEY
;
67 vid2mstid
[0] = vid2mstid
[MAX_VID
+ 1] = 0;
68 for(vid
= 1; vid
<= MAX_VID
; ++vid
)
69 vid2mstid
[vid
] = br
->fid2mstid
[br
->vid2fid
[vid
]];
71 hmac_md5((void *)vid2mstid
, sizeof(vid2mstid
), mstp_key
, sizeof(mstp_key
),
72 br
->MstConfigId
.s
.configuration_digest
);
76 * 13.37.1 - Table 13-3
78 static __u32
compute_pcost(int speed
)
82 return (speed
< 20000000) ? 20000000 / speed
: 1;
87 static tree_t
* create_tree(bridge_t
*br
, __u8
*macaddr
, __be16 MSTID
)
89 /* Initialize all fields except anchor */
90 tree_t
*tree
= calloc(1, sizeof(*tree
));
93 ERROR_BRNAME(br
, "Out of memory");
98 INIT_LIST_HEAD(&tree
->ports
);
100 memcpy(tree
->BridgeIdentifier
.s
.mac_address
, macaddr
, ETH_ALEN
);
101 /* 0x8000 = default bridge priority (17.14 of 802.1D) */
102 tree
->BridgeIdentifier
.s
.priority
= __constant_cpu_to_be16(0x8000) | MSTID
;
103 assign(tree
->BridgePriority
.RootID
, tree
->BridgeIdentifier
);
104 assign(tree
->BridgePriority
.RRootID
, tree
->BridgeIdentifier
);
105 assign(tree
->BridgePriority
.DesignatedBridgeID
, tree
->BridgeIdentifier
);
107 assign(tree
->BridgeTimes
.remainingHops
, br
->MaxHops
);
108 assign(tree
->BridgeTimes
.Forward_Delay
, br
->Forward_Delay
);
109 assign(tree
->BridgeTimes
.Max_Age
, br
->Max_Age
);
110 assign(tree
->BridgeTimes
.Message_Age
, (__u8
)0);
111 /* 17.14 of 802.1D */
112 assign(tree
->BridgeTimes
.Hello_Time
, (__u8
)2);
114 /* 12.8.1.1.3.(b,c,d) */
115 tree
->time_since_topology_change
= 0;
116 tree
->topology_change_count
= 0;
117 tree
->topology_change
= false; /* since all tcWhile are initialized to 0 */
119 /* The following are initialized in BEGIN state:
120 * - rootPortId, rootPriority, rootTimes: in Port Role Selection SM
125 static per_tree_port_t
* create_ptp(tree_t
*tree
, port_t
*prt
)
127 /* Initialize all fields except anchors */
128 per_tree_port_t
*ptp
= calloc(1, sizeof(*ptp
));
131 ERROR_PRTNAME(prt
->bridge
, prt
, "Out of memory");
136 ptp
->MSTID
= tree
->MSTID
;
138 ptp
->state
= BR_STATE_DISABLED
;
141 ptp
->updtInfo
= false;
142 /* 0x80 = default port priority (17.14 of 802.1D) */
143 ptp
->portId
= __constant_cpu_to_be16(0x8000) | prt
->port_number
;
144 ptp
->master
= false; /* 13.24.5 */
145 assign(ptp
->AdminInternalPortPathCost
, 0u);
146 assign(ptp
->InternalPortPathCost
, compute_pcost(GET_PORT_SPEED(prt
)));
147 /* 802.1Q leaves portPriority and portTimes uninitialized */
148 assign(ptp
->portPriority
, tree
->BridgePriority
);
149 assign(ptp
->portTimes
, tree
->BridgeTimes
);
151 /* The following are initialized in BEGIN state:
152 * - rcvdMsg: in Port Receive SM
153 * - fdWhile, rrWhile, rbWhile, role, learn, forward,
154 * sync, synced, reRoot: in Port Role Transitions SM
155 * - tcWhile, fdbFlush: Topology Change SM
156 * - rcvdInfoWhile, proposed, proposing, agree, agreed,
157 * infoIs, reselect, selected: Port Information SM
158 * - forwarding, learning: Port State Transition SM
159 * - selectedRole, designatedPriority, designatedTimes: Port Role Selection SM
162 /* The following are not initialized (set to zero thanks to calloc):
172 /* External events */
174 bool MSTP_IN_bridge_create(bridge_t
*br
, __u8
*macaddr
)
178 /* Initialize all fields except sysdeps and anchor */
179 INIT_LIST_HEAD(&br
->ports
);
180 INIT_LIST_HEAD(&br
->trees
);
181 br
->bridgeEnabled
= false;
182 memset(br
->vid2fid
, 0, sizeof(br
->vid2fid
));
183 memset(br
->fid2mstid
, 0, sizeof(br
->fid2mstid
));
184 assign(br
->MstConfigId
.s
.selector
, (__u8
)0);
185 sprintf(br
->MstConfigId
.s
.configuration_name
,
186 "%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
187 macaddr
[0], macaddr
[1], macaddr
[2],
188 macaddr
[3], macaddr
[4], macaddr
[5]);
189 assign(br
->MstConfigId
.s
.revision_level
, __constant_cpu_to_be16(0));
190 RecalcConfigDigest(br
); /* set br->MstConfigId.s.configuration_digest */
191 br
->ForceProtocolVersion
= protoMSTP
;
192 assign(br
->MaxHops
, (__u8
)20); /* 13.37.3 */
193 assign(br
->Forward_Delay
, (__u8
)15); /* 17.14 of 802.1D */
194 assign(br
->Max_Age
, (__u8
)20); /* 17.14 of 802.1D */
195 assign(br
->Transmit_Hold_Count
, 6u); /* 17.14 of 802.1D */
196 assign(br
->Migrate_Time
, 3u); /* 17.14 of 802.1D */
197 assign(br
->rapidAgeingWhile
, 0u);
202 if(!(cist
= create_tree(br
, macaddr
, 0)))
204 list_add_tail(&cist
->bridge_list
, &br
->trees
);
206 br_state_machines_begin(br
);
210 bool MSTP_IN_port_create_and_add_tail(port_t
*prt
, __u16 portno
)
213 per_tree_port_t
*ptp
, *nxt
;
214 bridge_t
*br
= prt
->bridge
;
216 /* Initialize all fields except sysdeps and bridge */
217 INIT_LIST_HEAD(&prt
->trees
);
218 prt
->port_number
= __cpu_to_be16(portno
);
220 assign(prt
->AdminExternalPortPathCost
, 0u);
221 /* Default for operP2P is false because by default AdminP2P
222 * says to auto-detect p2p state, and it is derived from duplex
223 * and initially port is in down state and in this down state
224 * duplex is set to false (half) */
225 prt
->AdminP2P
= p2pAuto
;
226 prt
->operPointToPointMAC
= false;
227 prt
->portEnabled
= false;
228 prt
->infoInternal
= false;
229 prt
->rcvdInternal
= false;
230 prt
->rcvdTcAck
= false;
231 prt
->rcvdTcn
= false;
232 prt
->restrictedRole
= false; /* 13.25.14 */
233 prt
->restrictedTcn
= false; /* 13.25.15 */
234 assign(prt
->ExternalPortPathCost
, MAX_PATH_COST
); /* 13.37.1 */
235 prt
->AdminEdgePort
= false; /* 13.25 */
236 prt
->AutoEdge
= true; /* 13.25 */
238 /* The following are initialized in BEGIN state:
239 * - mdelayWhile. mcheck, sendRSTP: in Port Protocol Migration SM
240 * - helloWhen, newInfo, newInfoMsti, txCount: in Port Transmit SM
241 * - edgeDelayWhile, rcvdBpdu, rcvdRSTP, rcvdSTP : in Port Receive SM
242 * - operEdge: in Bridge Detection SM
243 * - tcAck: in Topology Change SM
246 /* Create PerTreePort structures for all existing trees */
247 FOREACH_TREE_IN_BRIDGE(tree
, br
)
249 if(!(ptp
= create_ptp(tree
, prt
)))
251 /* Remove and free all previously created entries in port's list */
252 list_for_each_entry_safe(ptp
, nxt
, &prt
->trees
, port_list
)
254 list_del(&ptp
->port_list
);
255 list_del(&ptp
->tree_list
);
260 list_add_tail(&ptp
->port_list
, &prt
->trees
);
261 list_add_tail(&ptp
->tree_list
, &tree
->ports
);
264 /* Add new port to the tail of the list in the bridge */
265 /* NOTE: if one wants add port NOT to the tail of the list of ports,
266 * one should revise above loop (FOREACH_TREE_IN_BRIDGE)
267 * because it heavily depends on the fact that port is added to the tail.
269 list_add_tail(&prt
->br_list
, &br
->ports
);
271 prt_state_machines_begin(prt
);
275 void MSTP_IN_delete_port(port_t
*prt
)
277 per_tree_port_t
*ptp
, *nxt
;
278 bridge_t
*br
= prt
->bridge
;
282 prt
->portEnabled
= false;
283 br_state_machines_run(br
);
286 list_for_each_entry_safe(ptp
, nxt
, &prt
->trees
, port_list
)
288 list_del(&ptp
->port_list
);
289 list_del(&ptp
->tree_list
);
293 br_state_machines_run(br
);
296 void MSTP_IN_delete_bridge(bridge_t
*br
)
298 tree_t
*tree
, *nxt_tree
;
299 port_t
*prt
, *nxt_prt
;
301 br
->bridgeEnabled
= false;
303 /* We SHOULD first delete all ports and only THEN delete all tree_t
304 * structures as the tree_t structure contains the head for the per-port
305 * list of tree data (tree_t.ports).
306 * If this list_head will be deleted before all the per_tree_ports
307 * bad things will happen ;)
310 list_for_each_entry_safe(prt
, nxt_prt
, &br
->ports
, br_list
)
312 list_del(&prt
->br_list
);
313 MSTP_IN_delete_port(prt
);
317 list_for_each_entry_safe(tree
, nxt_tree
, &br
->trees
, bridge_list
)
319 list_del(&tree
->bridge_list
);
324 void MSTP_IN_set_bridge_address(bridge_t
*br
, __u8
*macaddr
)
327 bool changed
= false;
329 FOREACH_TREE_IN_BRIDGE(tree
, br
)
331 if(0 == memcmp(tree
->BridgeIdentifier
.s
.mac_address
, macaddr
, ETH_ALEN
))
334 memcpy(tree
->BridgeIdentifier
.s
.mac_address
, macaddr
, ETH_ALEN
);
335 tree
->BridgePriority
.RootID
= tree
->BridgePriority
.RRootID
=
336 tree
->BridgePriority
.DesignatedBridgeID
= tree
->BridgeIdentifier
;
340 br_state_machines_begin(br
);
343 void MSTP_IN_set_bridge_enable(bridge_t
*br
, bool up
)
345 if(br
->bridgeEnabled
== up
)
347 br
->bridgeEnabled
= up
;
348 br_state_machines_begin(br
);
351 void MSTP_IN_set_port_enable(port_t
*prt
, bool up
, int speed
, int duplex
)
353 __u32 computed_pcost
, new_ExternalPathCost
, new_InternalPathCost
;
354 per_tree_port_t
*ptp
;
356 bool changed
= false;
360 computed_pcost
= compute_pcost(speed
);
361 new_ExternalPathCost
= (0 == prt
->AdminExternalPortPathCost
) ?
363 : prt
->AdminExternalPortPathCost
;
364 if(prt
->ExternalPortPathCost
!= new_ExternalPathCost
)
366 assign(prt
->ExternalPortPathCost
, new_ExternalPathCost
);
369 FOREACH_PTP_IN_PORT(ptp
, prt
)
371 new_InternalPathCost
= (0 == ptp
->AdminInternalPortPathCost
) ?
373 : ptp
->AdminInternalPortPathCost
;
374 if(ptp
->InternalPortPathCost
!= new_InternalPathCost
)
376 assign(ptp
->InternalPortPathCost
, new_InternalPathCost
);
381 switch(prt
->AdminP2P
)
394 if(prt
->operPointToPointMAC
!= new_p2p
)
396 prt
->operPointToPointMAC
= new_p2p
;
400 if(!prt
->portEnabled
)
402 prt
->portEnabled
= true;
410 prt
->portEnabled
= false;
416 br_state_machines_run(prt
->bridge
);
419 void MSTP_IN_one_second(bridge_t
*br
)
426 if(!br
->bridgeEnabled
)
429 FOREACH_TREE_IN_BRIDGE(tree
, br
)
430 if(!(tree
->topology_change
))
431 ++(tree
->time_since_topology_change
);
433 FOREACH_PORT_IN_BRIDGE(prt
, br
)
435 /* support for rapid ageing */
436 if(br
->rapidAgeingWhile
)
438 if((--(br
->rapidAgeingWhile
)) == 0)
439 MSTP_OUT_set_ageing_time(br
, -1);
442 br_state_machines_run(br
);
445 void MSTP_IN_all_fids_flushed(per_tree_port_t
*ptp
)
447 bridge_t
*br
= ptp
->port
->bridge
;
448 if(!br
->bridgeEnabled
)
450 ptp
->fdbFlush
= false;
452 br_state_machines_run(br
);
455 /* NOTE: bpdu pointer is unaligned, but it works because
456 * bpdu_t is packed. Don't try to cast bpdu to non-packed type ;)
458 void MSTP_IN_rx_bpdu(port_t
*prt
, bpdu_t
*bpdu
, int size
)
461 bridge_t
*br
= prt
->bridge
;
463 if(!br
->bridgeEnabled
)
465 INFO_PRTNAME(br
, prt
, "Received BPDU while bridge is disabled");
471 ERROR_PRTNAME(br
, prt
, "Port hasn't processed previous BPDU");
475 /* 14.4 Validation */
476 if((TCN_BPDU_SIZE
> size
) || (0 != bpdu
->protocolIdentifier
))
478 bpdu_validation_failed
:
479 INFO_PRTNAME(br
, prt
, "BPDU validation failed");
482 switch(bpdu
->bpduType
)
487 bpdu
->protocolVersion
= protoSTP
;
488 LOG_PRTNAME(br
, prt
, "received TCN BPDU");
492 if(CONFIG_BPDU_SIZE
> size
)
493 goto bpdu_validation_failed
;
494 /* Valid Config BPDU */
495 bpdu
->protocolVersion
= protoSTP
;
496 LOG_PRTNAME(br
, prt
, "received Config BPDU");
499 if(protoRSTP
== bpdu
->protocolVersion
)
501 if(RST_BPDU_SIZE
> size
)
502 goto bpdu_validation_failed
;
504 /* bpdu->protocolVersion = protoRSTP; */
505 LOG_PRTNAME(br
, prt
, "received RST BPDU");
508 if(protoMSTP
> bpdu
->protocolVersion
)
509 goto bpdu_validation_failed
;
510 /* Yes, 802.1Q-2005 says here to check if it contains
511 * "35 or more octets", not 36! (see 14.4.d).1) )
512 * That's why I check size against CONFIG_BPDU_SIZE
513 * and not RST_BPDU_SIZE.
515 if(CONFIG_BPDU_SIZE
> size
)
516 goto bpdu_validation_failed
;
517 mstis_size
= __be16_to_cpu(bpdu
->version3_len
)
518 - MST_BPDU_VER3LEN_WO_MSTI_MSGS
;
519 if((MST_BPDU_SIZE_WO_MSTI_MSGS
> size
) || (0 != bpdu
->version1_len
)
521 || ((MAX_STANDARD_MSTIS
* sizeof(msti_configuration_message_t
))
523 || (0 != (mstis_size
% sizeof(msti_configuration_message_t
)))
527 bpdu
->protocolVersion
= protoRSTP
;
528 LOG_PRTNAME(br
, prt
, "received RST BPDU");
533 bpdu
->protocolVersion
= protoMSTP
;
534 prt
->rcvdBpduNumOfMstis
= mstis_size
535 / sizeof(msti_configuration_message_t
);
536 LOG_PRTNAME(br
, prt
, "received MST BPDU with %d MSTIs",
537 prt
->rcvdBpduNumOfMstis
);
540 goto bpdu_validation_failed
;
543 assign(prt
->rcvdBpduData
, *bpdu
);
544 prt
->rcvdBpdu
= true;
546 br_state_machines_run(br
);
549 /* 12.8.1.1 Read CIST Bridge Protocol Parameters */
550 void MSTP_IN_get_cist_bridge_status(bridge_t
*br
, CIST_BridgeStatus
*status
)
552 tree_t
*cist
= GET_CIST_TREE(br
);
553 assign(status
->bridge_id
, cist
->BridgeIdentifier
);
554 assign(status
->time_since_topology_change
,
555 cist
->time_since_topology_change
);
556 assign(status
->topology_change_count
, cist
->topology_change_count
);
557 status
->topology_change
= cist
->topology_change
;
558 assign(status
->designated_root
, cist
->rootPriority
.RootID
);
559 assign(status
->root_path_cost
,
560 __be32_to_cpu(cist
->rootPriority
.ExtRootPathCost
));
561 assign(status
->regional_root
, cist
->rootPriority
.RRootID
);
562 assign(status
->internal_path_cost
,
563 __be32_to_cpu(cist
->rootPriority
.IntRootPathCost
));
564 assign(status
->root_port_id
, cist
->rootPortId
);
565 assign(status
->root_max_age
, cist
->rootTimes
.Max_Age
);
566 assign(status
->root_forward_delay
, cist
->rootTimes
.Forward_Delay
);
567 assign(status
->bridge_max_age
, br
->Max_Age
);
568 assign(status
->bridge_forward_delay
, br
->Forward_Delay
);
569 assign(status
->max_hops
, br
->MaxHops
);
570 assign(status
->tx_hold_count
, br
->Transmit_Hold_Count
);
571 status
->protocol_version
= br
->ForceProtocolVersion
;
572 status
->enabled
= br
->bridgeEnabled
;
575 /* 12.8.1.2 Read MSTI Bridge Protocol Parameters */
576 void MSTP_IN_get_msti_bridge_status(tree_t
*tree
, MSTI_BridgeStatus
*status
)
578 assign(status
->bridge_id
, tree
->BridgeIdentifier
);
579 assign(status
->time_since_topology_change
,
580 tree
->time_since_topology_change
);
581 assign(status
->topology_change_count
, tree
->topology_change_count
);
582 status
->topology_change
= tree
->topology_change
;
583 assign(status
->regional_root
, tree
->rootPriority
.RRootID
);
584 assign(status
->internal_path_cost
,
585 __be32_to_cpu(tree
->rootPriority
.IntRootPathCost
));
586 assign(status
->root_port_id
, tree
->rootPortId
);
589 /* 12.8.1.3 Set CIST Bridge Protocol Parameters */
590 int MSTP_IN_set_cist_bridge_config(bridge_t
*br
, CIST_BridgeConfig
*cfg
)
592 bool changed
, changedBridgeTimes
, init
;
594 __u8 new_forward_delay
, new_max_age
;
597 per_tree_port_t
*ptp
;
599 /* Firstly, validation */
600 if(cfg
->set_bridge_max_age
)
602 new_max_age
= cfg
->bridge_max_age
;
603 if((6 > new_max_age
) || (40 < new_max_age
))
606 "Bridge Max Age must be between 6 and 40 seconds");
611 new_max_age
= br
->Max_Age
;
613 if(cfg
->set_bridge_forward_delay
)
615 new_forward_delay
= cfg
->bridge_forward_delay
;
616 if((4 > new_forward_delay
) || (30 < new_forward_delay
))
619 "Bridge Forward Delay must be between 4 and 30 seconds");
624 new_forward_delay
= br
->Forward_Delay
;
626 if(cfg
->set_bridge_max_age
|| cfg
->set_bridge_forward_delay
)
628 if((2 * (new_forward_delay
- 1)) < new_max_age
)
630 ERROR_BRNAME(br
, "Configured Bridge Times don't meet "
631 "2 * (Bridge Foward Delay - 1 second) >= Bridge Max Age");
636 if(cfg
->set_protocol_version
)
638 switch(cfg
->protocol_version
)
645 ERROR_BRNAME(br
, "Bad protocol version (%d)",
646 cfg
->protocol_version
);
651 if(cfg
->set_tx_hold_count
)
653 if((1 > cfg
->tx_hold_count
) || (10 < cfg
->tx_hold_count
))
656 "Transmit Hold Count must be between 1 and 10 seconds");
661 if(cfg
->set_max_hops
)
663 if((6 > cfg
->max_hops
) || (40 < cfg
->max_hops
))
665 ERROR_BRNAME(br
, "Bridge Max Hops must be between 6 and 40");
673 /* Secondly, do set */
674 changed
= changedBridgeTimes
= init
= false;
676 if(cfg
->set_bridge_max_age
|| cfg
->set_bridge_forward_delay
)
678 if(cmp(new_max_age
, !=, br
->Max_Age
)
679 || cmp(new_forward_delay
, !=, br
->Forward_Delay
)
682 assign(br
->Max_Age
, new_max_age
);
683 assign(br
->Forward_Delay
, new_forward_delay
);
684 changed
= changedBridgeTimes
= true;
688 if((cfg
->set_protocol_version
)
689 && (cfg
->protocol_version
!= br
->ForceProtocolVersion
)
692 br
->ForceProtocolVersion
= cfg
->protocol_version
;
693 changed
= init
= true;
696 if(cfg
->set_tx_hold_count
)
698 if(cfg
->tx_hold_count
!= br
->Transmit_Hold_Count
)
700 assign(br
->Transmit_Hold_Count
, cfg
->tx_hold_count
);
701 FOREACH_PORT_IN_BRIDGE(prt
, br
)
702 assign(prt
->txCount
, 0u);
707 if(cfg
->set_max_hops
)
709 if(cfg
->max_hops
!= br
->MaxHops
)
711 assign(br
->MaxHops
, cfg
->max_hops
);
712 changed
= changedBridgeTimes
= true;
716 /* Thirdly, finalize changes */
717 if(changedBridgeTimes
)
719 FOREACH_TREE_IN_BRIDGE(tree
, br
)
721 assign(tree
->BridgeTimes
.remainingHops
, br
->MaxHops
);
722 assign(tree
->BridgeTimes
.Forward_Delay
, br
->Forward_Delay
);
723 assign(tree
->BridgeTimes
.Max_Age
, br
->Max_Age
);
724 /* Comment found in rstpd by Srinivas Aji:
725 * Do this for any change in BridgeTimes.
726 * Otherwise we fail UNH rstp.op_D test 3.2 since when administratively
727 * setting BridgeForwardDelay, etc, the values don't propagate from
728 * rootTimes to designatedTimes immediately without this change.
730 FOREACH_PTP_IN_TREE(ptp
, tree
)
732 ptp
->selected
= false;
733 ptp
->reselect
= true;
738 if(changed
&& br
->bridgeEnabled
)
741 br_state_machines_begin(br
);
743 br_state_machines_run(br
);
749 /* 12.8.1.4 Set MSTI Bridge Protocol Parameters */
750 int MSTP_IN_set_msti_bridge_config(tree_t
*tree
, __u8 bridge_priority
)
752 per_tree_port_t
*ptp
;
755 if(15 < bridge_priority
)
757 ERROR_BRNAME(tree
->bridge
,
758 "MSTI %hu: Bridge Priority must be between 0 and 15",
759 __be16_to_cpu(tree
->MSTID
));
763 valuePri
= bridge_priority
<< 4;
764 if(GET_PRIORITY_FROM_IDENTIFIER(tree
->BridgeIdentifier
) == valuePri
)
766 SET_PRIORITY_IN_IDENTIFIER(valuePri
, tree
->BridgeIdentifier
);
767 tree
->BridgePriority
.RootID
= tree
->BridgePriority
.RRootID
=
768 tree
->BridgePriority
.DesignatedBridgeID
= tree
->BridgeIdentifier
;
769 /* 12.8.1.4.4 do not require reselect, but I think it is needed,
770 * because 12.8.1.3.4.c) requires it */
771 FOREACH_PTP_IN_TREE(ptp
, tree
)
773 ptp
->selected
= false;
774 ptp
->reselect
= true;
779 /* 12.8.2.1 Read CIST Port Parameters */
780 void MSTP_IN_get_cist_port_status(port_t
*prt
, CIST_PortStatus
*status
)
782 per_tree_port_t
*cist
= GET_CIST_PTP_FROM_PORT(prt
);
784 status
->uptime
= (signed int)((prt
->bridge
)->uptime
)
785 - (signed int)(cist
->start_time
);
786 status
->state
= cist
->state
;
787 assign(status
->port_id
, cist
->portId
);
788 assign(status
->admin_external_port_path_cost
,
789 prt
->AdminExternalPortPathCost
);
790 assign(status
->external_port_path_cost
, prt
->ExternalPortPathCost
);
791 assign(status
->designated_root
, cist
->portPriority
.RootID
);
792 assign(status
->designated_external_cost
,
793 __be32_to_cpu(cist
->portPriority
.ExtRootPathCost
));
794 assign(status
->designated_bridge
, cist
->portPriority
.DesignatedBridgeID
);
795 assign(status
->designated_port
, cist
->portPriority
.DesignatedPortID
);
796 assign(status
->designated_regional_root
, cist
->portPriority
.RRootID
);
797 assign(status
->designated_internal_cost
,
798 __be32_to_cpu(cist
->portPriority
.IntRootPathCost
));
799 status
->tc_ack
= prt
->tcAck
;
800 assign(status
->port_hello_time
, cist
->portTimes
.Hello_Time
);
801 status
->admin_edge_port
= prt
->AdminEdgePort
;
802 status
->auto_edge_port
= prt
->AutoEdge
;
803 status
->oper_edge_port
= prt
->operEdge
;
804 status
->enabled
= prt
->portEnabled
;
805 status
->admin_p2p
= prt
->AdminP2P
;
806 status
->oper_p2p
= prt
->operPointToPointMAC
;
807 status
->restricted_role
= prt
->restrictedRole
;
808 status
->restricted_tcn
= prt
->restrictedTcn
;
809 status
->role
= cist
->role
;
810 status
->disputed
= cist
->disputed
;
811 assign(status
->admin_internal_port_path_cost
,
812 cist
->AdminInternalPortPathCost
);
813 assign(status
->internal_port_path_cost
, cist
->InternalPortPathCost
);
816 /* 12.8.2.2 Read MSTI Port Parameters */
817 void MSTP_IN_get_msti_port_status(per_tree_port_t
*ptp
,
818 MSTI_PortStatus
*status
)
820 status
->uptime
= (signed int)((ptp
->port
->bridge
)->uptime
)
821 - (signed int)(ptp
->start_time
);
822 status
->state
= ptp
->state
;
823 assign(status
->port_id
, ptp
->portId
);
824 assign(status
->admin_internal_port_path_cost
,
825 ptp
->AdminInternalPortPathCost
);
826 assign(status
->internal_port_path_cost
, ptp
->InternalPortPathCost
);
827 assign(status
->designated_regional_root
, ptp
->portPriority
.RRootID
);
828 assign(status
->designated_internal_cost
,
829 __be32_to_cpu(ptp
->portPriority
.IntRootPathCost
));
830 assign(status
->designated_bridge
, ptp
->portPriority
.DesignatedBridgeID
);
831 assign(status
->designated_port
, ptp
->portPriority
.DesignatedPortID
);
832 status
->role
= ptp
->role
;
833 status
->disputed
= ptp
->disputed
;
836 /* 12.8.2.3 Set CIST port parameters */
837 int MSTP_IN_set_cist_port_config(port_t
*prt
, CIST_PortConfig
*cfg
)
840 __u32 new_ExternalPathCost
;
842 per_tree_port_t
*cist
;
844 /* Firstly, validation */
845 if(cfg
->set_admin_p2p
)
847 switch(cfg
->admin_p2p
)
854 cfg
->admin_p2p
= p2pAuto
;
858 /* Secondly, do set */
861 if(cfg
->set_admin_external_port_path_cost
)
863 prt
->AdminExternalPortPathCost
= cfg
->admin_external_port_path_cost
;
864 new_ExternalPathCost
= (0 == prt
->AdminExternalPortPathCost
) ?
865 compute_pcost(GET_PORT_SPEED(prt
))
866 : prt
->AdminExternalPortPathCost
;
867 if(prt
->ExternalPortPathCost
!= new_ExternalPathCost
)
869 assign(prt
->ExternalPortPathCost
, new_ExternalPathCost
);
872 cist
= GET_CIST_PTP_FROM_PORT(prt
);
873 cist
->selected
= false;
874 cist
->reselect
= true;
878 if(cfg
->set_admin_p2p
)
880 prt
->AdminP2P
= cfg
->admin_p2p
;
881 switch(prt
->AdminP2P
)
891 new_p2p
= !!GET_PORT_DUPLEX(prt
);
894 if(prt
->operPointToPointMAC
!= new_p2p
)
896 prt
->operPointToPointMAC
= new_p2p
;
901 if(cfg
->set_admin_edge_port
)
903 if(prt
->AdminEdgePort
!= cfg
->admin_edge_port
)
905 prt
->AdminEdgePort
= cfg
->admin_edge_port
;
911 if(cfg
->set_auto_edge_port
)
913 if(prt
->AutoEdge
!= cfg
->auto_edge_port
)
915 prt
->AutoEdge
= cfg
->auto_edge_port
;
920 if(cfg
->set_restricted_role
)
922 if(prt
->restrictedRole
!= cfg
->restricted_role
)
924 prt
->restrictedRole
= cfg
->restricted_role
;
929 if(cfg
->set_restricted_tcn
)
931 if(prt
->restrictedTcn
!= cfg
->restricted_tcn
)
933 prt
->restrictedTcn
= cfg
->restricted_tcn
;
938 if(changed
&& prt
->portEnabled
)
939 br_state_machines_run(prt
->bridge
);
944 /* 12.8.2.4 Set MSTI port parameters */
945 int MSTP_IN_set_msti_port_config(per_tree_port_t
*ptp
, MSTI_PortConfig
*cfg
)
948 __u32 new_InternalPathCost
;
949 bool changed
= false;
950 port_t
*prt
= ptp
->port
;
951 bridge_t
*br
= prt
->bridge
;
953 if(cfg
->set_port_priority
)
955 if(15 < cfg
->port_priority
)
957 ERROR_MSTINAME(br
, prt
, ptp
,
958 "Port Priority must be between 0 and 15");
961 valuePri
= cfg
->port_priority
<< 4;
962 if(GET_PRIORITY_FROM_IDENTIFIER(ptp
->portId
) != valuePri
)
964 SET_PRIORITY_IN_IDENTIFIER(valuePri
, ptp
->portId
);
969 if(cfg
->set_admin_internal_port_path_cost
)
971 ptp
->AdminInternalPortPathCost
= cfg
->admin_internal_port_path_cost
;
972 new_InternalPathCost
= (0 == ptp
->AdminInternalPortPathCost
) ?
973 compute_pcost(GET_PORT_SPEED(prt
))
974 : ptp
->AdminInternalPortPathCost
;
975 if(ptp
->InternalPortPathCost
!= new_InternalPathCost
)
977 assign(ptp
->InternalPortPathCost
, new_InternalPathCost
);
982 if(changed
&& prt
->portEnabled
)
985 ptp
->selected
= false;
986 ptp
->reselect
= true;
988 br_state_machines_run(br
);
994 /* 12.8.2.5 Force BPDU Migration Check */
995 int MSTP_IN_port_mcheck(port_t
*prt
)
997 bridge_t
*br
= prt
->bridge
;
999 if(rstpVersion(br
) && prt
->portEnabled
&& br
->bridgeEnabled
)
1002 br_state_machines_run(br
);
1008 /* 12.10.3.8 Set VID to FID allocation */
1009 bool MSTP_IN_set_vid2fid(bridge_t
*br
, __u16 vid
, __u16 fid
)
1011 bool vid2mstid_changed
;
1013 if((vid
< 1) || (vid
> MAX_VID
) || (fid
> MAX_FID
))
1015 ERROR_BRNAME(br
, "Error allocating VID(%hu) to FID(%hu)", vid
, fid
);
1020 (br
->fid2mstid
[fid
] != br
->fid2mstid
[br
->vid2fid
[vid
]]);
1021 br
->vid2fid
[vid
] = fid
;
1022 if(vid2mstid_changed
)
1024 RecalcConfigDigest(br
);
1025 br_state_machines_begin(br
);
1031 /* Set all VID-to-FID mappings at once */
1032 bool MSTP_IN_set_all_vids2fids(bridge_t
*br
, __u16
*vids2fids
)
1034 bool vid2mstid_changed
;
1037 for(vid
= 1; vid
<= MAX_VID
; ++vid
)
1038 if(vids2fids
[vid
] > MAX_FID
)
1040 ERROR_BRNAME(br
, "Error allocating VID(%hu) to FID(%hu)",
1041 vid
, vids2fids
[vid
]);
1045 vid2mstid_changed
= false;
1046 for(vid
= 1; vid
<= MAX_VID
; ++vid
)
1048 if(br
->fid2mstid
[vids2fids
[vid
]] != br
->fid2mstid
[br
->vid2fid
[vid
]])
1050 vid2mstid_changed
= true;
1054 memcpy(br
->vid2fid
, vids2fids
, sizeof(br
->vid2fid
));
1055 if(vid2mstid_changed
)
1057 RecalcConfigDigest(br
);
1058 br_state_machines_begin(br
);
1064 /* 12.12.2.2 Set FID to MSTID allocation */
1065 bool MSTP_IN_set_fid2mstid(bridge_t
*br
, __u16 fid
, __u16 mstid
)
1074 ERROR_BRNAME(br
, "Bad FID(%hu)", fid
);
1078 MSTID
= __cpu_to_be16(mstid
);
1080 FOREACH_TREE_IN_BRIDGE(tree
, br
)
1082 if(tree
->MSTID
== MSTID
)
1090 ERROR_BRNAME(br
, "MSTID(%hu) not found", mstid
);
1094 if(br
->fid2mstid
[fid
] != MSTID
)
1096 br
->fid2mstid
[fid
] = MSTID
;
1097 /* check if there are VLANs using this FID */
1098 for(vid
= 1; vid
<= MAX_VID
; ++vid
)
1100 if(br
->vid2fid
[vid
] == fid
)
1102 RecalcConfigDigest(br
);
1103 br_state_machines_begin(br
);
1112 /* Set all FID-to-MSTID mappings at once */
1113 bool MSTP_IN_set_all_fids2mstids(bridge_t
*br
, __u16
*fids2mstids
)
1116 __be16 MSTID
[MAX_FID
+ 1];
1117 bool found
, vid2mstid_changed
;
1119 __be16 prev_vid2mstid
[MAX_VID
+ 2];
1121 for(fid
= 0; fid
<= MAX_FID
; ++fid
)
1123 MSTID
[fid
] = __cpu_to_be16(fids2mstids
[fid
]);
1125 FOREACH_TREE_IN_BRIDGE(tree
, br
)
1127 if(tree
->MSTID
== MSTID
[fid
])
1136 "Error allocating FID(%hu) to MSTID(%hu): MSTID not found",
1137 fid
, fids2mstids
[fid
]);
1142 for(vid
= 1; vid
<= MAX_VID
; ++vid
)
1143 prev_vid2mstid
[vid
] = br
->fid2mstid
[br
->vid2fid
[vid
]];
1144 memcpy(br
->fid2mstid
, MSTID
, sizeof(br
->fid2mstid
));
1145 vid2mstid_changed
= false;
1146 for(vid
= 1; vid
<= MAX_VID
; ++vid
)
1148 if(prev_vid2mstid
[vid
] != br
->fid2mstid
[br
->vid2fid
[vid
]])
1150 vid2mstid_changed
= true;
1154 if(vid2mstid_changed
)
1156 RecalcConfigDigest(br
);
1157 br_state_machines_begin(br
);
1163 /* 12.12.1.1 Read MSTI List */
1164 bool MSTP_IN_get_mstilist(bridge_t
*br
, int *num_mstis
, __u16
*mstids
)
1169 FOREACH_TREE_IN_BRIDGE(tree
, br
)
1171 mstids
[*num_mstis
] = __be16_to_cpu(tree
->MSTID
);
1172 /* Check for "<", not for "<=", as num_mstis include CIST */
1173 if(MAX_IMPLEMENTATION_MSTIS
< ++(*num_mstis
))
1180 /* 12.12.1.2 Create MSTI */
1181 bool MSTP_IN_create_msti(bridge_t
*br
, __u16 mstid
)
1183 tree_t
*tree
, *tree_after
, *new_tree
;
1184 per_tree_port_t
*ptp
, *nxt
, *ptp_after
, *new_ptp
;
1188 if((mstid
< 1) || (mstid
> MAX_MSTID
))
1190 ERROR_BRNAME(br
, "Bad MSTID(%hu)", mstid
);
1194 MSTID
= __cpu_to_be16(mstid
);
1195 /* Find place where to insert new MSTID.
1196 * Also check if such MSTID is already in the list.
1197 * Also count existing mstis.
1201 FOREACH_TREE_IN_BRIDGE(tree
, br
)
1203 if(tree
->MSTID
== MSTID
)
1205 INFO_BRNAME(br
, "MSTID(%hu) is already in the list", mstid
);
1206 return true; /* yes, it is success */
1208 if(cmp(tree
->MSTID
, <, MSTID
))
1213 if(NULL
== tree_after
)
1215 ERROR_BRNAME(br
, "Can't add MSTID(%hu): no CIST in the list", mstid
);
1218 /* End of Sanity check */
1220 /* Check for "<", not for "<=", as num_of_mstis include CIST */
1221 if(MAX_IMPLEMENTATION_MSTIS
< num_of_mstis
)
1223 ERROR_BRNAME(br
, "Can't add MSTID(%hu): maximum count(%u) reached",
1224 mstid
, MAX_IMPLEMENTATION_MSTIS
);
1228 /* Create new tree and its list of PerTreePort structures */
1229 tree
= GET_CIST_TREE(br
);
1230 if(!(new_tree
=create_tree(br
,tree
->BridgeIdentifier
.s
.mac_address
,MSTID
)))
1233 FOREACH_PTP_IN_TREE(ptp_after
, tree_after
)
1235 if(!(new_ptp
= create_ptp(new_tree
, ptp_after
->port
)))
1237 /* Remove and free all previously created entries in tree's list */
1238 list_for_each_entry_safe(ptp
, nxt
, &new_tree
->ports
, tree_list
)
1240 list_del(&ptp
->port_list
);
1241 list_del(&ptp
->tree_list
);
1246 list_add(&new_ptp
->port_list
, &ptp_after
->port_list
);
1247 list_add_tail(&new_ptp
->tree_list
, &new_tree
->ports
);
1250 list_add(&new_tree
->bridge_list
, &tree_after
->bridge_list
);
1251 /* There are no FIDs allocated to this MSTID, so VID-to-MSTID mapping
1252 * did not change. So, no need in RecalcConfigDigest.
1253 * Just initialize state machines for this tree.
1255 tree_state_machines_begin(new_tree
);
1259 /* 12.12.1.3 Delete MSTI */
1260 bool MSTP_IN_delete_msti(bridge_t
*br
, __u16 mstid
)
1263 per_tree_port_t
*ptp
, *nxt
;
1266 __be16 MSTID
= __cpu_to_be16(mstid
);
1268 if((mstid
< 1) || (mstid
> MAX_MSTID
))
1270 ERROR_BRNAME(br
, "Bad MSTID(%hu)", mstid
);
1274 /* Check if there are FIDs associated with this MSTID */
1275 for(fid
= 0; fid
<= MAX_FID
; ++fid
)
1277 if(br
->fid2mstid
[fid
] == MSTID
)
1280 "Can't delete MSTID(%hu): there are FIDs allocated to it",
1287 FOREACH_TREE_IN_BRIDGE(tree
, br
)
1289 if(tree
->MSTID
== MSTID
)
1297 INFO_BRNAME(br
, "MSTID(%hu) is not in the list", mstid
);
1298 return true; /* yes, it is success */
1301 list_del(&tree
->bridge_list
);
1302 list_for_each_entry_safe(ptp
, nxt
, &tree
->ports
, tree_list
)
1304 list_del(&ptp
->port_list
);
1305 list_del(&ptp
->tree_list
);
1310 /* There are no FIDs allocated to this MSTID, so VID-to-MSTID mapping
1311 * did not change. So, no need in RecalcConfigDigest.
1312 * Give state machine a spare run, just for the case...
1314 br_state_machines_run(br
);
1318 /* 12.12.3.4 Set MST Configuration Identifier Elements */
1319 void MSTP_IN_set_mst_config_id(bridge_t
*br
, __u16 revision
, __u8
*name
)
1321 __be16 valueRevision
= __cpu_to_be16(revision
);
1322 bool changed
= (0 != strncmp(name
, br
->MstConfigId
.s
.configuration_name
,
1323 sizeof(br
->MstConfigId
.s
.configuration_name
))
1325 || (valueRevision
!= br
->MstConfigId
.s
.revision_level
);
1329 assign(br
->MstConfigId
.s
.revision_level
, valueRevision
);
1330 memset(br
->MstConfigId
.s
.configuration_name
, 0,
1331 sizeof(br
->MstConfigId
.s
.configuration_name
));
1332 strncpy(br
->MstConfigId
.s
.configuration_name
, name
,
1333 sizeof(br
->MstConfigId
.s
.configuration_name
));
1334 br_state_machines_begin(br
);
1339 * If hint_SetToYes == true, some tcWhile in this tree has non-zero value.
1340 * If hint_SetToYes == false, some tcWhile in this tree has just became zero,
1341 * so we should check all other tcWhile's in this tree.
1343 static void set_TopologyChange(tree_t
*tree
, bool hint_SetToYes
)
1345 per_tree_port_t
*ptp
;
1346 bool prev_tc_not_set
= !tree
->topology_change
;
1350 tree
->topology_change
= true;
1351 tree
->time_since_topology_change
= 0;
1353 ++(tree
->topology_change_count
);
1357 /* Some tcWhile has just became zero. Check if we need reset
1358 * topology_change flag */
1362 tree
->topology_change
= false;
1363 FOREACH_PTP_IN_TREE(ptp
, tree
)
1365 if(0 != ptp
->tcWhile
)
1367 tree
->topology_change
= true;
1368 tree
->time_since_topology_change
= 0;
1374 /* Helper functions, compare two priority vectors */
1375 static bool samePriorityAndTimers(port_priority_vector_t
*vec1
,
1376 port_priority_vector_t
*vec2
,
1383 if(cmp(time1
->Forward_Delay
, !=, time2
->Forward_Delay
))
1385 if(cmp(time1
->Max_Age
, !=, time2
->Max_Age
))
1387 if(cmp(time1
->Message_Age
, !=, time2
->Message_Age
))
1389 if(cmp(time1
->Hello_Time
, !=, time2
->Hello_Time
))
1392 if(cmp(vec1
->RootID
, !=, vec2
->RootID
))
1394 if(cmp(vec1
->ExtRootPathCost
, !=, vec2
->ExtRootPathCost
))
1398 if(cmp(time1
->remainingHops
, !=, time2
->remainingHops
))
1401 if(cmp(vec1
->RRootID
, !=, vec2
->RRootID
))
1403 if(cmp(vec1
->IntRootPathCost
, !=, vec2
->IntRootPathCost
))
1405 if(cmp(vec1
->DesignatedBridgeID
, !=, vec2
->DesignatedBridgeID
))
1407 if(cmp(vec1
->DesignatedPortID
, !=, vec2
->DesignatedPortID
))
1413 static bool betterorsamePriority(port_priority_vector_t
*vec1
,
1414 port_priority_vector_t
*vec2
,
1415 port_identifier_t pId1
,
1416 port_identifier_t pId2
,
1423 if(0 < (result
= _ncmp(vec1
->RootID
, vec2
->RootID
)))
1424 return false; /* worse */
1426 return true; /* better */
1427 /* The same. Check further. */
1428 if(0 < (result
= _ncmp(vec1
->ExtRootPathCost
, vec2
->ExtRootPathCost
)))
1429 return false; /* worse */
1431 return true; /* better */
1432 /* The same. Check further. */
1435 if(0 < (result
= _ncmp(vec1
->RRootID
, vec2
->RRootID
)))
1436 return false; /* worse */
1438 return true; /* better */
1439 /* The same. Check further. */
1441 if(0 < (result
= _ncmp(vec1
->IntRootPathCost
, vec2
->IntRootPathCost
)))
1442 return false; /* worse */
1444 return true; /* better */
1445 /* The same. Check further. */
1447 if(0 < (result
= _ncmp(vec1
->DesignatedBridgeID
, vec2
->DesignatedBridgeID
)))
1448 return false; /* worse */
1450 return true; /* better */
1451 /* The same. Check further. */
1453 if(0 < (result
= _ncmp(vec1
->DesignatedPortID
, vec2
->DesignatedPortID
)))
1454 return false; /* worse */
1456 return true; /* better */
1457 /* The same. Check further. */
1459 /* Port ID is a tie-breaker */
1460 return cmp(pId1
, <=, pId2
);
1463 /* 13.26.1 betterorsameInfo */
1464 static bool betterorsameInfo(per_tree_port_t
*ptp
, port_info_origin_t newInfoIs
)
1466 if((ioReceived
== newInfoIs
) && (ioReceived
== ptp
->infoIs
))
1467 return betterorsamePriority(&ptp
->msgPriority
,
1469 0, 0, (0 == ptp
->MSTID
));
1470 else if((ioMine
== newInfoIs
) && (ioMine
== ptp
->infoIs
))
1471 return betterorsamePriority(&ptp
->designatedPriority
,
1473 0, 0, (0 == ptp
->MSTID
));
1477 /* 13.26.2 clearAllRcvdMsgs */
1478 static void clearAllRcvdMsgs(port_t
*prt
)
1480 per_tree_port_t
*ptp
;
1482 FOREACH_PTP_IN_PORT(ptp
, prt
)
1483 ptp
->rcvdMsg
= false;
1486 /* 13.26.3 clearReselectTree */
1487 static void clearReselectTree(tree_t
*tree
)
1489 per_tree_port_t
*ptp
;
1491 FOREACH_PTP_IN_TREE(ptp
, tree
)
1492 ptp
->reselect
= false;
1495 /* 13.26.4 fromSameRegion */
1496 static bool fromSameRegion(port_t
*prt
)
1498 /* Check for rcvdRSTP is superfluous here */
1499 if((protoMSTP
> prt
->rcvdBpduData
.protocolVersion
)/* || (!prt->rcvdRSTP)*/)
1501 return cmp(prt
->bridge
->MstConfigId
,
1502 ==, prt
->rcvdBpduData
.mstConfigurationIdentifier
);
1505 /* 13.26.5 newTcWhile */
1506 static void newTcWhile(per_tree_port_t
*ptp
)
1508 if(0 != ptp
->tcWhile
)
1511 tree_t
*tree
= ptp
->tree
;
1512 port_t
*prt
= ptp
->port
;
1516 per_tree_port_t
*cist
= GET_CIST_PTP_FROM_PORT(prt
);
1518 ptp
->tcWhile
= cist
->portTimes
.Hello_Time
+ 1;
1519 set_TopologyChange(tree
, true);
1522 prt
->newInfo
= true;
1524 prt
->newInfoMsti
= true;
1528 times_t
*times
= &tree
->rootTimes
;
1530 ptp
->tcWhile
= times
->Max_Age
+ times
->Forward_Delay
;
1531 set_TopologyChange(tree
, true);
1534 /* 13.26.6 rcvInfo */
1535 static port_info_t
rcvInfo(per_tree_port_t
*ptp
)
1537 msti_configuration_message_t
*msti_msg
;
1538 per_tree_port_t
*ptp_1
;
1539 bool roleIsDesignated
, cist
;
1540 bool msg_Better_port
, msg_SamePriorityAndTimers_port
;
1541 port_priority_vector_t
*mPri
= &(ptp
->msgPriority
);
1542 times_t
*mTimes
= &(ptp
->msgTimes
);
1543 port_t
*prt
= ptp
->port
;
1544 bpdu_t
*b
= &(prt
->rcvdBpduData
);
1546 if(bpduTypeTCN
== b
->bpduType
)
1548 prt
->rcvdTcn
= true;
1549 FOREACH_PTP_IN_PORT(ptp_1
, prt
)
1550 ptp_1
->rcvdTc
= true;
1558 assign(mPri
->RRootID
, b
->cistRRootID
);
1559 assign(mPri
->DesignatedPortID
, b
->cistPortID
);
1560 assign(mPri
->RootID
, b
->cistRootID
);
1561 assign(mPri
->ExtRootPathCost
, b
->cistExtRootPathCost
);
1563 #define NEAREST_WHOLE_SECOND(msgTime) \
1564 ((128 > msgTime[1]) ? msgTime[0] : msgTime[0] + 1)
1565 mTimes
->Forward_Delay
= NEAREST_WHOLE_SECOND(b
->ForwardDelay
);
1566 mTimes
->Max_Age
= NEAREST_WHOLE_SECOND(b
->MaxAge
);
1567 mTimes
->Message_Age
= NEAREST_WHOLE_SECOND(b
->MessageAge
);
1568 mTimes
->Hello_Time
= NEAREST_WHOLE_SECOND(b
->HelloTime
);
1569 if(protoMSTP
> b
->protocolVersion
)
1570 { /* STP or RSTP Configuration BPDU */
1571 /* 13.26.6.NOTE: A Configuration BPDU implicitly conveys a
1572 * Designated Port Role */
1573 roleIsDesignated
= true;
1574 assign(mPri
->IntRootPathCost
, __constant_cpu_to_be32(0));
1575 assign(mPri
->DesignatedBridgeID
, b
->cistRRootID
);
1576 /* messageTimes.remainingHops */
1577 assign(mTimes
->remainingHops
, prt
->bridge
->MaxHops
);
1581 switch(BPDU_FLAGS_ROLE_GET(b
->flags
))
1583 case encodedRoleAlternateBackup
:
1584 case encodedRoleRoot
:
1585 roleIsDesignated
= false;
1587 case encodedRoleDesignated
:
1588 roleIsDesignated
= true;
1593 assign(mPri
->IntRootPathCost
, b
->cistIntRootPathCost
);
1594 assign(mPri
->DesignatedBridgeID
, b
->cistBridgeID
);
1595 /* messageTimes.remainingHops */
1596 assign(mTimes
->remainingHops
, b
->cistRemainingHops
);
1601 if(protoMSTP
> b
->protocolVersion
)
1603 msti_msg
= ptp
->rcvdMstiConfig
;
1604 switch(BPDU_FLAGS_ROLE_GET(msti_msg
->flags
))
1606 case encodedRoleAlternateBackup
:
1607 case encodedRoleRoot
:
1608 roleIsDesignated
= false;
1610 case encodedRoleDesignated
:
1611 roleIsDesignated
= true;
1618 assign(mPri
->RRootID
, msti_msg
->mstiRRootID
);
1619 assign(mPri
->IntRootPathCost
, msti_msg
->mstiIntRootPathCost
);
1620 /* Build MSTI DesignatedBridgeID */
1621 assign(mPri
->DesignatedBridgeID
, b
->cistBridgeID
);
1622 assign(mPri
->DesignatedBridgeID
.s
.priority
, ptp
->MSTID
);
1623 SET_PRIORITY_IN_IDENTIFIER(msti_msg
->bridgeIdentifierPriority
,
1624 mPri
->DesignatedBridgeID
);
1625 /* Build MSTI DesignatedPortID */
1626 assign(mPri
->DesignatedPortID
, b
->cistPortID
);
1627 SET_PRIORITY_IN_IDENTIFIER(msti_msg
->portIdentifierPriority
,
1628 mPri
->DesignatedPortID
);
1630 assign(mTimes
->remainingHops
, msti_msg
->remainingHops
);
1633 msg_Better_port
= !betterorsamePriority(&(ptp
->portPriority
), mPri
,
1635 if(roleIsDesignated
)
1639 || ((0 == memcmp(mPri
->DesignatedBridgeID
.s
.mac_address
,
1640 ptp
->portPriority
.DesignatedBridgeID
.s
.mac_address
,
1643 && (0 == ((mPri
->DesignatedPortID
1644 ^ ptp
->portPriority
.DesignatedPortID
1645 ) & __constant_cpu_to_be16(0x0FFF)
1650 return SuperiorDesignatedInfo
;
1653 /* We already know that msgPriority _IS_NOT_BETTER_than portPriority.
1654 * So, if msgPriority _IS_SAME_OR_BETTER_than portPriority then
1655 * msgPriority _IS_SAME_as portPriority.
1657 msg_SamePriorityAndTimers_port
=
1658 samePriorityAndTimers(mPri
, &(ptp
->portPriority
),
1659 mTimes
, &(ptp
->portTimes
),
1661 if((!msg_SamePriorityAndTimers_port
)
1662 && betterorsamePriority(mPri
, &(ptp
->portPriority
), 0, 0, cist
)
1664 return SuperiorDesignatedInfo
;
1667 if(msg_SamePriorityAndTimers_port
&& (ioReceived
== ptp
->infoIs
))
1668 return RepeatedDesignatedInfo
;
1671 return InferiorDesignatedInfo
;
1675 if(!msg_Better_port
)
1676 return InferiorRootAlternateInfo
;
1681 /* 13.26.7 recordAgreement */
1682 static void recordAgreement(per_tree_port_t
*ptp
)
1684 bool cist_agreed
, cist_proposing
;
1685 per_tree_port_t
*cist
;
1686 port_t
*prt
= ptp
->port
;
1687 bpdu_t
*b
= &(prt
->rcvdBpduData
);
1691 if(rstpVersion(prt
->bridge
) && prt
->operPointToPointMAC
1692 && (b
->flags
& (1 << offsetAgreement
))
1696 ptp
->proposing
= false;
1699 ptp
->agreed
= false;
1700 cist_agreed
= ptp
->agreed
;
1701 cist_proposing
= ptp
->proposing
;
1702 if(!prt
->rcvdInternal
)
1703 list_for_each_entry_continue(ptp
, &prt
->trees
, port_list
)
1705 ptp
->agreed
= cist_agreed
;
1706 ptp
->proposing
= cist_proposing
;
1711 cist
= GET_CIST_PTP_FROM_PORT(prt
);
1712 if(prt
->operPointToPointMAC
1713 && cmp(b
->cistRootID
, ==, cist
->portPriority
.RootID
)
1714 && cmp(b
->cistExtRootPathCost
, ==, cist
->portPriority
.ExtRootPathCost
)
1715 && cmp(b
->cistRRootID
, ==, cist
->portPriority
.RRootID
)
1716 && (ptp
->rcvdMstiConfig
->flags
& (1 << offsetAgreement
))
1720 ptp
->proposing
= false;
1723 ptp
->agreed
= false;
1726 /* 13.26.8 recordDispute */
1727 static void recordDispute(per_tree_port_t
*ptp
)
1734 /* 802.1Q-2005 is somewhat unclear for the case (!prt->rcvdInternal):
1735 * if we should record dispute for all MSTIs unconditionally
1736 * or only when CIST Learning flag is set in BPDU.
1737 * I guess that in this case MSTIs should be in sync with CIST
1738 * so record dispute for the MSTIs only when the same is done for CIST.
1739 * Additional supporting argument to this guess is that in
1740 * setTcFlags() we do the same.
1741 * But that is only a guess and I could be wrong here ;)
1742 * Maybe 802.1Q-2011 clarifies this, but I don't have the text.
1744 if(prt
->rcvdBpduData
.flags
& (1 << offsetLearnig
))
1746 ptp
->disputed
= true;
1747 ptp
->agreed
= false;
1748 if(!prt
->rcvdInternal
)
1749 list_for_each_entry_continue(ptp
, &prt
->trees
, port_list
)
1751 ptp
->disputed
= true;
1752 ptp
->agreed
= false;
1758 if(ptp
->rcvdMstiConfig
->flags
& (1 << offsetLearnig
))
1760 ptp
->disputed
= true;
1761 ptp
->agreed
= false;
1765 /* 13.26.9 recordMastered */
1766 static void recordMastered(per_tree_port_t
*ptp
)
1768 port_t
*prt
= ptp
->port
;
1772 if(!prt
->rcvdInternal
)
1773 list_for_each_entry_continue(ptp
, &prt
->trees
, port_list
)
1774 ptp
->mastered
= false;
1778 ptp
->mastered
= prt
->operPointToPointMAC
1779 && (ptp
->rcvdMstiConfig
->flags
& (1 << offsetMaster
));
1782 /* 13.26.f) recordPriority */
1783 static void recordPriority(per_tree_port_t
*ptp
)
1785 assign(ptp
->portPriority
, ptp
->msgPriority
);
1788 /* 13.26.10 recordProposal */
1789 static void recordProposal(per_tree_port_t
*ptp
)
1794 /* 802.1Q-2005 says to check if received message conveys
1795 * a Designated Port Role. But there is no need in this check,
1796 * as it is always true. This function is called only in two states:
1797 * PISM_SUPERIOR_DESIGNATED and PISM_REPEATED_DESIGNATED, which
1798 * can be entered only if rcvInfo returns
1799 * SuperiorDesignatedInfo or RepeatedDesignatedInfo.
1800 * Which in turn can only happen if message conveys designated role
1806 if(prt
->rcvdBpduData
.flags
& (1 << offsetProposal
))
1807 ptp
->proposed
= true;
1808 cist_proposed
= ptp
->proposed
;
1809 if(!prt
->rcvdInternal
)
1810 list_for_each_entry_continue(ptp
, &prt
->trees
, port_list
)
1811 ptp
->proposed
= cist_proposed
;
1815 if(ptp
->rcvdMstiConfig
->flags
& (1 << offsetProposal
))
1816 ptp
->proposed
= true;
1819 /* 13.26.11 recordTimes */
1820 static void recordTimes(per_tree_port_t
*ptp
)
1822 assign(ptp
->portTimes
, ptp
->msgTimes
);
1824 if(MIN_COMPAT_HELLO_TIME
> ptp
->portTimes
.Hello_Time
)
1825 ptp
->portTimes
.Hello_Time
= MIN_COMPAT_HELLO_TIME
;
1828 /* 13.24.s) + 17.19.7 of 802.1D : fdbFlush */
1829 static void set_fdbFlush(per_tree_port_t
*ptp
)
1831 port_t
*prt
= ptp
->port
;
1835 ptp
->fdbFlush
= false;
1839 bridge_t
*br
= prt
->bridge
;
1843 ptp
->fdbFlush
= true;
1844 MSTP_OUT_flush_all_fids(ptp
);
1848 per_tree_port_t
*cist
= GET_CIST_PTP_FROM_PORT(prt
);
1849 unsigned int FwdDelay
= cist
->designatedTimes
.Forward_Delay
;
1850 /* Initiate rapid ageing */
1851 MSTP_OUT_set_ageing_time(br
, FwdDelay
);
1852 assign(br
->rapidAgeingWhile
, FwdDelay
);
1853 ptp
->fdbFlush
= false;
1857 /* 13.26.12 setRcvdMsgs */
1858 static void setRcvdMsgs(port_t
*prt
)
1860 msti_configuration_message_t
*msti_msg
;
1864 per_tree_port_t
*ptp
= GET_CIST_PTP_FROM_PORT(prt
);
1865 ptp
->rcvdMsg
= true;
1867 /* 802.1Q-2005 says:
1868 * "Make the received CST or CIST message available to the CIST Port
1869 * Information state machines"
1870 * No need to do something special here, we already have rcvdBpduData.
1873 if(prt
->rcvdInternal
)
1875 list_for_each_entry_continue(ptp
, &prt
->trees
, port_list
)
1878 /* Find if message for this MSTI is conveyed in the BPDU */
1879 for(i
= 0, msti_msg
= prt
->rcvdBpduData
.mstConfiguration
;
1880 i
< prt
->rcvdBpduNumOfMstis
;
1883 msg_MSTID
= msti_msg
->mstiRRootID
.s
.priority
1884 & __constant_cpu_to_be16(0x0FFF);
1885 if(msg_MSTID
== ptp
->MSTID
)
1893 ptp
->rcvdMsg
= true;
1894 /* 802.1Q-2005 says:
1895 * "Make available each MSTI message and the common parts of
1896 * the CIST message priority (the CIST Root Identifier,
1897 * External Root Path Cost and Regional Root Identifier)
1898 * to the Port Information state machine for that MSTI"
1899 * We set pointer to the MSTI configuration message for
1900 * fast access, while do not anything special for common
1901 * parts of the message, as the whole message is available
1904 ptp
->rcvdMstiConfig
= msti_msg
;
1910 /* 13.26.13 setReRootTree */
1911 static void setReRootTree(tree_t
*tree
)
1913 per_tree_port_t
*ptp
;
1915 FOREACH_PTP_IN_TREE(ptp
, tree
)
1919 /* 13.26.14 setSelectedTree */
1920 static void setSelectedTree(tree_t
*tree
)
1922 per_tree_port_t
*ptp
;
1925 * 802.1Q-2005 says that I should check "reselect" var
1926 * and take no action if it is "true" for any of the ports.
1927 * But there is no need in this check as setSelectedTree is called
1928 * only from PRSSM_to_ROLE_SELECTION, which is atomic, and it is called
1929 * in this sequence (13.33):
1930 * clearReselectTree(tree);
1931 * updtRolesTree(tree);
1932 * setSelectedTree(tree);
1933 * And we know that clearReselectTree resets "reselect" for all ports
1934 * and updtRolesTree() does not change value of "reselect".
1936 FOREACH_PTP_IN_TREE(ptp
, tree
)
1937 ptp
->selected
= true;
1940 /* 13.26.15 setSyncTree */
1941 static void setSyncTree(tree_t
*tree
)
1943 per_tree_port_t
*ptp
;
1945 FOREACH_PTP_IN_TREE(ptp
, tree
)
1949 /* 13.26.16 setTcFlags */
1950 static void setTcFlags(per_tree_port_t
*ptp
)
1958 cistFlags
= prt
->rcvdBpduData
.flags
;
1959 if(cistFlags
& (1 << offsetTcAck
))
1960 prt
->rcvdTcAck
= true;
1961 if(cistFlags
& (1 << offsetTc
))
1964 if(!prt
->rcvdInternal
)
1965 list_for_each_entry_continue(ptp
, &prt
->trees
, port_list
)
1966 ptp
->proposed
= true;
1971 if(ptp
->rcvdMstiConfig
->flags
& (1 << offsetTc
))
1975 /* 13.26.17 setTcPropTree */
1976 static void setTcPropTree(per_tree_port_t
*ptp
)
1978 per_tree_port_t
*ptp_1
;
1980 if(ptp
->port
->restrictedTcn
)
1983 FOREACH_PTP_IN_TREE(ptp_1
, ptp
->tree
)
1986 ptp_1
->tcProp
= true;
1990 /* 13.26.18 syncMaster */
1991 static void syncMaster(bridge_t
*br
)
1993 per_tree_port_t
*ptp
;
1994 tree_t
*tree
= GET_CIST_TREE(br
);
1997 list_for_each_entry_continue(tree
, &br
->trees
, bridge_list
)
1999 FOREACH_PTP_IN_TREE(ptp
, tree
)
2001 /* for each Port that has infoInternal set */
2002 if(ptp
->port
->infoInternal
)
2005 ptp
->agreed
= false;
2006 ptp
->synced
= false;
2013 /* 13.26.19 txConfig */
2014 static void txConfig(port_t
*prt
)
2017 per_tree_port_t
*cist
= GET_CIST_PTP_FROM_PORT(prt
);
2019 b
.protocolIdentifier
= 0;
2020 b
.protocolVersion
= protoSTP
;
2021 b
.bpduType
= bpduTypeConfig
;
2022 /* Standard says "tcWhile ... for the Port". Which one tcWhile?
2023 * I guess that this means tcWhile for the CIST.
2024 * But that is only a guess and I could be wrong here ;)
2025 * Maybe 802.1Q-2011 clarifies this, but I don't have the text.
2027 b
.flags
= (0 != cist
->tcWhile
) ? (1 << offsetTc
) : 0;
2029 b
.flags
|= (1 << offsetTcAck
);
2030 assign(b
.cistRootID
, cist
->designatedPriority
.RootID
);
2031 assign(b
.cistExtRootPathCost
, cist
->designatedPriority
.ExtRootPathCost
);
2032 assign(b
.cistRRootID
, cist
->designatedPriority
.DesignatedBridgeID
);
2033 assign(b
.cistPortID
, cist
->designatedPriority
.DesignatedPortID
);
2034 b
.MessageAge
[0] = cist
->designatedTimes
.Message_Age
;
2035 b
.MessageAge
[1] = 0;
2036 b
.MaxAge
[0] = cist
->designatedTimes
.Max_Age
;
2038 b
.HelloTime
[0] = cist
->portTimes
.Hello_Time
; /* ! use portTimes ! */
2040 b
.ForwardDelay
[0] = cist
->designatedTimes
.Forward_Delay
;
2041 b
.ForwardDelay
[1] = 0;
2043 MSTP_OUT_tx_bpdu(prt
, &b
, CONFIG_BPDU_SIZE
);
2046 static inline __u8
message_role_from_port_role(per_tree_port_t
*ptp
)
2051 return encodedRoleRoot
;
2052 case roleDesignated
:
2053 return encodedRoleDesignated
;
2056 return encodedRoleAlternateBackup
;
2058 return encodedRoleMaster
;
2060 ERROR_PRTNAME(ptp
->port
->bridge
, ptp
->port
,
2061 "Attempt to send from port with Disabled role");
2062 return encodedRoleAlternateBackup
;
2066 /* 13.26.20 txMstp */
2067 static void txMstp(port_t
*prt
)
2070 bridge_t
*br
= prt
->bridge
;
2071 per_tree_port_t
*cist
= GET_CIST_PTP_FROM_PORT(prt
);
2072 int msti_msgs_total_size
;
2073 per_tree_port_t
*ptp
;
2074 msti_configuration_message_t
*msti_msg
;
2076 b
.protocolIdentifier
= 0;
2077 b
.bpduType
= bpduTypeRST
;
2078 /* Standard says "{tcWhile, agree, proposing, role} ... for the Port".
2079 * Which one {tcWhile, agree, proposing, role}?
2080 * I guess that this means {tcWhile, agree, proposing, role} for the CIST.
2081 * But that is only a guess and I could be wrong here ;)
2082 * Maybe 802.1Q-2011 clarifies this, but I don't have the text.
2084 b
.flags
= BPDU_FLAGS_ROLE_SET(message_role_from_port_role(cist
));
2085 if(0 != cist
->tcWhile
)
2086 b
.flags
|= (1 << offsetTc
);
2088 b
.flags
|= (1 << offsetProposal
);
2090 b
.flags
|= (1 << offsetLearnig
);
2091 if(cist
->forwarding
)
2092 b
.flags
|= (1 << offsetForwarding
);
2094 b
.flags
|= (1 << offsetAgreement
);
2095 assign(b
.cistRootID
, cist
->designatedPriority
.RootID
);
2096 assign(b
.cistExtRootPathCost
, cist
->designatedPriority
.ExtRootPathCost
);
2097 assign(b
.cistRRootID
, cist
->designatedPriority
.RRootID
);
2098 assign(b
.cistPortID
, cist
->designatedPriority
.DesignatedPortID
);
2099 b
.MessageAge
[0] = cist
->designatedTimes
.Message_Age
;
2100 b
.MessageAge
[1] = 0;
2101 b
.MaxAge
[0] = cist
->designatedTimes
.Max_Age
;
2103 b
.HelloTime
[0] = cist
->portTimes
.Hello_Time
; /* ! use portTimes ! */
2105 b
.ForwardDelay
[0] = cist
->designatedTimes
.Forward_Delay
;
2106 b
.ForwardDelay
[1] = 0;
2110 if(br
->ForceProtocolVersion
< protoMSTP
)
2112 b
.protocolVersion
= protoRSTP
;
2113 MSTP_OUT_tx_bpdu(prt
, &b
, RST_BPDU_SIZE
);
2117 b
.protocolVersion
= protoMSTP
;
2119 /* MST specific fields */
2120 assign(b
.mstConfigurationIdentifier
, br
->MstConfigId
);
2121 assign(b
.cistIntRootPathCost
, cist
->designatedPriority
.IntRootPathCost
);
2122 assign(b
.cistBridgeID
, cist
->designatedPriority
.DesignatedBridgeID
);
2123 assign(b
.cistRemainingHops
, cist
->designatedTimes
.remainingHops
);
2125 msti_msgs_total_size
= 0;
2127 msti_msg
= b
.mstConfiguration
;
2128 /* 13.26.20.f) requires that msti configs should be inserted in
2129 * MSTID order. This is met by inserting trees in port's list of trees
2130 * in sorted (by MSTID) order (see MSTP_IN_create_msti) */
2131 list_for_each_entry_continue(ptp
, &prt
->trees
, port_list
)
2134 BPDU_FLAGS_ROLE_SET(message_role_from_port_role(ptp
));
2135 if(0 != ptp
->tcWhile
)
2136 msti_msg
->flags
|= (1 << offsetTc
);
2138 msti_msg
->flags
|= (1 << offsetProposal
);
2140 msti_msg
->flags
|= (1 << offsetLearnig
);
2142 msti_msg
->flags
|= (1 << offsetForwarding
);
2144 msti_msg
->flags
|= (1 << offsetAgreement
);
2146 msti_msg
->flags
|= (1 << offsetMaster
);
2147 assign(msti_msg
->mstiRRootID
, ptp
->designatedPriority
.RRootID
);
2148 assign(msti_msg
->mstiIntRootPathCost
,
2149 ptp
->designatedPriority
.IntRootPathCost
);
2150 msti_msg
->bridgeIdentifierPriority
=
2151 GET_PRIORITY_FROM_IDENTIFIER(ptp
->designatedPriority
.DesignatedBridgeID
);
2152 msti_msg
->portIdentifierPriority
=
2153 GET_PRIORITY_FROM_IDENTIFIER(ptp
->designatedPriority
.DesignatedPortID
);
2154 assign(msti_msg
->remainingHops
, ptp
->designatedTimes
.remainingHops
);
2156 msti_msgs_total_size
+= sizeof(msti_configuration_message_t
);
2160 assign(b
.version3_len
, __cpu_to_be16(MST_BPDU_VER3LEN_WO_MSTI_MSGS
2161 + msti_msgs_total_size
));
2162 MSTP_OUT_tx_bpdu(prt
, &b
, MST_BPDU_SIZE_WO_MSTI_MSGS
2163 + msti_msgs_total_size
);
2166 /* 13.26.a) txTcn */
2167 static void txTcn(port_t
*prt
)
2171 b
.protocolIdentifier
= 0;
2172 b
.protocolVersion
= protoSTP
;
2173 b
.bpduType
= bpduTypeTCN
;
2175 MSTP_OUT_tx_bpdu(prt
, &b
, TCN_BPDU_SIZE
);
2178 /* 13.26.21 updtBPDUVersion */
2179 static void updtBPDUVersion(port_t
*prt
)
2181 if(protoRSTP
<= prt
->rcvdBpduData
.protocolVersion
)
2182 prt
->rcvdRSTP
= true;
2184 prt
->rcvdSTP
= true;
2187 /* 13.26.22 updtRcvdInfoWhile */
2188 static void updtRcvdInfoWhile(per_tree_port_t
*ptp
)
2190 port_t
*prt
= ptp
->port
;
2191 per_tree_port_t
*cist
= GET_CIST_PTP_FROM_PORT(prt
);
2192 unsigned int Message_Age
= cist
->portTimes
.Message_Age
;
2193 unsigned int Max_Age
= cist
->portTimes
.Max_Age
;
2194 unsigned int Hello_Time
= cist
->portTimes
.Hello_Time
;
2196 if((!prt
->rcvdInternal
&& ((Message_Age
+ 1) <= Max_Age
))
2197 || (prt
->rcvdInternal
&& (cist
->portTimes
.remainingHops
> 1))
2199 ptp
->rcvdInfoWhile
= 3 * Hello_Time
;
2201 ptp
->rcvdInfoWhile
= 0;
2204 /* 13.26.24 updtRolesDisabledTree */
2205 static void updtRolesDisabledTree(tree_t
*tree
)
2207 per_tree_port_t
*ptp
;
2209 FOREACH_PTP_IN_TREE(ptp
, tree
)
2210 ptp
->selectedRole
= roleDisabled
;
2213 /* 13.26.23 updtRolesTree */
2214 static void updtRolesTree(tree_t
*tree
)
2216 per_tree_port_t
*ptp
, *root_ptp
= NULL
;
2217 port_priority_vector_t root_path_priority
;
2218 bridge_identifier_t prevRRootID
= tree
->rootPriority
.RRootID
;
2219 __be32 prevExtRootPathCost
= tree
->rootPriority
.ExtRootPathCost
;
2220 bool cist
= (0 == tree
->MSTID
);
2221 times_t
*timesOfRootPort
;
2223 /* a), b) Select new root priority vector = {rootPriority, rootPortId} */
2224 /* Initial value = bridge priority vector = {BridgePriority, 0} */
2225 assign(tree
->rootPriority
, tree
->BridgePriority
);
2226 assign(tree
->rootPortId
, __constant_cpu_to_be16(0));
2227 /* Now check root path priority vectors of all ports in tree and see if
2228 * there is a better vector */
2229 FOREACH_PTP_IN_TREE(ptp
, tree
)
2231 port_t
*prt
= ptp
->port
;
2232 /* 802.1Q says to calculate root priority vector only if port
2233 * is not Disabled, but check (infoIs == ioReceived) covers
2234 * the case (infoIs != ioDisabled).
2236 if((ioReceived
== ptp
->infoIs
) && !prt
->restrictedRole
2237 && cmp(ptp
->portPriority
.DesignatedBridgeID
, !=,
2238 tree
->BridgeIdentifier
)
2241 root_path_priority
= ptp
->portPriority
;
2242 if(prt
->rcvdInternal
)
2244 assign(root_path_priority
.IntRootPathCost
,
2245 __cpu_to_be32(__be32_to_cpu(root_path_priority
.IntRootPathCost
)
2246 + ptp
->InternalPortPathCost
)
2251 assign(root_path_priority
.ExtRootPathCost
,
2252 __cpu_to_be32(__be32_to_cpu(root_path_priority
.ExtRootPathCost
)
2253 + prt
->ExternalPortPathCost
)
2255 assign(root_path_priority
.IntRootPathCost
,
2256 __constant_cpu_to_be32(0));
2258 if(betterorsamePriority(&root_path_priority
, &tree
->rootPriority
,
2259 ptp
->portId
, tree
->rootPortId
, cist
))
2261 assign(tree
->rootPriority
, root_path_priority
);
2262 assign(tree
->rootPortId
, ptp
->portId
);
2268 /* 802.1q-2005 says, that at some point we need compare portTimes with
2269 * "... one for the Root Port ...". Bad IEEE! Why not mention explicit
2270 * var names??? (see 13.26.23.g) for instance)
2271 * So, now I should guess what will work for the timesOfRootPort.
2272 * Below is the result of my guess. I could be wrong, of course:
2273 * timesOfRootPort = root_ptp ? &root_ptp->portTimes
2274 * : &tree->BridgeTimes;
2275 * NOTE: Both Alex Rozin (author of rstplib) and Srinivas Aji (author
2276 * of rstpd) compare portTimes with designatedTimes instead of
2277 * timesOfRootPort. This differs from my interpretation of the standard
2278 * because designatedTimes have incremented Message_Age (or decremented
2279 * remainingHops if rcvdInternal).
2282 /* c) Set new rootTimes */
2285 assign(tree
->rootTimes
, root_ptp
->portTimes
);
2286 port_t
*prt
= root_ptp
->port
;
2287 if(prt
->rcvdInternal
)
2289 if(tree
->rootTimes
.remainingHops
)
2290 --(tree
->rootTimes
.remainingHops
);
2293 ++(tree
->rootTimes
.Message_Age
);
2294 timesOfRootPort
= &root_ptp
->portTimes
;
2298 assign(tree
->rootTimes
, tree
->BridgeTimes
);
2299 timesOfRootPort
= &tree
->BridgeTimes
;
2302 FOREACH_PTP_IN_TREE(ptp
, tree
)
2304 port_t
*prt
= ptp
->port
;
2306 /* d) Set new designatedPriority */
2307 assign(ptp
->designatedPriority
, tree
->rootPriority
);
2308 assign(ptp
->designatedPriority
.DesignatedBridgeID
,
2309 tree
->BridgeIdentifier
);
2310 assign(ptp
->designatedPriority
.DesignatedPortID
, ptp
->portId
);
2311 /* I am not sure which condition to check here, as 802.1Q-2005 says:
2312 * "... If {Port} is attached to a LAN that has one or more STP Bridges
2313 * attached (as determined by the Port Protocol Migration state
2314 * machine) ..." -- why not to mention explicit var name? Bad IEEE.
2315 * But I guess that sendSTP (i.e. !sendRSTP) var will do ;)
2317 if(cist
&& !prt
->sendRSTP
)
2318 assign(ptp
->designatedPriority
.RRootID
, tree
->BridgeIdentifier
);
2320 /* e) Set new designatedTimes */
2321 assign(ptp
->designatedTimes
, tree
->rootTimes
);
2325 if(cist
&& cmp(tree
->rootPriority
.RRootID
, !=, prevRRootID
)
2326 && ((0 != tree
->rootPriority
.ExtRootPathCost
)
2327 || (0 != prevExtRootPathCost
)
2330 syncMaster(tree
->bridge
);
2332 FOREACH_PTP_IN_TREE(ptp
, tree
)
2334 port_t
*prt
= ptp
->port
;
2336 /* f) Set Disabled role */
2337 if(ioDisabled
== ptp
->infoIs
)
2339 ptp
->selectedRole
= roleDisabled
;
2343 if(!cist
&& (ioReceived
== ptp
->infoIs
)
2344 && !prt
->infoInternal
)
2346 /* g) Set role for the boundary port in MSTI */
2347 per_tree_port_t
*cist_tree
= GET_CIST_PTP_FROM_PORT(prt
);
2348 if(roleRoot
== cist_tree
->selectedRole
)
2350 ptp
->selectedRole
= roleMaster
;
2351 if(!samePriorityAndTimers(&ptp
->portPriority
,
2352 &ptp
->designatedPriority
,
2356 ptp
->updtInfo
= true;
2359 if(roleAlternate
== cist_tree
->selectedRole
)
2361 ptp
->selectedRole
= roleAlternate
;
2362 if(!samePriorityAndTimers(&ptp
->portPriority
,
2363 &ptp
->designatedPriority
,
2367 ptp
->updtInfo
= true;
2371 else /* if(cist || (ioReceived != ptp->infoIs) || prt->infoInternal) */
2373 /* h) Set role for the aged info */
2374 if(ioAged
== ptp
->infoIs
)
2376 ptp
->selectedRole
= roleDesignated
;
2377 ptp
->updtInfo
= true;
2380 /* i) Set role for the mine info */
2381 if(ioMine
== ptp
->infoIs
)
2383 ptp
->selectedRole
= roleDesignated
;
2384 if(!samePriorityAndTimers(&ptp
->portPriority
,
2385 &ptp
->designatedPriority
,
2389 ptp
->updtInfo
= true;
2392 if(ioReceived
== ptp
->infoIs
)
2394 /* j) Set Root role */
2397 ptp
->selectedRole
= roleRoot
;
2398 ptp
->updtInfo
= false;
2401 if(betterorsamePriority(&ptp
->portPriority
,
2402 &ptp
->designatedPriority
,
2405 if(cmp(ptp
->portPriority
.DesignatedBridgeID
, !=,
2406 tree
->BridgeIdentifier
))
2408 /* k) Set Alternate role */
2409 ptp
->selectedRole
= roleAlternate
;
2413 /* l) Set Backup role */
2414 ptp
->selectedRole
= roleBackup
;
2416 /* reset updtInfo for both k) and l) */
2417 ptp
->updtInfo
= false;
2420 else /* designatedPriority is better than portPriority */
2422 /* m) Set Designated role */
2423 ptp
->selectedRole
= roleDesignated
;
2424 ptp
->updtInfo
= true;
2432 /* 13.27 The Port Timers state machine */
2434 static void PTSM_tick(port_t
*prt
)
2436 per_tree_port_t
*ptp
;
2440 if(prt
->mdelayWhile
)
2441 --(prt
->mdelayWhile
);
2442 if(prt
->edgeDelayWhile
)
2443 --(prt
->edgeDelayWhile
);
2447 FOREACH_PTP_IN_PORT(ptp
, prt
)
2457 if(0 == --(ptp
->tcWhile
))
2458 set_TopologyChange(ptp
->tree
, false);
2460 if(ptp
->rcvdInfoWhile
)
2461 --(ptp
->rcvdInfoWhile
);
2465 /* 13.28 Port Receive state machine */
2466 #define PRSM_begin(prt) PRSM_to_DISCARD(prt)
2467 static void PRSM_to_DISCARD(port_t
*prt
/*, bool begin*/)
2469 prt
->PRSM_state
= PRSM_DISCARD
;
2471 prt
->rcvdBpdu
= false;
2472 prt
->rcvdRSTP
= false;
2473 prt
->rcvdSTP
= false;
2474 clearAllRcvdMsgs(prt
);
2475 assign(prt
->edgeDelayWhile
, prt
->bridge
->Migrate_Time
);
2477 /* No need to run, no one condition will be met
2482 static void PRSM_to_RECEIVE(port_t
*prt
)
2484 prt
->PRSM_state
= PRSM_RECEIVE
;
2486 updtBPDUVersion(prt
);
2487 prt
->rcvdInternal
= fromSameRegion(prt
);
2489 prt
->operEdge
= false;
2490 prt
->rcvdBpdu
= false;
2491 assign(prt
->edgeDelayWhile
, prt
->bridge
->Migrate_Time
);
2493 /* No need to run, no one condition will be met
2497 static void PRSM_run(port_t
*prt
)
2499 per_tree_port_t
*ptp
;
2502 if((prt
->rcvdBpdu
|| (prt
->edgeDelayWhile
!= prt
->bridge
->Migrate_Time
))
2503 && !prt
->portEnabled
)
2505 PRSM_to_DISCARD(prt
);
2509 switch(prt
->PRSM_state
)
2512 if(prt
->rcvdBpdu
&& prt
->portEnabled
)
2513 PRSM_to_RECEIVE(prt
);
2517 FOREACH_PTP_IN_PORT(ptp
, prt
)
2525 if(prt
->rcvdBpdu
&& prt
->portEnabled
&& !rcvdAnyMsg
)
2526 PRSM_to_RECEIVE(prt
);
2531 /* 13.29 Port Protocol Migration state machine */
2533 static void PPMSM_run(port_t
*prt
);
2534 #define PPMSM_begin(prt) PPMSM_to_CHECKING_RSTP(prt)
2536 static void PPMSM_to_CHECKING_RSTP(port_t
*prt
/*, bool begin*/)
2538 prt
->PPMSM_state
= PPMSM_CHECKING_RSTP
;
2540 bridge_t
*br
= prt
->bridge
;
2541 prt
->mcheck
= false;
2542 prt
->sendRSTP
= rstpVersion(br
);
2543 assign(prt
->mdelayWhile
, br
->Migrate_Time
);
2545 /* No need to run, no one condition will be met
2547 * PPMSM_run(prt); */
2550 static void PPMSM_to_SELECTING_STP(port_t
*prt
)
2552 prt
->PPMSM_state
= PPMSM_SELECTING_STP
;
2554 prt
->sendRSTP
= false;
2555 assign(prt
->mdelayWhile
, prt
->bridge
->Migrate_Time
);
2560 static void PPMSM_to_SENSING(port_t
*prt
)
2562 prt
->PPMSM_state
= PPMSM_SENSING
;
2564 prt
->rcvdRSTP
= false;
2565 prt
->rcvdSTP
= false;
2570 static void PPMSM_run(port_t
*prt
)
2572 bridge_t
*br
= prt
->bridge
;
2574 switch(prt
->PPMSM_state
)
2576 case PPMSM_CHECKING_RSTP
:
2577 if((prt
->mdelayWhile
!= br
->Migrate_Time
)
2578 && !prt
->portEnabled
)
2580 PPMSM_to_CHECKING_RSTP(prt
);
2583 if(0 == prt
->mdelayWhile
)
2584 PPMSM_to_SENSING(prt
);
2586 case PPMSM_SELECTING_STP
:
2587 if(0 == prt
->mdelayWhile
|| !prt
->portEnabled
|| prt
->mcheck
)
2588 PPMSM_to_SENSING(prt
);
2591 if(!prt
->portEnabled
|| prt
->mcheck
2592 || (rstpVersion(br
) && !prt
->sendRSTP
&& prt
->rcvdRSTP
))
2594 PPMSM_to_CHECKING_RSTP(prt
);
2597 if(prt
->sendRSTP
&& prt
->rcvdSTP
)
2598 PPMSM_to_SELECTING_STP(prt
);
2603 /* 13.30 Bridge Detection state machine */
2604 static void BDSM_to_EDGE(port_t
*prt
/*, bool begin*/)
2606 prt
->BDSM_state
= BDSM_EDGE
;
2608 prt
->operEdge
= true;
2610 /* No need to run, no one condition will be met
2615 static void BDSM_to_NOT_EDGE(port_t
*prt
/*, bool begin*/)
2617 prt
->BDSM_state
= BDSM_NOT_EDGE
;
2619 prt
->operEdge
= false;
2621 /* No need to run, no one condition will be met
2626 static void BDSM_begin(port_t
*prt
/*, bool begin*/)
2628 if(prt
->AdminEdgePort
)
2629 BDSM_to_EDGE(prt
/*, begin*/);
2631 BDSM_to_NOT_EDGE(prt
/*, begin*/);
2634 static void BDSM_run(port_t
*prt
)
2636 per_tree_port_t
*cist
;
2638 switch(prt
->BDSM_state
)
2641 if((!prt
->portEnabled
&& !prt
->AdminEdgePort
) || !prt
->operEdge
)
2642 BDSM_to_NOT_EDGE(prt
);
2645 cist
= GET_CIST_PTP_FROM_PORT(prt
);
2646 /* NOTE: 802.1Q-2005 is not clear, which of the per-tree
2647 * "proposing" flags to use here, or one should combine
2648 * them all for all trees? Maybe 802.1Q-2011 clarifies
2649 * this, but I don't have the text.
2650 * So, I decide that it will be the "proposing" flag
2651 * from CIST tree - it seems like a good bet.
2653 if((!prt
->portEnabled
&& prt
->AdminEdgePort
)
2654 || ((0 == prt
->edgeDelayWhile
) && prt
->AutoEdge
&& prt
->sendRSTP
2662 /* 13.31 Port Transmit state machine */
2664 static void PTSM_run(port_t
*prt
);
2665 #define PTSM_begin(prt) PTSM_to_TRANSMIT_INIT((prt), true)
2667 static void PTSM_to_TRANSMIT_INIT(port_t
*prt
, bool begin
)
2669 prt
->PTSM_state
= PTSM_TRANSMIT_INIT
;
2671 prt
->newInfo
= true;
2672 prt
->newInfoMsti
= true;
2673 assign(prt
->txCount
, 0u);
2675 if(!begin
&& prt
->portEnabled
) /* prevent infinite loop */
2679 static void PTSM_to_TRANSMIT_CONFIG(port_t
*prt
)
2681 prt
->PTSM_state
= PTSM_TRANSMIT_CONFIG
;
2683 prt
->newInfo
= false;
2691 static void PTSM_to_TRANSMIT_TCN(port_t
*prt
)
2693 prt
->PTSM_state
= PTSM_TRANSMIT_TCN
;
2695 prt
->newInfo
= false;
2702 static void PTSM_to_TRANSMIT_RSTP(port_t
*prt
)
2704 prt
->PTSM_state
= PTSM_TRANSMIT_RSTP
;
2706 prt
->newInfo
= false;
2707 prt
->newInfoMsti
= false;
2715 static void PTSM_to_TRANSMIT_PERIODIC(port_t
*prt
)
2717 prt
->PTSM_state
= PTSM_TRANSMIT_PERIODIC
;
2719 per_tree_port_t
*ptp
= GET_CIST_PTP_FROM_PORT(prt
);
2720 bool cistDesignatedOrTCpropagatingRootPort
=
2721 (roleDesignated
== ptp
->role
)
2722 || ((roleRoot
== ptp
->role
) && (0 != ptp
->tcWhile
));
2723 bool mstiDesignatedOrTCpropagatingRootPort
;
2725 mstiDesignatedOrTCpropagatingRootPort
= false;
2726 list_for_each_entry_continue(ptp
, &prt
->trees
, port_list
)
2728 if((roleDesignated
== ptp
->role
)
2729 || ((roleRoot
== ptp
->role
) && (0 != ptp
->tcWhile
))
2732 mstiDesignatedOrTCpropagatingRootPort
= true;
2737 prt
->newInfo
= prt
->newInfo
|| cistDesignatedOrTCpropagatingRootPort
;
2738 prt
->newInfoMsti
= prt
->newInfoMsti
2739 || mstiDesignatedOrTCpropagatingRootPort
;
2744 static void PTSM_to_IDLE(port_t
*prt
)
2746 prt
->PTSM_state
= PTSM_IDLE
;
2748 per_tree_port_t
*cist
= GET_CIST_PTP_FROM_PORT(prt
);
2749 prt
->helloWhen
= cist
->portTimes
.Hello_Time
;
2754 static void PTSM_run(port_t
*prt
)
2756 /* bool allTransmitReady; */
2757 per_tree_port_t
*ptp
;
2758 port_role_t cistRole
;
2759 bool mstiMasterPort
;
2761 if(!prt
->portEnabled
)
2763 PTSM_to_TRANSMIT_INIT(prt
, false);
2767 switch(prt
->PTSM_state
)
2769 case PTSM_TRANSMIT_INIT
:
2771 case PTSM_TRANSMIT_CONFIG
:
2773 case PTSM_TRANSMIT_TCN
:
2775 case PTSM_TRANSMIT_RSTP
:
2777 case PTSM_TRANSMIT_PERIODIC
:
2778 PTSM_to_IDLE(prt
); /* UnConditional Transition */
2781 /* allTransmitReady = true; */
2782 ptp
= GET_CIST_PTP_FROM_PORT(prt
);
2783 if(!ptp
->selected
|| ptp
->updtInfo
)
2785 /* allTransmitReady = false; */
2788 cistRole
= ptp
->role
;
2789 mstiMasterPort
= false;
2790 list_for_each_entry_continue(ptp
, &prt
->trees
, port_list
)
2792 if(!ptp
->selected
|| ptp
->updtInfo
)
2794 /* allTransmitReady = false; */
2797 if(roleMaster
== ptp
->role
)
2798 mstiMasterPort
= true;
2800 if(0 == prt
->helloWhen
)
2802 PTSM_to_TRANSMIT_PERIODIC(prt
);
2805 if(!(prt
->txCount
< prt
->bridge
->Transmit_Hold_Count
))
2808 { /* implement MSTP */
2809 if(prt
->newInfo
|| (prt
->newInfoMsti
&& !mstiMasterPort
))
2811 PTSM_to_TRANSMIT_RSTP(prt
);
2816 { /* fallback to STP */
2817 if(prt
->newInfo
&& (roleDesignated
== cistRole
))
2819 PTSM_to_TRANSMIT_CONFIG(prt
);
2822 if(prt
->newInfo
&& (roleRoot
== cistRole
))
2824 PTSM_to_TRANSMIT_TCN(prt
);
2832 /* 13.32 Port Information state machine */
2834 #ifdef PISM_ENABLE_LOG
2835 #define PISM_LOG(_fmt, _args...) SMLOG_MSTINAME(ptp, _fmt, ##_args)
2837 #define PISM_LOG(_fmt, _args...) {}
2838 #endif /* PISM_ENABLE_LOG */
2840 static void PISM_run(per_tree_port_t
*ptp
);
2841 #define PISM_begin(ptp) PISM_to_DISABLED((ptp), true)
2843 static void PISM_to_DISABLED(per_tree_port_t
*ptp
, bool begin
)
2846 ptp
->PISM_state
= PISM_DISABLED
;
2848 ptp
->rcvdMsg
= false;
2849 ptp
->proposing
= false;
2850 ptp
->proposed
= false;
2852 ptp
->agreed
= false;
2853 assign(ptp
->rcvdInfoWhile
, 0u);
2854 ptp
->infoIs
= ioDisabled
;
2855 ptp
->reselect
= true;
2856 ptp
->selected
= false;
2862 static void PISM_to_AGED(per_tree_port_t
*ptp
)
2865 ptp
->PISM_state
= PISM_AGED
;
2867 ptp
->infoIs
= ioAged
;
2868 ptp
->reselect
= true;
2869 ptp
->selected
= false;
2874 static void PISM_to_UPDATE(per_tree_port_t
*ptp
)
2877 ptp
->PISM_state
= PISM_UPDATE
;
2879 ptp
->proposing
= false;
2880 ptp
->proposed
= false;
2881 ptp
->agreed
= ptp
->agreed
&& betterorsameInfo(ptp
, ioMine
);
2882 ptp
->synced
= ptp
->synced
&& ptp
->agreed
;
2883 assign(ptp
->portPriority
, ptp
->designatedPriority
);
2884 assign(ptp
->portTimes
, ptp
->designatedTimes
);
2885 ptp
->updtInfo
= false;
2886 ptp
->infoIs
= ioMine
;
2887 /* newInfoXst = TRUE; */
2888 port_t
*prt
= ptp
->port
;
2890 prt
->newInfo
= true;
2892 prt
->newInfoMsti
= true;
2897 static void PISM_to_SUPERIOR_DESIGNATED(per_tree_port_t
*ptp
)
2900 ptp
->PISM_state
= PISM_SUPERIOR_DESIGNATED
;
2902 port_t
*prt
= ptp
->port
;
2904 prt
->infoInternal
= prt
->rcvdInternal
;
2905 ptp
->agreed
= false;
2906 ptp
->proposing
= false;
2907 recordProposal(ptp
);
2909 ptp
->agree
= ptp
->agree
&& betterorsameInfo(ptp
, ioReceived
);
2910 recordAgreement(ptp
);
2911 ptp
->synced
= ptp
->synced
&& ptp
->agreed
;
2912 recordPriority(ptp
);
2914 updtRcvdInfoWhile(ptp
);
2915 ptp
->infoIs
= ioReceived
;
2916 ptp
->reselect
= true;
2917 ptp
->selected
= false;
2918 ptp
->rcvdMsg
= false;
2923 static void PISM_to_REPEATED_DESIGNATED(per_tree_port_t
*ptp
)
2926 ptp
->PISM_state
= PISM_REPEATED_DESIGNATED
;
2928 port_t
*prt
= ptp
->port
;
2930 prt
->infoInternal
= prt
->rcvdInternal
;
2931 recordProposal(ptp
);
2933 recordAgreement(ptp
);
2934 updtRcvdInfoWhile(ptp
);
2935 ptp
->rcvdMsg
= false;
2940 static void PISM_to_INFERIOR_DESIGNATED(per_tree_port_t
*ptp
)
2943 ptp
->PISM_state
= PISM_INFERIOR_DESIGNATED
;
2946 ptp
->rcvdMsg
= false;
2951 static void PISM_to_NOT_DESIGNATED(per_tree_port_t
*ptp
)
2954 ptp
->PISM_state
= PISM_NOT_DESIGNATED
;
2956 recordAgreement(ptp
);
2958 ptp
->rcvdMsg
= false;
2963 static void PISM_to_OTHER(per_tree_port_t
*ptp
)
2966 ptp
->PISM_state
= PISM_OTHER
;
2968 ptp
->rcvdMsg
= false;
2973 static void PISM_to_CURRENT(per_tree_port_t
*ptp
)
2976 ptp
->PISM_state
= PISM_CURRENT
;
2981 static void PISM_to_RECEIVE(per_tree_port_t
*ptp
)
2984 ptp
->PISM_state
= PISM_RECEIVE
;
2986 ptp
->rcvdInfo
= rcvInfo(ptp
);
2987 recordMastered(ptp
);
2992 static void PISM_run(per_tree_port_t
*ptp
)
2994 bool rcvdXstMsg
, updtXstInfo
;
2995 port_t
*prt
= ptp
->port
;
2997 if((!prt
->portEnabled
) && (ioDisabled
!= ptp
->infoIs
))
2999 PISM_to_DISABLED(ptp
, false);
3003 switch(ptp
->PISM_state
)
3006 if(prt
->portEnabled
)
3012 PISM_to_DISABLED(ptp
, false);
3015 if(ptp
->selected
&& ptp
->updtInfo
)
3016 PISM_to_UPDATE(ptp
);
3020 case PISM_SUPERIOR_DESIGNATED
:
3022 case PISM_REPEATED_DESIGNATED
:
3024 case PISM_INFERIOR_DESIGNATED
:
3026 case PISM_NOT_DESIGNATED
:
3029 PISM_to_CURRENT(ptp
);
3033 * Although 802.1Q-2005 does not define rcvdXstMsg and updtXstInfo
3034 * from 802.1s we can conclude that they are:
3035 * - rcvdXstMsg = rcvdCistMsg, if tree is CIST
3036 * rcvdMstiMsg, if tree is MSTI.
3037 * - updtXstInfo = updtCistInfo, if tree is CIST
3038 * updtMstiInfo, if tree is MSTI.
3042 rcvdXstMsg
= ptp
->rcvdMsg
; /* 13.25.12 */
3043 updtXstInfo
= ptp
->updtInfo
; /* 13.25.16 */
3047 per_tree_port_t
*cist
= GET_CIST_PTP_FROM_PORT(prt
);
3048 rcvdXstMsg
= !cist
->rcvdMsg
&& ptp
->rcvdMsg
; /* 13.25.13 */
3049 updtXstInfo
= ptp
->updtInfo
|| cist
->updtInfo
; /* 13.25.17 */
3051 if(rcvdXstMsg
&& !updtXstInfo
)
3053 PISM_to_RECEIVE(ptp
);
3056 if((ioReceived
== ptp
->infoIs
) && (0 == ptp
->rcvdInfoWhile
)
3057 && !ptp
->updtInfo
&& !rcvdXstMsg
)
3062 if(ptp
->selected
&& ptp
->updtInfo
)
3063 PISM_to_UPDATE(ptp
);
3066 switch(ptp
->rcvdInfo
)
3068 case SuperiorDesignatedInfo
:
3069 PISM_to_SUPERIOR_DESIGNATED(ptp
);
3071 case RepeatedDesignatedInfo
:
3072 PISM_to_REPEATED_DESIGNATED(ptp
);
3074 case InferiorDesignatedInfo
:
3075 PISM_to_INFERIOR_DESIGNATED(ptp
);
3077 case InferiorRootAlternateInfo
:
3078 PISM_to_NOT_DESIGNATED(ptp
);
3088 /* 13.33 Port Role Selection state machine */
3090 static void PRSSM_run(tree_t
*tree
);
3091 #define PRSSM_begin(tree) PRSSM_to_INIT_TREE(tree)
3093 static void PRSSM_to_INIT_TREE(tree_t
*tree
/*, bool begin*/)
3095 tree
->PRSSM_state
= PRSSM_INIT_TREE
;
3097 updtRolesDisabledTree(tree
);
3099 /* No need to check, as we assume begin = true here
3100 * because transition to this state can be initiated only by BEGIN var.
3101 * In other words, this function is called via xxx_begin macro only.
3103 * PRSSM_run(prt); */
3106 static void PRSSM_to_ROLE_SELECTION(tree_t
*tree
)
3108 tree
->PRSSM_state
= PRSSM_ROLE_SELECTION
;
3110 clearReselectTree(tree
);
3111 updtRolesTree(tree
);
3112 setSelectedTree(tree
);
3114 /* No need to run, no one condition will be met
3118 static void PRSSM_run(tree_t
*tree
)
3120 per_tree_port_t
*ptp
;
3122 switch(tree
->PRSSM_state
)
3124 case PRSSM_INIT_TREE
:
3125 PRSSM_to_ROLE_SELECTION(tree
);
3127 case PRSSM_ROLE_SELECTION
:
3128 FOREACH_PTP_IN_TREE(ptp
, tree
)
3131 PRSSM_to_ROLE_SELECTION(tree
);
3138 /* 13.34 Port Role Transitions state machine */
3140 #ifdef PRTSM_ENABLE_LOG
3141 #define PRTSM_LOG(_fmt, _args...) SMLOG_MSTINAME(ptp, _fmt, ##_args)
3143 #define PRTSM_LOG(_fmt, _args...) {}
3144 #endif /* PRTSM_ENABLE_LOG */
3146 static void PRTSM_runr(per_tree_port_t
*ptp
, bool recursive_call
);
3147 #define PRTSM_run(ptp) PRTSM_runr((ptp), false)
3148 #define PRTSM_begin(ptp) PRTSM_to_INIT_PORT(ptp)
3150 /* Disabled Port role transitions */
3152 static void PRTSM_to_INIT_PORT(per_tree_port_t
*ptp
/*, bool begin*/)
3155 ptp
->PRTSM_state
= PRTSM_INIT_PORT
;
3157 unsigned int MaxAge
, FwdDelay
;
3158 per_tree_port_t
*cist
= GET_CIST_PTP_FROM_PORT(ptp
->port
);
3160 ptp
->role
= roleDisabled
;
3162 ptp
->forward
= false;
3163 ptp
->synced
= false;
3167 FwdDelay
= cist
->designatedTimes
.Forward_Delay
;
3168 assign(ptp
->rrWhile
, FwdDelay
);
3170 MaxAge
= cist
->designatedTimes
.Max_Age
;
3171 assign(ptp
->fdWhile
, MaxAge
);
3172 assign(ptp
->rbWhile
, 0u);
3174 /* No need to check, as we assume begin = true here
3175 * because transition to this state can be initiated only by BEGIN var.
3176 * In other words, this function is called via xxx_begin macro only.
3178 * PRTSM_runr(ptp, false); */
3181 static void PRTSM_to_DISABLE_PORT(per_tree_port_t
*ptp
)
3184 ptp
->PRTSM_state
= PRTSM_DISABLE_PORT
;
3186 /* Although 802.1Q-2005 says here to do role = selectedRole
3187 * I have difficulties with it in the next scenario:
3188 * 1) port was designated (role == selectedRole == roleDesignated)
3189 * 2) some config event occurs, e.g. MAC address changes and
3190 * br_state_machines_begin is called
3191 * 3) role == selectedRole == roleDisabled, PRTSM_state = PRTSM_INIT_PORT
3192 * Because port was not actually down, on the next run
3193 * Port Role Selection state machine sets selectedRole = roleDesignated
3194 * and updtInfo = true:
3195 * 4) we have unconditional transition to DISABLE_PORT, and because
3196 * updtInfo = true we can not follow transition to DESIGNATED_PORT
3197 * 5) if we follow standard, role = selectedRole = roleDesignated and
3198 * on the next run we have transition to the DISABLED_PORT
3199 * And there we stuck. role == selectedRole, so we can not transit to
3200 * DESIGNATED_PORT (it requires role != selectedRole ).
3202 * Solution: do not follow the standard, and do role = roleDisabled
3203 * instead of role = selectedRole.
3205 ptp
->role
= roleDisabled
;
3207 ptp
->forward
= false;
3209 PRTSM_runr(ptp
, true);
3212 static void PRTSM_to_DISABLED_PORT(per_tree_port_t
*ptp
, unsigned int MaxAge
)
3215 ptp
->PRTSM_state
= PRTSM_DISABLED_PORT
;
3217 assign(ptp
->fdWhile
, MaxAge
);
3219 assign(ptp
->rrWhile
, 0u);
3221 ptp
->reRoot
= false;
3223 PRTSM_runr(ptp
, true);
3226 /* MasterPort role transitions */
3228 static void PRTSM_to_MASTER_PROPOSED(per_tree_port_t
*ptp
)
3231 ptp
->PRTSM_state
= PRTSM_MASTER_PROPOSED
;
3233 setSyncTree(ptp
->tree
);
3234 ptp
->proposed
= false;
3236 PRTSM_runr(ptp
, true);
3239 static void PRTSM_to_MASTER_AGREED(per_tree_port_t
*ptp
)
3242 ptp
->PRTSM_state
= PRTSM_MASTER_AGREED
;
3244 ptp
->proposed
= false;
3248 PRTSM_runr(ptp
, true);
3251 static void PRTSM_to_MASTER_SYNCED(per_tree_port_t
*ptp
)
3254 ptp
->PRTSM_state
= PRTSM_MASTER_SYNCED
;
3256 assign(ptp
->rrWhile
, 0u);
3260 PRTSM_runr(ptp
, true);
3263 static void PRTSM_to_MASTER_RETIRED(per_tree_port_t
*ptp
)
3266 ptp
->PRTSM_state
= PRTSM_MASTER_RETIRED
;
3268 ptp
->reRoot
= false;
3270 PRTSM_runr(ptp
, true);
3273 static void PRTSM_to_MASTER_FORWARD(per_tree_port_t
*ptp
)
3276 ptp
->PRTSM_state
= PRTSM_MASTER_FORWARD
;
3278 ptp
->forward
= true;
3279 assign(ptp
->fdWhile
, 0u);
3280 ptp
->agreed
= ptp
->port
->sendRSTP
;
3282 PRTSM_runr(ptp
, true);
3285 static void PRTSM_to_MASTER_LEARN(per_tree_port_t
*ptp
, unsigned int forwardDelay
)
3288 ptp
->PRTSM_state
= PRTSM_MASTER_LEARN
;
3291 assign(ptp
->fdWhile
, forwardDelay
);
3293 PRTSM_runr(ptp
, true);
3296 static void PRTSM_to_MASTER_DISCARD(per_tree_port_t
*ptp
, unsigned int forwardDelay
)
3299 ptp
->PRTSM_state
= PRTSM_MASTER_DISCARD
;
3302 ptp
->forward
= false;
3303 ptp
->disputed
= false;
3304 assign(ptp
->fdWhile
, forwardDelay
);
3306 PRTSM_runr(ptp
, true);
3309 static void PRTSM_to_MASTER_PORT(per_tree_port_t
*ptp
)
3312 ptp
->PRTSM_state
= PRTSM_MASTER_PORT
;
3314 ptp
->role
= roleMaster
;
3316 PRTSM_runr(ptp
, true);
3319 /* RootPort role transitions */
3321 static void PRTSM_to_ROOT_PROPOSED(per_tree_port_t
*ptp
)
3324 ptp
->PRTSM_state
= PRTSM_ROOT_PROPOSED
;
3326 setSyncTree(ptp
->tree
);
3327 ptp
->proposed
= false;
3329 PRTSM_runr(ptp
, true);
3332 static void PRTSM_to_ROOT_AGREED(per_tree_port_t
*ptp
)
3335 ptp
->PRTSM_state
= PRTSM_ROOT_AGREED
;
3337 ptp
->proposed
= false;
3340 /* newInfoXst = TRUE; */
3341 port_t
*prt
= ptp
->port
;
3343 prt
->newInfo
= true;
3345 prt
->newInfoMsti
= true;
3347 PRTSM_runr(ptp
, true);
3350 static void PRTSM_to_ROOT_SYNCED(per_tree_port_t
*ptp
)
3353 ptp
->PRTSM_state
= PRTSM_ROOT_SYNCED
;
3358 PRTSM_runr(ptp
, true);
3361 static void PRTSM_to_REROOT(per_tree_port_t
*ptp
)
3364 ptp
->PRTSM_state
= PRTSM_REROOT
;
3366 setReRootTree(ptp
->tree
);
3368 PRTSM_runr(ptp
, true);
3371 static void PRTSM_to_ROOT_FORWARD(per_tree_port_t
*ptp
)
3374 ptp
->PRTSM_state
= PRTSM_ROOT_FORWARD
;
3376 assign(ptp
->fdWhile
, 0u);
3377 ptp
->forward
= true;
3379 PRTSM_runr(ptp
, true);
3382 static void PRTSM_to_ROOT_LEARN(per_tree_port_t
*ptp
, unsigned int forwardDelay
)
3385 ptp
->PRTSM_state
= PRTSM_ROOT_LEARN
;
3387 assign(ptp
->fdWhile
, forwardDelay
);
3390 PRTSM_runr(ptp
, true);
3393 static void PRTSM_to_REROOTED(per_tree_port_t
*ptp
)
3396 ptp
->PRTSM_state
= PRTSM_REROOTED
;
3398 ptp
->reRoot
= false;
3400 PRTSM_runr(ptp
, true);
3403 static void PRTSM_to_ROOT_PORT(per_tree_port_t
*ptp
, unsigned int FwdDelay
)
3406 ptp
->PRTSM_state
= PRTSM_ROOT_PORT
;
3408 ptp
->role
= roleRoot
;
3409 assign(ptp
->rrWhile
, FwdDelay
);
3411 PRTSM_runr(ptp
, true);
3414 /* DesignatedPort role transitions */
3416 static void PRTSM_to_DESIGNATED_PROPOSE(per_tree_port_t
*ptp
)
3419 ptp
->PRTSM_state
= PRTSM_DESIGNATED_PROPOSE
;
3421 port_t
*prt
= ptp
->port
;
3423 ptp
->proposing
= true;
3424 /* newInfoXst = TRUE; */
3427 /* 13.25.8. This tree is CIST. */
3428 unsigned int MaxAge
= ptp
->designatedTimes
.Max_Age
;
3429 /* 13.25.c) -> 17.20.4 of 802.1D : EdgeDelay */
3430 unsigned int EdgeDelay
= prt
->operPointToPointMAC
?
3431 prt
->bridge
->Migrate_Time
3433 assign(prt
->edgeDelayWhile
, EdgeDelay
);
3434 prt
->newInfo
= true;
3437 prt
->newInfoMsti
= true;
3439 PRTSM_runr(ptp
, true);
3442 static void PRTSM_to_DESIGNATED_AGREED(per_tree_port_t
*ptp
)
3445 ptp
->PRTSM_state
= PRTSM_DESIGNATED_AGREED
;
3447 ptp
->proposed
= false;
3450 /* newInfoXst = TRUE; */
3451 port_t
*prt
= ptp
->port
;
3453 prt
->newInfo
= true;
3455 prt
->newInfoMsti
= true;
3457 PRTSM_runr(ptp
, true);
3460 static void PRTSM_to_DESIGNATED_SYNCED(per_tree_port_t
*ptp
)
3463 ptp
->PRTSM_state
= PRTSM_DESIGNATED_SYNCED
;
3465 assign(ptp
->rrWhile
, 0u);
3469 PRTSM_runr(ptp
, true);
3472 static void PRTSM_to_DESIGNATED_RETIRED(per_tree_port_t
*ptp
)
3475 ptp
->PRTSM_state
= PRTSM_DESIGNATED_RETIRED
;
3477 ptp
->reRoot
= false;
3479 PRTSM_runr(ptp
, true);
3482 static void PRTSM_to_DESIGNATED_FORWARD(per_tree_port_t
*ptp
)
3485 ptp
->PRTSM_state
= PRTSM_DESIGNATED_FORWARD
;
3487 ptp
->forward
= true;
3488 assign(ptp
->fdWhile
, 0u);
3489 ptp
->agreed
= ptp
->port
->sendRSTP
;
3491 PRTSM_runr(ptp
, true);
3494 static void PRTSM_to_DESIGNATED_LEARN(per_tree_port_t
*ptp
, unsigned int forwardDelay
)
3497 ptp
->PRTSM_state
= PRTSM_DESIGNATED_LEARN
;
3500 assign(ptp
->fdWhile
, forwardDelay
);
3502 PRTSM_runr(ptp
, true);
3505 static void PRTSM_to_DESIGNATED_DISCARD(per_tree_port_t
*ptp
, unsigned int forwardDelay
)
3508 ptp
->PRTSM_state
= PRTSM_DESIGNATED_DISCARD
;
3511 ptp
->forward
= false;
3512 ptp
->disputed
= false;
3513 assign(ptp
->fdWhile
, forwardDelay
);
3515 PRTSM_runr(ptp
, true);
3518 static void PRTSM_to_DESIGNATED_PORT(per_tree_port_t
*ptp
)
3521 ptp
->PRTSM_state
= PRTSM_DESIGNATED_PORT
;
3523 ptp
->role
= roleDesignated
;
3525 PRTSM_runr(ptp
, true);
3528 /* AlternatePort and BackupPort role transitions */
3530 static void PRTSM_to_BLOCK_PORT(per_tree_port_t
*ptp
)
3533 ptp
->PRTSM_state
= PRTSM_BLOCK_PORT
;
3535 ptp
->role
= ptp
->selectedRole
;
3537 ptp
->forward
= false;
3539 PRTSM_runr(ptp
, true);
3542 static void PRTSM_to_BACKUP_PORT(per_tree_port_t
*ptp
, unsigned int HelloTime
)
3545 ptp
->PRTSM_state
= PRTSM_BACKUP_PORT
;
3547 assign(ptp
->rbWhile
, 2 * HelloTime
);
3549 PRTSM_runr(ptp
, true);
3552 static void PRTSM_to_ALTERNATE_PROPOSED(per_tree_port_t
*ptp
)
3555 ptp
->PRTSM_state
= PRTSM_ALTERNATE_PROPOSED
;
3557 setSyncTree(ptp
->tree
);
3558 ptp
->proposed
= false;
3560 PRTSM_runr(ptp
, true);
3563 static void PRTSM_to_ALTERNATE_AGREED(per_tree_port_t
*ptp
)
3566 ptp
->PRTSM_state
= PRTSM_ALTERNATE_AGREED
;
3568 ptp
->proposed
= false;
3570 /* newInfoXst = TRUE; */
3571 port_t
*prt
= ptp
->port
;
3573 prt
->newInfo
= true;
3575 prt
->newInfoMsti
= true;
3577 PRTSM_runr(ptp
, true);
3580 static void PRTSM_to_ALTERNATE_PORT(per_tree_port_t
*ptp
, unsigned int forwardDelay
)
3583 ptp
->PRTSM_state
= PRTSM_ALTERNATE_PORT
;
3585 assign(ptp
->fdWhile
, forwardDelay
);
3587 assign(ptp
->rrWhile
, 0u);
3589 ptp
->reRoot
= false;
3591 PRTSM_runr(ptp
, true);
3594 static void PRTSM_runr(per_tree_port_t
*ptp
, bool recursive_call
)
3596 /* Following vars do not need recalculating on recursive calls */
3597 static unsigned int MaxAge
, FwdDelay
, forwardDelay
, HelloTime
;
3599 static tree_t
*tree
;
3600 static per_tree_port_t
*cist
;
3601 /* Following vars are recalculated on each state transition */
3602 bool allSynced
, reRooted
;
3603 /* Following vars are auxiliary and don't depend on recursive_call */
3604 per_tree_port_t
*ptp_1
;
3607 { /* calculate these intermediate vars only first time in chain of
3608 * recursive calls */
3612 cist
= GET_CIST_PTP_FROM_PORT(prt
);
3615 FwdDelay
= cist
->designatedTimes
.Forward_Delay
;
3618 HelloTime
= cist
->portTimes
.Hello_Time
;
3620 /* 13.25.d) -> 17.20.5 of 802.1D */
3621 forwardDelay
= prt
->sendRSTP
? HelloTime
: FwdDelay
;
3624 MaxAge
= cist
->designatedTimes
.Max_Age
;
3627 PRTSM_LOG("role = %d, selectedRole = %d, selected = %d, updtInfo = %d",
3628 ptp
->role
, ptp
->selectedRole
, ptp
->selected
, ptp
->updtInfo
);
3629 if((ptp
->role
!= ptp
->selectedRole
) && ptp
->selected
&& !ptp
->updtInfo
)
3631 switch(ptp
->selectedRole
)
3634 PRTSM_to_DISABLE_PORT(ptp
);
3637 PRTSM_to_MASTER_PORT(ptp
);
3640 PRTSM_to_ROOT_PORT(ptp
, FwdDelay
);
3642 case roleDesignated
:
3643 PRTSM_to_DESIGNATED_PORT(ptp
);
3647 PRTSM_to_BLOCK_PORT(ptp
);
3654 FOREACH_PTP_IN_TREE(ptp_1
, tree
)
3658 || (ptp_1
->role
!= ptp_1
->selectedRole
)
3671 if((roleRoot
!= ptp_1
->role
) && !ptp_1
->synced
)
3674 case roleDesignated
:
3676 if((ptp
!= ptp_1
) && !ptp_1
->synced
)
3686 switch(ptp
->PRTSM_state
)
3688 /* Disabled Port role transitions */
3689 case PRTSM_INIT_PORT
:
3690 PRTSM_to_DISABLE_PORT(ptp
);
3692 case PRTSM_DISABLE_PORT
:
3693 if(ptp
->selected
&& !ptp
->updtInfo
3694 && !ptp
->learning
&& !ptp
->forwarding
3696 PRTSM_to_DISABLED_PORT(ptp
, MaxAge
);
3698 case PRTSM_DISABLED_PORT
:
3699 if(ptp
->selected
&& !ptp
->updtInfo
3700 && (ptp
->sync
|| ptp
->reRoot
|| !ptp
->synced
3701 || (ptp
->fdWhile
!= MaxAge
))
3703 PRTSM_to_DISABLED_PORT(ptp
, MaxAge
);
3705 /* MasterPort role transitions */
3706 case PRTSM_MASTER_PROPOSED
:
3708 case PRTSM_MASTER_AGREED
:
3710 case PRTSM_MASTER_SYNCED
:
3712 case PRTSM_MASTER_RETIRED
:
3714 case PRTSM_MASTER_FORWARD
:
3716 case PRTSM_MASTER_LEARN
:
3718 case PRTSM_MASTER_DISCARD
:
3719 PRTSM_to_MASTER_PORT(ptp
);
3721 case PRTSM_MASTER_PORT
:
3722 if(!(ptp
->selected
&& !ptp
->updtInfo
))
3724 if(ptp
->reRoot
&& (0 == ptp
->rrWhile
))
3726 PRTSM_to_MASTER_RETIRED(ptp
);
3729 if((!ptp
->learning
&& !ptp
->forwarding
&& !ptp
->synced
)
3730 || (ptp
->agreed
&& !ptp
->synced
)
3731 || (prt
->operEdge
&& !ptp
->synced
)
3732 || (ptp
->sync
&& ptp
->synced
)
3735 PRTSM_to_MASTER_SYNCED(ptp
);
3738 if((allSynced
&& !ptp
->agree
)
3739 || (ptp
->proposed
&& ptp
->agree
)
3742 PRTSM_to_MASTER_AGREED(ptp
);
3745 if(ptp
->proposed
&& !ptp
->agree
)
3747 PRTSM_to_MASTER_PROPOSED(ptp
);
3750 if(((0 == ptp
->fdWhile
) || allSynced
)
3751 && ptp
->learn
&& !ptp
->forward
3754 PRTSM_to_MASTER_FORWARD(ptp
);
3757 if(((0 == ptp
->fdWhile
) || allSynced
)
3761 PRTSM_to_MASTER_LEARN(ptp
, forwardDelay
);
3764 if(((ptp
->sync
&& !ptp
->synced
)
3765 || (ptp
->reRoot
&& (0 != ptp
->rrWhile
))
3768 && !prt
->operEdge
&& (ptp
->learn
|| ptp
->forward
)
3771 PRTSM_to_MASTER_DISCARD(ptp
, forwardDelay
);
3775 /* RootPort role transitions */
3776 case PRTSM_ROOT_PROPOSED
:
3778 case PRTSM_ROOT_AGREED
:
3780 case PRTSM_ROOT_SYNCED
:
3784 case PRTSM_ROOT_FORWARD
:
3786 case PRTSM_ROOT_LEARN
:
3788 case PRTSM_REROOTED
:
3789 PRTSM_to_ROOT_PORT(ptp
, FwdDelay
);
3791 case PRTSM_ROOT_PORT
:
3792 if(!(ptp
->selected
&& !ptp
->updtInfo
))
3794 if(!ptp
->forward
&& !ptp
->reRoot
)
3796 PRTSM_to_REROOT(ptp
);
3799 if((ptp
->agreed
&& !ptp
->synced
) || (ptp
->sync
&& ptp
->synced
))
3801 PRTSM_to_ROOT_SYNCED(ptp
);
3804 if((allSynced
&& !ptp
->agree
) || (ptp
->proposed
&& ptp
->agree
))
3806 PRTSM_to_ROOT_AGREED(ptp
);
3809 if(ptp
->proposed
&& !ptp
->agree
)
3811 PRTSM_to_ROOT_PROPOSED(ptp
);
3814 /* 17.20.10 of 802.1D : reRooted */
3816 FOREACH_PTP_IN_TREE(ptp_1
, tree
)
3818 if((ptp
!= ptp_1
) && (0 != ptp_1
->rrWhile
))
3824 if((0 == ptp
->fdWhile
)
3825 || (reRooted
&& (0 == ptp
->rbWhile
) && rstpVersion(prt
->bridge
))
3830 PRTSM_to_ROOT_LEARN(ptp
, forwardDelay
);
3833 else if(!ptp
->forward
)
3835 PRTSM_to_ROOT_FORWARD(ptp
);
3839 if(ptp
->reRoot
&& ptp
->forward
)
3841 PRTSM_to_REROOTED(ptp
);
3844 if(ptp
->rrWhile
!= FwdDelay
)
3846 PRTSM_to_ROOT_PORT(ptp
, FwdDelay
);
3850 /* DesignatedPort role transitions */
3851 case PRTSM_DESIGNATED_PROPOSE
:
3853 case PRTSM_DESIGNATED_AGREED
:
3855 case PRTSM_DESIGNATED_SYNCED
:
3857 case PRTSM_DESIGNATED_RETIRED
:
3859 case PRTSM_DESIGNATED_FORWARD
:
3861 case PRTSM_DESIGNATED_LEARN
:
3863 case PRTSM_DESIGNATED_DISCARD
:
3864 PRTSM_to_DESIGNATED_PORT(ptp
);
3866 case PRTSM_DESIGNATED_PORT
:
3867 if(!(ptp
->selected
&& !ptp
->updtInfo
))
3869 if(ptp
->reRoot
&& (0 == ptp
->rrWhile
))
3871 PRTSM_to_DESIGNATED_RETIRED(ptp
);
3874 if((!ptp
->learning
&& !ptp
->forwarding
&& !ptp
->synced
)
3875 || (ptp
->agreed
&& !ptp
->synced
)
3876 || (prt
->operEdge
&& !ptp
->synced
)
3877 || (ptp
->sync
&& ptp
->synced
)
3880 PRTSM_to_DESIGNATED_SYNCED(ptp
);
3883 if(allSynced
&& (ptp
->proposed
|| !ptp
->agree
))
3885 PRTSM_to_DESIGNATED_AGREED(ptp
);
3888 if(!ptp
->forward
&& !ptp
->agreed
&& !ptp
->proposing
3891 PRTSM_to_DESIGNATED_PROPOSE(ptp
);
3894 if(((0 == ptp
->fdWhile
) || ptp
->agreed
|| prt
->operEdge
)
3895 && ((0 == ptp
->rrWhile
) || !ptp
->reRoot
) && !ptp
->sync
3900 PRTSM_to_DESIGNATED_LEARN(ptp
, forwardDelay
);
3903 else if(!ptp
->forward
)
3905 PRTSM_to_DESIGNATED_FORWARD(ptp
);
3909 if(((ptp
->sync
&& !ptp
->synced
)
3910 || (ptp
->reRoot
&& (0 != ptp
->rrWhile
))
3913 && !prt
->operEdge
&& (ptp
->learn
|| ptp
->forward
)
3916 PRTSM_to_DESIGNATED_DISCARD(ptp
, forwardDelay
);
3920 /* AlternatePort and BackupPort role transitions */
3921 case PRTSM_BLOCK_PORT
:
3922 if(ptp
->selected
&& !ptp
->updtInfo
3923 && !ptp
->learning
&& !ptp
->forwarding
3925 PRTSM_to_ALTERNATE_PORT(ptp
, forwardDelay
);
3927 case PRTSM_BACKUP_PORT
:
3929 case PRTSM_ALTERNATE_PROPOSED
:
3931 case PRTSM_ALTERNATE_AGREED
:
3932 PRTSM_to_ALTERNATE_PORT(ptp
, forwardDelay
);
3934 case PRTSM_ALTERNATE_PORT
:
3935 if(!(ptp
->selected
&& !ptp
->updtInfo
))
3937 if((allSynced
&& !ptp
->agree
) || (ptp
->proposed
&& ptp
->agree
))
3939 PRTSM_to_ALTERNATE_AGREED(ptp
);
3942 if(ptp
->proposed
&& !ptp
->agree
)
3944 PRTSM_to_ALTERNATE_PROPOSED(ptp
);
3947 if((ptp
->rbWhile
!= 2 * HelloTime
) && (roleBackup
== ptp
->role
))
3949 PRTSM_to_BACKUP_PORT(ptp
, HelloTime
);
3952 if((ptp
->fdWhile
!= forwardDelay
) || ptp
->sync
|| ptp
->reRoot
3955 PRTSM_to_ALTERNATE_PORT(ptp
, forwardDelay
);
3962 /* 13.35 Port State Transition state machine */
3964 static void PSTSM_run(per_tree_port_t
*ptp
);
3965 #define PSTSM_begin(ptp) PSTSM_to_DISCARDING((ptp), true)
3967 static void PSTSM_to_DISCARDING(per_tree_port_t
*ptp
, bool begin
)
3969 ptp
->PSTSM_state
= PSTSM_DISCARDING
;
3971 /* This effectively sets BLOCKING state:
3973 disableForwarding();
3975 if(BR_STATE_BLOCKING
!= ptp
->state
)
3976 MSTP_OUT_set_state(ptp
, BR_STATE_BLOCKING
);
3977 ptp
->learning
= false;
3978 ptp
->forwarding
= false;
3984 static void PSTSM_to_LEARNING(per_tree_port_t
*ptp
)
3986 ptp
->PSTSM_state
= PSTSM_LEARNING
;
3988 /* enableLearning(); */
3989 if(BR_STATE_LEARNING
!= ptp
->state
)
3990 MSTP_OUT_set_state(ptp
, BR_STATE_LEARNING
);
3991 ptp
->learning
= true;
3996 static void PSTSM_to_FORWARDING(per_tree_port_t
*ptp
)
3998 ptp
->PSTSM_state
= PSTSM_FORWARDING
;
4000 /* enableForwarding(); */
4001 if(BR_STATE_FORWARDING
!= ptp
->state
)
4002 MSTP_OUT_set_state(ptp
, BR_STATE_FORWARDING
);
4003 ptp
->forwarding
= true;
4005 /* No need to run, no one condition will be met
4009 static void PSTSM_run(per_tree_port_t
*ptp
)
4011 switch(ptp
->PSTSM_state
)
4013 case PSTSM_DISCARDING
:
4015 PSTSM_to_LEARNING(ptp
);
4017 case PSTSM_LEARNING
:
4019 PSTSM_to_DISCARDING(ptp
, false);
4020 else if(ptp
->forward
)
4021 PSTSM_to_FORWARDING(ptp
);
4023 case PSTSM_FORWARDING
:
4025 PSTSM_to_DISCARDING(ptp
, false);
4030 /* 13.36 Topology Change state machine */
4032 #define TCSM_begin(ptp) TCSM_to_INACTIVE((ptp), true)
4034 static void TCSM_to_INACTIVE(per_tree_port_t
*ptp
, bool begin
)
4036 ptp
->TCSM_state
= TCSM_INACTIVE
;
4039 assign(ptp
->tcWhile
, 0u);
4040 set_TopologyChange(ptp
->tree
, false);
4041 if(0 == ptp
->MSTID
) /* CIST */
4042 ptp
->port
->tcAck
= false;
4048 static void TCSM_to_LEARNING(per_tree_port_t
*ptp
)
4050 ptp
->TCSM_state
= TCSM_LEARNING
;
4052 if(0 == ptp
->MSTID
) /* CIST */
4054 port_t
*prt
= ptp
->port
;
4055 prt
->rcvdTcn
= false;
4056 prt
->rcvdTcAck
= false;
4058 ptp
->rcvdTc
= false;
4059 ptp
->tcProp
= false;
4064 static void TCSM_to_DETECTED(per_tree_port_t
*ptp
)
4066 ptp
->TCSM_state
= TCSM_DETECTED
;
4070 /* newInfoXst = TRUE; */
4071 port_t
*prt
= ptp
->port
;
4073 prt
->newInfo
= true;
4075 prt
->newInfoMsti
= true;
4080 static void TCSM_to_NOTIFIED_TCN(per_tree_port_t
*ptp
)
4082 ptp
->TCSM_state
= TCSM_NOTIFIED_TCN
;
4089 static void TCSM_to_NOTIFIED_TC(per_tree_port_t
*ptp
)
4091 ptp
->TCSM_state
= TCSM_NOTIFIED_TC
;
4093 ptp
->rcvdTc
= false;
4094 if(0 == ptp
->MSTID
) /* CIST */
4096 port_t
*prt
= ptp
->port
;
4097 prt
->rcvdTcn
= false;
4098 if(roleDesignated
== ptp
->role
)
4106 static void TCSM_to_PROPAGATING(per_tree_port_t
*ptp
)
4108 ptp
->TCSM_state
= TCSM_PROPAGATING
;
4112 ptp
->tcProp
= false;
4117 static void TCSM_to_ACKNOWLEDGED(per_tree_port_t
*ptp
)
4119 ptp
->TCSM_state
= TCSM_ACKNOWLEDGED
;
4121 assign(ptp
->tcWhile
, 0u);
4122 set_TopologyChange(ptp
->tree
, false);
4123 ptp
->port
->rcvdTcAck
= false;
4128 static void TCSM_to_ACTIVE(per_tree_port_t
*ptp
)
4130 ptp
->TCSM_state
= TCSM_ACTIVE
;
4135 static void TCSM_run(per_tree_port_t
*ptp
)
4138 port_t
*prt
= ptp
->port
;
4140 switch(ptp
->TCSM_state
)
4143 if(ptp
->learn
&& !ptp
->fdbFlush
)
4144 TCSM_to_LEARNING(ptp
);
4147 active_port
= (roleRoot
== ptp
->role
)
4148 || (roleDesignated
== ptp
->role
)
4149 || (roleMaster
== ptp
->role
);
4150 if(active_port
&& ptp
->forward
&& !prt
->operEdge
)
4152 TCSM_to_DETECTED(ptp
);
4155 if(ptp
->rcvdTc
|| prt
->rcvdTcn
|| prt
->rcvdTcAck
|| ptp
->tcProp
)
4157 TCSM_to_LEARNING(ptp
);
4160 else if(!active_port
&& !(ptp
->learn
|| ptp
->learning
))
4161 TCSM_to_INACTIVE(ptp
, false);
4163 case TCSM_NOTIFIED_TCN
:
4164 TCSM_to_NOTIFIED_TC(ptp
);
4168 case TCSM_NOTIFIED_TC
:
4170 case TCSM_PROPAGATING
:
4172 case TCSM_ACKNOWLEDGED
:
4173 TCSM_to_ACTIVE(ptp
);
4176 active_port
= (roleRoot
== ptp
->role
)
4177 || (roleDesignated
== ptp
->role
)
4178 || (roleMaster
== ptp
->role
);
4179 if(!active_port
|| prt
->operEdge
)
4181 TCSM_to_LEARNING(ptp
);
4186 TCSM_to_NOTIFIED_TCN(ptp
);
4191 TCSM_to_NOTIFIED_TC(ptp
);
4194 if(ptp
->tcProp
/* && !prt->operEdge */)
4196 TCSM_to_PROPAGATING(ptp
);
4201 TCSM_to_ACKNOWLEDGED(ptp
);
4208 /* Execute BEGIN state. We do not define BEGIN variable
4209 * but instead xxx_state_machines_begin execute begin state
4210 * abd do one step out of it
4213 static void tree_state_machines_begin(tree_t
*tree
)
4215 bridge_t
*br
= tree
->bridge
;
4216 per_tree_port_t
*ptp
;
4218 if(!br
->bridgeEnabled
)
4221 /* 13.32 Port Information state machine */
4222 FOREACH_PTP_IN_TREE(ptp
, tree
)
4224 ptp
->start_time
= br
->uptime
; /* 12.8.2.2.3 b) */
4228 /* 13.33 Port Role Selection state machine */
4231 /* 13.34 Port Role Transitions state machine */
4232 FOREACH_PTP_IN_TREE(ptp
, tree
)
4234 /* 13.35 Port State Transition state machine */
4235 FOREACH_PTP_IN_TREE(ptp
, tree
)
4237 /* 13.36 Topology Change state machine */
4238 FOREACH_PTP_IN_TREE(ptp
, tree
)
4241 br_state_machines_run(br
);
4244 static void prt_state_machines_begin(port_t
*prt
)
4246 bridge_t
*br
= prt
->bridge
;
4248 per_tree_port_t
*ptp
;
4250 if(!br
->bridgeEnabled
)
4253 /* 13.28 Port Receive state machine */
4255 /* 13.29 Port Protocol Migration state machine */
4257 /* 13.30 Bridge Detection state machine */
4259 /* 13.31 Port Transmit state machine */
4262 /* 13.32 Port Information state machine */
4263 FOREACH_PTP_IN_PORT(ptp
, prt
)
4265 ptp
->start_time
= br
->uptime
; /* 12.8.2.2.3 b) */
4269 /* 13.33 Port Role Selection state machine */
4270 FOREACH_TREE_IN_BRIDGE(tree
, br
)
4273 /* 13.34 Port Role Transitions state machine */
4274 FOREACH_PTP_IN_PORT(ptp
, prt
)
4276 /* 13.35 Port State Transition state machine */
4277 FOREACH_PTP_IN_PORT(ptp
, prt
)
4279 /* 13.36 Topology Change state machine */
4280 FOREACH_PTP_IN_PORT(ptp
, prt
)
4283 br_state_machines_run(br
);
4286 static void br_state_machines_begin(bridge_t
*br
)
4289 per_tree_port_t
*ptp
;
4292 if(!br
->bridgeEnabled
)
4295 /* 13.28 Port Receive state machine */
4296 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4298 /* 13.29 Port Protocol Migration state machine */
4299 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4301 /* 13.30 Bridge Detection state machine */
4302 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4304 /* 13.31 Port Transmit state machine */
4305 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4308 /* 13.32 Port Information state machine */
4309 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4311 FOREACH_PTP_IN_PORT(ptp
, prt
)
4313 ptp
->start_time
= br
->uptime
; /* 12.8.2.2.3 b) */
4318 /* 13.33 Port Role Selection state machine */
4319 FOREACH_TREE_IN_BRIDGE(tree
, br
)
4322 /* 13.34 Port Role Transitions state machine */
4323 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4325 FOREACH_PTP_IN_PORT(ptp
, prt
)
4328 /* 13.35 Port State Transition state machine */
4329 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4331 FOREACH_PTP_IN_PORT(ptp
, prt
)
4334 /* 13.36 Topology Change state machine */
4335 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4337 FOREACH_PTP_IN_PORT(ptp
, prt
)
4341 br_state_machines_run(br
);
4344 /* Run each state machine */
4345 static void br_state_machines_run(bridge_t
*br
)
4348 per_tree_port_t
*ptp
;
4351 if(!br
->bridgeEnabled
)
4354 /* 13.28 Port Receive state machine */
4355 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4357 /* 13.29 Port Protocol Migration state machine */
4358 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4360 /* 13.30 Bridge Detection state machine */
4361 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4363 /* 13.31 Port Transmit state machine */
4364 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4367 /* 13.32 Port Information state machine */
4368 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4370 FOREACH_PTP_IN_PORT(ptp
, prt
)
4374 /* 13.33 Port Role Selection state machine */
4375 FOREACH_TREE_IN_BRIDGE(tree
, br
)
4378 /* 13.34 Port Role Transitions state machine */
4379 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4381 FOREACH_PTP_IN_PORT(ptp
, prt
)
4384 /* 13.35 Port State Transition state machine */
4385 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4387 FOREACH_PTP_IN_PORT(ptp
, prt
)
4390 /* 13.36 Topology Change state machine */
4391 FOREACH_PORT_IN_BRIDGE(prt
, br
)
4393 FOREACH_PTP_IN_PORT(ptp
, prt
)