From 7f98269f85022e152294cc005deb935e6473e5a4 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 5 Nov 2019 14:33:31 +0200 Subject: [PATCH] bgpd: Notify "Peer De-configured" after entering 'no neighbor cmd' Before changes: ~# vtysh -c 'show ip bgp neighbors 192.168.0.2 json' | \ jq '."192.168.0.2".lastNotificationReason' null After changes: ~# vtysh -c 'show ip bgp neighbors 192.168.0.2 json' | \ jq '."192.168.0.2".lastNotificationReason' "Cease/Peer Unconfigured" Signed-off-by: Donatas Abraitis --- bgpd/bgp_vty.c | 18 +++++++++++++----- bgpd/bgpd.c | 24 ++++++++++++++++++++++++ bgpd/bgpd.h | 2 ++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 3b15a9c7a2..2c0538d0a9 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -3152,14 +3152,16 @@ DEFUN (no_neighbor, * interface. */ if (peer->ifp) bgp_zebra_terminate_radv(peer->bgp, peer); + peer_notify_unconfig(peer); peer_delete(peer); return CMD_SUCCESS; } group = peer_group_lookup(bgp, argv[idx_peer]->arg); - if (group) + if (group) { + peer_group_notify_unconfig(group); peer_group_delete(group); - else { + } else { vty_out(vty, "%% Create the peer-group first\n"); return CMD_WARNING_CONFIG_FAILED; } @@ -3173,9 +3175,12 @@ DEFUN (no_neighbor, } other = peer->doppelganger; + peer_notify_unconfig(peer); peer_delete(peer); - if (other && other->status != Deleted) + if (other && other->status != Deleted) { + peer_notify_unconfig(other); peer_delete(other); + } } } @@ -3207,6 +3212,7 @@ DEFUN (no_neighbor_interface_config, /* Request zebra to terminate IPv6 RAs on this interface. */ if (peer->ifp) bgp_zebra_terminate_radv(peer->bgp, peer); + peer_notify_unconfig(peer); peer_delete(peer); } else { vty_out(vty, "%% Create the bgp interface first\n"); @@ -3228,9 +3234,10 @@ DEFUN (no_neighbor_peer_group, struct peer_group *group; group = peer_group_lookup(bgp, argv[idx_word]->arg); - if (group) + if (group) { + peer_group_notify_unconfig(group); peer_group_delete(group); - else { + } else { vty_out(vty, "%% Create the peer-group first\n"); return CMD_WARNING_CONFIG_FAILED; } @@ -3588,6 +3595,7 @@ DEFUN (no_neighbor_set_peer_group, return CMD_WARNING_CONFIG_FAILED; } + peer_notify_unconfig(peer); ret = peer_delete(peer); return bgp_vty_return(vty, ret); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index f0130c9768..a557c9c7bc 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -2553,6 +2553,30 @@ int peer_group_remote_as(struct bgp *bgp, const char *group_name, as_t *as, return 0; } +int peer_notify_unconfig(struct peer *peer) +{ + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) + bgp_notify_send(peer, BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_PEER_UNCONFIG); + return 0; +} + +int peer_group_notify_unconfig(struct peer_group *group) +{ + struct peer *peer, *other; + struct listnode *node, *nnode; + + for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { + other = peer->doppelganger; + if (other && other->status != Deleted) { + other->group = NULL; + peer_notify_unconfig(other); + } else + peer_notify_unconfig(peer); + } + return 0; +} + int peer_group_delete(struct peer_group *group) { struct bgp *bgp; diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 865f5a2b68..273fef43c2 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1618,9 +1618,11 @@ extern int peer_remote_as(struct bgp *, union sockunion *, const char *, as_t *, int, afi_t, safi_t); extern int peer_group_remote_as(struct bgp *, const char *, as_t *, int); extern int peer_delete(struct peer *peer); +extern int peer_notify_unconfig(struct peer *peer); extern int peer_group_delete(struct peer_group *); extern int peer_group_remote_as_delete(struct peer_group *); extern int peer_group_listen_range_add(struct peer_group *, struct prefix *); +extern int peer_group_notify_unconfig(struct peer_group *group); extern int peer_activate(struct peer *, afi_t, safi_t); extern int peer_deactivate(struct peer *, afi_t, safi_t); -- 2.39.5