From: Donatas Abraitis Date: Tue, 5 Nov 2019 12:33:31 +0000 (+0200) Subject: bgpd: Notify "Peer De-configured" after entering 'no neighbor cmd' X-Git-Tag: base_7.3~156^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=4e2786df3ec09810ace405b62d82d243ad15c062;p=mirror%2Ffrr.git 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 --- diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 17c93ffc38..3116e7cad0 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -3146,14 +3146,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; } @@ -3167,9 +3169,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); + } } } @@ -3201,6 +3206,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"); @@ -3222,9 +3228,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; } @@ -3582,6 +3589,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 7621d7ef0f..ffe0dc0e69 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -2562,6 +2562,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 317f200b85..e27018407f 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1638,9 +1638,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);