aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2020-05-06 23:50:35 +0200
committerLuca Deri <deri@ntop.org>2020-05-06 23:50:35 +0200
commit6a1b8baa00d4f0f9c52bce0e7d7618438de7f199 (patch)
tree5eb655327f0a819c1a2376ef69b0d8db7f511585
parent2ccd2c204bcc3f272cf19e03978a0c2c998386af (diff)
Fixed category matching
-rw-r--r--src/include/ndpi_api.h.in8
-rw-r--r--src/lib/ndpi_main.c38
2 files changed, 42 insertions, 4 deletions
diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in
index 81f929840..1ba0c1065 100644
--- a/src/include/ndpi_api.h.in
+++ b/src/include/ndpi_api.h.in
@@ -96,10 +96,16 @@ extern "C" {
*/
u_int32_t ndpi_detection_get_sizeof_ndpi_flow_udp_struct(void);
+ /*
+ Same as the API call above but used for matching raw id's added
+ via ndpi_add_string_value_to_automa()
+ */
+ int ndpi_match_string_value(void *_automa, char *string_to_match,
+ u_int match_len, u_int32_t *num);
/**
* nDPI personal allocation and free functions
- **/
+ **/
void * ndpi_malloc(size_t size);
void * ndpi_calloc(unsigned long count, size_t size);
void * ndpi_realloc(void *ptr, size_t old_size, size_t new_size);
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 718e5204f..ed2d5995b 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -2145,14 +2145,46 @@ int ndpi_match_string_protocol_id(void *_automa, char *string_to_match,
rc = 1;
if(rc)
- *protocol_id = match.number, *category = NDPI_PROTOCOL_CATEGORY_UNSPECIFIED,
- *breed = NDPI_PROTOCOL_UNRATED;
+ *protocol_id = (u_int16_t)match.number, *category = match.category,
+ *breed = match.breed;
else
*protocol_id = NDPI_PROTOCOL_UNKNOWN;
return((*protocol_id != NDPI_PROTOCOL_UNKNOWN) ? 0 : -1);
}
+/* ****************************************************** */
+
+int ndpi_match_string_value(void *_automa, char *string_to_match,
+ u_int match_len, u_int32_t *num) {
+ AC_TEXT_t ac_input_text;
+ AC_AUTOMATA_t *automa = (AC_AUTOMATA_t *) _automa;
+ AC_REP_t match = { 0, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED, NDPI_PROTOCOL_UNRATED };
+ int rc;
+
+ *num = (u_int32_t)-1;
+ if((automa == NULL) || (string_to_match == NULL) || (string_to_match[0] == '\0'))
+ return(-2);
+
+ ac_input_text.astring = string_to_match, ac_input_text.length = match_len;
+ rc = ac_automata_search(automa, &ac_input_text, &match);
+
+ /*
+ As ac_automata_search can detect partial matches and continue the search process
+ in case rc == 0 (i.e. no match), we need to check if there is a partial match
+ and in this case return it
+ */
+ if((rc == 0) && (match.number != 0))
+ rc = 1;
+
+ if(rc)
+ *num = match.number;
+ else
+ *num = 0;
+
+ return(rc ? 0 : -1);
+}
+
/* *********************************************** */
int ndpi_match_custom_category(struct ndpi_detection_module_struct *ndpi_str,
@@ -4143,7 +4175,7 @@ int ndpi_load_hostname_category(struct ndpi_detection_module_struct *ndpi_str, c
}
ac_pattern.astring = name, ac_pattern.length = strlen(ac_pattern.astring);
- ac_pattern.rep.number = (int) category;
+ ac_pattern.rep.number = (u_int32_t) category, ac_pattern.rep.category = category;;
rc = ac_automata_add(ndpi_str->custom_categories.hostnames_shadow.ac_automa, &ac_pattern);
if(rc != ACERR_DUPLICATE_PATTERN && rc != ACERR_SUCCESS) {