Fixed category matching
This commit is contained in:
@@ -96,10 +96,16 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
u_int32_t ndpi_detection_get_sizeof_ndpi_flow_udp_struct(void);
|
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
|
* nDPI personal allocation and free functions
|
||||||
**/
|
**/
|
||||||
void * ndpi_malloc(size_t size);
|
void * ndpi_malloc(size_t size);
|
||||||
void * ndpi_calloc(unsigned long count, 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);
|
void * ndpi_realloc(void *ptr, size_t old_size, size_t new_size);
|
||||||
|
|||||||
+35
-3
@@ -2145,14 +2145,46 @@ int ndpi_match_string_protocol_id(void *_automa, char *string_to_match,
|
|||||||
rc = 1;
|
rc = 1;
|
||||||
|
|
||||||
if(rc)
|
if(rc)
|
||||||
*protocol_id = match.number, *category = NDPI_PROTOCOL_CATEGORY_UNSPECIFIED,
|
*protocol_id = (u_int16_t)match.number, *category = match.category,
|
||||||
*breed = NDPI_PROTOCOL_UNRATED;
|
*breed = match.breed;
|
||||||
else
|
else
|
||||||
*protocol_id = NDPI_PROTOCOL_UNKNOWN;
|
*protocol_id = NDPI_PROTOCOL_UNKNOWN;
|
||||||
|
|
||||||
return((*protocol_id != NDPI_PROTOCOL_UNKNOWN) ? 0 : -1);
|
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,
|
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.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);
|
rc = ac_automata_add(ndpi_str->custom_categories.hostnames_shadow.ac_automa, &ac_pattern);
|
||||||
if(rc != ACERR_DUPLICATE_PATTERN && rc != ACERR_SUCCESS) {
|
if(rc != ACERR_DUPLICATE_PATTERN && rc != ACERR_SUCCESS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user