From 3c839977ebb9f2eb3b683e002fffa17be9a3e6e5 Mon Sep 17 00:00:00 2001
From: Maria Matejka <mq@ucw.cz>
Date: Wed, 4 Jun 2025 14:53:36 +0200
Subject: BGP: Restart if route refresh is impossible on attribute change

In previous commit, we force route refresh when some protocol attributes
change. Yet, when the neighbor doesn't support route refresh, we have to
restart the session, not send an unsupported request.

Note: if the neighbor is restarting right now with graceful restart
enabled, we keep the stale routes until the neighbor converges again.

Related to #268

diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c
index 203715258..d38666fab 100644
--- a/proto/bgp/bgp.c
+++ b/proto/bgp/bgp.c
@@ -2833,7 +2833,15 @@ bgp_channel_reconfigure(struct channel *C, struct channel_config *CC, int *impor
       (new->cost != old->cost) ||
       (new->c.preference != old->c.preference))
   {
-    /* import_changed itself does not force ROUTE_REFRESH when import_table is active */
+    /* Route refresh needed, these attributes are set by BGP itself
+     * and even if import table exists, we can't use it */
+
+    /* Route refresh impossible, restart is needed */
+    if ((c->c.channel_state == CS_UP) && !p->route_refresh)
+      return 0;
+
+    /* Force ROUTE_REFRESH with import table; otherwise
+     * it will be forced by import_changed set to 1 later */
     if (c->c.in_table && (c->c.channel_state == CS_UP))
       bgp_schedule_packet(p->conn, c, PKT_ROUTE_REFRESH);
 
