Skip to content

Commit

Permalink
bgpd: Make bgp ready to remove distinction between 2 nh tracking types
Browse files Browse the repository at this point in the history
Allow bgp to figure out if it cares about address resolution instead
of having zebra care about it.  This will allow the removal of the
zapi type for import checking and just use nexthop resolution.

Effectively we just look up the route being returned and
if it is in either table we just handle it instead of
looking for clues from the zapi message type.

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Sep 27, 2021
1 parent ed6cec9 commit b821084
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions bgpd/bgp_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ void bgp_nht_interface_events(struct peer *peer)
void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id)
{
struct bgp_nexthop_cache_head *tree = NULL;
struct bgp_nexthop_cache *bnc;
struct bgp_nexthop_cache *bnc_nhc, *bnc_import;
struct bgp *bgp;
struct zapi_route nhr;
afi_t afi;
Expand All @@ -685,22 +685,38 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id)
}

afi = family2afi(nhr.prefix.family);
if (command == ZEBRA_NEXTHOP_UPDATE)
tree = &bgp->nexthop_cache_table[afi];
else if (command == ZEBRA_IMPORT_CHECK_UPDATE)
tree = &bgp->import_check_table[afi];
tree = &bgp->nexthop_cache_table[afi];

bnc = bnc_find(tree, &nhr.prefix, nhr.srte_color);
if (!bnc) {
bnc_nhc = bnc_find(tree, &nhr.prefix, nhr.srte_color);
if (!bnc_nhc) {
if (BGP_DEBUG(nht, NHT))
zlog_debug(
"parse nexthop update(%pFX(%u)(%s)): bnc info not found",
"parse nexthop update(%pFX(%u)(%s)): bnc info not found for nexthop cache",
&nhr.prefix, nhr.srte_color, bgp->name_pretty);
} else
bgp_process_nexthop_update(bnc_nhc, &nhr);

tree = &bgp->import_check_table[afi];

bnc_import = bnc_find(tree, &nhr.prefix, nhr.srte_color);
if (!bnc_import) {
if (BGP_DEBUG(nht, NHT))
zlog_debug(
"parse nexthop update(%pFX(%u)(%s)): bnc info not found for import check",
&nhr.prefix, nhr.srte_color, bgp->name_pretty);
return;
} else {
if (nhr.type == ZEBRA_ROUTE_BGP
|| !prefix_same(&bnc_import->prefix, &nhr.prefix)) {
if (BGP_DEBUG(nht, NHT))
zlog_debug(
"%s: Import Check does not resolve to the same prefix for %pFX received %pFX",
__func__, &bnc_import->prefix, &nhr.prefix);
return;
}
bgp_process_nexthop_update(bnc_import, &nhr);
}

bgp_process_nexthop_update(bnc, &nhr);

/*
* HACK: if any BGP route is dependant on an SR-policy that doesn't
* exist, zebra will never send NH updates relative to that policy. In
Expand All @@ -712,12 +728,12 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id)
* which should provide a better infrastructure to solve this issue in
* a more efficient and elegant way.
*/
if (nhr.srte_color == 0) {
if (nhr.srte_color == 0 && bnc_nhc) {
struct bgp_nexthop_cache *bnc_iter;

frr_each (bgp_nexthop_cache, &bgp->nexthop_cache_table[afi],
bnc_iter) {
if (!prefix_same(&bnc->prefix, &bnc_iter->prefix)
if (!prefix_same(&bnc_import->prefix, &bnc_iter->prefix)
|| bnc_iter->srte_color == 0
|| CHECK_FLAG(bnc_iter->flags, BGP_NEXTHOP_VALID))
continue;
Expand Down

0 comments on commit b821084

Please sign in to comment.