bgpd: Fix missed unlocks

When iterating over the bgp_dest table, using this pattern:

	for (dest = bgp_table_top(table); dest;
	     dest = bgp_route_next(dest)) {

If the code breaks or returns in the middle we will not have
properly unlocked the node as that bgp_table_top locks the top
dest and bgp_route_next locks the next dest and unlocks the old
dest.

From code inspection I have found a bunch of places that
we either return in the middle of or a break is issued.

Add appropriate unlocks.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2020-11-14 15:32:49 -05:00
parent 15675d025d
commit dc52beced1
4 changed files with 12 additions and 1 deletions

View File

@ -51,6 +51,7 @@ bgp_check_rmap_prefixes_in_bgp_table(struct bgp_table *table,
if (ret != RMAP_PERMITMATCH) if (ret != RMAP_PERMITMATCH)
bgp_attr_flush(&dummy_attr); bgp_attr_flush(&dummy_attr);
else { else {
bgp_dest_unlock_node(dest);
if (BGP_DEBUG(update, UPDATE_OUT)) if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug( zlog_debug(
"%s: Condition map routes present in BGP table", "%s: Condition map routes present in BGP table",

View File

@ -2930,6 +2930,8 @@ static int install_uninstall_routes_for_vrf(struct bgp *bgp_vrf, int install)
evp, evp,
vrf_id_to_name( vrf_id_to_name(
bgp_vrf->vrf_id)); bgp_vrf->vrf_id));
bgp_dest_unlock_node(rd_dest);
bgp_dest_unlock_node(dest);
return ret; return ret;
} }
} }
@ -3009,6 +3011,9 @@ static int install_uninstall_routes_for_vni(struct bgp *bgp,
? "MACIP" ? "MACIP"
: "IMET", : "IMET",
vpn->vni); vpn->vni);
bgp_dest_unlock_node(rd_dest);
bgp_dest_unlock_node(dest);
return ret; return ret;
} }
} }

View File

@ -763,6 +763,9 @@ static int bgp_evpn_type4_remote_routes_import(struct bgp *bgp,
install ? "install" install ? "install"
: "uninstall", : "uninstall",
evp, es->esi_str); evp, es->esi_str);
bgp_dest_unlock_node(rd_dest);
bgp_dest_unlock_node(dest);
return ret; return ret;
} }
} }

View File

@ -842,8 +842,10 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
break; break;
} }
} }
if (ret == RMAP_PERMITMATCH) if (ret == RMAP_PERMITMATCH) {
bgp_dest_unlock_node(dest);
break; break;
}
} }
bgp->peer_self->rmap_type = 0; bgp->peer_self->rmap_type = 0;