Module: sip-router Branch: master Commit: 806e967e2e39e0140b992719e10693b9c768d758 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=806e967e...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri Feb 21 21:07:43 2014 +0100
registrar: allow randomization of expire value coming from UA
- new parameter expire_range - requested in FS#249
---
modules/registrar/config.c | 3 +++ modules/registrar/config.h | 2 ++ modules/registrar/reg_mod.c | 7 +++++++ modules/registrar/sip_msg.c | 7 ++++++- 4 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/modules/registrar/config.c b/modules/registrar/config.c index f183511..c52b9a4 100644 --- a/modules/registrar/config.c +++ b/modules/registrar/config.c @@ -34,6 +34,7 @@ struct cfg_group_registrar default_registrar_cfg = { STR_NULL, /* realm_pref */ 3600, /* default_expires */ 0, /* default_expires_range */ + 0, /* expires_range */ 60, /* min_expires */ 0, /* max_expires */ 0, /* max_contacts */ @@ -52,6 +53,8 @@ cfg_def_t registrar_cfg_def[] = { "Contains number of second to expire if no expire hf or contact expire present" }, {"default_expires_range", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 100, 0, default_expires_range_update, "Percent from default_expires that will be used in generating the range for the expire interval"}, + {"expires_range", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 100, 0, expires_range_update, + "Percent from incoming expires that will be used in generating the range for the expire interval"}, {"min_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0, 0, "The minimum expires value of a Contact. Value 0 disables the checking. "}, {"max_expires", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 0, 0, max_expires_stats_update, diff --git a/modules/registrar/config.h b/modules/registrar/config.h index 496a14b..022b14d 100644 --- a/modules/registrar/config.h +++ b/modules/registrar/config.h @@ -30,6 +30,7 @@ struct cfg_group_registrar { str realm_pref; unsigned int default_expires; unsigned int default_expires_range; + unsigned int expires_range; unsigned int min_expires; unsigned int max_expires; unsigned int max_contacts; @@ -45,6 +46,7 @@ extern cfg_def_t registrar_cfg_def[];
extern void default_expires_stats_update(str*, str*); extern void default_expires_range_update(str*, str*); +extern void expires_range_update(str*, str*); extern void max_expires_stats_update(str*, str*);
#endif diff --git a/modules/registrar/reg_mod.c b/modules/registrar/reg_mod.c index 4539f67..0b32ce4 100644 --- a/modules/registrar/reg_mod.c +++ b/modules/registrar/reg_mod.c @@ -153,6 +153,7 @@ stat_var *max_expires_stat; stat_var *max_contacts_stat; stat_var *default_expire_stat; stat_var *default_expire_range_stat; +stat_var *expire_range_stat; /** SL API structure */ sl_api_t slb;
@@ -210,6 +211,7 @@ static cmd_export_t cmds[] = { static param_export_t params[] = { {"default_expires", INT_PARAM, &default_registrar_cfg.default_expires }, {"default_expires_range", INT_PARAM, &default_registrar_cfg.default_expires_range }, + {"expires_range", INT_PARAM, &default_registrar_cfg.expires_range }, {"default_q", INT_PARAM, &default_registrar_cfg.default_q }, {"append_branches", INT_PARAM, &default_registrar_cfg.append_branches }, {"case_sensitive", INT_PARAM, &default_registrar_cfg.case_sensitive }, @@ -244,6 +246,7 @@ stat_export_t mod_stats[] = { {"max_contacts", STAT_NO_RESET, &max_contacts_stat }, {"default_expire", STAT_NO_RESET, &default_expire_stat }, {"default_expires_range", STAT_NO_RESET, &default_expire_range_stat }, + {"expires_range", STAT_NO_RESET, &expire_range_stat }, {"accepted_regs", 0, &accepted_registrations }, {"rejected_regs", 0, &rejected_registrations }, {0, 0, 0} @@ -709,3 +712,7 @@ void max_expires_stats_update(str* gname, str* name){ void default_expires_range_update(str* gname, str* name){ update_stat(default_expire_range_stat, cfg_get(registrar, registrar_cfg, default_expires_range)); } + +void expires_range_update(str* gname, str* name){ + update_stat(expire_range_stat, cfg_get(registrar, registrar_cfg, expires_range)); +} diff --git a/modules/registrar/sip_msg.c b/modules/registrar/sip_msg.c index a02b050..7ce9c59 100644 --- a/modules/registrar/sip_msg.c +++ b/modules/registrar/sip_msg.c @@ -67,11 +67,16 @@ static inline int get_expire_val(void) static inline int get_expires_hf(struct sip_msg* _m) { exp_body_t* p; + int range; if (_m->expires) { p = (exp_body_t*)_m->expires->parsed; if (p->valid) { if (p->val != 0) { - return p->val + act_time; + range = cfg_get(registrar, registrar_cfg, default_expires_range); + if(likely(range==0)) + return p->val + act_time; + return p->val + act_time - (float)range/100 * p->val + + ((float)(rand()%100)/100) * ((float)range/100 * p->val); } else return 0; } else { return act_time + get_expire_val();
On 21.02.2014 21:14, Daniel-Constantin Mierla wrote:
Module: sip-router Branch: master Commit: 806e967e2e39e0140b992719e10693b9c768d758 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=806e967e...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri Feb 21 21:07:43 2014 +0100
registrar: allow randomization of expire value coming from UA
- new parameter expire_range
- requested in FS#249
Hi,
can you merge this and 5961824bdd52cb71f9b7db4b24d5e136f3110444 to the 4.1-branch?
Thanks!
Øyvind
On 4 Mar 2014 19:18, "Øyvind Kolbu" oyvind.kolbu@usit.uio.no wrote:
can you merge this and 5961824bdd52cb71f9b7db4b24d5e136f3110444 to the 4.1-branch?
No. This is a stable branch and no new features will be backported, only fixes.
Cheers, Victor
On 04.03.2014 19:45, Victor Seva wrote:
On 4 Mar 2014 19:18, "Øyvind Kolbu" <oyvind.kolbu@usit.uio.no mailto:oyvind.kolbu@usit.uio.no> wrote:
can you merge this and 5961824bdd52cb71f9b7db4b24d5e136f3110444 to the 4.1-branch?
No. This is a stable branch and no new features will be backported, only fixes.
OK, will patch locally. Thanks for the quick reply.
On 21.02.2014 21:14, Daniel-Constantin Mierla wrote:
Module: sip-router Branch: master Commit: 806e967e2e39e0140b992719e10693b9c768d758 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=806e967e...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri Feb 21 21:07:43 2014 +0100
registrar: allow randomization of expire value coming from UA
- new parameter expire_range
- requested in FS#249
[...]
@@ -52,6 +53,8 @@ cfg_def_t registrar_cfg_def[] = { "Contains number of second to expire if no expire hf or contact expire present" }, {"default_expires_range", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 100, 0, default_expires_range_update, "Percent from default_expires that will be used in generating the range for the expire interval"},
- {"expires_range", CFG_VAR_INT | CFG_CB_ONLY_ONCE, 0, 100, 0, expires_range_update,
"Percent from incoming expires that will be used in generating the range for the expire interval"},
[...]
diff --git a/modules/registrar/sip_msg.c b/modules/registrar/sip_msg.c index a02b050..7ce9c59 100644 --- a/modules/registrar/sip_msg.c +++ b/modules/registrar/sip_msg.c @@ -67,11 +67,16 @@ static inline int get_expire_val(void)
return p->val + act_time;
range = cfg_get(registrar, registrar_cfg, default_expires_range);
if(likely(range==0))
return p->val + act_time;
return p->val + act_time - (float)range/100 * p->val
+ ((float)(rand()%100)/100) * ((float)range/100 * p->val);
Wrong variable fetched, should have been:
range = cfg_get(registrar, registrar_cfg, expires_range);
Also for clients who do not use the Expires header, the above logic does not work. E.g. a lot of Cisco devices sends like this:
Contact: "foo" sip:12345@10.10.1.234:5060;expires=3600.
All my Cisco devices got a similar Contact with expires=3600 back.