Add more utility functions to work with patricia trees
This commit is contained in:
@@ -975,11 +975,17 @@ extern "C" {
|
|||||||
ndpi_patricia_node_t *ndpi_patricia_search_exact(ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix);
|
ndpi_patricia_node_t *ndpi_patricia_search_exact(ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix);
|
||||||
ndpi_patricia_node_t *ndpi_patricia_search_best(ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix);
|
ndpi_patricia_node_t *ndpi_patricia_search_best(ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix);
|
||||||
ndpi_patricia_node_t *ndpi_patricia_lookup(ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix);
|
ndpi_patricia_node_t *ndpi_patricia_lookup(ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix);
|
||||||
|
size_t ndpi_patricia_walk_tree_inorder(ndpi_patricia_tree_t *patricia, ndpi_void_fn3_t func, void *data);
|
||||||
size_t ndpi_patricia_walk_inorder(ndpi_patricia_node_t *node, ndpi_void_fn3_t func, void *data);
|
size_t ndpi_patricia_walk_inorder(ndpi_patricia_node_t *node, ndpi_void_fn3_t func, void *data);
|
||||||
void ndpi_patricia_remove(ndpi_patricia_tree_t *patricia, ndpi_patricia_node_t *node);
|
void ndpi_patricia_remove(ndpi_patricia_tree_t *patricia, ndpi_patricia_node_t *node);
|
||||||
|
|
||||||
void ndpi_patricia_set_node_u64(ndpi_patricia_node_t *node, u_int64_t value);
|
void ndpi_patricia_set_node_u64(ndpi_patricia_node_t *node, u_int64_t value);
|
||||||
u_int64_t ndpi_patricia_get_node_u64(ndpi_patricia_node_t *node);
|
u_int64_t ndpi_patricia_get_node_u64(ndpi_patricia_node_t *node);
|
||||||
|
void ndpi_patricia_set_node_data(ndpi_patricia_node_t *node, void *data);
|
||||||
|
void *ndpi_patricia_get_node_data(ndpi_patricia_node_t *node);
|
||||||
|
ndpi_prefix_t *ndpi_patricia_get_node_prefix(ndpi_patricia_node_t *node);
|
||||||
|
u_int16_t ndpi_patricia_get_node_bits(ndpi_patricia_node_t *node);
|
||||||
|
u_int16_t ndpi_patricia_get_maxbits(ndpi_patricia_tree_t *tree);
|
||||||
|
|
||||||
/* ptree (trie) API - a wrapper on top of Patricia that seamlessly handle IPv4 and IPv6 */
|
/* ptree (trie) API - a wrapper on top of Patricia that seamlessly handle IPv4 and IPv6 */
|
||||||
ndpi_ptree_t* ndpi_ptree_create(void);
|
ndpi_ptree_t* ndpi_ptree_create(void);
|
||||||
|
|||||||
@@ -1660,6 +1660,12 @@ static int ac_match_handler(AC_MATCH_t *m, AC_TEXT_t *txt, AC_REP_t *match) {
|
|||||||
|
|
||||||
/* ******************************************************************** */
|
/* ******************************************************************** */
|
||||||
|
|
||||||
|
u_int16_t ndpi_patricia_get_maxbits(ndpi_patricia_tree_t *tree) {
|
||||||
|
return(tree->maxbits);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ******************************************************************** */
|
||||||
|
|
||||||
int ndpi_fill_prefix_v4(ndpi_prefix_t *p, const struct in_addr *a, int b, int mb) {
|
int ndpi_fill_prefix_v4(ndpi_prefix_t *p, const struct in_addr *a, int b, int mb) {
|
||||||
if(b < 0 || b > mb)
|
if(b < 0 || b > mb)
|
||||||
return(-1);
|
return(-1);
|
||||||
@@ -1703,6 +1709,30 @@ int ndpi_fill_prefix_mac(ndpi_prefix_t *prefix, u_int8_t *mac, int bits, int max
|
|||||||
|
|
||||||
/* ******************************************* */
|
/* ******************************************* */
|
||||||
|
|
||||||
|
ndpi_prefix_t *ndpi_patricia_get_node_prefix(ndpi_patricia_node_t *node) {
|
||||||
|
return(node->prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ******************************************* */
|
||||||
|
|
||||||
|
u_int16_t ndpi_patricia_get_node_bits(ndpi_patricia_node_t *node) {
|
||||||
|
return(node->bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ******************************************* */
|
||||||
|
|
||||||
|
void ndpi_patricia_set_node_data(ndpi_patricia_node_t *node, void *data) {
|
||||||
|
node->data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ******************************************* */
|
||||||
|
|
||||||
|
void *ndpi_patricia_get_node_data(ndpi_patricia_node_t *node) {
|
||||||
|
return(node->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ******************************************* */
|
||||||
|
|
||||||
void ndpi_patricia_set_node_u64(ndpi_patricia_node_t *node, u_int64_t value) {
|
void ndpi_patricia_set_node_u64(ndpi_patricia_node_t *node, u_int64_t value) {
|
||||||
node->value.u.uv64 = value;
|
node->value.u.uv64 = value;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -449,6 +449,13 @@ ndpi_patricia_walk_inorder(ndpi_patricia_node_t *node, ndpi_void_fn3_t func, voi
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
ndpi_patricia_walk_tree_inorder(ndpi_patricia_tree_t *patricia, ndpi_void_fn3_t func, void *data) {
|
||||||
|
if (patricia->head == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return ndpi_patricia_walk_inorder(patricia->head, func, data);
|
||||||
|
}
|
||||||
|
|
||||||
ndpi_patricia_node_t *
|
ndpi_patricia_node_t *
|
||||||
ndpi_patricia_search_exact (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
ndpi_patricia_search_exact (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
||||||
|
|||||||
Reference in New Issue
Block a user