Skip to content

virtual router: Apply BGP peer changes with frr-reload and add a minimum hold time - #14841

Open
MitchDrage wants to merge 6 commits into
apache:mainfrom
MitchDrage:bgp-frr-reload
Open

MitchDrage wants to merge 6 commits into
apache:mainfrom
MitchDrage:bgp-frr-reload

Conversation

@MitchDrage

@MitchDrage MitchDrage commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a BGP peer changes, the virtual router restarts FRR, which drops every BGP session on the router. This PR applies the change with frr-reload.py, so only the changed neighbours are touched. It prepares the router for #14687.

  • CsBgpPeers reloads FRR once bgpd is running. It restarts FRR only to start bgpd, or when frr-reload.py is missing or fails. The rendered file states ebgp-requires-policy, network import-check and the kernel's current forwarding setting, so a reload never changes them.
  • New account setting routed.bgp.min.holdtime (default 3) renders bgp minimum-holdtime, which applies to every peer on the router. BGP allows a hold time of 0 or 3 and up, so the default refuses only peers that turn keepalives off with hold time 0. Setting it to 0 turns the minimum off. Values outside 0-65535 are refused when the setting is saved.
  • Router diagnostics gain the FRR log and a copy of frr.conf with peer passwords masked. The router version health check prints which FRR tools the template has, for later use by BGP on VPC private gateways so tenants can peer their own routers with the VR #14687.
  • The systemvm template installs frr-pythontools, which ships frr-reload.py.

Please note, this needs a new systemvm template with frr-pythontools installed. Routers on an older template will continue to restart FRR, which affects all peers at once when one neighbour changes.

After upgrading, a router with Dynamic routing refuses a peer that proposes hold time 0. Set routed.bgp.min.holdtime to 0 for an account to keep accepting it.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Screenshots (if appropriate):

N/A

How Has This Been Tested?

  • New unit tests: TestCsBgpPeersFrr, TestRouterVersionCheck, SetBgpPeersMinHoldtimeTest, CommandSetupHelperBgpPeersMinHoldtimeTest, and DiagnosticsFilesListFrrTest. TestCsBgpPeers and its fixture are updated for the new lines, BGPServiceImplTest covers the new setting, and ConfigurationManagerImplTest covers its range.
  • On a KVM ROUTED VPC with Dynamic routing (4.22.1.1 management server, these router scripts, frr-pythontools installed), adding and then removing a second peer went through frr-reload.py. bgpd's pid stayed the same and the first peer's session stayed up. On the stock router the same change restarted bgpd and reset the session.
  • Without frr-pythontools the router restarted FRR and applied the new file. The router version health check showed frrreload=yes bfdd=yes frrmajor=8, and the masked copy hid the peer password.
  • On a 4.22.1.1 KVM lab with these changes, the hold-time setting reached the router end to end. With the minimum at 3, a peer asking for hold time 0 was refused with Unacceptable Hold Time. Set to 0, the bgp minimum-holdtime line disappeared and the session came up. After a router stop and start, peer changes still went through frr-reload.py.
  • The server, core and engine-schema tests and checkstyle pass.

How did you try to break this feature and the system with this change?

  • Removed frr-reload.py, or made it fail: the router falls back to a restart and still applies the config.
  • Configured the first peer on a router with bgpd off: FRR restarts to start bgpd.
  • Set the minimum hold time to 0: no bgp minimum-holdtime line is rendered, since FRR accepts only 1-65535 there. Values outside 0-65535 are refused.
  • Used a peer password with a line break: the diagnostics copy masks all of it.

/**
* Settings for BGP sessions on virtual routers.
*/
public final class TenantBgpConfig {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use BGPService

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I've moved the setting onto BGPService.

# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
frr version 8.4.4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'll remove it. I started my testing on a 4.22 template, which still writes frr version 6.0, so I bumped it to 8.4.4.
#9964 already dropped the header on main and added route-maps to every peer, and pinning 8.4.4 would just freeze the defaults again.
The two settings the version line was there to protect, ebgp-requires-policy and network import-check, are set explicitly by this PR anyway, so dropping the version number has no ill effect.

hostname r-1001-VM
service integrated-vtysh-config
ip forwarding
ipv6 forwarding

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these needed ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they're needed once changes go through frr-reload. zebra shows the kernel's forwarding state in the running config, so an IPv4-only router has no ipv6 forwarding there, and frr-reload deletes any running line the file doesn't state.
When I reloaded main's file unchanged on 8.4.4, net.ipv6.conf.all.forwarding went from 0 to 1.
The router already wrote the IPv6 line from the kernel's setting, and I've changed it to do the same for IPv4.
This fixture is just the dual-stack snapshot for test_full_frr_conf. The behaviour itself is covered by two new tests in TestCsBgpPeersFrr, test_operator_states_forwarding_off_from_kernel and ..._on_from_kernel.

router bgp 64512
bgp router-id 100.64.0.10
bgp ebgp-requires-policy
bgp network import-check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 2 are enabled by default, no harmless to explicitly set both

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, both are on by default in 8.4.4.
I'd like to keep these explicit since this PR now drops the version line, so these two settings don't depend on the defaults of whatever FRR version the template ships.
The route-maps from #9964 keep peers working with ebgp-requires-policy on, and import-check makes sure a tier is only announced while its route exists.


public static final ConfigKey<Integer> MinHoldtime = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class,
"vpc.gateway.bgp.min.holdtime",
"3",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 3 too small ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 only stops a peer from negotiating hold time 0, which switches failure detection off. It doesn't set the hold time itself: each session still negotiates the lower of the two proposals, and per-peer timers come in the next PR. The setting is in this PR to keep that next one smaller.
I didn't go higher because FRR applies the setting to the whole router, so e.g. 9 would drop existing operator upstream sessions that already run fast timers on their side. An operator can raise it, as long as it stays at or below their upstream hold time.
I tested it on 8.4.4: at 3, peers at 1/3 and 10/30 came up with hold time 3 and 30, and a peer asking for 0 was refused with Unacceptable Hold Time. I also load tested 4 peers at 3/9 with BFD at 300 ms on a 1-CPU router, with no dropped sessions up to 1,000 routes per peer, so I don't see a capacity issue at those timers.

*/
public final class TenantBgpConfig {

public static final ConfigKey<Integer> MinHoldtime = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be good to add it as an account setting or network (if possible) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea to me, that will allow specific accounts with unique requirements to override the default.
I've made it an account setting, read from the router's owning account, so it also covers peers dedicated to an account. Accounts without their own value use the global default of 3.

"The lowest BGP hold time, in seconds, that a virtual router accepts. "
+ "It applies to every BGP peer on the router. "
+ "A session that negotiates a lower hold time, including 0, is refused.",
true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use vpc.gateway ?
will it affect routed networks other than routed vpcs ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it applies to every router with Dynamic routing, isolated routed networks included.
I've renamed it to routed.bgp.min.holdtime to match the other routed settings.

"/etc/dnsmasq.conf,/etc/dhcphosts.txt,/etc/dhcpopts.txt,/etc/dnsmasq.d/cloud.conf,/etc/dnsmasq-resolv.conf,/var/lib/misc/dnsmasq.leases,/var/log/dnsmasq.log," +
"/etc/hosts,/etc/resolv.conf,/etc/haproxy/haproxy.cfg,/var/log/haproxy.log,/etc/ipsec.d/l2tp.conf,/var/log/cloud.log," +
"/var/log/routerServiceMonitor.log,/var/log/daemon.log",
"/var/log/routerServiceMonitor.log,/var/log/daemon.log,/var/log/frr/frr.log,/var/cache/cloud/frr.conf.masked",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frr.conf contains some sensitive info, not sure if good to add here by default

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only a masked copy, /var/cache/cloud/frr.conf.masked.
CsBgpPeers writes it each time it renders frr.conf, using the new CsFrrConfig.mask_passwords, which replaces every peer password with ; the plain frr.conf never leaves the router.
What's left is peer IPs, ASNs and route-maps, which admins can already see, and getDiagnosticsData is root-admin only.

Note however, while checking this I found that CsBgpPeers already logs the whole bgppeers databag to cloud.log, passwords included, and cloud.log is in the default bundle. Would you like me to raise an issue on this against 4.20?

*/
public final class TenantBgpConfig {

public static final ConfigKey<Integer> MinHoldtime = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could also become a BgpPeer setting, similar to EBGP_MultiHop
it might be more simple

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at that because that's what I'm familiar with from Cisco's BGP syntax, but FRR only supports the minimum hold time router-wide; there's no per-neighbour form.
For info, the next PR will add per-peer timers for tenant private-gateway peers.

haveged \
radvd \
frr \
frr frr-pythontools \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just note, this requires the rebuild of systemvm template

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, noted in the description and I can see that the tagging has picked that up too which is nice.
I've kept routers on older templates working: CsBgpPeers checks for /usr/lib/frr/frr-reload.py, and when it's missing it restarts FRR as it does today.
Additionally, the router version health check will also report frrreload=yes|no, so operators can see which routers still need the new template. I tested the fallback on a 4.22 router without frr-pythontools.

@wido
wido self-requested a review November 24, 2026 12:21

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants