From 0e55258d629c149c479e67c77c572039b02daff9 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Thu, 9 Jul 2026 18:29:22 +0200 Subject: [PATCH] BGP: Fix minor issues with send hold timer Fix division by zero during send hold time calculation when hold timer set to zero. Fix possible overflow in the send hold time calculation. Add minimum value for send hold time option as per RFC 9687 section 4.4. Reported-By: lzx0xf1@gmail.com Target: patch --- proto/bgp/bgp.c | 3 +++ proto/bgp/packets.c | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index bf801672e..9bbccc047 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -2954,6 +2954,9 @@ bgp_postconfig(struct proto_config *CF) if (cf->keepalive_time > (cf->hold_time / 2)) log(L_WARN "Keepalive time should be at most 1/2 of hold time"); + if ((cf->send_hold_time > 0) && (cf->send_hold_time < cf->hold_time)) + cf_error("Send hold time must be zero or at least hold time"); + if (cf->min_hold_time > cf->hold_time) cf_error("Min hold time (%u) exceeds hold time (%u)", cf->min_hold_time, cf->hold_time); diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index faa1558be..7990c8ffe 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -922,12 +922,14 @@ bgp_rx_open(struct bgp_conn *conn, byte *pkt, uint len) /* Compute effective hold and keepalive times */ uint hold_time = MIN(hold, p->cf->hold_time); + uint base_hold_time = p->cf->hold_time ?: 1; + uint keepalive_time = p->cf->keepalive_time ? - (p->cf->keepalive_time * hold_time / p->cf->hold_time) : + (p->cf->keepalive_time * hold_time / base_hold_time) : hold_time / 3; uint send_hold_time = (p->cf->send_hold_time >= 0) ? - (p->cf->send_hold_time * hold_time / p->cf->hold_time) : + ((u64) p->cf->send_hold_time * hold_time / base_hold_time) : 2 * hold_time; /* Keepalive time might be rounded down to zero */ -- 2.47.3