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"
49 VLOG_DEFINE_THIS_MODULE(rstp);
51 struct ovs_mutex rstp_mutex = OVS_MUTEX_INITIALIZER;
53 static struct ovs_list all_rstps__ = LIST_INITIALIZER(&all_rstps__);
54 static struct ovs_list *const all_rstps OVS_GUARDED_BY(rstp_mutex) = &all_rstps__;
56 /* Internal use only. */
57 static void rstp_set_bridge_address__(struct rstp *, rstp_identifier)
58 OVS_REQUIRES(rstp_mutex);
59 static void rstp_set_bridge_priority__(struct rstp *, int new_priority)
60 OVS_REQUIRES(rstp_mutex);
61 static void rstp_set_bridge_ageing_time__(struct rstp *, int new_ageing_time)
62 OVS_REQUIRES(rstp_mutex);
63 static void rstp_set_bridge_force_protocol_version__(struct rstp *,
64 enum rstp_force_protocol_version)
65 OVS_REQUIRES(rstp_mutex);
66 static void rstp_set_bridge_hello_time__(struct rstp *)
67 OVS_REQUIRES(rstp_mutex);
68 static void rstp_set_bridge_max_age__(struct rstp *, int new_max_age)
69 OVS_REQUIRES(rstp_mutex);
70 static void rstp_set_bridge_forward_delay__(struct rstp *, int new_forward_delay)
71 OVS_REQUIRES(rstp_mutex);
72 static void rstp_set_bridge_transmit_hold_count__(struct rstp *,
73 int new_transmit_hold_count)
74 OVS_REQUIRES(rstp_mutex);
75 static void rstp_set_bridge_migrate_time__(struct rstp *)
76 OVS_REQUIRES(rstp_mutex);
77 static void rstp_set_bridge_times__(struct rstp *, int new_forward_delay,
78 int new_hello_time, int new_max_age,
80 OVS_REQUIRES(rstp_mutex);
82 static struct rstp_port *rstp_get_port__(struct rstp *rstp,
84 OVS_REQUIRES(rstp_mutex);
85 static void set_port_id__(struct rstp_port *)
86 OVS_REQUIRES(rstp_mutex);
87 static void update_port_enabled__(struct rstp_port *)
88 OVS_REQUIRES(rstp_mutex);
89 static void set_bridge_priority__(struct rstp *)
90 OVS_REQUIRES(rstp_mutex);
91 static void reinitialize_rstp__(struct rstp *)
92 OVS_REQUIRES(rstp_mutex);
93 static bool is_port_number_available__(struct rstp *, int, struct rstp_port *)
94 OVS_REQUIRES(rstp_mutex);
95 static uint16_t rstp_first_free_number__(struct rstp *, struct rstp_port *)
96 OVS_REQUIRES(rstp_mutex);
97 static void rstp_initialize_port_defaults__(struct rstp_port *)
98 OVS_REQUIRES(rstp_mutex);
99 static void rstp_port_set_priority__(struct rstp_port *, int priority)
100 OVS_REQUIRES(rstp_mutex);
101 static void rstp_port_set_port_number__(struct rstp_port *,
102 uint16_t port_number)
103 OVS_REQUIRES(rstp_mutex);
104 static void rstp_port_set_path_cost__(struct rstp_port *, uint32_t path_cost)
105 OVS_REQUIRES(rstp_mutex);
106 static void rstp_port_set_administrative_bridge_port__(struct rstp_port *,
107 uint8_t admin_port_state,
109 OVS_REQUIRES(rstp_mutex);
110 static void rstp_port_set_admin_edge__(struct rstp_port *, bool admin_edge)
111 OVS_REQUIRES(rstp_mutex);
112 static void rstp_port_set_auto_edge__(struct rstp_port *, bool auto_edge)
113 OVS_REQUIRES(rstp_mutex);
114 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *,
115 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
116 OVS_REQUIRES(rstp_mutex);
117 static void rstp_port_set_mcheck__(struct rstp_port *, bool mcheck)
118 OVS_REQUIRES(rstp_mutex);
119 static void reinitialize_port__(struct rstp_port *p)
120 OVS_REQUIRES(rstp_mutex);
123 rstp_state_name(enum rstp_state state)
130 case RSTP_FORWARDING:
132 case RSTP_DISCARDING:
140 rstp_port_role_name(enum rstp_port_role role)
145 case ROLE_DESIGNATED:
158 /* Caller has to hold a reference to prevent 'rstp' from being deleted
159 * while taking a new reference. */
161 rstp_ref(struct rstp *rstp)
162 OVS_EXCLUDED(rstp_mutex)
165 ovs_refcount_ref(&rstp->ref_cnt);
170 /* Frees RSTP struct when reference count reaches zero. */
172 rstp_unref(struct rstp *rstp)
173 OVS_EXCLUDED(rstp_mutex)
175 if (rstp && ovs_refcount_unref_relaxed(&rstp->ref_cnt) == 1) {
176 ovs_mutex_lock(&rstp_mutex);
178 /* Each RSTP port points back to struct rstp without holding a
179 * reference for that pointer. This is OK as we never move
180 * ports from one bridge to another, and holders always
181 * release their ports before releasing the bridge. This
182 * means that there should be not ports at this time. */
183 ovs_assert(hmap_is_empty(&rstp->ports));
185 list_remove(&rstp->node);
186 ovs_mutex_unlock(&rstp_mutex);
192 /* Returns the port number. Mutex is needed to guard against
193 * concurrent reinitialization (which can temporarily clear the
196 rstp_port_get_number(const struct rstp_port *p)
197 OVS_EXCLUDED(rstp_mutex)
201 ovs_mutex_lock(&rstp_mutex);
202 number = p->port_number;
203 ovs_mutex_unlock(&rstp_mutex);
208 static void rstp_unixctl_tcn(struct unixctl_conn *, int argc,
209 const char *argv[], void *aux);
211 /* Decrements the State Machines' timers. */
213 rstp_tick_timers(struct rstp *rstp)
214 OVS_EXCLUDED(rstp_mutex)
216 ovs_mutex_lock(&rstp_mutex);
217 decrease_rstp_port_timers__(rstp);
218 ovs_mutex_unlock(&rstp_mutex);
221 /* Processes an incoming BPDU. */
223 rstp_port_received_bpdu(struct rstp_port *rp, const void *bpdu,
225 OVS_EXCLUDED(rstp_mutex)
227 ovs_mutex_lock(&rstp_mutex);
228 /* Only process packets on ports that have RSTP enabled. */
229 if (rp && rp->rstp_state != RSTP_DISABLED) {
230 process_received_bpdu__(rp, bpdu, bpdu_size);
232 ovs_mutex_unlock(&rstp_mutex);
237 OVS_EXCLUDED(rstp_mutex)
239 unixctl_command_register("rstp/tcn", "[bridge]", 0, 1, rstp_unixctl_tcn,
243 /* Creates and returns a new RSTP instance that initially has no ports. */
245 rstp_create(const char *name, rstp_identifier bridge_address,
246 void (*send_bpdu)(struct ofpbuf *bpdu, void *port_aux,
249 OVS_EXCLUDED(rstp_mutex)
253 VLOG_DBG("Creating RSTP instance");
255 rstp = xzalloc(sizeof *rstp);
256 rstp->name = xstrdup(name);
258 /* Initialize the ports map before calling any setters,
259 * so that the state machines will see an empty ports map. */
260 hmap_init(&rstp->ports);
262 ovs_mutex_lock(&rstp_mutex);
263 /* Set bridge address. */
264 rstp_set_bridge_address__(rstp, bridge_address);
265 /* Set default parameters values. */
266 rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
267 rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
268 rstp_set_bridge_force_protocol_version__(rstp, FPV_DEFAULT);
269 rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
270 rstp_set_bridge_hello_time__(rstp);
271 rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
272 rstp_set_bridge_migrate_time__(rstp);
273 rstp_set_bridge_transmit_hold_count__(rstp,
274 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
275 rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
276 RSTP_BRIDGE_HELLO_TIME,
277 RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
278 rstp->send_bpdu = send_bpdu;
280 rstp->changes = false;
283 ovs_refcount_init(&rstp->ref_cnt);
285 list_push_back(all_rstps, &rstp->node);
286 ovs_mutex_unlock(&rstp_mutex);
288 VLOG_DBG("RSTP instance creation done");
292 /* Called by rstp_set_bridge_address() and rstp_set_bridge_priority(),
293 * it updates the bridge priority vector according to the values passed by
297 set_bridge_priority__(struct rstp *rstp)
298 OVS_REQUIRES(rstp_mutex)
302 rstp->bridge_priority.root_bridge_id = rstp->bridge_identifier;
303 rstp->bridge_priority.designated_bridge_id = rstp->bridge_identifier;
304 VLOG_DBG("%s: new bridge identifier: "RSTP_ID_FMT"", rstp->name,
305 RSTP_ID_ARGS(rstp->bridge_identifier));
307 /* [17.13] When the bridge address changes, recalculates all priority
310 HMAP_FOR_EACH (p, node, &rstp->ports) {
314 rstp->changes = true;
315 updt_roles_tree__(rstp);
318 /* Sets the bridge address. */
320 rstp_set_bridge_address__(struct rstp *rstp, rstp_identifier bridge_address)
321 OVS_REQUIRES(rstp_mutex)
323 VLOG_DBG("%s: set bridge address to: "RSTP_ID_FMT"", rstp->name,
324 RSTP_ID_ARGS(bridge_address));
325 if (rstp->address != bridge_address) {
326 rstp->address = bridge_address;
327 rstp->bridge_identifier &= 0xffff000000000000ULL;
328 rstp->bridge_identifier |= bridge_address;
329 set_bridge_priority__(rstp);
333 /* Sets the bridge address. */
335 rstp_set_bridge_address(struct rstp *rstp, rstp_identifier bridge_address)
336 OVS_EXCLUDED(rstp_mutex)
338 ovs_mutex_lock(&rstp_mutex);
339 rstp_set_bridge_address__(rstp, bridge_address);
340 ovs_mutex_unlock(&rstp_mutex);
344 rstp_get_name(const struct rstp *rstp)
345 OVS_EXCLUDED(rstp_mutex)
349 ovs_mutex_lock(&rstp_mutex);
351 ovs_mutex_unlock(&rstp_mutex);
356 rstp_get_bridge_id(const struct rstp *rstp)
357 OVS_EXCLUDED(rstp_mutex)
359 rstp_identifier bridge_id;
361 ovs_mutex_lock(&rstp_mutex);
362 bridge_id = rstp->bridge_identifier;
363 ovs_mutex_unlock(&rstp_mutex);
368 /* Sets the bridge priority. */
370 rstp_set_bridge_priority__(struct rstp *rstp, int new_priority)
371 OVS_REQUIRES(rstp_mutex)
373 new_priority = ROUND_DOWN(new_priority, RSTP_PRIORITY_STEP);
375 if (rstp->priority != new_priority
376 && new_priority >= RSTP_MIN_PRIORITY
377 && new_priority <= RSTP_MAX_PRIORITY) {
378 VLOG_DBG("%s: set bridge priority to %d", rstp->name, new_priority);
380 rstp->priority = new_priority;
381 rstp->bridge_identifier &= 0x0000ffffffffffffULL;
382 rstp->bridge_identifier |= (uint64_t)new_priority << 48;
383 set_bridge_priority__(rstp);
388 rstp_set_bridge_priority(struct rstp *rstp, int new_priority)
389 OVS_EXCLUDED(rstp_mutex)
391 ovs_mutex_lock(&rstp_mutex);
392 rstp_set_bridge_priority__(rstp, new_priority);
393 ovs_mutex_unlock(&rstp_mutex);
396 /* Sets the bridge ageing time. */
398 rstp_set_bridge_ageing_time__(struct rstp *rstp, int new_ageing_time)
399 OVS_REQUIRES(rstp_mutex)
401 if (new_ageing_time >= RSTP_MIN_AGEING_TIME
402 && new_ageing_time <= RSTP_MAX_AGEING_TIME) {
403 VLOG_DBG("%s: set ageing time to %d", rstp->name, new_ageing_time);
405 rstp->ageing_time = new_ageing_time;
410 rstp_set_bridge_ageing_time(struct rstp *rstp, int new_ageing_time)
411 OVS_EXCLUDED(rstp_mutex)
413 ovs_mutex_lock(&rstp_mutex);
414 rstp_set_bridge_ageing_time__(rstp, new_ageing_time);
415 ovs_mutex_unlock(&rstp_mutex);
418 /* Reinitializes RSTP when switching from RSTP mode to STP mode
422 reinitialize_rstp__(struct rstp *rstp)
423 OVS_REQUIRES(rstp_mutex)
426 static struct hmap ports;
429 /* Copy rstp in temp */
433 /* stop and clear rstp */
434 memset(rstp, 0, sizeof(struct rstp));
436 /* Initialize rstp. */
437 rstp->name = temp.name;
439 /* Initialize the ports hmap before calling any setters,
440 * so that the state machines will see an empty ports list. */
441 hmap_init(&rstp->ports);
443 /* Set bridge address. */
444 rstp_set_bridge_address__(rstp, temp.address);
445 /* Set default parameters values. */
446 rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
447 rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
448 rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
449 rstp_set_bridge_hello_time__(rstp);
450 rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
451 rstp_set_bridge_migrate_time__(rstp);
452 rstp_set_bridge_transmit_hold_count__(rstp,
453 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
454 rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
455 RSTP_BRIDGE_HELLO_TIME,
456 RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
458 rstp->send_bpdu = temp.send_bpdu;
459 rstp->aux = temp.aux;
460 rstp->node = temp.node;
461 rstp->changes = false;
467 HMAP_FOR_EACH (p, node, &rstp->ports) {
468 reinitialize_port__(p);
471 rstp->ref_cnt = temp.ref_cnt;
474 /* Sets the force protocol version parameter. */
476 rstp_set_bridge_force_protocol_version__(struct rstp *rstp,
477 enum rstp_force_protocol_version new_force_protocol_version)
478 OVS_REQUIRES(rstp_mutex)
480 if (new_force_protocol_version != rstp->force_protocol_version &&
481 (new_force_protocol_version == FPV_STP_COMPATIBILITY ||
482 new_force_protocol_version == FPV_DEFAULT)) {
483 VLOG_DBG("%s: set bridge Force Protocol Version to %d", rstp->name,
484 new_force_protocol_version);
486 /* [17.13] The Spanning Tree Protocol Entity shall be reinitialized,
487 * as specified by the assertion of BEGIN (17.18.1) in the state
488 * machine specification.
490 reinitialize_rstp__(rstp);
491 rstp->force_protocol_version = new_force_protocol_version;
492 if (rstp->force_protocol_version < 2) {
493 rstp->stp_version = true;
494 rstp->rstp_version = false;
496 rstp->stp_version = false;
497 rstp->rstp_version = true;
499 rstp->changes = true;
505 rstp_set_bridge_force_protocol_version(struct rstp *rstp,
506 enum rstp_force_protocol_version new_force_protocol_version)
507 OVS_EXCLUDED(rstp_mutex)
509 ovs_mutex_lock(&rstp_mutex);
510 rstp_set_bridge_force_protocol_version__(rstp, new_force_protocol_version);
511 ovs_mutex_unlock(&rstp_mutex);
514 /* Sets the bridge Hello Time parameter. */
516 rstp_set_bridge_hello_time__(struct rstp *rstp)
517 OVS_REQUIRES(rstp_mutex)
519 VLOG_DBG("%s: set RSTP Hello Time to %d", rstp->name,
520 RSTP_BRIDGE_HELLO_TIME);
521 /* 2 is the only acceptable value. */
522 rstp->bridge_hello_time = RSTP_BRIDGE_HELLO_TIME;
525 /* Sets the bridge max age parameter. */
527 rstp_set_bridge_max_age__(struct rstp *rstp, int new_max_age)
528 OVS_REQUIRES(rstp_mutex)
530 if (rstp->bridge_max_age != new_max_age
531 && new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
532 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
534 if ((2 * (rstp->bridge_forward_delay - 1) >= new_max_age)
535 && (new_max_age >= 2 * rstp->bridge_hello_time)) {
536 VLOG_DBG("%s: set RSTP bridge Max Age to %d", rstp->name,
539 rstp->bridge_max_age = new_max_age;
540 rstp->bridge_times.max_age = new_max_age;
541 rstp->changes = true;
542 updt_roles_tree__(rstp);
548 rstp_set_bridge_max_age(struct rstp *rstp, int new_max_age)
549 OVS_EXCLUDED(rstp_mutex)
551 ovs_mutex_lock(&rstp_mutex);
552 rstp_set_bridge_max_age__(rstp, new_max_age);
553 ovs_mutex_unlock(&rstp_mutex);
556 /* Sets the bridge forward delay parameter. */
558 rstp_set_bridge_forward_delay__(struct rstp *rstp, int new_forward_delay)
559 OVS_REQUIRES(rstp_mutex)
561 if (rstp->bridge_forward_delay != new_forward_delay
562 && new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
563 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
564 if (2 * (new_forward_delay - 1) >= rstp->bridge_max_age) {
565 VLOG_DBG("%s: set RSTP Forward Delay to %d", rstp->name,
567 rstp->bridge_forward_delay = new_forward_delay;
568 rstp->bridge_times.forward_delay = new_forward_delay;
569 rstp->changes = true;
570 updt_roles_tree__(rstp);
576 rstp_set_bridge_forward_delay(struct rstp *rstp, int new_forward_delay)
577 OVS_EXCLUDED(rstp_mutex)
579 ovs_mutex_lock(&rstp_mutex);
580 rstp_set_bridge_forward_delay__(rstp, new_forward_delay);
581 ovs_mutex_unlock(&rstp_mutex);
584 /* Sets the bridge transmit hold count parameter. */
586 rstp_set_bridge_transmit_hold_count__(struct rstp *rstp,
587 int new_transmit_hold_count)
588 OVS_REQUIRES(rstp_mutex)
590 if (rstp->transmit_hold_count != new_transmit_hold_count
591 && new_transmit_hold_count >= RSTP_MIN_TRANSMIT_HOLD_COUNT
592 && new_transmit_hold_count <= RSTP_MAX_TRANSMIT_HOLD_COUNT) {
595 VLOG_DBG("%s: set RSTP Transmit Hold Count to %d", rstp->name,
596 new_transmit_hold_count);
597 /* Resetting txCount on all ports [17.13]. */
599 rstp->transmit_hold_count = new_transmit_hold_count;
600 HMAP_FOR_EACH (p, node, &rstp->ports) {
607 rstp_set_bridge_transmit_hold_count(struct rstp *rstp,
608 int new_transmit_hold_count)
609 OVS_EXCLUDED(rstp_mutex)
611 ovs_mutex_lock(&rstp_mutex);
612 rstp_set_bridge_transmit_hold_count__(rstp, new_transmit_hold_count);
613 ovs_mutex_unlock(&rstp_mutex);
616 /* Sets the bridge migrate time parameter. */
618 rstp_set_bridge_migrate_time__(struct rstp *rstp)
619 OVS_REQUIRES(rstp_mutex)
621 VLOG_DBG("%s: set RSTP Migrate Time to %d", rstp->name,
623 /* 3 is the only acceptable value */
624 rstp->migrate_time = RSTP_MIGRATE_TIME;
627 /* Sets the bridge times. */
629 rstp_set_bridge_times__(struct rstp *rstp, int new_forward_delay,
630 int new_hello_time, int new_max_age,
632 OVS_REQUIRES(rstp_mutex)
634 VLOG_DBG("%s: set RSTP times to (%d, %d, %d, %d)", rstp->name,
635 new_forward_delay, new_hello_time, new_max_age, new_message_age);
636 if (new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
637 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
638 rstp->bridge_times.forward_delay = new_forward_delay;
640 if (new_hello_time == RSTP_BRIDGE_HELLO_TIME) {
641 rstp->bridge_times.hello_time = new_hello_time;
643 if (new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
644 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
645 rstp->bridge_times.max_age = new_max_age;
647 rstp->bridge_times.message_age = new_message_age;
650 /* Sets the port id, it is called by rstp_port_set_port_number__() or
651 * rstp_port_set_priority__().
654 set_port_id__(struct rstp_port *p)
655 OVS_REQUIRES(rstp_mutex)
660 /* [9.2.7] Port identifier. */
661 p->port_id = p->port_number | (p->priority << 8);
662 VLOG_DBG("%s: new RSTP port id "RSTP_PORT_ID_FMT"", rstp->name,
666 /* Sets the port priority. */
668 rstp_port_set_priority__(struct rstp_port *port, int priority)
669 OVS_REQUIRES(rstp_mutex)
671 if (port->priority != priority
672 && priority >= RSTP_MIN_PORT_PRIORITY
673 && priority <= RSTP_MAX_PORT_PRIORITY) {
674 VLOG_DBG("%s, port %u: set RSTP port priority to %d", port->rstp->name,
675 port->port_number, priority);
677 priority -= priority % RSTP_STEP_PORT_PRIORITY;
678 port->priority = priority;
680 port->selected = false;
681 port->reselect = true;
685 /* Checks if a port number is available. */
687 is_port_number_available__(struct rstp *rstp, int n, struct rstp_port *port)
688 OVS_REQUIRES(rstp_mutex)
690 if (n >= 1 && n <= RSTP_MAX_PORTS) {
691 struct rstp_port *p = rstp_get_port__(rstp, n);
693 return p == NULL || p == port;
699 rstp_first_free_number__(struct rstp *rstp, struct rstp_port *rstp_port)
700 OVS_REQUIRES(rstp_mutex)
704 while (free_number <= RSTP_MAX_PORTS) {
705 if (is_port_number_available__(rstp, free_number, rstp_port)) {
710 VLOG_DBG("%s, No free port number available.", rstp->name);
714 /* Sets the port number. */
716 rstp_port_set_port_number__(struct rstp_port *port, uint16_t port_number)
717 OVS_REQUIRES(rstp_mutex)
719 int old_port_number = port->port_number;
721 /* If new_port_number is available, use it, otherwise use the first free
722 * available port number. */
723 if (port->port_number != port_number || port_number == 0) {
725 is_port_number_available__(port->rstp, port_number, port)
727 : rstp_first_free_number__(port->rstp, port);
729 if (port->port_number != old_port_number) {
731 /* [17.13] is not clear. I suppose that a port number change
732 * should trigger reselection like a port priority change. */
733 port->selected = false;
734 port->reselect = true;
736 /* Adjust the ports hmap. */
737 if (!hmap_node_is_null(&port->node)) {
738 hmap_remove(&port->rstp->ports, &port->node);
740 hmap_insert(&port->rstp->ports, &port->node,
741 hash_int(port->port_number, 0));
743 VLOG_DBG("%s: set new RSTP port number %d", port->rstp->name,
749 /* Converts the link speed to a port path cost [Table 17-3]. */
751 rstp_convert_speed_to_cost(unsigned int speed)
755 value = speed >= 10000000 ? 2 /* 10 Tb/s. */
756 : speed >= 1000000 ? 20 /* 1 Tb/s. */
757 : speed >= 100000 ? 200 /* 100 Gb/s. */
758 : speed >= 10000 ? 2000 /* 10 Gb/s. */
759 : speed >= 1000 ? 20000 /* 1 Gb/s. */
760 : speed >= 100 ? 200000 /* 100 Mb/s. */
761 : speed >= 10 ? 2000000 /* 10 Mb/s. */
762 : speed >= 1 ? 20000000 /* 1 Mb/s. */
763 : RSTP_DEFAULT_PORT_PATH_COST; /* 100 Mb/s. */
768 /* Sets the port path cost. */
770 rstp_port_set_path_cost__(struct rstp_port *port, uint32_t path_cost)
771 OVS_REQUIRES(rstp_mutex)
773 if (port->port_path_cost != path_cost
774 && path_cost >= RSTP_MIN_PORT_PATH_COST
775 && path_cost <= RSTP_MAX_PORT_PATH_COST) {
776 VLOG_DBG("%s, port %u, set RSTP port path cost to %d",
777 port->rstp->name, port->port_number, path_cost);
779 port->port_path_cost = path_cost;
780 port->selected = false;
781 port->reselect = true;
785 /* Gets the root path cost. */
787 rstp_get_root_path_cost(const struct rstp *rstp)
788 OVS_EXCLUDED(rstp_mutex)
792 ovs_mutex_lock(&rstp_mutex);
793 cost = rstp->root_priority.root_path_cost;
794 ovs_mutex_unlock(&rstp_mutex);
798 /* Finds a port which needs to flush its own MAC learning table. A NULL
799 * pointer is returned if no port needs to flush its MAC learning table.
800 * '*port' needs to be NULL in the first call to start the iteration. If
801 * '*port' is passed as non-NULL, it must be the value set by the last
802 * invocation of this function.
804 * This function may only be called by the thread that creates and deletes
805 * ports. Otherwise this function is not thread safe, as the returned
806 * '*port' could become stale before it is used in the next invocation. */
808 rstp_check_and_reset_fdb_flush(struct rstp *rstp, struct rstp_port **port)
809 OVS_EXCLUDED(rstp_mutex)
813 ovs_mutex_lock(&rstp_mutex);
817 HMAP_FOR_EACH (p, node, &rstp->ports) {
824 } else { /* continue */
825 struct rstp_port *p = *port;
827 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
835 /* No port needs flushing. */
838 /* fdb_flush should be reset by the filtering database
839 * once the entries are removed if rstp_version is TRUE, and
840 * immediately if stp_version is TRUE.*/
842 (*port)->fdb_flush = false;
844 ovs_mutex_unlock(&rstp_mutex);
849 /* Finds a port whose state has changed, and returns the aux pointer set for
850 * the port. A NULL pointer is returned when no changed port is found. On
851 * return '*portp' contains the pointer to the rstp port that changed, or NULL
852 * if no changed port can be found.
854 * If '*portp' is passed as non-NULL, it must be the value set by the last
855 * invocation of this function.
857 * This function may only be called by the thread that creates and deletes
858 * ports. Otherwise this function is not thread safe, as the returned
859 * '*portp' could become stale before it is used in the next invocation. */
861 rstp_get_next_changed_port_aux(struct rstp *rstp, struct rstp_port **portp)
865 ovs_mutex_lock(&rstp_mutex);
866 if (*portp == NULL) {
869 HMAP_FOR_EACH (p, node, &rstp->ports) {
870 if (p->state_changed) {
871 p->state_changed = false;
877 } else { /* continue */
878 struct rstp_port *p = *portp;
880 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
881 if (p->state_changed) {
882 p->state_changed = false;
889 /* No changed port found. */
892 ovs_mutex_unlock(&rstp_mutex);
898 rstp_shift_root_learned_address(struct rstp *rstp)
902 ovs_mutex_lock(&rstp_mutex);
903 ret = rstp->root_changed;
904 ovs_mutex_unlock(&rstp_mutex);
910 rstp_get_old_root_aux(struct rstp *rstp)
914 ovs_mutex_lock(&rstp_mutex);
915 aux = rstp->old_root_aux;
916 ovs_mutex_unlock(&rstp_mutex);
922 rstp_get_new_root_aux(struct rstp *rstp)
926 ovs_mutex_lock(&rstp_mutex);
927 aux = rstp->new_root_aux;
928 ovs_mutex_unlock(&rstp_mutex);
934 rstp_reset_root_changed(struct rstp *rstp)
936 ovs_mutex_lock(&rstp_mutex);
937 rstp->root_changed = false;
938 ovs_mutex_unlock(&rstp_mutex);
941 /* Returns the port in 'rstp' with number 'port_number'.
943 * XXX: May only be called while concurrent deletion of ports is excluded. */
944 static struct rstp_port *
945 rstp_get_port__(struct rstp *rstp, uint16_t port_number)
946 OVS_REQUIRES(rstp_mutex)
948 struct rstp_port *port;
950 ovs_assert(rstp && port_number > 0 && port_number <= RSTP_MAX_PORTS);
952 HMAP_FOR_EACH_WITH_HASH (port, node, hash_int(port_number, 0),
954 if (port->port_number == port_number) {
962 rstp_get_port(struct rstp *rstp, uint16_t port_number)
963 OVS_EXCLUDED(rstp_mutex)
967 ovs_mutex_lock(&rstp_mutex);
968 p = rstp_get_port__(rstp, port_number);
969 ovs_mutex_unlock(&rstp_mutex);
974 rstp_get_port_aux__(struct rstp *rstp, uint16_t port_number)
975 OVS_REQUIRES(rstp_mutex)
978 p = rstp_get_port__(rstp, port_number);
985 /* Updates the port_enabled parameter. */
987 update_port_enabled__(struct rstp_port *p)
988 OVS_REQUIRES(rstp_mutex)
990 if (p->mac_operational && p->is_administrative_bridge_port
991 == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED) {
992 p->port_enabled = true;
994 p->port_enabled = false;
998 /* Sets the port MAC_Operational parameter [6.4.2]. */
1000 rstp_port_set_mac_operational(struct rstp_port *p, bool new_mac_operational)
1001 OVS_EXCLUDED(rstp_mutex)
1005 ovs_mutex_lock(&rstp_mutex);
1007 if (p->mac_operational != new_mac_operational) {
1008 p->mac_operational = new_mac_operational;
1009 update_port_enabled__(p);
1010 rstp->changes = true;
1013 ovs_mutex_unlock(&rstp_mutex);
1016 /* Sets the port Administrative Bridge Port parameter. */
1018 rstp_port_set_administrative_bridge_port__(struct rstp_port *p,
1019 uint8_t admin_port_state,
1021 OVS_REQUIRES(rstp_mutex)
1023 VLOG_DBG("%s, port %u: set RSTP port admin-port-state to %d",
1024 p->rstp->name, p->port_number, admin_port_state);
1026 if (p->is_administrative_bridge_port != admin_port_state
1027 && (admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_DISABLED
1028 || admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED)) {
1029 p->is_administrative_bridge_port = admin_port_state;
1030 update_port_enabled__(p);
1032 if (!initializing) {
1033 struct rstp *rstp = p->rstp;
1035 rstp->changes = true;
1041 /* Sets the port oper_point_to_point_mac parameter. */
1043 rstp_port_set_oper_point_to_point_mac__(struct rstp_port *p,
1044 uint8_t new_oper_p2p_mac)
1045 OVS_REQUIRES(rstp_mutex)
1047 if (p->oper_point_to_point_mac != new_oper_p2p_mac
1048 && (new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_DISABLED
1049 || new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_ENABLED)) {
1051 p->oper_point_to_point_mac = new_oper_p2p_mac;
1052 update_port_enabled__(p);
1056 /* Initializes a port with the defaults values for its parameters. */
1058 rstp_initialize_port_defaults__(struct rstp_port *p)
1059 OVS_REQUIRES(rstp_mutex)
1061 rstp_port_set_administrative_bridge_port__(p,
1062 RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED,
1064 rstp_port_set_oper_point_to_point_mac__(p,
1065 RSTP_OPER_P2P_MAC_STATE_ENABLED);
1066 rstp_port_set_path_cost__(p, RSTP_DEFAULT_PORT_PATH_COST);
1067 rstp_port_set_admin_edge__(p, false);
1068 rstp_port_set_auto_edge__(p, true);
1069 rstp_port_set_mcheck__(p, false);
1071 /* Initialize state machines. */
1072 p->port_receive_sm_state = PORT_RECEIVE_SM_INIT;
1073 p->port_protocol_migration_sm_state = PORT_PROTOCOL_MIGRATION_SM_INIT;
1074 p->bridge_detection_sm_state = BRIDGE_DETECTION_SM_INIT;
1075 p->port_transmit_sm_state = PORT_TRANSMIT_SM_INIT;
1076 p->port_information_sm_state = PORT_INFORMATION_SM_INIT;
1077 p->port_role_transition_sm_state = PORT_ROLE_TRANSITION_SM_INIT;
1078 p->port_state_transition_sm_state = PORT_STATE_TRANSITION_SM_INIT;
1079 p->topology_change_sm_state = TOPOLOGY_CHANGE_SM_INIT;
1085 reinitialize_port__(struct rstp_port *p)
1086 OVS_REQUIRES(rstp_mutex)
1088 struct rstp_port temp_port;
1093 memset(p, 0, sizeof(struct rstp_port));
1095 p->ref_cnt = temp_port.ref_cnt;
1097 p->node = temp_port.node;
1098 p->aux = temp_port.aux;
1099 p->port_number = temp_port.port_number;
1100 p->port_priority = temp_port.port_priority;
1101 p->port_id = temp_port.port_id;
1102 p->rstp_state = RSTP_DISCARDING;
1104 rstp_initialize_port_defaults__(p);
1106 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" reinitialized.", rstp->name,
1111 reinitialize_port(struct rstp_port *p)
1112 OVS_EXCLUDED(rstp_mutex)
1114 ovs_mutex_lock(&rstp_mutex);
1115 reinitialize_port__(p);
1116 ovs_mutex_unlock(&rstp_mutex);
1119 /* Sets the port state. */
1121 rstp_port_set_state__(struct rstp_port *p, enum rstp_state state)
1122 OVS_REQUIRES(rstp_mutex)
1127 VLOG_DBG("%s, port %u: set RSTP port state %s -> %s", rstp->name,
1129 rstp_state_name(p->rstp_state), rstp_state_name(state));
1131 if (state != p->rstp_state && !p->state_changed) {
1132 p->state_changed = true;
1133 seq_change(connectivity_seq_get());
1135 p->rstp_state = state;
1139 rstp_port_set_state(struct rstp_port *p, enum rstp_state state)
1140 OVS_EXCLUDED(rstp_mutex)
1142 ovs_mutex_lock(&rstp_mutex);
1143 rstp_port_set_state__(p, state);
1144 ovs_mutex_unlock(&rstp_mutex);
1147 /* Adds a RSTP port. */
1149 rstp_add_port(struct rstp *rstp)
1150 OVS_EXCLUDED(rstp_mutex)
1152 struct rstp_port *p = xzalloc(sizeof *p);
1154 ovs_refcount_init(&p->ref_cnt);
1155 hmap_node_nullify(&p->node);
1157 ovs_mutex_lock(&rstp_mutex);
1159 rstp_port_set_priority__(p, RSTP_DEFAULT_PORT_PRIORITY);
1160 rstp_port_set_port_number__(p, 0);
1162 rstp_initialize_port_defaults__(p);
1163 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" initialized.", rstp->name,
1166 rstp_port_set_state__(p, RSTP_DISCARDING);
1167 rstp->changes = true;
1169 VLOG_DBG("%s: added port "RSTP_PORT_ID_FMT"", rstp->name, p->port_id);
1170 ovs_mutex_unlock(&rstp_mutex);
1174 /* Caller has to hold a reference to prevent 'rstp_port' from being deleted
1175 * while taking a new reference. */
1177 rstp_port_ref(const struct rstp_port *rp_)
1178 OVS_EXCLUDED(rstp_mutex)
1180 struct rstp_port *rp = CONST_CAST(struct rstp_port *, rp_);
1183 ovs_refcount_ref(&rp->ref_cnt);
1188 /* Frees RSTP struct. This can be caller by any thread. */
1190 rstp_port_unref(struct rstp_port *rp)
1191 OVS_EXCLUDED(rstp_mutex)
1193 if (rp && ovs_refcount_unref_relaxed(&rp->ref_cnt) == 1) {
1196 ovs_mutex_lock(&rstp_mutex);
1198 rstp_port_set_state__(rp, RSTP_DISABLED);
1199 hmap_remove(&rstp->ports, &rp->node);
1200 VLOG_DBG("%s: removed port "RSTP_PORT_ID_FMT"", rstp->name,
1202 ovs_mutex_unlock(&rstp_mutex);
1207 /* Sets the port Admin Edge parameter. */
1209 rstp_port_set_admin_edge__(struct rstp_port *port, bool admin_edge)
1210 OVS_REQUIRES(rstp_mutex)
1212 if (port->admin_edge != admin_edge) {
1213 VLOG_DBG("%s, port %u: set RSTP Admin Edge to %d", port->rstp->name,
1214 port->port_number, admin_edge);
1216 port->admin_edge = admin_edge;
1220 /* Sets the port Auto Edge parameter. */
1222 rstp_port_set_auto_edge__(struct rstp_port *port, bool auto_edge)
1223 OVS_REQUIRES(rstp_mutex)
1225 if (port->auto_edge != auto_edge) {
1226 VLOG_DBG("%s, port %u: set RSTP Auto Edge to %d", port->rstp->name,
1227 port->port_number, auto_edge);
1229 port->auto_edge = auto_edge;
1233 /* Sets the port admin_point_to_point_mac parameter. */
1234 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *port,
1235 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
1236 OVS_REQUIRES(rstp_mutex)
1238 VLOG_DBG("%s, port %u: set RSTP port admin-point-to-point-mac to %d",
1239 port->rstp->name, port->port_number, admin_p2p_mac_state);
1240 if (port->admin_point_to_point_mac != admin_p2p_mac_state) {
1241 if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_TRUE) {
1242 port->admin_point_to_point_mac = admin_p2p_mac_state;
1243 rstp_port_set_oper_point_to_point_mac__(
1244 port, RSTP_OPER_P2P_MAC_STATE_ENABLED);
1245 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_FALSE) {
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_DISABLED);
1249 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_AUTO) {
1250 /* If adminPointToPointMAC is set to Auto, then the value of
1251 * operPointToPointMAC is determined in accordance with the
1252 * specific procedures defined for the MAC entity concerned, as
1253 * defined in 6.5. If these procedures determine that the MAC
1254 * entity is connected to a point-to-point LAN, then
1255 * operPointToPointMAC is set TRUE; otherwise it is set FALSE.
1256 * In the absence of a specific definition of how to determine
1257 * whether the MAC is connected to a point-to-point LAN or not,
1258 * the value of operPointToPointMAC shall be FALSE. */
1259 port->admin_point_to_point_mac = admin_p2p_mac_state;
1260 rstp_port_set_oper_point_to_point_mac__(
1261 port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
1266 /* Sets the port mcheck parameter.
1267 * [17.19.13] May be set by management to force the Port Protocol Migration
1268 * state machine to transmit RST BPDUs for a MigrateTime (17.13.9) period, to
1269 * test whether all STP Bridges (17.4) on the attached LAN have been removed
1270 * and the Port can continue to transmit RSTP BPDUs. Setting mcheck has no
1271 * effect if stpVersion (17.20.12) is TRUE, i.e., the Bridge is operating in
1272 * STP Compatibility mode.
1275 rstp_port_set_mcheck__(struct rstp_port *port, bool mcheck)
1276 OVS_REQUIRES(rstp_mutex)
1278 if (mcheck == true && port->rstp->force_protocol_version >= 2) {
1279 port->mcheck = true;
1281 VLOG_DBG("%s, port %u: set RSTP mcheck to %d", port->rstp->name,
1282 port->port_number, mcheck);
1286 /* Returns the designated bridge id. */
1288 rstp_get_designated_id(const struct rstp *rstp)
1289 OVS_EXCLUDED(rstp_mutex)
1291 rstp_identifier designated_id;
1293 ovs_mutex_lock(&rstp_mutex);
1294 designated_id = rstp->root_priority.designated_bridge_id;
1295 ovs_mutex_unlock(&rstp_mutex);
1297 return designated_id;
1300 /* Returns the root bridge id. */
1302 rstp_get_root_id(const struct rstp *rstp)
1303 OVS_EXCLUDED(rstp_mutex)
1305 rstp_identifier root_id;
1307 ovs_mutex_lock(&rstp_mutex);
1308 root_id = rstp->root_priority.root_bridge_id;
1309 ovs_mutex_unlock(&rstp_mutex);
1314 /* Returns the designated port id. */
1316 rstp_get_designated_port_id(const struct rstp *rstp)
1317 OVS_EXCLUDED(rstp_mutex)
1319 uint16_t designated_port_id;
1321 ovs_mutex_lock(&rstp_mutex);
1322 designated_port_id = rstp->root_priority.designated_port_id;
1323 ovs_mutex_unlock(&rstp_mutex);
1325 return designated_port_id;
1328 /* Return the bridge port id. */
1330 rstp_get_bridge_port_id(const struct rstp *rstp)
1331 OVS_EXCLUDED(rstp_mutex)
1333 uint16_t bridge_port_id;
1335 ovs_mutex_lock(&rstp_mutex);
1336 bridge_port_id = rstp->root_priority.bridge_port_id;
1337 ovs_mutex_unlock(&rstp_mutex);
1339 return bridge_port_id;
1342 /* Returns true if the bridge believes to the be root of the spanning tree,
1346 rstp_is_root_bridge(const struct rstp *rstp)
1347 OVS_EXCLUDED(rstp_mutex)
1351 ovs_mutex_lock(&rstp_mutex);
1352 is_root = rstp->bridge_identifier ==
1353 rstp->root_priority.designated_bridge_id;
1354 ovs_mutex_unlock(&rstp_mutex);
1359 /* Returns the bridge ID of the bridge currently believed to be the root. */
1361 rstp_get_designated_root(const struct rstp *rstp)
1362 OVS_EXCLUDED(rstp_mutex)
1364 rstp_identifier designated_root;
1366 ovs_mutex_lock(&rstp_mutex);
1367 designated_root = rstp->root_priority.designated_bridge_id;
1368 ovs_mutex_unlock(&rstp_mutex);
1370 return designated_root;
1373 /* Returns the port connecting 'rstp' to the root bridge, or a null pointer if
1374 * there is no such port.
1377 rstp_get_root_port(struct rstp *rstp)
1378 OVS_EXCLUDED(rstp_mutex)
1380 struct rstp_port *p;
1382 ovs_mutex_lock(&rstp_mutex);
1383 HMAP_FOR_EACH (p, node, &rstp->ports) {
1384 if (p->port_id == rstp->root_port_id) {
1385 ovs_mutex_unlock(&rstp_mutex);
1389 ovs_mutex_unlock(&rstp_mutex);
1393 /* Returns the state of port 'p'. */
1395 rstp_port_get_state(const struct rstp_port *p)
1396 OVS_EXCLUDED(rstp_mutex)
1398 enum rstp_state state;
1400 ovs_mutex_lock(&rstp_mutex);
1401 state = p->rstp_state;
1402 ovs_mutex_unlock(&rstp_mutex);
1407 /* Retrieves port status. */
1409 rstp_port_get_status(const struct rstp_port *p, uint16_t *id,
1410 enum rstp_state *state, enum rstp_port_role *role,
1411 rstp_identifier *designated_bridge_id,
1412 uint16_t *designated_port_id,
1413 uint32_t *designated_path_cost, int *tx_count,
1414 int *rx_count, int *error_count, int *uptime)
1415 OVS_EXCLUDED(rstp_mutex)
1417 ovs_mutex_lock(&rstp_mutex);
1419 *state = p->rstp_state;
1422 *designated_bridge_id = p->port_priority.designated_bridge_id;
1423 *designated_port_id = p->port_priority.designated_port_id;
1424 *designated_path_cost = p->port_priority.root_path_cost;
1426 *tx_count = p->tx_count;
1427 *rx_count = p->rx_rstp_bpdu_cnt;
1428 *error_count = p->error_count;
1429 *uptime = p->uptime;
1430 ovs_mutex_unlock(&rstp_mutex);
1434 rstp_port_set(struct rstp_port *port, uint16_t port_num, int priority,
1435 uint32_t path_cost, bool is_admin_edge, bool is_auto_edge,
1436 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state,
1437 bool admin_port_state, bool do_mcheck, void *aux)
1438 OVS_EXCLUDED(rstp_mutex)
1440 ovs_mutex_lock(&rstp_mutex);
1442 rstp_port_set_priority__(port, priority);
1443 rstp_port_set_port_number__(port, port_num);
1444 rstp_port_set_path_cost__(port, path_cost);
1445 rstp_port_set_admin_edge__(port, is_admin_edge);
1446 rstp_port_set_auto_edge__(port, is_auto_edge);
1447 rstp_port_set_admin_point_to_point_mac__(port, admin_p2p_mac_state);
1448 rstp_port_set_administrative_bridge_port__(port, admin_port_state, false);
1449 rstp_port_set_mcheck__(port, do_mcheck);
1450 ovs_mutex_unlock(&rstp_mutex);
1453 /* Individual setters only used by test-rstp.c. */
1455 rstp_port_set_priority(struct rstp_port *port, int priority)
1456 OVS_EXCLUDED(rstp_mutex)
1458 ovs_mutex_lock(&rstp_mutex);
1459 rstp_port_set_priority__(port, priority);
1460 ovs_mutex_unlock(&rstp_mutex);
1464 rstp_port_set_path_cost(struct rstp_port *port, uint32_t path_cost)
1465 OVS_EXCLUDED(rstp_mutex)
1467 ovs_mutex_lock(&rstp_mutex);
1468 rstp_port_set_path_cost__(port, path_cost);
1469 ovs_mutex_unlock(&rstp_mutex);
1473 rstp_port_set_aux(struct rstp_port *port, void *aux)
1474 OVS_EXCLUDED(rstp_mutex)
1476 ovs_mutex_lock(&rstp_mutex);
1478 ovs_mutex_unlock(&rstp_mutex);
1482 static struct rstp *
1483 rstp_find(const char *name)
1484 OVS_REQUIRES(rstp_mutex)
1488 LIST_FOR_EACH (rstp, node, all_rstps) {
1489 if (!strcmp(rstp->name, name)) {
1497 rstp_unixctl_tcn(struct unixctl_conn *conn, int argc,
1498 const char *argv[], void *aux OVS_UNUSED)
1499 OVS_EXCLUDED(rstp_mutex)
1501 ovs_mutex_lock(&rstp_mutex);
1503 struct rstp *rstp = rstp_find(argv[1]);
1505 unixctl_command_reply_error(conn, "No such RSTP object");
1508 rstp->changes = true;
1512 LIST_FOR_EACH (rstp, node, all_rstps) {
1513 rstp->changes = true;
1517 unixctl_command_reply(conn, "OK");
1520 ovs_mutex_unlock(&rstp_mutex);