From 76459094605efd46bd71ce28ce9616280f4a440d Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Tue, 5 Jul 2022 17:01:00 +0200 Subject: Fix handling of NDPI_UNIDIRECTIONAL_TRAFFIC risk (#1636) --- src/lib/ndpi_utils.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/lib/ndpi_utils.c') diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c index e1a088ee5..15b71caf1 100644 --- a/src/lib/ndpi_utils.c +++ b/src/lib/ndpi_utils.c @@ -2303,6 +2303,33 @@ void ndpi_set_risk(struct ndpi_detection_module_struct *ndpi_str, /* ******************************************************************** */ +void ndpi_unset_risk(struct ndpi_detection_module_struct *ndpi_str, + struct ndpi_flow_struct *flow, ndpi_risk_enum r) { + if(ndpi_isset_risk(ndpi_str, flow, r)) { + u_int8_t i, j; + ndpi_risk v = 1ull << r; + + flow->risk &= ~v; + + for(i = 0; i < flow->num_risk_infos; i++) { + if(flow->risk_infos[i].id == r) { + flow->risk_infos[i].id = 0; + if(flow->risk_infos[i].info) { + ndpi_free(flow->risk_infos[i].info); + flow->risk_infos[i].info = NULL; + } + for(j = i + 1; j < flow->num_risk_infos; j++) { + flow->risk_infos[j - 1].id = flow->risk_infos[j].id; + flow->risk_infos[j - 1].info = flow->risk_infos[j].info; + } + flow->num_risk_infos--; + } + } + } +} + +/* ******************************************************************** */ + int ndpi_isset_risk(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, ndpi_risk_enum r) { ndpi_risk v = 1ull << r; -- cgit v1.2.3