Previously, netdev_ports_insert() would allocate and insert an ifindex->odp_port mapping, but netdev_ports_remove() would never remove the mapping or free the mapping structure. This patch fixes these up.
Fixes: 32b77c316d9982("dpif: Save added ports in a port map.") Reported-by: Andy Zhou <az...@ovn.org> Signed-off-by: Joe Stringer <j...@ovn.org> Acked-by: Andy Zhou <az...@ovn.org> --- v2: Added more safety checks for ifindex, NULL pointers. Added warning message if the ifindex can't be obtained. --- lib/netdev.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/netdev.c b/lib/netdev.c index cb4d9f007b85..3cf9117b3683 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -2266,6 +2266,26 @@ netdev_ports_remove(odp_port_t port_no, const struct dpif_class *dpif_class) data = netdev_ports_lookup(port_no, dpif_class); if (data) { + int ifindex = netdev_get_ifindex(data->netdev); + + if (ifindex > 0) { + struct ifindex_to_port_data *ifidx = NULL; + + HMAP_FOR_EACH_WITH_HASH (ifidx, node, ifindex, &ifindex_to_port) { + if (ifidx && ifidx->port == port_no) { + hmap_remove(&ifindex_to_port, &ifidx->node); + break; + } + } + free(ifidx); + } else { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); + + VLOG_WARN_RL(&rl, "netdev ports map has dpif port %"PRIu32 + " but netdev has no ifindex: %s", port_no, + ovs_strerror(ifindex)); + } + dpif_port_destroy(&data->dpif_port); netdev_close(data->netdev); /* unref and possibly close */ hmap_remove(&port_to_netdev, &data->node); -- 2.13.3 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev