Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uac_registrant: avoid bulk re-registrations on large servers #701

Merged
merged 3 commits into from Dec 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions modules/uac_registrant/registrant.c
Expand Up @@ -824,6 +824,34 @@ static struct mi_root* mi_reg_list(struct mi_root* cmd, void* param)
return rpl_tree;
}

int run_compare_rec(void *e_data, void *data, void *r_data)
{
reg_record_t *old_rec = (reg_record_t*)e_data;
reg_record_t *new_rec = (reg_record_t*)data;

if ((old_rec->state == REGISTERED_STATE) &&
(str_strcmp(&old_rec->td.rem_uri, &new_rec->td.rem_uri) == 0)) {
memcpy(new_rec->td.id.call_id.s, old_rec->td.id.call_id.s,
new_rec->td.id.call_id.len);
memcpy(new_rec->td.id.loc_tag.s, old_rec->td.id.loc_tag.s,
new_rec->td.id.loc_tag.len);
new_rec->td.loc_seq.value = old_rec->td.loc_seq.value;
new_rec->last_register_sent = old_rec->last_register_sent;
new_rec->registration_timeout = old_rec->registration_timeout;
new_rec->state = old_rec->state;
}
return 0;
}

int run_find_same_rec(void *e_data, void *data, void *r_data)
{
reg_record_t *new_rec = (reg_record_t*)e_data;
int i = (int*)data;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ovidiusas could you review this a bit - while looking at the Travis log I noticed this warning, which actually may lead to a bug.

data is a pointer to an integer, that is passed to an integer. This may be a huge value, that is used below to index the reg_htable.

My guess is that the line should be int i = *(int *)data;, but please give it a look too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for spotting this out!


slinkedl_traverse(reg_htable[i].p_list, &run_compare_rec, new_rec, NULL);
return 0;
}

static struct mi_root* mi_reg_reload(struct mi_root* cmd, void* param)
{
struct mi_root *rpl_tree;
Expand Down Expand Up @@ -857,6 +885,9 @@ static struct mi_root* mi_reg_reload(struct mi_root* cmd, void* param)
/* Swap the lists: secondary will become primary */
for(i=0; i<reg_hsize; i++) {
lock_get(&reg_htable[i].lock);

slinkedl_traverse(reg_htable[i].s_list, &run_find_same_rec, &i, NULL);

slinkedl_list_destroy(reg_htable[i].p_list);
reg_htable[i].p_list = reg_htable[i].s_list;
reg_htable[i].s_list = NULL;
Expand Down