Skip to content

Commit

Permalink
bgpd: Ensure BGP does not stop monitoring nexthops
Browse files Browse the repository at this point in the history
In some cases BGP can be monitoring the same prefix
in both the nexthop and import check tables.  If this
is the case, when unregistering one bnc from one table
make sure we are not still registered in the other

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Nov 6, 2023
1 parent d67c60e commit ac795e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bgpd/bgp_nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ PREDECL_RBTREE_UNIQ(bgp_nexthop_cache);

/* BGP nexthop cache value structure. */
struct bgp_nexthop_cache {
afi_t afi;

/* The ifindex of the outgoing interface *if* it's a v6 LL */
ifindex_t ifindex_ipv6_ll;

Expand Down
19 changes: 19 additions & 0 deletions bgpd/bgp_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop,
bnc = bnc_find(tree, &p, srte_color, ifindex);
if (!bnc) {
bnc = bnc_new(tree, &p, srte_color, ifindex);
bnc->afi = afi;
bnc->bgp = bgp_nexthop;
if (BGP_DEBUG(nht, NHT))
zlog_debug("Allocated bnc %pFX(%d)(%u)(%s) peer %p",
Expand Down Expand Up @@ -1170,6 +1171,11 @@ static void register_zebra_rnh(struct bgp_nexthop_cache *bnc)
*/
static void unregister_zebra_rnh(struct bgp_nexthop_cache *bnc)
{
struct bgp_nexthop_cache *import;
struct bgp_nexthop_cache *nexthop;

struct bgp *bgp = bnc->bgp;

/* Check if we have already registered */
if (!CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED))
return;
Expand All @@ -1179,6 +1185,19 @@ static void unregister_zebra_rnh(struct bgp_nexthop_cache *bnc)
return;
}

import = bnc_find(&bgp->import_check_table[bnc->afi], &bnc->prefix, 0,
0);
nexthop = bnc_find(&bgp->nexthop_cache_table[bnc->afi], &bnc->prefix, 0,
0);

/*
* If this entry has both a import and a nexthop entry
* then let's not send the unregister quite as of yet
* wait until we only have 1 left
*/
if (import && nexthop)
return;

sendmsg_zebra_rnh(bnc, ZEBRA_NEXTHOP_UNREGISTER);
}

Expand Down

0 comments on commit ac795e8

Please sign in to comment.