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
+14
View File
@@ -5473,6 +5473,19 @@ void domainSearchUnitTest() {
/* *********************************************** */
void domainSearchUnitTest2() {
ndpi_domain_classify *c = ndpi_domain_classify_alloc();
u_int16_t class_id = 9;
ndpi_domain_classify_add(c, class_id, "ntop.org");
ndpi_domain_classify_add(c, class_id, "apple.com");
assert(ndpi_domain_classify_contains(c,"ntop.com") == 0);
ndpi_domain_classify_free(c);
}
/* *********************************************** */
/**
@brief MAIN FUNCTION
**/
@@ -5513,6 +5526,7 @@ int main(int argc, char **argv) {
#endif
domainSearchUnitTest();
domainSearchUnitTest2();
sketchUnitTest();
linearUnitTest();
zscoreUnitTest();
+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;
}
}