From 9acb67cbf8bd0a0e3ff9ecad4b1aec2401dc5491 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 3 Dec 2020 15:48:59 -0500 Subject: [PATCH] bgpd: Add global `bgp suppress-fib-pending` command On top of the recent `bgp suppress-fib-pending which was at a BGP_NODE level, add this command at the CONFIG_NODE level as well and allow the command to apply to all instances of bgp running. Signed-off-by: Donald Sharp --- bgpd/bgp_vty.c | 18 ++++++++++++++++++ bgpd/bgpd.c | 24 ++++++++++++++++++++++++ bgpd/bgpd.h | 9 +++++++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 955e73fcf3..e840f8bceb 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -1514,6 +1514,18 @@ void cli_show_router_bgp_router_id(struct vty *vty, struct lyd_node *dnode, vty_out(vty, " bgp router-id %s\n", yang_dnode_get_string(dnode, NULL)); } +DEFPY (bgp_global_suppress_fib_pending, + bgp_global_suppress_fib_pending_cmd, + "[no] bgp suppress-fib-pending", + NO_STR + BGP_STR + "Advertise only routes that are programmed in kernel to peers globally\n") +{ + bm_wait_for_fib_set(!no); + + return CMD_SUCCESS; +} + DEFPY (bgp_suppress_fib_pending, bgp_suppress_fib_pending_cmd, "[no] bgp suppress-fib-pending", @@ -16936,6 +16948,9 @@ int bgp_config_write(struct vty *vty) vty_out(vty, "\n"); } + if (bm->wait_for_fib) + vty_out(vty, "bgp suppress-fib-pending\n"); + if (CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)) vty_out(vty, "bgp graceful-shutdown\n"); @@ -17464,6 +17479,9 @@ void bgp_vty_init(void) install_element(CONFIG_NODE, &bgp_local_mac_cmd); install_element(CONFIG_NODE, &no_bgp_local_mac_cmd); + /* "bgp suppress-fib-pending" global */ + install_element(CONFIG_NODE, &bgp_global_suppress_fib_pending_cmd); + /* bgp route-map delay-timer commands. */ install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd); install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index d3db540871..22c1caacad 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -393,6 +393,29 @@ void bgp_router_id_static_set(struct bgp *bgp, struct in_addr id) true /* is config */); } +void bm_wait_for_fib_set(bool set) +{ + bool send_msg = false; + + if (bm->wait_for_fib == set) + return; + + bm->wait_for_fib = set; + if (set) { + if (bgp_suppress_fib_count == 0) + send_msg = true; + bgp_suppress_fib_count++; + } else { + bgp_suppress_fib_count--; + if (bgp_suppress_fib_count == 0) + send_msg = true; + } + + if (send_msg && zclient) + zebra_route_notify_send(ZEBRA_ROUTE_NOTIFY_REQUEST, + zclient, set); +} + /* Set the suppress fib pending for the bgp configuration */ void bgp_suppress_fib_pending_set(struct bgp *bgp, bool set) { @@ -7419,6 +7442,7 @@ void bgp_master_init(struct thread_master *master, const int buffer_size) bm->terminating = false; bm->socket_buffer = buffer_size; bm->send_extra_data_to_zebra = true; + bm->wait_for_fib = false; bgp_mac_init(); /* init the rd id space. diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 3451a616a4..ebc53fe192 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -159,6 +159,9 @@ struct bgp_master { /* How big should we set the socket buffer size */ uint32_t socket_buffer; + /* Should we do wait for fib install globally? */ + bool wait_for_fib; + /* EVPN multihoming */ struct bgp_evpn_mh_info *mh_info; @@ -719,8 +722,9 @@ struct afi_safi_info { #define BGP_SELECT_DEFER_DISABLE(bgp) \ (CHECK_FLAG(bgp->flags, BGP_FLAG_SELECT_DEFER_DISABLE)) -#define BGP_SUPPRESS_FIB_ENABLED(bgp) \ - (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING)) +#define BGP_SUPPRESS_FIB_ENABLED(bgp) \ + (CHECK_FLAG(bgp->flags, BGP_FLAG_SUPPRESS_FIB_PENDING) \ + || bm->wait_for_fib) /* BGP peer-group support. */ struct peer_group { @@ -1879,6 +1883,7 @@ extern int bgp_handle_socket(struct bgp *bgp, struct vrf *vrf, extern void bgp_router_id_zebra_bump(vrf_id_t, const struct prefix *); extern void bgp_router_id_static_set(struct bgp *, struct in_addr); +extern void bm_wait_for_fib_set(bool set); extern void bgp_suppress_fib_pending_set(struct bgp *bgp, bool set); extern int bgp_cluster_id_set(struct bgp *, struct in_addr *); extern int bgp_cluster_id_unset(struct bgp *); -- 2.39.5