Skip to content

Commit

Permalink
Merge pull request #15731 from anlancs/bgpd-add-gr-fsm
Browse files Browse the repository at this point in the history
bgpd: adjust checking return value for commands
  • Loading branch information
ton31337 authored Apr 13, 2024
2 parents 88c55b8 + 70c4dea commit 33331ab
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 66 deletions.
138 changes: 76 additions & 62 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,14 +3035,17 @@ DEFUN (bgp_graceful_restart,
VTY_DECLVAR_CONTEXT(bgp, bgp);

ret = bgp_gr_update_all(bgp, GLOBAL_GR_CMD);

VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
ret);
if (ret == BGP_GR_SUCCESS) {
VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
bgp->peer,
ret);
vty_out(vty,
"Graceful restart configuration changed, reset all peers to take effect\n");
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug("[BGP_GR] bgp_graceful_restart_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset all peers to take effect\n");

return bgp_vty_return(vty, ret);
}

Expand All @@ -3062,14 +3065,16 @@ DEFUN (no_bgp_graceful_restart,
int ret = BGP_GR_FAILURE;

ret = bgp_gr_update_all(bgp, NO_GLOBAL_GR_CMD);

VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
ret);
if (ret == BGP_GR_SUCCESS) {
VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
bgp->peer,
ret);
vty_out(vty,
"Graceful restart configuration changed, reset all peers to take effect\n");
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug("[BGP_GR] no_bgp_graceful_restart_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset all peers to take effect\n");

return bgp_vty_return(vty, ret);
}
Expand Down Expand Up @@ -3277,24 +3282,25 @@ DEFUN (bgp_graceful_restart_disable,
VTY_DECLVAR_CONTEXT(bgp, bgp);

ret = bgp_gr_update_all(bgp, GLOBAL_DISABLE_CMD);
if (ret == BGP_GR_SUCCESS) {
VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
bgp->peer,
ret);
vty_out(vty,
"Graceful restart configuration changed, reset all peers to take effect\n");

VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
bgp->peer, ret);
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
bgp_capability_send(peer, AFI_IP, SAFI_UNICAST,
CAPABILITY_CODE_RESTART,
CAPABILITY_ACTION_UNSET);
bgp_capability_send(peer, AFI_IP, SAFI_UNICAST,
CAPABILITY_CODE_LLGR,
CAPABILITY_ACTION_UNSET);
}
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug(
"[BGP_GR] bgp_graceful_restart_disable_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset all peers to take effect\n");

for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
bgp_capability_send(peer, AFI_IP, SAFI_UNICAST,
CAPABILITY_CODE_RESTART,
CAPABILITY_ACTION_UNSET);
bgp_capability_send(peer, AFI_IP, SAFI_UNICAST,
CAPABILITY_CODE_LLGR,
CAPABILITY_ACTION_UNSET);
}
zlog_debug("[BGP_GR] bgp_graceful_restart_disable_cmd : END ");

return bgp_vty_return(vty, ret);
}
Expand All @@ -3316,15 +3322,17 @@ DEFUN (no_bgp_graceful_restart_disable,
int ret = BGP_GR_FAILURE;

ret = bgp_gr_update_all(bgp, NO_GLOBAL_DISABLE_CMD);

VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer,
ret);
if (ret == BGP_GR_SUCCESS) {
VTY_BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp,
bgp->peer,
ret);
vty_out(vty,
"Graceful restart configuration changed, reset all peers to take effect\n");
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug(
"[BGP_GR] no_bgp_graceful_restart_disable_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset all peers to take effect\n");

return bgp_vty_return(vty, ret);
}
Expand Down Expand Up @@ -3352,15 +3360,16 @@ DEFUN (bgp_neighbor_graceful_restart_set,
return CMD_WARNING_CONFIG_FAILED;

ret = bgp_neighbor_graceful_restart(peer, PEER_GR_CMD);

VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
if (ret == BGP_GR_SUCCESS) {
VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug(
"[BGP_GR] bgp_neighbor_graceful_restart_set_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");

return bgp_vty_return(vty, ret);
}
Expand Down Expand Up @@ -3389,15 +3398,16 @@ DEFUN (no_bgp_neighbor_graceful_restart,
"[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : START ");

ret = bgp_neighbor_graceful_restart(peer, NO_PEER_GR_CMD);

VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
if (ret == BGP_GR_SUCCESS) {
VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug(
"[BGP_GR] no_bgp_neighbor_graceful_restart_set_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");

return bgp_vty_return(vty, ret);
}
Expand Down Expand Up @@ -3427,15 +3437,16 @@ DEFUN (bgp_neighbor_graceful_restart_helper_set,


ret = bgp_neighbor_graceful_restart(peer, PEER_HELPER_CMD);

VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
if (ret == BGP_GR_SUCCESS) {
VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug(
"[BGP_GR] bgp_neighbor_graceful_restart_helper_set_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");

return bgp_vty_return(vty, ret);
}
Expand Down Expand Up @@ -3464,15 +3475,16 @@ DEFUN (no_bgp_neighbor_graceful_restart_helper,
"[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : START ");

ret = bgp_neighbor_graceful_restart(peer, NO_PEER_HELPER_CMD);

VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
if (ret == BGP_GR_SUCCESS) {
VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug(
"[BGP_GR] no_bgp_neighbor_graceful_restart_helper_set_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");

return bgp_vty_return(vty, ret);
}
Expand Down Expand Up @@ -3500,18 +3512,19 @@ DEFUN (bgp_neighbor_graceful_restart_disable_set,
return CMD_WARNING_CONFIG_FAILED;

ret = bgp_neighbor_graceful_restart(peer, PEER_DISABLE_CMD);
if (ret == BGP_GR_SUCCESS) {
if (peer->bgp->t_startup)
bgp_peer_gr_flags_update(peer);

if (peer->bgp->t_startup)
bgp_peer_gr_flags_update(peer);

VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug(
"[BGP_GR]bgp_neighbor_graceful_restart_disable_set_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");

return bgp_vty_return(vty, ret);
}
Expand Down Expand Up @@ -3540,15 +3553,16 @@ DEFUN (no_bgp_neighbor_graceful_restart_disable,
"[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : START ");

ret = bgp_neighbor_graceful_restart(peer, NO_PEER_DISABLE_CMD);

VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
if (ret == BGP_GR_SUCCESS) {
VTY_BGP_GR_ROUTER_DETECT(bgp, peer, peer->bgp->peer);
VTY_SEND_BGP_GR_CAPABILITY_TO_ZEBRA(peer->bgp, ret);
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");
}

if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
zlog_debug(
"[BGP_GR] no_bgp_neighbor_graceful_restart_disable_set_cmd : END ");
vty_out(vty,
"Graceful restart configuration changed, reset this peer to take effect\n");

return bgp_vty_return(vty, ret);
}
Expand Down
8 changes: 4 additions & 4 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ int bgp_global_gr_init(struct bgp *bgp)
/*GLOBAL_GR_cmd */ /*no_Global_GR_cmd*/
GLOBAL_GR, GLOBAL_INVALID,
/*GLOBAL_DISABLE_cmd*//*no_Global_Disable_cmd*/
GLOBAL_INVALID, GLOBAL_HELPER
GLOBAL_DISABLE, GLOBAL_HELPER
},
/* GLOBAL_INVALID Mode */
{
Expand Down Expand Up @@ -1411,13 +1411,13 @@ int bgp_peer_gr_init(struct peer *peer)
/* Event-> */ /* PEER_DISABLE_CMD */ /* NO_PEER_DISABLE_CMD */
{PEER_DISABLE, bgp_peer_gr_action }, {PEER_INVALID, NULL },
/* Event-> */ /* PEER_HELPER_cmd */ /* NO_PEER_HELPER_CMD */
{ PEER_INVALID, NULL }, {PEER_GLOBAL_INHERIT,
{ PEER_HELPER, NULL }, {PEER_GLOBAL_INHERIT,
bgp_peer_gr_action }
},
{
/* PEER_GR Mode */
/* Event-> */ /* PEER_GR_CMD */ /* NO_PEER_GR_CMD */
{ PEER_INVALID, NULL }, { PEER_GLOBAL_INHERIT,
{ PEER_GR, NULL }, { PEER_GLOBAL_INHERIT,
bgp_peer_gr_action },
/* Event-> */ /* PEER_DISABLE_CMD */ /* NO_PEER_DISABLE_CMD */
{PEER_DISABLE, bgp_peer_gr_action }, { PEER_INVALID, NULL },
Expand All @@ -1429,7 +1429,7 @@ int bgp_peer_gr_init(struct peer *peer)
/* Event-> */ /* PEER_GR_CMD */ /* NO_PEER_GR_CMD */
{ PEER_GR, bgp_peer_gr_action }, { PEER_INVALID, NULL },
/* Event-> */ /* PEER_DISABLE_CMD */ /* NO_PEER_DISABLE_CMD */
{ PEER_INVALID, NULL }, { PEER_GLOBAL_INHERIT,
{ PEER_DISABLE, NULL }, { PEER_GLOBAL_INHERIT,
bgp_peer_gr_action },
/* Event-> */ /* PEER_HELPER_cmd */ /* NO_PEER_HELPER_CMD */
{ PEER_HELPER, bgp_peer_gr_action }, { PEER_INVALID, NULL }
Expand Down

0 comments on commit 33331ab

Please sign in to comment.