From: Donald Sharp Date: Fri, 5 Oct 2018 15:31:29 +0000 (-0400) Subject: bgpd: Allow registration of nexthops after zebra connection X-Git-Tag: frr-7.1-dev~227^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=1ee0a2df0d7f7052485b455966757be2a5562a1d;p=mirror%2Ffrr.git bgpd: Allow registration of nexthops after zebra connection If we attempt to register nexthops before we have the zebra connection, they will not be installed. After we have noticed that we are up, re-install them. Signed-off-by: Donald Sharp --- diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 5ed6fd6ebe..2ef792e129 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -628,7 +628,10 @@ static void bgp_show_nexthops(struct vty *vty, struct bgp *bgp, int detail) if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED)) vty_out(vty, " Must be Connected\n"); - } + if (!CHECK_FLAG(bnc->flags, + BGP_NEXTHOP_REGISTERED)) + vty_out(vty, " Is not Registered\n"); + } tbuf = time(NULL) - (bgp_clock() - bnc->last_update); vty_out(vty, " Last update: %s", ctime(&tbuf)); vty_out(vty, "\n"); diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 2e7f17fdae..8aa7798af4 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -240,8 +240,8 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, UNSET_FLAG(bnc->flags, BGP_NEXTHOP_VALID); } if (bgp_route->inst_type == BGP_INSTANCE_TYPE_VIEW) { - bnc->flags |= BGP_NEXTHOP_REGISTERED; - bnc->flags |= BGP_NEXTHOP_VALID; + SET_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED); + SET_FLAG(bnc->flags, BGP_NEXTHOP_VALID); } else if (!CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED)) register_zebra_rnh(bnc, is_bgp_static_route); if (pi && pi->nexthop != bnc) { @@ -594,6 +594,11 @@ static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command) return; } + if (!bgp_zebra_num_connects()) { + if (BGP_DEBUG(zebra, ZEBRA)) + zlog_debug("%s: We have not connected yet, cannot send nexthops", + __PRETTY_FUNCTION__); + } p = &(bnc->node->p); if ((command == ZEBRA_NEXTHOP_REGISTER || command == ZEBRA_IMPORT_ROUTE_REGISTER) @@ -806,3 +811,30 @@ void path_nh_map(struct bgp_path_info *path, struct bgp_nexthop_cache *bnc, path->nexthop->path_count++; } } + +/* + * This function is called to register nexthops to zebra + * as that we may have tried to install the nexthops + * before we actually have a zebra connection + */ +void bgp_nht_register_nexthops(struct bgp *bgp) +{ + struct bgp_node *rn; + struct bgp_nexthop_cache *bnc; + afi_t afi; + + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + if (!bgp->nexthop_cache_table[afi]) + continue; + + for (rn = bgp_table_top(bgp->nexthop_cache_table[afi]); rn; + rn = bgp_route_next(rn)) { + bnc = bgp_nexthop_get_node_info(rn); + + if (!bnc) + continue; + + register_zebra_rnh(bnc, 0); + } + } +} diff --git a/bgpd/bgp_nht.h b/bgpd/bgp_nht.h index 0cc045a065..96dd915596 100644 --- a/bgpd/bgp_nht.h +++ b/bgpd/bgp_nht.h @@ -81,5 +81,11 @@ extern void bgp_cleanup_nexthops(struct bgp *bgp); */ extern void path_nh_map(struct bgp_path_info *path, struct bgp_nexthop_cache *bnc, bool make); +/* + * When we actually have the connection to + * the zebra daemon, we need to reregister + * any nexthops we may have sitting around + */ +extern void bgp_nht_register_nexthops(struct bgp *bgp); #endif /* _BGP_NHT_H */ diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 0b79a9ee18..50b790eb11 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1837,6 +1837,8 @@ void bgp_zebra_instance_register(struct bgp *bgp) */ if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT && is_evpn_enabled()) bgp_zebra_advertise_all_vni(bgp, 1); + + bgp_nht_register_nexthops(bgp); } /* Deregister this instance with Zebra. Invoked upon the instance