Improvement for reducing false positives

This commit is contained in:
Luca Deri
2023-09-01 10:26:07 +02:00
parent 74fdac7d77
commit 854c2d80f1
2 changed files with 22 additions and 8 deletions
+8 -8
View File
@@ -104,7 +104,7 @@ static u_int32_t ndpi_domain_search_size(ndpi_domain_search *search) {
/* NOTE: domain will be modified: copy it if necessary */
static bool ndpi_domain_search_add(ndpi_domain_search *search, char *domain) {
char *elem;
u_int32_t bitmap_id = 0, len;
u_int32_t bitmap_id = 0, len, hsum = 0;
bool quit = false;
if(domain == NULL) return(false);
@@ -133,9 +133,9 @@ static bool ndpi_domain_search_add(ndpi_domain_search *search, char *domain) {
h += END_OF_TOKENS_DELIMITER;
}
ndpi_bitmap_set(search->bitmap[bitmap_id], h);
ndpi_bitmap_set(search->bitmap[bitmap_id], h + hsum);
bitmap_id++;
bitmap_id++, hsum += h;
if(quit)
break;
@@ -158,7 +158,7 @@ static bool ndpi_domain_search_add(ndpi_domain_search *search, char *domain) {
static bool ndpi_domain_search_contains(ndpi_domain_search *search, char *domain) {
char *elem;
u_int32_t bitmap_id = 0;
u_int32_t bitmap_id = 0, hsum = 0;
bool quit = false;
if((elem = strrchr(domain, '.')) == NULL)
@@ -171,16 +171,16 @@ static bool ndpi_domain_search_contains(ndpi_domain_search *search, char *domain
h = ndpi_hash_string(elem);
if(!ndpi_bitmap_isset(search->bitmap[bitmap_id], h)) {
if(!ndpi_bitmap_isset(search->bitmap[bitmap_id], h + hsum)) {
/* Exact match does not work, so let's see if a partial match works instead */
/* We're adding the beginning of the domain, hence the last token before quitting */
h += END_OF_TOKENS_DELIMITER;
return(ndpi_bitmap_isset(search->bitmap[bitmap_id], h));
return(ndpi_bitmap_isset(search->bitmap[bitmap_id], h + hsum));
}
bitmap_id++;
bitmap_id++, hsum += h;
if(quit)
break;
@@ -306,7 +306,7 @@ u_int32_t ndpi_domain_classify_add_domains(ndpi_domain_classify *_s,
return(false);
s->class[i]->class_id = class_id;
s->class[i]->domains = ndpi_domain_search_alloc();
s->class[i]->domains = ndpi_domain_search_alloc();
break;
}
}