From 64396cba7358b597d2e8093f71092d08bbf0021d Mon Sep 17 00:00:00 2001 From: vivek Date: Tue, 23 May 2017 23:08:09 -0700 Subject: [PATCH] bgpd: Fix route handling for 2-level routing tables For certain (sub) address families such as EVPN or L3VPN, the routing table is organized as a 2-level tree. Ensure that code walking the routing table does the correct handling in such cases. Signed-off-by: Vivek Venkatraman --- bgpd/bgpd.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 92a0cd6acc..9d404b16dc 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -1477,17 +1477,28 @@ bgp_recalculate_all_bestpaths (struct bgp *bgp) { afi_t afi; safi_t safi; - struct bgp_node *rn; + struct bgp_node *rn, *nrn; for (afi = AFI_IP; afi < AFI_MAX; afi++) { for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { - for (rn = bgp_table_top (bgp->rib[afi][safi]); rn; rn = bgp_route_next (rn)) + for (rn = bgp_table_top (bgp->rib[afi][safi]); rn; + rn = bgp_route_next (rn)) { if (rn->info != NULL) { - bgp_process (bgp, rn, afi, safi); + /* Special handling for 2-level routing tables. */ + if (safi == SAFI_MPLS_VPN || + safi == SAFI_ENCAP || + safi == SAFI_EVPN) + { + for (nrn = bgp_table_top((struct bgp_table *)(rn->info)); + nrn; nrn = bgp_route_next (nrn)) + bgp_process (bgp, nrn, afi, safi); + } + else + bgp_process (bgp, rn, afi, safi); } } } @@ -3289,6 +3300,8 @@ bgp_free (struct bgp *bgp) { afi_t afi; safi_t safi; + struct bgp_table *table; + struct bgp_node *rn; QOBJ_UNREG (bgp); @@ -3304,6 +3317,18 @@ bgp_free (struct bgp *bgp) for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { + /* Special handling for 2-level routing tables. */ + if (safi == SAFI_MPLS_VPN || + safi == SAFI_ENCAP || + safi == SAFI_EVPN) + { + for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; + rn = bgp_route_next (rn)) + { + table = (struct bgp_table *) rn->info; + bgp_table_finish(&table); + } + } if (bgp->route[afi][safi]) bgp_table_finish (&bgp->route[afi][safi]); if (bgp->aggregate[afi][safi]) -- 2.39.5