[OpenSIPS-Devel] [OpenSIPS/opensips] 78e736: drouting: fix random GW selection when all weights...

Bogdan Andrei IANCU noreply at github.com
Wed Apr 22 11:27:13 UTC 2026


  Branch: refs/heads/master
  Home:   https://github.com/OpenSIPS/opensips
  Commit: 78e7361292d855be06db45fb039f54d6bfa6156d
      https://github.com/OpenSIPS/opensips/commit/78e7361292d855be06db45fb039f54d6bfa6156d
  Author: mattia <me at mattiacampagna.com>
  Date:   2026-04-08 (Wed, 08 Apr 2026)

  Changed paths:
    M modules/drouting/drouting.c

  Log Message:
  -----------
  drouting: fix random GW selection when all weights are zero

When weight_sum is 0 (all remaining gateways have weight 0), the code
was always selecting the first gateway (i = first) instead of randomly
picking one among the equally-weighted candidates.

Restore uniform random selection by computing:
  i = first + (unsigned int)((size - first) * ((double)rand() / ((double)RAND_MAX + 1.0)));

The +1.0 on RAND_MAX prevents the index from going out of bounds (i.e.
when rand() == RAND_MAX the result stays strictly below size-first).

Closes: https://github.com/OpenSIPS/opensips/issues/3863


  Commit: 61ff46b0058245fa96565c2f386eae676efb540d
      https://github.com/OpenSIPS/opensips/commit/61ff46b0058245fa96565c2f386eae676efb540d
  Author: Bogdan Andrei IANCU <bogdan at opensips.org>
  Date:   2026-04-22 (Wed, 22 Apr 2026)

  Changed paths:
    M modules/drouting/drouting.c

  Log Message:
  -----------
  Merge pull request #3867 from wlp2s0/fix/drouting-weight-zero-random-selection

drouting: fix random GW selection when all weights are zero


Compare: https://github.com/OpenSIPS/opensips/compare/f1fc0aa4062a...61ff46b00582

To unsubscribe from these emails, change your notification settings at https://github.com/OpenSIPS/opensips/settings/notifications



More information about the Devel mailing list