4b7986fe5b96bc42de08deac6f5c981a54e82c91
[openwrt/svn-archive/archive.git] / net / olsrd / patches / 140-olsrd_optimize.patch
1 diff -Nur olsrd-0.4.10.orig/src/duplicate_set.c olsrd-0.4.10/src/duplicate_set.c
2 --- olsrd-0.4.10.orig/src/duplicate_set.c 2005-02-27 19:39:43.000000000 +0100
3 +++ olsrd-0.4.10/src/duplicate_set.c 2006-02-22 12:24:03.000000000 +0100
4 @@ -93,7 +93,7 @@
5
6
7 /* Hash the senders address */
8 - hash = olsr_hashing(originator);
9 + hash = HASHMASK & seqno;
10
11 new_dup_entry = olsr_malloc(sizeof(struct dup_entry), "New dup entry");
12
13 @@ -131,7 +131,7 @@
14 struct dup_entry *tmp_dup_table;
15
16 /* Hash the senders address */
17 - hash = olsr_hashing(originator);
18 + hash = HASHMASK & seqno;
19
20 /* Check for entry */
21 for(tmp_dup_table = dup_set[hash].next;
22 @@ -163,7 +163,7 @@
23 struct dup_entry *tmp_dup_table;
24
25 /* Hash the senders address */
26 - hash = olsr_hashing(originator);
27 + hash = HASHMASK & seqno;
28
29 /* Check for entry */
30 for(tmp_dup_table = dup_set[hash].next;
31 @@ -268,7 +268,7 @@
32 struct dup_iface *new_iface;
33
34 /* Hash the senders address */
35 - hash = olsr_hashing(originator);
36 + hash = HASHMASK & seqno;
37
38
39 /* Check for entry */
40 @@ -313,7 +313,7 @@
41 struct dup_entry *tmp_dup_table;
42
43 /* Hash the senders address */
44 - hash = olsr_hashing(originator);
45 + hash = HASHMASK & seqno;
46
47 /* Check for entry */
48 for(tmp_dup_table = dup_set[hash].next;
49 diff -Nur olsrd-0.4.10.orig/src/hashing.c olsrd-0.4.10/src/hashing.c
50 --- olsrd-0.4.10.orig/src/hashing.c 2005-02-20 19:52:18.000000000 +0100
51 +++ olsrd-0.4.10/src/hashing.c 2006-02-22 12:23:24.000000000 +0100
52 @@ -58,7 +58,7 @@
53
54 if(olsr_cnf->ip_version == AF_INET)
55 /* IPv4 */
56 - hash = (ntohl(address->v4));
57 + hash = address->v4x[0] ^ address->v4x[1] ^ address->v4x[2] ^ address->v4x[3];
58 else
59 {
60 /* IPv6 */
61 diff -Nur olsrd-0.4.10.orig/src/hashing.h olsrd-0.4.10/src/hashing.h
62 --- olsrd-0.4.10.orig/src/hashing.h 2005-02-20 19:52:18.000000000 +0100
63 +++ olsrd-0.4.10/src/hashing.h 2006-02-22 12:23:14.000000000 +0100
64 @@ -43,7 +43,7 @@
65 #ifndef _OLSR_HASHING
66 #define _OLSR_HASHING
67
68 -#define HASHSIZE 32
69 +#define HASHSIZE 128
70 #define HASHMASK (HASHSIZE - 1)
71
72 #include "olsr_types.h"
73 diff -Nur olsrd-0.4.10.orig/src/lq_avl.c olsrd-0.4.10/src/lq_avl.c
74 --- olsrd-0.4.10.orig/src/lq_avl.c 2005-01-22 15:30:57.000000000 +0100
75 +++ olsrd-0.4.10/src/lq_avl.c 2006-02-22 12:22:12.000000000 +0100
76 @@ -40,6 +40,7 @@
77 */
78
79 #include <stddef.h>
80 +#include <time.h>
81
82 #include "lq_avl.h"
83
84 @@ -52,11 +55,29 @@
85 tree->comp = comp;
86 }
87
88 +static struct avl_node *avl_find_rec_ipv4(struct avl_node *node, void *key)
89 +{
90 + if (*(unsigned int *)key < *(unsigned int *)node->key) {
91 + if (node->left != NULL) {
92 + return avl_find_rec_ipv4(node->left, key);
93 + }
94 + }
95 + else if (*(unsigned int *)key > *(unsigned int *)node->key) {
96 + if (node->right != NULL) {
97 + return avl_find_rec_ipv4(node->right, key);
98 + }
99 + }
100 + return node;
101 +}
102 +
103 static struct avl_node *avl_find_rec(struct avl_node *node, void *key,
104 int (*comp)(void *, void *))
105 {
106 int diff;
107
108 + if (0 == comp) {
109 + return avl_find_rec_ipv4(node, key);
110 + }
111 diff = (*comp)(key, node->key);
112
113 if (diff < 0)
114 @@ -87,6 +112,11 @@
115
116 node = avl_find_rec(tree->root, key, tree->comp);
117
118 + if (0 == tree->comp) {
119 + if (0 != svenola_avl_comp_ipv4(node->key, key))
120 + return NULL;
121 + }
122 + else
123 if ((*tree->comp)(node->key, key) != 0)
124 return NULL;
125
126 @@ -228,6 +260,10 @@
127
128 node = avl_find_rec(tree->root, new->key, tree->comp);
129
130 + if (0 == tree->comp) {
131 + diff = svenola_avl_comp_ipv4(new->key, node->key);
132 + }
133 + else
134 diff = (*tree->comp)(new->key, node->key);
135
136 if (diff == 0)
137 diff -Nur olsrd-0.4.10.orig/src/lq_avl.h olsrd-0.4.10/src/lq_avl.h
138 --- olsrd-0.4.10.orig/src/lq_avl.h 2005-02-20 19:52:18.000000000 +0100
139 +++ olsrd-0.4.10/src/lq_avl.h 2006-02-22 12:22:12.000000000 +0100
140 @@ -62,4 +62,7 @@
141 struct avl_node *avl_find(struct avl_tree *, void *);
142 int avl_insert(struct avl_tree *, struct avl_node *);
143
144 +#define svenola_avl_comp_ipv4(ip1, ip2) \
145 + (*(unsigned int *)ip1 == *(unsigned int *)ip2 ? 0 : \
146 + *(unsigned int *)ip1 < *(unsigned int *)ip2 ? -1 : +1)
147 #endif
148 diff -Nur olsrd-0.4.10.orig/src/lq_list.c olsrd-0.4.10/src/lq_list.c
149 --- olsrd-0.4.10.orig/src/lq_list.c 2004-12-04 18:06:57.000000000 +0100
150 +++ olsrd-0.4.10/src/lq_list.c 2006-02-22 12:22:12.000000000 +0100
151 @@ -48,6 +48,7 @@
152 list->tail = NULL;
153 }
154
155 +#if 0
156 struct list_node *list_get_head(struct list *list)
157 {
158 return list->head;
159 @@ -67,6 +68,7 @@
160 {
161 return node->prev;
162 }
163 +#endif
164
165 void list_add_head(struct list *list, struct list_node *node)
166 {
167 diff -Nur olsrd-0.4.10.orig/src/lq_list.h olsrd-0.4.10/src/lq_list.h
168 --- olsrd-0.4.10.orig/src/lq_list.h 2005-02-20 19:52:18.000000000 +0100
169 +++ olsrd-0.4.10/src/lq_list.h 2006-02-22 12:22:12.000000000 +0100
170 @@ -58,11 +58,18 @@
171
172 void list_init(struct list *list);
173
174 +#if 1
175 +#define list_get_head(node) (node)->head
176 +#define list_get_tail(node) (node)->tail
177 +#define list_get_next(node) (node)->next
178 +#define list_get_prev(node) (node)->prev
179 +#else
180 struct list_node *list_get_head(struct list *list);
181 struct list_node *list_get_tail(struct list *list);
182
183 struct list_node *list_get_next(struct list_node *node);
184 struct list_node *list_get_prev(struct list_node *node);
185 +#endif
186
187 void list_add_head(struct list *list, struct list_node *node);
188 void list_add_tail(struct list *list, struct list_node *node);
189 diff -Nur olsrd-0.4.10.orig/src/lq_route.c olsrd-0.4.10/src/lq_route.c
190 --- olsrd-0.4.10.orig/src/lq_route.c 2005-11-29 19:37:58.000000000 +0100
191 +++ olsrd-0.4.10/src/lq_route.c 2006-02-22 12:22:12.000000000 +0100
192 @@ -205,6 +205,14 @@
193
194 // add the vertex to the list, if it's not us
195
196 + if (0 == comp) {
197 + if (svenola_avl_comp_ipv4(&main_addr, node->key) != 0)
198 + {
199 + vert->node.data = vert;
200 + list_add_tail(vertex_list, &vert->node);
201 + }
202 + }
203 + else
204 if ((*comp)(&main_addr, node->key) != 0)
205 {
206 vert->node.data = vert;
207 @@ -371,7 +381,11 @@
208 struct interface *inter;
209
210 if (ipsize == 4)
211 +#if 1
212 + avl_comp = 0;
213 +#else
214 avl_comp = avl_comp_ipv4;
215 +#endif
216
217 else
218 avl_comp = avl_comp_ipv6;
219 diff -Nur olsrd-0.4.10.orig/src/olsr_types.h olsrd-0.4.10/src/olsr_types.h
220 --- olsrd-0.4.10.orig/src/olsr_types.h 2005-05-15 14:57:24.000000000 +0200
221 +++ olsrd-0.4.10/src/olsr_types.h 2006-02-22 12:22:43.000000000 +0100
222 @@ -93,6 +93,7 @@
223 union olsr_ip_addr
224 {
225 olsr_u32_t v4;
226 + olsr_u8_t v4x[4];
227 struct in6_addr v6;
228 };
229