Add support for MAC to Patricia tree. Expose full API to applications. Add utility functions.
This commit is contained in:
+19
-50
@@ -41,15 +41,11 @@
|
||||
#ifndef _NDPI_PATRICIA_H
|
||||
#define _NDPI_PATRICIA_H
|
||||
|
||||
#ifndef WIN32
|
||||
#define PATRICIA_IPV6 HAVE_IPV6
|
||||
#else
|
||||
#undef PATRICIA_IPV6
|
||||
#endif
|
||||
#include "ndpi_api.h"
|
||||
|
||||
/* typedef unsigned int u_int; */
|
||||
/* { from defs.h */
|
||||
#define prefix_touchar(prefix) ((u_char *)&(prefix)->add.sin)
|
||||
#define ndpi_prefix_touchar(prefix) ((u_char *)&(prefix)->add.sin)
|
||||
|
||||
#define MAXLINE 1024
|
||||
|
||||
@@ -80,25 +76,13 @@
|
||||
|
||||
/* { from mrt.h */
|
||||
|
||||
typedef struct the_prefix4_t {
|
||||
typedef struct _prefix4_t {
|
||||
u_int16_t family; /* AF_INET | AF_INET6 */
|
||||
u_int16_t bitlen; /* same as mask? */
|
||||
int ref_count; /* reference count */
|
||||
struct in_addr sin;
|
||||
} prefix4_t;
|
||||
|
||||
typedef struct the_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 PATRICIA_IPV6
|
||||
struct in6_addr sin6;
|
||||
#endif /* IPV6 */
|
||||
} add;
|
||||
} prefix_t;
|
||||
|
||||
/* } */
|
||||
|
||||
/* pointer to usr data (ex. route flap info) */
|
||||
@@ -115,35 +99,20 @@ union patricia_node_value_t {
|
||||
} u;
|
||||
};
|
||||
|
||||
typedef struct _patricia_node_t {
|
||||
typedef struct _ndpi_patricia_node_t {
|
||||
u_int16_t bit; /* flag if this node used */
|
||||
prefix_t *prefix; /* who we are in patricia tree */
|
||||
struct _patricia_node_t *l, *r; /* left and right children */
|
||||
struct _patricia_node_t *parent;/* may be used */
|
||||
ndpi_prefix_t *prefix; /* who we are in patricia tree */
|
||||
struct _ndpi_patricia_node_t *l, *r; /* left and right children */
|
||||
struct _ndpi_patricia_node_t *parent;/* may be used */
|
||||
void *data; /* pointer to data */
|
||||
union patricia_node_value_t value;
|
||||
} patricia_node_t;
|
||||
} ndpi_patricia_node_t;
|
||||
|
||||
typedef struct _patricia_tree_t {
|
||||
patricia_node_t *head;
|
||||
typedef struct _ndpi_patricia_tree_t {
|
||||
ndpi_patricia_node_t *head;
|
||||
u_int16_t maxbits; /* for IP, 32 bit addresses */
|
||||
int num_active_node; /* for debug purpose */
|
||||
} patricia_tree_t;
|
||||
|
||||
typedef void (*void_fn_t)(void *data);
|
||||
typedef void (*void_fn2_t)(prefix_t *prefix, void *data);
|
||||
|
||||
/* renamed to ndpi_Patricia to avoid name conflicts */
|
||||
patricia_node_t *ndpi_patricia_search_exact (patricia_tree_t *patricia, prefix_t *prefix);
|
||||
patricia_node_t *ndpi_patricia_search_best (patricia_tree_t *patricia, prefix_t *prefix);
|
||||
patricia_node_t * ndpi_patricia_search_best2 (patricia_tree_t *patricia, prefix_t *prefix,
|
||||
int inclusive);
|
||||
patricia_node_t *ndpi_patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix);
|
||||
void ndpi_patricia_remove (patricia_tree_t *patricia, patricia_node_t *node);
|
||||
patricia_tree_t *ndpi_New_Patricia (u_int16_t maxbits);
|
||||
void ndpi_Clear_Patricia (patricia_tree_t *patricia, void_fn_t func);
|
||||
void ndpi_Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func);
|
||||
void ndpi_patricia_process (patricia_tree_t *patricia, void_fn2_t func);
|
||||
} ndpi_patricia_tree_t;
|
||||
|
||||
#ifdef WIN32
|
||||
#define PATRICIA_MAXBITS 128
|
||||
@@ -158,17 +127,17 @@ void ndpi_patricia_process (patricia_tree_t *patricia, void_fn2_t func);
|
||||
|
||||
#define PATRICIA_WALK(Xhead, Xnode) \
|
||||
do { \
|
||||
patricia_node_t *Xstack[PATRICIA_MAXBITS+1]; \
|
||||
patricia_node_t **Xsp = Xstack; \
|
||||
patricia_node_t *Xrn = (Xhead); \
|
||||
ndpi_patricia_node_t *Xstack[PATRICIA_MAXBITS+1]; \
|
||||
ndpi_patricia_node_t **Xsp = Xstack; \
|
||||
ndpi_patricia_node_t *Xrn = (Xhead); \
|
||||
while ((Xnode = Xrn)) { \
|
||||
if (Xnode->prefix)
|
||||
|
||||
#define PATRICIA_WALK_ALL(Xhead, Xnode) \
|
||||
do { \
|
||||
patricia_node_t *Xstack[PATRICIA_MAXBITS+1]; \
|
||||
patricia_node_t **Xsp = Xstack; \
|
||||
patricia_node_t *Xrn = (Xhead); \
|
||||
ndpi_patricia_node_t *Xstack[PATRICIA_MAXBITS+1]; \
|
||||
ndpi_patricia_node_t **Xsp = Xstack; \
|
||||
ndpi_patricia_node_t *Xrn = (Xhead); \
|
||||
while ((Xnode = Xrn)) { \
|
||||
if (1)
|
||||
|
||||
@@ -176,7 +145,7 @@ void ndpi_patricia_process (patricia_tree_t *patricia, void_fn2_t func);
|
||||
if (Xsp != Xstack) { \
|
||||
Xrn = *(--Xsp); \
|
||||
} else { \
|
||||
Xrn = (patricia_node_t *) 0; \
|
||||
Xrn = (ndpi_patricia_node_t *) 0; \
|
||||
} \
|
||||
continue; }
|
||||
|
||||
@@ -191,7 +160,7 @@ void ndpi_patricia_process (patricia_tree_t *patricia, void_fn2_t func);
|
||||
} else if (Xsp != Xstack) { \
|
||||
Xrn = *(--Xsp); \
|
||||
} else { \
|
||||
Xrn = (patricia_node_t *) 0; \
|
||||
Xrn = (ndpi_patricia_node_t *) 0; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
+123
-74
@@ -54,7 +54,6 @@
|
||||
#include <arpa/inet.h> /* BSD, Linux, Solaris: for inet_addr */
|
||||
#endif
|
||||
#include "ndpi_patricia.h"
|
||||
#include "ndpi_api.h"
|
||||
|
||||
static void ndpi_DeleteEntry(void *a) {
|
||||
ndpi_free(a);
|
||||
@@ -65,11 +64,19 @@ static void ndpi_DeleteEntry(void *a) {
|
||||
/* ndpi_prefix_tochar
|
||||
* convert prefix information to bytes
|
||||
*/
|
||||
static u_char* ndpi_prefix_tochar (prefix_t * prefix)
|
||||
static u_char* ndpi_prefix_tochar (ndpi_prefix_t * prefix)
|
||||
{
|
||||
unsigned short family;
|
||||
|
||||
if(prefix == NULL)
|
||||
return (NULL);
|
||||
|
||||
family = prefix->family;
|
||||
|
||||
if(family == AF_INET) return ((u_char *) & prefix->add.sin);
|
||||
else if(family == AF_INET6) return ((u_char *) & prefix->add.sin6);
|
||||
else /* if(family == AF_MAC) */ return ((u_char *) & prefix->add.mac);
|
||||
|
||||
return ((u_char *) & prefix->add.sin);
|
||||
}
|
||||
|
||||
@@ -115,10 +122,10 @@ static int ndpi_my_inet_pton (int af, const char *src, void *dst)
|
||||
}
|
||||
memcpy (dst, xp, sizeof(struct in_addr));
|
||||
return (1);
|
||||
#if defined(PATRICIA_IPV6)
|
||||
#if defined(NDPI_PATRICIA_IPV6)
|
||||
} else if(af == AF_INET6) {
|
||||
return (inet_pton (af, src, dst));
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
#endif /* NDPI_PATRICIA_IPV6 */
|
||||
} else {
|
||||
#ifndef NT
|
||||
errno = EAFNOSUPPORT;
|
||||
@@ -135,7 +142,7 @@ static int ndpi_my_inet_pton (int af, const char *src, void *dst)
|
||||
* convert prefix information to ascii string with length
|
||||
* thread safe and (almost) re-entrant implementation
|
||||
*/
|
||||
static char * ndpi_prefix_toa2x (prefix_t *prefix, char *buff, int with_len)
|
||||
static char * ndpi_prefix_toa2x (ndpi_prefix_t *prefix, char *buff, int with_len)
|
||||
{
|
||||
if(prefix == NULL)
|
||||
return ((char*)"(Null)");
|
||||
@@ -165,7 +172,7 @@ static char * ndpi_prefix_toa2x (prefix_t *prefix, char *buff, int with_len)
|
||||
if(prefix->family == AF_INET) {
|
||||
u_char *a;
|
||||
assert (prefix->bitlen <= sizeof(struct in_addr) * 8);
|
||||
a = prefix_touchar (prefix);
|
||||
a = ndpi_prefix_touchar (prefix);
|
||||
if(with_len) {
|
||||
sprintf (buff, "%d.%d.%d.%d/%d", a[0], a[1], a[2], a[3],
|
||||
prefix->bitlen);
|
||||
@@ -175,7 +182,7 @@ static char * ndpi_prefix_toa2x (prefix_t *prefix, char *buff, int with_len)
|
||||
}
|
||||
return (buff);
|
||||
}
|
||||
#if defined(PATRICIA_IPV6)
|
||||
#if defined(NDPI_PATRICIA_IPV6)
|
||||
else if(prefix->family == AF_INET6) {
|
||||
char *r;
|
||||
r = (char *) inet_ntop (AF_INET6, &prefix->add.sin6, buff, 48 /* a guess value */ );
|
||||
@@ -185,7 +192,7 @@ static char * ndpi_prefix_toa2x (prefix_t *prefix, char *buff, int with_len)
|
||||
}
|
||||
return (buff);
|
||||
}
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
#endif /* NDPI_PATRICIA_IPV6 */
|
||||
else
|
||||
return (NULL);
|
||||
}
|
||||
@@ -193,43 +200,43 @@ static char * ndpi_prefix_toa2x (prefix_t *prefix, char *buff, int with_len)
|
||||
/* ndpi_prefix_toa2
|
||||
* convert prefix information to ascii string
|
||||
*/
|
||||
static char * ndpi_prefix_toa2 (prefix_t *prefix, char *buff)
|
||||
static char * ndpi_prefix_toa2 (ndpi_prefix_t *prefix, char *buff)
|
||||
{
|
||||
return (ndpi_prefix_toa2x (prefix, buff, 0));
|
||||
}
|
||||
|
||||
/* ndpi_prefix_toa
|
||||
*/
|
||||
static char * ndpi_prefix_toa (prefix_t * prefix)
|
||||
static char * ndpi_prefix_toa (ndpi_prefix_t * prefix)
|
||||
{
|
||||
return (ndpi_prefix_toa2 (prefix, (char *) NULL));
|
||||
}
|
||||
#endif
|
||||
|
||||
static prefix_t * ndpi_New_Prefix2 (int family, void *dest, int bitlen, prefix_t *prefix)
|
||||
static ndpi_prefix_t * ndpi_New_Prefix2 (int family, void *dest, int bitlen, ndpi_prefix_t *prefix)
|
||||
{
|
||||
int dynamic_allocated = 0;
|
||||
int default_bitlen = sizeof(struct in_addr) * 8;
|
||||
|
||||
#if defined(PATRICIA_IPV6)
|
||||
#if defined(NDPI_PATRICIA_IPV6)
|
||||
if(family == AF_INET6) {
|
||||
default_bitlen = sizeof(struct in6_addr) * 8;
|
||||
if(prefix == NULL) {
|
||||
prefix = (prefix_t*)ndpi_calloc(1, sizeof (prefix_t));
|
||||
prefix = (ndpi_prefix_t*)ndpi_calloc(1, sizeof (ndpi_prefix_t));
|
||||
dynamic_allocated++;
|
||||
}
|
||||
memcpy (&prefix->add.sin6, dest, sizeof(struct in6_addr));
|
||||
}
|
||||
else
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
#endif /* NDPI_PATRICIA_IPV6 */
|
||||
if(family == AF_INET) {
|
||||
if(prefix == NULL) {
|
||||
#ifndef NT
|
||||
prefix = (prefix_t*)ndpi_calloc(1, sizeof (prefix4_t));
|
||||
prefix = (ndpi_prefix_t*)ndpi_calloc(1, sizeof (prefix4_t));
|
||||
#else
|
||||
//for some reason, compiler is getting
|
||||
//prefix4_t size incorrect on NT
|
||||
prefix = ndpi_calloc(1, sizeof (prefix_t));
|
||||
prefix = ndpi_calloc(1, sizeof (ndpi_prefix_t));
|
||||
#endif /* NT */
|
||||
|
||||
dynamic_allocated++;
|
||||
@@ -251,14 +258,14 @@ static prefix_t * ndpi_New_Prefix2 (int family, void *dest, int bitlen, prefix_t
|
||||
}
|
||||
|
||||
#if 0
|
||||
static prefix_t * ndpi_New_Prefix (int family, void *dest, int bitlen)
|
||||
static ndpi_prefix_t * ndpi_New_Prefix (int family, void *dest, int bitlen)
|
||||
{
|
||||
return (ndpi_New_Prefix2 (family, dest, bitlen, NULL));
|
||||
}
|
||||
#endif
|
||||
|
||||
static prefix_t *
|
||||
ndpi_Ref_Prefix (prefix_t * prefix)
|
||||
static ndpi_prefix_t *
|
||||
ndpi_Ref_Prefix (ndpi_prefix_t * prefix)
|
||||
{
|
||||
if(prefix == NULL)
|
||||
return (NULL);
|
||||
@@ -272,7 +279,7 @@ ndpi_Ref_Prefix (prefix_t * prefix)
|
||||
}
|
||||
|
||||
static void
|
||||
ndpi_Deref_Prefix (prefix_t * prefix)
|
||||
ndpi_Deref_Prefix (ndpi_prefix_t * prefix)
|
||||
{
|
||||
if(prefix == NULL)
|
||||
return;
|
||||
@@ -293,10 +300,10 @@ static int num_active_patricia = 0;
|
||||
|
||||
/* these routines support continuous mask only */
|
||||
|
||||
patricia_tree_t *
|
||||
ndpi_New_Patricia (u_int16_t maxbits)
|
||||
ndpi_patricia_tree_t *
|
||||
ndpi_patricia_new (u_int16_t maxbits)
|
||||
{
|
||||
patricia_tree_t *patricia = (patricia_tree_t*)ndpi_calloc(1, sizeof *patricia);
|
||||
ndpi_patricia_tree_t *patricia = (ndpi_patricia_tree_t*)ndpi_calloc(1, sizeof *patricia);
|
||||
|
||||
patricia->maxbits = maxbits;
|
||||
patricia->head = NULL;
|
||||
@@ -312,18 +319,18 @@ ndpi_New_Patricia (u_int16_t maxbits)
|
||||
* before deleting the node
|
||||
*/
|
||||
void
|
||||
ndpi_Clear_Patricia (patricia_tree_t *patricia, void_fn_t func)
|
||||
ndpi_Clear_Patricia (ndpi_patricia_tree_t *patricia, ndpi_void_fn_t func)
|
||||
{
|
||||
assert (patricia);
|
||||
if(patricia->head) {
|
||||
|
||||
patricia_node_t *Xstack[PATRICIA_MAXBITS+1];
|
||||
patricia_node_t **Xsp = Xstack;
|
||||
patricia_node_t *Xrn = patricia->head;
|
||||
ndpi_patricia_node_t *Xstack[PATRICIA_MAXBITS+1];
|
||||
ndpi_patricia_node_t **Xsp = Xstack;
|
||||
ndpi_patricia_node_t *Xrn = patricia->head;
|
||||
|
||||
while (Xrn) {
|
||||
patricia_node_t *l = Xrn->l;
|
||||
patricia_node_t *r = Xrn->r;
|
||||
ndpi_patricia_node_t *l = Xrn->l;
|
||||
ndpi_patricia_node_t *r = Xrn->r;
|
||||
|
||||
if(Xrn->prefix) {
|
||||
ndpi_Deref_Prefix (Xrn->prefix);
|
||||
@@ -354,9 +361,8 @@ ndpi_Clear_Patricia (patricia_tree_t *patricia, void_fn_t func)
|
||||
/* ndpi_DeleteEntry (patricia); */
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ndpi_Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func)
|
||||
ndpi_patricia_destroy (ndpi_patricia_tree_t *patricia, ndpi_void_fn_t func)
|
||||
{
|
||||
ndpi_Clear_Patricia (patricia, func);
|
||||
ndpi_DeleteEntry (patricia);
|
||||
@@ -368,9 +374,9 @@ ndpi_Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func)
|
||||
* if func is supplied, it will be called as func(node->prefix, node->data)
|
||||
*/
|
||||
void
|
||||
ndpi_patricia_process (patricia_tree_t *patricia, void_fn2_t func)
|
||||
ndpi_patricia_process (ndpi_patricia_tree_t *patricia, ndpi_void_fn2_t func)
|
||||
{
|
||||
patricia_node_t *node;
|
||||
ndpi_patricia_node_t *node;
|
||||
assert (func);
|
||||
|
||||
PATRICIA_WALK (patricia->head, node) {
|
||||
@@ -378,8 +384,51 @@ ndpi_patricia_process (patricia_tree_t *patricia, void_fn2_t func)
|
||||
} PATRICIA_WALK_END;
|
||||
}
|
||||
|
||||
static size_t
|
||||
ndpi_patricia_clone_walk(ndpi_patricia_node_t *node, ndpi_patricia_tree_t *dst)
|
||||
{
|
||||
ndpi_patricia_node_t *cloned_node;
|
||||
size_t n = 0;
|
||||
|
||||
if(node->l) {
|
||||
n += ndpi_patricia_clone_walk(node->l, dst);
|
||||
}
|
||||
|
||||
if(node->prefix) {
|
||||
cloned_node = ndpi_patricia_lookup(dst, node->prefix);
|
||||
|
||||
if(cloned_node) {
|
||||
/* Note: this is not cloning clone referenced void * data / user_data */
|
||||
memcpy(&cloned_node->value, &node->value, sizeof(cloned_node->value));
|
||||
}
|
||||
|
||||
n++;
|
||||
}
|
||||
|
||||
if(node->r) {
|
||||
n += ndpi_patricia_clone_walk(node->r, dst);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
ndpi_patricia_tree_t *
|
||||
ndpi_patricia_clone (const ndpi_patricia_tree_t * const from)
|
||||
{
|
||||
if(!from) return (NULL);
|
||||
|
||||
ndpi_patricia_tree_t *patricia = ndpi_patricia_new(from->maxbits);
|
||||
|
||||
if(!patricia) return (NULL);
|
||||
|
||||
if(from->head)
|
||||
ndpi_patricia_clone_walk(from->head, patricia);
|
||||
|
||||
return (patricia);
|
||||
}
|
||||
|
||||
size_t
|
||||
ndpi_patricia_walk_inorder(patricia_node_t *node, void_fn2_t func)
|
||||
ndpi_patricia_walk_inorder(ndpi_patricia_node_t *node, ndpi_void_fn2_t func)
|
||||
{
|
||||
size_t n = 0;
|
||||
assert(func);
|
||||
@@ -401,10 +450,10 @@ ndpi_patricia_walk_inorder(patricia_node_t *node, void_fn2_t func)
|
||||
}
|
||||
|
||||
|
||||
patricia_node_t *
|
||||
ndpi_patricia_search_exact (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
ndpi_patricia_node_t *
|
||||
ndpi_patricia_search_exact (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
||||
{
|
||||
patricia_node_t *node;
|
||||
ndpi_patricia_node_t *node;
|
||||
u_char *addr;
|
||||
u_int16_t bitlen;
|
||||
|
||||
@@ -416,7 +465,7 @@ ndpi_patricia_search_exact (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
return (NULL);
|
||||
|
||||
node = patricia->head;
|
||||
addr = prefix_touchar (prefix);
|
||||
addr = ndpi_prefix_touchar (prefix);
|
||||
bitlen = prefix->bitlen;
|
||||
|
||||
while (node->bit < bitlen) {
|
||||
@@ -474,11 +523,11 @@ ndpi_patricia_search_exact (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
|
||||
|
||||
/* if inclusive != 0, "best" may be the given prefix itself */
|
||||
patricia_node_t *
|
||||
ndpi_patricia_search_best2 (patricia_tree_t *patricia, prefix_t *prefix, int inclusive)
|
||||
ndpi_patricia_node_t *
|
||||
ndpi_patricia_search_best2 (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix, int inclusive)
|
||||
{
|
||||
patricia_node_t *node;
|
||||
patricia_node_t *stack[PATRICIA_MAXBITS + 1];
|
||||
ndpi_patricia_node_t *node;
|
||||
ndpi_patricia_node_t *stack[PATRICIA_MAXBITS + 1];
|
||||
u_char *addr;
|
||||
u_int16_t bitlen;
|
||||
int cnt = 0;
|
||||
@@ -491,7 +540,7 @@ ndpi_patricia_search_best2 (patricia_tree_t *patricia, prefix_t *prefix, int inc
|
||||
return (NULL);
|
||||
|
||||
node = patricia->head;
|
||||
addr = prefix_touchar (prefix);
|
||||
addr = ndpi_prefix_touchar (prefix);
|
||||
bitlen = prefix->bitlen;
|
||||
|
||||
while (node->bit < bitlen) {
|
||||
@@ -571,17 +620,17 @@ ndpi_patricia_search_best2 (patricia_tree_t *patricia, prefix_t *prefix, int inc
|
||||
}
|
||||
|
||||
|
||||
patricia_node_t *
|
||||
ndpi_patricia_search_best (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
ndpi_patricia_node_t *
|
||||
ndpi_patricia_search_best (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
||||
{
|
||||
return (ndpi_patricia_search_best2 (patricia, prefix, 1));
|
||||
}
|
||||
|
||||
|
||||
patricia_node_t *
|
||||
ndpi_patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
ndpi_patricia_node_t *
|
||||
ndpi_patricia_lookup (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
||||
{
|
||||
patricia_node_t *node, *new_node, *parent, *glue;
|
||||
ndpi_patricia_node_t *node, *new_node, *parent, *glue;
|
||||
u_char *addr, *test_addr;
|
||||
u_int16_t bitlen, check_bit, differ_bit;
|
||||
int i, j;
|
||||
@@ -596,7 +645,7 @@ ndpi_patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
assert (prefix->bitlen <= patricia->maxbits);
|
||||
|
||||
if(patricia->head == NULL) {
|
||||
node = (patricia_node_t*)ndpi_calloc(1, sizeof *node);
|
||||
node = (ndpi_patricia_node_t*)ndpi_calloc(1, sizeof *node);
|
||||
node->bit = prefix->bitlen;
|
||||
node->prefix = ndpi_Ref_Prefix (prefix);
|
||||
node->parent = NULL;
|
||||
@@ -611,7 +660,7 @@ ndpi_patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
return (node);
|
||||
}
|
||||
|
||||
addr = prefix_touchar (prefix);
|
||||
addr = ndpi_prefix_touchar (prefix);
|
||||
bitlen = prefix->bitlen;
|
||||
node = patricia->head;
|
||||
|
||||
@@ -651,7 +700,7 @@ ndpi_patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
ndpi_prefix_toa (node->prefix), node->prefix->bitlen);
|
||||
#endif /* PATRICIA_DEBUG */
|
||||
|
||||
test_addr = prefix_touchar (node->prefix);
|
||||
test_addr = ndpi_prefix_touchar (node->prefix);
|
||||
/* find the first bit different */
|
||||
check_bit = (node->bit < bitlen)? node->bit: bitlen;
|
||||
differ_bit = 0;
|
||||
@@ -709,7 +758,7 @@ ndpi_patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
return (node);
|
||||
}
|
||||
|
||||
new_node = (patricia_node_t*)ndpi_calloc(1, sizeof *new_node);
|
||||
new_node = (ndpi_patricia_node_t*)ndpi_calloc(1, sizeof *new_node);
|
||||
if(!new_node) return NULL;
|
||||
new_node->bit = prefix->bitlen;
|
||||
new_node->prefix = ndpi_Ref_Prefix (prefix);
|
||||
@@ -762,7 +811,7 @@ ndpi_patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
#endif /* PATRICIA_DEBUG */
|
||||
}
|
||||
else {
|
||||
glue = (patricia_node_t*)ndpi_calloc(1, sizeof *glue);
|
||||
glue = (ndpi_patricia_node_t*)ndpi_calloc(1, sizeof *glue);
|
||||
|
||||
if(!glue) return(NULL);
|
||||
glue->bit = differ_bit;
|
||||
@@ -802,9 +851,9 @@ ndpi_patricia_lookup (patricia_tree_t *patricia, prefix_t *prefix)
|
||||
|
||||
|
||||
void
|
||||
ndpi_patricia_remove (patricia_tree_t *patricia, patricia_node_t *node)
|
||||
ndpi_patricia_remove (ndpi_patricia_tree_t *patricia, ndpi_patricia_node_t *node)
|
||||
{
|
||||
patricia_node_t *parent, *child;
|
||||
ndpi_patricia_node_t *parent, *child;
|
||||
|
||||
assert (patricia);
|
||||
assert (node);
|
||||
@@ -910,15 +959,15 @@ ndpi_patricia_remove (patricia_tree_t *patricia, patricia_node_t *node)
|
||||
#if 0
|
||||
|
||||
/* ndpi_ascii2prefix */
|
||||
static prefix_t * ndpi_ascii2prefix (int family, char *string)
|
||||
static ndpi_prefix_t * ndpi_ascii2prefix (int family, char *string)
|
||||
{
|
||||
long bitlen;
|
||||
long maxbitlen = 0;
|
||||
char *cp;
|
||||
struct in_addr sin;
|
||||
#if defined(PATRICIA_IPV6)
|
||||
#if defined(NDPI_PATRICIA_IPV6)
|
||||
struct in6_addr sin6;
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
#endif /* NDPI_PATRICIA_IPV6 */
|
||||
char save[MAXLINE];
|
||||
|
||||
if(string == NULL)
|
||||
@@ -927,19 +976,19 @@ static prefix_t * ndpi_ascii2prefix (int family, char *string)
|
||||
/* easy way to handle both families */
|
||||
if(family == 0) {
|
||||
family = AF_INET;
|
||||
#if defined(PATRICIA_IPV6)
|
||||
#if defined(NDPI_PATRICIA_IPV6)
|
||||
if(strchr (string, ':')) family = AF_INET6;
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
#endif /* NDPI_PATRICIA_IPV6 */
|
||||
}
|
||||
|
||||
if(family == AF_INET) {
|
||||
maxbitlen = sizeof(struct in_addr) * 8;
|
||||
}
|
||||
#if defined(PATRICIA_IPV6)
|
||||
#if defined(NDPI_PATRICIA_IPV6)
|
||||
else if(family == AF_INET6) {
|
||||
maxbitlen = sizeof(struct in6_addr) * 8;
|
||||
}
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
#endif /* NDPI_PATRICIA_IPV6 */
|
||||
|
||||
if((cp = strchr (string, '/')) != NULL) {
|
||||
bitlen = atol (cp + 1);
|
||||
@@ -961,7 +1010,7 @@ static prefix_t * ndpi_ascii2prefix (int family, char *string)
|
||||
return (ndpi_New_Prefix (AF_INET, &sin, bitlen));
|
||||
}
|
||||
|
||||
#if defined(PATRICIA_IPV6)
|
||||
#if defined(NDPI_PATRICIA_IPV6)
|
||||
else if(family == AF_INET6) {
|
||||
// Get rid of this with next IPv6 upgrade
|
||||
#if defined(NT) && !defined(HAVE_INET_NTOP)
|
||||
@@ -973,16 +1022,16 @@ static prefix_t * ndpi_ascii2prefix (int family, char *string)
|
||||
#endif /* NT */
|
||||
return (ndpi_New_Prefix (AF_INET6, &sin6, bitlen));
|
||||
}
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
#endif /* NDPI_PATRICIA_IPV6 */
|
||||
else
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
patricia_node_t *
|
||||
ndpi_make_and_lookup (patricia_tree_t *tree, char *string)
|
||||
ndpi_patricia_node_t *
|
||||
ndpi_make_and_lookup (ndpi_patricia_tree_t *tree, char *string)
|
||||
{
|
||||
prefix_t *prefix;
|
||||
patricia_node_t *node;
|
||||
ndpi_prefix_t *prefix;
|
||||
ndpi_patricia_node_t *node;
|
||||
|
||||
prefix = ndpi_ascii2prefix (AF_INET, string);
|
||||
printf ("make_and_lookup: %s/%d\n", ndpi_prefix_toa (prefix), prefix->bitlen);
|
||||
@@ -991,11 +1040,11 @@ ndpi_make_and_lookup (patricia_tree_t *tree, char *string)
|
||||
return (node);
|
||||
}
|
||||
|
||||
patricia_node_t *
|
||||
ndpi_try_search_exact (patricia_tree_t *tree, char *string)
|
||||
ndpi_patricia_node_t *
|
||||
ndpi_try_search_exact (ndpi_patricia_tree_t *tree, char *string)
|
||||
{
|
||||
prefix_t *prefix;
|
||||
patricia_node_t *node;
|
||||
ndpi_prefix_t *prefix;
|
||||
ndpi_patricia_node_t *node;
|
||||
|
||||
prefix = ndpi_ascii2prefix (AF_INET, string);
|
||||
printf ("try_search_exact: %s/%d\n", ndpi_prefix_toa (prefix), prefix->bitlen);
|
||||
@@ -1011,9 +1060,9 @@ ndpi_try_search_exact (patricia_tree_t *tree, char *string)
|
||||
}
|
||||
|
||||
void
|
||||
ndpi_lookup_then_remove (patricia_tree_t *tree, char *string)
|
||||
ndpi_lookup_then_remove (ndpi_patricia_tree_t *tree, char *string)
|
||||
{
|
||||
patricia_node_t *node;
|
||||
ndpi_patricia_node_t *node;
|
||||
|
||||
if((node = try_search_exact (tree, string)))
|
||||
patricia_remove (tree, node);
|
||||
|
||||
Reference in New Issue
Block a user