1 From 4b91b102eb6edb63472728dd3545e3dff800a5a0 Mon Sep 17 00:00:00 2001
2 From: Nick Hainke <vincent@systemli.org>
3 Date: Sat, 15 Jan 2022 16:13:24 +0100
4 Subject: [PATCH] rename avl to olsrd_avl
7 lib/nameservice/src/nameservice.c | 4 +-
8 lib/netjson/src/olsrd_netjson.c | 12 +-
9 lib/netjson/src/olsrd_netjson_helpers.c | 74 +++++-----
10 lib/netjson/src/olsrd_netjson_helpers.h | 18 +--
11 src/common/{avl.c => olsrd_avl.c} | 184 ++++++++++++------------
12 src/common/{avl.h => olsrd_avl.h} | 90 ++++++------
13 src/duplicate_set.c | 18 +--
14 src/duplicate_set.h | 12 +-
15 src/gateway.c | 18 +--
16 src/gateway.h | 16 +--
17 src/kernel_tunnel.h | 4 +-
18 src/linux/kernel_tunnel.c | 12 +-
19 src/lq_packet.c | 6 +-
20 src/lq_plugin.c | 14 +-
21 src/lq_plugin.h | 14 +-
23 src/olsr_spf.c | 36 ++---
24 src/process_routes.c | 22 +--
25 src/routing_table.c | 56 ++++----
26 src/routing_table.h | 36 ++---
27 src/scheduler.c | 30 ++--
28 src/tc_set.c | 30 ++--
29 src/tc_set.h | 38 ++---
30 24 files changed, 390 insertions(+), 390 deletions(-)
31 rename src/common/{avl.c => olsrd_avl.c} (67%)
32 rename src/common/{avl.h => olsrd_avl.h} (58%)
33 --- a/lib/nameservice/src/nameservice.c
34 +++ b/lib/nameservice/src/nameservice.c
35 @@ -1621,13 +1621,13 @@ void
36 lookup_defhna_latlon(union olsr_ip_addr *ip)
39 - struct avl_node *rt_tree_node;
40 + struct olsrd_avl_node *rt_tree_node;
41 struct olsr_ip_prefix prefix;
43 memset(ip, 0, sizeof(*ip));
44 memset(&prefix, 0, sizeof(prefix));
46 - if (NULL != (rt_tree_node = avl_find(&routingtree, &prefix))) {
47 + if (NULL != (rt_tree_node = olsrd_avl_find(&routingtree, &prefix))) {
48 rt = rt_tree2rt(rt_tree_node);
49 *ip = rt->rt_best->rtp_nexthop.gateway;
51 --- a/lib/netjson/src/olsrd_netjson.c
52 +++ b/lib/netjson/src/olsrd_netjson.c
54 #include "info/info_types.h"
55 #include "info/http_headers.h"
56 #include "info/json_helpers.h"
57 -#include "common/avl.h"
58 +#include "common/olsrd_avl.h"
60 #include "builddata.h"
61 #include "routing_table.h"
62 @@ -161,7 +161,7 @@ void ipc_print_network_routes(struct aut
65 void ipc_print_network_graph(struct autobuf *abuf) {
66 - struct avl_tree nodes;
67 + struct olsrd_avl_tree nodes;
68 struct mid_entry mid_self;
69 struct node_entry * node_self;
71 @@ -169,7 +169,7 @@ void ipc_print_network_graph(struct auto
72 struct neighbor_entry * neighbor;
75 - avl_init(&nodes, (olsr_cnf->ip_version == AF_INET) ? avl_comp_ipv4 : avl_comp_ipv6);
76 + olsrd_avl_init(&nodes, (olsr_cnf->ip_version == AF_INET) ? olsrd_avl_comp_ipv4 : olsrd_avl_comp_ipv6);
79 abuf_json_string(&json_session, abuf, "type", "NetworkGraph");
80 @@ -226,8 +226,8 @@ void ipc_print_network_graph(struct auto
82 abuf_json_mark_object(&json_session, true, true, abuf, "nodes");
83 while (nodes.count > 0) {
84 - struct avl_node *node = avl_walk_first(&nodes);
85 - struct node_entry *node_entry = avlnode2node(node);
86 + struct olsrd_avl_node *node = olsrd_avl_walk_first(&nodes);
87 + struct node_entry *node_entry = olsrd_avlnode2node(node);
89 if (!node_entry->isAlias) {
90 abuf_json_mark_array_entry(&json_session, true, abuf);
91 @@ -265,7 +265,7 @@ void ipc_print_network_graph(struct auto
92 netjson_cleanup_mid_self(node_self);
95 - avl_delete(&nodes, node);
96 + olsrd_avl_delete(&nodes, node);
99 abuf_json_mark_object(&json_session, false, true, abuf, NULL);
100 --- a/lib/netjson/src/olsrd_netjson_helpers.c
101 +++ b/lib/netjson/src/olsrd_netjson_helpers.c
102 @@ -57,7 +57,7 @@ struct node_entry * netjson_constructMid
104 node_self = olsr_malloc(sizeof(struct node_entry), "netjson NetworkGraph node - MID - self");
105 memset(node_self, 0, sizeof(*node_self));
106 - node_self->avl.key = &olsr_cnf->main_addr;
107 + node_self->olsrd_avl.key = &olsr_cnf->main_addr;
108 node_self->isAlias = false;
109 node_self->mid = mid;
111 @@ -93,7 +93,7 @@ struct node_entry * netjson_constructMid
113 node_self_alias = olsr_malloc(sizeof(struct node_entry), "netjson NetworkGraph node - MID - self alias");
114 memset(node_self_alias, 0, sizeof(*node_self_alias));
115 - node_self_alias->avl.key = addr;
116 + node_self_alias->olsrd_avl.key = addr;
117 node_self_alias->isAlias = true;
118 node_self_alias->mid = mid;
120 @@ -112,7 +112,7 @@ struct node_entry * netjson_constructMid
123 void netjson_cleanup_mid_self(struct node_entry *node_entry) {
124 - if (node_entry->avl.key != &olsr_cnf->main_addr) {
125 + if (node_entry->olsrd_avl.key != &olsr_cnf->main_addr) {
129 @@ -123,21 +123,21 @@ void netjson_cleanup_mid_self(struct nod
133 -void netjson_midIntoNodesTree(struct avl_tree *nodes, struct mid_entry *mid) {
134 - struct avl_node *avlnode;
135 +void netjson_midIntoNodesTree(struct olsrd_avl_tree *nodes, struct mid_entry *mid) {
136 + struct olsrd_avl_node *olsrd_avlnode;
137 struct node_entry *node;
138 struct mid_address *alias;
140 - avlnode = avl_find(nodes, &mid->main_addr);
142 + olsrd_avlnode = olsrd_avl_find(nodes, &mid->main_addr);
143 + if (!olsrd_avlnode) {
144 /* the IP address is not yet known */
146 node = olsr_malloc(sizeof(struct node_entry), "netjson NetworkGraph node - MID - main");
147 memset(node, 0, sizeof(*node));
148 - node->avl.key = &mid->main_addr;
149 + node->olsrd_avl.key = &mid->main_addr;
150 node->isAlias = false;
152 - if (avl_insert(nodes, &node->avl, AVL_DUP_NO) == -1) {
153 + if (olsrd_avl_insert(nodes, &node->olsrd_avl, OLSRD_AVL_DUP_NO) == -1) {
157 @@ -145,16 +145,16 @@ void netjson_midIntoNodesTree(struct avl
159 alias = mid->aliases;
161 - avlnode = avl_find(nodes, &alias->alias);
163 + olsrd_avlnode = olsrd_avl_find(nodes, &alias->alias);
164 + if (!olsrd_avlnode) {
165 /* the IP address is not yet known */
167 node = olsr_malloc(sizeof(struct node_entry), "netjson NetworkGraph node - MID - alias");
168 memset(node, 0, sizeof(*node));
169 - node->avl.key = &alias->alias;
170 + node->olsrd_avl.key = &alias->alias;
171 node->isAlias = true;
173 - if (avl_insert(nodes, &node->avl, AVL_DUP_NO) == -1) {
174 + if (olsrd_avl_insert(nodes, &node->olsrd_avl, OLSRD_AVL_DUP_NO) == -1) {
178 @@ -164,12 +164,12 @@ void netjson_midIntoNodesTree(struct avl
182 -void netjson_tcIntoNodesTree(struct avl_tree *nodes, struct tc_entry *tc) {
183 - struct avl_node *avlnode;
184 +void netjson_tcIntoNodesTree(struct olsrd_avl_tree *nodes, struct tc_entry *tc) {
185 + struct olsrd_avl_node *olsrd_avlnode;
186 struct node_entry *node;
188 - avlnode = avl_find(nodes, &tc->addr);
190 + olsrd_avlnode = olsrd_avl_find(nodes, &tc->addr);
191 + if (olsrd_avlnode) {
192 /* the IP address is already known */
195 @@ -178,21 +178,21 @@ void netjson_tcIntoNodesTree(struct avl_
197 node = olsr_malloc(sizeof(struct node_entry), "netjson NetworkGraph node - TC - main");
198 memset(node, 0, sizeof(*node));
199 - node->avl.key = &tc->addr;
200 + node->olsrd_avl.key = &tc->addr;
201 node->isAlias = false;
203 - if (avl_insert(nodes, &node->avl, AVL_DUP_NO) == -1) {
204 + if (olsrd_avl_insert(nodes, &node->olsrd_avl, OLSRD_AVL_DUP_NO) == -1) {
210 -void netjson_tcEdgeIntoNodesTree(struct avl_tree *nodes, struct tc_edge_entry *tc_edge) {
211 - struct avl_node *avlnode;
212 +void netjson_tcEdgeIntoNodesTree(struct olsrd_avl_tree *nodes, struct tc_edge_entry *tc_edge) {
213 + struct olsrd_avl_node *olsrd_avlnode;
214 struct node_entry *node;
216 - avlnode = avl_find(nodes, &tc_edge->T_dest_addr);
218 + olsrd_avlnode = olsrd_avl_find(nodes, &tc_edge->T_dest_addr);
219 + if (olsrd_avlnode) {
220 /* the IP address is already known */
223 @@ -201,21 +201,21 @@ void netjson_tcEdgeIntoNodesTree(struct
225 node = olsr_malloc(sizeof(struct node_entry), "netjson NetworkGraph node - TC - main");
226 memset(node, 0, sizeof(*node));
227 - node->avl.key = &tc_edge->T_dest_addr;
228 + node->olsrd_avl.key = &tc_edge->T_dest_addr;
229 node->isAlias = false;
230 node->tc_edge = tc_edge;
231 - if (avl_insert(nodes, &node->avl, AVL_DUP_NO) == -1) {
232 + if (olsrd_avl_insert(nodes, &node->olsrd_avl, OLSRD_AVL_DUP_NO) == -1) {
238 -void netjson_linkIntoNodesTree(struct avl_tree *nodes, struct link_entry *link, union olsr_ip_addr *addr) {
239 - struct avl_node *avlnode;
240 +void netjson_linkIntoNodesTree(struct olsrd_avl_tree *nodes, struct link_entry *link, union olsr_ip_addr *addr) {
241 + struct olsrd_avl_node *olsrd_avlnode;
242 struct node_entry *node;
244 - avlnode = avl_find(nodes, addr);
246 + olsrd_avlnode = olsrd_avl_find(nodes, addr);
247 + if (olsrd_avlnode) {
248 /* the IP address is already known */
251 @@ -224,21 +224,21 @@ void netjson_linkIntoNodesTree(struct av
253 node = olsr_malloc(sizeof(struct node_entry), "netjson NetworkGraph node - link");
254 memset(node, 0, sizeof(*node));
255 - node->avl.key = addr;
256 + node->olsrd_avl.key = addr;
257 node->isAlias = false;
259 - if (avl_insert(nodes, &node->avl, AVL_DUP_NO) == -1) {
260 + if (olsrd_avl_insert(nodes, &node->olsrd_avl, OLSRD_AVL_DUP_NO) == -1) {
266 -void netjson_neighborIntoNodesTree(struct avl_tree *nodes, struct neighbor_entry *neighbor) {
267 - struct avl_node *avlnode;
268 +void netjson_neighborIntoNodesTree(struct olsrd_avl_tree *nodes, struct neighbor_entry *neighbor) {
269 + struct olsrd_avl_node *olsrd_avlnode;
270 struct node_entry *node;
272 - avlnode = avl_find(nodes, &neighbor->neighbor_main_addr);
274 + olsrd_avlnode = olsrd_avl_find(nodes, &neighbor->neighbor_main_addr);
275 + if (olsrd_avlnode) {
276 /* the IP address is already known */
279 @@ -247,10 +247,10 @@ void netjson_neighborIntoNodesTree(struc
281 node = olsr_malloc(sizeof(struct node_entry), "netjson NetworkGraph node - neighbor");
282 memset(node, 0, sizeof(*node));
283 - node->avl.key = &neighbor->neighbor_main_addr;
284 + node->olsrd_avl.key = &neighbor->neighbor_main_addr;
285 node->isAlias = false;
286 node->neighbor = neighbor;
287 - if (avl_insert(nodes, &node->avl, AVL_DUP_NO) == -1) {
288 + if (olsrd_avl_insert(nodes, &node->olsrd_avl, OLSRD_AVL_DUP_NO) == -1) {
292 --- a/lib/netjson/src/olsrd_netjson_helpers.h
293 +++ b/lib/netjson/src/olsrd_netjson_helpers.h
298 -#include "common/avl.h"
299 +#include "common/olsrd_avl.h"
302 #include "link_set.h"
304 #include "olsr_types.h"
307 - struct avl_node avl;
308 + struct olsrd_avl_node olsrd_avl;
310 struct mid_entry *mid;
312 @@ -65,15 +65,15 @@ struct node_entry {
313 struct neighbor_entry *neighbor;
316 -/* static INLINE struct node_entry * avlnode2node(struct avl_node *ptr) */
317 -AVLNODE2STRUCT(avlnode2node, struct node_entry, avl);
318 +/* static INLINE struct node_entry * olsrd_avlnode2node(struct olsrd_avl_node *ptr) */
319 +OLSRD_AVLNODE2STRUCT(olsrd_avlnode2node, struct node_entry, olsrd_avl);
321 struct node_entry * netjson_constructMidSelf(struct mid_entry *mid);
322 void netjson_cleanup_mid_self(struct node_entry *node_entry);
323 -void netjson_midIntoNodesTree(struct avl_tree *nodes, struct mid_entry *mid);
324 -void netjson_tcIntoNodesTree(struct avl_tree *nodes, struct tc_entry *tc);
325 -void netjson_tcEdgeIntoNodesTree(struct avl_tree *nodes, struct tc_edge_entry *tc_edge);
326 -void netjson_linkIntoNodesTree(struct avl_tree *nodes, struct link_entry *link, union olsr_ip_addr *addr);
327 -void netjson_neighborIntoNodesTree(struct avl_tree *nodes, struct neighbor_entry *neigh);
328 +void netjson_midIntoNodesTree(struct olsrd_avl_tree *nodes, struct mid_entry *mid);
329 +void netjson_tcIntoNodesTree(struct olsrd_avl_tree *nodes, struct tc_entry *tc);
330 +void netjson_tcEdgeIntoNodesTree(struct olsrd_avl_tree *nodes, struct tc_edge_entry *tc_edge);
331 +void netjson_linkIntoNodesTree(struct olsrd_avl_tree *nodes, struct link_entry *link, union olsr_ip_addr *addr);
332 +void netjson_neighborIntoNodesTree(struct olsrd_avl_tree *nodes, struct neighbor_entry *neigh);
334 #endif /* LIB_NETJSON_SRC_OLSRD_NETJSON_HELPERS_H_ */
335 --- a/src/common/avl.c
339 - * The olsr.org Optimized Link-State Routing daemon (olsrd)
341 - * (c) by the OLSR project
343 - * See our Git repository to find out who worked on this file
344 - * and thus is a copyright holder on it.
346 - * All rights reserved.
348 - * Redistribution and use in source and binary forms, with or without
349 - * modification, are permitted provided that the following conditions
352 - * * Redistributions of source code must retain the above copyright
353 - * notice, this list of conditions and the following disclaimer.
354 - * * Redistributions in binary form must reproduce the above copyright
355 - * notice, this list of conditions and the following disclaimer in
356 - * the documentation and/or other materials provided with the
358 - * * Neither the name of olsr.org, olsrd nor the names of its
359 - * contributors may be used to endorse or promote products derived
360 - * from this software without specific prior written permission.
362 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
363 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
364 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
365 - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
366 - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
367 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
368 - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
369 - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
370 - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
371 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
372 - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
373 - * POSSIBILITY OF SUCH DAMAGE.
375 - * Visit http://www.olsr.org for more information.
377 - * If you find this software useful feel free to make a donation
378 - * to the project. For more information see the website or contact
379 - * the copyright holders.
388 -#include "common/avl.h"
389 -#include "net_olsr.h"
392 - * default comparison pointers
393 - * set to the respective compare function.
394 - * if avl_comp_default is set to zero, a fast
395 - * INLINE ipv4 comparison will be executed.
397 -avl_tree_comp avl_comp_default = NULL;
398 -avl_tree_comp avl_comp_prefix_default;
401 -avl_comp_ipv4(const void *ip1, const void *ip2)
403 - return ip4cmp(ip1, ip2);
407 -avl_comp_ipv6(const void *ip1, const void *ip2)
409 - return ip6cmp(ip1, ip2);
413 -avl_comp_mac(const void *ip1, const void *ip2)
415 - return memcmp(ip1, ip2, 6);
419 -avl_init(struct avl_tree *tree, avl_tree_comp comp)
422 - tree->first = NULL;
426 - tree->comp = comp == avl_comp_ipv4 ? NULL : comp;
429 -static struct avl_node *
430 -avl_find_rec_ipv4(struct avl_node *node, const void *key)
432 - if (*(const unsigned int *)key < *(const unsigned int *)node->key) {
433 - if (node->left != NULL)
434 - return avl_find_rec_ipv4(node->left, key);
437 - else if (*(const unsigned int *)key > *(const unsigned int *)node->key) {
438 - if (node->right != NULL)
439 - return avl_find_rec_ipv4(node->right, key);
445 -static struct avl_node *
446 -avl_find_rec(struct avl_node *node, const void *key, avl_tree_comp comp)
451 - return avl_find_rec_ipv4(node, key);
453 - diff = (*comp) (key, node->key);
456 - if (node->left != NULL)
457 - return avl_find_rec(node->left, key, comp);
463 - if (node->right != NULL)
464 - return avl_find_rec(node->right, key, comp);
473 -avl_find(struct avl_tree *tree, const void *key)
475 - struct avl_node *node;
477 - if (tree->root == NULL)
480 - node = avl_find_rec(tree->root, key, tree->comp);
482 - if (NULL == tree->comp) {
483 - if (0 != ip4cmp(node->key, key))
488 - if ((*tree->comp) (node->key, key) != 0)
496 -avl_rotate_right(struct avl_tree *tree, struct avl_node *node)
498 - struct avl_node *left, *parent;
501 - parent = node->parent;
503 - left->parent = parent;
504 - node->parent = left;
506 - if (parent == NULL)
510 - if (parent->left == node)
511 - parent->left = left;
514 - parent->right = left;
517 - node->left = left->right;
518 - left->right = node;
520 - if (node->left != NULL)
521 - node->left->parent = node;
523 - node->balance += 1 - MIN(left->balance, 0);
524 - left->balance += 1 + MAX(node->balance, 0);
528 -avl_rotate_left(struct avl_tree *tree, struct avl_node *node)
530 - struct avl_node *right, *parent;
532 - right = node->right;
533 - parent = node->parent;
535 - right->parent = parent;
536 - node->parent = right;
538 - if (parent == NULL)
539 - tree->root = right;
542 - if (parent->left == node)
543 - parent->left = right;
546 - parent->right = right;
549 - node->right = right->left;
550 - right->left = node;
552 - if (node->right != NULL)
553 - node->right->parent = node;
555 - node->balance -= 1 + MAX(right->balance, 0);
556 - right->balance -= 1 - MIN(node->balance, 0);
560 -post_insert(struct avl_tree *tree, struct avl_node *node)
562 - struct avl_node *parent = node->parent;
564 - if (parent == NULL)
567 - if (node == parent->left) {
570 - if (parent->balance == 0)
573 - if (parent->balance == -1) {
574 - post_insert(tree, parent);
578 - if (node->balance == -1) {
579 - avl_rotate_right(tree, parent);
583 - avl_rotate_left(tree, node);
584 - avl_rotate_right(tree, node->parent->parent);
590 - if (parent->balance == 0)
593 - if (parent->balance == 1) {
594 - post_insert(tree, parent);
598 - if (node->balance == 1) {
599 - avl_rotate_left(tree, parent);
603 - avl_rotate_right(tree, node);
604 - avl_rotate_left(tree, node->parent->parent);
608 -avl_insert_before(struct avl_tree *tree, struct avl_node *pos_node, struct avl_node *node)
610 - if (pos_node->prev != NULL)
611 - pos_node->prev->next = node;
613 - tree->first = node;
615 - node->prev = pos_node->prev;
616 - node->next = pos_node;
618 - pos_node->prev = node;
624 -avl_insert_after(struct avl_tree *tree, struct avl_node *pos_node, struct avl_node *node)
626 - if (pos_node->next != NULL)
627 - pos_node->next->prev = node;
631 - node->prev = pos_node;
632 - node->next = pos_node->next;
634 - pos_node->next = node;
640 -avl_remove(struct avl_tree *tree, struct avl_node *node)
642 - if (node->prev != NULL)
643 - node->prev->next = node->next;
645 - tree->first = node->next;
647 - if (node->next != NULL)
648 - node->next->prev = node->prev;
650 - tree->last = node->prev;
656 -avl_insert(struct avl_tree *tree, struct avl_node *new, int allow_duplicates)
658 - struct avl_node *node;
659 - struct avl_node *last;
662 - new->parent = NULL;
673 - if (tree->root == NULL) {
681 - node = avl_find_rec(tree->root, new->key, tree->comp);
685 - while (last->next != NULL && last->next->leader == 0)
688 - if (NULL == tree->comp)
689 - diff = ip4cmp(new->key, node->key);
692 - diff = (*tree->comp) (new->key, node->key);
695 - if (allow_duplicates == AVL_DUP_NO)
700 - avl_insert_after(tree, last, new);
704 - if (node->balance == 1) {
705 - avl_insert_before(tree, node, new);
708 - new->parent = node;
713 - if (node->balance == -1) {
714 - avl_insert_after(tree, last, new);
717 - new->parent = node;
723 - avl_insert_before(tree, node, new);
725 - node->balance = -1;
726 - new->parent = node;
728 - post_insert(tree, node);
732 - avl_insert_after(tree, last, new);
735 - new->parent = node;
737 - post_insert(tree, node);
742 -avl_post_delete(struct avl_tree *tree, struct avl_node *node)
744 - struct avl_node *parent;
746 - if ((parent = node->parent) == NULL)
749 - if (node == parent->left) {
752 - if (parent->balance == 0) {
753 - avl_post_delete(tree, parent);
757 - if (parent->balance == 1)
760 - if (parent->right->balance == 0) {
761 - avl_rotate_left(tree, parent);
765 - if (parent->right->balance == 1) {
766 - avl_rotate_left(tree, parent);
767 - avl_post_delete(tree, parent->parent);
771 - avl_rotate_right(tree, parent->right);
772 - avl_rotate_left(tree, parent);
773 - avl_post_delete(tree, parent->parent);
779 - if (parent->balance == 0) {
780 - avl_post_delete(tree, parent);
784 - if (parent->balance == -1)
787 - if (parent->left->balance == 0) {
788 - avl_rotate_right(tree, parent);
792 - if (parent->left->balance == -1) {
793 - avl_rotate_right(tree, parent);
794 - avl_post_delete(tree, parent->parent);
798 - avl_rotate_left(tree, parent->left);
799 - avl_rotate_right(tree, parent);
800 - avl_post_delete(tree, parent->parent);
803 -static struct avl_node *
804 -avl_local_min(struct avl_node *node)
806 - while (node->left != NULL)
813 -avl_delete_worker(struct avl_tree *tree, struct avl_node *node)
815 - struct avl_node *parent, *min;
817 - parent = node->parent;
819 - if (node->left == NULL && node->right == NULL) {
820 - if (parent == NULL) {
825 - if (parent->left == node) {
826 - parent->left = NULL;
829 - if (parent->balance == 1)
832 - if (parent->balance == 0) {
833 - avl_post_delete(tree, parent);
837 - if (parent->right->balance == 0) {
838 - avl_rotate_left(tree, parent);
842 - if (parent->right->balance == 1) {
843 - avl_rotate_left(tree, parent);
844 - avl_post_delete(tree, parent->parent);
848 - avl_rotate_right(tree, parent->right);
849 - avl_rotate_left(tree, parent);
850 - avl_post_delete(tree, parent->parent);
853 - parent->right = NULL;
856 - if (parent->balance == -1)
859 - if (parent->balance == 0) {
860 - avl_post_delete(tree, parent);
864 - if (parent->left->balance == 0) {
865 - avl_rotate_right(tree, parent);
869 - if (parent->left->balance == -1) {
870 - avl_rotate_right(tree, parent);
871 - avl_post_delete(tree, parent->parent);
875 - avl_rotate_left(tree, parent->left);
876 - avl_rotate_right(tree, parent);
877 - avl_post_delete(tree, parent->parent);
882 - if (node->left == NULL) {
883 - if (parent == NULL) {
884 - tree->root = node->right;
885 - node->right->parent = NULL;
889 - node->right->parent = parent;
891 - if (parent->left == node)
892 - parent->left = node->right;
895 - parent->right = node->right;
897 - avl_post_delete(tree, node->right);
901 - if (node->right == NULL) {
902 - if (parent == NULL) {
903 - tree->root = node->left;
904 - node->left->parent = NULL;
908 - node->left->parent = parent;
910 - if (parent->left == node)
911 - parent->left = node->left;
914 - parent->right = node->left;
916 - avl_post_delete(tree, node->left);
920 - min = avl_local_min(node->right);
921 - avl_delete_worker(tree, min);
922 - parent = node->parent;
924 - min->balance = node->balance;
925 - min->parent = parent;
926 - min->left = node->left;
927 - min->right = node->right;
929 - if (min->left != NULL)
930 - min->left->parent = min;
932 - if (min->right != NULL)
933 - min->right->parent = min;
935 - if (parent == NULL) {
940 - if (parent->left == node) {
941 - parent->left = min;
945 - parent->right = min;
949 -avl_delete(struct avl_tree *tree, struct avl_node *node)
951 - struct avl_node *next;
952 - struct avl_node *parent;
953 - struct avl_node *left;
954 - struct avl_node *right;
956 - if (node->leader != 0) {
959 - if (next != NULL && next->leader == 0) {
961 - next->balance = node->balance;
963 - parent = node->parent;
965 - right = node->right;
967 - next->parent = parent;
969 - next->right = right;
971 - if (parent == NULL)
975 - if (node == parent->left)
976 - parent->left = next;
979 - parent->right = next;
983 - left->parent = next;
986 - right->parent = next;
990 - avl_delete_worker(tree, node);
993 - avl_remove(tree, node);
998 - * c-basic-offset: 2
999 - * indent-tabs-mode: nil
1003 +++ b/src/common/olsrd_avl.c
1006 + * The olsr.org Optimized Link-State Routing daemon (olsrd)
1008 + * (c) by the OLSR project
1010 + * See our Git repository to find out who worked on this file
1011 + * and thus is a copyright holder on it.
1013 + * All rights reserved.
1015 + * Redistribution and use in source and binary forms, with or without
1016 + * modification, are permitted provided that the following conditions
1019 + * * Redistributions of source code must retain the above copyright
1020 + * notice, this list of conditions and the following disclaimer.
1021 + * * Redistributions in binary form must reproduce the above copyright
1022 + * notice, this list of conditions and the following disclaimer in
1023 + * the documentation and/or other materials provided with the
1025 + * * Neither the name of olsr.org, olsrd nor the names of its
1026 + * contributors may be used to endorse or promote products derived
1027 + * from this software without specific prior written permission.
1029 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1030 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1031 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1032 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1033 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1034 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1035 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1036 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1037 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1038 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
1039 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1040 + * POSSIBILITY OF SUCH DAMAGE.
1042 + * Visit http://www.olsr.org for more information.
1044 + * If you find this software useful feel free to make a donation
1045 + * to the project. For more information see the website or contact
1046 + * the copyright holders.
1050 +#include <stddef.h>
1052 +#include <string.h>
1054 +#include "ipcalc.h"
1055 +#include "common/olsrd_avl.h"
1056 +#include "net_olsr.h"
1059 + * default comparison pointers
1060 + * set to the respective compare function.
1061 + * if olsrd_avl_comp_default is set to zero, a fast
1062 + * INLINE ipv4 comparison will be executed.
1064 +olsrd_avl_tree_comp olsrd_avl_comp_default = NULL;
1065 +olsrd_avl_tree_comp olsrd_avl_comp_prefix_default;
1068 +olsrd_avl_comp_ipv4(const void *ip1, const void *ip2)
1070 + return ip4cmp(ip1, ip2);
1074 +olsrd_avl_comp_ipv6(const void *ip1, const void *ip2)
1076 + return ip6cmp(ip1, ip2);
1080 +olsrd_avl_comp_mac(const void *ip1, const void *ip2)
1082 + return memcmp(ip1, ip2, 6);
1086 +olsrd_avl_init(struct olsrd_avl_tree *tree, olsrd_avl_tree_comp comp)
1088 + tree->root = NULL;
1089 + tree->first = NULL;
1090 + tree->last = NULL;
1093 + tree->comp = comp == olsrd_avl_comp_ipv4 ? NULL : comp;
1096 +static struct olsrd_avl_node *
1097 +olsrd_avl_find_rec_ipv4(struct olsrd_avl_node *node, const void *key)
1099 + if (*(const unsigned int *)key < *(const unsigned int *)node->key) {
1100 + if (node->left != NULL)
1101 + return olsrd_avl_find_rec_ipv4(node->left, key);
1104 + else if (*(const unsigned int *)key > *(const unsigned int *)node->key) {
1105 + if (node->right != NULL)
1106 + return olsrd_avl_find_rec_ipv4(node->right, key);
1112 +static struct olsrd_avl_node *
1113 +olsrd_avl_find_rec(struct olsrd_avl_node *node, const void *key, olsrd_avl_tree_comp comp)
1118 + return olsrd_avl_find_rec_ipv4(node, key);
1120 + diff = (*comp) (key, node->key);
1123 + if (node->left != NULL)
1124 + return olsrd_avl_find_rec(node->left, key, comp);
1130 + if (node->right != NULL)
1131 + return olsrd_avl_find_rec(node->right, key, comp);
1139 +struct olsrd_avl_node *
1140 +olsrd_avl_find(struct olsrd_avl_tree *tree, const void *key)
1142 + struct olsrd_avl_node *node;
1144 + if (tree->root == NULL)
1147 + node = olsrd_avl_find_rec(tree->root, key, tree->comp);
1149 + if (NULL == tree->comp) {
1150 + if (0 != ip4cmp(node->key, key))
1155 + if ((*tree->comp) (node->key, key) != 0)
1163 +olsrd_avl_rotate_right(struct olsrd_avl_tree *tree, struct olsrd_avl_node *node)
1165 + struct olsrd_avl_node *left, *parent;
1167 + left = node->left;
1168 + parent = node->parent;
1170 + left->parent = parent;
1171 + node->parent = left;
1173 + if (parent == NULL)
1174 + tree->root = left;
1177 + if (parent->left == node)
1178 + parent->left = left;
1181 + parent->right = left;
1184 + node->left = left->right;
1185 + left->right = node;
1187 + if (node->left != NULL)
1188 + node->left->parent = node;
1190 + node->balance += 1 - MIN(left->balance, 0);
1191 + left->balance += 1 + MAX(node->balance, 0);
1195 +olsrd_avl_rotate_left(struct olsrd_avl_tree *tree, struct olsrd_avl_node *node)
1197 + struct olsrd_avl_node *right, *parent;
1199 + right = node->right;
1200 + parent = node->parent;
1202 + right->parent = parent;
1203 + node->parent = right;
1205 + if (parent == NULL)
1206 + tree->root = right;
1209 + if (parent->left == node)
1210 + parent->left = right;
1213 + parent->right = right;
1216 + node->right = right->left;
1217 + right->left = node;
1219 + if (node->right != NULL)
1220 + node->right->parent = node;
1222 + node->balance -= 1 + MAX(right->balance, 0);
1223 + right->balance -= 1 - MIN(node->balance, 0);
1227 +post_insert(struct olsrd_avl_tree *tree, struct olsrd_avl_node *node)
1229 + struct olsrd_avl_node *parent = node->parent;
1231 + if (parent == NULL)
1234 + if (node == parent->left) {
1235 + parent->balance--;
1237 + if (parent->balance == 0)
1240 + if (parent->balance == -1) {
1241 + post_insert(tree, parent);
1245 + if (node->balance == -1) {
1246 + olsrd_avl_rotate_right(tree, parent);
1250 + olsrd_avl_rotate_left(tree, node);
1251 + olsrd_avl_rotate_right(tree, node->parent->parent);
1255 + parent->balance++;
1257 + if (parent->balance == 0)
1260 + if (parent->balance == 1) {
1261 + post_insert(tree, parent);
1265 + if (node->balance == 1) {
1266 + olsrd_avl_rotate_left(tree, parent);
1270 + olsrd_avl_rotate_right(tree, node);
1271 + olsrd_avl_rotate_left(tree, node->parent->parent);
1275 +olsrd_avl_insert_before(struct olsrd_avl_tree *tree, struct olsrd_avl_node *pos_node, struct olsrd_avl_node *node)
1277 + if (pos_node->prev != NULL)
1278 + pos_node->prev->next = node;
1280 + tree->first = node;
1282 + node->prev = pos_node->prev;
1283 + node->next = pos_node;
1285 + pos_node->prev = node;
1291 +olsrd_avl_insert_after(struct olsrd_avl_tree *tree, struct olsrd_avl_node *pos_node, struct olsrd_avl_node *node)
1293 + if (pos_node->next != NULL)
1294 + pos_node->next->prev = node;
1296 + tree->last = node;
1298 + node->prev = pos_node;
1299 + node->next = pos_node->next;
1301 + pos_node->next = node;
1307 +olsrd_avl_remove(struct olsrd_avl_tree *tree, struct olsrd_avl_node *node)
1309 + if (node->prev != NULL)
1310 + node->prev->next = node->next;
1312 + tree->first = node->next;
1314 + if (node->next != NULL)
1315 + node->next->prev = node->prev;
1317 + tree->last = node->prev;
1323 +olsrd_avl_insert(struct olsrd_avl_tree *tree, struct olsrd_avl_node *new, int allow_duplicates)
1325 + struct olsrd_avl_node *node;
1326 + struct olsrd_avl_node *last;
1329 + new->parent = NULL;
1332 + new->right = NULL;
1340 + if (tree->root == NULL) {
1342 + tree->first = new;
1348 + node = olsrd_avl_find_rec(tree->root, new->key, tree->comp);
1352 + while (last->next != NULL && last->next->leader == 0)
1353 + last = last->next;
1355 + if (NULL == tree->comp)
1356 + diff = ip4cmp(new->key, node->key);
1359 + diff = (*tree->comp) (new->key, node->key);
1362 + if (allow_duplicates == OLSRD_AVL_DUP_NO)
1367 + olsrd_avl_insert_after(tree, last, new);
1371 + if (node->balance == 1) {
1372 + olsrd_avl_insert_before(tree, node, new);
1374 + node->balance = 0;
1375 + new->parent = node;
1380 + if (node->balance == -1) {
1381 + olsrd_avl_insert_after(tree, last, new);
1383 + node->balance = 0;
1384 + new->parent = node;
1385 + node->right = new;
1390 + olsrd_avl_insert_before(tree, node, new);
1392 + node->balance = -1;
1393 + new->parent = node;
1395 + post_insert(tree, node);
1399 + olsrd_avl_insert_after(tree, last, new);
1401 + node->balance = 1;
1402 + new->parent = node;
1403 + node->right = new;
1404 + post_insert(tree, node);
1409 +olsrd_avl_post_delete(struct olsrd_avl_tree *tree, struct olsrd_avl_node *node)
1411 + struct olsrd_avl_node *parent;
1413 + if ((parent = node->parent) == NULL)
1416 + if (node == parent->left) {
1417 + parent->balance++;
1419 + if (parent->balance == 0) {
1420 + olsrd_avl_post_delete(tree, parent);
1424 + if (parent->balance == 1)
1427 + if (parent->right->balance == 0) {
1428 + olsrd_avl_rotate_left(tree, parent);
1432 + if (parent->right->balance == 1) {
1433 + olsrd_avl_rotate_left(tree, parent);
1434 + olsrd_avl_post_delete(tree, parent->parent);
1438 + olsrd_avl_rotate_right(tree, parent->right);
1439 + olsrd_avl_rotate_left(tree, parent);
1440 + olsrd_avl_post_delete(tree, parent->parent);
1444 + parent->balance--;
1446 + if (parent->balance == 0) {
1447 + olsrd_avl_post_delete(tree, parent);
1451 + if (parent->balance == -1)
1454 + if (parent->left->balance == 0) {
1455 + olsrd_avl_rotate_right(tree, parent);
1459 + if (parent->left->balance == -1) {
1460 + olsrd_avl_rotate_right(tree, parent);
1461 + olsrd_avl_post_delete(tree, parent->parent);
1465 + olsrd_avl_rotate_left(tree, parent->left);
1466 + olsrd_avl_rotate_right(tree, parent);
1467 + olsrd_avl_post_delete(tree, parent->parent);
1470 +static struct olsrd_avl_node *
1471 +olsrd_avl_local_min(struct olsrd_avl_node *node)
1473 + while (node->left != NULL)
1474 + node = node->left;
1480 +olsrd_avl_delete_worker(struct olsrd_avl_tree *tree, struct olsrd_avl_node *node)
1482 + struct olsrd_avl_node *parent, *min;
1484 + parent = node->parent;
1486 + if (node->left == NULL && node->right == NULL) {
1487 + if (parent == NULL) {
1488 + tree->root = NULL;
1492 + if (parent->left == node) {
1493 + parent->left = NULL;
1494 + parent->balance++;
1496 + if (parent->balance == 1)
1499 + if (parent->balance == 0) {
1500 + olsrd_avl_post_delete(tree, parent);
1504 + if (parent->right->balance == 0) {
1505 + olsrd_avl_rotate_left(tree, parent);
1509 + if (parent->right->balance == 1) {
1510 + olsrd_avl_rotate_left(tree, parent);
1511 + olsrd_avl_post_delete(tree, parent->parent);
1515 + olsrd_avl_rotate_right(tree, parent->right);
1516 + olsrd_avl_rotate_left(tree, parent);
1517 + olsrd_avl_post_delete(tree, parent->parent);
1520 + parent->right = NULL;
1521 + parent->balance--;
1523 + if (parent->balance == -1)
1526 + if (parent->balance == 0) {
1527 + olsrd_avl_post_delete(tree, parent);
1531 + if (parent->left->balance == 0) {
1532 + olsrd_avl_rotate_right(tree, parent);
1536 + if (parent->left->balance == -1) {
1537 + olsrd_avl_rotate_right(tree, parent);
1538 + olsrd_avl_post_delete(tree, parent->parent);
1542 + olsrd_avl_rotate_left(tree, parent->left);
1543 + olsrd_avl_rotate_right(tree, parent);
1544 + olsrd_avl_post_delete(tree, parent->parent);
1549 + if (node->left == NULL) {
1550 + if (parent == NULL) {
1551 + tree->root = node->right;
1552 + node->right->parent = NULL;
1556 + node->right->parent = parent;
1558 + if (parent->left == node)
1559 + parent->left = node->right;
1562 + parent->right = node->right;
1564 + olsrd_avl_post_delete(tree, node->right);
1568 + if (node->right == NULL) {
1569 + if (parent == NULL) {
1570 + tree->root = node->left;
1571 + node->left->parent = NULL;
1575 + node->left->parent = parent;
1577 + if (parent->left == node)
1578 + parent->left = node->left;
1581 + parent->right = node->left;
1583 + olsrd_avl_post_delete(tree, node->left);
1587 + min = olsrd_avl_local_min(node->right);
1588 + olsrd_avl_delete_worker(tree, min);
1589 + parent = node->parent;
1591 + min->balance = node->balance;
1592 + min->parent = parent;
1593 + min->left = node->left;
1594 + min->right = node->right;
1596 + if (min->left != NULL)
1597 + min->left->parent = min;
1599 + if (min->right != NULL)
1600 + min->right->parent = min;
1602 + if (parent == NULL) {
1607 + if (parent->left == node) {
1608 + parent->left = min;
1612 + parent->right = min;
1616 +olsrd_avl_delete(struct olsrd_avl_tree *tree, struct olsrd_avl_node *node)
1618 + struct olsrd_avl_node *next;
1619 + struct olsrd_avl_node *parent;
1620 + struct olsrd_avl_node *left;
1621 + struct olsrd_avl_node *right;
1623 + if (node->leader != 0) {
1624 + next = node->next;
1626 + if (next != NULL && next->leader == 0) {
1628 + next->balance = node->balance;
1630 + parent = node->parent;
1631 + left = node->left;
1632 + right = node->right;
1634 + next->parent = parent;
1635 + next->left = left;
1636 + next->right = right;
1638 + if (parent == NULL)
1639 + tree->root = next;
1642 + if (node == parent->left)
1643 + parent->left = next;
1646 + parent->right = next;
1650 + left->parent = next;
1652 + if (right != NULL)
1653 + right->parent = next;
1657 + olsrd_avl_delete_worker(tree, node);
1660 + olsrd_avl_remove(tree, node);
1664 + * Local Variables:
1665 + * c-basic-offset: 2
1666 + * indent-tabs-mode: nil
1669 --- a/src/common/avl.h
1673 - * The olsr.org Optimized Link-State Routing daemon (olsrd)
1675 - * (c) by the OLSR project
1677 - * See our Git repository to find out who worked on this file
1678 - * and thus is a copyright holder on it.
1680 - * All rights reserved.
1682 - * Redistribution and use in source and binary forms, with or without
1683 - * modification, are permitted provided that the following conditions
1686 - * * Redistributions of source code must retain the above copyright
1687 - * notice, this list of conditions and the following disclaimer.
1688 - * * Redistributions in binary form must reproduce the above copyright
1689 - * notice, this list of conditions and the following disclaimer in
1690 - * the documentation and/or other materials provided with the
1692 - * * Neither the name of olsr.org, olsrd nor the names of its
1693 - * contributors may be used to endorse or promote products derived
1694 - * from this software without specific prior written permission.
1696 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1697 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1698 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1699 - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1700 - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1701 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1702 - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1703 - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1704 - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1705 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
1706 - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1707 - * POSSIBILITY OF SUCH DAMAGE.
1709 - * Visit http://www.olsr.org for more information.
1711 - * If you find this software useful feel free to make a donation
1712 - * to the project. For more information see the website or contact
1713 - * the copyright holders.
1720 -#include <stddef.h>
1721 -#include "compiler.h"
1725 - struct avl_node *parent;
1726 - struct avl_node *left;
1727 - struct avl_node *right;
1728 - struct avl_node *next;
1729 - struct avl_node *prev;
1731 - signed char balance;
1732 - unsigned char leader;
1735 -typedef int (*avl_tree_comp) (const void *, const void *);
1738 - struct avl_node *root;
1739 - struct avl_node *first;
1740 - struct avl_node *last;
1741 - unsigned int count;
1742 - avl_tree_comp comp;
1746 -#define AVL_DUP_NO 0
1748 -void avl_init(struct avl_tree *, avl_tree_comp);
1749 -struct avl_node *avl_find(struct avl_tree *, const void *);
1750 -int avl_insert(struct avl_tree *, struct avl_node *, int);
1751 -void avl_delete(struct avl_tree *, struct avl_node *);
1753 -static INLINE struct avl_node *
1754 -avl_walk_first(struct avl_tree *tree)
1760 - return tree->first;
1762 -static INLINE struct avl_node *
1763 -avl_walk_last(struct avl_tree *tree)
1769 - return tree->last;
1771 -static INLINE struct avl_node *
1772 -avl_walk_next(struct avl_node *node)
1778 - return node->next;
1780 -static INLINE struct avl_node *
1781 -avl_walk_prev(struct avl_node *node)
1787 - return node->prev;
1790 -/* and const versions*/
1791 -static INLINE const struct avl_node *
1792 -avl_walk_first_c(const struct avl_tree *tree)
1798 - return tree->first;
1800 -static INLINE const struct avl_node *
1801 -avl_walk_last_c(const struct avl_tree *tree)
1807 - return tree->last;
1809 -static INLINE const struct avl_node *
1810 -avl_walk_next_c(const struct avl_node *node)
1816 - return node->next;
1818 -static INLINE const struct avl_node *
1819 -avl_walk_prev_c(const struct avl_node *node)
1825 - return node->prev;
1828 -extern avl_tree_comp avl_comp_default;
1829 -extern avl_tree_comp avl_comp_prefix_default;
1830 -extern int avl_comp_ipv4(const void *, const void *);
1831 -extern int avl_comp_ipv6(const void *, const void *);
1832 -extern int avl_comp_mac(const void *, const void *);
1835 - * Macro to define an INLINE function to map from a list_node offset back to the
1836 - * base of the datastructure. That way you save an extra data pointer.
1838 -#define AVLNODE2STRUCT(funcname, structname, avlnodename) \
1839 -static INLINE structname * funcname (struct avl_node *ptr)\
1843 - (structname *) (((size_t) ptr) - offsetof(structname, avlnodename)) : \
1847 -#endif /* _AVL_H */
1850 - * Local Variables:
1851 - * c-basic-offset: 2
1852 - * indent-tabs-mode: nil
1856 +++ b/src/common/olsrd_avl.h
1859 + * The olsr.org Optimized Link-State Routing daemon (olsrd)
1861 + * (c) by the OLSR project
1863 + * See our Git repository to find out who worked on this file
1864 + * and thus is a copyright holder on it.
1866 + * All rights reserved.
1868 + * Redistribution and use in source and binary forms, with or without
1869 + * modification, are permitted provided that the following conditions
1872 + * * Redistributions of source code must retain the above copyright
1873 + * notice, this list of conditions and the following disclaimer.
1874 + * * Redistributions in binary form must reproduce the above copyright
1875 + * notice, this list of conditions and the following disclaimer in
1876 + * the documentation and/or other materials provided with the
1878 + * * Neither the name of olsr.org, olsrd nor the names of its
1879 + * contributors may be used to endorse or promote products derived
1880 + * from this software without specific prior written permission.
1882 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1883 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1884 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1885 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1886 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1887 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1888 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1889 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1890 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1891 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
1892 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1893 + * POSSIBILITY OF SUCH DAMAGE.
1895 + * Visit http://www.olsr.org for more information.
1897 + * If you find this software useful feel free to make a donation
1898 + * to the project. For more information see the website or contact
1899 + * the copyright holders.
1903 +#ifndef _OLSRD_AVL_H
1904 +#define _OLSRD_AVL_H
1906 +#include <stddef.h>
1907 +#include "compiler.h"
1910 +struct olsrd_avl_node {
1911 + struct olsrd_avl_node *parent;
1912 + struct olsrd_avl_node *left;
1913 + struct olsrd_avl_node *right;
1914 + struct olsrd_avl_node *next;
1915 + struct olsrd_avl_node *prev;
1917 + signed char balance;
1918 + unsigned char leader;
1921 +typedef int (*olsrd_avl_tree_comp) (const void *, const void *);
1923 +struct olsrd_avl_tree {
1924 + struct olsrd_avl_node *root;
1925 + struct olsrd_avl_node *first;
1926 + struct olsrd_avl_node *last;
1927 + unsigned int count;
1928 + olsrd_avl_tree_comp comp;
1931 +#define OLSRD_AVL_DUP 1
1932 +#define OLSRD_AVL_DUP_NO 0
1934 +void olsrd_avl_init(struct olsrd_avl_tree *, olsrd_avl_tree_comp);
1935 +struct olsrd_avl_node *olsrd_avl_find(struct olsrd_avl_tree *, const void *);
1936 +int olsrd_avl_insert(struct olsrd_avl_tree *, struct olsrd_avl_node *, int);
1937 +void olsrd_avl_delete(struct olsrd_avl_tree *, struct olsrd_avl_node *);
1939 +static INLINE struct olsrd_avl_node *
1940 +olsrd_avl_walk_first(struct olsrd_avl_tree *tree)
1946 + return tree->first;
1948 +static INLINE struct olsrd_avl_node *
1949 +olsrd_avl_walk_last(struct olsrd_avl_tree *tree)
1955 + return tree->last;
1957 +static INLINE struct olsrd_avl_node *
1958 +olsrd_avl_walk_next(struct olsrd_avl_node *node)
1964 + return node->next;
1966 +static INLINE struct olsrd_avl_node *
1967 +olsrd_avl_walk_prev(struct olsrd_avl_node *node)
1973 + return node->prev;
1976 +/* and const versions*/
1977 +static INLINE const struct olsrd_avl_node *
1978 +olsrd_avl_walk_first_c(const struct olsrd_avl_tree *tree)
1984 + return tree->first;
1986 +static INLINE const struct olsrd_avl_node *
1987 +olsrd_avl_walk_last_c(const struct olsrd_avl_tree *tree)
1993 + return tree->last;
1995 +static INLINE const struct olsrd_avl_node *
1996 +olsrd_avl_walk_next_c(const struct olsrd_avl_node *node)
2002 + return node->next;
2004 +static INLINE const struct olsrd_avl_node *
2005 +olsrd_avl_walk_prev_c(const struct olsrd_avl_node *node)
2011 + return node->prev;
2014 +extern olsrd_avl_tree_comp olsrd_avl_comp_default;
2015 +extern olsrd_avl_tree_comp olsrd_avl_comp_prefix_default;
2016 +extern int olsrd_avl_comp_ipv4(const void *, const void *);
2017 +extern int olsrd_avl_comp_ipv6(const void *, const void *);
2018 +extern int olsrd_avl_comp_mac(const void *, const void *);
2021 + * Macro to define an INLINE function to map from a list_node offset back to the
2022 + * base of the datastructure. That way you save an extra data pointer.
2024 +#define OLSRD_AVLNODE2STRUCT(funcname, structname, olsrd_avlnodename) \
2025 +static INLINE structname * funcname (struct olsrd_avl_node *ptr)\
2029 + (structname *) (((size_t) ptr) - offsetof(structname, olsrd_avlnodename)) : \
2033 +#endif /* _OLSRD_AVL_H */
2036 + * Local Variables:
2037 + * c-basic-offset: 2
2038 + * indent-tabs-mode: nil
2041 --- a/src/duplicate_set.c
2042 +++ b/src/duplicate_set.c
2045 #include "duplicate_set.h"
2047 -#include "common/avl.h"
2048 +#include "common/olsrd_avl.h"
2050 #include "mid_set.h"
2051 #include "scheduler.h"
2054 static void olsr_cleanup_duplicate_entry(void *unused);
2056 -struct avl_tree duplicate_set;
2057 +struct olsrd_avl_tree duplicate_set;
2058 struct timer_entry *duplicate_cleanup_timer;
2061 olsr_init_duplicate_set(void)
2063 - avl_init(&duplicate_set, olsr_cnf->ip_version == AF_INET ? &avl_comp_ipv4 : &avl_comp_ipv6);
2064 + olsrd_avl_init(&duplicate_set, olsr_cnf->ip_version == AF_INET ? &olsrd_avl_comp_ipv4 : &olsrd_avl_comp_ipv6);
2066 olsr_set_timer(&duplicate_cleanup_timer, DUPLICATE_CLEANUP_INTERVAL, DUPLICATE_CLEANUP_JITTER, OLSR_TIMER_PERIODIC,
2067 &olsr_cleanup_duplicate_entry, NULL, 0);
2068 @@ -68,7 +68,7 @@ olsr_init_duplicate_set(void)
2069 void olsr_cleanup_duplicates(union olsr_ip_addr *orig) {
2070 struct dup_entry *entry;
2072 - entry = (struct dup_entry *)avl_find(&duplicate_set, orig);
2073 + entry = (struct dup_entry *)olsrd_avl_find(&duplicate_set, orig);
2074 if (entry != NULL) {
2075 entry->too_low_counter = DUP_MAX_TOO_LOW - 2;
2077 @@ -83,7 +83,7 @@ olsr_create_duplicate_entry(void *ip, ui
2078 memcpy(&entry->ip, ip, olsr_cnf->ip_version == AF_INET ? sizeof(entry->ip.v4) : sizeof(entry->ip.v6));
2079 entry->seqnr = seqnr;
2080 entry->too_low_counter = 0;
2081 - entry->avl.key = &entry->ip;
2082 + entry->olsrd_avl.key = &entry->ip;
2086 @@ -96,7 +96,7 @@ olsr_cleanup_duplicate_entry(void __attr
2088 OLSR_FOR_ALL_DUP_ENTRIES(entry) {
2089 if (TIMED_OUT(entry->valid_until)) {
2090 - avl_delete(&duplicate_set, &entry->avl);
2091 + olsrd_avl_delete(&duplicate_set, &entry->olsrd_avl);
2095 @@ -143,11 +143,11 @@ olsr_message_is_duplicate(union olsr_mes
2097 valid_until = GET_TIMESTAMP(DUPLICATE_VTIME);
2099 - entry = (struct dup_entry *)avl_find(&duplicate_set, ip);
2100 + entry = (struct dup_entry *)olsrd_avl_find(&duplicate_set, ip);
2101 if (entry == NULL) {
2102 entry = olsr_create_duplicate_entry(ip, seqnr);
2103 if (entry != NULL) {
2104 - avl_insert(&duplicate_set, &entry->avl, 0);
2105 + olsrd_avl_insert(&duplicate_set, &entry->olsrd_avl, 0);
2106 entry->valid_until = valid_until;
2108 return false; // okay, we process this package
2109 @@ -209,7 +209,7 @@ olsr_print_duplicate_table(void)
2110 olsr_wallclock_string(), ipwidth, "Node IP", "DupArray", "VTime");
2112 OLSR_FOR_ALL_DUP_ENTRIES(entry) {
2113 - OLSR_PRINTF(1, "%-*s %08x %s\n", ipwidth, olsr_ip_to_string(&addrbuf, (union olsr_ip_addr *)(entry->avl.key)),
2114 + OLSR_PRINTF(1, "%-*s %08x %s\n", ipwidth, olsr_ip_to_string(&addrbuf, (union olsr_ip_addr *)(entry->olsrd_avl.key)),
2115 entry->array, olsr_clock_string(entry->valid_until));
2116 } OLSR_FOR_ALL_DUP_ENTRIES_END(entry);
2118 --- a/src/duplicate_set.h
2119 +++ b/src/duplicate_set.h
2123 #include "mantissa.h"
2124 -#include "common/avl.h"
2125 +#include "common/olsrd_avl.h"
2127 #define DUPLICATE_CLEANUP_INTERVAL 15000
2128 #define DUPLICATE_CLEANUP_JITTER 25
2130 #define DUP_MAX_TOO_LOW 16
2133 - struct avl_node avl;
2134 + struct olsrd_avl_node olsrd_avl;
2135 union olsr_ip_addr ip;
2137 uint16_t too_low_counter;
2138 @@ -65,7 +65,7 @@ struct dup_entry {
2139 uint32_t valid_until;
2142 -AVLNODE2STRUCT(duptree2dupentry, struct dup_entry, avl);
2143 +OLSRD_AVLNODE2STRUCT(duptree2dupentry, struct dup_entry, olsrd_avl);
2145 void olsr_init_duplicate_set(void);
2146 void olsr_cleanup_duplicates(union olsr_ip_addr *orig);
2147 @@ -80,10 +80,10 @@ void olsr_print_duplicate_table(void);
2149 #define OLSR_FOR_ALL_DUP_ENTRIES(dup) \
2151 - struct avl_node *dup_tree_node, *next_dup_tree_node; \
2152 - for (dup_tree_node = avl_walk_first(&duplicate_set); \
2153 + struct olsrd_avl_node *dup_tree_node, *next_dup_tree_node; \
2154 + for (dup_tree_node = olsrd_avl_walk_first(&duplicate_set); \
2155 dup_tree_node; dup_tree_node = next_dup_tree_node) { \
2156 - next_dup_tree_node = avl_walk_next(dup_tree_node); \
2157 + next_dup_tree_node = olsrd_avl_walk_next(dup_tree_node); \
2158 dup = duptree2dupentry(dup_tree_node);
2159 #define OLSR_FOR_ALL_DUP_ENTRIES_END(dup) }}
2167 -#include "common/avl.h"
2168 +#include "common/olsrd_avl.h"
2172 @@ -89,7 +89,7 @@ static struct olsr_ip_prefix ipv4_slash_
2173 static struct olsr_ip_prefix ipv4_slash_1_routes[2];
2175 /** the gateway tree */
2176 -struct avl_tree gateway_tree;
2177 +struct olsrd_avl_tree gateway_tree;
2179 /** gateway cookie */
2180 static struct olsr_cookie_info *gateway_entry_mem_cookie = NULL;
2181 @@ -713,7 +713,7 @@ static void cleanup_gateway_handler(void
2184 /* remove gateway entry */
2185 - avl_delete(&gateway_tree, &gw->node);
2186 + olsrd_avl_delete(&gateway_tree, &gw->node);
2187 olsr_cookie_free(gateway_entry_mem_cookie, gw);
2190 @@ -837,7 +837,7 @@ int olsr_init_gateways(void) {
2191 gw_container_entry_mem_cookie = olsr_alloc_cookie("gw_container_entry_mem_cookie", OLSR_COOKIE_TYPE_MEMORY);
2192 olsr_cookie_set_memory_size(gw_container_entry_mem_cookie, sizeof(struct gw_container_entry));
2194 - avl_init(&gateway_tree, avl_comp_default);
2195 + olsrd_avl_init(&gateway_tree, olsrd_avl_comp_default);
2197 olsr_gw_list_init(&gw_list_ipv4, olsr_cnf->smart_gw_use_count);
2198 olsr_gw_list_init(&gw_list_ipv6, olsr_cnf->smart_gw_use_count);
2199 @@ -1078,7 +1078,7 @@ void olsr_cleanup_gateways(void) {
2200 OLSR_FOR_ALL_GWS_END(gw);
2202 /* there should be no more gateways */
2203 - assert(!avl_walk_first(&gateway_tree));
2204 + assert(!olsrd_avl_walk_first(&gateway_tree));
2205 assert(!current_ipv4_gw);
2206 assert(!current_ipv6_gw);
2208 @@ -1244,14 +1244,14 @@ void olsr_update_gateway_entry(union ols
2209 struct gw_container_entry * new_gw_in_list;
2211 int64_t prev_path_cost = 0;
2212 - struct gateway_entry *gw = node2gateway(avl_find(&gateway_tree, originator));
2213 + struct gateway_entry *gw = node2gateway(olsrd_avl_find(&gateway_tree, originator));
2216 gw = olsr_cookie_malloc(gateway_entry_mem_cookie);
2217 gw->originator = *originator;
2218 gw->node.key = &gw->originator;
2220 - avl_insert(&gateway_tree, &gw->node, AVL_DUP_NO);
2221 + olsrd_avl_insert(&gateway_tree, &gw->node, OLSRD_AVL_DUP_NO);
2222 } else if (olsr_seqno_diff(seqno, gw->seqno) <= 0) {
2223 /* ignore older HNAs */
2225 @@ -1353,7 +1353,7 @@ void olsr_update_gateway_entry(union ols
2226 * gateway tree immediately, else it is removed on a delayed schedule.
2228 void olsr_delete_gateway_entry(union olsr_ip_addr *originator, uint8_t prefixlen, bool immediate) {
2229 - olsr_delete_gateway_tree_entry(node2gateway(avl_find(&gateway_tree, originator)), prefixlen, immediate);
2230 + olsr_delete_gateway_tree_entry(node2gateway(olsrd_avl_find(&gateway_tree, originator)), prefixlen, immediate);
2234 @@ -1526,7 +1526,7 @@ bool olsr_set_inet_gateway(struct gatewa
2238 - new_gw = node2gateway(avl_find(&gateway_tree, &chosen_gw->originator));
2239 + new_gw = node2gateway(olsrd_avl_find(&gateway_tree, &chosen_gw->originator));
2241 /* the originator is not in the gateway tree, we can't set it as gateway */
2249 -#include "common/avl.h"
2250 +#include "common/olsrd_avl.h"
2251 #include "common/list.h"
2254 @@ -96,7 +96,7 @@ enum gateway_hna_fields {
2256 /** a gateway entry */
2257 struct gateway_entry {
2258 - struct avl_node node;
2259 + struct olsrd_avl_node node;
2260 union olsr_ip_addr originator;
2261 struct olsr_ip_prefix external_prefix;
2263 @@ -129,27 +129,27 @@ struct interfaceName {
2264 #endif /* __linux__ */
2267 - * static INLINE struct gateway_entry * node2gateway (struct avl_node *ptr)
2268 + * static INLINE struct gateway_entry * node2gateway (struct olsrd_avl_node *ptr)
2270 * Converts a node into a gateway entry
2272 -AVLNODE2STRUCT(node2gateway, struct gateway_entry, node);
2273 +OLSRD_AVLNODE2STRUCT(node2gateway, struct gateway_entry, node);
2276 * Loop over all gateway entries and put the iterated gateway entry in gw
2278 #define OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) \
2280 - struct avl_node *gw_node, *next_gw_node; \
2281 - for (gw_node = avl_walk_first(&gateway_tree); \
2282 + struct olsrd_avl_node *gw_node, *next_gw_node; \
2283 + for (gw_node = olsrd_avl_walk_first(&gateway_tree); \
2284 gw_node; gw_node = next_gw_node) { \
2285 - next_gw_node = avl_walk_next(gw_node); \
2286 + next_gw_node = olsrd_avl_walk_next(gw_node); \
2287 gw = node2gateway(gw_node); \
2289 #define OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw) }}}
2291 /** the gateway tree */
2292 -extern struct avl_tree gateway_tree;
2293 +extern struct olsrd_avl_tree gateway_tree;
2295 /** the list IPv4 gateways */
2296 extern struct gw_list gw_list_ipv4;
2297 --- a/src/kernel_tunnel.h
2298 +++ b/src/kernel_tunnel.h
2302 #include "olsr_types.h"
2303 -#include "common/avl.h"
2304 +#include "common/olsrd_avl.h"
2306 #define TUNNEL_ENDPOINT_IF "tunl0"
2307 #define TUNNEL_ENDPOINT_IF6 "ip6tnl0"
2311 struct olsr_iptunnel_entry {
2312 - struct avl_node node;
2313 + struct olsrd_avl_node node;
2314 union olsr_ip_addr target;
2316 char if_name[IF_NAMESIZE];
2317 --- a/src/linux/kernel_tunnel.c
2318 +++ b/src/linux/kernel_tunnel.c
2321 static bool store_iptunnel_state;
2322 static struct olsr_cookie_info *tunnel_cookie;
2323 -static struct avl_tree tunnel_tree;
2324 +static struct olsrd_avl_tree tunnel_tree;
2326 int olsr_os_init_iptunnel(const char * dev) {
2327 tunnel_cookie = olsr_alloc_cookie("iptunnel", OLSR_COOKIE_TYPE_MEMORY);
2328 olsr_cookie_set_memory_size(tunnel_cookie, sizeof(struct olsr_iptunnel_entry));
2329 - avl_init(&tunnel_tree, avl_comp_default);
2330 + olsrd_avl_init(&tunnel_tree, olsrd_avl_comp_default);
2332 store_iptunnel_state = olsr_if_isup(dev);
2333 if (store_iptunnel_state) {
2334 @@ -107,7 +107,7 @@ void olsr_os_cleanup_iptunnel(const char
2335 struct olsr_iptunnel_entry *t;
2338 - t = (struct olsr_iptunnel_entry *)avl_walk_first(&tunnel_tree);
2339 + t = (struct olsr_iptunnel_entry *)olsrd_avl_walk_first(&tunnel_tree);
2342 olsr_os_del_ipip_tunnel(t);
2343 @@ -201,7 +201,7 @@ struct olsr_iptunnel_entry *olsr_os_add_
2345 assert(olsr_cnf->ip_version == AF_INET6 || transportV4);
2347 - t = (struct olsr_iptunnel_entry *)avl_find(&tunnel_tree, target);
2348 + t = (struct olsr_iptunnel_entry *)olsrd_avl_find(&tunnel_tree, target);
2351 struct ipaddr_str buf;
2352 @@ -228,7 +228,7 @@ struct olsr_iptunnel_entry *olsr_os_add_
2353 strscpy(t->if_name, name, sizeof(t->if_name));
2354 t->if_index = if_idx;
2356 - avl_insert(&tunnel_tree, &t->node, AVL_DUP_NO);
2357 + olsrd_avl_insert(&tunnel_tree, &t->node, OLSRD_AVL_DUP_NO);
2361 @@ -253,7 +253,7 @@ void olsr_os_del_ipip_tunnel(struct olsr
2362 olsr_if_set_state(t->if_name, false);
2363 os_ip_tunnel(t->if_name, NULL);
2365 - avl_delete(&tunnel_tree, &t->node);
2366 + olsrd_avl_delete(&tunnel_tree, &t->node);
2367 olsr_cookie_free(tunnel_cookie, t);
2369 #endif /* __linux__ */
2370 --- a/src/lq_packet.c
2371 +++ b/src/lq_packet.c
2372 @@ -272,16 +272,16 @@ create_lq_tc(struct lq_tc_message *lq_tc
2374 /* Queue the neighbour entry. */
2376 - // TODO: ugly hack until neighbor table is ported to avl tree
2377 + // TODO: ugly hack until neighbor table is ported to olsrd_avl tree
2379 - if (lq_tc->neigh == NULL || avl_comp_default(&lq_tc->neigh->address, &neigh->address) > 0) {
2380 + if (lq_tc->neigh == NULL || olsrd_avl_comp_default(&lq_tc->neigh->address, &neigh->address) > 0) {
2381 neigh->next = lq_tc->neigh;
2382 lq_tc->neigh = neigh;
2384 struct tc_mpr_addr *last = lq_tc->neigh, *n = last->next;
2387 - if (avl_comp_default(&n->address, &neigh->address) > 0) {
2388 + if (olsrd_avl_comp_default(&n->address, &neigh->address) > 0) {
2392 --- a/src/lq_plugin.c
2393 +++ b/src/lq_plugin.c
2397 #include "two_hop_neighbor_table.h"
2398 -#include "common/avl.h"
2399 +#include "common/olsrd_avl.h"
2401 #include "lq_plugin_default_float.h"
2402 #include "lq_plugin_default_fpm.h"
2407 -struct avl_tree lq_handler_tree;
2408 +struct olsrd_avl_tree lq_handler_tree;
2409 struct lq_handler *active_lq_handler = NULL;
2412 - * case-insensitive string comparator for avl-trees
2413 + * case-insensitive string comparator for olsrd_avl-trees
2419 -avl_strcasecmp(const void *str1, const void *str2)
2420 +olsrd_avl_strcasecmp(const void *str1, const void *str2)
2422 return strcasecmp(str1, str2);
2424 @@ -88,7 +88,7 @@ activate_lq_handler(const char *name)
2426 struct lq_handler_node *node;
2428 - node = (struct lq_handler_node *)avl_find(&lq_handler_tree, name);
2429 + node = (struct lq_handler_node *)olsrd_avl_find(&lq_handler_tree, name);
2432 snprintf(buf, sizeof(buf), "Error, unknown lq_handler '%s'", name);
2433 @@ -106,7 +106,7 @@ activate_lq_handler(const char *name)
2435 init_lq_handler_tree(void)
2437 - avl_init(&lq_handler_tree, &avl_strcasecmp);
2438 + olsrd_avl_init(&lq_handler_tree, &olsrd_avl_strcasecmp);
2439 register_lq_handler(&lq_etx_float_handler, LQ_ALGORITHM_ETX_FLOAT_NAME);
2440 register_lq_handler(&lq_etx_fpm_handler, LQ_ALGORITHM_ETX_FPM_NAME);
2441 register_lq_handler(&lq_etx_ff_handler, LQ_ALGORITHM_ETX_FF_NAME);
2442 @@ -147,7 +147,7 @@ register_lq_handler(struct lq_handler *h
2443 node->node.key = node->name;
2444 node->handler = handler;
2446 - avl_insert(&lq_handler_tree, &node->node, false);
2447 + olsrd_avl_insert(&lq_handler_tree, &node->node, false);
2451 --- a/src/lq_plugin.h
2452 +++ b/src/lq_plugin.h
2454 #include "olsr_spf.h"
2455 #include "lq_packet.h"
2457 -#include "common/avl.h"
2458 +#include "common/olsrd_avl.h"
2460 #define LINK_COST_BROKEN (1u<<22)
2461 #define ROUTE_COST_BROKEN (0xffffffffu)
2462 @@ -97,23 +97,23 @@ struct lq_handler {
2465 struct lq_handler_node {
2466 - struct avl_node node;
2467 + struct olsrd_avl_node node;
2468 struct lq_handler *handler;
2472 -AVLNODE2STRUCT(lq_handler_tree2lq_handler_node, struct lq_handler_node, node);
2473 +OLSRD_AVLNODE2STRUCT(lq_handler_tree2lq_handler_node, struct lq_handler_node, node);
2475 #define OLSR_FOR_ALL_LQ_HANDLERS(lq) \
2477 - struct avl_node *lq_tree_node, *next_lq_tree_node; \
2478 - for (lq_tree_node = avl_walk_first(&lq_handler_tree); \
2479 + struct olsrd_avl_node *lq_tree_node, *next_lq_tree_node; \
2480 + for (lq_tree_node = olsrd_avl_walk_first(&lq_handler_tree); \
2481 lq_tree_node; lq_tree_node = next_lq_tree_node) { \
2482 - next_lq_tree_node = avl_walk_next(lq_tree_node); \
2483 + next_lq_tree_node = olsrd_avl_walk_next(lq_tree_node); \
2484 lq = lq_handler_tree2lq_handler_node(lq_tree_node);
2485 #define OLSR_FOR_ALL_LQ_HANDLERS_END(tc) }}
2487 -int avl_strcasecmp(const void *str1, const void *str2);
2488 +int olsrd_avl_strcasecmp(const void *str1, const void *str2);
2489 void init_lq_handler_tree(void);
2491 void register_lq_handler(struct lq_handler *handler, const char *name);
2495 #include "neighbor_table.h"
2497 #include "lq_packet.h"
2498 -#include "common/avl.h"
2499 +#include "common/olsrd_avl.h"
2500 #include "net_olsr.h"
2501 #include "lq_plugin.h"
2502 #include "gateway.h"
2503 @@ -260,13 +260,13 @@ olsr_init_tables(void)
2504 changes_neighborhood = false;
2505 changes_hna = false;
2507 - /* Set avl tree comparator */
2508 + /* Set olsrd_avl tree comparator */
2509 if (olsr_cnf->ipsize == 4) {
2510 - avl_comp_default = avl_comp_ipv4;
2511 - avl_comp_prefix_default = avl_comp_ipv4_prefix;
2512 + olsrd_avl_comp_default = olsrd_avl_comp_ipv4;
2513 + olsrd_avl_comp_prefix_default = olsrd_avl_comp_ipv4_prefix;
2515 - avl_comp_default = avl_comp_ipv6;
2516 - avl_comp_prefix_default = avl_comp_ipv6_prefix;
2517 + olsrd_avl_comp_default = olsrd_avl_comp_ipv6;
2518 + olsrd_avl_comp_prefix_default = olsrd_avl_comp_ipv6_prefix;
2521 /* Initialize lq plugin set */
2522 --- a/src/olsr_spf.c
2523 +++ b/src/olsr_spf.c
2525 * Implementation of Dijkstras algorithm. Initially all nodes
2526 * are initialized to infinite cost. First we put ourselves
2527 * on the heap of reachable nodes. Our heap implementation
2528 - * is based on an AVL tree which gives interesting performance
2529 + * is based on an OLSRD_AVL tree which gives interesting performance
2530 * characteristics for the frequent operations of minimum key
2531 * extraction and re-keying. Next all neighbors of a node are
2532 * explored and put on the heap if the cost of reaching them is
2534 #include "mid_set.h"
2535 #include "hna_set.h"
2536 #include "common/list.h"
2537 -#include "common/avl.h"
2538 +#include "common/olsrd_avl.h"
2539 #include "olsr_spf.h"
2540 #include "net_olsr.h"
2541 #include "lq_plugin.h"
2543 struct timer_entry *spf_backoff_timer = NULL;
2547 + * olsrd_avl_comp_etx
2549 * compare two etx metrics.
2550 * return 0 if there is an exact match and
2551 @@ -89,7 +89,7 @@ struct timer_entry *spf_backoff_timer =
2552 * after compiler optimization.
2555 -avl_comp_etx(const void *etx1, const void *etx2)
2556 +olsrd_avl_comp_etx(const void *etx1, const void *etx2)
2558 if (*(const olsr_linkcost *)etx1 < *(const olsr_linkcost *)etx2) {
2560 @@ -108,7 +108,7 @@ avl_comp_etx(const void *etx1, const voi
2561 * Key an existing vertex to a candidate tree.
2564 -olsr_spf_add_cand_tree(struct avl_tree *tree, struct tc_entry *tc)
2565 +olsr_spf_add_cand_tree(struct olsrd_avl_tree *tree, struct tc_entry *tc)
2567 #if !defined(NODEBUG) && defined(DEBUG)
2568 struct ipaddr_str buf;
2569 @@ -121,7 +121,7 @@ olsr_spf_add_cand_tree(struct avl_tree *
2570 get_linkcost_text(tc->path_cost, true, &lqbuffer));
2573 - avl_insert(tree, &tc->cand_tree_node, AVL_DUP);
2574 + olsrd_avl_insert(tree, &tc->cand_tree_node, OLSRD_AVL_DUP);
2578 @@ -130,7 +130,7 @@ olsr_spf_add_cand_tree(struct avl_tree *
2579 * Unkey an existing vertex from a candidate tree.
2582 -olsr_spf_del_cand_tree(struct avl_tree *tree, struct tc_entry *tc)
2583 +olsr_spf_del_cand_tree(struct olsrd_avl_tree *tree, struct tc_entry *tc)
2587 @@ -142,7 +142,7 @@ olsr_spf_del_cand_tree(struct avl_tree *
2588 get_linkcost_text(tc->path_cost, true, &lqbuffer));
2591 - avl_delete(tree, &tc->cand_tree_node);
2592 + olsrd_avl_delete(tree, &tc->cand_tree_node);
2596 @@ -175,9 +175,9 @@ olsr_spf_add_path_list(struct list_node
2597 * return the node with the minimum pathcost.
2599 static struct tc_entry *
2600 -olsr_spf_extract_best(struct avl_tree *tree)
2601 +olsr_spf_extract_best(struct olsrd_avl_tree *tree)
2603 - struct avl_node *node = avl_walk_first(tree);
2604 + struct olsrd_avl_node *node = olsrd_avl_walk_first(tree);
2606 return (node ? cand_tree2tc(node) : NULL);
2608 @@ -190,9 +190,9 @@ olsr_spf_extract_best(struct avl_tree *t
2609 * path cost is better.
2612 -olsr_spf_relax(struct avl_tree *cand_tree, struct tc_entry *tc)
2613 +olsr_spf_relax(struct olsrd_avl_tree *cand_tree, struct tc_entry *tc)
2615 - struct avl_node *edge_node;
2616 + struct olsrd_avl_node *edge_node;
2617 olsr_linkcost new_cost;
2620 @@ -207,7 +207,7 @@ olsr_spf_relax(struct avl_tree *cand_tre
2622 * loop through all edges of this vertex.
2624 - for (edge_node = avl_walk_first(&tc->edge_tree); edge_node; edge_node = avl_walk_next(edge_node)) {
2625 + for (edge_node = olsrd_avl_walk_first(&tc->edge_tree); edge_node; edge_node = olsrd_avl_walk_next(edge_node)) {
2627 struct tc_entry *new_tc;
2628 struct tc_edge_entry *tc_edge = edge_tree2tc_edge(edge_node);
2629 @@ -289,7 +289,7 @@ olsr_spf_relax(struct avl_tree *cand_tre
2630 * on the candidate tree.
2633 -olsr_spf_run_full(struct avl_tree *cand_tree, struct list_node *path_list, int *path_count)
2634 +olsr_spf_run_full(struct olsrd_avl_tree *cand_tree, struct list_node *path_list, int *path_count)
2636 struct tc_entry *tc;
2638 @@ -335,8 +335,8 @@ olsr_calculate_routing_table(bool force)
2639 #ifdef SPF_PROFILING
2640 struct timespec t1, t2, t3, t4, t5, spf_init, spf_run, route, kernel, total;
2641 #endif /* SPF_PROFILING */
2642 - struct avl_tree cand_tree;
2643 - struct avl_node *rtp_tree_node;
2644 + struct olsrd_avl_tree cand_tree;
2645 + struct olsrd_avl_node *rtp_tree_node;
2646 struct list_node path_list; /* head of the path_list */
2647 struct tc_entry *tc;
2648 struct rt_path *rtp;
2649 @@ -362,7 +362,7 @@ olsr_calculate_routing_table(bool force)
2651 * Prepare the candidate tree and result list.
2653 - avl_init(&cand_tree, avl_comp_etx);
2654 + olsrd_avl_init(&cand_tree, olsrd_avl_comp_etx);
2655 list_head_init(&path_list);
2656 olsr_bump_routingtree_version();
2658 @@ -493,7 +493,7 @@ olsr_calculate_routing_table(bool force)
2659 * If the prefix is already in the RIB, refresh the entry such
2660 * that olsr_delete_outdated_routes() does not purge it off.
2662 - for (rtp_tree_node = avl_walk_first(&tc->prefix_tree); rtp_tree_node; rtp_tree_node = avl_walk_next(rtp_tree_node)) {
2663 + for (rtp_tree_node = olsrd_avl_walk_first(&tc->prefix_tree); rtp_tree_node; rtp_tree_node = olsrd_avl_walk_next(rtp_tree_node)) {
2665 rtp = rtp_prefix_tree2rtp(rtp_tree_node);
2667 --- a/src/process_routes.c
2668 +++ b/src/process_routes.c
2672 #include "kernel_routes.h"
2673 -#include "common/avl.h"
2674 +#include "common/olsrd_avl.h"
2675 #include "net_olsr.h"
2677 #include "olsr_cookie.h"
2678 @@ -289,13 +289,13 @@ static void
2679 olsr_delete_outdated_routes(struct rt_entry *rt)
2681 struct rt_path *rtp;
2682 - struct avl_node *rtp_tree_node, *next_rtp_tree_node;
2683 + struct olsrd_avl_node *rtp_tree_node, *next_rtp_tree_node;
2685 - for (rtp_tree_node = avl_walk_first(&rt->rt_path_tree); rtp_tree_node != NULL; rtp_tree_node = next_rtp_tree_node) {
2686 + for (rtp_tree_node = olsrd_avl_walk_first(&rt->rt_path_tree); rtp_tree_node != NULL; rtp_tree_node = next_rtp_tree_node) {
2688 * pre-fetch the next node before loosing context.
2690 - next_rtp_tree_node = avl_walk_next(rtp_tree_node);
2691 + next_rtp_tree_node = olsrd_avl_walk_next(rtp_tree_node);
2693 rtp = rtp_tree2rtp(rtp_tree_node);
2695 @@ -305,7 +305,7 @@ olsr_delete_outdated_routes(struct rt_en
2697 if (routingtree_version != rtp->rtp_version) {
2698 /* remove from the originator tree */
2699 - avl_delete(&rt->rt_path_tree, rtp_tree_node);
2700 + olsrd_avl_delete(&rt->rt_path_tree, rtp_tree_node);
2703 if (rt->rt_best == rtp) {
2704 @@ -341,7 +341,7 @@ olsr_update_rib_routes(void)
2706 if (olsr_delete_kernel_route(rt) == 0) {
2707 /*only remove if deletion was successful*/
2708 - avl_delete(&routingtree, &rt->rt_tree_node);
2709 + olsrd_avl_delete(&routingtree, &rt->rt_tree_node);
2710 olsr_cookie_free(rt_mem_cookie, rt);
2713 @@ -370,21 +370,21 @@ olsr_delete_interface_routes(int if_inde
2714 OLSR_FOR_ALL_RT_ENTRIES(rt) {
2715 bool mightTrigger = false;
2716 struct rt_path *rtp;
2717 - struct avl_node *rtp_tree_node, *next_rtp_tree_node;
2718 + struct olsrd_avl_node *rtp_tree_node, *next_rtp_tree_node;
2720 /* run through all routing paths of route */
2721 - for (rtp_tree_node = avl_walk_first(&rt->rt_path_tree); rtp_tree_node != NULL; rtp_tree_node = next_rtp_tree_node) {
2722 + for (rtp_tree_node = olsrd_avl_walk_first(&rt->rt_path_tree); rtp_tree_node != NULL; rtp_tree_node = next_rtp_tree_node) {
2724 * pre-fetch the next node before loosing context.
2726 - next_rtp_tree_node = avl_walk_next(rtp_tree_node);
2727 + next_rtp_tree_node = olsrd_avl_walk_next(rtp_tree_node);
2729 rtp = rtp_tree2rtp(rtp_tree_node);
2731 /* nexthop use lost interface ? */
2732 if (rtp->rtp_nexthop.iif_index == if_index) {
2733 /* remove from the originator tree */
2734 - avl_delete(&rt->rt_path_tree, rtp_tree_node);
2735 + olsrd_avl_delete(&rt->rt_path_tree, rtp_tree_node);
2738 if (rt->rt_best == rtp) {
2739 @@ -397,7 +397,7 @@ olsr_delete_interface_routes(int if_inde
2741 if (!rt->rt_path_tree.count) {
2742 /* oops, all routes are gone - flush the route head */
2743 - avl_delete(&routingtree, rt_tree_node);
2744 + olsrd_avl_delete(&routingtree, rt_tree_node);
2746 /* do not dequeue route because they are already gone */
2748 --- a/src/routing_table.c
2749 +++ b/src/routing_table.c
2751 #include "neighbor_table.h"
2753 #include "link_set.h"
2754 -#include "common/avl.h"
2755 +#include "common/olsrd_avl.h"
2756 #include "olsr_spf.h"
2757 #include "net_olsr.h"
2759 @@ -72,7 +72,7 @@ struct olsr_cookie_info *rtp_mem_cookie
2760 static struct rt_path *current_inetgw = NULL;
2762 /* Root of our RIB */
2763 -struct avl_tree routingtree;
2764 +struct olsrd_avl_tree routingtree;
2767 * Keep a version number for detecting outdated elements
2768 @@ -95,7 +95,7 @@ olsr_bump_routingtree_version(void)
2772 - * avl_comp_ipv4_prefix
2773 + * olsrd_avl_comp_ipv4_prefix
2775 * compare two ipv4 prefixes.
2776 * first compare the prefixes, then
2777 @@ -105,7 +105,7 @@ olsr_bump_routingtree_version(void)
2778 * -1 / +1 depending on being smaller or bigger.
2781 -avl_comp_ipv4_prefix(const void *prefix1, const void *prefix2)
2782 +olsrd_avl_comp_ipv4_prefix(const void *prefix1, const void *prefix2)
2784 const struct olsr_ip_prefix *pfx1 = prefix1;
2785 const struct olsr_ip_prefix *pfx2 = prefix2;
2786 @@ -132,7 +132,7 @@ avl_comp_ipv4_prefix(const void *prefix1
2790 - * avl_comp_ipv6_prefix
2791 + * olsrd_avl_comp_ipv6_prefix
2793 * compare two ipv6 prefixes.
2794 * first compare the prefixes, then
2795 @@ -142,7 +142,7 @@ avl_comp_ipv4_prefix(const void *prefix1
2796 * -1 / +1 depending on being smaller or bigger.
2799 -avl_comp_ipv6_prefix(const void *prefix1, const void *prefix2)
2800 +olsrd_avl_comp_ipv6_prefix(const void *prefix1, const void *prefix2)
2803 const struct olsr_ip_prefix *pfx1 = prefix1;
2804 @@ -173,7 +173,7 @@ olsr_init_routing_table(void)
2805 OLSR_PRINTF(5, "RIB: init routing tree\n");
2807 /* the routing tree */
2808 - avl_init(&routingtree, avl_comp_prefix_default);
2809 + olsrd_avl_init(&routingtree, olsrd_avl_comp_prefix_default);
2810 routingtree_version = 0;
2813 @@ -197,13 +197,13 @@ olsr_init_routing_table(void)
2815 olsr_lookup_routing_table(const union olsr_ip_addr *dst)
2817 - struct avl_node *rt_tree_node;
2818 + struct olsrd_avl_node *rt_tree_node;
2819 struct olsr_ip_prefix prefix;
2821 prefix.prefix = *dst;
2822 prefix.prefix_len = olsr_cnf->maxplen;
2824 - rt_tree_node = avl_find(&routingtree, &prefix);
2825 + rt_tree_node = olsrd_avl_find(&routingtree, &prefix);
2827 return rt_tree_node ? rt_tree2rt(rt_tree_node) : NULL;
2829 @@ -248,10 +248,10 @@ olsr_alloc_rt_entry(struct olsr_ip_prefi
2830 rt->rt_dst = *prefix;
2832 rt->rt_tree_node.key = &rt->rt_dst;
2833 - avl_insert(&routingtree, &rt->rt_tree_node, AVL_DUP_NO);
2834 + olsrd_avl_insert(&routingtree, &rt->rt_tree_node, OLSRD_AVL_DUP_NO);
2836 /* init the originator subtree */
2837 - avl_init(&rt->rt_path_tree, avl_comp_default);
2838 + olsrd_avl_init(&rt->rt_path_tree, olsrd_avl_comp_default);
2842 @@ -276,7 +276,7 @@ olsr_alloc_rt_path(struct tc_entry *tc,
2843 rtp->rtp_prefix_tree_node.key = &rtp->rtp_dst;
2845 /* insert to the tc prefix tree */
2846 - avl_insert(&tc->prefix_tree, &rtp->rtp_prefix_tree_node, AVL_DUP_NO);
2847 + olsrd_avl_insert(&tc->prefix_tree, &rtp->rtp_prefix_tree_node, OLSRD_AVL_DUP_NO);
2848 olsr_lock_tc_entry(tc);
2850 /* backlink to the owning tc entry */
2851 @@ -296,7 +296,7 @@ void
2852 olsr_insert_rt_path(struct rt_path *rtp, struct tc_entry *tc, struct link_entry *link)
2854 struct rt_entry *rt;
2855 - struct avl_node *node;
2856 + struct olsrd_avl_node *node;
2859 * no unreachable routes please.
2860 @@ -315,7 +315,7 @@ olsr_insert_rt_path(struct rt_path *rtp,
2862 * first check if there is a route_entry for the prefix.
2864 - node = avl_find(&routingtree, &rtp->rtp_dst);
2865 + node = olsrd_avl_find(&routingtree, &rtp->rtp_dst);
2869 @@ -337,7 +337,7 @@ olsr_insert_rt_path(struct rt_path *rtp,
2870 rtp->rtp_tree_node.key = &rtp->rtp_originator;
2872 /* insert to the route entry originator tree */
2873 - avl_insert(&rt->rt_path_tree, &rtp->rtp_tree_node, AVL_DUP_NO);
2874 + olsrd_avl_insert(&rt->rt_path_tree, &rtp->rtp_tree_node, OLSRD_AVL_DUP_NO);
2876 /* backlink to the owning route entry */
2878 @@ -356,13 +356,13 @@ olsr_delete_rt_path(struct rt_path *rtp)
2880 /* remove from the originator tree */
2882 - avl_delete(&rtp->rtp_rt->rt_path_tree, &rtp->rtp_tree_node);
2883 + olsrd_avl_delete(&rtp->rtp_rt->rt_path_tree, &rtp->rtp_tree_node);
2887 /* remove from the tc prefix tree */
2889 - avl_delete(&rtp->rtp_tc->prefix_tree, &rtp->rtp_prefix_tree_node);
2890 + olsrd_avl_delete(&rtp->rtp_tc->prefix_tree, &rtp->rtp_prefix_tree_node);
2891 olsr_unlock_tc_entry(rtp->rtp_tc);
2894 @@ -498,14 +498,14 @@ void
2895 olsr_rt_best(struct rt_entry *rt)
2897 /* grab the first entry */
2898 - struct avl_node *node = avl_walk_first(&rt->rt_path_tree);
2899 + struct olsrd_avl_node *node = olsrd_avl_walk_first(&rt->rt_path_tree);
2901 assert(node != 0); /* should not happen */
2903 rt->rt_best = rtp_tree2rtp(node);
2905 /* walk all remaining originator entries */
2906 - while ((node = avl_walk_next(node))) {
2907 + while ((node = olsrd_avl_walk_next(node))) {
2908 struct rt_path *rtp = rtp_tree2rtp(node);
2910 if (olsr_cmp_rtp(rtp, rt->rt_best, current_inetgw)) {
2911 @@ -541,7 +541,7 @@ olsr_insert_routing_table(union olsr_ip_
2913 struct tc_entry *tc;
2914 struct rt_path *rtp;
2915 - struct avl_node *node;
2916 + struct olsrd_avl_node *node;
2917 struct olsr_ip_prefix prefix;
2920 @@ -567,7 +567,7 @@ olsr_insert_routing_table(union olsr_ip_
2921 prefix.prefix = *dst;
2922 prefix.prefix_len = plen;
2924 - node = avl_find(&tc->prefix_tree, &prefix);
2925 + node = olsrd_avl_find(&tc->prefix_tree, &prefix);
2929 @@ -604,7 +604,7 @@ olsr_delete_routing_table(union olsr_ip_
2931 struct tc_entry *tc;
2932 struct rt_path *rtp;
2933 - struct avl_node *node;
2934 + struct olsrd_avl_node *node;
2935 struct olsr_ip_prefix prefix;
2938 @@ -625,7 +625,7 @@ olsr_delete_routing_table(union olsr_ip_
2939 prefix.prefix = *dst;
2940 prefix.prefix_len = plen;
2942 - node = avl_find(&tc->prefix_tree, &prefix);
2943 + node = olsrd_avl_find(&tc->prefix_tree, &prefix);
2946 rtp = rtp_prefix_tree2rtp(node);
2947 @@ -682,16 +682,16 @@ olsr_rtp_to_string(const struct rt_path
2951 -olsr_print_routing_table(struct avl_tree *tree)
2952 +olsr_print_routing_table(struct olsrd_avl_tree *tree)
2954 /* The whole function makes no sense without it. */
2955 - struct avl_node *rt_tree_node;
2956 + struct olsrd_avl_node *rt_tree_node;
2957 struct lqtextbuffer lqbuffer;
2959 OLSR_PRINTF(6, "ROUTING TABLE\n");
2961 - for (rt_tree_node = avl_walk_first(tree); rt_tree_node != NULL; rt_tree_node = avl_walk_next(rt_tree_node)) {
2962 - struct avl_node *rtp_tree_node;
2963 + for (rt_tree_node = olsrd_avl_walk_first(tree); rt_tree_node != NULL; rt_tree_node = olsrd_avl_walk_next(rt_tree_node)) {
2964 + struct olsrd_avl_node *rtp_tree_node;
2965 struct ipaddr_str prefixstr, origstr, gwstr;
2966 struct rt_entry *rt = rt_tree2rt(rt_tree_node);
2968 @@ -700,7 +700,7 @@ olsr_print_routing_table(struct avl_tree
2969 olsr_ip_to_string(&origstr, &rt->rt_nexthop.gateway), olsr_ip_to_string(&gwstr, &rt->rt_best->rtp_originator));
2971 /* walk the per-originator path tree of routes */
2972 - for (rtp_tree_node = avl_walk_first(&rt->rt_path_tree); rtp_tree_node != NULL; rtp_tree_node = avl_walk_next(rtp_tree_node)) {
2973 + for (rtp_tree_node = olsrd_avl_walk_first(&rt->rt_path_tree); rtp_tree_node != NULL; rtp_tree_node = olsrd_avl_walk_next(rtp_tree_node)) {
2974 struct rt_path *rtp = rtp_tree2rtp(rtp_tree_node);
2975 OLSR_PRINTF(6, "\tfrom %s, cost %s, metric %u, via %s, %s, v %u\n", olsr_ip_to_string(&origstr, &rtp->rtp_originator),
2976 get_linkcost_text(rtp->rtp_metric.cost, true, &lqbuffer), rtp->rtp_metric.hops, olsr_ip_to_string(&gwstr,
2977 --- a/src/routing_table.h
2978 +++ b/src/routing_table.h
2980 #include "hna_set.h"
2981 #include "link_set.h"
2982 #include "olsr_cookie.h"
2983 -#include "common/avl.h"
2984 +#include "common/olsrd_avl.h"
2985 #include "common/list.h"
2987 #define NETMASK_HOST 0xffffffff
2988 @@ -81,15 +81,15 @@ struct rt_nexthop {
2991 struct olsr_ip_prefix rt_dst;
2992 - struct avl_node rt_tree_node;
2993 + struct olsrd_avl_node rt_tree_node;
2994 struct rt_path *rt_best; /* shortcut to the best path */
2995 struct rt_nexthop rt_nexthop; /* nexthop of FIB route */
2996 struct rt_metric rt_metric; /* metric of FIB route */
2997 - struct avl_tree rt_path_tree;
2998 + struct olsrd_avl_tree rt_path_tree;
2999 struct list_node rt_change_node; /* queue for kernel FIB add/chg/del */
3002 -AVLNODE2STRUCT(rt_tree2rt, struct rt_entry, rt_tree_node);
3003 +OLSRD_AVLNODE2STRUCT(rt_tree2rt, struct rt_entry, rt_tree_node);
3004 LISTNODE2STRUCT(changelist2rt, struct rt_entry, rt_change_node);
3007 @@ -105,16 +105,16 @@ struct rt_path {
3008 struct tc_entry *rtp_tc; /* backpointer to owning tc entry */
3009 struct rt_nexthop rtp_nexthop;
3010 struct rt_metric rtp_metric;
3011 - struct avl_node rtp_tree_node; /* global rtp node */
3012 + struct olsrd_avl_node rtp_tree_node; /* global rtp node */
3013 union olsr_ip_addr rtp_originator; /* originator of the route */
3014 - struct avl_node rtp_prefix_tree_node; /* tc entry rtp node */
3015 + struct olsrd_avl_node rtp_prefix_tree_node; /* tc entry rtp node */
3016 struct olsr_ip_prefix rtp_dst; /* the prefix */
3017 uint32_t rtp_version; /* for detection of outdated rt_paths */
3018 uint8_t rtp_origin; /* internal, MID or HNA */
3021 -AVLNODE2STRUCT(rtp_tree2rtp, struct rt_path, rtp_tree_node);
3022 -AVLNODE2STRUCT(rtp_prefix_tree2rtp, struct rt_path, rtp_prefix_tree_node);
3023 +OLSRD_AVLNODE2STRUCT(rtp_tree2rtp, struct rt_path, rtp_tree_node);
3024 +OLSRD_AVLNODE2STRUCT(rtp_prefix_tree2rtp, struct rt_path, rtp_prefix_tree_node);
3027 * In olsrd we have three different route types.
3028 @@ -143,10 +143,10 @@ enum olsr_rt_origin {
3030 #define OLSR_FOR_ALL_RT_ENTRIES(rt) \
3032 - struct avl_node *rt_tree_node, *next_rt_tree_node; \
3033 - for (rt_tree_node = avl_walk_first(&routingtree); \
3034 + struct olsrd_avl_node *rt_tree_node, *next_rt_tree_node; \
3035 + for (rt_tree_node = olsrd_avl_walk_first(&routingtree); \
3036 rt_tree_node; rt_tree_node = next_rt_tree_node) { \
3037 - next_rt_tree_node = avl_walk_next(rt_tree_node); \
3038 + next_rt_tree_node = olsrd_avl_walk_next(rt_tree_node); \
3039 rt = rt_tree2rt(rt_tree_node);
3040 #define OLSR_FOR_ALL_RT_ENTRIES_END(rt) }}
3042 @@ -164,10 +164,10 @@ enum olsr_rt_origin {
3044 #define OLSR_FOR_ALL_HNA_RT_ENTRIES(rt) \
3046 - struct avl_node *rt_tree_node, *next_rt_tree_node; \
3047 - for (rt_tree_node = avl_walk_first(&routingtree); \
3048 + struct olsrd_avl_node *rt_tree_node, *next_rt_tree_node; \
3049 + for (rt_tree_node = olsrd_avl_walk_first(&routingtree); \
3050 rt_tree_node; rt_tree_node = next_rt_tree_node) { \
3051 - next_rt_tree_node = avl_walk_next(rt_tree_node); \
3052 + next_rt_tree_node = olsrd_avl_walk_next(rt_tree_node); \
3053 rt = rt_tree2rt(rt_tree_node); \
3054 if (rt->rt_best->rtp_origin != OLSR_RT_ORIGIN_HNA) \
3056 @@ -190,7 +190,7 @@ union olsr_kernel_route {
3060 -extern struct avl_tree routingtree;
3061 +extern struct olsrd_avl_tree routingtree;
3062 extern unsigned int routingtree_version;
3063 extern struct olsr_cookie_info *rt_mem_cookie;
3065 @@ -198,8 +198,8 @@ void olsr_init_routing_table(void);
3067 unsigned int olsr_bump_routingtree_version(void);
3069 -int avl_comp_ipv4_prefix(const void *, const void *);
3070 -int avl_comp_ipv6_prefix(const void *, const void *);
3071 +int olsrd_avl_comp_ipv4_prefix(const void *, const void *);
3072 +int olsrd_avl_comp_ipv6_prefix(const void *, const void *);
3074 void olsr_rt_best(struct rt_entry *);
3075 bool olsr_nh_change(const struct rt_nexthop *, const struct rt_nexthop *);
3076 @@ -210,7 +210,7 @@ uint8_t olsr_fib_metric(const struct rt_
3077 char *olsr_rt_to_string(const struct rt_entry *);
3078 char *olsr_rtp_to_string(const struct rt_path *);
3080 -void olsr_print_routing_table(struct avl_tree *);
3081 +void olsr_print_routing_table(struct olsrd_avl_tree *);
3083 #define olsr_print_routing_table(x) do { } while(0)
3085 --- a/src/scheduler.c
3086 +++ b/src/scheduler.c
3089 #include "mpr_selector_set.h"
3090 #include "olsr_random.h"
3091 -#include "common/avl.h"
3092 +#include "common/olsrd_avl.h"
3094 #include <sys/times.h>
3096 @@ -89,29 +89,29 @@ static void poll_sockets(void);
3097 static uint32_t calc_jitter(unsigned int rel_time, uint8_t jitter_pct, unsigned int random_val);
3098 static void olsr_cleanup_timer(struct timer_entry *timer);
3100 -struct avl_tree timer_cleanup_tree;
3101 +struct olsrd_avl_tree timer_cleanup_tree;
3103 struct timer_cleanup_entry {
3104 - struct avl_node avl;
3105 + struct olsrd_avl_node olsrd_avl;
3106 struct timer_entry * timer;
3109 -/* static INLINE struct timer_cleanup_entry * node2timercleanup(struct avl_node *ptr) */
3110 -AVLNODE2STRUCT(node2timercleanup, struct timer_cleanup_entry, avl);
3111 +/* static INLINE struct timer_cleanup_entry * node2timercleanup(struct olsrd_avl_node *ptr) */
3112 +OLSRD_AVLNODE2STRUCT(node2timercleanup, struct timer_cleanup_entry, olsrd_avl);
3115 * Loop over all timer cleanup entries and put the iterated entry in timer
3117 #define OLSR_FOR_ALL_TIMERS_CLEANUP(timer) \
3119 - struct avl_node *timer_avl_node, *timer_avl_node_next; \
3120 - for (timer_avl_node = avl_walk_first(&timer_cleanup_tree); \
3121 - timer_avl_node; timer_avl_node = timer_avl_node_next) { \
3122 - timer_avl_node_next = avl_walk_next(timer_avl_node); \
3123 - timer = node2timercleanup(timer_avl_node);
3124 + struct olsrd_avl_node *timer_olsrd_avl_node, *timer_olsrd_avl_node_next; \
3125 + for (timer_olsrd_avl_node = olsrd_avl_walk_first(&timer_cleanup_tree); \
3126 + timer_olsrd_avl_node; timer_olsrd_avl_node = timer_olsrd_avl_node_next) { \
3127 + timer_olsrd_avl_node_next = olsrd_avl_walk_next(timer_olsrd_avl_node); \
3128 + timer = node2timercleanup(timer_olsrd_avl_node);
3129 #define OLSR_FOR_ALL_TIMER_CLEANUP_END(timer) }}
3131 -static int avl_comp_timer(const void *entry1, const void *entry2) {
3132 +static int olsrd_avl_comp_timer(const void *entry1, const void *entry2) {
3133 if (entry1 < entry2) {
3136 @@ -638,7 +638,7 @@ olsr_init_timers(void)
3138 now_times = olsr_times();
3140 - avl_init(&timer_cleanup_tree, avl_comp_timer);
3141 + olsrd_avl_init(&timer_cleanup_tree, olsrd_avl_comp_timer);
3143 for (idx = 0; idx < TIMER_WHEEL_SLOTS; idx++) {
3144 list_head_init(&timer_wheel[idx]);
3145 @@ -760,7 +760,7 @@ static void walk_timers_cleanup(void) {
3147 OLSR_FOR_ALL_TIMERS_CLEANUP(timer) {
3148 olsr_cleanup_timer(timer->timer);
3149 - avl_delete(&timer_cleanup_tree, &timer->avl);
3150 + olsrd_avl_delete(&timer_cleanup_tree, &timer->olsrd_avl);
3152 } OLSR_FOR_ALL_TIMER_CLEANUP_END(slot)
3154 @@ -969,9 +969,9 @@ olsr_stop_timer(struct timer_entry *time
3157 struct timer_cleanup_entry * node = olsr_malloc(sizeof(struct timer_cleanup_entry), "timer cleanup entry");
3158 - node->avl.key = timer;
3159 + node->olsrd_avl.key = timer;
3160 node->timer = timer;
3161 - if (avl_insert(&timer_cleanup_tree, &node->avl, AVL_DUP_NO) == -1) {
3162 + if (olsrd_avl_insert(&timer_cleanup_tree, &node->olsrd_avl, OLSRD_AVL_DUP_NO) == -1) {
3170 #include "scheduler.h"
3171 #include "olsr_spf.h"
3172 -#include "common/avl.h"
3173 +#include "common/olsrd_avl.h"
3174 #include "lq_packet.h"
3175 #include "net_olsr.h"
3176 #include "lq_plugin.h"
3180 /* Root of the link state database */
3181 -struct avl_tree tc_tree;
3182 +struct olsrd_avl_tree tc_tree;
3183 struct tc_entry *tc_myself; /* Shortcut to ourselves */
3185 /* Some cookies for stats keeping */
3186 @@ -165,14 +165,14 @@ olsr_add_tc_entry(union olsr_ip_addr *ad
3188 * Insert into the global tc tree.
3190 - avl_insert(&tc_tree, &tc->vertex_node, AVL_DUP_NO);
3191 + olsrd_avl_insert(&tc_tree, &tc->vertex_node, OLSRD_AVL_DUP_NO);
3192 olsr_lock_tc_entry(tc);
3195 * Initialize subtrees for edges and prefixes.
3197 - avl_init(&tc->edge_tree, avl_comp_default);
3198 - avl_init(&tc->prefix_tree, avl_comp_prefix_default);
3199 + olsrd_avl_init(&tc->edge_tree, olsrd_avl_comp_default);
3200 + olsrd_avl_init(&tc->prefix_tree, olsrd_avl_comp_prefix_default);
3203 * Add a rt_path for ourselves.
3204 @@ -191,7 +191,7 @@ olsr_init_tc(void)
3206 OLSR_PRINTF(5, "TC: init topo\n");
3208 - avl_init(&tc_tree, avl_comp_default);
3209 + olsrd_avl_init(&tc_tree, olsrd_avl_comp_default);
3212 * Get some cookies for getting stats to ease troubleshooting.
3213 @@ -308,7 +308,7 @@ olsr_delete_tc_entry(struct tc_entry *tc
3214 olsr_stop_timer(tc->validity_timer);
3215 tc->validity_timer = NULL;
3217 - avl_delete(&tc_tree, &tc->vertex_node);
3218 + olsrd_avl_delete(&tc_tree, &tc->vertex_node);
3219 olsr_unlock_tc_entry(tc);
3222 @@ -321,9 +321,9 @@ olsr_delete_tc_entry(struct tc_entry *tc
3224 olsr_lookup_tc_entry(union olsr_ip_addr *adr)
3226 - struct avl_node *node;
3227 + struct olsrd_avl_node *node;
3229 - node = avl_find(&tc_tree, adr);
3230 + node = olsrd_avl_find(&tc_tree, adr);
3232 return (node ? vertex_tree2tc(node) : NULL);
3234 @@ -454,7 +454,7 @@ olsr_add_tc_edge_entry(struct tc_entry *
3236 * Insert into the edge tree.
3238 - avl_insert(&tc->edge_tree, &tc_edge->edge_node, AVL_DUP_NO);
3239 + olsrd_avl_insert(&tc->edge_tree, &tc_edge->edge_node, OLSRD_AVL_DUP_NO);
3240 olsr_lock_tc_entry(tc);
3243 @@ -515,7 +515,7 @@ olsr_delete_tc_edge_entry(struct tc_edge
3247 - avl_delete(&tc->edge_tree, &tc_edge->edge_node);
3248 + olsrd_avl_delete(&tc->edge_tree, &tc_edge->edge_node);
3249 olsr_unlock_tc_entry(tc);
3252 @@ -572,7 +572,7 @@ olsr_delete_revoked_tc_edges(struct tc_e
3254 OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
3255 if (!passedLowerBorder) {
3256 - if (avl_comp_default(lower_border, &tc_edge->T_dest_addr) <= 0) {
3257 + if (olsrd_avl_comp_default(lower_border, &tc_edge->T_dest_addr) <= 0) {
3258 passedLowerBorder = true;
3261 @@ -580,7 +580,7 @@ olsr_delete_revoked_tc_edges(struct tc_e
3264 if (passedLowerBorder) {
3265 - if (avl_comp_default(upper_border, &tc_edge->T_dest_addr) <= 0) {
3266 + if (olsrd_avl_comp_default(upper_border, &tc_edge->T_dest_addr) <= 0) {
3270 @@ -680,9 +680,9 @@ olsr_tc_update_edge(struct tc_entry *tc,
3271 struct tc_edge_entry *
3272 olsr_lookup_tc_edge(struct tc_entry *tc, union olsr_ip_addr *edge_addr)
3274 - struct avl_node *edge_node;
3275 + struct olsrd_avl_node *edge_node;
3277 - edge_node = avl_find(&tc->edge_tree, edge_addr);
3278 + edge_node = olsrd_avl_find(&tc->edge_tree, edge_addr);
3280 return (edge_node ? edge_tree2tc_edge(edge_node) : NULL);
3288 -#include "common/avl.h"
3289 +#include "common/olsrd_avl.h"
3290 #include "common/list.h"
3291 #include "scheduler.h"
3296 struct tc_edge_entry {
3297 - struct avl_node edge_node; /* edge_tree node in tc_entry */
3298 + struct olsrd_avl_node edge_node; /* edge_tree node in tc_entry */
3299 union olsr_ip_addr T_dest_addr; /* edge_node key */
3300 struct tc_edge_entry *edge_inv; /* shortcut, used during SPF calculation */
3301 struct tc_entry *tc; /* backpointer to owning tc entry */
3302 @@ -69,16 +69,16 @@ struct tc_edge_entry {
3303 uint32_t linkquality[0];
3306 -AVLNODE2STRUCT(edge_tree2tc_edge, struct tc_edge_entry, edge_node);
3307 +OLSRD_AVLNODE2STRUCT(edge_tree2tc_edge, struct tc_edge_entry, edge_node);
3310 - struct avl_node vertex_node; /* node keyed by ip address */
3311 + struct olsrd_avl_node vertex_node; /* node keyed by ip address */
3312 union olsr_ip_addr addr; /* vertex_node key */
3313 - struct avl_node cand_tree_node; /* SPF candidate heap, node keyed by path_etx */
3314 + struct olsrd_avl_node cand_tree_node; /* SPF candidate heap, node keyed by path_etx */
3315 olsr_linkcost path_cost; /* SPF calculated distance, cand_tree_node key */
3316 struct list_node path_list_node; /* SPF result list */
3317 - struct avl_tree edge_tree; /* subtree for edges */
3318 - struct avl_tree prefix_tree; /* subtree for prefixes */
3319 + struct olsrd_avl_tree edge_tree; /* subtree for edges */
3320 + struct olsrd_avl_tree prefix_tree; /* subtree for prefixes */
3321 struct link_entry *next_hop; /* SPF calculated link to the 1st hop neighbor */
3322 struct timer_entry *edge_gc_timer; /* used for edge garbage collection */
3323 struct timer_entry *validity_timer; /* tc validity time */
3324 @@ -102,8 +102,8 @@ struct tc_entry {
3326 #define OLSR_TC_VTIME_JITTER 5 /* percent */
3328 -AVLNODE2STRUCT(vertex_tree2tc, struct tc_entry, vertex_node);
3329 -AVLNODE2STRUCT(cand_tree2tc, struct tc_entry, cand_tree_node);
3330 +OLSRD_AVLNODE2STRUCT(vertex_tree2tc, struct tc_entry, vertex_node);
3331 +OLSRD_AVLNODE2STRUCT(cand_tree2tc, struct tc_entry, cand_tree_node);
3332 LISTNODE2STRUCT(pathlist2tc, struct tc_entry, path_list_node);
3335 @@ -116,32 +116,32 @@ LISTNODE2STRUCT(pathlist2tc, struct tc_e
3337 #define OLSR_FOR_ALL_TC_ENTRIES(tc) \
3339 - struct avl_node *tc_tree_node, *next_tc_tree_node; \
3340 - for (tc_tree_node = avl_walk_first(&tc_tree); \
3341 + struct olsrd_avl_node *tc_tree_node, *next_tc_tree_node; \
3342 + for (tc_tree_node = olsrd_avl_walk_first(&tc_tree); \
3343 tc_tree_node; tc_tree_node = next_tc_tree_node) { \
3344 - next_tc_tree_node = avl_walk_next(tc_tree_node); \
3345 + next_tc_tree_node = olsrd_avl_walk_next(tc_tree_node); \
3346 tc = vertex_tree2tc(tc_tree_node);
3347 #define OLSR_FOR_ALL_TC_ENTRIES_END(tc) }}
3349 #define OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) \
3351 - struct avl_node *tc_edge_node, *next_tc_edge_node; \
3352 - for (tc_edge_node = avl_walk_first(&tc->edge_tree); \
3353 + struct olsrd_avl_node *tc_edge_node, *next_tc_edge_node; \
3354 + for (tc_edge_node = olsrd_avl_walk_first(&tc->edge_tree); \
3355 tc_edge_node; tc_edge_node = next_tc_edge_node) { \
3356 - next_tc_edge_node = avl_walk_next(tc_edge_node); \
3357 + next_tc_edge_node = olsrd_avl_walk_next(tc_edge_node); \
3358 tc_edge = edge_tree2tc_edge(tc_edge_node);
3359 #define OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge) }}
3361 #define OLSR_FOR_ALL_PREFIX_ENTRIES(tc, rtp) \
3363 - struct avl_node *rtp_node, *next_rtp_node; \
3364 - for (rtp_node = avl_walk_first(&tc->prefix_tree); \
3365 + struct olsrd_avl_node *rtp_node, *next_rtp_node; \
3366 + for (rtp_node = olsrd_avl_walk_first(&tc->prefix_tree); \
3367 rtp_node; rtp_node = next_rtp_node) { \
3368 - next_rtp_node = avl_walk_next(rtp_node); \
3369 + next_rtp_node = olsrd_avl_walk_next(rtp_node); \
3370 rtp = rtp_prefix_tree2rtp(rtp_node);
3371 #define OLSR_FOR_ALL_PREFIX_ENTRIES_END(tc, rtp) }}
3373 -extern struct avl_tree tc_tree;
3374 +extern struct olsrd_avl_tree tc_tree;
3375 extern struct tc_entry *tc_myself;
3377 void olsr_init_tc(void);