2 * Copyright (c) 2011-2014 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>
24 * References to IEEE 802.1D-2004 standard are enclosed in square brackets.
25 * E.g. [17.3], [Table 17-1], etc.
32 #include "rstp-common.h"
33 #include "rstp-state-machines.h"
34 #include <arpa/inet.h>
36 #include <netinet/in.h>
38 #include <sys/types.h>
39 #include "byte-order.h"
40 #include "connectivity.h"
42 #include "ofproto/ofproto.h"
43 #include "dp-packet.h"
48 #include "openvswitch/vlog.h"
50 VLOG_DEFINE_THIS_MODULE(rstp);
52 struct ovs_mutex rstp_mutex = OVS_MUTEX_INITIALIZER;
54 static struct ovs_list all_rstps__ = OVS_LIST_INITIALIZER(&all_rstps__);
55 static struct ovs_list *const all_rstps OVS_GUARDED_BY(rstp_mutex) = &all_rstps__;
57 /* Internal use only. */
58 static void rstp_set_bridge_address__(struct rstp *, rstp_identifier)
59 OVS_REQUIRES(rstp_mutex);
60 static void rstp_set_bridge_priority__(struct rstp *, int new_priority)
61 OVS_REQUIRES(rstp_mutex);
62 static void rstp_set_bridge_ageing_time__(struct rstp *, int new_ageing_time)
63 OVS_REQUIRES(rstp_mutex);
64 static void rstp_set_bridge_force_protocol_version__(struct rstp *,
65 enum rstp_force_protocol_version)
66 OVS_REQUIRES(rstp_mutex);
67 static void rstp_set_bridge_hello_time__(struct rstp *)
68 OVS_REQUIRES(rstp_mutex);
69 static void rstp_set_bridge_max_age__(struct rstp *, int new_max_age)
70 OVS_REQUIRES(rstp_mutex);
71 static void rstp_set_bridge_forward_delay__(struct rstp *, int new_forward_delay)
72 OVS_REQUIRES(rstp_mutex);
73 static void rstp_set_bridge_transmit_hold_count__(struct rstp *,
74 int new_transmit_hold_count)
75 OVS_REQUIRES(rstp_mutex);
76 static void rstp_set_bridge_migrate_time__(struct rstp *)
77 OVS_REQUIRES(rstp_mutex);
78 static void rstp_set_bridge_times__(struct rstp *, int new_forward_delay,
79 int new_hello_time, int new_max_age,
81 OVS_REQUIRES(rstp_mutex);
83 static struct rstp_port *rstp_get_port__(struct rstp *rstp,
85 OVS_REQUIRES(rstp_mutex);
86 static void set_port_id__(struct rstp_port *)
87 OVS_REQUIRES(rstp_mutex);
88 static void update_port_enabled__(struct rstp_port *)
89 OVS_REQUIRES(rstp_mutex);
90 static void set_bridge_priority__(struct rstp *)
91 OVS_REQUIRES(rstp_mutex);
92 static void reinitialize_rstp__(struct rstp *)
93 OVS_REQUIRES(rstp_mutex);
94 static bool is_port_number_available__(struct rstp *, int, struct rstp_port *)
95 OVS_REQUIRES(rstp_mutex);
96 static uint16_t rstp_first_free_number__(struct rstp *, struct rstp_port *)
97 OVS_REQUIRES(rstp_mutex);
98 static void rstp_initialize_port_defaults__(struct rstp_port *)
99 OVS_REQUIRES(rstp_mutex);
100 static void rstp_port_set_priority__(struct rstp_port *, int priority)
101 OVS_REQUIRES(rstp_mutex);
102 static void rstp_port_set_port_number__(struct rstp_port *,
103 uint16_t port_number)
104 OVS_REQUIRES(rstp_mutex);
105 static void rstp_port_set_path_cost__(struct rstp_port *, uint32_t path_cost)
106 OVS_REQUIRES(rstp_mutex);
107 static void rstp_port_set_administrative_bridge_port__(struct rstp_port *,
108 uint8_t admin_port_state,
110 OVS_REQUIRES(rstp_mutex);
111 static void rstp_port_set_admin_edge__(struct rstp_port *, bool admin_edge)
112 OVS_REQUIRES(rstp_mutex);
113 static void rstp_port_set_auto_edge__(struct rstp_port *, bool auto_edge)
114 OVS_REQUIRES(rstp_mutex);
115 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *,
116 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
117 OVS_REQUIRES(rstp_mutex);
118 static void rstp_port_set_mcheck__(struct rstp_port *, bool mcheck)
119 OVS_REQUIRES(rstp_mutex);
120 static void reinitialize_port__(struct rstp_port *p)
121 OVS_REQUIRES(rstp_mutex);
124 rstp_state_name(enum rstp_state state)
131 case RSTP_FORWARDING:
133 case RSTP_DISCARDING:
141 rstp_port_role_name(enum rstp_port_role role)
146 case ROLE_DESIGNATED:
159 /* Caller has to hold a reference to prevent 'rstp' from being deleted
160 * while taking a new reference. */
162 rstp_ref(struct rstp *rstp)
163 OVS_EXCLUDED(rstp_mutex)
166 ovs_refcount_ref(&rstp->ref_cnt);
171 /* Frees RSTP struct when reference count reaches zero. */
173 rstp_unref(struct rstp *rstp)
174 OVS_EXCLUDED(rstp_mutex)
176 if (rstp && ovs_refcount_unref_relaxed(&rstp->ref_cnt) == 1) {
177 ovs_mutex_lock(&rstp_mutex);
179 /* Each RSTP port points back to struct rstp without holding a
180 * reference for that pointer. This is OK as we never move
181 * ports from one bridge to another, and holders always
182 * release their ports before releasing the bridge. This
183 * means that there should be not ports at this time. */
184 ovs_assert(hmap_is_empty(&rstp->ports));
186 list_remove(&rstp->node);
187 ovs_mutex_unlock(&rstp_mutex);
193 /* Returns the port number. Mutex is needed to guard against
194 * concurrent reinitialization (which can temporarily clear the
197 rstp_port_get_number(const struct rstp_port *p)
198 OVS_EXCLUDED(rstp_mutex)
202 ovs_mutex_lock(&rstp_mutex);
203 number = p->port_number;
204 ovs_mutex_unlock(&rstp_mutex);
209 static void rstp_unixctl_tcn(struct unixctl_conn *, int argc,
210 const char *argv[], void *aux);
212 /* Decrements the State Machines' timers. */
214 rstp_tick_timers(struct rstp *rstp)
215 OVS_EXCLUDED(rstp_mutex)
217 ovs_mutex_lock(&rstp_mutex);
218 decrease_rstp_port_timers__(rstp);
219 ovs_mutex_unlock(&rstp_mutex);
222 /* Processes an incoming BPDU. */
224 rstp_port_received_bpdu(struct rstp_port *rp, const void *bpdu,
226 OVS_EXCLUDED(rstp_mutex)
228 ovs_mutex_lock(&rstp_mutex);
229 /* Only process packets on ports that have RSTP enabled. */
230 if (rp && rp->rstp_state != RSTP_DISABLED) {
231 process_received_bpdu__(rp, bpdu, bpdu_size);
233 ovs_mutex_unlock(&rstp_mutex);
238 OVS_EXCLUDED(rstp_mutex)
240 unixctl_command_register("rstp/tcn", "[bridge]", 0, 1, rstp_unixctl_tcn,
244 /* Creates and returns a new RSTP instance that initially has no ports. */
246 rstp_create(const char *name, rstp_identifier bridge_address,
247 void (*send_bpdu)(struct dp_packet *bpdu, void *port_aux,
250 OVS_EXCLUDED(rstp_mutex)
254 VLOG_DBG("Creating RSTP instance");
256 rstp = xzalloc(sizeof *rstp);
257 rstp->name = xstrdup(name);
259 /* Initialize the ports map before calling any setters,
260 * so that the state machines will see an empty ports map. */
261 hmap_init(&rstp->ports);
263 ovs_mutex_lock(&rstp_mutex);
264 /* Set bridge address. */
265 rstp_set_bridge_address__(rstp, bridge_address);
266 /* Set default parameters values. */
267 rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
268 rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
269 rstp_set_bridge_force_protocol_version__(rstp, FPV_DEFAULT);
270 rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
271 rstp_set_bridge_hello_time__(rstp);
272 rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
273 rstp_set_bridge_migrate_time__(rstp);
274 rstp_set_bridge_transmit_hold_count__(rstp,
275 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
276 rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
277 RSTP_BRIDGE_HELLO_TIME,
278 RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
279 rstp->send_bpdu = send_bpdu;
281 rstp->changes = false;
283 rstp->old_root_aux = NULL;
284 rstp->new_root_aux = NULL;
286 ovs_refcount_init(&rstp->ref_cnt);
288 list_push_back(all_rstps, &rstp->node);
289 ovs_mutex_unlock(&rstp_mutex);
291 VLOG_DBG("RSTP instance creation done");
295 /* Called by rstp_set_bridge_address() and rstp_set_bridge_priority(),
296 * it updates the bridge priority vector according to the values passed by
300 set_bridge_priority__(struct rstp *rstp)
301 OVS_REQUIRES(rstp_mutex)
305 rstp->bridge_priority.root_bridge_id = rstp->bridge_identifier;
306 rstp->bridge_priority.designated_bridge_id = rstp->bridge_identifier;
307 VLOG_DBG("%s: new bridge identifier: "RSTP_ID_FMT"", rstp->name,
308 RSTP_ID_ARGS(rstp->bridge_identifier));
310 /* [17.13] When the bridge address changes, recalculates all priority
313 HMAP_FOR_EACH (p, node, &rstp->ports) {
317 rstp->changes = true;
318 updt_roles_tree__(rstp);
321 /* Sets the bridge address. */
323 rstp_set_bridge_address__(struct rstp *rstp, rstp_identifier bridge_address)
324 OVS_REQUIRES(rstp_mutex)
326 VLOG_DBG("%s: set bridge address to: "RSTP_ID_FMT"", rstp->name,
327 RSTP_ID_ARGS(bridge_address));
328 if (rstp->address != bridge_address) {
329 rstp->address = bridge_address;
330 rstp->bridge_identifier &= 0xffff000000000000ULL;
331 rstp->bridge_identifier |= bridge_address;
332 set_bridge_priority__(rstp);
336 /* Sets the bridge address. */
338 rstp_set_bridge_address(struct rstp *rstp, rstp_identifier bridge_address)
339 OVS_EXCLUDED(rstp_mutex)
341 ovs_mutex_lock(&rstp_mutex);
342 rstp_set_bridge_address__(rstp, bridge_address);
343 ovs_mutex_unlock(&rstp_mutex);
347 rstp_get_name(const struct rstp *rstp)
348 OVS_EXCLUDED(rstp_mutex)
352 ovs_mutex_lock(&rstp_mutex);
354 ovs_mutex_unlock(&rstp_mutex);
359 rstp_get_bridge_id(const struct rstp *rstp)
360 OVS_EXCLUDED(rstp_mutex)
362 rstp_identifier bridge_id;
364 ovs_mutex_lock(&rstp_mutex);
365 bridge_id = rstp->bridge_identifier;
366 ovs_mutex_unlock(&rstp_mutex);
371 /* Sets the bridge priority. */
373 rstp_set_bridge_priority__(struct rstp *rstp, int new_priority)
374 OVS_REQUIRES(rstp_mutex)
376 new_priority = ROUND_DOWN(new_priority, RSTP_PRIORITY_STEP);
378 if (rstp->priority != new_priority
379 && new_priority >= RSTP_MIN_PRIORITY
380 && new_priority <= RSTP_MAX_PRIORITY) {
381 VLOG_DBG("%s: set bridge priority to %d", rstp->name, new_priority);
383 rstp->priority = new_priority;
384 rstp->bridge_identifier &= 0x0000ffffffffffffULL;
385 rstp->bridge_identifier |= (uint64_t)new_priority << 48;
386 set_bridge_priority__(rstp);
391 rstp_set_bridge_priority(struct rstp *rstp, int new_priority)
392 OVS_EXCLUDED(rstp_mutex)
394 ovs_mutex_lock(&rstp_mutex);
395 rstp_set_bridge_priority__(rstp, new_priority);
396 ovs_mutex_unlock(&rstp_mutex);
399 /* Sets the bridge ageing time. */
401 rstp_set_bridge_ageing_time__(struct rstp *rstp, int new_ageing_time)
402 OVS_REQUIRES(rstp_mutex)
404 if (new_ageing_time >= RSTP_MIN_AGEING_TIME
405 && new_ageing_time <= RSTP_MAX_AGEING_TIME) {
406 VLOG_DBG("%s: set ageing time to %d", rstp->name, new_ageing_time);
408 rstp->ageing_time = new_ageing_time;
413 rstp_set_bridge_ageing_time(struct rstp *rstp, int new_ageing_time)
414 OVS_EXCLUDED(rstp_mutex)
416 ovs_mutex_lock(&rstp_mutex);
417 rstp_set_bridge_ageing_time__(rstp, new_ageing_time);
418 ovs_mutex_unlock(&rstp_mutex);
421 /* Reinitializes RSTP when switching from RSTP mode to STP mode
425 reinitialize_rstp__(struct rstp *rstp)
426 OVS_REQUIRES(rstp_mutex)
429 static struct hmap ports;
432 /* Copy rstp in temp */
436 /* stop and clear rstp */
437 memset(rstp, 0, sizeof(struct rstp));
439 /* Initialize rstp. */
440 rstp->name = temp.name;
442 /* Initialize the ports hmap before calling any setters,
443 * so that the state machines will see an empty ports list. */
444 hmap_init(&rstp->ports);
446 /* Set bridge address. */
447 rstp_set_bridge_address__(rstp, temp.address);
448 /* Set default parameters values. */
449 rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
450 rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
451 rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
452 rstp_set_bridge_hello_time__(rstp);
453 rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
454 rstp_set_bridge_migrate_time__(rstp);
455 rstp_set_bridge_transmit_hold_count__(rstp,
456 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
457 rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
458 RSTP_BRIDGE_HELLO_TIME,
459 RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
461 rstp->send_bpdu = temp.send_bpdu;
462 rstp->aux = temp.aux;
463 rstp->node = temp.node;
464 rstp->changes = false;
470 HMAP_FOR_EACH (p, node, &rstp->ports) {
471 reinitialize_port__(p);
474 rstp->ref_cnt = temp.ref_cnt;
477 /* Sets the force protocol version parameter. */
479 rstp_set_bridge_force_protocol_version__(struct rstp *rstp,
480 enum rstp_force_protocol_version new_force_protocol_version)
481 OVS_REQUIRES(rstp_mutex)
483 if (new_force_protocol_version != rstp->force_protocol_version &&
484 (new_force_protocol_version == FPV_STP_COMPATIBILITY ||
485 new_force_protocol_version == FPV_DEFAULT)) {
486 VLOG_DBG("%s: set bridge Force Protocol Version to %d", rstp->name,
487 new_force_protocol_version);
489 /* [17.13] The Spanning Tree Protocol Entity shall be reinitialized,
490 * as specified by the assertion of BEGIN (17.18.1) in the state
491 * machine specification.
493 reinitialize_rstp__(rstp);
494 rstp->force_protocol_version = new_force_protocol_version;
495 if (rstp->force_protocol_version < 2) {
496 rstp->stp_version = true;
497 rstp->rstp_version = false;
499 rstp->stp_version = false;
500 rstp->rstp_version = true;
502 rstp->changes = true;
508 rstp_set_bridge_force_protocol_version(struct rstp *rstp,
509 enum rstp_force_protocol_version new_force_protocol_version)
510 OVS_EXCLUDED(rstp_mutex)
512 ovs_mutex_lock(&rstp_mutex);
513 rstp_set_bridge_force_protocol_version__(rstp, new_force_protocol_version);
514 ovs_mutex_unlock(&rstp_mutex);
517 /* Sets the bridge Hello Time parameter. */
519 rstp_set_bridge_hello_time__(struct rstp *rstp)
520 OVS_REQUIRES(rstp_mutex)
522 VLOG_DBG("%s: set RSTP Hello Time to %d", rstp->name,
523 RSTP_BRIDGE_HELLO_TIME);
524 /* 2 is the only acceptable value. */
525 rstp->bridge_hello_time = RSTP_BRIDGE_HELLO_TIME;
528 /* Sets the bridge max age parameter. */
530 rstp_set_bridge_max_age__(struct rstp *rstp, int new_max_age)
531 OVS_REQUIRES(rstp_mutex)
533 if (rstp->bridge_max_age != new_max_age
534 && new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
535 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
537 if ((2 * (rstp->bridge_forward_delay - 1) >= new_max_age)
538 && (new_max_age >= 2 * rstp->bridge_hello_time)) {
539 VLOG_DBG("%s: set RSTP bridge Max Age to %d", rstp->name,
542 rstp->bridge_max_age = new_max_age;
543 rstp->bridge_times.max_age = new_max_age;
544 rstp->changes = true;
545 updt_roles_tree__(rstp);
551 rstp_set_bridge_max_age(struct rstp *rstp, int new_max_age)
552 OVS_EXCLUDED(rstp_mutex)
554 ovs_mutex_lock(&rstp_mutex);
555 rstp_set_bridge_max_age__(rstp, new_max_age);
556 ovs_mutex_unlock(&rstp_mutex);
559 /* Sets the bridge forward delay parameter. */
561 rstp_set_bridge_forward_delay__(struct rstp *rstp, int new_forward_delay)
562 OVS_REQUIRES(rstp_mutex)
564 if (rstp->bridge_forward_delay != new_forward_delay
565 && new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
566 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
567 if (2 * (new_forward_delay - 1) >= rstp->bridge_max_age) {
568 VLOG_DBG("%s: set RSTP Forward Delay to %d", rstp->name,
570 rstp->bridge_forward_delay = new_forward_delay;
571 rstp->bridge_times.forward_delay = new_forward_delay;
572 rstp->changes = true;
573 updt_roles_tree__(rstp);
579 rstp_set_bridge_forward_delay(struct rstp *rstp, int new_forward_delay)
580 OVS_EXCLUDED(rstp_mutex)
582 ovs_mutex_lock(&rstp_mutex);
583 rstp_set_bridge_forward_delay__(rstp, new_forward_delay);
584 ovs_mutex_unlock(&rstp_mutex);
587 /* Sets the bridge transmit hold count parameter. */
589 rstp_set_bridge_transmit_hold_count__(struct rstp *rstp,
590 int new_transmit_hold_count)
591 OVS_REQUIRES(rstp_mutex)
593 if (rstp->transmit_hold_count != new_transmit_hold_count
594 && new_transmit_hold_count >= RSTP_MIN_TRANSMIT_HOLD_COUNT
595 && new_transmit_hold_count <= RSTP_MAX_TRANSMIT_HOLD_COUNT) {
598 VLOG_DBG("%s: set RSTP Transmit Hold Count to %d", rstp->name,
599 new_transmit_hold_count);
600 /* Resetting txCount on all ports [17.13]. */
602 rstp->transmit_hold_count = new_transmit_hold_count;
603 HMAP_FOR_EACH (p, node, &rstp->ports) {
610 rstp_set_bridge_transmit_hold_count(struct rstp *rstp,
611 int new_transmit_hold_count)
612 OVS_EXCLUDED(rstp_mutex)
614 ovs_mutex_lock(&rstp_mutex);
615 rstp_set_bridge_transmit_hold_count__(rstp, new_transmit_hold_count);
616 ovs_mutex_unlock(&rstp_mutex);
619 /* Sets the bridge migrate time parameter. */
621 rstp_set_bridge_migrate_time__(struct rstp *rstp)
622 OVS_REQUIRES(rstp_mutex)
624 VLOG_DBG("%s: set RSTP Migrate Time to %d", rstp->name,
626 /* 3 is the only acceptable value */
627 rstp->migrate_time = RSTP_MIGRATE_TIME;
630 /* Sets the bridge times. */
632 rstp_set_bridge_times__(struct rstp *rstp, int new_forward_delay,
633 int new_hello_time, int new_max_age,
635 OVS_REQUIRES(rstp_mutex)
637 VLOG_DBG("%s: set RSTP times to (%d, %d, %d, %d)", rstp->name,
638 new_forward_delay, new_hello_time, new_max_age, new_message_age);
639 if (new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
640 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
641 rstp->bridge_times.forward_delay = new_forward_delay;
643 if (new_hello_time == RSTP_BRIDGE_HELLO_TIME) {
644 rstp->bridge_times.hello_time = new_hello_time;
646 if (new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
647 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
648 rstp->bridge_times.max_age = new_max_age;
650 rstp->bridge_times.message_age = new_message_age;
653 /* Sets the port id, it is called by rstp_port_set_port_number__() or
654 * rstp_port_set_priority__().
657 set_port_id__(struct rstp_port *p)
658 OVS_REQUIRES(rstp_mutex)
663 /* [9.2.7] Port identifier. */
664 p->port_id = p->port_number | (p->priority << 8);
665 VLOG_DBG("%s: new RSTP port id "RSTP_PORT_ID_FMT"", rstp->name,
669 /* Sets the port priority. */
671 rstp_port_set_priority__(struct rstp_port *port, int priority)
672 OVS_REQUIRES(rstp_mutex)
674 if (port->priority != priority
675 && priority >= RSTP_MIN_PORT_PRIORITY
676 && priority <= RSTP_MAX_PORT_PRIORITY) {
677 VLOG_DBG("%s, port %u: set RSTP port priority to %d", port->rstp->name,
678 port->port_number, priority);
680 priority -= priority % RSTP_STEP_PORT_PRIORITY;
681 port->priority = priority;
683 port->selected = false;
684 port->reselect = true;
688 /* Checks if a port number is available. */
690 is_port_number_available__(struct rstp *rstp, int n, struct rstp_port *port)
691 OVS_REQUIRES(rstp_mutex)
693 if (n >= 1 && n <= RSTP_MAX_PORTS) {
694 struct rstp_port *p = rstp_get_port__(rstp, n);
696 return p == NULL || p == port;
702 rstp_first_free_number__(struct rstp *rstp, struct rstp_port *rstp_port)
703 OVS_REQUIRES(rstp_mutex)
707 while (free_number <= RSTP_MAX_PORTS) {
708 if (is_port_number_available__(rstp, free_number, rstp_port)) {
713 VLOG_DBG("%s, No free port number available.", rstp->name);
717 /* Sets the port number. */
719 rstp_port_set_port_number__(struct rstp_port *port, uint16_t port_number)
720 OVS_REQUIRES(rstp_mutex)
722 int old_port_number = port->port_number;
724 /* If new_port_number is available, use it, otherwise use the first free
725 * available port number. */
726 if (port->port_number != port_number || port_number == 0) {
728 is_port_number_available__(port->rstp, port_number, port)
730 : rstp_first_free_number__(port->rstp, port);
732 if (port->port_number != old_port_number) {
734 /* [17.13] is not clear. I suppose that a port number change
735 * should trigger reselection like a port priority change. */
736 port->selected = false;
737 port->reselect = true;
739 /* Adjust the ports hmap. */
740 if (!hmap_node_is_null(&port->node)) {
741 hmap_remove(&port->rstp->ports, &port->node);
743 hmap_insert(&port->rstp->ports, &port->node,
744 hash_int(port->port_number, 0));
746 VLOG_DBG("%s: set new RSTP port number %d", port->rstp->name,
752 /* Converts the link speed to a port path cost [Table 17-3]. */
754 rstp_convert_speed_to_cost(unsigned int speed)
758 value = speed >= 10000000 ? 2 /* 10 Tb/s. */
759 : speed >= 1000000 ? 20 /* 1 Tb/s. */
760 : speed >= 100000 ? 200 /* 100 Gb/s. */
761 : speed >= 10000 ? 2000 /* 10 Gb/s. */
762 : speed >= 1000 ? 20000 /* 1 Gb/s. */
763 : speed >= 100 ? 200000 /* 100 Mb/s. */
764 : speed >= 10 ? 2000000 /* 10 Mb/s. */
765 : speed >= 1 ? 20000000 /* 1 Mb/s. */
766 : RSTP_DEFAULT_PORT_PATH_COST; /* 100 Mb/s. */
771 /* Sets the port path cost. */
773 rstp_port_set_path_cost__(struct rstp_port *port, uint32_t path_cost)
774 OVS_REQUIRES(rstp_mutex)
776 if (port->port_path_cost != path_cost
777 && path_cost >= RSTP_MIN_PORT_PATH_COST
778 && path_cost <= RSTP_MAX_PORT_PATH_COST) {
779 VLOG_DBG("%s, port %u, set RSTP port path cost to %d",
780 port->rstp->name, port->port_number, path_cost);
782 port->port_path_cost = path_cost;
783 port->selected = false;
784 port->reselect = true;
788 /* Gets the root path cost. */
790 rstp_get_root_path_cost(const struct rstp *rstp)
791 OVS_EXCLUDED(rstp_mutex)
795 ovs_mutex_lock(&rstp_mutex);
796 cost = rstp->root_priority.root_path_cost;
797 ovs_mutex_unlock(&rstp_mutex);
801 /* Finds a port which needs to flush its own MAC learning table. A NULL
802 * pointer is returned if no port needs to flush its MAC learning table.
803 * '*port' needs to be NULL in the first call to start the iteration. If
804 * '*port' is passed as non-NULL, it must be the value set by the last
805 * invocation of this function.
807 * This function may only be called by the thread that creates and deletes
808 * ports. Otherwise this function is not thread safe, as the returned
809 * '*port' could become stale before it is used in the next invocation. */
811 rstp_check_and_reset_fdb_flush(struct rstp *rstp, struct rstp_port **port)
812 OVS_EXCLUDED(rstp_mutex)
816 ovs_mutex_lock(&rstp_mutex);
820 HMAP_FOR_EACH (p, node, &rstp->ports) {
827 } else { /* continue */
828 struct rstp_port *p = *port;
830 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
838 /* No port needs flushing. */
841 /* fdb_flush should be reset by the filtering database
842 * once the entries are removed if rstp_version is TRUE, and
843 * immediately if stp_version is TRUE.*/
845 (*port)->fdb_flush = false;
847 ovs_mutex_unlock(&rstp_mutex);
852 /* Finds a port whose state has changed, and returns the aux pointer set for
853 * the port. A NULL pointer is returned when no changed port is found. On
854 * return '*portp' contains the pointer to the rstp port that changed, or NULL
855 * if no changed port can be found.
857 * If '*portp' is passed as non-NULL, it must be the value set by the last
858 * invocation of this function.
860 * This function may only be called by the thread that creates and deletes
861 * ports. Otherwise this function is not thread safe, as the returned
862 * '*portp' could become stale before it is used in the next invocation. */
864 rstp_get_next_changed_port_aux(struct rstp *rstp, struct rstp_port **portp)
868 ovs_mutex_lock(&rstp_mutex);
869 if (*portp == NULL) {
872 HMAP_FOR_EACH (p, node, &rstp->ports) {
873 if (p->state_changed) {
874 p->state_changed = false;
880 } else { /* continue */
881 struct rstp_port *p = *portp;
883 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
884 if (p->state_changed) {
885 p->state_changed = false;
892 /* No changed port found. */
895 ovs_mutex_unlock(&rstp_mutex);
901 rstp_shift_root_learned_address(struct rstp *rstp)
905 ovs_mutex_lock(&rstp_mutex);
906 ret = rstp->root_changed;
907 ovs_mutex_unlock(&rstp_mutex);
913 rstp_get_old_root_aux(struct rstp *rstp)
917 ovs_mutex_lock(&rstp_mutex);
918 aux = rstp->old_root_aux;
919 ovs_mutex_unlock(&rstp_mutex);
925 rstp_get_new_root_aux(struct rstp *rstp)
929 ovs_mutex_lock(&rstp_mutex);
930 aux = rstp->new_root_aux;
931 ovs_mutex_unlock(&rstp_mutex);
937 rstp_reset_root_changed(struct rstp *rstp)
939 ovs_mutex_lock(&rstp_mutex);
940 rstp->root_changed = false;
941 ovs_mutex_unlock(&rstp_mutex);
944 /* Returns the port in 'rstp' with number 'port_number'.
946 * XXX: May only be called while concurrent deletion of ports is excluded. */
947 static struct rstp_port *
948 rstp_get_port__(struct rstp *rstp, uint16_t port_number)
949 OVS_REQUIRES(rstp_mutex)
951 struct rstp_port *port;
953 ovs_assert(rstp && port_number > 0 && port_number <= RSTP_MAX_PORTS);
955 HMAP_FOR_EACH_WITH_HASH (port, node, hash_int(port_number, 0),
957 if (port->port_number == port_number) {
965 rstp_get_port(struct rstp *rstp, uint16_t port_number)
966 OVS_EXCLUDED(rstp_mutex)
970 ovs_mutex_lock(&rstp_mutex);
971 p = rstp_get_port__(rstp, port_number);
972 ovs_mutex_unlock(&rstp_mutex);
977 rstp_get_port_aux__(struct rstp *rstp, uint16_t port_number)
978 OVS_REQUIRES(rstp_mutex)
981 p = rstp_get_port__(rstp, port_number);
988 /* Updates the port_enabled parameter. */
990 update_port_enabled__(struct rstp_port *p)
991 OVS_REQUIRES(rstp_mutex)
993 if (p->mac_operational && p->is_administrative_bridge_port
994 == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED) {
995 p->port_enabled = true;
997 p->port_enabled = false;
1001 /* Sets the port MAC_Operational parameter [6.4.2]. */
1003 rstp_port_set_mac_operational(struct rstp_port *p, bool new_mac_operational)
1004 OVS_EXCLUDED(rstp_mutex)
1008 ovs_mutex_lock(&rstp_mutex);
1010 if (p->mac_operational != new_mac_operational) {
1011 p->mac_operational = new_mac_operational;
1012 update_port_enabled__(p);
1013 rstp->changes = true;
1016 ovs_mutex_unlock(&rstp_mutex);
1019 /* Sets the port Administrative Bridge Port parameter. */
1021 rstp_port_set_administrative_bridge_port__(struct rstp_port *p,
1022 uint8_t admin_port_state,
1024 OVS_REQUIRES(rstp_mutex)
1026 VLOG_DBG("%s, port %u: set RSTP port admin-port-state to %d",
1027 p->rstp->name, p->port_number, admin_port_state);
1029 if (p->is_administrative_bridge_port != admin_port_state
1030 && (admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_DISABLED
1031 || admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED)) {
1032 p->is_administrative_bridge_port = admin_port_state;
1033 update_port_enabled__(p);
1035 if (!initializing) {
1036 struct rstp *rstp = p->rstp;
1038 rstp->changes = true;
1044 /* Sets the port oper_point_to_point_mac parameter. */
1046 rstp_port_set_oper_point_to_point_mac__(struct rstp_port *p,
1047 uint8_t new_oper_p2p_mac)
1048 OVS_REQUIRES(rstp_mutex)
1050 if (p->oper_point_to_point_mac != new_oper_p2p_mac
1051 && (new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_DISABLED
1052 || new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_ENABLED)) {
1054 p->oper_point_to_point_mac = new_oper_p2p_mac;
1055 update_port_enabled__(p);
1059 /* Initializes a port with the defaults values for its parameters. */
1061 rstp_initialize_port_defaults__(struct rstp_port *p)
1062 OVS_REQUIRES(rstp_mutex)
1064 rstp_port_set_administrative_bridge_port__(p,
1065 RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED,
1067 rstp_port_set_oper_point_to_point_mac__(p,
1068 RSTP_OPER_P2P_MAC_STATE_ENABLED);
1069 rstp_port_set_path_cost__(p, RSTP_DEFAULT_PORT_PATH_COST);
1070 rstp_port_set_admin_edge__(p, false);
1071 rstp_port_set_auto_edge__(p, true);
1072 rstp_port_set_mcheck__(p, false);
1074 /* Initialize state machines. */
1075 p->port_receive_sm_state = PORT_RECEIVE_SM_INIT;
1076 p->port_protocol_migration_sm_state = PORT_PROTOCOL_MIGRATION_SM_INIT;
1077 p->bridge_detection_sm_state = BRIDGE_DETECTION_SM_INIT;
1078 p->port_transmit_sm_state = PORT_TRANSMIT_SM_INIT;
1079 p->port_information_sm_state = PORT_INFORMATION_SM_INIT;
1080 p->port_role_transition_sm_state = PORT_ROLE_TRANSITION_SM_INIT;
1081 p->port_state_transition_sm_state = PORT_STATE_TRANSITION_SM_INIT;
1082 p->topology_change_sm_state = TOPOLOGY_CHANGE_SM_INIT;
1088 reinitialize_port__(struct rstp_port *p)
1089 OVS_REQUIRES(rstp_mutex)
1091 struct rstp_port temp_port;
1096 memset(p, 0, sizeof(struct rstp_port));
1098 p->ref_cnt = temp_port.ref_cnt;
1100 p->node = temp_port.node;
1101 p->aux = temp_port.aux;
1102 p->port_number = temp_port.port_number;
1103 p->port_priority = temp_port.port_priority;
1104 p->port_id = temp_port.port_id;
1105 p->rstp_state = RSTP_DISCARDING;
1107 rstp_initialize_port_defaults__(p);
1109 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" reinitialized.", rstp->name,
1114 reinitialize_port(struct rstp_port *p)
1115 OVS_EXCLUDED(rstp_mutex)
1117 ovs_mutex_lock(&rstp_mutex);
1118 reinitialize_port__(p);
1119 ovs_mutex_unlock(&rstp_mutex);
1122 /* Sets the port state. */
1124 rstp_port_set_state__(struct rstp_port *p, enum rstp_state state)
1125 OVS_REQUIRES(rstp_mutex)
1130 VLOG_DBG("%s, port %u: set RSTP port state %s -> %s", rstp->name,
1132 rstp_state_name(p->rstp_state), rstp_state_name(state));
1134 if (state != p->rstp_state && !p->state_changed) {
1135 p->state_changed = true;
1136 seq_change(connectivity_seq_get());
1138 p->rstp_state = state;
1142 rstp_port_set_state(struct rstp_port *p, enum rstp_state state)
1143 OVS_EXCLUDED(rstp_mutex)
1145 ovs_mutex_lock(&rstp_mutex);
1146 rstp_port_set_state__(p, state);
1147 ovs_mutex_unlock(&rstp_mutex);
1150 /* Adds a RSTP port. */
1152 rstp_add_port(struct rstp *rstp)
1153 OVS_EXCLUDED(rstp_mutex)
1155 struct rstp_port *p = xzalloc(sizeof *p);
1157 ovs_refcount_init(&p->ref_cnt);
1158 hmap_node_nullify(&p->node);
1160 ovs_mutex_lock(&rstp_mutex);
1162 rstp_port_set_priority__(p, RSTP_DEFAULT_PORT_PRIORITY);
1163 rstp_port_set_port_number__(p, 0);
1165 rstp_initialize_port_defaults__(p);
1166 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" initialized.", rstp->name,
1169 rstp_port_set_state__(p, RSTP_DISCARDING);
1170 rstp->changes = true;
1172 VLOG_DBG("%s: added port "RSTP_PORT_ID_FMT"", rstp->name, p->port_id);
1173 ovs_mutex_unlock(&rstp_mutex);
1177 /* Caller has to hold a reference to prevent 'rstp_port' from being deleted
1178 * while taking a new reference. */
1180 rstp_port_ref(const struct rstp_port *rp_)
1181 OVS_EXCLUDED(rstp_mutex)
1183 struct rstp_port *rp = CONST_CAST(struct rstp_port *, rp_);
1186 ovs_refcount_ref(&rp->ref_cnt);
1191 /* Frees RSTP struct. This can be caller by any thread. */
1193 rstp_port_unref(struct rstp_port *rp)
1194 OVS_EXCLUDED(rstp_mutex)
1196 if (rp && ovs_refcount_unref_relaxed(&rp->ref_cnt) == 1) {
1199 ovs_mutex_lock(&rstp_mutex);
1201 rstp_port_set_state__(rp, RSTP_DISABLED);
1202 hmap_remove(&rstp->ports, &rp->node);
1203 VLOG_DBG("%s: removed port "RSTP_PORT_ID_FMT"", rstp->name,
1205 ovs_mutex_unlock(&rstp_mutex);
1210 /* Sets the port Admin Edge parameter. */
1212 rstp_port_set_admin_edge__(struct rstp_port *port, bool admin_edge)
1213 OVS_REQUIRES(rstp_mutex)
1215 if (port->admin_edge != admin_edge) {
1216 VLOG_DBG("%s, port %u: set RSTP Admin Edge to %d", port->rstp->name,
1217 port->port_number, admin_edge);
1219 port->admin_edge = admin_edge;
1223 /* Sets the port Auto Edge parameter. */
1225 rstp_port_set_auto_edge__(struct rstp_port *port, bool auto_edge)
1226 OVS_REQUIRES(rstp_mutex)
1228 if (port->auto_edge != auto_edge) {
1229 VLOG_DBG("%s, port %u: set RSTP Auto Edge to %d", port->rstp->name,
1230 port->port_number, auto_edge);
1232 port->auto_edge = auto_edge;
1236 /* Sets the port admin_point_to_point_mac parameter. */
1237 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *port,
1238 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
1239 OVS_REQUIRES(rstp_mutex)
1241 VLOG_DBG("%s, port %u: set RSTP port admin-point-to-point-mac to %d",
1242 port->rstp->name, port->port_number, admin_p2p_mac_state);
1243 if (port->admin_point_to_point_mac != admin_p2p_mac_state) {
1244 if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_TRUE) {
1245 port->admin_point_to_point_mac = admin_p2p_mac_state;
1246 rstp_port_set_oper_point_to_point_mac__(
1247 port, RSTP_OPER_P2P_MAC_STATE_ENABLED);
1248 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_FALSE) {
1249 port->admin_point_to_point_mac = admin_p2p_mac_state;
1250 rstp_port_set_oper_point_to_point_mac__(
1251 port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
1252 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_AUTO) {
1253 /* If adminPointToPointMAC is set to Auto, then the value of
1254 * operPointToPointMAC is determined in accordance with the
1255 * specific procedures defined for the MAC entity concerned, as
1256 * defined in 6.5. If these procedures determine that the MAC
1257 * entity is connected to a point-to-point LAN, then
1258 * operPointToPointMAC is set TRUE; otherwise it is set FALSE.
1259 * In the absence of a specific definition of how to determine
1260 * whether the MAC is connected to a point-to-point LAN or not,
1261 * the value of operPointToPointMAC shall be FALSE. */
1262 port->admin_point_to_point_mac = admin_p2p_mac_state;
1263 rstp_port_set_oper_point_to_point_mac__(
1264 port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
1269 /* Sets the port mcheck parameter.
1270 * [17.19.13] May be set by management to force the Port Protocol Migration
1271 * state machine to transmit RST BPDUs for a MigrateTime (17.13.9) period, to
1272 * test whether all STP Bridges (17.4) on the attached LAN have been removed
1273 * and the Port can continue to transmit RSTP BPDUs. Setting mcheck has no
1274 * effect if stpVersion (17.20.12) is TRUE, i.e., the Bridge is operating in
1275 * STP Compatibility mode.
1278 rstp_port_set_mcheck__(struct rstp_port *port, bool mcheck)
1279 OVS_REQUIRES(rstp_mutex)
1281 if (mcheck == true && port->rstp->force_protocol_version >= 2) {
1282 port->mcheck = true;
1284 VLOG_DBG("%s, port %u: set RSTP mcheck to %d", port->rstp->name,
1285 port->port_number, mcheck);
1289 /* Returns the designated bridge id. */
1291 rstp_get_designated_id(const struct rstp *rstp)
1292 OVS_EXCLUDED(rstp_mutex)
1294 rstp_identifier designated_id;
1296 ovs_mutex_lock(&rstp_mutex);
1297 designated_id = rstp->root_priority.designated_bridge_id;
1298 ovs_mutex_unlock(&rstp_mutex);
1300 return designated_id;
1303 /* Returns the root bridge id. */
1305 rstp_get_root_id(const struct rstp *rstp)
1306 OVS_EXCLUDED(rstp_mutex)
1308 rstp_identifier root_id;
1310 ovs_mutex_lock(&rstp_mutex);
1311 root_id = rstp->root_priority.root_bridge_id;
1312 ovs_mutex_unlock(&rstp_mutex);
1317 /* Returns the designated port id. */
1319 rstp_get_designated_port_id(const struct rstp *rstp)
1320 OVS_EXCLUDED(rstp_mutex)
1322 uint16_t designated_port_id;
1324 ovs_mutex_lock(&rstp_mutex);
1325 designated_port_id = rstp->root_priority.designated_port_id;
1326 ovs_mutex_unlock(&rstp_mutex);
1328 return designated_port_id;
1331 /* Return the bridge port id. */
1333 rstp_get_bridge_port_id(const struct rstp *rstp)
1334 OVS_EXCLUDED(rstp_mutex)
1336 uint16_t bridge_port_id;
1338 ovs_mutex_lock(&rstp_mutex);
1339 bridge_port_id = rstp->root_priority.bridge_port_id;
1340 ovs_mutex_unlock(&rstp_mutex);
1342 return bridge_port_id;
1345 /* Returns true if the bridge believes to the be root of the spanning tree,
1349 rstp_is_root_bridge(const struct rstp *rstp)
1350 OVS_EXCLUDED(rstp_mutex)
1354 ovs_mutex_lock(&rstp_mutex);
1355 is_root = rstp->bridge_identifier ==
1356 rstp->root_priority.designated_bridge_id;
1357 ovs_mutex_unlock(&rstp_mutex);
1362 /* Returns the bridge ID of the bridge currently believed to be the root. */
1364 rstp_get_designated_root(const struct rstp *rstp)
1365 OVS_EXCLUDED(rstp_mutex)
1367 rstp_identifier designated_root;
1369 ovs_mutex_lock(&rstp_mutex);
1370 designated_root = rstp->root_priority.designated_bridge_id;
1371 ovs_mutex_unlock(&rstp_mutex);
1373 return designated_root;
1376 /* Returns the port connecting 'rstp' to the root bridge, or a null pointer if
1377 * there is no such port.
1380 rstp_get_root_port(struct rstp *rstp)
1381 OVS_EXCLUDED(rstp_mutex)
1383 struct rstp_port *p;
1385 ovs_mutex_lock(&rstp_mutex);
1386 HMAP_FOR_EACH (p, node, &rstp->ports) {
1387 if (p->port_id == rstp->root_port_id) {
1388 ovs_mutex_unlock(&rstp_mutex);
1392 ovs_mutex_unlock(&rstp_mutex);
1396 /* Returns the state of port 'p'. */
1398 rstp_port_get_state(const struct rstp_port *p)
1399 OVS_EXCLUDED(rstp_mutex)
1401 enum rstp_state state;
1403 ovs_mutex_lock(&rstp_mutex);
1404 state = p->rstp_state;
1405 ovs_mutex_unlock(&rstp_mutex);
1410 /* Retrieves port status. */
1412 rstp_port_get_status(const struct rstp_port *p, uint16_t *id,
1413 enum rstp_state *state, enum rstp_port_role *role,
1414 rstp_identifier *designated_bridge_id,
1415 uint16_t *designated_port_id,
1416 uint32_t *designated_path_cost, int *tx_count,
1417 int *rx_count, int *error_count, int *uptime)
1418 OVS_EXCLUDED(rstp_mutex)
1420 ovs_mutex_lock(&rstp_mutex);
1422 *state = p->rstp_state;
1425 *designated_bridge_id = p->port_priority.designated_bridge_id;
1426 *designated_port_id = p->port_priority.designated_port_id;
1427 *designated_path_cost = p->port_priority.root_path_cost;
1429 *tx_count = p->tx_count;
1430 *rx_count = p->rx_rstp_bpdu_cnt;
1431 *error_count = p->error_count;
1432 *uptime = p->uptime;
1433 ovs_mutex_unlock(&rstp_mutex);
1437 rstp_port_set(struct rstp_port *port, uint16_t port_num, int priority,
1438 uint32_t path_cost, bool is_admin_edge, bool is_auto_edge,
1439 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state,
1440 bool admin_port_state, bool do_mcheck, void *aux)
1441 OVS_EXCLUDED(rstp_mutex)
1443 ovs_mutex_lock(&rstp_mutex);
1445 rstp_port_set_priority__(port, priority);
1446 rstp_port_set_port_number__(port, port_num);
1447 rstp_port_set_path_cost__(port, path_cost);
1448 rstp_port_set_admin_edge__(port, is_admin_edge);
1449 rstp_port_set_auto_edge__(port, is_auto_edge);
1450 rstp_port_set_admin_point_to_point_mac__(port, admin_p2p_mac_state);
1451 rstp_port_set_administrative_bridge_port__(port, admin_port_state, false);
1452 rstp_port_set_mcheck__(port, do_mcheck);
1453 ovs_mutex_unlock(&rstp_mutex);
1456 /* Individual setters only used by test-rstp.c. */
1458 rstp_port_set_priority(struct rstp_port *port, int priority)
1459 OVS_EXCLUDED(rstp_mutex)
1461 ovs_mutex_lock(&rstp_mutex);
1462 rstp_port_set_priority__(port, priority);
1463 ovs_mutex_unlock(&rstp_mutex);
1467 rstp_port_set_path_cost(struct rstp_port *port, uint32_t path_cost)
1468 OVS_EXCLUDED(rstp_mutex)
1470 ovs_mutex_lock(&rstp_mutex);
1471 rstp_port_set_path_cost__(port, path_cost);
1472 ovs_mutex_unlock(&rstp_mutex);
1476 rstp_port_set_aux(struct rstp_port *port, void *aux)
1477 OVS_EXCLUDED(rstp_mutex)
1479 ovs_mutex_lock(&rstp_mutex);
1481 ovs_mutex_unlock(&rstp_mutex);
1485 static struct rstp *
1486 rstp_find(const char *name)
1487 OVS_REQUIRES(rstp_mutex)
1491 LIST_FOR_EACH (rstp, node, all_rstps) {
1492 if (!strcmp(rstp->name, name)) {
1500 rstp_unixctl_tcn(struct unixctl_conn *conn, int argc,
1501 const char *argv[], void *aux OVS_UNUSED)
1502 OVS_EXCLUDED(rstp_mutex)
1504 ovs_mutex_lock(&rstp_mutex);
1506 struct rstp *rstp = rstp_find(argv[1]);
1508 unixctl_command_reply_error(conn, "No such RSTP object");
1511 rstp->changes = true;
1515 LIST_FOR_EACH (rstp, node, all_rstps) {
1516 rstp->changes = true;
1520 unixctl_command_reply(conn, "OK");
1523 ovs_mutex_unlock(&rstp_mutex);