Reworked domain classification based on binary filters

This commit is contained in:
Luca Deri
2023-09-02 19:16:40 +02:00
parent 854c2d80f1
commit 1d480c18e3
8 changed files with 329 additions and 310 deletions
+9 -6
View File
@@ -1802,6 +1802,7 @@ extern "C" {
u_int32_t ndpi_quick_hash(unsigned char *str, u_int str_len);
u_int32_t ndpi_hash_string(char *str);
u_int32_t ndpi_rev_hash_string(char *str);
u_int32_t ndpi_hash_string_len(char *str, u_int len);
/* ******************************* */
@@ -2073,11 +2074,13 @@ extern "C" {
void ndpi_domain_classify_free(ndpi_domain_classify *s);
u_int32_t ndpi_domain_classify_size(ndpi_domain_classify *s);
bool ndpi_domain_classify_add(ndpi_domain_classify *s,
u_int16_t classification_id, char *domain);
u_int32_t ndpi_domain_classify_add_domains(ndpi_domain_classify *_s,
u_int16_t classification_id,
u_int8_t class_id, char *domain);
u_int32_t ndpi_domain_classify_add_domains(ndpi_domain_classify *s,
u_int8_t class_id,
char *file_path);
u_int16_t ndpi_domain_classify_contains(ndpi_domain_classify *s, char *domain);
bool ndpi_domain_classify_contains(ndpi_domain_classify *s,
u_int8_t *class_id /* out */,
char *domain);
/* ******************************* */
@@ -2086,9 +2089,9 @@ extern "C" {
ability to store a category per value (as ndpi_domain_classify)
*/
ndpi_binary_bitmap* ndpi_binary_bitmap_alloc();
bool ndpi_binary_bitmap_set(ndpi_binary_bitmap *b, u_int32_t value, u_int8_t category);
bool ndpi_binary_bitmap_set(ndpi_binary_bitmap *b, u_int64_t value, u_int8_t category);
bool ndpi_binary_bitmap_compress(ndpi_binary_bitmap *b);
bool ndpi_binary_bitmap_isset(ndpi_binary_bitmap *b, u_int32_t value, u_int8_t *out_category);
bool ndpi_binary_bitmap_isset(ndpi_binary_bitmap *b, u_int64_t value, u_int8_t *out_category);
void ndpi_binary_bitmap_free(ndpi_binary_bitmap *b);
u_int32_t ndpi_binary_bitmap_size(ndpi_binary_bitmap *b);
u_int32_t ndpi_binary_bitmap_cardinality(ndpi_binary_bitmap *b);
+26 -21
View File
@@ -1175,7 +1175,32 @@ typedef struct ndpi_proto {
#define NUM_CUSTOM_CATEGORIES 5
#define CUSTOM_CATEGORY_LABEL_LEN 32
typedef void ndpi_domain_classify;
typedef void ndpi_bitmap;
typedef void ndpi_bitmap_iterator;
typedef void ndpi_filter;
/* Save memory limiting the key to 56 bit */
#define SAVE_BINARY_BITMAP_MEMORY
PACK_ON
struct ndpi_binary_bitmap_entry {
#ifdef SAVE_BINARY_BITMAP_MEMORY
u_int64_t value:56, category:8;
#else
u_int64_t value;
u_int8_t category;
#endif
} PACK_OFF;
typedef struct {
u_int32_t num_allocated_entries, num_used_entries;
struct ndpi_binary_bitmap_entry *entries;
bool is_compressed;
} ndpi_binary_bitmap;
typedef struct {
ndpi_binary_bitmap *bitmap;
} ndpi_domain_classify;
#ifdef NDPI_LIB_COMPILATION
@@ -2027,24 +2052,4 @@ typedef int (*ndpi_custom_dga_predict_fctn)(const char* domain, int domain_lengt
/* **************************************** */
typedef void ndpi_bitmap;
typedef void ndpi_bitmap_iterator;
typedef void ndpi_filter;
#define MAX_NUM_NDPI_DOMAIN_CLASSIFICATIONS 16
PACK_ON
struct ndpi_binary_bitmap_entry {
u_int32_t value;
u_int8_t category;
} PACK_OFF;
typedef struct {
u_int32_t num_allocated_entries, num_used_entries;
struct ndpi_binary_bitmap_entry *entries;
bool is_compressed;
} ndpi_binary_bitmap;
/* **************************************** */
#endif /* __NDPI_TYPEDEFS_H__ */