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);
189 hmap_destroy(&rstp->ports);
195 /* Returns the port number. Mutex is needed to guard against
196 * concurrent reinitialization (which can temporarily clear the
199 rstp_port_get_number(const struct rstp_port *p)
200 OVS_EXCLUDED(rstp_mutex)
204 ovs_mutex_lock(&rstp_mutex);
205 number = p->port_number;
206 ovs_mutex_unlock(&rstp_mutex);
211 static void rstp_unixctl_tcn(struct unixctl_conn *, int argc,
212 const char *argv[], void *aux);
214 /* Decrements the State Machines' timers. */
216 rstp_tick_timers(struct rstp *rstp)
217 OVS_EXCLUDED(rstp_mutex)
219 ovs_mutex_lock(&rstp_mutex);
220 decrease_rstp_port_timers__(rstp);
221 ovs_mutex_unlock(&rstp_mutex);
224 /* Processes an incoming BPDU. */
226 rstp_port_received_bpdu(struct rstp_port *rp, const void *bpdu,
228 OVS_EXCLUDED(rstp_mutex)
230 ovs_mutex_lock(&rstp_mutex);
231 /* Only process packets on ports that have RSTP enabled. */
232 if (rp && rp->rstp_state != RSTP_DISABLED) {
233 process_received_bpdu__(rp, bpdu, bpdu_size);
235 ovs_mutex_unlock(&rstp_mutex);
240 OVS_EXCLUDED(rstp_mutex)
242 unixctl_command_register("rstp/tcn", "[bridge]", 0, 1, rstp_unixctl_tcn,
246 /* Creates and returns a new RSTP instance that initially has no ports. */
248 rstp_create(const char *name, rstp_identifier bridge_address,
249 void (*send_bpdu)(struct dp_packet *bpdu, void *port_aux,
252 OVS_EXCLUDED(rstp_mutex)
256 VLOG_DBG("Creating RSTP instance");
258 rstp = xzalloc(sizeof *rstp);
259 rstp->name = xstrdup(name);
261 /* Initialize the ports map before calling any setters,
262 * so that the state machines will see an empty ports map. */
263 hmap_init(&rstp->ports);
265 ovs_mutex_lock(&rstp_mutex);
266 /* Set bridge address. */
267 rstp_set_bridge_address__(rstp, bridge_address);
268 /* Set default parameters values. */
269 rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
270 rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
271 rstp_set_bridge_force_protocol_version__(rstp, FPV_DEFAULT);
272 rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
273 rstp_set_bridge_hello_time__(rstp);
274 rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
275 rstp_set_bridge_migrate_time__(rstp);
276 rstp_set_bridge_transmit_hold_count__(rstp,
277 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
278 rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
279 RSTP_BRIDGE_HELLO_TIME,
280 RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
281 rstp->send_bpdu = send_bpdu;
283 rstp->changes = false;
285 rstp->old_root_aux = NULL;
286 rstp->new_root_aux = NULL;
288 ovs_refcount_init(&rstp->ref_cnt);
290 list_push_back(all_rstps, &rstp->node);
291 ovs_mutex_unlock(&rstp_mutex);
293 VLOG_DBG("RSTP instance creation done");
297 /* Called by rstp_set_bridge_address() and rstp_set_bridge_priority(),
298 * it updates the bridge priority vector according to the values passed by
302 set_bridge_priority__(struct rstp *rstp)
303 OVS_REQUIRES(rstp_mutex)
307 rstp->bridge_priority.root_bridge_id = rstp->bridge_identifier;
308 rstp->bridge_priority.designated_bridge_id = rstp->bridge_identifier;
309 VLOG_DBG("%s: new bridge identifier: "RSTP_ID_FMT"", rstp->name,
310 RSTP_ID_ARGS(rstp->bridge_identifier));
312 /* [17.13] When the bridge address changes, recalculates all priority
315 HMAP_FOR_EACH (p, node, &rstp->ports) {
319 rstp->changes = true;
320 updt_roles_tree__(rstp);
323 /* Sets the bridge address. */
325 rstp_set_bridge_address__(struct rstp *rstp, rstp_identifier bridge_address)
326 OVS_REQUIRES(rstp_mutex)
328 VLOG_DBG("%s: set bridge address to: "RSTP_ID_FMT"", rstp->name,
329 RSTP_ID_ARGS(bridge_address));
330 if (rstp->address != bridge_address) {
331 rstp->address = bridge_address;
332 rstp->bridge_identifier &= 0xffff000000000000ULL;
333 rstp->bridge_identifier |= bridge_address;
334 set_bridge_priority__(rstp);
338 /* Sets the bridge address. */
340 rstp_set_bridge_address(struct rstp *rstp, rstp_identifier bridge_address)
341 OVS_EXCLUDED(rstp_mutex)
343 ovs_mutex_lock(&rstp_mutex);
344 rstp_set_bridge_address__(rstp, bridge_address);
345 ovs_mutex_unlock(&rstp_mutex);
349 rstp_get_name(const struct rstp *rstp)
350 OVS_EXCLUDED(rstp_mutex)
354 ovs_mutex_lock(&rstp_mutex);
356 ovs_mutex_unlock(&rstp_mutex);
361 rstp_get_bridge_id(const struct rstp *rstp)
362 OVS_EXCLUDED(rstp_mutex)
364 rstp_identifier bridge_id;
366 ovs_mutex_lock(&rstp_mutex);
367 bridge_id = rstp->bridge_identifier;
368 ovs_mutex_unlock(&rstp_mutex);
373 /* Sets the bridge priority. */
375 rstp_set_bridge_priority__(struct rstp *rstp, int new_priority)
376 OVS_REQUIRES(rstp_mutex)
378 new_priority = ROUND_DOWN(new_priority, RSTP_PRIORITY_STEP);
380 if (rstp->priority != new_priority
381 && new_priority >= RSTP_MIN_PRIORITY
382 && new_priority <= RSTP_MAX_PRIORITY) {
383 VLOG_DBG("%s: set bridge priority to %d", rstp->name, new_priority);
385 rstp->priority = new_priority;
386 rstp->bridge_identifier &= 0x0000ffffffffffffULL;
387 rstp->bridge_identifier |= (uint64_t)new_priority << 48;
388 set_bridge_priority__(rstp);
393 rstp_set_bridge_priority(struct rstp *rstp, int new_priority)
394 OVS_EXCLUDED(rstp_mutex)
396 ovs_mutex_lock(&rstp_mutex);
397 rstp_set_bridge_priority__(rstp, new_priority);
398 ovs_mutex_unlock(&rstp_mutex);
401 /* Sets the bridge ageing time. */
403 rstp_set_bridge_ageing_time__(struct rstp *rstp, int new_ageing_time)
404 OVS_REQUIRES(rstp_mutex)
406 if (new_ageing_time >= RSTP_MIN_AGEING_TIME
407 && new_ageing_time <= RSTP_MAX_AGEING_TIME) {
408 VLOG_DBG("%s: set ageing time to %d", rstp->name, new_ageing_time);
410 rstp->ageing_time = new_ageing_time;
415 rstp_set_bridge_ageing_time(struct rstp *rstp, int new_ageing_time)
416 OVS_EXCLUDED(rstp_mutex)
418 ovs_mutex_lock(&rstp_mutex);
419 rstp_set_bridge_ageing_time__(rstp, new_ageing_time);
420 ovs_mutex_unlock(&rstp_mutex);
423 /* Reinitializes RSTP when switching from RSTP mode to STP mode
427 reinitialize_rstp__(struct rstp *rstp)
428 OVS_REQUIRES(rstp_mutex)
431 static struct hmap ports;
434 /* Copy rstp in temp */
438 /* stop and clear rstp */
439 memset(rstp, 0, sizeof(struct rstp));
441 /* Initialize rstp. */
442 rstp->name = temp.name;
444 /* Initialize the ports hmap before calling any setters,
445 * so that the state machines will see an empty ports list. */
446 hmap_init(&rstp->ports);
448 /* Set bridge address. */
449 rstp_set_bridge_address__(rstp, temp.address);
450 /* Set default parameters values. */
451 rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
452 rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
453 rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
454 rstp_set_bridge_hello_time__(rstp);
455 rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
456 rstp_set_bridge_migrate_time__(rstp);
457 rstp_set_bridge_transmit_hold_count__(rstp,
458 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
459 rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
460 RSTP_BRIDGE_HELLO_TIME,
461 RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
463 rstp->send_bpdu = temp.send_bpdu;
464 rstp->aux = temp.aux;
465 rstp->node = temp.node;
466 rstp->changes = false;
472 HMAP_FOR_EACH (p, node, &rstp->ports) {
473 reinitialize_port__(p);
476 rstp->ref_cnt = temp.ref_cnt;
479 /* Sets the force protocol version parameter. */
481 rstp_set_bridge_force_protocol_version__(struct rstp *rstp,
482 enum rstp_force_protocol_version new_force_protocol_version)
483 OVS_REQUIRES(rstp_mutex)
485 if (new_force_protocol_version != rstp->force_protocol_version &&
486 (new_force_protocol_version == FPV_STP_COMPATIBILITY ||
487 new_force_protocol_version == FPV_DEFAULT)) {
488 VLOG_DBG("%s: set bridge Force Protocol Version to %d", rstp->name,
489 new_force_protocol_version);
491 /* [17.13] The Spanning Tree Protocol Entity shall be reinitialized,
492 * as specified by the assertion of BEGIN (17.18.1) in the state
493 * machine specification.
495 reinitialize_rstp__(rstp);
496 rstp->force_protocol_version = new_force_protocol_version;
497 if (rstp->force_protocol_version < 2) {
498 rstp->stp_version = true;
499 rstp->rstp_version = false;
501 rstp->stp_version = false;
502 rstp->rstp_version = true;
504 rstp->changes = true;
510 rstp_set_bridge_force_protocol_version(struct rstp *rstp,
511 enum rstp_force_protocol_version new_force_protocol_version)
512 OVS_EXCLUDED(rstp_mutex)
514 ovs_mutex_lock(&rstp_mutex);
515 rstp_set_bridge_force_protocol_version__(rstp, new_force_protocol_version);
516 ovs_mutex_unlock(&rstp_mutex);
519 /* Sets the bridge Hello Time parameter. */
521 rstp_set_bridge_hello_time__(struct rstp *rstp)
522 OVS_REQUIRES(rstp_mutex)
524 VLOG_DBG("%s: set RSTP Hello Time to %d", rstp->name,
525 RSTP_BRIDGE_HELLO_TIME);
526 /* 2 is the only acceptable value. */
527 rstp->bridge_hello_time = RSTP_BRIDGE_HELLO_TIME;
530 /* Sets the bridge max age parameter. */
532 rstp_set_bridge_max_age__(struct rstp *rstp, int new_max_age)
533 OVS_REQUIRES(rstp_mutex)
535 if (rstp->bridge_max_age != new_max_age
536 && new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
537 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
539 if ((2 * (rstp->bridge_forward_delay - 1) >= new_max_age)
540 && (new_max_age >= 2 * rstp->bridge_hello_time)) {
541 VLOG_DBG("%s: set RSTP bridge Max Age to %d", rstp->name,
544 rstp->bridge_max_age = new_max_age;
545 rstp->bridge_times.max_age = new_max_age;
546 rstp->changes = true;
547 updt_roles_tree__(rstp);
553 rstp_set_bridge_max_age(struct rstp *rstp, int new_max_age)
554 OVS_EXCLUDED(rstp_mutex)
556 ovs_mutex_lock(&rstp_mutex);
557 rstp_set_bridge_max_age__(rstp, new_max_age);
558 ovs_mutex_unlock(&rstp_mutex);
561 /* Sets the bridge forward delay parameter. */
563 rstp_set_bridge_forward_delay__(struct rstp *rstp, int new_forward_delay)
564 OVS_REQUIRES(rstp_mutex)
566 if (rstp->bridge_forward_delay != new_forward_delay
567 && new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
568 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
569 if (2 * (new_forward_delay - 1) >= rstp->bridge_max_age) {
570 VLOG_DBG("%s: set RSTP Forward Delay to %d", rstp->name,
572 rstp->bridge_forward_delay = new_forward_delay;
573 rstp->bridge_times.forward_delay = new_forward_delay;
574 rstp->changes = true;
575 updt_roles_tree__(rstp);
581 rstp_set_bridge_forward_delay(struct rstp *rstp, int new_forward_delay)
582 OVS_EXCLUDED(rstp_mutex)
584 ovs_mutex_lock(&rstp_mutex);
585 rstp_set_bridge_forward_delay__(rstp, new_forward_delay);
586 ovs_mutex_unlock(&rstp_mutex);
589 /* Sets the bridge transmit hold count parameter. */
591 rstp_set_bridge_transmit_hold_count__(struct rstp *rstp,
592 int new_transmit_hold_count)
593 OVS_REQUIRES(rstp_mutex)
595 if (rstp->transmit_hold_count != new_transmit_hold_count
596 && new_transmit_hold_count >= RSTP_MIN_TRANSMIT_HOLD_COUNT
597 && new_transmit_hold_count <= RSTP_MAX_TRANSMIT_HOLD_COUNT) {
600 VLOG_DBG("%s: set RSTP Transmit Hold Count to %d", rstp->name,
601 new_transmit_hold_count);
602 /* Resetting txCount on all ports [17.13]. */
604 rstp->transmit_hold_count = new_transmit_hold_count;
605 HMAP_FOR_EACH (p, node, &rstp->ports) {
612 rstp_set_bridge_transmit_hold_count(struct rstp *rstp,
613 int new_transmit_hold_count)
614 OVS_EXCLUDED(rstp_mutex)
616 ovs_mutex_lock(&rstp_mutex);
617 rstp_set_bridge_transmit_hold_count__(rstp, new_transmit_hold_count);
618 ovs_mutex_unlock(&rstp_mutex);
621 /* Sets the bridge migrate time parameter. */
623 rstp_set_bridge_migrate_time__(struct rstp *rstp)
624 OVS_REQUIRES(rstp_mutex)
626 VLOG_DBG("%s: set RSTP Migrate Time to %d", rstp->name,
628 /* 3 is the only acceptable value */
629 rstp->migrate_time = RSTP_MIGRATE_TIME;
632 /* Sets the bridge times. */
634 rstp_set_bridge_times__(struct rstp *rstp, int new_forward_delay,
635 int new_hello_time, int new_max_age,
637 OVS_REQUIRES(rstp_mutex)
639 VLOG_DBG("%s: set RSTP times to (%d, %d, %d, %d)", rstp->name,
640 new_forward_delay, new_hello_time, new_max_age, new_message_age);
641 if (new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
642 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
643 rstp->bridge_times.forward_delay = new_forward_delay;
645 if (new_hello_time == RSTP_BRIDGE_HELLO_TIME) {
646 rstp->bridge_times.hello_time = new_hello_time;
648 if (new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
649 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
650 rstp->bridge_times.max_age = new_max_age;
652 rstp->bridge_times.message_age = new_message_age;
655 /* Sets the port id, it is called by rstp_port_set_port_number__() or
656 * rstp_port_set_priority__().
659 set_port_id__(struct rstp_port *p)
660 OVS_REQUIRES(rstp_mutex)
665 /* [9.2.7] Port identifier. */
666 p->port_id = p->port_number | (p->priority << 8);
667 VLOG_DBG("%s: new RSTP port id "RSTP_PORT_ID_FMT"", rstp->name,
671 /* Sets the port priority. */
673 rstp_port_set_priority__(struct rstp_port *port, int priority)
674 OVS_REQUIRES(rstp_mutex)
676 if (port->priority != priority
677 && priority >= RSTP_MIN_PORT_PRIORITY
678 && priority <= RSTP_MAX_PORT_PRIORITY) {
679 VLOG_DBG("%s, port %u: set RSTP port priority to %d", port->rstp->name,
680 port->port_number, priority);
682 priority -= priority % RSTP_STEP_PORT_PRIORITY;
683 port->priority = priority;
685 port->selected = false;
686 port->reselect = true;
690 /* Checks if a port number is available. */
692 is_port_number_available__(struct rstp *rstp, int n, struct rstp_port *port)
693 OVS_REQUIRES(rstp_mutex)
695 if (n >= 1 && n <= RSTP_MAX_PORTS) {
696 struct rstp_port *p = rstp_get_port__(rstp, n);
698 return p == NULL || p == port;
704 rstp_first_free_number__(struct rstp *rstp, struct rstp_port *rstp_port)
705 OVS_REQUIRES(rstp_mutex)
709 while (free_number <= RSTP_MAX_PORTS) {
710 if (is_port_number_available__(rstp, free_number, rstp_port)) {
715 VLOG_DBG("%s, No free port number available.", rstp->name);
719 /* Sets the port number. */
721 rstp_port_set_port_number__(struct rstp_port *port, uint16_t port_number)
722 OVS_REQUIRES(rstp_mutex)
724 int old_port_number = port->port_number;
726 /* If new_port_number is available, use it, otherwise use the first free
727 * available port number. */
728 if (port->port_number != port_number || port_number == 0) {
730 is_port_number_available__(port->rstp, port_number, port)
732 : rstp_first_free_number__(port->rstp, port);
734 if (port->port_number != old_port_number) {
736 /* [17.13] is not clear. I suppose that a port number change
737 * should trigger reselection like a port priority change. */
738 port->selected = false;
739 port->reselect = true;
741 /* Adjust the ports hmap. */
742 if (!hmap_node_is_null(&port->node)) {
743 hmap_remove(&port->rstp->ports, &port->node);
745 hmap_insert(&port->rstp->ports, &port->node,
746 hash_int(port->port_number, 0));
748 VLOG_DBG("%s: set new RSTP port number %d", port->rstp->name,
754 /* Converts the link speed to a port path cost [Table 17-3]. */
756 rstp_convert_speed_to_cost(unsigned int speed)
760 value = speed >= 10000000 ? 2 /* 10 Tb/s. */
761 : speed >= 1000000 ? 20 /* 1 Tb/s. */
762 : speed >= 100000 ? 200 /* 100 Gb/s. */
763 : speed >= 10000 ? 2000 /* 10 Gb/s. */
764 : speed >= 1000 ? 20000 /* 1 Gb/s. */
765 : speed >= 100 ? 200000 /* 100 Mb/s. */
766 : speed >= 10 ? 2000000 /* 10 Mb/s. */
767 : speed >= 1 ? 20000000 /* 1 Mb/s. */
768 : RSTP_DEFAULT_PORT_PATH_COST; /* 100 Mb/s. */
773 /* Sets the port path cost. */
775 rstp_port_set_path_cost__(struct rstp_port *port, uint32_t path_cost)
776 OVS_REQUIRES(rstp_mutex)
778 if (port->port_path_cost != path_cost
779 && path_cost >= RSTP_MIN_PORT_PATH_COST
780 && path_cost <= RSTP_MAX_PORT_PATH_COST) {
781 VLOG_DBG("%s, port %u, set RSTP port path cost to %d",
782 port->rstp->name, port->port_number, path_cost);
784 port->port_path_cost = path_cost;
785 port->selected = false;
786 port->reselect = true;
790 /* Gets the root path cost. */
792 rstp_get_root_path_cost(const struct rstp *rstp)
793 OVS_EXCLUDED(rstp_mutex)
797 ovs_mutex_lock(&rstp_mutex);
798 cost = rstp->root_priority.root_path_cost;
799 ovs_mutex_unlock(&rstp_mutex);
803 /* Finds a port which needs to flush its own MAC learning table. A NULL
804 * pointer is returned if no port needs to flush its MAC learning table.
805 * '*port' needs to be NULL in the first call to start the iteration. If
806 * '*port' is passed as non-NULL, it must be the value set by the last
807 * invocation of this function.
809 * This function may only be called by the thread that creates and deletes
810 * ports. Otherwise this function is not thread safe, as the returned
811 * '*port' could become stale before it is used in the next invocation. */
813 rstp_check_and_reset_fdb_flush(struct rstp *rstp, struct rstp_port **port)
814 OVS_EXCLUDED(rstp_mutex)
818 ovs_mutex_lock(&rstp_mutex);
822 HMAP_FOR_EACH (p, node, &rstp->ports) {
829 } else { /* continue */
830 struct rstp_port *p = *port;
832 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
840 /* No port needs flushing. */
843 /* fdb_flush should be reset by the filtering database
844 * once the entries are removed if rstp_version is TRUE, and
845 * immediately if stp_version is TRUE.*/
847 (*port)->fdb_flush = false;
849 ovs_mutex_unlock(&rstp_mutex);
854 /* Finds a port whose state has changed, and returns the aux pointer set for
855 * the port. A NULL pointer is returned when no changed port is found. On
856 * return '*portp' contains the pointer to the rstp port that changed, or NULL
857 * if no changed port can be found.
859 * If '*portp' is passed as non-NULL, it must be the value set by the last
860 * invocation of this function.
862 * This function may only be called by the thread that creates and deletes
863 * ports. Otherwise this function is not thread safe, as the returned
864 * '*portp' could become stale before it is used in the next invocation. */
866 rstp_get_next_changed_port_aux(struct rstp *rstp, struct rstp_port **portp)
870 ovs_mutex_lock(&rstp_mutex);
871 if (*portp == NULL) {
874 HMAP_FOR_EACH (p, node, &rstp->ports) {
875 if (p->state_changed) {
876 p->state_changed = false;
882 } else { /* continue */
883 struct rstp_port *p = *portp;
885 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
886 if (p->state_changed) {
887 p->state_changed = false;
894 /* No changed port found. */
897 ovs_mutex_unlock(&rstp_mutex);
903 rstp_shift_root_learned_address(struct rstp *rstp)
907 ovs_mutex_lock(&rstp_mutex);
908 ret = rstp->root_changed;
909 ovs_mutex_unlock(&rstp_mutex);
915 rstp_get_old_root_aux(struct rstp *rstp)
919 ovs_mutex_lock(&rstp_mutex);
920 aux = rstp->old_root_aux;
921 ovs_mutex_unlock(&rstp_mutex);
927 rstp_get_new_root_aux(struct rstp *rstp)
931 ovs_mutex_lock(&rstp_mutex);
932 aux = rstp->new_root_aux;
933 ovs_mutex_unlock(&rstp_mutex);
939 rstp_reset_root_changed(struct rstp *rstp)
941 ovs_mutex_lock(&rstp_mutex);
942 rstp->root_changed = false;
943 ovs_mutex_unlock(&rstp_mutex);
946 /* Returns the port in 'rstp' with number 'port_number'.
948 * XXX: May only be called while concurrent deletion of ports is excluded. */
949 static struct rstp_port *
950 rstp_get_port__(struct rstp *rstp, uint16_t port_number)
951 OVS_REQUIRES(rstp_mutex)
953 struct rstp_port *port;
955 ovs_assert(rstp && port_number > 0 && port_number <= RSTP_MAX_PORTS);
957 HMAP_FOR_EACH_WITH_HASH (port, node, hash_int(port_number, 0),
959 if (port->port_number == port_number) {
967 rstp_get_port(struct rstp *rstp, uint16_t port_number)
968 OVS_EXCLUDED(rstp_mutex)
972 ovs_mutex_lock(&rstp_mutex);
973 p = rstp_get_port__(rstp, port_number);
974 ovs_mutex_unlock(&rstp_mutex);
979 rstp_get_port_aux__(struct rstp *rstp, uint16_t port_number)
980 OVS_REQUIRES(rstp_mutex)
983 p = rstp_get_port__(rstp, port_number);
990 /* Updates the port_enabled parameter. */
992 update_port_enabled__(struct rstp_port *p)
993 OVS_REQUIRES(rstp_mutex)
995 if (p->mac_operational && p->is_administrative_bridge_port
996 == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED) {
997 p->port_enabled = true;
999 p->port_enabled = false;
1003 /* Sets the port MAC_Operational parameter [6.4.2]. */
1005 rstp_port_set_mac_operational(struct rstp_port *p, bool new_mac_operational)
1006 OVS_EXCLUDED(rstp_mutex)
1010 ovs_mutex_lock(&rstp_mutex);
1012 if (p->mac_operational != new_mac_operational) {
1013 p->mac_operational = new_mac_operational;
1014 update_port_enabled__(p);
1015 rstp->changes = true;
1018 ovs_mutex_unlock(&rstp_mutex);
1021 /* Sets the port Administrative Bridge Port parameter. */
1023 rstp_port_set_administrative_bridge_port__(struct rstp_port *p,
1024 uint8_t admin_port_state,
1026 OVS_REQUIRES(rstp_mutex)
1028 VLOG_DBG("%s, port %u: set RSTP port admin-port-state to %d",
1029 p->rstp->name, p->port_number, admin_port_state);
1031 if (p->is_administrative_bridge_port != admin_port_state
1032 && (admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_DISABLED
1033 || admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED)) {
1034 p->is_administrative_bridge_port = admin_port_state;
1035 update_port_enabled__(p);
1037 if (!initializing) {
1038 struct rstp *rstp = p->rstp;
1040 rstp->changes = true;
1046 /* Sets the port oper_point_to_point_mac parameter. */
1048 rstp_port_set_oper_point_to_point_mac__(struct rstp_port *p,
1049 uint8_t new_oper_p2p_mac)
1050 OVS_REQUIRES(rstp_mutex)
1052 if (p->oper_point_to_point_mac != new_oper_p2p_mac
1053 && (new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_DISABLED
1054 || new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_ENABLED)) {
1056 p->oper_point_to_point_mac = new_oper_p2p_mac;
1057 update_port_enabled__(p);
1061 /* Initializes a port with the defaults values for its parameters. */
1063 rstp_initialize_port_defaults__(struct rstp_port *p)
1064 OVS_REQUIRES(rstp_mutex)
1066 rstp_port_set_administrative_bridge_port__(p,
1067 RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED,
1069 rstp_port_set_oper_point_to_point_mac__(p,
1070 RSTP_OPER_P2P_MAC_STATE_ENABLED);
1071 rstp_port_set_path_cost__(p, RSTP_DEFAULT_PORT_PATH_COST);
1072 rstp_port_set_admin_edge__(p, false);
1073 rstp_port_set_auto_edge__(p, true);
1074 rstp_port_set_mcheck__(p, false);
1076 /* Initialize state machines. */
1077 p->port_receive_sm_state = PORT_RECEIVE_SM_INIT;
1078 p->port_protocol_migration_sm_state = PORT_PROTOCOL_MIGRATION_SM_INIT;
1079 p->bridge_detection_sm_state = BRIDGE_DETECTION_SM_INIT;
1080 p->port_transmit_sm_state = PORT_TRANSMIT_SM_INIT;
1081 p->port_information_sm_state = PORT_INFORMATION_SM_INIT;
1082 p->port_role_transition_sm_state = PORT_ROLE_TRANSITION_SM_INIT;
1083 p->port_state_transition_sm_state = PORT_STATE_TRANSITION_SM_INIT;
1084 p->topology_change_sm_state = TOPOLOGY_CHANGE_SM_INIT;
1090 reinitialize_port__(struct rstp_port *p)
1091 OVS_REQUIRES(rstp_mutex)
1093 struct rstp_port temp_port;
1098 memset(p, 0, sizeof(struct rstp_port));
1100 p->ref_cnt = temp_port.ref_cnt;
1102 p->node = temp_port.node;
1103 p->aux = temp_port.aux;
1104 p->port_number = temp_port.port_number;
1105 p->port_priority = temp_port.port_priority;
1106 p->port_id = temp_port.port_id;
1107 p->rstp_state = RSTP_DISCARDING;
1109 rstp_initialize_port_defaults__(p);
1111 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" reinitialized.", rstp->name,
1116 reinitialize_port(struct rstp_port *p)
1117 OVS_EXCLUDED(rstp_mutex)
1119 ovs_mutex_lock(&rstp_mutex);
1120 reinitialize_port__(p);
1121 ovs_mutex_unlock(&rstp_mutex);
1124 /* Sets the port state. */
1126 rstp_port_set_state__(struct rstp_port *p, enum rstp_state state)
1127 OVS_REQUIRES(rstp_mutex)
1132 VLOG_DBG("%s, port %u: set RSTP port state %s -> %s", rstp->name,
1134 rstp_state_name(p->rstp_state), rstp_state_name(state));
1136 if (state != p->rstp_state && !p->state_changed) {
1137 p->state_changed = true;
1138 seq_change(connectivity_seq_get());
1140 p->rstp_state = state;
1144 rstp_port_set_state(struct rstp_port *p, enum rstp_state state)
1145 OVS_EXCLUDED(rstp_mutex)
1147 ovs_mutex_lock(&rstp_mutex);
1148 rstp_port_set_state__(p, state);
1149 ovs_mutex_unlock(&rstp_mutex);
1152 /* Adds a RSTP port. */
1154 rstp_add_port(struct rstp *rstp)
1155 OVS_EXCLUDED(rstp_mutex)
1157 struct rstp_port *p = xzalloc(sizeof *p);
1159 ovs_refcount_init(&p->ref_cnt);
1160 hmap_node_nullify(&p->node);
1162 ovs_mutex_lock(&rstp_mutex);
1164 rstp_port_set_priority__(p, RSTP_DEFAULT_PORT_PRIORITY);
1165 rstp_port_set_port_number__(p, 0);
1167 rstp_initialize_port_defaults__(p);
1168 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" initialized.", rstp->name,
1171 rstp_port_set_state__(p, RSTP_DISCARDING);
1172 rstp->changes = true;
1174 VLOG_DBG("%s: added port "RSTP_PORT_ID_FMT"", rstp->name, p->port_id);
1175 ovs_mutex_unlock(&rstp_mutex);
1179 /* Caller has to hold a reference to prevent 'rstp_port' from being deleted
1180 * while taking a new reference. */
1182 rstp_port_ref(const struct rstp_port *rp_)
1183 OVS_EXCLUDED(rstp_mutex)
1185 struct rstp_port *rp = CONST_CAST(struct rstp_port *, rp_);
1188 ovs_refcount_ref(&rp->ref_cnt);
1193 /* Frees RSTP struct. This can be caller by any thread. */
1195 rstp_port_unref(struct rstp_port *rp)
1196 OVS_EXCLUDED(rstp_mutex)
1198 if (rp && ovs_refcount_unref_relaxed(&rp->ref_cnt) == 1) {
1201 ovs_mutex_lock(&rstp_mutex);
1203 rstp_port_set_state__(rp, RSTP_DISABLED);
1204 hmap_remove(&rstp->ports, &rp->node);
1205 VLOG_DBG("%s: removed port "RSTP_PORT_ID_FMT"", rstp->name,
1207 ovs_mutex_unlock(&rstp_mutex);
1212 /* Sets the port Admin Edge parameter. */
1214 rstp_port_set_admin_edge__(struct rstp_port *port, bool admin_edge)
1215 OVS_REQUIRES(rstp_mutex)
1217 if (port->admin_edge != admin_edge) {
1218 VLOG_DBG("%s, port %u: set RSTP Admin Edge to %d", port->rstp->name,
1219 port->port_number, admin_edge);
1221 port->admin_edge = admin_edge;
1225 /* Sets the port Auto Edge parameter. */
1227 rstp_port_set_auto_edge__(struct rstp_port *port, bool auto_edge)
1228 OVS_REQUIRES(rstp_mutex)
1230 if (port->auto_edge != auto_edge) {
1231 VLOG_DBG("%s, port %u: set RSTP Auto Edge to %d", port->rstp->name,
1232 port->port_number, auto_edge);
1234 port->auto_edge = auto_edge;
1238 /* Sets the port admin_point_to_point_mac parameter. */
1239 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *port,
1240 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
1241 OVS_REQUIRES(rstp_mutex)
1243 VLOG_DBG("%s, port %u: set RSTP port admin-point-to-point-mac to %d",
1244 port->rstp->name, port->port_number, admin_p2p_mac_state);
1245 if (port->admin_point_to_point_mac != admin_p2p_mac_state) {
1246 if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_TRUE) {
1247 port->admin_point_to_point_mac = admin_p2p_mac_state;
1248 rstp_port_set_oper_point_to_point_mac__(
1249 port, RSTP_OPER_P2P_MAC_STATE_ENABLED);
1250 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_FALSE) {
1251 port->admin_point_to_point_mac = admin_p2p_mac_state;
1252 rstp_port_set_oper_point_to_point_mac__(
1253 port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
1254 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_AUTO) {
1255 /* If adminPointToPointMAC is set to Auto, then the value of
1256 * operPointToPointMAC is determined in accordance with the
1257 * specific procedures defined for the MAC entity concerned, as
1258 * defined in 6.5. If these procedures determine that the MAC
1259 * entity is connected to a point-to-point LAN, then
1260 * operPointToPointMAC is set TRUE; otherwise it is set FALSE.
1261 * In the absence of a specific definition of how to determine
1262 * whether the MAC is connected to a point-to-point LAN or not,
1263 * the value of operPointToPointMAC shall be FALSE. */
1264 port->admin_point_to_point_mac = admin_p2p_mac_state;
1265 rstp_port_set_oper_point_to_point_mac__(
1266 port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
1271 /* Sets the port mcheck parameter.
1272 * [17.19.13] May be set by management to force the Port Protocol Migration
1273 * state machine to transmit RST BPDUs for a MigrateTime (17.13.9) period, to
1274 * test whether all STP Bridges (17.4) on the attached LAN have been removed
1275 * and the Port can continue to transmit RSTP BPDUs. Setting mcheck has no
1276 * effect if stpVersion (17.20.12) is TRUE, i.e., the Bridge is operating in
1277 * STP Compatibility mode.
1280 rstp_port_set_mcheck__(struct rstp_port *port, bool mcheck)
1281 OVS_REQUIRES(rstp_mutex)
1283 if (mcheck == true && port->rstp->force_protocol_version >= 2) {
1284 port->mcheck = true;
1286 VLOG_DBG("%s, port %u: set RSTP mcheck to %d", port->rstp->name,
1287 port->port_number, mcheck);
1291 /* Returns the designated bridge id. */
1293 rstp_get_designated_id(const struct rstp *rstp)
1294 OVS_EXCLUDED(rstp_mutex)
1296 rstp_identifier designated_id;
1298 ovs_mutex_lock(&rstp_mutex);
1299 designated_id = rstp->root_priority.designated_bridge_id;
1300 ovs_mutex_unlock(&rstp_mutex);
1302 return designated_id;
1305 /* Returns the root bridge id. */
1307 rstp_get_root_id(const struct rstp *rstp)
1308 OVS_EXCLUDED(rstp_mutex)
1310 rstp_identifier root_id;
1312 ovs_mutex_lock(&rstp_mutex);
1313 root_id = rstp->root_priority.root_bridge_id;
1314 ovs_mutex_unlock(&rstp_mutex);
1319 /* Returns the designated port id. */
1321 rstp_get_designated_port_id(const struct rstp *rstp)
1322 OVS_EXCLUDED(rstp_mutex)
1324 uint16_t designated_port_id;
1326 ovs_mutex_lock(&rstp_mutex);
1327 designated_port_id = rstp->root_priority.designated_port_id;
1328 ovs_mutex_unlock(&rstp_mutex);
1330 return designated_port_id;
1333 /* Return the bridge port id. */
1335 rstp_get_bridge_port_id(const struct rstp *rstp)
1336 OVS_EXCLUDED(rstp_mutex)
1338 uint16_t bridge_port_id;
1340 ovs_mutex_lock(&rstp_mutex);
1341 bridge_port_id = rstp->root_priority.bridge_port_id;
1342 ovs_mutex_unlock(&rstp_mutex);
1344 return bridge_port_id;
1347 /* Returns true if the bridge believes to the be root of the spanning tree,
1351 rstp_is_root_bridge(const struct rstp *rstp)
1352 OVS_EXCLUDED(rstp_mutex)
1356 ovs_mutex_lock(&rstp_mutex);
1357 is_root = rstp->bridge_identifier ==
1358 rstp->root_priority.designated_bridge_id;
1359 ovs_mutex_unlock(&rstp_mutex);
1364 /* Returns the bridge ID of the bridge currently believed to be the root. */
1366 rstp_get_designated_root(const struct rstp *rstp)
1367 OVS_EXCLUDED(rstp_mutex)
1369 rstp_identifier designated_root;
1371 ovs_mutex_lock(&rstp_mutex);
1372 designated_root = rstp->root_priority.designated_bridge_id;
1373 ovs_mutex_unlock(&rstp_mutex);
1375 return designated_root;
1378 /* Returns the port connecting 'rstp' to the root bridge, or a null pointer if
1379 * there is no such port.
1382 rstp_get_root_port(struct rstp *rstp)
1383 OVS_EXCLUDED(rstp_mutex)
1385 struct rstp_port *p;
1387 ovs_mutex_lock(&rstp_mutex);
1388 HMAP_FOR_EACH (p, node, &rstp->ports) {
1389 if (p->port_id == rstp->root_port_id) {
1390 ovs_mutex_unlock(&rstp_mutex);
1394 ovs_mutex_unlock(&rstp_mutex);
1398 /* Returns the state of port 'p'. */
1400 rstp_port_get_state(const struct rstp_port *p)
1401 OVS_EXCLUDED(rstp_mutex)
1403 enum rstp_state state;
1405 ovs_mutex_lock(&rstp_mutex);
1406 state = p->rstp_state;
1407 ovs_mutex_unlock(&rstp_mutex);
1412 /* Retrieves port status. */
1414 rstp_port_get_status(const struct rstp_port *p, uint16_t *id,
1415 enum rstp_state *state, enum rstp_port_role *role,
1416 rstp_identifier *designated_bridge_id,
1417 uint16_t *designated_port_id,
1418 uint32_t *designated_path_cost, int *tx_count,
1419 int *rx_count, int *error_count, int *uptime)
1420 OVS_EXCLUDED(rstp_mutex)
1422 ovs_mutex_lock(&rstp_mutex);
1424 *state = p->rstp_state;
1427 *designated_bridge_id = p->port_priority.designated_bridge_id;
1428 *designated_port_id = p->port_priority.designated_port_id;
1429 *designated_path_cost = p->port_priority.root_path_cost;
1431 *tx_count = p->tx_count;
1432 *rx_count = p->rx_rstp_bpdu_cnt;
1433 *error_count = p->error_count;
1434 *uptime = p->uptime;
1435 ovs_mutex_unlock(&rstp_mutex);
1439 rstp_port_set(struct rstp_port *port, uint16_t port_num, int priority,
1440 uint32_t path_cost, bool is_admin_edge, bool is_auto_edge,
1441 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state,
1442 bool admin_port_state, bool do_mcheck, void *aux)
1443 OVS_EXCLUDED(rstp_mutex)
1445 ovs_mutex_lock(&rstp_mutex);
1447 rstp_port_set_priority__(port, priority);
1448 rstp_port_set_port_number__(port, port_num);
1449 rstp_port_set_path_cost__(port, path_cost);
1450 rstp_port_set_admin_edge__(port, is_admin_edge);
1451 rstp_port_set_auto_edge__(port, is_auto_edge);
1452 rstp_port_set_admin_point_to_point_mac__(port, admin_p2p_mac_state);
1453 rstp_port_set_administrative_bridge_port__(port, admin_port_state, false);
1454 rstp_port_set_mcheck__(port, do_mcheck);
1455 ovs_mutex_unlock(&rstp_mutex);
1458 /* Individual setters only used by test-rstp.c. */
1460 rstp_port_set_priority(struct rstp_port *port, int priority)
1461 OVS_EXCLUDED(rstp_mutex)
1463 ovs_mutex_lock(&rstp_mutex);
1464 rstp_port_set_priority__(port, priority);
1465 ovs_mutex_unlock(&rstp_mutex);
1469 rstp_port_set_path_cost(struct rstp_port *port, uint32_t path_cost)
1470 OVS_EXCLUDED(rstp_mutex)
1472 ovs_mutex_lock(&rstp_mutex);
1473 rstp_port_set_path_cost__(port, path_cost);
1474 ovs_mutex_unlock(&rstp_mutex);
1478 rstp_port_set_aux(struct rstp_port *port, void *aux)
1479 OVS_EXCLUDED(rstp_mutex)
1481 ovs_mutex_lock(&rstp_mutex);
1483 ovs_mutex_unlock(&rstp_mutex);
1487 static struct rstp *
1488 rstp_find(const char *name)
1489 OVS_REQUIRES(rstp_mutex)
1493 LIST_FOR_EACH (rstp, node, all_rstps) {
1494 if (!strcmp(rstp->name, name)) {
1502 rstp_unixctl_tcn(struct unixctl_conn *conn, int argc,
1503 const char *argv[], void *aux OVS_UNUSED)
1504 OVS_EXCLUDED(rstp_mutex)
1506 ovs_mutex_lock(&rstp_mutex);
1508 struct rstp *rstp = rstp_find(argv[1]);
1510 unixctl_command_reply_error(conn, "No such RSTP object");
1513 rstp->changes = true;
1517 LIST_FOR_EACH (rstp, node, all_rstps) {
1518 rstp->changes = true;
1522 unixctl_command_reply(conn, "OK");
1525 ovs_mutex_unlock(&rstp_mutex);