From: Ding Zhi <zhi.d...@6wind.com>

Running `ovs-appctl stp/tcn ovsbr0` tries to lock `mutex` in
`stp_unixctl_tcn()`; but `mutex` is initialized only once in
`stp_create()`. As a result, the command crashes if STP has not been
enabled on the switch yet.

This commit ensures that the `stp/tcn` command is registered only after
`mutex` is initialized (and thus cannot be called at all if STP has not
been enabled).

Signed-off-by: Ding Zhi <zhi.d...@6wind.com>
Signed-off-by: Liu Xiaofeng <xiaofeng....@6wind.com>
Signed-off-by: Quentin Monnet <quentin.mon...@6wind.com>
---
 lib/stp.c         | 3 ++-
 lib/stp.h         | 1 -
 vswitchd/bridge.c | 1 -
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/stp.c b/lib/stp.c
index 0f92ed176ea4..808fff03b12e 100644
--- a/lib/stp.c
+++ b/lib/stp.c
@@ -237,7 +237,7 @@ static void stp_send_bpdu(struct stp_port *, const void *, 
size_t)
 static void stp_unixctl_tcn(struct unixctl_conn *, int argc,
                             const char *argv[], void *aux);
 
-void
+static void
 stp_init(void)
 {
     unixctl_command_register("stp/tcn", "[bridge]", 0, 1, stp_unixctl_tcn,
@@ -272,6 +272,7 @@ stp_create(const char *name, stp_identifier bridge_id,
          * intentionally as part of the unit tests.  Ideally we'd ditch
          * the call back function, but for now this is what we have. */
         ovs_mutex_init_recursive(&mutex);
+        stp_init();
         ovsthread_once_done(&once);
     }
 
diff --git a/lib/stp.h b/lib/stp.h
index 9f945ad21db5..021a9cc311f9 100644
--- a/lib/stp.h
+++ b/lib/stp.h
@@ -50,7 +50,6 @@ typedef uint64_t stp_identifier;
 
 /* Basic STP functionality. */
 #define STP_MAX_PORTS 255
-void stp_init(void);
 struct stp *stp_create(const char *name, stp_identifier bridge_id,
                        void (*send_bpdu)(struct dp_packet *bpdu, int port_no,
                                          void *aux),
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 41ec4ba9a86f..dbdeb0c371b4 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -471,7 +471,6 @@ bridge_init(const char *remote)
     cfm_init();
     bfd_init();
     ovs_numa_init();
-    stp_init();
     lldp_init();
     rstp_init();
     ifnotifier = if_notifier_create(if_change_cb, NULL);
-- 
2.1.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to