Skip to content

Commit

Permalink
dialog: don't run TERMINATED and EXPIRED DLGCBs when replication tag …
Browse files Browse the repository at this point in the history
…is backup
  • Loading branch information
rvlad-patrascu committed Mar 13, 2018
1 parent afa4c77 commit 71a11a1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
18 changes: 10 additions & 8 deletions modules/dialog/dlg_handlers.c
Expand Up @@ -1422,7 +1422,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
struct dlg_entry *d_entry;
str *msg_cseq;
char *final_cseq;
int replicate_events = 1;
int is_active = 1;

/* as this callback is triggered from loose_route, which can be
accidentaly called more than once from script, we need to be sure
Expand Down Expand Up @@ -1523,7 +1523,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
}

if (dialog_repl_cluster)
replicate_events = get_repltag_state(dlg) != REPLTAG_STATE_BACKUP;
is_active = get_repltag_state(dlg) != REPLTAG_STATE_BACKUP;

/* run state machine */
switch ( req->first_line.u.request.method_value ) {
Expand All @@ -1538,7 +1538,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
}

next_state_dlg(dlg, event, dir, &old_state, &new_state, &unref, dst_leg,
replicate_events);
is_active);

/* set current dialog - it will keep a ref! */
ctx_dialog_set(dlg);
Expand Down Expand Up @@ -1627,7 +1627,8 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
}

/* dialog terminated (BYE) */
run_dlg_callbacks( DLGCB_TERMINATED, dlg, req, dir, NULL, 0);
if (is_active)
run_dlg_callbacks( DLGCB_TERMINATED, dlg, req, dir, NULL, 0);

/* delete the dialog from DB */
if (should_remove_dlg_db())
Expand Down Expand Up @@ -1752,7 +1753,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
if ( dlg_db_mode==DB_MODE_REALTIME )
update_dialog_dbinfo(dlg);

if (dialog_repl_cluster && replicate_events)
if (dialog_repl_cluster && is_active)
replicate_dialog_updated(dlg);
}
} else {
Expand Down Expand Up @@ -1865,7 +1866,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
if(dlg_db_mode == DB_MODE_REALTIME)
update_dialog_dbinfo(dlg);

if (dialog_repl_cluster && replicate_events)
if (dialog_repl_cluster && is_active)
replicate_dialog_updated(dlg);

if (dlg->flags & DLG_FLAG_PING_CALLER ||
Expand Down Expand Up @@ -1971,8 +1972,9 @@ void dlg_ontimeout(struct dlg_tl *tl)

/* dialog timeout */
if (push_new_processing_context(dlg, &old_ctx, &new_ctx, &fake_msg)==0) {
run_dlg_callbacks(DLGCB_EXPIRED, dlg, fake_msg,
DLG_DIR_NONE, NULL, 0);
if (do_expire_actions)
run_dlg_callbacks(DLGCB_EXPIRED, dlg, fake_msg,
DLG_DIR_NONE, NULL, 0);

if (current_processing_ctx == NULL)
*new_ctx = NULL;
Expand Down
14 changes: 8 additions & 6 deletions modules/dialog/dlg_req_within.c
Expand Up @@ -217,7 +217,7 @@ dlg_t * build_dialog_info(struct dlg_cell * cell, int dst_leg, int src_leg,char


static void dual_bye_event(struct dlg_cell* dlg, struct sip_msg *req,
int extra_unref, int replicate_events)
int extra_unref, int is_active)
{
int event, old_state, new_state, unref, ret;
struct sip_msg *fake_msg=NULL;
Expand All @@ -226,7 +226,7 @@ static void dual_bye_event(struct dlg_cell* dlg, struct sip_msg *req,

event = DLG_EVENT_REQBYE;
next_state_dlg(dlg, event, DLG_DIR_DOWNSTREAM, &old_state, &new_state,
&unref, dlg->legs_no[DLG_LEG_200OK], replicate_events);
&unref, dlg->legs_no[DLG_LEG_200OK], is_active);
unref += extra_unref;

if(new_state == DLG_STATE_DELETED && old_state != DLG_STATE_DELETED){
Expand Down Expand Up @@ -265,8 +265,9 @@ static void dual_bye_event(struct dlg_cell* dlg, struct sip_msg *req,
/* set new msg & processing context */
if (push_new_processing_context( dlg, &old_ctx, &new_ctx, &fake_msg)==0) {
/* dialog terminated (BYE) */
run_dlg_callbacks( DLGCB_TERMINATED, dlg, fake_msg,
DLG_DIR_NONE, NULL, 0);
if (is_active)
run_dlg_callbacks( DLGCB_TERMINATED, dlg, fake_msg,
DLG_DIR_NONE, NULL, 0);
/* reset the processing context */
if (current_processing_ctx == NULL)
*new_ctx = NULL;
Expand All @@ -277,8 +278,9 @@ static void dual_bye_event(struct dlg_cell* dlg, struct sip_msg *req,
} else {
/* we should have the msg and context from upper levels */
/* dialog terminated (BYE) */
run_dlg_callbacks( DLGCB_TERMINATED, dlg, req,
DLG_DIR_NONE, NULL, 0);
if (is_active)
run_dlg_callbacks( DLGCB_TERMINATED, dlg, req,
DLG_DIR_NONE, NULL, 0);
}

LM_DBG("first final reply\n");
Expand Down
2 changes: 1 addition & 1 deletion modules/fraud_detection/fraud_detection.c
Expand Up @@ -442,7 +442,7 @@ static int check_fraud(struct sip_msg *msg, char *_user, char *_number, char *_p
param->data_rev = frd_data_rev;

if (dlgb.register_dlgcb(dlgc, DLGCB_TERMINATED|DLGCB_FAILED|DLGCB_EXPIRED,
dialog_terminate_CB, param, NULL) != 0) {
dialog_terminate_CB, param, free_dialog_CB_param) != 0) {
LM_ERR("failed to register dialog terminated callback\n");
lock_stop_read(frd_data_lock);
shm_free(param->number.s);
Expand Down
9 changes: 7 additions & 2 deletions modules/fraud_detection/frd_events.c
Expand Up @@ -168,7 +168,12 @@ void dialog_terminate_CB(struct dlg_cell *dlgc, int type,
lock_get(&frdparam->stats->lock);
--frdparam->stats->stats.concurrent_calls;
lock_release(&frdparam->stats->lock);
}

void free_dialog_CB_param(void *param)
{
frd_dlg_param *p = (frd_dlg_param *)param;

shm_free(frdparam->number.s);
shm_free(frdparam);
shm_free(p->number.s);
shm_free(p);
}
2 changes: 1 addition & 1 deletion modules/fraud_detection/frd_events.h
Expand Up @@ -50,6 +50,6 @@ typedef struct {

void dialog_terminate_CB(struct dlg_cell *dlgc, int type,
struct dlg_cb_params *params);

void free_dialog_CB_param(void *param);

#endif
15 changes: 11 additions & 4 deletions modules/sngtc/sngtc.c
Expand Up @@ -266,13 +266,17 @@ void sngtc_dlg_terminated(struct dlg_cell *dlg, int type,
{
str info_ptr;
struct sngtc_info *info;
int rc;

LM_DBG("freeing the sdp buffer\n");
rc = dlg_binds.fetch_dlg_value(dlg, &dlg_key_sngtc_info, &info_ptr, 0);

if (dlg_binds.fetch_dlg_value(dlg, &dlg_key_sngtc_info, &info_ptr, 0) != 0) {
if (rc == -1) {
LM_ERR("failed to fetch caller sdp\n");
return;
}
} else if (rc == -2)
return;

LM_DBG("freeing the sdp buffer\n");

info = *(struct sngtc_info **)info_ptr.s;
LM_DBG("Info ptr: %p\n", info);
Expand All @@ -285,6 +289,9 @@ void sngtc_dlg_terminated(struct dlg_cell *dlg, int type,
shm_free(info->modified_caller_sdp.s);

shm_free(info);

if (dlg_binds.store_dlg_value(dlg, &dlg_key_sngtc_info, NULL) < 0)
LM_ERR("failed to clear dlg val with caller sdp\n");
}

static int mod_init(void)
Expand Down Expand Up @@ -538,7 +545,7 @@ static int sngtc_offer(struct sip_msg *msg)

/* register a callback to free the above */
if (dlg_binds.register_dlgcb(dlg,
DLGCB_EXPIRED|DLGCB_FAILED|DLGCB_TERMINATED,
DLGCB_EXPIRED|DLGCB_FAILED|DLGCB_TERMINATED|DLGCB_DESTROY,
sngtc_dlg_terminated, NULL, NULL) != 0) {

LM_ERR("failed to register dialog callback\n");
Expand Down

0 comments on commit 71a11a1

Please sign in to comment.