]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
BGP: Fix minor issues with send hold timer master oz-test
authorOndrej Zajicek <santiago@crfreenet.org>
Thu, 9 Jul 2026 16:29:22 +0000 (18:29 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Thu, 9 Jul 2026 16:29:22 +0000 (18:29 +0200)
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
proto/bgp/packets.c

index bf801672e84f5f82d57af99fe51aaa3adbd8585a..9bbccc047bc1d020e02fa4c33dea2b661342c798 100644 (file)
@@ -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);
index faa1558be974b5f32bdf193e79c0b35c572d5a5c..7990c8ffe952baa8d64205dfe8be04f1ae197600 100644 (file)
@@ -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 */