Add support for MAC to Patricia tree. Expose full API to applications. Add utility functions.

This commit is contained in:
Alfredo Cardigliano
2021-02-23 10:01:56 +01:00
parent b757cf606b
commit f8e83f7e35
5 changed files with 268 additions and 176 deletions
+20 -1
View File
@@ -962,7 +962,26 @@ extern "C" {
const char* ndpi_http_method2str(ndpi_http_method m);
ndpi_http_method ndpi_http_str2method(const char* method, u_int16_t method_len);
/* ptree (trie) API */
/* Utility functions to fill prefix (used by the patricia tree) */
int ndpi_fill_prefix_v4(ndpi_prefix_t *p, const struct in_addr *a, int b, int mb);
int ndpi_fill_prefix_v6(ndpi_prefix_t *prefix, const struct in6_addr *addr, int bits, int maxbits);
int ndpi_fill_prefix_mac(ndpi_prefix_t *prefix, u_int8_t *mac, int bits, int maxbits);
/* Patricia tree API (radix tree supporting IPv4/IPv6/MAC) */
ndpi_patricia_tree_t *ndpi_patricia_new(u_int16_t maxbits);
ndpi_patricia_tree_t *ndpi_patricia_clone (const ndpi_patricia_tree_t * const from);
void ndpi_patricia_destroy(ndpi_patricia_tree_t *patricia, ndpi_void_fn_t func);
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_lookup(ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix);
size_t ndpi_patricia_walk_inorder(ndpi_patricia_node_t *node, ndpi_void_fn2_t func);
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);
u_int64_t ndpi_patricia_get_node_u64(ndpi_patricia_node_t *node);
/* ptree (trie) API - a wrapper on top of Patricia that seamlessly handle IPv4 and IPv6 */
ndpi_ptree_t* ndpi_ptree_create(void);
int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int8_t bits, u_int64_t user_data);
int ndpi_ptree_match_addr(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int64_t *user_data);
+31
View File
@@ -1574,6 +1574,37 @@ struct ndpi_jitter_struct {
/* **************************************** */
#ifndef WIN32
#define NDPI_PATRICIA_IPV6
#else
#undef NDPI_PATRICIA_IPV6
#endif
#ifndef AF_MAC
#define AF_MAC 99
#endif
typedef struct _ndpi_prefix_t {
u_int16_t family; /* AF_INET | AF_INET6 */
u_int16_t bitlen; /* same as mask? */
int ref_count; /* reference count */
union {
struct in_addr sin;
#ifdef NDPI_PATRICIA_IPV6
struct in6_addr sin6;
#endif /* IPV6 */
u_int8_t mac[6];
} add;
} ndpi_prefix_t;
typedef void (*ndpi_void_fn_t)(void *data);
typedef void (*ndpi_void_fn2_t)(ndpi_prefix_t *prefix, void *data);
typedef struct _ndpi_patricia_node_t ndpi_patricia_node_t;
typedef struct _ndpi_patricia_tree_t ndpi_patricia_tree_t;
/* **************************************** */
typedef struct ndpi_ptree ndpi_ptree_t;
/* **************************************** */