aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2023-09-01 10:26:07 +0200
committerLuca Deri <deri@ntop.org>2023-09-01 10:26:07 +0200
commit854c2d80f1cf5c567a602ce25f8fd7e166bc4c2f (patch)
tree10184f62084900baf02a1f4d3fcabf723c651fbf /src
parent74fdac7d77a933f6b8ef894d1f2fbd3c9052fdcb (diff)
Improvement for reducing false positives
Diffstat (limited to 'src')
-rw-r--r--src/lib/ndpi_domain_classify.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/ndpi_domain_classify.c b/src/lib/ndpi_domain_classify.c
index b0cf06d72..f0e6ff7cb 100644
--- a/src/lib/ndpi_domain_classify.c
+++ b/src/lib/ndpi_domain_classify.c
@@ -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;
}
}