From cbd577d661d99d37785d847ba8f15e5f4b58db87 Mon Sep 17 00:00:00 2001 From: ZhengLingyun Date: Tue, 8 Oct 2013 23:52:40 +0800 Subject: [PATCH] ovs-controller: Avoid dereferencing NULL pointer when the switch acts as a hub 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 Signed-off-by: Ben Pfaff --- 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 76ec3e13e..b133637d5 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)) { -- 2.47.0