Skip to content

Commit

Permalink
fraud_detection: Fix the 'call duration' events
Browse files Browse the repository at this point in the history
The 'call duration' events were not being raised anymore since commit
a0fcf85, due to the mismatching callback type check in
dialog_terminate_CB().

Also rework commit a0fcf85, where instead of switching the
decrement operation on the DLGCB_DESTROY callback (to guarantee it only
gets called one time), we just store and use a boolean marker, thus
achieving the same effect but while using the optimal callbacks!
  • Loading branch information
liviuchircu committed Feb 10, 2022
1 parent 6118412 commit 7aa272a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/fraud_detection/fraud_detection.c
Expand Up @@ -434,7 +434,7 @@ static int check_fraud(struct sip_msg *msg, str *user, str *number, int *pid)
param->calldur_crit = thr->call_duration_thr.critical;
param->interval_id = se->interval_id;

if (dlgb.register_dlgcb(dlgc, DLGCB_DESTROY,
if (dlgb.register_dlgcb(dlgc, DLGCB_FAILED|DLGCB_TERMINATED|DLGCB_EXPIRED,
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
30 changes: 18 additions & 12 deletions modules/fraud_detection/frd_events.c
Expand Up @@ -151,18 +151,24 @@ void dialog_terminate_CB(struct dlg_cell *dlg, int type,
extern str call_dur_name;
frd_dlg_param *frdparam = (frd_dlg_param*) *(params->param);

if (type & (DLGCB_TERMINATED|DLGCB_EXPIRED)) {
unsigned int duration = time(NULL) - dlg->start_ts;
if (frdparam->calldur_crit && duration >= frdparam->calldur_crit)
raise_critical_event(&call_dur_name, &duration,
&frdparam->calldur_crit,
&frdparam->user, &frdparam->number, &frdparam->ruleid);

else if (frdparam->calldur_warn && duration >= frdparam->calldur_warn)
raise_warning_event(&call_dur_name, &duration,
&frdparam->calldur_warn,
&frdparam->user, &frdparam->number, &frdparam->ruleid);
}
if (frdparam->dlg_terminated ||
!(type & (DLGCB_FAILED|DLGCB_TERMINATED|DLGCB_EXPIRED)))
return;
frdparam->dlg_terminated = 1;

unsigned int duration = time(NULL) - dlg->start_ts;
LM_DBG("call-duration: %u sec (warn: %u, crit: %u), dlgcb: %d\n",
duration, frdparam->calldur_warn, frdparam->calldur_crit, type);

if (frdparam->calldur_crit && duration >= frdparam->calldur_crit)
raise_critical_event(&call_dur_name, &duration,
&frdparam->calldur_crit,
&frdparam->user, &frdparam->number, &frdparam->ruleid);

else if (frdparam->calldur_warn && duration >= frdparam->calldur_warn)
raise_warning_event(&call_dur_name, &duration,
&frdparam->calldur_warn,
&frdparam->user, &frdparam->number, &frdparam->ruleid);

lock_get(&frdparam->stats->lock);
if (frdparam->interval_id == frdparam->stats->interval_id)
Expand Down
2 changes: 2 additions & 0 deletions modules/fraud_detection/frd_events.h
Expand Up @@ -48,6 +48,8 @@ typedef struct {

unsigned int calldur_warn;
unsigned int calldur_crit;

int dlg_terminated;
} frd_dlg_param;

void dialog_terminate_CB(struct dlg_cell *dlgc, int type,
Expand Down

0 comments on commit 7aa272a

Please sign in to comment.