From 5cce3f05447f191a221a07960dbd68adf5265a80 Mon Sep 17 00:00:00 2001 From: bisdhdh Date: Thu, 24 Oct 2019 00:42:10 +0530 Subject: [PATCH] bgpd: Adding BGP GR change mode config apply on notification sent & received. * Changing GR mode on a router needs a session reset from the SAME router to negotiate new GR capability. * The present GR implementation needs a session reset after every new BGP GR mode change. * When BGP session reset happens due to sending or receiving BGP notification after changing BGP GR mode, there is no need of explicit session reset. Signed-off-by: Biswajit Sadhu --- bgpd/bgp_fsm.c | 1 - bgpd/bgp_packet.c | 4 ++++ bgpd/bgp_vty.c | 49 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index bafba62029..5e5ac636ed 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -1308,7 +1308,6 @@ int bgp_stop(struct peer *peer) } else { bgp_peer_conf_if_to_su_update(peer); } - return ret; } diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 0c52585a10..49b6f2f279 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -759,6 +759,8 @@ void bgp_notify_send_with_data(struct peer *peer, uint8_t code, /* Add packet to peer's output queue */ stream_fifo_push(peer->obuf, s); + bgp_peer_gr_flags_update(peer); + bgp_write_notify(peer); } @@ -1796,6 +1798,8 @@ static int bgp_notify_receive(struct peer *peer, bgp_size_t size) && bgp_notify.subcode == BGP_NOTIFY_OPEN_UNSUP_PARAM) UNSET_FLAG(peer->sflags, PEER_STATUS_CAPABILITY_OPEN); + bgp_peer_gr_flags_update(peer); + return Receive_NOTIFICATION_message; } diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index b1bef99306..896d1f0e89 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -843,6 +843,8 @@ static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, if (ret < 0) bgp_clear_vty_error(vty, peer, afi, safi, ret); + + bgp_peer_gr_flags_update(peer); } /* This is to apply read-only mode on this clear. */ @@ -2145,6 +2147,9 @@ DEFUN (bgp_graceful_restart, ) { int ret = BGP_GR_FAILURE; + struct peer *peer; + struct listnode *node = {0}; + struct listnode *nnode = {0}; if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug("BGP_GR:: bgp_graceful_restart_cmd : START "); @@ -2152,6 +2157,11 @@ DEFUN (bgp_graceful_restart, ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD); + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { + if (peer->bgp->t_startup) + bgp_peer_gr_flags_update(peer); + } + if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug("BGP_GR:: bgp_graceful_restart_cmd : END "); return bgp_vty_return(vty, ret); @@ -2166,6 +2176,9 @@ DEFUN (no_bgp_graceful_restart, ) { VTY_DECLVAR_CONTEXT(bgp, bgp); + struct peer *peer; + struct listnode *node = {0}; + struct listnode *nnode = {0}; if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug("BGP_GR:: no_bgp_graceful_restart_cmd : START "); @@ -2174,6 +2187,11 @@ DEFUN (no_bgp_graceful_restart, ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD); + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { + if (peer->bgp->t_startup) + bgp_peer_gr_flags_update(peer); + } + if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug("BGP_GR:: no_bgp_graceful_restart_cmd : END "); @@ -2315,6 +2333,9 @@ DEFUN (bgp_graceful_restart_disable, GR_DISABLE) { int ret = BGP_GR_FAILURE; + struct peer *peer; + struct listnode *node = {0}; + struct listnode *nnode = {0}; if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug( @@ -2323,6 +2344,11 @@ DEFUN (bgp_graceful_restart_disable, ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD); + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { + if (peer->bgp->t_startup) + bgp_peer_gr_flags_update(peer); + } + if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug( "BGP_GR:: bgp_graceful_restart_disable_cmd : END "); @@ -2338,6 +2364,9 @@ DEFUN (no_bgp_graceful_restart_disable, ) { VTY_DECLVAR_CONTEXT(bgp, bgp); + struct peer *peer; + struct listnode *node = {0}; + struct listnode *nnode = {0}; if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug( @@ -2347,6 +2376,11 @@ DEFUN (no_bgp_graceful_restart_disable, ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD); + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { + if (peer->bgp->t_startup) + bgp_peer_gr_flags_update(peer); + } + if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug( "BGP_GR:: no_bgp_graceful_restart_disable_cmd : END "); @@ -2413,7 +2447,7 @@ DEFUN (no_bgp_neighbor_graceful_restart, if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug( - "BGP_GR:: no_bgp_neighbor_graceful_restart_set_cmd : END "); + "BGP_GR:: no_bgp_neighbor_graceful_restart_helper_set_cmd : END "); return bgp_vty_return(vty, ret); } @@ -2432,17 +2466,18 @@ DEFUN (bgp_neighbor_graceful_restart_helper_set, if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug( - "BGP_GR:: bgp_neighbor_graceful_restart_set_helper_cmd : START "); + "BGP_GR:: bgp_neighbor_graceful_restart_helper_set_cmd : START "); peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); - if (peer->bgp->t_startup) - bgp_peer_gr_flags_update(peer); - if (!peer) return CMD_WARNING_CONFIG_FAILED; ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD); + + if (peer->bgp->t_startup) + bgp_peer_gr_flags_update(peer); + if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug( "BGP_GR:: bgp_neighbor_graceful_restart_helper_set_cmd : END "); @@ -2479,7 +2514,7 @@ DEFUN (no_bgp_neighbor_graceful_restart_helper, if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) zlog_debug( - "BGP_GR:: no_bgp_neighbor_graceful_restart_set_cmd : END "); + "BGP_GR:: no_bgp_neighbor_graceful_restart_disable_set_cmd : END "); return bgp_vty_return(vty, ret); } @@ -2506,7 +2541,7 @@ DEFUN (bgp_neighbor_graceful_restart_disable_set, ret = bgp_neighbor_graceful_restart(peer, - PEER_DISABLE_cmd); + PEER_DISABLE_cmd); if (peer->bgp->t_startup) bgp_peer_gr_flags_update(peer); -- 2.39.5