bgpd: factorize bgp_table_cleanup()

Factorize bgp_table_cleanup(). Cosmetic change. It will help adding
AFI / SAFI in the future.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This commit is contained in:
Louis Scalbert 2025-02-07 11:27:13 +01:00
parent 007243d94d
commit b5014d371c

View File

@ -6719,58 +6719,28 @@ static void bgp_cleanup_table(struct bgp *bgp, struct bgp_table *table,
/* Delete all kernel routes. */ /* Delete all kernel routes. */
void bgp_cleanup_routes(struct bgp *bgp) void bgp_cleanup_routes(struct bgp *bgp)
{ {
safi_t safi;
afi_t afi; afi_t afi;
struct bgp_dest *dest; struct bgp_dest *dest;
struct bgp_table *table; struct bgp_table *table;
for (afi = AFI_IP; afi < AFI_MAX; ++afi) { FOREACH_AFI_SAFI (afi, safi) {
if (afi == AFI_L2VPN) if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP && safi != SAFI_EVPN) {
bgp_cleanup_table(bgp, bgp->rib[afi][safi], afi, safi);
continue; continue;
bgp_cleanup_table(bgp, bgp->rib[afi][SAFI_UNICAST], afi, }
SAFI_UNICAST);
/* /*
* VPN and ENCAP and EVPN tables are two-level (RD is top level) * VPN and ENCAP and EVPN tables are two-level (RD is top level)
*/ */
if (afi != AFI_L2VPN) { if (safi != SAFI_MPLS_VPN && IS_BGP_INSTANCE_HIDDEN(bgp))
safi_t safi; continue;
safi = SAFI_MPLS_VPN;
if (!IS_BGP_INSTANCE_HIDDEN(bgp)) {
for (dest = bgp_table_top(bgp->rib[afi][safi]);
dest; dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(
dest);
if (table != NULL) {
bgp_cleanup_table(bgp, table,
afi, safi);
bgp_table_finish(&table);
bgp_dest_set_bgp_table_info(dest,
NULL);
dest = bgp_dest_unlock_node(
dest);
assert(dest);
}
}
}
safi = SAFI_ENCAP;
for (dest = bgp_table_top(bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(dest);
if (table != NULL) {
bgp_cleanup_table(bgp, table, afi, safi);
bgp_table_finish(&table);
bgp_dest_set_bgp_table_info(dest, NULL);
dest = bgp_dest_unlock_node(dest);
assert(dest); for (dest = bgp_table_top(bgp->rib[afi][safi]); dest; dest = bgp_route_next(dest)) {
} table = bgp_dest_get_bgp_table_info(dest);
} if (!table)
} continue;
} bgp_cleanup_table(bgp, table, afi, safi);
for (dest = bgp_table_top(bgp->rib[AFI_L2VPN][SAFI_EVPN]); dest;
dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(dest);
if (table != NULL) {
bgp_cleanup_table(bgp, table, afi, SAFI_EVPN);
bgp_table_finish(&table); bgp_table_finish(&table);
bgp_dest_set_bgp_table_info(dest, NULL); bgp_dest_set_bgp_table_info(dest, NULL);
dest = bgp_dest_unlock_node(dest); dest = bgp_dest_unlock_node(dest);