From: David Schweizer Date: Mon, 17 Aug 2020 09:45:02 +0000 (+0200) Subject: bgpd: enhancement of bgp administrative shutdown X-Git-Tag: base_7.5~51^2~9 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=8389c83aa191bcf6871d5a8e5d06a249720f1eff;p=matthieu%2Ffrr.git bgpd: enhancement of bgp administrative shutdown * Added message to RFC 8203 peer notification about BGP instance shutdown. * Added informational log message to instance shutdown enable/disable functions. Signed-off-by: David Schweizer --- diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index f9d030e08c..79a9a80f4f 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -3601,18 +3601,31 @@ DEFUN (bgp_default_shutdown, } DEFPY (bgp_shutdown, - bgp_shutdown_cmd, - "bgp shutdown", + bgp_shutdown_msg_cmd, + "bgp shutdown message MSG...", BGP_STR - "Enable administrative shutdown of the BGP instance\n") + "Enable administrative shutdown of the BGP instance\n" + "Add a shutdown message (RFC 8203)\n" + "Shutdown message\n") { + char* msgstr = NULL; + VTY_DECLVAR_CONTEXT(bgp, bgp); - bgp_shutdown_enable(bgp); + if (argc > 3) + msgstr = argv_concat(argv, argc, 4); + + bgp_shutdown_enable(bgp, msgstr); + XFREE(MTYPE_TMP, msgstr); return CMD_SUCCESS; } +ALIAS(bgp_shutdown, bgp_shutdown_cmd, + "bgp shutdown", + BGP_STR + "Enable administrative shutdown of the BGP instance\n") + DEFPY (no_bgp_shutdown, no_bgp_shutdown_cmd, "no bgp shutdown", @@ -16064,6 +16077,7 @@ void bgp_vty_init(void) /* "bgp shutdown" commands */ install_element(BGP_NODE, &bgp_shutdown_cmd); + install_element(BGP_NODE, &bgp_shutdown_msg_cmd); install_element(BGP_NODE, &no_bgp_shutdown_cmd); /* "neighbor remote-as" commands. */ diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index aa3aba6856..7a52727a43 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4024,7 +4024,7 @@ static void peer_flag_modify_action(struct peer *peer, uint32_t flag) } /* Enable global administrative shutdown of all peers of BGP instance */ -void bgp_shutdown_enable(struct bgp *bgp) +void bgp_shutdown_enable(struct bgp *bgp, char *msg) { struct peer *peer; struct listnode *node; @@ -4033,9 +4033,9 @@ void bgp_shutdown_enable(struct bgp *bgp) if (CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN)) return; - /* TODO: log message - zlog_info("Enabled administrative shutdown on BGP instance %s", - bgp->name); */ + /* informational log message */ + zlog_info("Enabled administrative shutdown on BGP instance AS %u", + bgp->as); /* iterate through peers of BGP instance */ for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { @@ -4045,8 +4045,14 @@ void bgp_shutdown_enable(struct bgp *bgp) /* send a RFC 4486 notification message if necessary */ if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { - bgp_notify_send(peer, BGP_NOTIFY_CEASE, - BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN); + if (msg) + bgp_notify_send_with_data(peer, BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, + (uint8_t *)(msg), + strlen(msg)); + else + bgp_notify_send(peer, BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN); } /* reset start timer to initial value */ @@ -4054,11 +4060,6 @@ void bgp_shutdown_enable(struct bgp *bgp) /* trigger a RFC 4271 ManualStop event */ BGP_EVENT_ADD(peer, BGP_Stop); - - /* TODO: log message per peer? - if (bgp_debug_neighbor_events(peer)) - zlog_debug("Neighbor %s is now in administrative shutdown.", - peer->host); */ } /* set the BGP instances shutdown flag */ @@ -4072,9 +4073,9 @@ void bgp_shutdown_disable(struct bgp *bgp) if (!CHECK_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN)) return; - /* TODO: log message - zlog_info("Disabled administrative shutdown on BGP instance %s", - bgp->name); */ + /* informational log message */ + zlog_info("Disabled administrative shutdown on BGP instance AS %u", + bgp->as); /* clear the BGP instances shutdown flag */ UNSET_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN); diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 43a800326d..4e5ccf59dc 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1951,7 +1951,7 @@ extern struct peer_af *peer_af_create(struct peer *, afi_t, safi_t); extern struct peer_af *peer_af_find(struct peer *, afi_t, safi_t); extern int peer_af_delete(struct peer *, afi_t, safi_t); -extern void bgp_shutdown_enable(struct bgp *bgp); +extern void bgp_shutdown_enable(struct bgp *bgp, char *msg); extern void bgp_shutdown_disable(struct bgp *bgp); extern void bgp_close(void);