Skip to content

Commit

Permalink
fraud_detection: Improve accuracy for 'concurrent calls'
Browse files Browse the repository at this point in the history
Avoid using the DLGCB_FAILED callback, since it has no protection
against the "408 Request Timeout / 200 OK" race condition, and simply
use DLGCB_DESTROY in order to decrement the concurrent calls counter.

This fixes a bug where a "408 Timeout / 200 OK" call would cause a
concurrent calls value of 4294967295, due to an extra decrement.

Fixes #2079
  • Loading branch information
liviuchircu committed Aug 3, 2020
1 parent 57caa6c commit 35a6146
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions modules/dialog/dlg_cb.h
Expand Up @@ -116,7 +116,7 @@ typedef int (*register_dlgcb_f)(struct dlg_cell* dlg, int cb_types,
* care of generating proper BYEs for each participant)
* Registration: per-dialog, "dlg" must be given
* Trigger count: 0 - 1 times per dialog, exclusive with DLGCB_EXPIRED, and one
* of these two will always be called for a dialog
* of these two will always be called for an established dialog
*/
#define DLGCB_TERMINATED (1<<5)

Expand All @@ -129,7 +129,8 @@ typedef int (*register_dlgcb_f)(struct dlg_cell* dlg, int cb_types,
* Registration: per-dialog, "dlg" must be given
* Trigger count:
* * 0 - 1 times per dialog, exclusive with DLGCB_TERMINATED,
* and one of these two will always be called for a dialog
* and one of these two will always be called for an
* established dialog
*
* * if using replication sharing tags, this callback is only
* ran by the node that has the Active tag.
Expand Down
2 changes: 1 addition & 1 deletion modules/fraud_detection/fraud_detection.c
Expand Up @@ -431,7 +431,7 @@ static int check_fraud(struct sip_msg *msg, str *user, str *number, int *pid)
param->calldur_warn = thr->call_duration_thr.warning;
param->calldur_crit = thr->call_duration_thr.critical;

if (dlgb.register_dlgcb(dlgc, DLGCB_TERMINATED|DLGCB_FAILED|DLGCB_EXPIRED,
if (dlgb.register_dlgcb(dlgc, DLGCB_DESTROY,
dialog_terminate_CB, param, free_dialog_CB_param) != 0) {
LM_ERR("failed to register dialog terminated callback\n");
shm_free(param->number.s);
Expand Down

0 comments on commit 35a6146

Please sign in to comment.