Skip to content

Commit

Permalink
mid-registrar: Avoid generating De-REGISTER from Passive node
Browse files Browse the repository at this point in the history
    * enhance the usrloc API with a contact ownership checking function
    * mid-registrar now only generates De-REGISTER for owned contacts

Credits to Giovanni Maruzzelli for detailed reporting and instructions
on how to reproduce this issue!

Fixes #2559

(cherry picked from commit 4128f67)
  • Loading branch information
liviuchircu committed Aug 13, 2021
1 parent 04259f6 commit e8494eb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
17 changes: 8 additions & 9 deletions modules/mid_registrar/ulcb.c
Expand Up @@ -229,15 +229,14 @@ void mid_reg_ct_event(void *binding, ul_cb_type type)

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

if (type & (UL_CONTACT_DELETE|UL_CONTACT_EXPIRE)) {
if (reg_mode == MID_REG_THROTTLE_CT) {
skip_dereg = ul.get_ucontact_key(c, &ul_key_skip_dereg);
if (skip_dereg && skip_dereg->i == 1)
return;

if (unregister_contact(c) != 0)
LM_ERR("failed to unregister contact\n");
}
if (type & (UL_CONTACT_DELETE|UL_CONTACT_EXPIRE)
&& reg_mode == MID_REG_THROTTLE_CT) {
skip_dereg = ul.get_ucontact_key(c, &ul_key_skip_dereg);
if ((skip_dereg && skip_dereg->i == 1) || !ul.is_my_ucontact(c))
return;

if (unregister_contact(c) != 0)
LM_ERR("failed to unregister contact\n");
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/usrloc/dlist.c
Expand Up @@ -716,7 +716,7 @@ get_domain_mem_ucontacts(udomain_t *d,void *buf, int *len, unsigned int flags,
/* a lot slower than fetching all tags before the outermost
* loop, but at least we have proper responsiveness to tag
* switches! */
if (pinging_mode == PMD_OWNERSHIP && !is_my_contact(c))
if (pinging_mode == PMD_OWNERSHIP && !_is_my_ucontact(c))
continue;

needed = (int)((c->received.s?
Expand Down
5 changes: 5 additions & 0 deletions modules/usrloc/ucontact.c
Expand Up @@ -1045,3 +1045,8 @@ int_str_t *put_ucontact_key(ucontact_t* _ct, const str* _key,
{
return kv_put(_ct->kv_storage, _key, _val);
}

int is_my_ucontact(ucontact_t *c)
{
return _is_my_ucontact(c);
}
1 change: 1 addition & 0 deletions modules/usrloc/ucontact.h
Expand Up @@ -199,6 +199,7 @@ typedef struct {

int ucontact_coords_cmp(ucontact_coords a, ucontact_coords b);
void free_ucontact_coords(ucontact_coords coords);
int is_my_ucontact(ucontact_t *c);

/*! \brief
* ancient time used for marking the contacts forced to expired
Expand Down
2 changes: 1 addition & 1 deletion modules/usrloc/ul_cluster.h
Expand Up @@ -50,7 +50,7 @@ extern str ul_shtag_key;
extern str contact_repl_cap;

int ul_init_cluster(void);
#define is_my_contact(__ct) \
#define _is_my_ucontact(__ct) \
(!__ct->shtag.s || \
clusterer_api.shtag_get(&__ct->shtag, location_cluster) \
== SHTAG_STATE_ACTIVE)
Expand Down
1 change: 1 addition & 0 deletions modules/usrloc/usrloc.c
Expand Up @@ -78,6 +78,7 @@ int bind_usrloc(usrloc_api_t* api)
api->delete_ucontact_from_coords = delete_ucontact_from_coords;
api->ucontact_coords_cmp = ucontact_coords_cmp;
api->free_ucontact_coords = free_ucontact_coords;
api->is_my_ucontact = is_my_ucontact;
api->next_contact_id = next_contact_id;
api->update_sipping_latency = update_sipping_latency;
api->raise_ev_ct_refresh = ul_raise_ct_refresh_event;
Expand Down
9 changes: 9 additions & 0 deletions modules/usrloc/usrloc.h
Expand Up @@ -326,6 +326,15 @@ typedef struct usrloc_api {
*/
void (*free_ucontact_coords) (ucontact_coords coords);

/**
* Check if an ucontact is logically owned by the current OpenSIPS node.
* Always returns true in single node setups or if a contact does not have
* an ownership tag attached.
*
* Return: 1 (true), 0 (false)
*/
int (*is_my_ucontact) (ucontact_t *c);

/**
* Generate the next contact ID of a given record. Returns a different
* contact ID on each new call, rotating across CLABEL_MASK values.
Expand Down

0 comments on commit e8494eb

Please sign in to comment.