From f26845f9a63e1be1c87632281fb30a67752886f9 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 11 Jan 2018 12:50:08 -0500 Subject: [PATCH] bgpd: add neighbor autoshutdown Adds ability to specify that peers should be administratively shutdown when first configured. Signed-off-by: Quentin Young --- bgpd/bgp_vty.c | 17 ++++++++++++++++- bgpd/bgpd.c | 9 ++++++++- bgpd/bgpd.h | 3 +++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 50e5bcf096..443f299ab1 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -2677,6 +2677,19 @@ static int peer_remote_as_vty(struct vty *vty, const char *peer_str, return bgp_vty_return(vty, ret); } +DEFUN (bgp_default_shutdown, + bgp_default_shutdown_cmd, + "[no] bgp default shutdown", + NO_STR + BGP_STR + "Configure BGP defaults\n" + "Do not automatically activate peers upon configuration\n") +{ + VTY_DECLVAR_CONTEXT(bgp, bgp); + bgp->autoshutdown = !strmatch(argv[0]->text, "no"); + return CMD_SUCCESS; +} + DEFUN (neighbor_remote_as, neighbor_remote_as_cmd, "neighbor remote-as <(1-4294967295)|internal|external>", @@ -3223,7 +3236,6 @@ DEFUN (no_neighbor_password, return bgp_vty_return(vty, ret); } - DEFUN (neighbor_activate, neighbor_activate_cmd, "neighbor activate", @@ -11555,6 +11567,9 @@ void bgp_vty_init(void) install_element(BGP_NODE, &bgp_listen_range_cmd); install_element(BGP_NODE, &no_bgp_listen_range_cmd); + /* "neighbors auto-shutdown" command */ + install_element(BGP_NODE, &bgp_default_shutdown_cmd); + /* "neighbor remote-as" commands. */ install_element(BGP_NODE, &neighbor_remote_as_cmd); install_element(BGP_NODE, &neighbor_interface_config_cmd); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 2e660c20eb..a471bbaa9d 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -1497,8 +1497,11 @@ struct peer *peer_create(union sockunion *su, const char *conf_if, peer_af_create(peer, afi, safi); } + /* auto shutdown if configured */ + if (bgp->autoshutdown) + peer_flag_set(peer, PEER_FLAG_SHUTDOWN); /* Set up peer's events and timers. */ - if (!active && peer_active(peer)) + else if (!active && peer_active(peer)) bgp_timer_set(peer); return peer; @@ -7140,6 +7143,10 @@ int bgp_config_write(struct vty *vty) vty_out(vty, " bgp default subgroup-pkt-queue-max %u\n", bgp->default_subgroup_pkt_queue_max); + /* BGP default autoshutdown neighbors */ + if (bgp->autoshutdown) + vty_out(vty, " bgp default auto-shutdown\n"); + /* BGP client-to-client reflection. */ if (bgp_flag_check(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT)) vty_out(vty, " no bgp client-to-client reflection\n"); diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 20b99c171e..1e2b4c8cd7 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -386,6 +386,9 @@ struct bgp { /* Actual coalesce time */ uint32_t coalesce_time; + /* Auto-shutdown new peers */ + bool autoshutdown; + u_int32_t addpath_tx_id; int addpath_tx_used[AFI_MAX][SAFI_MAX];