From 3d6f855d3482cd90d15c758bc9f6bf3a44e3689e Mon Sep 17 00:00:00 2001 From: evgeny Date: Fri, 23 Oct 2026 00:17:14 +0200 Subject: [PATCH] Keep BBR probing and aggregation counters dimensionally consistent in bytes --- src/transport_layer/etcp_bbr.c | 19 +++++++++++++------ src/transport_layer/etcp_bbr.h | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/transport_layer/etcp_bbr.c b/src/transport_layer/etcp_bbr.c index 5b486b4f..f6b8a33a 100644 --- a/src/transport_layer/etcp_bbr.c +++ b/src/transport_layer/etcp_bbr.c @@ -32,9 +32,9 @@ static int bbr_full_bw_reached(const struct bbr* bbr) return bbr->full_bw_reached; } -static uint16_t bbr_extra_acked(const struct bbr* bbr) +static uint32_t bbr_extra_acked(const struct bbr* bbr) { - return (uint16_t)(bbr->extra_acked[0] > bbr->extra_acked[1] ? + return (uint32_t)(bbr->extra_acked[0] > bbr->extra_acked[1] ? bbr->extra_acked[0] : bbr->extra_acked[1]); } @@ -68,8 +68,10 @@ static uint32_t bbr_bdp(const struct bbr* bbr, uint32_t bw, int gain, uint32_t m static uint32_t bbr_quantization_budget(struct bbr* bbr, uint32_t cwnd, uint32_t mss) { cwnd = (uint32_t)(cwnd > BBR_CWND_MIN_TARGET * mss ? cwnd : BBR_CWND_MIN_TARGET * mss); - if (bbr->mode == BBR_PROBE_BW && bbr->cycle_idx == BBR_BW_PROBE_UP) - cwnd += 2; + if (bbr->mode == BBR_PROBE_BW && bbr->cycle_idx == BBR_BW_PROBE_UP) { + uint64_t budget = (uint64_t)cwnd + 2ULL * mss; + cwnd = budget > UINT32_MAX ? UINT32_MAX : (uint32_t)budget; + } return cwnd; } @@ -453,7 +455,7 @@ static void bbr_adapt_upper_bounds(struct bbr* bbr, const struct bbr_rate_sample static int bbr_is_reno_coexistence_probe_time(struct bbr* bbr, uint32_t cwnd, uint32_t mss) { - uint32_t rounds = bbr_target_inflight(bbr, cwnd, mss); + uint32_t rounds = bbr_target_inflight(bbr, cwnd, mss) / mss; if (rounds > BBR_BW_PROBE_MAX_ROUNDS) rounds = BBR_BW_PROBE_MAX_ROUNDS; return bbr->rounds_since_probe >= rounds; @@ -708,7 +710,7 @@ static void bbr_update_ack_aggregation(struct bbr* bbr, const struct bbr_rate_sa extra_acked = bbr->ack_epoch_acked - expected_acked; extra_acked = (uint32_t)(extra_acked < cwnd ? extra_acked : cwnd); if (extra_acked > bbr->extra_acked[bbr->extra_acked_win_idx]) - bbr->extra_acked[bbr->extra_acked_win_idx] = (uint16_t)extra_acked; + bbr->extra_acked[bbr->extra_acked_win_idx] = extra_acked; } static void bbr_init_pacing_rate_from_rtt(struct bbr* bbr, uint32_t cwnd, uint32_t* pacing_rate_out) @@ -881,6 +883,11 @@ void bbr_main(struct bbr* bbr, const struct bbr_rate_sample* rs, uint32_t* cwnd_out, uint32_t* pacing_rate_out, uint32_t mss, uint32_t inflight_bytes, int is_cwnd_limited) { + if (!bbr || !rs || !cwnd_out || !pacing_rate_out || !mss) { + DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "BBR invalid arguments: model=%p sample=%p cwnd=%p pacing=%p mss=%u", + (void*)bbr, (const void*)rs, (void*)cwnd_out, (void*)pacing_rate_out, mss); + return; + } uint32_t cwnd = *cwnd_out; uint32_t sample_bw, bw; int update_model = 1; diff --git a/src/transport_layer/etcp_bbr.h b/src/transport_layer/etcp_bbr.h index 5e8bb07c..88b132c6 100644 --- a/src/transport_layer/etcp_bbr.h +++ b/src/transport_layer/etcp_bbr.h @@ -90,7 +90,7 @@ struct bbr { uint64_t probe_rtt_min_stamp_tb; uint64_t probe_rtt_done_stamp_tb; uint8_t probe_rtt_round_done : 1; - uint16_t extra_acked[2]; + uint32_t extra_acked[2]; // избыточно подтверждённые байты, без усечения на 64KiB uint32_t ack_epoch_acked; uint64_t ack_epoch_mstamp_tb; uint8_t extra_acked_win_idx : 1;