From b308140aa09d330a56c6cd971327a2d283db8a77 Mon Sep 17 00:00:00 2001
From: Justin Pettit <jpettit@nicira.com>
Date: Tue, 15 Nov 2011 01:33:08 -0800
Subject: [PATCH] ofproto: Disable STP when unregistering a port.

If a port is removed when spanning tree was configured on it, then the
system may crash, since the STP library will try to send packets out a
now non-existent port.  This commit disables STP on ports when they are
destroyed.
---
 ofproto/ofproto-dpif.c | 2 +-
 ofproto/ofproto.c      | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 4cc720667..e89ae893f 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1035,7 +1035,7 @@ update_stp_port_state(struct ofport_dpif *ofport)
         ofport->stp_state = state;
         ofport->stp_state_entered = time_msec();
 
-        if (fwd_change) {
+        if (fwd_change && ofport->bundle) {
             bundle_update(ofport->bundle);
         }
 
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index b7b31b022..60cf5245f 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1367,6 +1367,9 @@ ofproto_port_unregister(struct ofproto *ofproto, uint16_t ofp_port)
 {
     struct ofport *port = ofproto_get_port(ofproto, ofp_port);
     if (port) {
+        if (port->ofproto->ofproto_class->set_stp_port) {
+            port->ofproto->ofproto_class->set_stp_port(port, NULL);
+        }
         if (port->ofproto->ofproto_class->set_cfm) {
             port->ofproto->ofproto_class->set_cfm(port, NULL);
         }
-- 
2.47.0