aboutsummaryrefslogtreecommitdiffstats
path: root/src/fnettrace/radix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fnettrace/radix.c')
-rw-r--r--src/fnettrace/radix.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/fnettrace/radix.c b/src/fnettrace/radix.c
index a1f44dd31..d68aaf85c 100644
--- a/src/fnettrace/radix.c
+++ b/src/fnettrace/radix.c
@@ -26,6 +26,7 @@
26#include "fnettrace.h" 26#include "fnettrace.h"
27 27
28RNode *head = 0; 28RNode *head = 0;
29int radix_nodes = 0;
29 30
30static inline RNode *addOne(RNode *ptr, uint32_t ip, uint32_t mask, char *name) { 31static inline RNode *addOne(RNode *ptr, uint32_t ip, uint32_t mask, char *name) {
31 assert(ptr); 32 assert(ptr);
@@ -34,6 +35,7 @@ static inline RNode *addOne(RNode *ptr, uint32_t ip, uint32_t mask, char *name)
34 RNode *node = malloc(sizeof(RNode)); 35 RNode *node = malloc(sizeof(RNode));
35 if (!node) 36 if (!node)
36 errExit("malloc"); 37 errExit("malloc");
38 radix_nodes++;
37 memset(node, 0, sizeof(RNode)); 39 memset(node, 0, sizeof(RNode));
38 node->ip = ip; 40 node->ip = ip;
39 node->mask = mask; 41 node->mask = mask;
@@ -42,7 +44,7 @@ static inline RNode *addOne(RNode *ptr, uint32_t ip, uint32_t mask, char *name)
42 if (!node->name) 44 if (!node->name)
43 errExit("strdup"); 45 errExit("strdup");
44 } 46 }
45 47
46 ptr->one = node; 48 ptr->one = node;
47 return node; 49 return node;
48} 50}
@@ -62,7 +64,7 @@ static inline RNode *addZero(RNode *ptr, uint32_t ip, uint32_t mask, char *name)
62 if (!node->name) 64 if (!node->name)
63 errExit("strdup"); 65 errExit("strdup");
64 } 66 }
65 67
66 ptr->zero = node; 68 ptr->zero = node;
67 return node; 69 return node;
68} 70}
@@ -146,13 +148,13 @@ char *radix_find_last(uint32_t ip) {
146 if (ptr->name) 148 if (ptr->name)
147 rv = ptr; 149 rv = ptr;
148 } 150 }
149 151
150 return (rv)? rv->name: NULL; 152 return (rv)? rv->name: NULL;
151} 153}
152 154
153static void radix_print_node(RNode *ptr, int level) { 155static void radix_print_node(RNode *ptr, int level) {
154 assert(ptr); 156 assert(ptr);
155 157
156 int i; 158 int i;
157 for (i = 0; i < level; i++) 159 for (i = 0; i < level; i++)
158 printf(" "); 160 printf(" ");
@@ -173,7 +175,7 @@ void radix_print(void) {
173 printf("radix tree is empty\n"); 175 printf("radix tree is empty\n");
174 return; 176 return;
175 } 177 }
176 178
177 printf("radix IPv4 tree\n"); 179 printf("radix IPv4 tree\n");
178 radix_print_node(head, 0); 180 radix_print_node(head, 0);
179} 181}
@@ -187,14 +189,14 @@ static inline int mask2cidr(uint32_t mask) {
187 if (mask & m) 189 if (mask & m)
188 cnt++; 190 cnt++;
189 } 191 }
190 192
191 return cnt; 193 return cnt;
192} 194}
193 195
194static void radix_build_list_node(RNode *ptr) { 196static void radix_build_list_node(RNode *ptr) {
195 assert(ptr); 197 assert(ptr);
196 198
197 199
198 if (ptr->name) { 200 if (ptr->name) {
199 printf("%d.%d.%d.%d/%d %s\n", PRINT_IP(ptr->ip), mask2cidr(ptr->mask), ptr->name); 201 printf("%d.%d.%d.%d/%d %s\n", PRINT_IP(ptr->ip), mask2cidr(ptr->mask), ptr->name);
200 return; 202 return;
@@ -213,6 +215,6 @@ void radix_build_list(void) {
213 return; 215 return;
214 } 216 }
215 217
216 radix_build_list_node(head); 218 radix_build_list_node(head);
217} 219}
218 220