Skip to content

Commit

Permalink
bgpd : Prevent deletion of BGP peer groups associated to listen range
Browse files Browse the repository at this point in the history
Description:
-----
Deleting a peer group also deletes its associated BGP listen range.
This behaviour is undesired as it could cause unintended configuration changes.

Fix :
-----
-Do not allow peer group deletion until they are no longer associated with any listen range.
-Check the count of listen ranges attached to the group.
If any listen ranges are found, returns a configuration warning, preventing the deletion.

Signed-off-by: Pooja Rathore <rathorepo@vmware.com>
  • Loading branch information
rathorepo committed Apr 27, 2024
1 parent 27cc9ae commit 48faeaf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -5102,6 +5102,8 @@ DEFUN (no_neighbor,
struct peer_group *group;
struct peer *peer;
struct peer *other;
afi_t afi;
int lr_count;

ret = str2sockunion(argv[idx_peer]->arg, &su);
if (ret < 0) {
Expand All @@ -5119,6 +5121,15 @@ DEFUN (no_neighbor,

group = peer_group_lookup(bgp, argv[idx_peer]->arg);
if (group) {
for (afi = AFI_IP; afi < AFI_MAX; afi++) {
lr_count = listcount(group->listen_range[afi]);
if (lr_count) {
vty_out(vty,
"%%Peer-group %s is attached to %d listen-range(s), delete them first\n",
group->name, lr_count);
return CMD_WARNING_CONFIG_FAILED;
}
}
peer_group_notify_unconfig(group);
peer_group_delete(group);
} else {
Expand Down Expand Up @@ -5196,9 +5207,20 @@ DEFUN (no_neighbor_peer_group,
VTY_DECLVAR_CONTEXT(bgp, bgp);
int idx_word = 2;
struct peer_group *group;
afi_t afi;
int lr_count;

group = peer_group_lookup(bgp, argv[idx_word]->arg);
if (group) {
for (afi = AFI_IP; afi < AFI_MAX; afi++) {
lr_count = listcount(group->listen_range[afi]);
if (lr_count) {
vty_out(vty,
"%%Peer-group %s is attached to %d listen-range(s), delete them first\n",
group->name, lr_count);
return CMD_WARNING_CONFIG_FAILED;
}
}
peer_group_notify_unconfig(group);
peer_group_delete(group);
} else {
Expand Down

0 comments on commit 48faeaf

Please sign in to comment.