Skip to content

Commit

Permalink
mid_registrar: Skip usrloc callbacks for foreign domains
Browse files Browse the repository at this point in the history
In case mid_registrar is used alongside registrar using separate domains
(location tables), then mid_registrar must not process any callbacks for
Contacts/AORs which it is not responsible for.

A similar logic should be added for registrar as well, however it
currently does not subscribe to any usrloc callbacks.

Fixes #2716

(cherry picked from commit 30cdbd6)

mid_registrar: Improve previous commit

Check the domain list for duplicates before appending a new one.

(cherry picked from commit c5d884e)
  • Loading branch information
liviuchircu committed Jan 25, 2022
1 parent 19f1541 commit 4541680
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
39 changes: 32 additions & 7 deletions modules/mid_registrar/mid_registrar.c
Expand Up @@ -58,6 +58,9 @@ struct usrloc_api ul;
struct tm_binds tmb;
struct sig_binds sig_api;

/* the list of domains (tables) used at opensips.cfg level by mid-registrar */
static str_list *mid_reg_domains;

/* specifically used to mutually exclude concurrent calls of the
* TMCB_RESPONSE_IN callback, upon SIP 200 OK retransmissions */
rw_lock_t *tm_retrans_lk;
Expand Down Expand Up @@ -211,25 +214,47 @@ struct module_exports exports= {
cfg_validate /* reload confirm function */
};

int is_mid_reg_domain(const str *dom)
{
str_list *it;

for (it = mid_reg_domains; it; it = it->next)
if (str_match(&it->s, dom))
return 1;

return 0;
}

/*! \brief
* Convert char* parameter to udomain_t* pointer
*/
static int domain_fixup(void** param)
{
udomain_t* d;
str dom_s;
str *dom_s = (str *)*param; /* CMD_PARAM_STATIC is always NT */
str_list *dom;

if (!is_mid_reg_domain(dom_s)) {
dom = pkg_malloc(sizeof *dom);
if (!dom) {
LM_ERR("oom\n");
return E_OUT_OF_MEM;
}
memset(dom, 0, sizeof *dom);

if (pkg_nt_str_dup(&dom->s, dom_s) < 0) {
pkg_free(dom);
return E_OUT_OF_MEM;
}

if (pkg_nt_str_dup(&dom_s, (str*)*param) < 0)
return E_OUT_OF_MEM;
add_last(dom, mid_reg_domains);
}

if (ul.register_udomain(dom_s.s, &d) < 0) {
if (ul.register_udomain(dom_s->s, &d) < 0) {
LM_ERR("failed to register domain\n");
pkg_free(dom_s.s);
return E_UNSPEC;
}

pkg_free(dom_s.s);

*param = (void*)d;
return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions modules/mid_registrar/mid_registrar.h
Expand Up @@ -115,6 +115,9 @@ struct mid_reg_info {
rw_lock_t *tm_lock;
};

/* check if a given domain belongs to mid-registrar or not */
int is_mid_reg_domain(const str *dom);

extern rw_lock_t *tm_retrans_lk;

extern int case_sensitive;
Expand Down
12 changes: 12 additions & 0 deletions modules/mid_registrar/ulcb.c
Expand Up @@ -227,6 +227,12 @@ void mid_reg_ct_event(void *binding, ul_cb_type type)
ucontact_t *c = (ucontact_t *)binding;
int_str_t *skip_dereg;

if (!is_mid_reg_domain(c->domain)) {
LM_DBG("skipping domain '%.*s', contact: '%.*s', cb: %d\n",
c->domain->len, c->domain->s, c->c.len, c->c.s, type);
return;
}

LM_DBG("Contact callback (%d): contact='%.*s'\n", type, c->c.len, c->c.s);

if (type & (UL_CONTACT_DELETE|UL_CONTACT_EXPIRE)
Expand All @@ -245,6 +251,12 @@ void mid_reg_aor_event(void *binding, ul_cb_type type)
urecord_t *r = (urecord_t *)binding;
int_str_t *skip_dereg;

if (!is_mid_reg_domain(r->domain)) {
LM_DBG("skipping domain '%.*s', aor: '%.*s', cb: %d\n",
r->domain->len, r->domain->s, r->aor.len, r->aor.s, type);
return;
}

LM_DBG("AOR callback (%d): contact='%.*s'\n", type,
r->aor.len, r->aor.s);

Expand Down

0 comments on commit 4541680

Please sign in to comment.