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;
284 ovs_refcount_init(&rstp->ref_cnt);
286 list_push_back(all_rstps, &rstp->node);
287 ovs_mutex_unlock(&rstp_mutex);
289 VLOG_DBG("RSTP instance creation done");
293 /* Called by rstp_set_bridge_address() and rstp_set_bridge_priority(),
294 * it updates the bridge priority vector according to the values passed by
298 set_bridge_priority__(struct rstp *rstp)
299 OVS_REQUIRES(rstp_mutex)
303 rstp->bridge_priority.root_bridge_id = rstp->bridge_identifier;
304 rstp->bridge_priority.designated_bridge_id = rstp->bridge_identifier;
305 VLOG_DBG("%s: new bridge identifier: "RSTP_ID_FMT"", rstp->name,
306 RSTP_ID_ARGS(rstp->bridge_identifier));
308 /* [17.13] When the bridge address changes, recalculates all priority
311 HMAP_FOR_EACH (p, node, &rstp->ports) {
315 rstp->changes = true;
316 updt_roles_tree__(rstp);
319 /* Sets the bridge address. */
321 rstp_set_bridge_address__(struct rstp *rstp, rstp_identifier bridge_address)
322 OVS_REQUIRES(rstp_mutex)
324 VLOG_DBG("%s: set bridge address to: "RSTP_ID_FMT"", rstp->name,
325 RSTP_ID_ARGS(bridge_address));
326 if (rstp->address != bridge_address) {
327 rstp->address = bridge_address;
328 rstp->bridge_identifier &= 0xffff000000000000ULL;
329 rstp->bridge_identifier |= bridge_address;
330 set_bridge_priority__(rstp);
334 /* Sets the bridge address. */
336 rstp_set_bridge_address(struct rstp *rstp, rstp_identifier bridge_address)
337 OVS_EXCLUDED(rstp_mutex)
339 ovs_mutex_lock(&rstp_mutex);
340 rstp_set_bridge_address__(rstp, bridge_address);
341 ovs_mutex_unlock(&rstp_mutex);
345 rstp_get_name(const struct rstp *rstp)
346 OVS_EXCLUDED(rstp_mutex)
350 ovs_mutex_lock(&rstp_mutex);
352 ovs_mutex_unlock(&rstp_mutex);
357 rstp_get_bridge_id(const struct rstp *rstp)
358 OVS_EXCLUDED(rstp_mutex)
360 rstp_identifier bridge_id;
362 ovs_mutex_lock(&rstp_mutex);
363 bridge_id = rstp->bridge_identifier;
364 ovs_mutex_unlock(&rstp_mutex);
369 /* Sets the bridge priority. */
371 rstp_set_bridge_priority__(struct rstp *rstp, int new_priority)
372 OVS_REQUIRES(rstp_mutex)
374 new_priority = ROUND_DOWN(new_priority, RSTP_PRIORITY_STEP);
376 if (rstp->priority != new_priority
377 && new_priority >= RSTP_MIN_PRIORITY
378 && new_priority <= RSTP_MAX_PRIORITY) {
379 VLOG_DBG("%s: set bridge priority to %d", rstp->name, new_priority);
381 rstp->priority = new_priority;
382 rstp->bridge_identifier &= 0x0000ffffffffffffULL;
383 rstp->bridge_identifier |= (uint64_t)new_priority << 48;
384 set_bridge_priority__(rstp);
389 rstp_set_bridge_priority(struct rstp *rstp, int new_priority)
390 OVS_EXCLUDED(rstp_mutex)
392 ovs_mutex_lock(&rstp_mutex);
393 rstp_set_bridge_priority__(rstp, new_priority);
394 ovs_mutex_unlock(&rstp_mutex);
397 /* Sets the bridge ageing time. */
399 rstp_set_bridge_ageing_time__(struct rstp *rstp, int new_ageing_time)
400 OVS_REQUIRES(rstp_mutex)
402 if (new_ageing_time >= RSTP_MIN_AGEING_TIME
403 && new_ageing_time <= RSTP_MAX_AGEING_TIME) {
404 VLOG_DBG("%s: set ageing time to %d", rstp->name, new_ageing_time);
406 rstp->ageing_time = new_ageing_time;
411 rstp_set_bridge_ageing_time(struct rstp *rstp, int new_ageing_time)
412 OVS_EXCLUDED(rstp_mutex)
414 ovs_mutex_lock(&rstp_mutex);
415 rstp_set_bridge_ageing_time__(rstp, new_ageing_time);
416 ovs_mutex_unlock(&rstp_mutex);
419 /* Reinitializes RSTP when switching from RSTP mode to STP mode
423 reinitialize_rstp__(struct rstp *rstp)
424 OVS_REQUIRES(rstp_mutex)
427 static struct hmap ports;
430 /* Copy rstp in temp */
434 /* stop and clear rstp */
435 memset(rstp, 0, sizeof(struct rstp));
437 /* Initialize rstp. */
438 rstp->name = temp.name;
440 /* Initialize the ports hmap before calling any setters,
441 * so that the state machines will see an empty ports list. */
442 hmap_init(&rstp->ports);
444 /* Set bridge address. */
445 rstp_set_bridge_address__(rstp, temp.address);
446 /* Set default parameters values. */
447 rstp_set_bridge_priority__(rstp, RSTP_DEFAULT_PRIORITY);
448 rstp_set_bridge_ageing_time__(rstp, RSTP_DEFAULT_AGEING_TIME);
449 rstp_set_bridge_forward_delay__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY);
450 rstp_set_bridge_hello_time__(rstp);
451 rstp_set_bridge_max_age__(rstp, RSTP_DEFAULT_BRIDGE_MAX_AGE);
452 rstp_set_bridge_migrate_time__(rstp);
453 rstp_set_bridge_transmit_hold_count__(rstp,
454 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT);
455 rstp_set_bridge_times__(rstp, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY,
456 RSTP_BRIDGE_HELLO_TIME,
457 RSTP_DEFAULT_BRIDGE_MAX_AGE, 0);
459 rstp->send_bpdu = temp.send_bpdu;
460 rstp->aux = temp.aux;
461 rstp->node = temp.node;
462 rstp->changes = false;
468 HMAP_FOR_EACH (p, node, &rstp->ports) {
469 reinitialize_port__(p);
472 rstp->ref_cnt = temp.ref_cnt;
475 /* Sets the force protocol version parameter. */
477 rstp_set_bridge_force_protocol_version__(struct rstp *rstp,
478 enum rstp_force_protocol_version new_force_protocol_version)
479 OVS_REQUIRES(rstp_mutex)
481 if (new_force_protocol_version != rstp->force_protocol_version &&
482 (new_force_protocol_version == FPV_STP_COMPATIBILITY ||
483 new_force_protocol_version == FPV_DEFAULT)) {
484 VLOG_DBG("%s: set bridge Force Protocol Version to %d", rstp->name,
485 new_force_protocol_version);
487 /* [17.13] The Spanning Tree Protocol Entity shall be reinitialized,
488 * as specified by the assertion of BEGIN (17.18.1) in the state
489 * machine specification.
491 reinitialize_rstp__(rstp);
492 rstp->force_protocol_version = new_force_protocol_version;
493 if (rstp->force_protocol_version < 2) {
494 rstp->stp_version = true;
495 rstp->rstp_version = false;
497 rstp->stp_version = false;
498 rstp->rstp_version = true;
500 rstp->changes = true;
506 rstp_set_bridge_force_protocol_version(struct rstp *rstp,
507 enum rstp_force_protocol_version new_force_protocol_version)
508 OVS_EXCLUDED(rstp_mutex)
510 ovs_mutex_lock(&rstp_mutex);
511 rstp_set_bridge_force_protocol_version__(rstp, new_force_protocol_version);
512 ovs_mutex_unlock(&rstp_mutex);
515 /* Sets the bridge Hello Time parameter. */
517 rstp_set_bridge_hello_time__(struct rstp *rstp)
518 OVS_REQUIRES(rstp_mutex)
520 VLOG_DBG("%s: set RSTP Hello Time to %d", rstp->name,
521 RSTP_BRIDGE_HELLO_TIME);
522 /* 2 is the only acceptable value. */
523 rstp->bridge_hello_time = RSTP_BRIDGE_HELLO_TIME;
526 /* Sets the bridge max age parameter. */
528 rstp_set_bridge_max_age__(struct rstp *rstp, int new_max_age)
529 OVS_REQUIRES(rstp_mutex)
531 if (rstp->bridge_max_age != new_max_age
532 && new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
533 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
535 if ((2 * (rstp->bridge_forward_delay - 1) >= new_max_age)
536 && (new_max_age >= 2 * rstp->bridge_hello_time)) {
537 VLOG_DBG("%s: set RSTP bridge Max Age to %d", rstp->name,
540 rstp->bridge_max_age = new_max_age;
541 rstp->bridge_times.max_age = new_max_age;
542 rstp->changes = true;
543 updt_roles_tree__(rstp);
549 rstp_set_bridge_max_age(struct rstp *rstp, int new_max_age)
550 OVS_EXCLUDED(rstp_mutex)
552 ovs_mutex_lock(&rstp_mutex);
553 rstp_set_bridge_max_age__(rstp, new_max_age);
554 ovs_mutex_unlock(&rstp_mutex);
557 /* Sets the bridge forward delay parameter. */
559 rstp_set_bridge_forward_delay__(struct rstp *rstp, int new_forward_delay)
560 OVS_REQUIRES(rstp_mutex)
562 if (rstp->bridge_forward_delay != new_forward_delay
563 && new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
564 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
565 if (2 * (new_forward_delay - 1) >= rstp->bridge_max_age) {
566 VLOG_DBG("%s: set RSTP Forward Delay to %d", rstp->name,
568 rstp->bridge_forward_delay = new_forward_delay;
569 rstp->bridge_times.forward_delay = new_forward_delay;
570 rstp->changes = true;
571 updt_roles_tree__(rstp);
577 rstp_set_bridge_forward_delay(struct rstp *rstp, int new_forward_delay)
578 OVS_EXCLUDED(rstp_mutex)
580 ovs_mutex_lock(&rstp_mutex);
581 rstp_set_bridge_forward_delay__(rstp, new_forward_delay);
582 ovs_mutex_unlock(&rstp_mutex);
585 /* Sets the bridge transmit hold count parameter. */
587 rstp_set_bridge_transmit_hold_count__(struct rstp *rstp,
588 int new_transmit_hold_count)
589 OVS_REQUIRES(rstp_mutex)
591 if (rstp->transmit_hold_count != new_transmit_hold_count
592 && new_transmit_hold_count >= RSTP_MIN_TRANSMIT_HOLD_COUNT
593 && new_transmit_hold_count <= RSTP_MAX_TRANSMIT_HOLD_COUNT) {
596 VLOG_DBG("%s: set RSTP Transmit Hold Count to %d", rstp->name,
597 new_transmit_hold_count);
598 /* Resetting txCount on all ports [17.13]. */
600 rstp->transmit_hold_count = new_transmit_hold_count;
601 HMAP_FOR_EACH (p, node, &rstp->ports) {
608 rstp_set_bridge_transmit_hold_count(struct rstp *rstp,
609 int new_transmit_hold_count)
610 OVS_EXCLUDED(rstp_mutex)
612 ovs_mutex_lock(&rstp_mutex);
613 rstp_set_bridge_transmit_hold_count__(rstp, new_transmit_hold_count);
614 ovs_mutex_unlock(&rstp_mutex);
617 /* Sets the bridge migrate time parameter. */
619 rstp_set_bridge_migrate_time__(struct rstp *rstp)
620 OVS_REQUIRES(rstp_mutex)
622 VLOG_DBG("%s: set RSTP Migrate Time to %d", rstp->name,
624 /* 3 is the only acceptable value */
625 rstp->migrate_time = RSTP_MIGRATE_TIME;
628 /* Sets the bridge times. */
630 rstp_set_bridge_times__(struct rstp *rstp, int new_forward_delay,
631 int new_hello_time, int new_max_age,
633 OVS_REQUIRES(rstp_mutex)
635 VLOG_DBG("%s: set RSTP times to (%d, %d, %d, %d)", rstp->name,
636 new_forward_delay, new_hello_time, new_max_age, new_message_age);
637 if (new_forward_delay >= RSTP_MIN_BRIDGE_FORWARD_DELAY
638 && new_forward_delay <= RSTP_MAX_BRIDGE_FORWARD_DELAY) {
639 rstp->bridge_times.forward_delay = new_forward_delay;
641 if (new_hello_time == RSTP_BRIDGE_HELLO_TIME) {
642 rstp->bridge_times.hello_time = new_hello_time;
644 if (new_max_age >= RSTP_MIN_BRIDGE_MAX_AGE
645 && new_max_age <= RSTP_MAX_BRIDGE_MAX_AGE) {
646 rstp->bridge_times.max_age = new_max_age;
648 rstp->bridge_times.message_age = new_message_age;
651 /* Sets the port id, it is called by rstp_port_set_port_number__() or
652 * rstp_port_set_priority__().
655 set_port_id__(struct rstp_port *p)
656 OVS_REQUIRES(rstp_mutex)
661 /* [9.2.7] Port identifier. */
662 p->port_id = p->port_number | (p->priority << 8);
663 VLOG_DBG("%s: new RSTP port id "RSTP_PORT_ID_FMT"", rstp->name,
667 /* Sets the port priority. */
669 rstp_port_set_priority__(struct rstp_port *port, int priority)
670 OVS_REQUIRES(rstp_mutex)
672 if (port->priority != priority
673 && priority >= RSTP_MIN_PORT_PRIORITY
674 && priority <= RSTP_MAX_PORT_PRIORITY) {
675 VLOG_DBG("%s, port %u: set RSTP port priority to %d", port->rstp->name,
676 port->port_number, priority);
678 priority -= priority % RSTP_STEP_PORT_PRIORITY;
679 port->priority = priority;
681 port->selected = false;
682 port->reselect = true;
686 /* Checks if a port number is available. */
688 is_port_number_available__(struct rstp *rstp, int n, struct rstp_port *port)
689 OVS_REQUIRES(rstp_mutex)
691 if (n >= 1 && n <= RSTP_MAX_PORTS) {
692 struct rstp_port *p = rstp_get_port__(rstp, n);
694 return p == NULL || p == port;
700 rstp_first_free_number__(struct rstp *rstp, struct rstp_port *rstp_port)
701 OVS_REQUIRES(rstp_mutex)
705 while (free_number <= RSTP_MAX_PORTS) {
706 if (is_port_number_available__(rstp, free_number, rstp_port)) {
711 VLOG_DBG("%s, No free port number available.", rstp->name);
715 /* Sets the port number. */
717 rstp_port_set_port_number__(struct rstp_port *port, uint16_t port_number)
718 OVS_REQUIRES(rstp_mutex)
720 int old_port_number = port->port_number;
722 /* If new_port_number is available, use it, otherwise use the first free
723 * available port number. */
724 if (port->port_number != port_number || port_number == 0) {
726 is_port_number_available__(port->rstp, port_number, port)
728 : rstp_first_free_number__(port->rstp, port);
730 if (port->port_number != old_port_number) {
732 /* [17.13] is not clear. I suppose that a port number change
733 * should trigger reselection like a port priority change. */
734 port->selected = false;
735 port->reselect = true;
737 /* Adjust the ports hmap. */
738 if (!hmap_node_is_null(&port->node)) {
739 hmap_remove(&port->rstp->ports, &port->node);
741 hmap_insert(&port->rstp->ports, &port->node,
742 hash_int(port->port_number, 0));
744 VLOG_DBG("%s: set new RSTP port number %d", port->rstp->name,
750 /* Converts the link speed to a port path cost [Table 17-3]. */
752 rstp_convert_speed_to_cost(unsigned int speed)
756 value = speed >= 10000000 ? 2 /* 10 Tb/s. */
757 : speed >= 1000000 ? 20 /* 1 Tb/s. */
758 : speed >= 100000 ? 200 /* 100 Gb/s. */
759 : speed >= 10000 ? 2000 /* 10 Gb/s. */
760 : speed >= 1000 ? 20000 /* 1 Gb/s. */
761 : speed >= 100 ? 200000 /* 100 Mb/s. */
762 : speed >= 10 ? 2000000 /* 10 Mb/s. */
763 : speed >= 1 ? 20000000 /* 1 Mb/s. */
764 : RSTP_DEFAULT_PORT_PATH_COST; /* 100 Mb/s. */
769 /* Sets the port path cost. */
771 rstp_port_set_path_cost__(struct rstp_port *port, uint32_t path_cost)
772 OVS_REQUIRES(rstp_mutex)
774 if (port->port_path_cost != path_cost
775 && path_cost >= RSTP_MIN_PORT_PATH_COST
776 && path_cost <= RSTP_MAX_PORT_PATH_COST) {
777 VLOG_DBG("%s, port %u, set RSTP port path cost to %d",
778 port->rstp->name, port->port_number, path_cost);
780 port->port_path_cost = path_cost;
781 port->selected = false;
782 port->reselect = true;
786 /* Gets the root path cost. */
788 rstp_get_root_path_cost(const struct rstp *rstp)
789 OVS_EXCLUDED(rstp_mutex)
793 ovs_mutex_lock(&rstp_mutex);
794 cost = rstp->root_priority.root_path_cost;
795 ovs_mutex_unlock(&rstp_mutex);
799 /* Finds a port which needs to flush its own MAC learning table. A NULL
800 * pointer is returned if no port needs to flush its MAC learning table.
801 * '*port' needs to be NULL in the first call to start the iteration. If
802 * '*port' is passed as non-NULL, it must be the value set by the last
803 * invocation of this function.
805 * This function may only be called by the thread that creates and deletes
806 * ports. Otherwise this function is not thread safe, as the returned
807 * '*port' could become stale before it is used in the next invocation. */
809 rstp_check_and_reset_fdb_flush(struct rstp *rstp, struct rstp_port **port)
810 OVS_EXCLUDED(rstp_mutex)
814 ovs_mutex_lock(&rstp_mutex);
818 HMAP_FOR_EACH (p, node, &rstp->ports) {
825 } else { /* continue */
826 struct rstp_port *p = *port;
828 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
836 /* No port needs flushing. */
839 /* fdb_flush should be reset by the filtering database
840 * once the entries are removed if rstp_version is TRUE, and
841 * immediately if stp_version is TRUE.*/
843 (*port)->fdb_flush = false;
845 ovs_mutex_unlock(&rstp_mutex);
850 /* Finds a port whose state has changed, and returns the aux pointer set for
851 * the port. A NULL pointer is returned when no changed port is found. On
852 * return '*portp' contains the pointer to the rstp port that changed, or NULL
853 * if no changed port can be found.
855 * If '*portp' is passed as non-NULL, it must be the value set by the last
856 * invocation of this function.
858 * This function may only be called by the thread that creates and deletes
859 * ports. Otherwise this function is not thread safe, as the returned
860 * '*portp' could become stale before it is used in the next invocation. */
862 rstp_get_next_changed_port_aux(struct rstp *rstp, struct rstp_port **portp)
866 ovs_mutex_lock(&rstp_mutex);
867 if (*portp == NULL) {
870 HMAP_FOR_EACH (p, node, &rstp->ports) {
871 if (p->state_changed) {
872 p->state_changed = false;
878 } else { /* continue */
879 struct rstp_port *p = *portp;
881 HMAP_FOR_EACH_CONTINUE (p, node, &rstp->ports) {
882 if (p->state_changed) {
883 p->state_changed = false;
890 /* No changed port found. */
893 ovs_mutex_unlock(&rstp_mutex);
899 rstp_shift_root_learned_address(struct rstp *rstp)
903 ovs_mutex_lock(&rstp_mutex);
904 ret = rstp->root_changed;
905 ovs_mutex_unlock(&rstp_mutex);
911 rstp_get_old_root_aux(struct rstp *rstp)
915 ovs_mutex_lock(&rstp_mutex);
916 aux = rstp->old_root_aux;
917 ovs_mutex_unlock(&rstp_mutex);
923 rstp_get_new_root_aux(struct rstp *rstp)
927 ovs_mutex_lock(&rstp_mutex);
928 aux = rstp->new_root_aux;
929 ovs_mutex_unlock(&rstp_mutex);
935 rstp_reset_root_changed(struct rstp *rstp)
937 ovs_mutex_lock(&rstp_mutex);
938 rstp->root_changed = false;
939 ovs_mutex_unlock(&rstp_mutex);
942 /* Returns the port in 'rstp' with number 'port_number'.
944 * XXX: May only be called while concurrent deletion of ports is excluded. */
945 static struct rstp_port *
946 rstp_get_port__(struct rstp *rstp, uint16_t port_number)
947 OVS_REQUIRES(rstp_mutex)
949 struct rstp_port *port;
951 ovs_assert(rstp && port_number > 0 && port_number <= RSTP_MAX_PORTS);
953 HMAP_FOR_EACH_WITH_HASH (port, node, hash_int(port_number, 0),
955 if (port->port_number == port_number) {
963 rstp_get_port(struct rstp *rstp, uint16_t port_number)
964 OVS_EXCLUDED(rstp_mutex)
968 ovs_mutex_lock(&rstp_mutex);
969 p = rstp_get_port__(rstp, port_number);
970 ovs_mutex_unlock(&rstp_mutex);
975 rstp_get_port_aux__(struct rstp *rstp, uint16_t port_number)
976 OVS_REQUIRES(rstp_mutex)
979 p = rstp_get_port__(rstp, port_number);
986 /* Updates the port_enabled parameter. */
988 update_port_enabled__(struct rstp_port *p)
989 OVS_REQUIRES(rstp_mutex)
991 if (p->mac_operational && p->is_administrative_bridge_port
992 == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED) {
993 p->port_enabled = true;
995 p->port_enabled = false;
999 /* Sets the port MAC_Operational parameter [6.4.2]. */
1001 rstp_port_set_mac_operational(struct rstp_port *p, bool new_mac_operational)
1002 OVS_EXCLUDED(rstp_mutex)
1006 ovs_mutex_lock(&rstp_mutex);
1008 if (p->mac_operational != new_mac_operational) {
1009 p->mac_operational = new_mac_operational;
1010 update_port_enabled__(p);
1011 rstp->changes = true;
1014 ovs_mutex_unlock(&rstp_mutex);
1017 /* Sets the port Administrative Bridge Port parameter. */
1019 rstp_port_set_administrative_bridge_port__(struct rstp_port *p,
1020 uint8_t admin_port_state,
1022 OVS_REQUIRES(rstp_mutex)
1024 VLOG_DBG("%s, port %u: set RSTP port admin-port-state to %d",
1025 p->rstp->name, p->port_number, admin_port_state);
1027 if (p->is_administrative_bridge_port != admin_port_state
1028 && (admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_DISABLED
1029 || admin_port_state == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED)) {
1030 p->is_administrative_bridge_port = admin_port_state;
1031 update_port_enabled__(p);
1033 if (!initializing) {
1034 struct rstp *rstp = p->rstp;
1036 rstp->changes = true;
1042 /* Sets the port oper_point_to_point_mac parameter. */
1044 rstp_port_set_oper_point_to_point_mac__(struct rstp_port *p,
1045 uint8_t new_oper_p2p_mac)
1046 OVS_REQUIRES(rstp_mutex)
1048 if (p->oper_point_to_point_mac != new_oper_p2p_mac
1049 && (new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_DISABLED
1050 || new_oper_p2p_mac == RSTP_OPER_P2P_MAC_STATE_ENABLED)) {
1052 p->oper_point_to_point_mac = new_oper_p2p_mac;
1053 update_port_enabled__(p);
1057 /* Initializes a port with the defaults values for its parameters. */
1059 rstp_initialize_port_defaults__(struct rstp_port *p)
1060 OVS_REQUIRES(rstp_mutex)
1062 rstp_port_set_administrative_bridge_port__(p,
1063 RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED,
1065 rstp_port_set_oper_point_to_point_mac__(p,
1066 RSTP_OPER_P2P_MAC_STATE_ENABLED);
1067 rstp_port_set_path_cost__(p, RSTP_DEFAULT_PORT_PATH_COST);
1068 rstp_port_set_admin_edge__(p, false);
1069 rstp_port_set_auto_edge__(p, true);
1070 rstp_port_set_mcheck__(p, false);
1072 /* Initialize state machines. */
1073 p->port_receive_sm_state = PORT_RECEIVE_SM_INIT;
1074 p->port_protocol_migration_sm_state = PORT_PROTOCOL_MIGRATION_SM_INIT;
1075 p->bridge_detection_sm_state = BRIDGE_DETECTION_SM_INIT;
1076 p->port_transmit_sm_state = PORT_TRANSMIT_SM_INIT;
1077 p->port_information_sm_state = PORT_INFORMATION_SM_INIT;
1078 p->port_role_transition_sm_state = PORT_ROLE_TRANSITION_SM_INIT;
1079 p->port_state_transition_sm_state = PORT_STATE_TRANSITION_SM_INIT;
1080 p->topology_change_sm_state = TOPOLOGY_CHANGE_SM_INIT;
1086 reinitialize_port__(struct rstp_port *p)
1087 OVS_REQUIRES(rstp_mutex)
1089 struct rstp_port temp_port;
1094 memset(p, 0, sizeof(struct rstp_port));
1096 p->ref_cnt = temp_port.ref_cnt;
1098 p->node = temp_port.node;
1099 p->aux = temp_port.aux;
1100 p->port_number = temp_port.port_number;
1101 p->port_priority = temp_port.port_priority;
1102 p->port_id = temp_port.port_id;
1103 p->rstp_state = RSTP_DISCARDING;
1105 rstp_initialize_port_defaults__(p);
1107 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" reinitialized.", rstp->name,
1112 reinitialize_port(struct rstp_port *p)
1113 OVS_EXCLUDED(rstp_mutex)
1115 ovs_mutex_lock(&rstp_mutex);
1116 reinitialize_port__(p);
1117 ovs_mutex_unlock(&rstp_mutex);
1120 /* Sets the port state. */
1122 rstp_port_set_state__(struct rstp_port *p, enum rstp_state state)
1123 OVS_REQUIRES(rstp_mutex)
1128 VLOG_DBG("%s, port %u: set RSTP port state %s -> %s", rstp->name,
1130 rstp_state_name(p->rstp_state), rstp_state_name(state));
1132 if (state != p->rstp_state && !p->state_changed) {
1133 p->state_changed = true;
1134 seq_change(connectivity_seq_get());
1136 p->rstp_state = state;
1140 rstp_port_set_state(struct rstp_port *p, enum rstp_state state)
1141 OVS_EXCLUDED(rstp_mutex)
1143 ovs_mutex_lock(&rstp_mutex);
1144 rstp_port_set_state__(p, state);
1145 ovs_mutex_unlock(&rstp_mutex);
1148 /* Adds a RSTP port. */
1150 rstp_add_port(struct rstp *rstp)
1151 OVS_EXCLUDED(rstp_mutex)
1153 struct rstp_port *p = xzalloc(sizeof *p);
1155 ovs_refcount_init(&p->ref_cnt);
1156 hmap_node_nullify(&p->node);
1158 ovs_mutex_lock(&rstp_mutex);
1160 rstp_port_set_priority__(p, RSTP_DEFAULT_PORT_PRIORITY);
1161 rstp_port_set_port_number__(p, 0);
1163 rstp_initialize_port_defaults__(p);
1164 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT" initialized.", rstp->name,
1167 rstp_port_set_state__(p, RSTP_DISCARDING);
1168 rstp->changes = true;
1170 VLOG_DBG("%s: added port "RSTP_PORT_ID_FMT"", rstp->name, p->port_id);
1171 ovs_mutex_unlock(&rstp_mutex);
1175 /* Caller has to hold a reference to prevent 'rstp_port' from being deleted
1176 * while taking a new reference. */
1178 rstp_port_ref(const struct rstp_port *rp_)
1179 OVS_EXCLUDED(rstp_mutex)
1181 struct rstp_port *rp = CONST_CAST(struct rstp_port *, rp_);
1184 ovs_refcount_ref(&rp->ref_cnt);
1189 /* Frees RSTP struct. This can be caller by any thread. */
1191 rstp_port_unref(struct rstp_port *rp)
1192 OVS_EXCLUDED(rstp_mutex)
1194 if (rp && ovs_refcount_unref_relaxed(&rp->ref_cnt) == 1) {
1197 ovs_mutex_lock(&rstp_mutex);
1199 rstp_port_set_state__(rp, RSTP_DISABLED);
1200 hmap_remove(&rstp->ports, &rp->node);
1201 VLOG_DBG("%s: removed port "RSTP_PORT_ID_FMT"", rstp->name,
1203 ovs_mutex_unlock(&rstp_mutex);
1208 /* Sets the port Admin Edge parameter. */
1210 rstp_port_set_admin_edge__(struct rstp_port *port, bool admin_edge)
1211 OVS_REQUIRES(rstp_mutex)
1213 if (port->admin_edge != admin_edge) {
1214 VLOG_DBG("%s, port %u: set RSTP Admin Edge to %d", port->rstp->name,
1215 port->port_number, admin_edge);
1217 port->admin_edge = admin_edge;
1221 /* Sets the port Auto Edge parameter. */
1223 rstp_port_set_auto_edge__(struct rstp_port *port, bool auto_edge)
1224 OVS_REQUIRES(rstp_mutex)
1226 if (port->auto_edge != auto_edge) {
1227 VLOG_DBG("%s, port %u: set RSTP Auto Edge to %d", port->rstp->name,
1228 port->port_number, auto_edge);
1230 port->auto_edge = auto_edge;
1234 /* Sets the port admin_point_to_point_mac parameter. */
1235 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port *port,
1236 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state)
1237 OVS_REQUIRES(rstp_mutex)
1239 VLOG_DBG("%s, port %u: set RSTP port admin-point-to-point-mac to %d",
1240 port->rstp->name, port->port_number, admin_p2p_mac_state);
1241 if (port->admin_point_to_point_mac != admin_p2p_mac_state) {
1242 if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_TRUE) {
1243 port->admin_point_to_point_mac = admin_p2p_mac_state;
1244 rstp_port_set_oper_point_to_point_mac__(
1245 port, RSTP_OPER_P2P_MAC_STATE_ENABLED);
1246 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_FORCE_FALSE) {
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_DISABLED);
1250 } else if (admin_p2p_mac_state == RSTP_ADMIN_P2P_MAC_AUTO) {
1251 /* If adminPointToPointMAC is set to Auto, then the value of
1252 * operPointToPointMAC is determined in accordance with the
1253 * specific procedures defined for the MAC entity concerned, as
1254 * defined in 6.5. If these procedures determine that the MAC
1255 * entity is connected to a point-to-point LAN, then
1256 * operPointToPointMAC is set TRUE; otherwise it is set FALSE.
1257 * In the absence of a specific definition of how to determine
1258 * whether the MAC is connected to a point-to-point LAN or not,
1259 * the value of operPointToPointMAC shall be FALSE. */
1260 port->admin_point_to_point_mac = admin_p2p_mac_state;
1261 rstp_port_set_oper_point_to_point_mac__(
1262 port, RSTP_OPER_P2P_MAC_STATE_DISABLED);
1267 /* Sets the port mcheck parameter.
1268 * [17.19.13] May be set by management to force the Port Protocol Migration
1269 * state machine to transmit RST BPDUs for a MigrateTime (17.13.9) period, to
1270 * test whether all STP Bridges (17.4) on the attached LAN have been removed
1271 * and the Port can continue to transmit RSTP BPDUs. Setting mcheck has no
1272 * effect if stpVersion (17.20.12) is TRUE, i.e., the Bridge is operating in
1273 * STP Compatibility mode.
1276 rstp_port_set_mcheck__(struct rstp_port *port, bool mcheck)
1277 OVS_REQUIRES(rstp_mutex)
1279 if (mcheck == true && port->rstp->force_protocol_version >= 2) {
1280 port->mcheck = true;
1282 VLOG_DBG("%s, port %u: set RSTP mcheck to %d", port->rstp->name,
1283 port->port_number, mcheck);
1287 /* Returns the designated bridge id. */
1289 rstp_get_designated_id(const struct rstp *rstp)
1290 OVS_EXCLUDED(rstp_mutex)
1292 rstp_identifier designated_id;
1294 ovs_mutex_lock(&rstp_mutex);
1295 designated_id = rstp->root_priority.designated_bridge_id;
1296 ovs_mutex_unlock(&rstp_mutex);
1298 return designated_id;
1301 /* Returns the root bridge id. */
1303 rstp_get_root_id(const struct rstp *rstp)
1304 OVS_EXCLUDED(rstp_mutex)
1306 rstp_identifier root_id;
1308 ovs_mutex_lock(&rstp_mutex);
1309 root_id = rstp->root_priority.root_bridge_id;
1310 ovs_mutex_unlock(&rstp_mutex);
1315 /* Returns the designated port id. */
1317 rstp_get_designated_port_id(const struct rstp *rstp)
1318 OVS_EXCLUDED(rstp_mutex)
1320 uint16_t designated_port_id;
1322 ovs_mutex_lock(&rstp_mutex);
1323 designated_port_id = rstp->root_priority.designated_port_id;
1324 ovs_mutex_unlock(&rstp_mutex);
1326 return designated_port_id;
1329 /* Return the bridge port id. */
1331 rstp_get_bridge_port_id(const struct rstp *rstp)
1332 OVS_EXCLUDED(rstp_mutex)
1334 uint16_t bridge_port_id;
1336 ovs_mutex_lock(&rstp_mutex);
1337 bridge_port_id = rstp->root_priority.bridge_port_id;
1338 ovs_mutex_unlock(&rstp_mutex);
1340 return bridge_port_id;
1343 /* Returns true if the bridge believes to the be root of the spanning tree,
1347 rstp_is_root_bridge(const struct rstp *rstp)
1348 OVS_EXCLUDED(rstp_mutex)
1352 ovs_mutex_lock(&rstp_mutex);
1353 is_root = rstp->bridge_identifier ==
1354 rstp->root_priority.designated_bridge_id;
1355 ovs_mutex_unlock(&rstp_mutex);
1360 /* Returns the bridge ID of the bridge currently believed to be the root. */
1362 rstp_get_designated_root(const struct rstp *rstp)
1363 OVS_EXCLUDED(rstp_mutex)
1365 rstp_identifier designated_root;
1367 ovs_mutex_lock(&rstp_mutex);
1368 designated_root = rstp->root_priority.designated_bridge_id;
1369 ovs_mutex_unlock(&rstp_mutex);
1371 return designated_root;
1374 /* Returns the port connecting 'rstp' to the root bridge, or a null pointer if
1375 * there is no such port.
1378 rstp_get_root_port(struct rstp *rstp)
1379 OVS_EXCLUDED(rstp_mutex)
1381 struct rstp_port *p;
1383 ovs_mutex_lock(&rstp_mutex);
1384 HMAP_FOR_EACH (p, node, &rstp->ports) {
1385 if (p->port_id == rstp->root_port_id) {
1386 ovs_mutex_unlock(&rstp_mutex);
1390 ovs_mutex_unlock(&rstp_mutex);
1394 /* Returns the state of port 'p'. */
1396 rstp_port_get_state(const struct rstp_port *p)
1397 OVS_EXCLUDED(rstp_mutex)
1399 enum rstp_state state;
1401 ovs_mutex_lock(&rstp_mutex);
1402 state = p->rstp_state;
1403 ovs_mutex_unlock(&rstp_mutex);
1408 /* Retrieves port status. */
1410 rstp_port_get_status(const struct rstp_port *p, uint16_t *id,
1411 enum rstp_state *state, enum rstp_port_role *role,
1412 rstp_identifier *designated_bridge_id,
1413 uint16_t *designated_port_id,
1414 uint32_t *designated_path_cost, int *tx_count,
1415 int *rx_count, int *error_count, int *uptime)
1416 OVS_EXCLUDED(rstp_mutex)
1418 ovs_mutex_lock(&rstp_mutex);
1420 *state = p->rstp_state;
1423 *designated_bridge_id = p->port_priority.designated_bridge_id;
1424 *designated_port_id = p->port_priority.designated_port_id;
1425 *designated_path_cost = p->port_priority.root_path_cost;
1427 *tx_count = p->tx_count;
1428 *rx_count = p->rx_rstp_bpdu_cnt;
1429 *error_count = p->error_count;
1430 *uptime = p->uptime;
1431 ovs_mutex_unlock(&rstp_mutex);
1435 rstp_port_set(struct rstp_port *port, uint16_t port_num, int priority,
1436 uint32_t path_cost, bool is_admin_edge, bool is_auto_edge,
1437 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state,
1438 bool admin_port_state, bool do_mcheck, void *aux)
1439 OVS_EXCLUDED(rstp_mutex)
1441 ovs_mutex_lock(&rstp_mutex);
1443 rstp_port_set_priority__(port, priority);
1444 rstp_port_set_port_number__(port, port_num);
1445 rstp_port_set_path_cost__(port, path_cost);
1446 rstp_port_set_admin_edge__(port, is_admin_edge);
1447 rstp_port_set_auto_edge__(port, is_auto_edge);
1448 rstp_port_set_admin_point_to_point_mac__(port, admin_p2p_mac_state);
1449 rstp_port_set_administrative_bridge_port__(port, admin_port_state, false);
1450 rstp_port_set_mcheck__(port, do_mcheck);
1451 ovs_mutex_unlock(&rstp_mutex);
1454 /* Individual setters only used by test-rstp.c. */
1456 rstp_port_set_priority(struct rstp_port *port, int priority)
1457 OVS_EXCLUDED(rstp_mutex)
1459 ovs_mutex_lock(&rstp_mutex);
1460 rstp_port_set_priority__(port, priority);
1461 ovs_mutex_unlock(&rstp_mutex);
1465 rstp_port_set_path_cost(struct rstp_port *port, uint32_t path_cost)
1466 OVS_EXCLUDED(rstp_mutex)
1468 ovs_mutex_lock(&rstp_mutex);
1469 rstp_port_set_path_cost__(port, path_cost);
1470 ovs_mutex_unlock(&rstp_mutex);
1474 rstp_port_set_aux(struct rstp_port *port, void *aux)
1475 OVS_EXCLUDED(rstp_mutex)
1477 ovs_mutex_lock(&rstp_mutex);
1479 ovs_mutex_unlock(&rstp_mutex);
1483 static struct rstp *
1484 rstp_find(const char *name)
1485 OVS_REQUIRES(rstp_mutex)
1489 LIST_FOR_EACH (rstp, node, all_rstps) {
1490 if (!strcmp(rstp->name, name)) {
1498 rstp_unixctl_tcn(struct unixctl_conn *conn, int argc,
1499 const char *argv[], void *aux OVS_UNUSED)
1500 OVS_EXCLUDED(rstp_mutex)
1502 ovs_mutex_lock(&rstp_mutex);
1504 struct rstp *rstp = rstp_find(argv[1]);
1506 unixctl_command_reply_error(conn, "No such RSTP object");
1509 rstp->changes = true;
1513 LIST_FOR_EACH (rstp, node, all_rstps) {
1514 rstp->changes = true;
1518 unixctl_command_reply(conn, "OK");
1521 ovs_mutex_unlock(&rstp_mutex);