Skip to content

Commit

Permalink
mid_registrar: Restore "default_expires" and "max_expires"
Browse files Browse the repository at this point in the history
These registrar modparams were left unmaintained / ignored during development.
However, they are still valid and completely separate from
"outgoing_expires". The former two params control ingress expirations,
while the latter one controls egress expirations.

To match the newly introduced defaults, we also increase the default
"outgoing_expires" from 600s to 3600s.

(cherry picked from commit 67c3160)
  • Loading branch information
liviuchircu committed Jan 17, 2018
1 parent 478637e commit d3bcf48
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
16 changes: 15 additions & 1 deletion modules/mid_registrar/mid_registrar.c
Expand Up @@ -127,7 +127,7 @@ static int registrar_fixup(void** param, int param_no);
*/
enum mid_reg_mode reg_mode = MID_REG_MIRROR;

unsigned int outgoing_expires = 600;
unsigned int outgoing_expires = 3600;

#define is_matching_mode(v) (v == MATCH_BY_PARAM || v == MATCH_BY_USER)
#define matching_mode_str(v) (v == MATCH_BY_PARAM ? "by uri param" : "by user")
Expand Down Expand Up @@ -164,7 +164,9 @@ static cmd_export_t cmds[] = {

static param_export_t mod_params[] = {
{ "mode", INT_PARAM, &reg_mode },
{ "default_expires", INT_PARAM, &default_expires },
{ "min_expires", INT_PARAM, &min_expires },
{ "max_expires", INT_PARAM, &max_expires },
{ "default_q", INT_PARAM, &default_q },
{ "tcp_persistent_flag", INT_PARAM, &tcp_persistent_flag },
{ "tcp_persistent_flag", STR_PARAM, &tcp_persistent_flag_s },
Expand Down Expand Up @@ -306,6 +308,18 @@ static int mod_init(void)
LM_DBG("contact matching mode: '%s'\n", matching_mode_str(matching_mode));
}

if (min_expires > default_expires) {
LM_ERR("min_expires > default_expires! "
"Decreasing min_expires to %d...\n", default_expires);
min_expires = default_expires;
}

if (max_expires < default_expires) {
LM_ERR("max_expires < default_expires! "
"Increasing max_expires to %d...\n", default_expires);
max_expires = default_expires;
}

/* Normalize default_q parameter */
if (default_q != Q_UNSPECIFIED) {
if (default_q > MAX_Q) {
Expand Down
38 changes: 22 additions & 16 deletions modules/mid_registrar/save.c
Expand Up @@ -91,7 +91,7 @@ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, struct save
}
}

if ((*_e != 0) && ((*_e) < min_expires))
if ((*_e != 0) && min_expires && ((*_e) < min_expires))
*_e = min_expires;

if ((*_e != 0) && max_expires && ((*_e) > max_expires))
Expand All @@ -103,8 +103,15 @@ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, struct save
/* with the optionally added outgoing timeout extension
*
* @_e: output param (UNIX timestamp) - expiration time on the main registrar
* @behavior:
* if 0: the "outgoing_expires" modparam works as a minimal value
* (useful when forcing egress expirations)
*
* if !0: the "outgoing_expires" modparam works as a maximal value
* (useful when interpreting expirations of successful
* main registrar replies)
*/
void calc_ob_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, struct save_ctx *_sctx)
void calc_ob_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, int behavior)
{
if (!_ep || !_ep->body.len) {
*_e = get_expires_hf(_m);
Expand All @@ -115,21 +122,19 @@ void calc_ob_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, struct s
}

/* extend outgoing timeout, thus "throttling" heavy incoming traffic */
if (reg_mode != MID_REG_MIRROR && *_e > 0 && *_e < outgoing_expires)
*_e = outgoing_expires;
if (reg_mode != MID_REG_MIRROR && *_e > 0) {
if (behavior == 0) {
if (*_e < outgoing_expires)
*_e = outgoing_expires;
} else {
if (*_e > outgoing_expires)
*_e = outgoing_expires;
}
}

/* Convert to absolute value */
if (*_e > 0) *_e += get_act_time();

if (*_e > 0 && (*_e - get_act_time()) < min_expires) {
*_e = min_expires + get_act_time();
}

/* cutting timeout down to "max_expires" */
if (*_e > 0 && max_expires && ((*_e - get_act_time()) > max_expires)) {
*_e = max_expires + get_act_time();
}

LM_DBG("outgoing expires: %d\n", *_e);
}

Expand Down Expand Up @@ -296,7 +301,7 @@ static int overwrite_req_contacts(struct sip_msg *req,

new_username.s = int2str(ctid, &new_username.len);

calc_ob_contact_expires(req, c->expires, &expiry_tick, NULL);
calc_ob_contact_expires(req, c->expires, &expiry_tick, 0);
expires = expiry_tick == 0 ? 0 : expiry_tick - get_act_time();
ctmap = append_ct_mapping(&c->uri, &new_username, mri);
if (!ctmap) {
Expand Down Expand Up @@ -463,7 +468,7 @@ void overwrite_contact_expirations(struct sip_msg *req, struct mid_reg_info *mri

for (c = get_first_contact(req); c; c = get_next_contact(c)) {
calc_contact_expires(req, c->expires, &e, NULL);
calc_ob_contact_expires(req, c->expires, &expiry_tick, NULL);
calc_ob_contact_expires(req, c->expires, &expiry_tick, 0);
if (expiry_tick == 0)
new_expires = 0;
else
Expand Down Expand Up @@ -1179,7 +1184,8 @@ static inline int save_restore_rpl_contacts(struct sip_msg *req, struct sip_msg*
if (!_c)
goto update_usrloc;

calc_contact_expires(rpl, _c->expires, &e_out, NULL);
calc_ob_contact_expires(rpl, _c->expires, &e_out, 1);
e_out -= get_act_time();

LM_DBG(" >> REGISTER %ds ------- %ds 200 OK <<!\n", e, e_out);

Expand Down

0 comments on commit d3bcf48

Please sign in to comment.