[ovs-dev] [PATCH] ovs-controller: Avoid dereferencing NULL pointer when the switch acts as a hub

ZhengLingyun konghuarukhr at 163.com
Tue Oct 8 15:52:40 UTC 2013


Starting ovs-controller with '-H' option will lead to a segment fault problem.
Add a check, and adjust the indentation of the following code.

Signed-off-by: ZhengLingyun <konghuarukhr at 163.com>
---
 lib/learning-switch.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/learning-switch.c b/lib/learning-switch.c
index 76ec3e1..b133637 100644
--- a/lib/learning-switch.c
+++ b/lib/learning-switch.c
@@ -477,19 +477,23 @@ lswitch_choose_destination(struct lswitch *sw, const struct flow *flow)
     ofp_port_t out_port;
 
     /* Learn the source MAC. */
-    ovs_rwlock_wrlock(&sw->ml->rwlock);
-    if (mac_learning_may_learn(sw->ml, flow->dl_src, 0)) {
-        struct mac_entry *mac = mac_learning_insert(sw->ml, flow->dl_src, 0);
-        if (mac->port.ofp_port != flow->in_port.ofp_port) {
-            VLOG_DBG_RL(&rl, "%016llx: learned that "ETH_ADDR_FMT" is on "
-                        "port %"PRIu16, sw->datapath_id,
-                        ETH_ADDR_ARGS(flow->dl_src), flow->in_port.ofp_port);
-
-            mac->port.ofp_port = flow->in_port.ofp_port;
-            mac_learning_changed(sw->ml);
+    if (sw->ml) {
+        ovs_rwlock_wrlock(&sw->ml->rwlock);
+        if (mac_learning_may_learn(sw->ml, flow->dl_src, 0)) {
+            struct mac_entry *mac = mac_learning_insert(sw->ml, flow->dl_src,
+                                                        0);
+            if (mac->port.ofp_port != flow->in_port.ofp_port) {
+                VLOG_DBG_RL(&rl, "%016llx: learned that "ETH_ADDR_FMT" is on "
+                            "port %"PRIu16, sw->datapath_id,
+                            ETH_ADDR_ARGS(flow->dl_src),
+                            flow->in_port.ofp_port);
+
+                mac->port.ofp_port = flow->in_port.ofp_port;
+                mac_learning_changed(sw->ml);
+            }
         }
+        ovs_rwlock_unlock(&sw->ml->rwlock);
     }
-    ovs_rwlock_unlock(&sw->ml->rwlock);
 
     /* Drop frames for reserved multicast addresses. */
     if (eth_addr_is_reserved(flow->dl_dst)) {
--
1.8.1.4

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20131008/7e4d545d/attachment-0003.html>


More information about the dev mailing list