Revert "Patricia tree, Ahocarasick automa, LRU cache: add statistics (#1677)" (#1682)

This reverts commit bb83899985.
This commit is contained in:
Ivan Nardi
2022-07-29 12:08:40 +02:00
committed by GitHub
parent bb83899985
commit df2e11ef51
9 changed files with 8 additions and 378 deletions
+1 -116
View File
@@ -2039,38 +2039,6 @@ u_int16_t ndpi_patricia_get_maxbits(ndpi_patricia_tree_t *tree) {
/* ******************************************************************** */
void ndpi_patricia_get_stats(ndpi_patricia_tree_t *tree, struct ndpi_patricia_tree_stats *stats) {
if(tree) {
stats->n_search = tree->stats.n_search;
stats->n_found = tree->stats.n_found;
} else {
stats->n_search = 0;
stats->n_found = 0;
}
}
/* ******************************************************************** */
int ndpi_get_patricia_stats(struct ndpi_detection_module_struct *ndpi_struct,
ptree_type ptree_type,
struct ndpi_patricia_tree_stats *stats) {
switch(ptree_type) {
case NDPI_PTREE_RISK_MASK:
ndpi_patricia_get_stats((ndpi_patricia_tree_t *)ndpi_struct->ip_risk_mask_ptree, stats);
return 0;
case NDPI_PTREE_RISK:
ndpi_patricia_get_stats((ndpi_patricia_tree_t *)ndpi_struct->ip_risk_ptree, stats);
return 0;
case NDPI_PTREE_PROTOCOLS:
ndpi_patricia_get_stats((ndpi_patricia_tree_t *)ndpi_struct->protocols_ptree, stats);
return 0;
default:
return -1;
}
}
/* ****************************************************** */
int ndpi_fill_prefix_v4(ndpi_prefix_t *p, const struct in_addr *a, int b, int mb) {
if(b < 0 || b > mb)
return(-1);
@@ -2873,43 +2841,6 @@ void ndpi_finalize_automa(void *_automa) {
/* ****************************************************** */
void ndpi_automa_get_stats(void *_automa, struct ndpi_automa_stats *stats) {
struct ac_stats ac_stats;
ac_automata_get_stats((AC_AUTOMATA_t *) _automa, &ac_stats);
stats->n_search = ac_stats.n_search;
stats->n_found = ac_stats.n_found;
}
/* ****************************************************** */
int ndpi_get_automa_stats(struct ndpi_detection_module_struct *ndpi_struct,
automa_type automa_type,
struct ndpi_automa_stats *stats)
{
switch(automa_type) {
case NDPI_AUTOMA_HOST:
ndpi_automa_get_stats(ndpi_struct->host_automa.ac_automa, stats);
return 0;
case NDPI_AUTOMA_DOMAIN:
ndpi_automa_get_stats(ndpi_struct->risky_domain_automa.ac_automa, stats);
return 0;
case NDPI_AUTOMA_TLS_CERT:
ndpi_automa_get_stats(ndpi_struct->tls_cert_subject_automa.ac_automa, stats);
return 0;
case NDPI_AUTOMA_RISK_MASK:
ndpi_automa_get_stats(ndpi_struct->host_risk_mask_automa.ac_automa, stats);
return 0;
case NDPI_AUTOMA_COMMON_ALPNS:
ndpi_automa_get_stats(ndpi_struct->common_alpns_automa.ac_automa, stats);
return 0;
default:
return -1;
}
}
/* ****************************************************** */
static int ndpi_match_string_common(AC_AUTOMATA_t *automa, char *string_to_match,size_t string_len,
u_int32_t *protocol_id, ndpi_protocol_category_t *category,
ndpi_protocol_breed_t *breed) {
@@ -8122,7 +8053,7 @@ void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_str, u_int l){
/* LRU cache */
struct ndpi_lru_cache *ndpi_lru_cache_init(u_int32_t num_entries) {
struct ndpi_lru_cache *c = (struct ndpi_lru_cache *) ndpi_calloc(1, sizeof(struct ndpi_lru_cache));
struct ndpi_lru_cache *c = (struct ndpi_lru_cache *) ndpi_malloc(sizeof(struct ndpi_lru_cache));
if(!c)
return(NULL);
@@ -8147,12 +8078,10 @@ u_int8_t ndpi_lru_find_cache(struct ndpi_lru_cache *c, u_int32_t key,
u_int16_t *value, u_int8_t clean_key_when_found) {
u_int32_t slot = key % c->num_entries;
c->stats.n_search++;
if(c->entries[slot].is_full && c->entries[slot].key == key) {
*value = c->entries[slot].value;
if(clean_key_when_found)
c->entries[slot].is_full = 0;
c->stats.n_found++;
return(1);
} else
return(0);
@@ -8161,53 +8090,9 @@ u_int8_t ndpi_lru_find_cache(struct ndpi_lru_cache *c, u_int32_t key,
void ndpi_lru_add_to_cache(struct ndpi_lru_cache *c, u_int32_t key, u_int16_t value) {
u_int32_t slot = key % c->num_entries;
c->stats.n_insert++;
c->entries[slot].is_full = 1, c->entries[slot].key = key, c->entries[slot].value = value;
}
void ndpi_lru_get_stats(struct ndpi_lru_cache *c, struct ndpi_lru_cache_stats *stats) {
if(c) {
stats->n_insert = c->stats.n_insert;
stats->n_search = c->stats.n_search;
stats->n_found = c->stats.n_found;
} else {
stats->n_insert = 0;
stats->n_search = 0;
stats->n_found = 0;
}
}
int ndpi_get_lru_cache_stats(struct ndpi_detection_module_struct *ndpi_struct,
lru_cache_type cache_type,
struct ndpi_lru_cache_stats *stats)
{
switch(cache_type) {
case NDPI_LRUCACHE_OOKLA:
ndpi_lru_get_stats(ndpi_struct->ookla_cache, stats);
return 0;
case NDPI_LRUCACHE_BITTORRENT:
ndpi_lru_get_stats(ndpi_struct->bittorrent_cache, stats);
return 0;
case NDPI_LRUCACHE_ZOOM:
ndpi_lru_get_stats(ndpi_struct->zoom_cache, stats);
return 0;
case NDPI_LRUCACHE_STUN:
ndpi_lru_get_stats(ndpi_struct->stun_cache, stats);
return 0;
case NDPI_LRUCACHE_TLS_CERT:
ndpi_lru_get_stats(ndpi_struct->tls_cert_cache, stats);
return 0;
case NDPI_LRUCACHE_MINING:
ndpi_lru_get_stats(ndpi_struct->mining_cache, stats);
return 0;
case NDPI_LRUCACHE_MSTEAMS:
ndpi_lru_get_stats(ndpi_struct->msteams_cache, stats);
return 0;
default:
return -1;
}
}
/* ******************************************************************** */
/*
-7
View File
@@ -212,11 +212,6 @@ struct ac_path {
unsigned short int idx,l;
};
struct ac_stats {
uint64_t n_search;
uint64_t n_found;
};
typedef struct
{
/* The root of the Aho-Corasick trie */
@@ -241,7 +236,6 @@ typedef struct
int add_to_range; /* for convert to range */
int n_oc,n_range,n_find; /* statistics */
char name[32]; /* if debug != 0 */
struct ac_stats stats;
} AC_AUTOMATA_t;
typedef AC_ERROR_t (*NODE_CALLBACK_f)(AC_AUTOMATA_t *, AC_NODE_t *,int idx, void *);
@@ -272,5 +266,4 @@ void ac_automata_enable_debug (int debug);
/* See man open_memstream() for get result as string */
void ac_automata_dump (AC_AUTOMATA_t * thiz, FILE *);
#endif
void ac_automata_get_stats(AC_AUTOMATA_t * thiz, struct ac_stats *stats);
#endif
+2 -21
View File
@@ -434,8 +434,6 @@ int ac_automata_search (AC_AUTOMATA_t * thiz,
AC_NODE_t *next;
AC_ALPHABET_t *apos;
thiz->stats.n_search++;
if(thiz->automata_open)
/* you must call ac_automata_locate_failure() first */
return -1;
@@ -495,20 +493,15 @@ int ac_automata_search (AC_AUTOMATA_t * thiz,
match->position = position;
match->match_num = curr->matched_patterns->num;
match->patterns = curr->matched_patterns->patterns;
if (thiz->match_handler(match, txt, param)) {
thiz->stats.n_found++;
if (thiz->match_handler(match, txt, param))
return 1;
}
}
} /* match->match_map */
}
}
}
if(thiz->match_handler) {
if(match->match_counter > 0)
thiz->stats.n_found++;
if(thiz->match_handler)
return match->match_counter > 0 ? 1:0;
}
for(i = 0; i < 4; i++)
if(txt->match.matched[i]) {
@@ -523,7 +516,6 @@ int ac_automata_search (AC_AUTOMATA_t * thiz,
pattern->rep.number);
}
#endif
thiz->stats.n_found++;
return 1;
}
return 0;
@@ -1246,16 +1238,5 @@ static inline void node_sort_edges (AC_NODE_t * thiz)
}
}
void ac_automata_get_stats(AC_AUTOMATA_t * thiz, struct ac_stats *stats)
{
if (thiz) {
stats->n_search = thiz->stats.n_search;
stats->n_found = thiz->stats.n_found;
} else {
stats->n_search = 0;
stats->n_found = 0;
}
}
/* vim: set ts=4 sw=4 et : */
-6
View File
@@ -462,8 +462,6 @@ ndpi_patricia_search_exact (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefi
assert (prefix);
assert (prefix->bitlen <= patricia->maxbits);
patricia->stats.n_search++;
if(patricia->head == NULL)
return (NULL);
@@ -519,7 +517,6 @@ ndpi_patricia_search_exact (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefi
fprintf (stderr, "patricia_search_exact: found %s/%d\n",
ndpi_prefix_toa (node->prefix), node->prefix->bitlen);
#endif /* PATRICIA_DEBUG */
patricia->stats.n_found++;
return (node);
}
return (NULL);
@@ -540,8 +537,6 @@ ndpi_patricia_search_best2 (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefi
assert (prefix);
assert (prefix->bitlen <= patricia->maxbits);
patricia->stats.n_search++;
if(patricia->head == NULL)
return (NULL);
@@ -619,7 +614,6 @@ ndpi_patricia_search_best2 (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefi
fprintf (stderr, "patricia_search_best: found %s/%d\n",
ndpi_prefix_toa (node->prefix), node->prefix->bitlen);
#endif /* PATRICIA_DEBUG */
patricia->stats.n_found++;
return (node);
}
}