From 50c09c5c7b89bd427d8c7a7e93c3217f4ee9a5e5 Mon Sep 17 00:00:00 2001
From: Kyrylo Yatsenko <hedrok@gmail.com>
Date: Fri, 6 Nov 2026 17:20:20 +0200
Subject: [PATCH] bgpd: Remove extra leak processing on router bgp

On each vty command `router bgp` (no vrf) there was a call of
`vpn_leak_postchange_all` even when there was no change in configuration
at all.

frr-reload.py can issue a lot of `router bgp` commands for a
configuration change, which made its usage in such cases very
time-consuming.

This was introduced in 9f7177af13c4ccf8166bf861994702635703dd9a with
change:

```
- if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
+ if (bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
```

After that comment (removed in this commit) became outdated:

```
* If we just instantiated the default instance, complete
* any pending VRF-VPN leaking that was configured via
* earlier "router bgp X vrf FOO" blocks.
```

`bgp` was always not NULL at that point, so later commit
25b6751d14900f3a3b6304f5c1292da6516dc119 removed it.

The call is not needed anymore at all after
94d12dc490d7c4109828e7d4421e7ae0d84c3448 as now
`vpn_leak_postchange_all` is called from `bgp_ifp_create` on every
loopback/vrf interface creation message, so when default bgp instance is
created, it receives these messages and calls this function anyway.

Even one extra call can take a long time when import table is large.

Signed-off-by: Kyrylo Yatsenko <hedrok@gmail.com>
---
 bgpd/bgp_mplsvpn.c | 3 ---
 bgpd/bgp_vty.c     | 7 -------
 bgpd/bgp_zebra.c   | 4 ++++
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c
index e74afebdfc..652dee30ae 100644
--- a/bgpd/bgp_mplsvpn.c
+++ b/bgpd/bgp_mplsvpn.c
@@ -3997,9 +3997,6 @@ vrf_id_t get_first_vrf_for_redirect_with_rt(struct ecommunity *eckey)
  *
  *     router bgp NNN
  *       ...
- *
- * This function gets called when the default instance ("router bgp NNN")
- * is created.
  */
 void vpn_leak_postchange_all(void)
 {
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 9045929ae6..12d2e0d4dc 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -1641,13 +1641,6 @@ DEFUN_NOSH (router_bgp,
 			vty_out(vty, "BGP instance not found\n");
 			return CMD_WARNING_CONFIG_FAILED;
 		}
-		/*
-		 * If we just instantiated the default instance, complete
-		 * any pending VRF-VPN leaking that was configured via
-		 * earlier "router bgp X vrf FOO" blocks.
-		 */
-		if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
-			vpn_leak_postchange_all();
 
 		if (inst_type == BGP_INSTANCE_TYPE_VRF || IS_BGP_INSTANCE_HIDDEN(bgp)) {
 			bgp_vpn_leak_export(bgp);
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 0658beffa6..85901b01a2 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -3476,6 +3476,10 @@ static int bgp_ifp_create(struct interface *ifp)
 		vpn_leak_zebra_vrf_label_update(bgp, AFI_IP6);
 		vpn_leak_zebra_vrf_sid_update(bgp, AFI_IP);
 		vpn_leak_zebra_vrf_sid_update(bgp, AFI_IP6);
+		/* Be careful when changing: this call is also responsible for
+		 * processing deferred route leaks when default BGP instance is
+		 * created
+		 */
 		vpn_leak_postchange_all();
 	}
 
-- 
2.55.0

