aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ndpi_utils.c
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2022-05-30 00:31:52 +0200
committerLuca Deri <deri@ntop.org>2022-05-30 00:32:32 +0200
commitf25deeccb1ccbebd6346271828762fdd8326c32b (patch)
tree677c846f19b9b1468e6ec62637e77ae354fe0a24 /src/lib/ndpi_utils.c
parenta9d7cc4841ea098074b3dc0b42b7b6e73d4d8cd9 (diff)
Added RiskInfo string
Diffstat (limited to 'src/lib/ndpi_utils.c')
-rw-r--r--src/lib/ndpi_utils.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c
index e5739ae5c..6d832115b 100644
--- a/src/lib/ndpi_utils.c
+++ b/src/lib/ndpi_utils.c
@@ -1286,7 +1286,7 @@ int ndpi_dpi2json(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_serialize_start_of_block(serializer, "http");
if(flow->host_server_name[0] != '\0')
ndpi_serialize_string_string(serializer, "hostname", flow->host_server_name);
- if(flow->http.url != NULL){
+ if(flow->http.url != NULL) {
ndpi_serialize_string_string(serializer, "url", flow->http.url);
ndpi_serialize_string_uint32(serializer, "code", flow->http.response_status_code);
ndpi_serialize_string_string(serializer, "content_type", flow->http.content_type);
@@ -2239,12 +2239,27 @@ static void ndpi_handle_risk_exceptions(struct ndpi_detection_module_struct *ndp
/* ******************************************************************** */
void ndpi_set_risk(struct ndpi_detection_module_struct *ndpi_str,
- struct ndpi_flow_struct *flow, ndpi_risk_enum r) {
- ndpi_risk v = 1ull << r;
+ struct ndpi_flow_struct *flow, ndpi_risk_enum r,
+ char *risk_message) {
+ /* Check if the risk is not yet set */
+ if(!ndpi_isset_risk(ndpi_str, flow, r)) {
+ ndpi_risk v = 1ull << r;
+
+ // NDPI_SET_BIT(flow->risk, (u_int32_t)r);
+ flow->risk |= v;
+
+ ndpi_handle_risk_exceptions(ndpi_str, flow);
- // NDPI_SET_BIT(flow->risk, (u_int32_t)r);
- flow->risk |= v;
- ndpi_handle_risk_exceptions(ndpi_str, flow);
+ if(risk_message != NULL) {
+ if(flow->num_risk_infos < MAX_NUM_RISK_INFOS) {
+ char *s = ndpi_strdup(risk_message);
+
+ if(s != NULL) {
+ flow->risk_infos[flow->num_risk_infos++] = s;
+ }
+ }
+ }
+ }
}
/* ******************************************************************** */
@@ -2501,6 +2516,32 @@ int ndpi_snprintf(char * str, size_t size, char const * format, ...) {
va_start(va_args, format);
int ret = ndpi_vsnprintf(str, size, format, va_args);
va_end(va_args);
+
return ret;
}
+/* ******************************************* */
+
+char* ndpi_get_flow_risk_info(struct ndpi_flow_struct *flow,
+ char *out, u_int out_len) {
+ if(out == NULL)
+ return(NULL);
+ else
+ out[0] = '\0';
+
+ if(flow->num_risk_infos) {
+ u_int i, offset = 0;
+ for(i=0; i<flow->num_risk_infos; i++) {
+ int rc = snprintf(&out[offset], out_len-offset, "%s%s",
+ (i == 0) ? "" : " / ",
+ flow->risk_infos[i]);
+
+ if(rc <= 0)
+ break;
+ else
+ offset += rc;
+ }
+ }
+
+ return(out[0] == '\0' ? NULL : out);
+}