From 080a31aebd87a214464ea00833a1c373f9f29f37 Mon Sep 17 00:00:00 2001 From: Ahron Greenberg Date: Sun, 8 Sep 2024 19:55:12 -0400 Subject: [PATCH] fraud_detection: add profile id to the raised events --- modules/fraud_detection/fraud_detection.c | 3 ++- modules/fraud_detection/frd_events.c | 19 +++++++++++-------- modules/fraud_detection/frd_events.h | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/fraud_detection/fraud_detection.c b/modules/fraud_detection/fraud_detection.c index 3e04ec4f7fc..4a64cef5be8 100644 --- a/modules/fraud_detection/fraud_detection.c +++ b/modules/fraud_detection/fraud_detection.c @@ -390,7 +390,7 @@ static int check_fraud(struct sip_msg *msg, str *user, str *number, int *pid) #define CHECK_AND_RAISE(pname, type) \ (thr->pname ## _thr.type && se->stats.pname >= thr->pname ## _thr.type) { \ raise_ ## type ## _event(&pname ## _name, &se->stats.pname,\ - &thr->pname ## _thr.type, user, number, &rule->id);\ + &thr->pname ## _thr.type, user, number, &rule->id, pid);\ rc = rc_ ## type ## _thr;\ } @@ -429,6 +429,7 @@ static int check_fraud(struct sip_msg *msg, str *user, str *number, int *pid) param->stats = se; /* safe to ref, only freed @ shutdown */ param->user = shm_user; /* safe to ref, only freed @ shutdown */ param->ruleid = rule->id; + param->pid = *pid; param->dlg_terminated = 0; param->calldur_warn = thr->call_duration_thr.warning; diff --git a/modules/fraud_detection/frd_events.c b/modules/fraud_detection/frd_events.c index d4dcae53d9f..4c6a2e086d9 100644 --- a/modules/fraud_detection/frd_events.c +++ b/modules/fraud_detection/frd_events.c @@ -49,8 +49,9 @@ static str ei_thr_name = str_init("threshold"); static str ei_user_name = str_init("user"); static str ei_number_name = str_init("called_number"); static str ei_ruleid_name = str_init("rule_id"); +static str ei_pid_name = str_init("profile_id"); -static evi_param_p param_p, val_p, thr_p, user_p, number_p, ruleid_p; +static evi_param_p param_p, val_p, thr_p, user_p, number_p, ruleid_p, pid_p; /* @@ -87,6 +88,7 @@ int frd_event_init(void) CREATE_PARAM(user); CREATE_PARAM(number); CREATE_PARAM(ruleid); + CREATE_PARAM(pid); #undef CREATE_PARAM return 0; @@ -106,7 +108,7 @@ void frd_event_destroy(void) */ static void raise_event(event_id_t e, str *param, unsigned int *val, unsigned int *thr, str *user, - str *number, unsigned int *ruleid) + str *number, unsigned int *ruleid, int *pid) { #define SET_PARAM(pname, ptype) \ if (evi_param_set_ ##ptype (pname ## _p, pname) < 0) { \ @@ -120,6 +122,7 @@ static void raise_event(event_id_t e, SET_PARAM(user, str); SET_PARAM(number, str); SET_PARAM(ruleid, int); + SET_PARAM(pid, int); #undef SET_PARAM if (evi_raise_event(e, event_params) < 0) @@ -127,15 +130,15 @@ static void raise_event(event_id_t e, } void raise_warning_event(str *param, unsigned int *val, unsigned int *thr, - str *user, str *number, unsigned int *ruleid) + str *user, str *number, unsigned int *ruleid, int *pid) { - raise_event(ei_warn_id, param, val, thr, user, number, ruleid); + raise_event(ei_warn_id, param, val, thr, user, number, ruleid, pid); } void raise_critical_event(str *param, unsigned int *val, unsigned int *thr, - str *user, str *number, unsigned int *ruleid) + str *user, str *number, unsigned int *ruleid, int *pid) { - raise_event(ei_crit_id, param, val, thr, user, number, ruleid); + raise_event(ei_crit_id, param, val, thr, user, number, ruleid, pid); } @@ -163,13 +166,13 @@ void dialog_terminate_CB(struct dlg_cell *dlg, int type, && duration >= frdparam->calldur_crit) raise_critical_event(&call_dur_name, &duration, &frdparam->calldur_crit, - &frdparam->user, &frdparam->number, &frdparam->ruleid); + &frdparam->user, &frdparam->number, &frdparam->ruleid, &frdparam->pid); else if (!(type & DLGCB_FAILED) && frdparam->calldur_warn && duration >= frdparam->calldur_warn) raise_warning_event(&call_dur_name, &duration, &frdparam->calldur_warn, - &frdparam->user, &frdparam->number, &frdparam->ruleid); + &frdparam->user, &frdparam->number, &frdparam->ruleid, &frdparam->pid); lock_get(&frdparam->stats->lock); if (!frdparam->dlg_terminated diff --git a/modules/fraud_detection/frd_events.h b/modules/fraud_detection/frd_events.h index 049ac4b97d1..65be020b928 100644 --- a/modules/fraud_detection/frd_events.h +++ b/modules/fraud_detection/frd_events.h @@ -32,9 +32,9 @@ int frd_event_init(void); void frd_event_destroy(void); void raise_warning_event(str *param, unsigned int *val, unsigned int *thr, - str *user, str *number, unsigned int *ruleid); + str *user, str *number, unsigned int *ruleid, int *pid); void raise_critical_event(str *param, unsigned int *val, unsigned int *thr, - str *user, str *number, unsigned int *ruleid); + str *user, str *number, unsigned int *ruleid, int *pid); /* Dialog callback */ @@ -44,6 +44,7 @@ typedef struct { str user; str number; unsigned int ruleid; + int pid; unsigned int interval_id; unsigned int calldur_warn;