Module: sip-router
Branch: master
Commit: 806e967e2e39e0140b992719e10693b9c768d758
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=806e967…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)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();