2 * Copyright (c) 2011-2015 M3S, Srl - Italy
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Rapid Spanning Tree Protocol (IEEE 802.1D-2004) public interface.
21 * Martino Fornasa <mf@fornasa.it>
22 * Daniele Venturino <daniele.venturino@m3s.it>
23 * Carlo Andreotti <c.andreotti@m3s.it>
25 * References to IEEE 802.1D-2004 standard are enclosed in square brackets.
26 * E.g. [17.3], [Table 17-1], etc.
33 #include "rstp-common.h"
34 #include "rstp-state-machines.h"
35 #include <arpa/inet.h>
37 #include <netinet/in.h>
39 #include <sys/types.h>
40 #include "byte-order.h"
41 #include "connectivity.h"
43 #include "ofproto/ofproto.h"
44 #include "dp-packet.h"
49 #include "openvswitch/vlog.h"
51 VLOG_DEFINE_THIS_MODULE(rstp);
53 struct ovs_mutex rstp_mutex = OVS_MUTEX_INITIALIZER;
55 static struct ovs_list all_rstps__ = OVS_LIST_INITIALIZER(&all_rstps__);
56 static struct ovs_list *const all_rstps OVS_GUARDED_BY(rstp_mutex) = &all_rstps__;
58 /* Internal use only. */
59 static void rstp_set_bridge_address__(struct rstp *, rstp_identifier)
60 OVS_REQUIRES(rstp_mutex);
61 static void rstp_set_bridge_priority__(struct rstp *, int new_priority)
62 OVS_REQUIRES(rstp_mutex);
63 static void rstp_set_bridge_ageing_time__(struct rstp *, int new_ageing_time)
64 OVS_REQUIRES(rstp_mutex);
65 static void rstp_set_bridge_force_protocol_version__(struct rstp *,
66 enum rstp_force_protocol_version)
67 OVS_REQUIRES(rstp_mutex);
68 static void rstp_set_bridge_hello_time__(struct rstp *)
69 OVS_REQUIRES(rstp_mutex);
70 static void rstp_set_bridge_max_age__(struct rstp *, int new_max_age)
71 OVS_REQUIRES(rstp_mutex);
72 static void rstp_set_bridge_forward_delay__(struct rstp *, int new_forward_delay)
73 OVS_REQUIRES(rstp_mutex);
74 static void rstp_set_bridge_transmit_hold_count__(struct rstp *,
75 int new_transmit_hold_count)
76 OVS_REQUIRES(rstp_mutex);
77 static void rstp_set_bridge_migrate_time__(struct rstp *)
78 OVS_REQUIRES(rstp_mutex);
79 static void rstp_set_bridge_times__(struct rstp *, int new_forward_delay,
80 int new_hello_time, int new_max_age,
82 OVS_REQUIRES(rstp_mutex);
84 static struct rstp_port *rstp_get_port__(struct rstp *rstp,
86 OVS_REQUIRES(rstp_mutex);
87 static void set_port_id__(struct rstp_port *)
88 OVS_REQUIRES(rstp_mutex);
89 static void update_port_enabled__(struct rstp_port *)
90 OVS_REQUIRES(rstp_mutex);
91 static void set_bridge_priority__(struct rstp *)
92 OVS_REQUIRES(rstp_mutex);
93 static void reinitialize_rstp__(struct rstp *)
94 OVS_REQUIRES(rstp_mutex);
95 static bool is_port_number_available__(struct rstp *, int, struct rstp_port *)
96 OVS_REQUIRES(rstp_mutex);
97 static uint16_t rstp_first_free_number__(struct rstp *, struct rstp_port *)
98 OVS_REQUIRES(rstp_mutex);
99 static void rstp_initialize_port_defaults__(struct rstp_port *)
100 OVS_REQUIRES(rstp_mutex);
101 static void rstp_port_set_priority__(struct rstp_port *, int priority)
102 OVS_REQUIRES(rstp_mutex);
103 static void rstp_port_set_port_number__(struct rstp_port *,
104 uint16_t port_number)
105 OVS_REQUIRES(rstp_mutex);
106 static void rstp_port_set_path_cost__(struct rstp_port *, uint32_t path_cost)
107 OVS_REQUIRES(rstp_mutex);
108 static void rstp_port_set_administrative_bridge_port__(struct rstp_port *,
109 uint8_t admin_port_state,
111 OVS_REQUIRES(rstp_mutex);
112 static void rstp_port_set_admin_edge__(struct rstp_port *, bool admin_edge)
113 OVS_REQUIRES(rstp_mutex);
114 static void rstp_port_set_auto_edge__(struct rstp_port *, bool auto_edge)
115 OVS_REQUIRES(rstp_mutex);
116 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *,
117 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
118 OVS_REQUIRES(rstp_mutex);
119 static void rstp_port_set_mcheck__(struct rstp_port *, bool mcheck)
120 OVS_REQUIRES(rstp_mutex);
121 static void reinitialize_port__(struct rstp_port *p)
122 OVS_REQUIRES(rstp_mutex);
125 rstp_state_name(enum rstp_state state)
132 case RSTP_FORWARDING:
134 case RSTP_DISCARDING:
142 rstp_port_role_name(enum rstp_port_role role)
147 case ROLE_DESIGNATED:
160 /* Caller has to hold a reference to prevent 'rstp' from being deleted
161 * while taking a new reference. */
163 rstp_ref(struct rstp *rstp)
164 OVS_EXCLUDED(rstp_mutex)
167 ovs_refcount_ref(&rstp->ref_cnt);
172 /* Frees RSTP struct when reference count reaches zero. */
174 rstp_unref(struct rstp *rstp)
175 OVS_EXCLUDED(rstp_mutex)
177 if (rstp && ovs_refcount_unref_relaxed(&rstp->ref_cnt) == 1) {
178 ovs_mutex_lock(&rstp_mutex);
180 /* Each RSTP port points back to struct rstp without holding a
181 * reference for that pointer. This is OK as we never move
182 * ports from one bridge to another, and holders always
183 * release their ports before releasing the bridge. This
184 * means that there should be not ports at this time. */
185 ovs_assert(hmap_is_empty(&rstp->ports));
187 list_remove(&rstp->node);
188 ovs_mutex_unlock(&rstp_mutex);
194 /* Returns the port number. Mutex is needed to guard against
195 * concurrent reinitialization (which can temporarily clear the
198 rstp_port_get_number(const struct rstp_port *p)
199 OVS_EXCLUDED(rstp_mutex)
203 ovs_mutex_lock(&rstp_mutex);
204 number = p->port_number;
205 ovs_mutex_unlock(&rstp_mutex);
210 static void rstp_unixctl_tcn(struct unixctl_conn *, int argc,
211 const char *argv[], void *aux);
213 /* Decrements the State Machines' timers. */
215 rstp_tick_timers(struct rstp *rstp)
216 OVS_EXCLUDED(rstp_mutex)
218 ovs_mutex_lock(&rstp_mutex);
219 decrease_rstp_port_timers__(rstp);
220 ovs_mutex_unlock(&rstp_mutex);
223 /* Processes an incoming BPDU. */
225 rstp_port_received_bpdu(struct rstp_port *rp, const void *bpdu,
227 OVS_EXCLUDED(rstp_mutex)
229 ovs_mutex_lock(&rstp_mutex);
230 /* Only process packets on ports that have RSTP enabled. */
231 if (rp && rp->rstp_state != RSTP_DISABLED) {
232 process_received_bpdu__(rp, bpdu, bpdu_size);
234 ovs_mutex_unlock(&rstp_mutex);
239 OVS_EXCLUDED(rstp_mutex)
241 unixctl_command_register("rstp/tcn", "[bridge]", 0, 1, rstp_unixctl_tcn,
245 /* Creates and returns a new RSTP instance that initially has no ports. */
247 rstp_create(const char *name, rstp_identifier bridge_address,
248 void (*send_bpdu)(struct dp_packet *bpdu, void *port_aux,
251 OVS_EXCLUDED(rstp_mutex)
255 VLOG_DBG("Creating RSTP instance");
257 rstp = xzalloc(sizeof *rstp);
258 rstp->name = xstrdup(name);
260 /* Initialize the ports map before calling any setters,
261 * so that the state machines will see an empty ports map. */
262 hmap_init(&rstp->ports);
264 ovs_mutex_lock(&rstp_mutex);
265 /* Set bridge address. */
266 rstp_set_bridge_address__(rstp, bridge_address);
267 /* Set default parameters values. */
268 rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
269 rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
270 rstp_set_bridge_force_protocol_version__(rstp, FPV_DEFAULT);
271 rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
272 rstp_set_bridge_hello_time__(rstp);
273 rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
274 rstp_set_bridge_migrate_time__(rstp);
275 rstp_set_bridge_transmit_hold_count__(rstp,
276 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
277 rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
278 RSTP_BRIDGE_HELLO_TIME,
279 RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
280 rstp->send_bpdu = send_bpdu;
282 rstp->changes = false;
284 rstp->old_root_aux = NULL;
285 rstp->new_root_aux = NULL;
287 ovs_refcount_init(&rstp->ref_cnt);
289 list_push_back(all_rstps, &rstp->node);
290 ovs_mutex_unlock(&rstp_mutex);
292 VLOG_DBG("RSTP instance creation done");
296 /* Called by rstp_set_bridge_address() and rstp_set_bridge_priority(),
297 * it updates the bridge priority vector according to the values passed by
301 set_bridge_priority__(struct rstp *rstp)
302 OVS_REQUIRES(rstp_mutex)
306 rstp->bridge_priority.root_bridge_id = rstp->bridge_identifier;
307 rstp->bridge_priority.designated_bridge_id = rstp->bridge_identifier;
308 VLOG_DBG("%s: new bridge identifier: "RSTP_ID_FMT"", rstp->name,
309 RSTP_ID_ARGS(rstp->bridge_identifier));
311 /* [17.13] When the bridge address changes, recalculates all priority
314 HMAP_FOR_EACH (p, node, &rstp->ports) {
318 rstp->changes = true;
319 updt_roles_tree__(rstp);
322 /* Sets the bridge address. */
324 rstp_set_bridge_address__(struct rstp *rstp, rstp_identifier bridge_address)
325 OVS_REQUIRES(rstp_mutex)
327 VLOG_DBG("%s: set bridge address to: "RSTP_ID_FMT"", rstp->name,
328 RSTP_ID_ARGS(bridge_address));
329 if (rstp->address != bridge_address) {
330 rstp->address = bridge_address;
331 rstp->bridge_identifier &= 0xffff000000000000ULL;
332 rstp->bridge_identifier |= bridge_address;
333 set_bridge_priority__(rstp);
337 /* Sets the bridge address. */
339 rstp_set_bridge_address(struct rstp *rstp, rstp_identifier bridge_address)
340 OVS_EXCLUDED(rstp_mutex)
342 ovs_mutex_lock(&rstp_mutex);
343 rstp_set_bridge_address__(rstp, bridge_address);
344 ovs_mutex_unlock(&rstp_mutex);
348 rstp_get_name(const struct rstp *rstp)
349 OVS_EXCLUDED(rstp_mutex)
353 ovs_mutex_lock(&rstp_mutex);
355 ovs_mutex_unlock(&rstp_mutex);
360 rstp_get_bridge_id(const struct rstp *rstp)
361 OVS_EXCLUDED(rstp_mutex)
363 rstp_identifier bridge_id;
365 ovs_mutex_lock(&rstp_mutex);
366 bridge_id = rstp->bridge_identifier;
367 ovs_mutex_unlock(&rstp_mutex);
372 /* Sets the bridge priority. */
374 rstp_set_bridge_priority__(struct rstp *rstp, int new_priority)
375 OVS_REQUIRES(rstp_mutex)
377 new_priority = ROUND_DOWN(new_priority, RSTP_PRIORITY_STEP);
379 if (rstp->priority != new_priority
380 && new_priority >= RSTP_MIN_PRIORITY
381 && new_priority <= RSTP_MAX_PRIORITY) {
382 VLOG_DBG("%s: set bridge priority to %d", rstp->name, new_priority);
384 rstp->priority = new_priority;
385 rstp->bridge_identifier &= 0x0000ffffffffffffULL;
386 rstp->bridge_identifier |= (uint64_t)new_priority << 48;
387 set_bridge_priority__(rstp);
392 rstp_set_bridge_priority(struct rstp *rstp, int new_priority)
393 OVS_EXCLUDED(rstp_mutex)
395 ovs_mutex_lock(&rstp_mutex);
396 rstp_set_bridge_priority__(rstp, new_priority);
397 ovs_mutex_unlock(&rstp_mutex);
400 /* Sets the bridge ageing time. */
402 rstp_set_bridge_ageing_time__(struct rstp *rstp, int new_ageing_time)
403 OVS_REQUIRES(rstp_mutex)
405 if (new_ageing_time >= RSTP_MIN_AGEING_TIME
406 && new_ageing_time <= RSTP_MAX_AGEING_TIME) {
407 VLOG_DBG("%s: set ageing time to %d", rstp->name, new_ageing_time);
409 rstp->ageing_time = new_ageing_time;
414 rstp_set_bridge_ageing_time(struct rstp *rstp, int new_ageing_time)
415 OVS_EXCLUDED(rstp_mutex)
417 ovs_mutex_lock(&rstp_mutex);
418 rstp_set_bridge_ageing_time__(rstp, new_ageing_time);
419 ovs_mutex_unlock(&rstp_mutex);
422 /* Reinitializes RSTP when switching from RSTP mode to STP mode
426 reinitialize_rstp__(struct rstp *rstp)
427 OVS_REQUIRES(rstp_mutex)
430 static struct hmap ports;
433 /* Copy rstp in temp */
437 /* stop and clear rstp */
438 memset(rstp, 0, sizeof(struct rstp));
440 /* Initialize rstp. */
441 rstp->name = temp.name;
443 /* Initialize the ports hmap before calling any setters,
444 * so that the state machines will see an empty ports list. */
445 hmap_init(&rstp->ports);
447 /* Set bridge address. */
448 rstp_set_bridge_address__(rstp, temp.address);
449 /* Set default parameters values. */
450 rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
451 rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
452 rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
453 rstp_set_bridge_hello_time__(rstp);
454 rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
455 rstp_set_bridge_migrate_time__(rstp);
456 rstp_set_bridge_transmit_hold_count__(rstp,
457 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
458 rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
459 RSTP_BRIDGE_HELLO_TIME,
460 RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
462 rstp->send_bpdu = temp.send_bpdu;
463 rstp->aux = temp.aux;
464 rstp->node = temp.node;
465 rstp->changes = false;
471 HMAP_FOR_EACH (p, node, &rstp->ports) {
472 reinitialize_port__(p);
475 rstp->ref_cnt = temp.ref_cnt;
478 /* Sets the force protocol version parameter. */
480 rstp_set_bridge_force_protocol_version__(struct rstp *rstp,
481 enum rstp_force_protocol_version new_force_protocol_version)
482 OVS_REQUIRES(rstp_mutex)
484 if (new_force_protocol_version != rstp->force_protocol_version &&
485 (new_force_protocol_version == FPV_STP_COMPATIBILITY ||
486 new_force_protocol_version == FPV_DEFAULT)) {
487 VLOG_DBG("%s: set bridge Force Protocol Version to %d", rstp->name,
488 new_force_protocol_version);
490 /* [17.13] The Spanning Tree Protocol Entity shall be reinitialized,
491 * as specified by the assertion of BEGIN (17.18.1) in the state
492 * machine specification.
494 reinitialize_rstp__(rstp);
495 rstp->force_protocol_version = new_force_protocol_version;
496 if (rstp->force_protocol_version < 2) {
497 rstp->stp_version = true;
498 rstp->rstp_version = false;
500 rstp->stp_version = false;
501 rstp->rstp_version = true;
503 rstp->changes = true;
509 rstp_set_bridge_force_protocol_version(struct rstp *rstp,
510 enum rstp_force_protocol_version new_force_protocol_version)
511 OVS_EXCLUDED(rstp_mutex)
513 ovs_mutex_lock(&rstp_mutex);
514 rstp_set_bridge_force_protocol_version__(rstp, new_force_protocol_version);
515 ovs_mutex_unlock(&rstp_mutex);
518 /* Sets the bridge Hello Time parameter. */
520 rstp_set_bridge_hello_time__(struct rstp *rstp)
521 OVS_REQUIRES(rstp_mutex)
523 VLOG_DBG("%s: set RSTP Hello Time to %d", rstp->name,
524 RSTP_BRIDGE_HELLO_TIME);
525 /* 2 is the only acceptable value. */
526 rstp->bridge_hello_time = RSTP_BRIDGE_HELLO_TIME;
529 /* Sets the bridge max age parameter. */
531 rstp_set_bridge_max_age__(struct rstp *rstp, int new_max_age)
532 OVS_REQUIRES(rstp_mutex)
534 if (rstp->bridge_max_age != new_max_age
535 && new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
536 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
538 if ((2 * (rstp->bridge_forward_delay - 1) >= new_max_age)
539 && (new_max_age >= 2 * rstp->bridge_hello_time)) {
540 VLOG_DBG("%s: set RSTP bridge Max Age to %d", rstp->name,
543 rstp->bridge_max_age = new_max_age;
544 rstp->bridge_times.max_age = new_max_age;
545 rstp->changes = true;
546 updt_roles_tree__(rstp);
552 rstp_set_bridge_max_age(struct rstp *rstp, int new_max_age)
553 OVS_EXCLUDED(rstp_mutex)
555 ovs_mutex_lock(&rstp_mutex);
556 rstp_set_bridge_max_age__(rstp, new_max_age);
557 ovs_mutex_unlock(&rstp_mutex);
560 /* Sets the bridge forward delay parameter. */
562 rstp_set_bridge_forward_delay__(struct rstp *rstp, int new_forward_delay)
563 OVS_REQUIRES(rstp_mutex)
565 if (rstp->bridge_forward_delay != new_forward_delay
566 && new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
567 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
568 if (2 * (new_forward_delay - 1) >= rstp->bridge_max_age) {
569 VLOG_DBG("%s: set RSTP Forward Delay to %d", rstp->name,
571 rstp->bridge_forward_delay = new_forward_delay;
572 rstp->bridge_times.forward_delay = new_forward_delay;
573 rstp->changes = true;
574 updt_roles_tree__(rstp);
580 rstp_set_bridge_forward_delay(struct rstp *rstp, int new_forward_delay)
581 OVS_EXCLUDED(rstp_mutex)
583 ovs_mutex_lock(&rstp_mutex);
584 rstp_set_bridge_forward_delay__(rstp, new_forward_delay);
585 ovs_mutex_unlock(&rstp_mutex);
588 /* Sets the bridge transmit hold count parameter. */
590 rstp_set_bridge_transmit_hold_count__(struct rstp *rstp,
591 int new_transmit_hold_count)
592 OVS_REQUIRES(rstp_mutex)
594 if (rstp->transmit_hold_count != new_transmit_hold_count
595 && new_transmit_hold_count >= RSTP_MIN_TRANSMIT_HOLD_COUNT
596 && new_transmit_hold_count <= RSTP_MAX_TRANSMIT_HOLD_COUNT) {
599 VLOG_DBG("%s: set RSTP Transmit Hold Count to %d", rstp->name,
600 new_transmit_hold_count);
601 /* Resetting txCount on all ports [17.13]. */
603 rstp->transmit_hold_count = new_transmit_hold_count;
604 HMAP_FOR_EACH (p, node, &rstp->ports) {
611 rstp_set_bridge_transmit_hold_count(struct rstp *rstp,
612 int new_transmit_hold_count)
613 OVS_EXCLUDED(rstp_mutex)
615 ovs_mutex_lock(&rstp_mutex);
616 rstp_set_bridge_transmit_hold_count__(rstp, new_transmit_hold_count);
617 ovs_mutex_unlock(&rstp_mutex);
620 /* Sets the bridge migrate time parameter. */
622 rstp_set_bridge_migrate_time__(struct rstp *rstp)
623 OVS_REQUIRES(rstp_mutex)
625 VLOG_DBG("%s: set RSTP Migrate Time to %d", rstp->name,
627 /* 3 is the only acceptable value */
628 rstp->migrate_time = RSTP_MIGRATE_TIME;
631 /* Sets the bridge times. */
633 rstp_set_bridge_times__(struct rstp *rstp, int new_forward_delay,
634 int new_hello_time, int new_max_age,
636 OVS_REQUIRES(rstp_mutex)
638 VLOG_DBG("%s: set RSTP times to (%d, %d, %d, %d)", rstp->name,
639 new_forward_delay, new_hello_time, new_max_age, new_message_age);
640 if (new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
641 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
642 rstp->bridge_times.forward_delay = new_forward_delay;
644 if (new_hello_time == RSTP_BRIDGE_HELLO_TIME) {
645 rstp->bridge_times.hello_time = new_hello_time;
647 if (new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
648 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
649 rstp->bridge_times.max_age = new_max_age;
651 rstp->bridge_times.message_age = new_message_age;
654 /* Sets the port id, it is called by rstp_port_set_port_number__() or
655 * rstp_port_set_priority__().
658 set_port_id__(struct rstp_port *p)
659 OVS_REQUIRES(rstp_mutex)
664 /* [9.2.7] Port identifier. */
665 p->port_id = p->port_number | (p->priority << 8);
666 VLOG_DBG("%s: new RSTP port id "RSTP_PORT_ID_FMT"", rstp->name,
670 /* Sets the port priority. */
672 rstp_port_set_priority__(struct rstp_port *port, int priority)
673 OVS_REQUIRES(rstp_mutex)
675 if (port->priority != priority
676 && priority >= RSTP_MIN_PORT_PRIORITY
677 && priority <= RSTP_MAX_PORT_PRIORITY) {
678 VLOG_DBG("%s, port %u: set RSTP port priority to %d", port->rstp->name,
679 port->port_number, priority);
681 priority -= priority % RSTP_STEP_PORT_PRIORITY;
682 port->priority = priority;
684 port->selected = false;
685 port->reselect = true;
689 /* Checks if a port number is available. */
691 is_port_number_available__(struct rstp *rstp, int n, struct rstp_port *port)
692 OVS_REQUIRES(rstp_mutex)
694 if (n >= 1 && n <= RSTP_MAX_PORTS) {
695 struct rstp_port *p = rstp_get_port__(rstp, n);
697 return p == NULL || p == port;
703 rstp_first_free_number__(struct rstp *rstp, struct rstp_port *rstp_port)
704 OVS_REQUIRES(rstp_mutex)
708 while (free_number <= RSTP_MAX_PORTS) {
709 if (is_port_number_available__(rstp, free_number, rstp_port)) {
714 VLOG_DBG("%s, No free port number available.", rstp->name);
718 /* Sets the port number. */
720 rstp_port_set_port_number__(struct rstp_port *port, uint16_t port_number)
721 OVS_REQUIRES(rstp_mutex)
723 int old_port_number = port->port_number;
725 /* If new_port_number is available, use it, otherwise use the first free
726 * available port number. */
727 if (port->port_number != port_number || port_number == 0) {
729 is_port_number_available__(port->rstp, port_number, port)
731 : rstp_first_free_number__(port->rstp, port);
733 if (port->port_number != old_port_number) {
735 /* [17.13] is not clear. I suppose that a port number change
736 * should trigger reselection like a port priority change. */
737 port->selected = false;
738 port->reselect = true;
740 /* Adjust the ports hmap. */
741 if (!hmap_node_is_null(&port->node)) {
742 hmap_remove(&port->rstp->ports, &port->node);
744 hmap_insert(&port->rstp->ports, &port->node,
745 hash_int(port->port_number, 0));
747 VLOG_DBG("%s: set new RSTP port number %d", port->rstp->name,
753 /* Converts the link speed to a port path cost [Table 17-3]. */
755 rstp_convert_speed_to_cost(unsigned int speed)
759 value = speed >= 10000000 ? 2 /* 10 Tb/s. */
760 : speed >= 1000000 ? 20 /* 1 Tb/s. */
761 : speed >= 100000 ? 200 /* 100 Gb/s. */
762 : speed >= 10000 ? 2000 /* 10 Gb/s. */
763 : speed >= 1000 ? 20000 /* 1 Gb/s. */
764 : speed >= 100 ? 200000 /* 100 Mb/s. */
765 : speed >= 10 ? 2000000 /* 10 Mb/s. */
766 : speed >= 1 ? 20000000 /* 1 Mb/s. */
767 : RSTP_DEFAULT_PORT_PATH_COST; /* 100 Mb/s. */
772 /* Sets the port path cost. */
774 rstp_port_set_path_cost__(struct rstp_port *port, uint32_t path_cost)
775 OVS_REQUIRES(rstp_mutex)
777 if (port->port_path_cost != path_cost
778 && path_cost >= RSTP_MIN_PORT_PATH_COST
779 && path_cost <= RSTP_MAX_PORT_PATH_COST) {
780 VLOG_DBG("%s, port %u, set RSTP port path cost to %d",
781 port->rstp->name, port->port_number, path_cost);
783 port->port_path_cost = path_cost;
784 port->selected = false;
785 port->reselect = true;
789 /* Gets the root path cost. */
791 rstp_get_root_path_cost(const struct rstp *rstp)
792 OVS_EXCLUDED(rstp_mutex)
796 ovs_mutex_lock(&rstp_mutex);
797 cost = rstp->root_priority.root_path_cost;
798 ovs_mutex_unlock(&rstp_mutex);
802 /* Finds a port which needs to flush its own MAC learning table. A NULL
803 * pointer is returned if no port needs to flush its MAC learning table.
804 * '*port' needs to be NULL in the first call to start the iteration. If
805 * '*port' is passed as non-NULL, it must be the value set by the last
806 * invocation of this function.
808 * This function may only be called by the thread that creates and deletes
809 * ports. Otherwise this function is not thread safe, as the returned
810 * '*port' could become stale before it is used in the next invocation. */
812 rstp_check_and_reset_fdb_flush(struct rstp *rstp, struct rstp_port **port)
813 OVS_EXCLUDED(rstp_mutex)
817 ovs_mutex_lock(&rstp_mutex);
821 HMAP_FOR_EACH (p, node, &rstp->ports) {
828 } else { /* continue */
829 struct rstp_port *p = *port;
831 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
839 /* No port needs flushing. */
842 /* fdb_flush should be reset by the filtering database
843 * once the entries are removed if rstp_version is TRUE, and
844 * immediately if stp_version is TRUE.*/
846 (*port)->fdb_flush = false;
848 ovs_mutex_unlock(&rstp_mutex);
853 /* Finds a port whose state has changed, and returns the aux pointer set for
854 * the port. A NULL pointer is returned when no changed port is found. On
855 * return '*portp' contains the pointer to the rstp port that changed, or NULL
856 * if no changed port can be found.
858 * If '*portp' is passed as non-NULL, it must be the value set by the last
859 * invocation of this function.
861 * This function may only be called by the thread that creates and deletes
862 * ports. Otherwise this function is not thread safe, as the returned
863 * '*portp' could become stale before it is used in the next invocation. */
865 rstp_get_next_changed_port_aux(struct rstp *rstp, struct rstp_port **portp)
869 ovs_mutex_lock(&rstp_mutex);
870 if (*portp == NULL) {
873 HMAP_FOR_EACH (p, node, &rstp->ports) {
874 if (p->state_changed) {
875 p->state_changed = false;
881 } else { /* continue */
882 struct rstp_port *p = *portp;
884 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
885 if (p->state_changed) {
886 p->state_changed = false;
893 /* No changed port found. */
896 ovs_mutex_unlock(&rstp_mutex);
902 rstp_shift_root_learned_address(struct rstp *rstp)
906 ovs_mutex_lock(&rstp_mutex);
907 ret = rstp->root_changed;
908 ovs_mutex_unlock(&rstp_mutex);
914 rstp_get_old_root_aux(struct rstp *rstp)
918 ovs_mutex_lock(&rstp_mutex);
919 aux = rstp->old_root_aux;
920 ovs_mutex_unlock(&rstp_mutex);
926 rstp_get_new_root_aux(struct rstp *rstp)
930 ovs_mutex_lock(&rstp_mutex);
931 aux = rstp->new_root_aux;
932 ovs_mutex_unlock(&rstp_mutex);
938 rstp_reset_root_changed(struct rstp *rstp)
940 ovs_mutex_lock(&rstp_mutex);
941 rstp->root_changed = false;
942 ovs_mutex_unlock(&rstp_mutex);
945 /* Returns the port in 'rstp' with number 'port_number'.
947 * XXX: May only be called while concurrent deletion of ports is excluded. */
948 static struct rstp_port *
949 rstp_get_port__(struct rstp *rstp, uint16_t port_number)
950 OVS_REQUIRES(rstp_mutex)
952 struct rstp_port *port;
954 ovs_assert(rstp && port_number > 0 && port_number <= RSTP_MAX_PORTS);
956 HMAP_FOR_EACH_WITH_HASH (port, node, hash_int(port_number, 0),
958 if (port->port_number == port_number) {
966 rstp_get_port(struct rstp *rstp, uint16_t port_number)
967 OVS_EXCLUDED(rstp_mutex)
971 ovs_mutex_lock(&rstp_mutex);
972 p = rstp_get_port__(rstp, port_number);
973 ovs_mutex_unlock(&rstp_mutex);
978 rstp_get_port_aux__(struct rstp *rstp, uint16_t port_number)
979 OVS_REQUIRES(rstp_mutex)
982 p = rstp_get_port__(rstp, port_number);
989 /* Updates the port_enabled parameter. */
991 update_port_enabled__(struct rstp_port *p)
992 OVS_REQUIRES(rstp_mutex)
994 if (p->mac_operational && p->is_administrative_bridge_port
995 == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED) {
996 p->port_enabled = true;
998 p->port_enabled = false;
1002 /* Sets the port MAC_Operational parameter [6.4.2]. */
1004 rstp_port_set_mac_operational(struct rstp_port *p, bool new_mac_operational)
1005 OVS_EXCLUDED(rstp_mutex)
1009 ovs_mutex_lock(&rstp_mutex);
1011 if (p->mac_operational != new_mac_operational) {
1012 p->mac_operational = new_mac_operational;
1013 update_port_enabled__(p);
1014 rstp->changes = true;
1017 ovs_mutex_unlock(&rstp_mutex);
1020 /* Sets the port Administrative Bridge Port parameter. */
1022 rstp_port_set_administrative_bridge_port__(struct rstp_port *p,
1023 uint8_t admin_port_state,
1025 OVS_REQUIRES(rstp_mutex)
1027 VLOG_DBG("%s, port %u: set RSTP port admin-port-state to %d",
1028 p->rstp->name, p->port_number, admin_port_state);
1030 if (p->is_administrative_bridge_port != admin_port_state
1031 && (admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_DISABLED
1032 || admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED)) {
1033 p->is_administrative_bridge_port = admin_port_state;
1034 update_port_enabled__(p);
1036 if (!initializing) {
1037 struct rstp *rstp = p->rstp;
1039 rstp->changes = true;
1045 /* Sets the port oper_point_to_point_mac parameter. */
1047 rstp_port_set_oper_point_to_point_mac__(struct rstp_port *p,
1048 uint8_t new_oper_p2p_mac)
1049 OVS_REQUIRES(rstp_mutex)
1051 if (p->oper_point_to_point_mac != new_oper_p2p_mac
1052 && (new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_DISABLED
1053 || new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_ENABLED)) {
1055 p->oper_point_to_point_mac = new_oper_p2p_mac;
1056 update_port_enabled__(p);
1060 /* Initializes a port with the defaults values for its parameters. */
1062 rstp_initialize_port_defaults__(struct rstp_port *p)
1063 OVS_REQUIRES(rstp_mutex)
1065 rstp_port_set_administrative_bridge_port__(p,
1066 RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED,
1068 rstp_port_set_oper_point_to_point_mac__(p,
1069 RSTP_OPER_P2P_MAC_STATE_ENABLED);
1070 rstp_port_set_path_cost__(p, RSTP_DEFAULT_PORT_PATH_COST);
1071 rstp_port_set_admin_edge__(p, false);
1072 rstp_port_set_auto_edge__(p, true);
1073 rstp_port_set_mcheck__(p, false);
1075 /* Initialize state machines. */
1076 p->port_receive_sm_state = PORT_RECEIVE_SM_INIT;
1077 p->port_protocol_migration_sm_state = PORT_PROTOCOL_MIGRATION_SM_INIT;
1078 p->bridge_detection_sm_state = BRIDGE_DETECTION_SM_INIT;
1079 p->port_transmit_sm_state = PORT_TRANSMIT_SM_INIT;
1080 p->port_information_sm_state = PORT_INFORMATION_SM_INIT;
1081 p->port_role_transition_sm_state = PORT_ROLE_TRANSITION_SM_INIT;
1082 p->port_state_transition_sm_state = PORT_STATE_TRANSITION_SM_INIT;
1083 p->topology_change_sm_state = TOPOLOGY_CHANGE_SM_INIT;
1089 reinitialize_port__(struct rstp_port *p)
1090 OVS_REQUIRES(rstp_mutex)
1092 struct rstp_port temp_port;
1097 memset(p, 0, sizeof(struct rstp_port));
1099 p->ref_cnt = temp_port.ref_cnt;
1101 p->node = temp_port.node;
1102 p->aux = temp_port.aux;
1103 p->port_number = temp_port.port_number;
1104 p->port_priority = temp_port.port_priority;
1105 p->port_id = temp_port.port_id;
1106 p->rstp_state = RSTP_DISCARDING;
1108 rstp_initialize_port_defaults__(p);
1110 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" reinitialized.", rstp->name,
1115 reinitialize_port(struct rstp_port *p)
1116 OVS_EXCLUDED(rstp_mutex)
1118 ovs_mutex_lock(&rstp_mutex);
1119 reinitialize_port__(p);
1120 ovs_mutex_unlock(&rstp_mutex);
1123 /* Sets the port state. */
1125 rstp_port_set_state__(struct rstp_port *p, enum rstp_state state)
1126 OVS_REQUIRES(rstp_mutex)
1131 VLOG_DBG("%s, port %u: set RSTP port state %s -> %s", rstp->name,
1133 rstp_state_name(p->rstp_state), rstp_state_name(state));
1135 if (state != p->rstp_state && !p->state_changed) {
1136 p->state_changed = true;
1137 seq_change(connectivity_seq_get());
1139 p->rstp_state = state;
1143 rstp_port_set_state(struct rstp_port *p, enum rstp_state state)
1144 OVS_EXCLUDED(rstp_mutex)
1146 ovs_mutex_lock(&rstp_mutex);
1147 rstp_port_set_state__(p, state);
1148 ovs_mutex_unlock(&rstp_mutex);
1151 /* Adds a RSTP port. */
1153 rstp_add_port(struct rstp *rstp)
1154 OVS_EXCLUDED(rstp_mutex)
1156 struct rstp_port *p = xzalloc(sizeof *p);
1158 ovs_refcount_init(&p->ref_cnt);
1159 hmap_node_nullify(&p->node);
1161 ovs_mutex_lock(&rstp_mutex);
1163 rstp_port_set_priority__(p, RSTP_DEFAULT_PORT_PRIORITY);
1164 rstp_port_set_port_number__(p, 0);
1166 rstp_initialize_port_defaults__(p);
1167 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" initialized.", rstp->name,
1170 rstp_port_set_state__(p, RSTP_DISCARDING);
1171 rstp->changes = true;
1173 VLOG_DBG("%s: added port "RSTP_PORT_ID_FMT"", rstp->name, p->port_id);
1174 ovs_mutex_unlock(&rstp_mutex);
1178 /* Caller has to hold a reference to prevent 'rstp_port' from being deleted
1179 * while taking a new reference. */
1181 rstp_port_ref(const struct rstp_port *rp_)
1182 OVS_EXCLUDED(rstp_mutex)
1184 struct rstp_port *rp = CONST_CAST(struct rstp_port *, rp_);
1187 ovs_refcount_ref(&rp->ref_cnt);
1192 /* Frees RSTP struct. This can be caller by any thread. */
1194 rstp_port_unref(struct rstp_port *rp)
1195 OVS_EXCLUDED(rstp_mutex)
1197 if (rp && ovs_refcount_unref_relaxed(&rp->ref_cnt) == 1) {
1200 ovs_mutex_lock(&rstp_mutex);
1202 rstp_port_set_state__(rp, RSTP_DISABLED);
1203 hmap_remove(&rstp->ports, &rp->node);
1204 VLOG_DBG("%s: removed port "RSTP_PORT_ID_FMT"", rstp->name,
1206 ovs_mutex_unlock(&rstp_mutex);
1211 /* Sets the port Admin Edge parameter. */
1213 rstp_port_set_admin_edge__(struct rstp_port *port, bool admin_edge)
1214 OVS_REQUIRES(rstp_mutex)
1216 if (port->admin_edge != admin_edge) {
1217 VLOG_DBG("%s, port %u: set RSTP Admin Edge to %d", port->rstp->name,
1218 port->port_number, admin_edge);
1220 port->admin_edge = admin_edge;
1224 /* Sets the port Auto Edge parameter. */
1226 rstp_port_set_auto_edge__(struct rstp_port *port, bool auto_edge)
1227 OVS_REQUIRES(rstp_mutex)
1229 if (port->auto_edge != auto_edge) {
1230 VLOG_DBG("%s, port %u: set RSTP Auto Edge to %d", port->rstp->name,
1231 port->port_number, auto_edge);
1233 port->auto_edge = auto_edge;
1237 /* Sets the port admin_point_to_point_mac parameter. */
1238 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *port,
1239 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
1240 OVS_REQUIRES(rstp_mutex)
1242 VLOG_DBG("%s, port %u: set RSTP port admin-point-to-point-mac to %d",
1243 port->rstp->name, port->port_number, admin_p2p_mac_state);
1244 if (port->admin_point_to_point_mac != admin_p2p_mac_state) {
1245 if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_TRUE) {
1246 port->admin_point_to_point_mac = admin_p2p_mac_state;
1247 rstp_port_set_oper_point_to_point_mac__(
1248 port, RSTP_OPER_P2P_MAC_STATE_ENABLED);
1249 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_FALSE) {
1250 port->admin_point_to_point_mac = admin_p2p_mac_state;
1251 rstp_port_set_oper_point_to_point_mac__(
1252 port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
1253 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_AUTO) {
1254 /* If adminPointToPointMAC is set to Auto, then the value of
1255 * operPointToPointMAC is determined in accordance with the
1256 * specific procedures defined for the MAC entity concerned, as
1257 * defined in 6.5. If these procedures determine that the MAC
1258 * entity is connected to a point-to-point LAN, then
1259 * operPointToPointMAC is set TRUE; otherwise it is set FALSE.
1260 * In the absence of a specific definition of how to determine
1261 * whether the MAC is connected to a point-to-point LAN or not,
1262 * the value of operPointToPointMAC shall be FALSE. */
1263 port->admin_point_to_point_mac = admin_p2p_mac_state;
1264 rstp_port_set_oper_point_to_point_mac__(
1265 port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
1270 /* Sets the port mcheck parameter.
1271 * [17.19.13] May be set by management to force the Port Protocol Migration
1272 * state machine to transmit RST BPDUs for a MigrateTime (17.13.9) period, to
1273 * test whether all STP Bridges (17.4) on the attached LAN have been removed
1274 * and the Port can continue to transmit RSTP BPDUs. Setting mcheck has no
1275 * effect if stpVersion (17.20.12) is TRUE, i.e., the Bridge is operating in
1276 * STP Compatibility mode.
1279 rstp_port_set_mcheck__(struct rstp_port *port, bool mcheck)
1280 OVS_REQUIRES(rstp_mutex)
1282 if (mcheck == true && port->rstp->force_protocol_version >= 2) {
1283 port->mcheck = true;
1285 VLOG_DBG("%s, port %u: set RSTP mcheck to %d", port->rstp->name,
1286 port->port_number, mcheck);
1290 /* Returns the designated bridge id. */
1292 rstp_get_designated_id(const struct rstp *rstp)
1293 OVS_EXCLUDED(rstp_mutex)
1295 rstp_identifier designated_id;
1297 ovs_mutex_lock(&rstp_mutex);
1298 designated_id = rstp->root_priority.designated_bridge_id;
1299 ovs_mutex_unlock(&rstp_mutex);
1301 return designated_id;
1304 /* Returns the root bridge id. */
1306 rstp_get_root_id(const struct rstp *rstp)
1307 OVS_EXCLUDED(rstp_mutex)
1309 rstp_identifier root_id;
1311 ovs_mutex_lock(&rstp_mutex);
1312 root_id = rstp->root_priority.root_bridge_id;
1313 ovs_mutex_unlock(&rstp_mutex);
1318 /* Returns the designated port id. */
1320 rstp_get_designated_port_id(const struct rstp *rstp)
1321 OVS_EXCLUDED(rstp_mutex)
1323 uint16_t designated_port_id;
1325 ovs_mutex_lock(&rstp_mutex);
1326 designated_port_id = rstp->root_priority.designated_port_id;
1327 ovs_mutex_unlock(&rstp_mutex);
1329 return designated_port_id;
1332 /* Return the bridge port id. */
1334 rstp_get_bridge_port_id(const struct rstp *rstp)
1335 OVS_EXCLUDED(rstp_mutex)
1337 uint16_t bridge_port_id;
1339 ovs_mutex_lock(&rstp_mutex);
1340 bridge_port_id = rstp->root_priority.bridge_port_id;
1341 ovs_mutex_unlock(&rstp_mutex);
1343 return bridge_port_id;
1346 /* Returns true if the bridge believes to the be root of the spanning tree,
1350 rstp_is_root_bridge(const struct rstp *rstp)
1351 OVS_EXCLUDED(rstp_mutex)
1355 ovs_mutex_lock(&rstp_mutex);
1356 is_root = rstp->bridge_identifier ==
1357 rstp->root_priority.designated_bridge_id;
1358 ovs_mutex_unlock(&rstp_mutex);
1363 /* Returns the bridge ID of the bridge currently believed to be the root. */
1365 rstp_get_designated_root(const struct rstp *rstp)
1366 OVS_EXCLUDED(rstp_mutex)
1368 rstp_identifier designated_root;
1370 ovs_mutex_lock(&rstp_mutex);
1371 designated_root = rstp->root_priority.designated_bridge_id;
1372 ovs_mutex_unlock(&rstp_mutex);
1374 return designated_root;
1377 /* Returns the port connecting 'rstp' to the root bridge, or a null pointer if
1378 * there is no such port.
1381 rstp_get_root_port(struct rstp *rstp)
1382 OVS_EXCLUDED(rstp_mutex)
1384 struct rstp_port *p;
1386 ovs_mutex_lock(&rstp_mutex);
1387 HMAP_FOR_EACH (p, node, &rstp->ports) {
1388 if (p->port_id == rstp->root_port_id) {
1389 ovs_mutex_unlock(&rstp_mutex);
1393 ovs_mutex_unlock(&rstp_mutex);
1397 /* Returns the state of port 'p'. */
1399 rstp_port_get_state(const struct rstp_port *p)
1400 OVS_EXCLUDED(rstp_mutex)
1402 enum rstp_state state;
1404 ovs_mutex_lock(&rstp_mutex);
1405 state = p->rstp_state;
1406 ovs_mutex_unlock(&rstp_mutex);
1411 /* Retrieves port status. */
1413 rstp_port_get_status(const struct rstp_port *p, uint16_t *id,
1414 enum rstp_state *state, enum rstp_port_role *role,
1415 rstp_identifier *designated_bridge_id,
1416 uint16_t *designated_port_id,
1417 uint32_t *designated_path_cost, int *tx_count,
1418 int *rx_count, int *error_count, int *uptime)
1419 OVS_EXCLUDED(rstp_mutex)
1421 ovs_mutex_lock(&rstp_mutex);
1423 *state = p->rstp_state;
1426 *designated_bridge_id = p->port_priority.designated_bridge_id;
1427 *designated_port_id = p->port_priority.designated_port_id;
1428 *designated_path_cost = p->port_priority.root_path_cost;
1430 *tx_count = p->tx_count;
1431 *rx_count = p->rx_rstp_bpdu_cnt;
1432 *error_count = p->error_count;
1433 *uptime = p->uptime;
1434 ovs_mutex_unlock(&rstp_mutex);
1438 rstp_port_set(struct rstp_port *port, uint16_t port_num, int priority,
1439 uint32_t path_cost, bool is_admin_edge, bool is_auto_edge,
1440 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state,
1441 bool admin_port_state, bool do_mcheck, void *aux)
1442 OVS_EXCLUDED(rstp_mutex)
1444 ovs_mutex_lock(&rstp_mutex);
1446 rstp_port_set_priority__(port, priority);
1447 rstp_port_set_port_number__(port, port_num);
1448 rstp_port_set_path_cost__(port, path_cost);
1449 rstp_port_set_admin_edge__(port, is_admin_edge);
1450 rstp_port_set_auto_edge__(port, is_auto_edge);
1451 rstp_port_set_admin_point_to_point_mac__(port, admin_p2p_mac_state);
1452 rstp_port_set_administrative_bridge_port__(port, admin_port_state, false);
1453 rstp_port_set_mcheck__(port, do_mcheck);
1454 ovs_mutex_unlock(&rstp_mutex);
1457 /* Individual setters only used by test-rstp.c. */
1459 rstp_port_set_priority(struct rstp_port *port, int priority)
1460 OVS_EXCLUDED(rstp_mutex)
1462 ovs_mutex_lock(&rstp_mutex);
1463 rstp_port_set_priority__(port, priority);
1464 ovs_mutex_unlock(&rstp_mutex);
1468 rstp_port_set_path_cost(struct rstp_port *port, uint32_t path_cost)
1469 OVS_EXCLUDED(rstp_mutex)
1471 ovs_mutex_lock(&rstp_mutex);
1472 rstp_port_set_path_cost__(port, path_cost);
1473 ovs_mutex_unlock(&rstp_mutex);
1477 rstp_port_set_aux(struct rstp_port *port, void *aux)
1478 OVS_EXCLUDED(rstp_mutex)
1480 ovs_mutex_lock(&rstp_mutex);
1482 ovs_mutex_unlock(&rstp_mutex);
1486 static struct rstp *
1487 rstp_find(const char *name)
1488 OVS_REQUIRES(rstp_mutex)
1492 LIST_FOR_EACH (rstp, node, all_rstps) {
1493 if (!strcmp(rstp->name, name)) {
1501 rstp_unixctl_tcn(struct unixctl_conn *conn, int argc,
1502 const char *argv[], void *aux OVS_UNUSED)
1503 OVS_EXCLUDED(rstp_mutex)
1505 ovs_mutex_lock(&rstp_mutex);
1507 struct rstp *rstp = rstp_find(argv[1]);
1509 unixctl_command_reply_error(conn, "No such RSTP object");
1512 rstp->changes = true;
1516 LIST_FOR_EACH (rstp, node, all_rstps) {
1517 rstp->changes = true;
1521 unixctl_command_reply(conn, "OK");
1524 ovs_mutex_unlock(&rstp_mutex);