From 4385ff11cc63a02732bb8bcb3e145a4de63ac546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 21 Oct 2024 14:42:18 -0400 Subject: [PATCH] incusd/network/bgp: Only advertise networks with BGP configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber --- internal/server/network/driver_common.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/server/network/driver_common.go b/internal/server/network/driver_common.go index f4d6fd536d2..28d26172922 100644 --- a/internal/server/network/driver_common.go +++ b/internal/server/network/driver_common.go @@ -637,17 +637,30 @@ func (n *common) bgpValidationRules(config map[string]string) (map[string]func(v // bgpSetup initializes BGP peers and prefixes. func (n *common) bgpSetup(oldConfig map[string]string) error { + currentPeers := n.bgpGetPeers(n.config) + oldPeers := n.bgpGetPeers(oldConfig) + + // Don't set up BGP when no peers are configured. + if len(currentPeers) == 0 { + if len(oldPeers) > 0 { + return n.bgpClear(oldConfig) + } + + return nil + } + + // Set up the peers. err := n.bgpSetupPeers(oldConfig) if err != nil { return fmt.Errorf("Failed setting up BGP peers: %w", err) } + // Export the prefixes. err = n.bgpSetupPrefixes(oldConfig) if err != nil { return fmt.Errorf("Failed setting up BGP prefixes: %w", err) } - // Refresh exported BGP prefixes on local member. err = n.forwardBGPSetupPrefixes() if err != nil { return fmt.Errorf("Failed applying BGP prefixes for address forwards: %w", err) @@ -661,7 +674,7 @@ func (n *common) bgpSetup(oldConfig map[string]string) error { return nil } -// bgpClear initializes BGP peers and prefixes. +// bgpClear clears BGP peers and prefixes. func (n *common) bgpClear(config map[string]string) error { // Clear all peers. err := n.bgpClearPeers(config)