Module: kamailio Branch: master Commit: 5bf1a7ab30f14d989ab185585427c868429224fa URL: https://github.com/kamailio/kamailio/commit/5bf1a7ab30f14d989ab185585427c868...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2024-01-10T13:20:34+01:00
usrloc: option to randomize when keepalive is sent
- default adds a range from 0 to 20 seconds to ka_interval
---
Modified: src/modules/usrloc/ul_keepalive.c Modified: src/modules/usrloc/usrloc_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/5bf1a7ab30f14d989ab185585427c868... Patch: https://github.com/kamailio/kamailio/commit/5bf1a7ab30f14d989ab185585427c868...
---
diff --git a/src/modules/usrloc/ul_keepalive.c b/src/modules/usrloc/ul_keepalive.c index 435f84d7c71..eba6bec5c0d 100644 --- a/src/modules/usrloc/ul_keepalive.c +++ b/src/modules/usrloc/ul_keepalive.c @@ -44,6 +44,7 @@
extern int ul_keepalive_timeout; extern int ul_ka_interval; +extern int ul_ka_randomize;
static int ul_ka_send(str *kamsg, dest_info_t *kadst);
@@ -110,6 +111,7 @@ int ul_ka_urecord(urecord_t *ur) int i; struct timeval tv; time_t tnow = 0; + int ka_limit = 0;
if(ul_ka_mode == ULKA_NONE) { return 0; @@ -160,10 +162,12 @@ int ul_ka_urecord(urecord_t *ur) } } } - if(ul_ka_interval > 0 && uc->last_keepalive > 0 - && (uc->last_keepalive + ul_ka_interval) < tnow) { - /* not yet the time for keepalive */ - continue; + if(ul_ka_interval > 0 && uc->last_keepalive > 0) { + ka_limit = ul_ka_interval - (fastrand() % ul_ka_randomize); + if((uc->last_keepalive + ka_limit) < tnow) { + /* not yet the time for keepalive */ + continue; + } } if(uc->received.len > 0) { sdst = uc->received; diff --git a/src/modules/usrloc/usrloc_mod.c b/src/modules/usrloc/usrloc_mod.c index f493915a564..b14fe7273e1 100644 --- a/src/modules/usrloc/usrloc_mod.c +++ b/src/modules/usrloc/usrloc_mod.c @@ -128,6 +128,7 @@ str ul_ka_method = str_init("OPTIONS"); int ul_ka_mode = 0; int ul_ka_filter = 0; int ul_ka_interval = 40; +int ul_ka_randomize = 20; int ul_ka_loglevel = 255; str ul_ka_logmsg = str_init(" to-uri: [$tu] remote-addr: [$sas]"); pv_elem_t *ul_ka_logfmt = NULL; @@ -302,6 +303,7 @@ static param_export_t params[] = { {"ka_method", PARAM_STR, &ul_ka_method}, {"ka_filter", PARAM_INT, &ul_ka_filter}, {"ka_interval", PARAM_INT, &ul_ka_interval}, + {"ka_randomize", PARAM_INT, &ul_ka_randomize}, {"ka_timeout", PARAM_INT, &ul_keepalive_timeout}, {"ka_loglevel", PARAM_INT, &ul_ka_loglevel}, {"ka_logmsg", PARAM_STR, &ul_ka_logmsg},