From 62a452c47fd328db450923c13ed9c180d6938e10 Mon Sep 17 00:00:00 2001 From: Trey Aspelund Date: Mon, 24 Jul 2023 20:16:08 +0000 Subject: [PATCH] bgpd: skip reset when removing dup update-source When 'no neighbor .. update-source' is issued for a regular peer, that peer is always reset. This is unnecessary if the peer is a member of a peer-group and it inherits an identical update-source, so let's skip the reset/Notification for that condition. Config: ------------ router bgp 1 neighbor PG peer-group neighbor PG remote-as internal neighbor PG update-source 100.64.0.3 neighbor 192.168.122.99 peer-group PG neighbor 192.168.122.99 update-source 100.64.0.3 Before: ------------ ub20-2(config-router)# do show ip bgp sum | include .99 192.168.122.99 4 1 36 34 0 0 0 00:00:17 0 0 N/A ub20-2(config-router)# do show ip bgp neighbors 192.168.122.99 | include Local host Local host: 100.64.0.3, Local port: 46083 ub20-2(config-router)# no neighbor 192.168.122.99 update-source ub20-2(config-router)# do show ip bgp sum | include .99 192.168.122.99 4 1 36 35 0 0 0 00:00:01 Idle 0 N/A ub20-2(config-router)# do show ip bgp neighbors 192.168.122.99 | include Local host Local host: 100.64.0.3, Local port: 39847 After: ------------ ub20-2(config-router)# do show ip bgp sum | include .99 192.168.122.99 4 1 3 3 0 0 0 00:00:20 0 0 N/A ub20-2(config-router)# do show ip bgp neighbors 192.168.122.99 | include Local host Local host: 100.64.0.3, Local port: 39415 ub20-2(config-router)# no neighbor 192.168.122.99 update-source ub20-2(config-router)# do show ip bgp sum | include .99 192.168.122.99 4 1 3 3 0 0 0 00:00:28 0 0 N/A ub20-2(config-router)# do show ip bgp neighbors 192.168.122.99 | include Local host Local host: 100.64.0.3, Local port: 39415 Signed-off-by: Trey Aspelund --- bgpd/bgpd.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 28c1a9da6b..84890da8c1 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -5393,16 +5393,29 @@ void peer_update_source_unset(struct peer *peer) { struct peer *member; struct listnode *node, *nnode; + bool src_unchanged = false; if (!CHECK_FLAG(peer->flags, PEER_FLAG_UPDATE_SOURCE)) return; /* Inherit configuration from peer-group if peer is member. */ if (peer_group_active(peer)) { + /* Don't reset peer if the update_source we'll inherit from + * the peer-group matches the peer's existing update_source + */ + src_unchanged = + (peer->update_source && + peer->group->conf->update_source && + sockunion_cmp(peer->update_source, + peer->group->conf->update_source) == 0); + peer_flag_inherit(peer, PEER_FLAG_UPDATE_SOURCE); PEER_SU_ATTR_INHERIT(peer, peer->group, update_source); PEER_STR_ATTR_INHERIT(peer, peer->group, update_if, MTYPE_PEER_UPDATE_SOURCE); + + if (src_unchanged) + return; } else { /* Otherwise remove flag and configuration from peer. */ peer_flag_unset(peer, PEER_FLAG_UPDATE_SOURCE);