59eac7118da7a40f0f903dfd87b71325b44e2ce5
[openwrt/svn-archive/archive.git] / net / olsrd / patches / 150-olsrd_quagga_backport.patch
1 --- a/lib/quagga/Makefile
2 +++ b/lib/quagga/Makefile
3 @@ -40,21 +40,19 @@ OLSRD_PLUGIN = true
4 PLUGIN_NAME = olsrd_quagga
5 PLUGIN_VER = 0.2.2
6
7 -TOPDIR= ../..
8 +TOPDIR = ../..
9 include $(TOPDIR)/Makefile.inc
10
11 -#CPPFLAGS +=-DMY_DEBUG
12 CFLAGS += -g
13 CPPFLAGS +=-DUSE_UNIX_DOMAIN_SOCKET
14
15 -#uncomment the following line only if you are sure what you're doing, it will
16 -#probably break things!
17 -# CPPFLAGS +=-DZEBRA_HEADER_MARKER=255
18 -
19 ifeq ($(OS),win32)
20 +
21 default_target install clean:
22 - @echo "**** Quagga not supportet on Windows (so it would be pointless to build the Quagga Plugin)"
23 + @echo "*** Quagga not supported on Windows (so it would be pointless to build the Quagga plugin)"
24 +
25 else
26 +
27 default_target: $(PLUGIN_FULLNAME)
28
29 $(PLUGIN_FULLNAME): $(OBJS) version-script.txt
30 @@ -66,4 +64,5 @@ install: $(PLUGIN_FULLNAME)
31
32 clean:
33 rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
34 +
35 endif
36 --- /dev/null
37 +++ b/lib/quagga/patches/quagga-0.98.6.diff
38 @@ -0,0 +1,860 @@
39 +diff -Nur quagga-0.98.6/bgpd/bgp_vty.c quagga-0.98.6.patched/bgpd/bgp_vty.c
40 +--- quagga-0.98.6/bgpd/bgp_vty.c 2006-03-30 18:12:25.000000000 +0200
41 ++++ quagga-0.98.6.patched/bgpd/bgp_vty.c 2007-12-30 14:18:22.000000000 +0200
42 +@@ -3,6 +3,9 @@
43 +
44 + This file is part of GNU Zebra.
45 +
46 ++This file was modified from the original on 30/12/2007
47 ++by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
48 ++
49 + GNU Zebra is free software; you can redistribute it and/or modify it
50 + under the terms of the GNU General Public License as published by the
51 + Free Software Foundation; either version 2, or (at your option) any
52 +@@ -7793,8 +7796,12 @@
53 + return ZEBRA_ROUTE_STATIC;
54 + else if (strncmp (str, "r", 1) == 0)
55 + return ZEBRA_ROUTE_RIP;
56 +- else if (strncmp (str, "o", 1) == 0)
57 ++ else if (strncmp (str, "ol", 2) == 0)
58 ++ return ZEBRA_ROUTE_OLSR;
59 ++ else if (strncmp (str, "os", 2) == 0)
60 + return ZEBRA_ROUTE_OSPF;
61 ++ else if (strncmp (str, "ba", 2) == 0)
62 ++ return ZEBRA_ROUTE_BATMAN;
63 + }
64 + if (afi == AFI_IP6)
65 + {
66 +@@ -7806,21 +7813,28 @@
67 + return ZEBRA_ROUTE_STATIC;
68 + else if (strncmp (str, "r", 1) == 0)
69 + return ZEBRA_ROUTE_RIPNG;
70 +- else if (strncmp (str, "o", 1) == 0)
71 ++ else if (strncmp (str, "os", 2) == 0)
72 + return ZEBRA_ROUTE_OSPF6;
73 ++ else if (strncmp (str, "ol", 2) == 0)
74 ++ return ZEBRA_ROUTE_OLSR;
75 ++ else if (strncmp (str, "ba", 2) == 0)
76 ++ return ZEBRA_ROUTE_BATMAN;
77 + }
78 + return 0;
79 + }
80 +
81 + DEFUN (bgp_redistribute_ipv4,
82 + bgp_redistribute_ipv4_cmd,
83 +- "redistribute (connected|kernel|ospf|rip|static)",
84 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman)",
85 + "Redistribute information from another routing protocol\n"
86 + "Connected\n"
87 + "Kernel routes\n"
88 + "Open Shurtest Path First (OSPF)\n"
89 + "Routing Information Protocol (RIP)\n"
90 +- "Static routes\n")
91 ++ "Static routes\n"
92 ++ "Optimized Link State Routing (OLSR)\n"
93 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
94 ++ )
95 + {
96 + int type;
97 +
98 +@@ -7835,13 +7849,15 @@
99 +
100 + DEFUN (bgp_redistribute_ipv4_rmap,
101 + bgp_redistribute_ipv4_rmap_cmd,
102 +- "redistribute (connected|kernel|ospf|rip|static) route-map WORD",
103 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD",
104 + "Redistribute information from another routing protocol\n"
105 + "Connected\n"
106 + "Kernel routes\n"
107 + "Open Shurtest Path First (OSPF)\n"
108 + "Routing Information Protocol (RIP)\n"
109 + "Static routes\n"
110 ++ "Optimized Link State Routing (OLSR)\n"
111 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
112 + "Route map reference\n"
113 + "Pointer to route-map entries\n")
114 + {
115 +@@ -7860,13 +7876,15 @@
116 +
117 + DEFUN (bgp_redistribute_ipv4_metric,
118 + bgp_redistribute_ipv4_metric_cmd,
119 +- "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
120 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295>",
121 + "Redistribute information from another routing protocol\n"
122 + "Connected\n"
123 + "Kernel routes\n"
124 + "Open Shurtest Path First (OSPF)\n"
125 + "Routing Information Protocol (RIP)\n"
126 + "Static routes\n"
127 ++ "Optimized Link State Routing (OLSR)\n"
128 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
129 + "Metric for redistributed routes\n"
130 + "Default metric\n")
131 + {
132 +@@ -7887,13 +7905,15 @@
133 +
134 + DEFUN (bgp_redistribute_ipv4_rmap_metric,
135 + bgp_redistribute_ipv4_rmap_metric_cmd,
136 +- "redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
137 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD metric <0-4294967295>",
138 + "Redistribute information from another routing protocol\n"
139 + "Connected\n"
140 + "Kernel routes\n"
141 + "Open Shurtest Path First (OSPF)\n"
142 + "Routing Information Protocol (RIP)\n"
143 + "Static routes\n"
144 ++ "Optimized Link State Routing (OLSR)\n"
145 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
146 + "Route map reference\n"
147 + "Pointer to route-map entries\n"
148 + "Metric for redistributed routes\n"
149 +@@ -7917,13 +7937,15 @@
150 +
151 + DEFUN (bgp_redistribute_ipv4_metric_rmap,
152 + bgp_redistribute_ipv4_metric_rmap_cmd,
153 +- "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
154 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295> route-map WORD",
155 + "Redistribute information from another routing protocol\n"
156 + "Connected\n"
157 + "Kernel routes\n"
158 + "Open Shurtest Path First (OSPF)\n"
159 + "Routing Information Protocol (RIP)\n"
160 + "Static routes\n"
161 ++ "Optimized Link State Routing (OLSR)\n"
162 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
163 + "Metric for redistributed routes\n"
164 + "Default metric\n"
165 + "Route map reference\n"
166 +@@ -7947,14 +7969,17 @@
167 +
168 + DEFUN (no_bgp_redistribute_ipv4,
169 + no_bgp_redistribute_ipv4_cmd,
170 +- "no redistribute (connected|kernel|ospf|rip|static)",
171 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman)",
172 + NO_STR
173 + "Redistribute information from another routing protocol\n"
174 + "Connected\n"
175 + "Kernel routes\n"
176 + "Open Shurtest Path First (OSPF)\n"
177 + "Routing Information Protocol (RIP)\n"
178 +- "Static routes\n")
179 ++ "Static routes\n"
180 ++ "Optimized Link State Routing (OLSR)\n"
181 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
182 ++ )
183 + {
184 + int type;
185 +
186 +@@ -7970,7 +7995,7 @@
187 +
188 + DEFUN (no_bgp_redistribute_ipv4_rmap,
189 + no_bgp_redistribute_ipv4_rmap_cmd,
190 +- "no redistribute (connected|kernel|ospf|rip|static) route-map WORD",
191 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD",
192 + NO_STR
193 + "Redistribute information from another routing protocol\n"
194 + "Connected\n"
195 +@@ -7978,6 +8003,8 @@
196 + "Open Shurtest Path First (OSPF)\n"
197 + "Routing Information Protocol (RIP)\n"
198 + "Static routes\n"
199 ++ "Optimized Link State Routing (OLSR)\n"
200 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
201 + "Route map reference\n"
202 + "Pointer to route-map entries\n")
203 + {
204 +@@ -7996,7 +8023,7 @@
205 +
206 + DEFUN (no_bgp_redistribute_ipv4_metric,
207 + no_bgp_redistribute_ipv4_metric_cmd,
208 +- "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
209 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295>",
210 + NO_STR
211 + "Redistribute information from another routing protocol\n"
212 + "Connected\n"
213 +@@ -8004,6 +8031,8 @@
214 + "Open Shurtest Path First (OSPF)\n"
215 + "Routing Information Protocol (RIP)\n"
216 + "Static routes\n"
217 ++ "Optimized Link State Routing (OLSR)\n"
218 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
219 + "Metric for redistributed routes\n"
220 + "Default metric\n")
221 + {
222 +@@ -8022,7 +8051,7 @@
223 +
224 + DEFUN (no_bgp_redistribute_ipv4_rmap_metric,
225 + no_bgp_redistribute_ipv4_rmap_metric_cmd,
226 +- "no redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
227 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD metric <0-4294967295>",
228 + NO_STR
229 + "Redistribute information from another routing protocol\n"
230 + "Connected\n"
231 +@@ -8030,6 +8059,8 @@
232 + "Open Shurtest Path First (OSPF)\n"
233 + "Routing Information Protocol (RIP)\n"
234 + "Static routes\n"
235 ++ "Optimized Link State Routing (OLSR)\n"
236 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
237 + "Route map reference\n"
238 + "Pointer to route-map entries\n"
239 + "Metric for redistributed routes\n"
240 +@@ -8051,7 +8082,7 @@
241 +
242 + ALIAS (no_bgp_redistribute_ipv4_rmap_metric,
243 + no_bgp_redistribute_ipv4_metric_rmap_cmd,
244 +- "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
245 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295> route-map WORD",
246 + NO_STR
247 + "Redistribute information from another routing protocol\n"
248 + "Connected\n"
249 +@@ -8059,6 +8090,8 @@
250 + "Open Shurtest Path First (OSPF)\n"
251 + "Routing Information Protocol (RIP)\n"
252 + "Static routes\n"
253 ++ "Optimized Link State Routing (OLSR)\n"
254 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
255 + "Metric for redistributed routes\n"
256 + "Default metric\n"
257 + "Route map reference\n"
258 +@@ -8067,13 +8100,16 @@
259 + #ifdef HAVE_IPV6
260 + DEFUN (bgp_redistribute_ipv6,
261 + bgp_redistribute_ipv6_cmd,
262 +- "redistribute (connected|kernel|ospf6|ripng|static)",
263 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman)",
264 + "Redistribute information from another routing protocol\n"
265 + "Connected\n"
266 + "Kernel routes\n"
267 + "Open Shurtest Path First (OSPFv3)\n"
268 + "Routing Information Protocol (RIPng)\n"
269 +- "Static routes\n")
270 ++ "Static routes\n"
271 ++ "Optimized Link State Routing (OLSR)\n"
272 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
273 ++ )
274 + {
275 + int type;
276 +
277 +@@ -8089,13 +8125,15 @@
278 +
279 + DEFUN (bgp_redistribute_ipv6_rmap,
280 + bgp_redistribute_ipv6_rmap_cmd,
281 +- "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
282 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD",
283 + "Redistribute information from another routing protocol\n"
284 + "Connected\n"
285 + "Kernel routes\n"
286 + "Open Shurtest Path First (OSPFv3)\n"
287 + "Routing Information Protocol (RIPng)\n"
288 + "Static routes\n"
289 ++ "Optimized Link State Routing (OLSR)\n"
290 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
291 + "Route map reference\n"
292 + "Pointer to route-map entries\n")
293 + {
294 +@@ -8114,13 +8152,15 @@
295 +
296 + DEFUN (bgp_redistribute_ipv6_metric,
297 + bgp_redistribute_ipv6_metric_cmd,
298 +- "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
299 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295>",
300 + "Redistribute information from another routing protocol\n"
301 + "Connected\n"
302 + "Kernel routes\n"
303 + "Open Shurtest Path First (OSPFv3)\n"
304 + "Routing Information Protocol (RIPng)\n"
305 + "Static routes\n"
306 ++ "Optimized Link State Routing (OLSR)\n"
307 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
308 + "Metric for redistributed routes\n"
309 + "Default metric\n")
310 + {
311 +@@ -8141,13 +8181,15 @@
312 +
313 + DEFUN (bgp_redistribute_ipv6_rmap_metric,
314 + bgp_redistribute_ipv6_rmap_metric_cmd,
315 +- "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
316 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD metric <0-4294967295>",
317 + "Redistribute information from another routing protocol\n"
318 + "Connected\n"
319 + "Kernel routes\n"
320 + "Open Shurtest Path First (OSPFv3)\n"
321 + "Routing Information Protocol (RIPng)\n"
322 + "Static routes\n"
323 ++ "Optimized Link State Routing (OLSR)\n"
324 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
325 + "Route map reference\n"
326 + "Pointer to route-map entries\n"
327 + "Metric for redistributed routes\n"
328 +@@ -8171,13 +8213,15 @@
329 +
330 + DEFUN (bgp_redistribute_ipv6_metric_rmap,
331 + bgp_redistribute_ipv6_metric_rmap_cmd,
332 +- "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
333 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295> route-map WORD",
334 + "Redistribute information from another routing protocol\n"
335 + "Connected\n"
336 + "Kernel routes\n"
337 + "Open Shurtest Path First (OSPFv3)\n"
338 + "Routing Information Protocol (RIPng)\n"
339 + "Static routes\n"
340 ++ "Optimized Link State Routing (OLSR)\n"
341 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
342 + "Metric for redistributed routes\n"
343 + "Default metric\n"
344 + "Route map reference\n"
345 +@@ -8201,14 +8245,17 @@
346 +
347 + DEFUN (no_bgp_redistribute_ipv6,
348 + no_bgp_redistribute_ipv6_cmd,
349 +- "no redistribute (connected|kernel|ospf6|ripng|static)",
350 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman)",
351 + NO_STR
352 + "Redistribute information from another routing protocol\n"
353 + "Connected\n"
354 + "Kernel routes\n"
355 + "Open Shurtest Path First (OSPFv3)\n"
356 + "Routing Information Protocol (RIPng)\n"
357 +- "Static routes\n")
358 ++ "Static routes\n"
359 ++ "Optimized Link State Routing (OLSR)\n"
360 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
361 ++ )
362 + {
363 + int type;
364 +
365 +@@ -8224,7 +8271,7 @@
366 +
367 + DEFUN (no_bgp_redistribute_ipv6_rmap,
368 + no_bgp_redistribute_ipv6_rmap_cmd,
369 +- "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
370 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD",
371 + NO_STR
372 + "Redistribute information from another routing protocol\n"
373 + "Connected\n"
374 +@@ -8232,6 +8279,8 @@
375 + "Open Shurtest Path First (OSPFv3)\n"
376 + "Routing Information Protocol (RIPng)\n"
377 + "Static routes\n"
378 ++ "Optimized Link State Routing (OLSR)\n"
379 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
380 + "Route map reference\n"
381 + "Pointer to route-map entries\n")
382 + {
383 +@@ -8250,7 +8299,7 @@
384 +
385 + DEFUN (no_bgp_redistribute_ipv6_metric,
386 + no_bgp_redistribute_ipv6_metric_cmd,
387 +- "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
388 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295>",
389 + NO_STR
390 + "Redistribute information from another routing protocol\n"
391 + "Connected\n"
392 +@@ -8258,6 +8307,8 @@
393 + "Open Shurtest Path First (OSPFv3)\n"
394 + "Routing Information Protocol (RIPng)\n"
395 + "Static routes\n"
396 ++ "Optimized Link State Routing (OLSR)\n"
397 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
398 + "Metric for redistributed routes\n"
399 + "Default metric\n")
400 + {
401 +@@ -8276,7 +8327,7 @@
402 +
403 + DEFUN (no_bgp_redistribute_ipv6_rmap_metric,
404 + no_bgp_redistribute_ipv6_rmap_metric_cmd,
405 +- "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
406 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD metric <0-4294967295>",
407 + NO_STR
408 + "Redistribute information from another routing protocol\n"
409 + "Connected\n"
410 +@@ -8284,6 +8335,8 @@
411 + "Open Shurtest Path First (OSPFv3)\n"
412 + "Routing Information Protocol (RIPng)\n"
413 + "Static routes\n"
414 ++ "Optimized Link State Routing (OLSR)\n"
415 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
416 + "Route map reference\n"
417 + "Pointer to route-map entries\n"
418 + "Metric for redistributed routes\n"
419 +@@ -8305,7 +8358,7 @@
420 +
421 + ALIAS (no_bgp_redistribute_ipv6_rmap_metric,
422 + no_bgp_redistribute_ipv6_metric_rmap_cmd,
423 +- "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
424 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295> route-map WORD",
425 + NO_STR
426 + "Redistribute information from another routing protocol\n"
427 + "Connected\n"
428 +@@ -8313,6 +8366,8 @@
429 + "Open Shurtest Path First (OSPFv3)\n"
430 + "Routing Information Protocol (RIPng)\n"
431 + "Static routes\n"
432 ++ "Optimized Link State Routing (OLSR)\n"
433 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
434 + "Metric for redistributed routes\n"
435 + "Default metric\n"
436 + "Route map reference\n"
437 +@@ -8325,7 +8380,7 @@
438 + {
439 + int i;
440 + const char *str[] = { "system", "kernel", "connected", "static", "rip",
441 +- "ripng", "ospf", "ospf6", "isis", "bgp"};
442 ++ "ripng", "ospf", "ospf6", "isis", "bgp", "hsls", "olsr", "batman"};
443 +
444 + /* Unicast redistribution only. */
445 + if (safi != SAFI_UNICAST)
446 +diff -Nur quagga-0.98.6/lib/zebra.h quagga-0.98.6.patched/lib/zebra.h
447 +--- quagga-0.98.6/lib/zebra.h 2005-06-15 14:54:18.000000000 +0300
448 ++++ quagga-0.98.6.patched/lib/zebra.h 2007-12-30 14:18:22.000000000 +0200
449 +@@ -3,6 +3,9 @@
450 +
451 + This file is part of GNU Zebra.
452 +
453 ++This file was modified from the original on 30/12/2007
454 ++by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
455 ++
456 + GNU Zebra is free software; you can redistribute it and/or modify it
457 + under the terms of the GNU General Public License as published by the
458 + Free Software Foundation; either version 2, or (at your option) any
459 +@@ -378,7 +381,9 @@
460 + #define ZEBRA_ROUTE_ISIS 8
461 + #define ZEBRA_ROUTE_BGP 9
462 + #define ZEBRA_ROUTE_HSLS 10
463 +-#define ZEBRA_ROUTE_MAX 11
464 ++#define ZEBRA_ROUTE_OLSR 11
465 ++#define ZEBRA_ROUTE_BATMAN 12
466 ++#define ZEBRA_ROUTE_MAX 13
467 +
468 + /* Zebra's family types. */
469 + #define ZEBRA_FAMILY_IPV4 1
470 +diff -Nur quagga-0.98.6/ospfd/ospf_vty.c quagga-0.98.6.patched/ospfd/ospf_vty.c
471 +--- quagga-0.98.6/ospfd/ospf_vty.c 2006-03-30 17:41:20.000000000 +0200
472 ++++ quagga-0.98.6.patched/ospfd/ospf_vty.c 2007-12-30 14:18:22.000000000 +0200
473 +@@ -3,6 +3,9 @@
474 + *
475 + * This file is part of GNU Zebra.
476 + *
477 ++ * This file was modified from the original on 30/12/2007
478 ++ * by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
479 ++ *
480 + * GNU Zebra is free software; you can redistribute it and/or modify it
481 + * under the terms of the GNU General Public License as published by the
482 + * Free Software Foundation; either version 2, or (at your option) any
483 +@@ -106,11 +109,15 @@
484 + *source = ZEBRA_ROUTE_STATIC;
485 + else if (strncmp (str, "r", 1) == 0)
486 + *source = ZEBRA_ROUTE_RIP;
487 +- else if (strncmp (str, "b", 1) == 0)
488 ++ else if (strncmp (str, "bg", 2) == 0)
489 + *source = ZEBRA_ROUTE_BGP;
490 ++ else if (strncmp (str, "ol", 2) == 0)
491 ++ *source = ZEBRA_ROUTE_OLSR;
492 ++ else if (strncmp (str, "ba", 2) == 0)
493 ++ *source = ZEBRA_ROUTE_BATMAN;
494 + else
495 + return 0;
496 +-
497 ++
498 + return 1;
499 + }
500 +
501 +@@ -5302,13 +5309,15 @@
502 + \f
503 + DEFUN (ospf_redistribute_source_metric_type,
504 + ospf_redistribute_source_metric_type_routemap_cmd,
505 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> metric-type (1|2) route-map WORD",
506 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> metric-type (1|2) route-map WORD",
507 + "Redistribute information from another routing protocol\n"
508 + "Kernel routes\n"
509 + "Connected\n"
510 + "Static routes\n"
511 + "Routing Information Protocol (RIP)\n"
512 + "Border Gateway Protocol (BGP)\n"
513 ++ "Optimized Link State Routing (OLSR)\n"
514 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
515 + "Metric for redistributed routes\n"
516 + "OSPF default metric\n"
517 + "OSPF exterior metric type for redistributed routes\n"
518 +@@ -5346,13 +5355,15 @@
519 +
520 + ALIAS (ospf_redistribute_source_metric_type,
521 + ospf_redistribute_source_metric_type_cmd,
522 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> metric-type (1|2)",
523 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> metric-type (1|2)",
524 + "Redistribute information from another routing protocol\n"
525 + "Kernel routes\n"
526 + "Connected\n"
527 + "Static routes\n"
528 + "Routing Information Protocol (RIP)\n"
529 + "Border Gateway Protocol (BGP)\n"
530 ++ "Optimized Link State Routing (OLSR)\n"
531 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
532 + "Metric for redistributed routes\n"
533 + "OSPF default metric\n"
534 + "OSPF exterior metric type for redistributed routes\n"
535 +@@ -5361,25 +5372,29 @@
536 +
537 + ALIAS (ospf_redistribute_source_metric_type,
538 + ospf_redistribute_source_metric_cmd,
539 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214>",
540 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214>",
541 + "Redistribute information from another routing protocol\n"
542 + "Kernel routes\n"
543 + "Connected\n"
544 + "Static routes\n"
545 + "Routing Information Protocol (RIP)\n"
546 + "Border Gateway Protocol (BGP)\n"
547 ++ "Optimized Link State Routing (OLSR)\n"
548 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
549 + "Metric for redistributed routes\n"
550 + "OSPF default metric\n")
551 +
552 + DEFUN (ospf_redistribute_source_type_metric,
553 + ospf_redistribute_source_type_metric_routemap_cmd,
554 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) metric <0-16777214> route-map WORD",
555 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) metric <0-16777214> route-map WORD",
556 + "Redistribute information from another routing protocol\n"
557 + "Kernel routes\n"
558 + "Connected\n"
559 + "Static routes\n"
560 + "Routing Information Protocol (RIP)\n"
561 + "Border Gateway Protocol (BGP)\n"
562 ++ "Optimized Link State Routing (OLSR)\n"
563 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
564 + "OSPF exterior metric type for redistributed routes\n"
565 + "Set OSPF External Type 1 metrics\n"
566 + "Set OSPF External Type 2 metrics\n"
567 +@@ -5417,13 +5432,15 @@
568 +
569 + ALIAS (ospf_redistribute_source_type_metric,
570 + ospf_redistribute_source_type_metric_cmd,
571 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) metric <0-16777214>",
572 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) metric <0-16777214>",
573 + "Redistribute information from another routing protocol\n"
574 + "Kernel routes\n"
575 + "Connected\n"
576 + "Static routes\n"
577 + "Routing Information Protocol (RIP)\n"
578 + "Border Gateway Protocol (BGP)\n"
579 ++ "Optimized Link State Routing (OLSR)\n"
580 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
581 + "OSPF exterior metric type for redistributed routes\n"
582 + "Set OSPF External Type 1 metrics\n"
583 + "Set OSPF External Type 2 metrics\n"
584 +@@ -5432,7 +5449,7 @@
585 +
586 + ALIAS (ospf_redistribute_source_type_metric,
587 + ospf_redistribute_source_type_cmd,
588 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2)",
589 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2)",
590 + "Redistribute information from another routing protocol\n"
591 + "Kernel routes\n"
592 + "Connected\n"
593 +@@ -5440,28 +5457,35 @@
594 + "Routing Information Protocol (RIP)\n"
595 + "Border Gateway Protocol (BGP)\n"
596 + "OSPF exterior metric type for redistributed routes\n"
597 ++ "Optimized Link State Routing (OLSR)\n"
598 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
599 + "Set OSPF External Type 1 metrics\n"
600 + "Set OSPF External Type 2 metrics\n")
601 +
602 + ALIAS (ospf_redistribute_source_type_metric,
603 + ospf_redistribute_source_cmd,
604 +- "redistribute (kernel|connected|static|rip|bgp)",
605 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman)",
606 + "Redistribute information from another routing protocol\n"
607 + "Kernel routes\n"
608 + "Connected\n"
609 + "Static routes\n"
610 + "Routing Information Protocol (RIP)\n"
611 +- "Border Gateway Protocol (BGP)\n")
612 ++ "Border Gateway Protocol (BGP)\n"
613 ++ "Optimized Link State Routing (OLSR)\n"
614 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
615 ++ )
616 +
617 + DEFUN (ospf_redistribute_source_metric_routemap,
618 + ospf_redistribute_source_metric_routemap_cmd,
619 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> route-map WORD",
620 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> route-map WORD",
621 + "Redistribute information from another routing protocol\n"
622 + "Kernel routes\n"
623 + "Connected\n"
624 + "Static routes\n"
625 + "Routing Information Protocol (RIP)\n"
626 + "Border Gateway Protocol (BGP)\n"
627 ++ "Optimized Link State Routing (OLSR)\n"
628 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
629 + "Metric for redistributed routes\n"
630 + "OSPF default metric\n"
631 + "Route map reference\n"
632 +@@ -5490,13 +5514,15 @@
633 +
634 + DEFUN (ospf_redistribute_source_type_routemap,
635 + ospf_redistribute_source_type_routemap_cmd,
636 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) route-map WORD",
637 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) route-map WORD",
638 + "Redistribute information from another routing protocol\n"
639 + "Kernel routes\n"
640 + "Connected\n"
641 + "Static routes\n"
642 + "Routing Information Protocol (RIP)\n"
643 + "Border Gateway Protocol (BGP)\n"
644 ++ "Optimized Link State Routing (OLSR)\n"
645 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
646 + "OSPF exterior metric type for redistributed routes\n"
647 + "Set OSPF External Type 1 metrics\n"
648 + "Set OSPF External Type 2 metrics\n"
649 +@@ -5526,13 +5552,15 @@
650 +
651 + DEFUN (ospf_redistribute_source_routemap,
652 + ospf_redistribute_source_routemap_cmd,
653 +- "redistribute (kernel|connected|static|rip|bgp) route-map WORD",
654 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) route-map WORD",
655 + "Redistribute information from another routing protocol\n"
656 + "Kernel routes\n"
657 + "Connected\n"
658 + "Static routes\n"
659 + "Routing Information Protocol (RIP)\n"
660 + "Border Gateway Protocol (BGP)\n"
661 ++ "Optimized Link State Routing (OLSR)\n"
662 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
663 + "Route map reference\n"
664 + "Pointer to route-map entries\n")
665 + {
666 +@@ -5553,14 +5581,17 @@
667 +
668 + DEFUN (no_ospf_redistribute_source,
669 + no_ospf_redistribute_source_cmd,
670 +- "no redistribute (kernel|connected|static|rip|bgp)",
671 ++ "no redistribute (kernel|connected|static|rip|bgp|olsr|batman)",
672 + NO_STR
673 + "Redistribute information from another routing protocol\n"
674 + "Kernel routes\n"
675 + "Connected\n"
676 + "Static routes\n"
677 + "Routing Information Protocol (RIP)\n"
678 +- "Border Gateway Protocol (BGP)\n")
679 ++ "Border Gateway Protocol (BGP)\n"
680 ++ "Optimized Link State Routing (OLSR)\n"
681 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
682 ++ )
683 + {
684 + struct ospf *ospf = vty->index;
685 + int source;
686 +@@ -5574,7 +5605,7 @@
687 +
688 + DEFUN (ospf_distribute_list_out,
689 + ospf_distribute_list_out_cmd,
690 +- "distribute-list WORD out (kernel|connected|static|rip|bgp)",
691 ++ "distribute-list WORD out (kernel|connected|static|rip|bgp|olsr|batman)",
692 + "Filter networks in routing updates\n"
693 + "Access-list name\n"
694 + OUT_STR
695 +@@ -5582,7 +5613,10 @@
696 + "Connected\n"
697 + "Static routes\n"
698 + "Routing Information Protocol (RIP)\n"
699 +- "Border Gateway Protocol (BGP)\n")
700 ++ "Border Gateway Protocol (BGP)\n"
701 ++ "Optimized Link State Routing (OLSR)\n"
702 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
703 ++)
704 + {
705 + struct ospf *ospf = vty->index;
706 + int source;
707 +@@ -5596,7 +5630,7 @@
708 +
709 + DEFUN (no_ospf_distribute_list_out,
710 + no_ospf_distribute_list_out_cmd,
711 +- "no distribute-list WORD out (kernel|connected|static|rip|bgp)",
712 ++ "no distribute-list WORD out (kernel|connected|static|rip|bgp|olsr|batman)",
713 + NO_STR
714 + "Filter networks in routing updates\n"
715 + "Access-list name\n"
716 +@@ -5605,7 +5639,10 @@
717 + "Connected\n"
718 + "Static routes\n"
719 + "Routing Information Protocol (RIP)\n"
720 +- "Border Gateway Protocol (BGP)\n")
721 ++ "Border Gateway Protocol (BGP)\n"
722 ++ "Optimized Link State Routing (OLSR)\n"
723 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
724 ++)
725 + {
726 + struct ospf *ospf = vty->index;
727 + int source;
728 +@@ -7121,7 +7158,8 @@
729 +
730 + \f
731 + const char *distribute_str[] = { "system", "kernel", "connected", "static",
732 +- "rip", "ripng", "ospf", "ospf6", "isis", "bgp"};
733 ++ "rip", "ripng", "ospf", "ospf6", "isis", "bgp",
734 ++ "hsls","olsr","batman"};
735 + int
736 + config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf)
737 + {
738 +diff -Nur quagga-0.98.6/zebra/redistribute.c quagga-0.98.6.patched/zebra/redistribute.c
739 +--- quagga-0.98.6/zebra/redistribute.c 2005-06-15 14:54:51.000000000 +0300
740 ++++ quagga-0.98.6.patched/zebra/redistribute.c 2007-12-30 14:18:22.000000000 +0200
741 +@@ -3,6 +3,9 @@
742 + *
743 + * This file is part of GNU Zebra.
744 + *
745 ++ * This file was modified from the original on 30/12/2007
746 ++ * by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
747 ++ *
748 + * GNU Zebra is free software; you can redistribute it and/or modify it
749 + * under the terms of the GNU General Public License as published by the
750 + * Free Software Foundation; either version 2, or (at your option) any
751 +@@ -253,6 +256,8 @@
752 + case ZEBRA_ROUTE_OSPF:
753 + case ZEBRA_ROUTE_OSPF6:
754 + case ZEBRA_ROUTE_BGP:
755 ++ case ZEBRA_ROUTE_OLSR:
756 ++ case ZEBRA_ROUTE_BATMAN:
757 + if (! client->redist[type])
758 + {
759 + client->redist[type] = 1;
760 +@@ -281,6 +286,8 @@
761 + case ZEBRA_ROUTE_OSPF:
762 + case ZEBRA_ROUTE_OSPF6:
763 + case ZEBRA_ROUTE_BGP:
764 ++ case ZEBRA_ROUTE_OLSR:
765 ++ case ZEBRA_ROUTE_BATMAN:
766 + client->redist[type] = 0;
767 + break;
768 + default:
769 +diff -Nur quagga-0.98.6/zebra/zebra_vty.c quagga-0.98.6.patched/zebra/zebra_vty.c
770 +--- quagga-0.98.6/zebra/zebra_vty.c 2004-12-18 18:03:29.000000000 +0200
771 ++++ quagga-0.98.6.patched/zebra/zebra_vty.c 2007-12-30 14:25:48.000000000 +0200
772 +@@ -53,6 +53,10 @@
773 + return "isis";
774 + case ZEBRA_ROUTE_BGP:
775 + return "bgp";
776 ++ case ZEBRA_ROUTE_OLSR:
777 ++ return "olsr";
778 ++ case ZEBRA_ROUTE_BATMAN:
779 ++ return "batman";
780 + default:
781 + return "unknown";
782 + }
783 +@@ -84,6 +88,12 @@
784 + return 'I';
785 + case ZEBRA_ROUTE_BGP:
786 + return 'B';
787 ++ case ZEBRA_ROUTE_HSLS:
788 ++ return 'H';
789 ++ case ZEBRA_ROUTE_OLSR:
790 ++ return 'L';
791 ++ case ZEBRA_ROUTE_BATMAN:
792 ++ return 'M';
793 + default:
794 + return '?';
795 + }
796 +@@ -755,8 +765,8 @@
797 + }
798 +
799 + #define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, " \
800 +- "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, " \
801 +- "> - selected route, * - FIB route%s%s"
802 ++ "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, H - HSLS, " \
803 ++ "L - OLSR, M - BATMAN, > - selected route, * - FIB route%s%s"
804 +
805 + DEFUN (show_ip_route,
806 + show_ip_route_cmd,
807 +@@ -874,7 +884,7 @@
808 +
809 + DEFUN (show_ip_route_protocol,
810 + show_ip_route_protocol_cmd,
811 +- "show ip route (bgp|connected|isis|kernel|ospf|rip|static)",
812 ++ "show ip route (bgp|connected|isis|kernel|ospf|rip|olsr|batman|static)",
813 + SHOW_STR
814 + IP_STR
815 + "IP routing table\n"
816 +@@ -884,6 +894,8 @@
817 + "Kernel\n"
818 + "Open Shortest Path First (OSPF)\n"
819 + "Routing Information Protocol (RIP)\n"
820 ++ "Optimized Link State Routing (OLSR)\n"
821 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
822 + "Static routes\n")
823 + {
824 + int type;
825 +@@ -892,13 +904,13 @@
826 + struct rib *rib;
827 + int first = 1;
828 +
829 +- if (strncmp (argv[0], "b", 1) == 0)
830 ++ if (strncmp (argv[0], "bg", 2) == 0)
831 + type = ZEBRA_ROUTE_BGP;
832 + else if (strncmp (argv[0], "c", 1) == 0)
833 + type = ZEBRA_ROUTE_CONNECT;
834 + else if (strncmp (argv[0], "k", 1) ==0)
835 + type = ZEBRA_ROUTE_KERNEL;
836 +- else if (strncmp (argv[0], "o", 1) == 0)
837 ++ else if (strncmp (argv[0], "os", 2) == 0)
838 + type = ZEBRA_ROUTE_OSPF;
839 + else if (strncmp (argv[0], "i", 1) == 0)
840 + type = ZEBRA_ROUTE_ISIS;
841 +@@ -906,6 +918,10 @@
842 + type = ZEBRA_ROUTE_RIP;
843 + else if (strncmp (argv[0], "s", 1) == 0)
844 + type = ZEBRA_ROUTE_STATIC;
845 ++ else if (strncmp (argv[0], "ol", 2) == 0)
846 ++ type = ZEBRA_ROUTE_OLSR;
847 ++ else if (strncmp (argv[0], "ba", 2) == 0)
848 ++ type = ZEBRA_ROUTE_BATMAN;
849 + else
850 + {
851 + vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
852 +@@ -1732,7 +1748,7 @@
853 +
854 + DEFUN (show_ipv6_route_protocol,
855 + show_ipv6_route_protocol_cmd,
856 +- "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|static)",
857 ++ "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|olsr|batman|static)",
858 + SHOW_STR
859 + IP_STR
860 + "IP routing table\n"
861 +@@ -1742,6 +1758,8 @@
862 + "Kernel\n"
863 + "Open Shortest Path First (OSPFv3)\n"
864 + "Routing Information Protocol (RIPng)\n"
865 ++ "Optimized Link State Routing (OLSR)\n"
866 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
867 + "Static routes\n")
868 + {
869 + int type;
870 +@@ -1750,13 +1768,13 @@
871 + struct rib *rib;
872 + int first = 1;
873 +
874 +- if (strncmp (argv[0], "b", 1) == 0)
875 ++ if (strncmp (argv[0], "bg", 2) == 0)
876 + type = ZEBRA_ROUTE_BGP;
877 + else if (strncmp (argv[0], "c", 1) == 0)
878 + type = ZEBRA_ROUTE_CONNECT;
879 + else if (strncmp (argv[0], "k", 1) ==0)
880 + type = ZEBRA_ROUTE_KERNEL;
881 +- else if (strncmp (argv[0], "o", 1) == 0)
882 ++ else if (strncmp (argv[0], "os", 2) == 0)
883 + type = ZEBRA_ROUTE_OSPF6;
884 + else if (strncmp (argv[0], "i", 1) == 0)
885 + type = ZEBRA_ROUTE_ISIS;
886 +@@ -1764,7 +1782,11 @@
887 + type = ZEBRA_ROUTE_RIPNG;
888 + else if (strncmp (argv[0], "s", 1) == 0)
889 + type = ZEBRA_ROUTE_STATIC;
890 +- else
891 ++ else if (strncmp (argv[0], "ol", 2) == 0)
892 ++ type = ZEBRA_ROUTE_OLSR;
893 ++ else if (strncmp (argv[0], "ba", 2) == 0)
894 ++ type = ZEBRA_ROUTE_BATMAN;
895 ++ else
896 + {
897 + vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
898 + return CMD_WARNING;
899 --- a/lib/quagga/README_QUAGGA
900 +++ b/lib/quagga/README_QUAGGA
901 @@ -1,20 +1,20 @@
902 ---------------------------------------------------------------------
903 QUAGGA PLUGIN FOR OLSRD
904 by Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
905 +
906 +addittions by: Sven-Ola Tuecke <sven-ola-aet-gmx.de>
907 + Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
908 ---------------------------------------------------------------------
909
910 -This is the Quagga Plugin for the OLSRD.
911 -It allowes olsrd to redistribute from various quagga-protocols
912 +This is the Quagga Plugin for OLSRd.
913 +It allows olsrd to redistribute from various quagga-protocols
914 as well as to export olsr-routes to quagga so that they can be
915 redistributed by the quagga-routing-daemons.
916
917 -Note Sven-Ola: You also need a source distribution of quagga-0.98.5
918 -or quagga-0.98.6 (that is the current stable). The quagga source tree
919 -needs to be patched with quagga-0.98.6-olsr.diff, compiled and installed
920 -via 'make install'. Because many people will otherwise have compile
921 -probs, I've added 2 include files in lib/quagga/src/quagga. If you
922 -want to use another version of quagga, make sure to remove these
923 -before you compile the olsrd_quagga plugin.
924 +You also need a source distribution of quagga-0.98.5 or quagga-0.98.6
925 +(that is the current stable). The quagga source tree needs to be
926 +patched with quagga-0.98.6.diff, compiled and installed via
927 +'make install'.
928
929 ---------------------------------------------------------------------
930 PLUGIN PARAMETERS (PlParam)
931 @@ -27,22 +27,22 @@ PlParam "redistribute" "<protocol>"
932 May be used more then once
933
934 PlParam "ExportRoutes" "<only/both>"
935 - exportes olsr-routes to quagga or to both, quagga and kernel
936 + exports olsr-routes to quagga or to both, quagga and kernel
937 no routes are exported to quagga (normal behaviour) if not set.
938
939 -PlParam "LocalPref" "true"
940 +PlParam "LocalPref" "<true/false>"
941 sets the Zebra SELECTED-flag on the routes exported to zebra
942 which means these routes are prefered in any case.
943
944 PlParam "Distance" "0-255"
945 - allowes to set the administrative distance to routes exported
946 - to Zebra.
947 + allows to set the administrative distance to routes exported
948 + to zebra.
949
950 ---------------------------------------------------------------------
951 SAMPLE CONFIG
952 ---------------------------------------------------------------------
953
954 -add in /etc/olsrd.conf:
955 +add in /usr/local/etc/olsrd.conf:
956
957 LoadPlugin "olsrd_quagga.so.0.2.2"
958 {
959 @@ -55,4 +55,4 @@ LoadPlugin "olsrd_quagga.so.0.2.2"
960
961
962 ---------------------------------------------------------------------
963 -EOF / 8.5.2006
964 +EOF / 29.12.2008
965 --- a/lib/quagga/src/olsrd_plugin.c
966 +++ b/lib/quagga/src/olsrd_plugin.c
967 @@ -1,19 +1,22 @@
968 +/*
969 + * OLSRd Quagga plugin
970 + *
971 + * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
972 + * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
973 + *
974 + * This program is free software; you can redistribute it and/or modify
975 + * it under the terms of the GNU General Public License version 2 as
976 + * published by the Free Software Foundation or - at your option - under
977 + * the terms of the GNU General Public Licence version 2 but can be
978 + * linked to any BSD-Licenced Software with public available sourcecode
979 + *
980 + */
981 +
982 +/* -------------------------------------------------------------------------
983 + * File : olsrd_plugin.c
984 + * Description : functions to setup plugin
985 + * ------------------------------------------------------------------------- */
986
987 -/***************************************************************************
988 - projekt : olsrd-quagga
989 - file : olsrd_plugin.c
990 - usage : olsrd-plugin-handler-stuff
991 - copyright : (C) 2006 by Immo 'FaUl' Wehrenberg
992 - e-mail : immo@chaostreff-dortmund.de
993 - ***************************************************************************/
994 -
995 -/***************************************************************************
996 - * *
997 - * This program is free software; you can redistribute it and/or modify *
998 - * it under the terms of the GNU General Public License version 2 as *
999 - * published by the Free Software Foundation. *
1000 - * *
1001 - ***************************************************************************/
1002
1003 #include <stdio.h>
1004 #include <string.h>
1005 @@ -24,7 +27,6 @@
1006 #include "scheduler.h"
1007 #include "defs.h"
1008 #include "quagga.h"
1009 -#include "kernel_routes.h"
1010 #include "net_olsr.h"
1011
1012 #define PLUGIN_NAME "OLSRD quagga plugin"
1013 @@ -41,120 +43,94 @@ static set_plugin_parameter set_exportro
1014 static set_plugin_parameter set_distance;
1015 static set_plugin_parameter set_localpref;
1016
1017 -static export_route_function orig_addroute_function;
1018 -static export_route_function orig_delroute_function;
1019
1020 -int
1021 -olsrd_plugin_interface_version(void)
1022 -{
1023 +int olsrd_plugin_interface_version (void) {
1024 return PLUGIN_INTERFACE_VERSION;
1025 }
1026
1027 static const struct olsrd_plugin_parameters plugin_parameters[] = {
1028 - {.name = "redistribute",.set_plugin_parameter = &set_redistribute,},
1029 - {.name = "ExportRoutes",.set_plugin_parameter = &set_exportroutes,},
1030 - {.name = "Distance",.set_plugin_parameter = &set_distance,},
1031 - {.name = "LocalPref",.set_plugin_parameter = &set_localpref,},
1032 + { .name = "redistribute", .set_plugin_parameter = &set_redistribute, },
1033 + { .name = "ExportRoutes", .set_plugin_parameter = &set_exportroutes, },
1034 + { .name = "Distance", .set_plugin_parameter = &set_distance, },
1035 + { .name = "LocalPref", .set_plugin_parameter = &set_localpref, },
1036 };
1037
1038 -void
1039 -olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
1040 -{
1041 +void olsrd_get_plugin_parameters (const struct olsrd_plugin_parameters **params,
1042 + int *size) {
1043 *params = plugin_parameters;
1044 - *size = sizeof plugin_parameters / sizeof *plugin_parameters;
1045 + *size = ARRAYSIZE(plugin_parameters);
1046 }
1047
1048 -static int
1049 -set_redistribute(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1050 -{
1051 - const char *zebra_route_types[] = { "system", "kernel", "connect",
1052 - "static", "rip", "ripng", "ospf",
1053 - "ospf6", "isis", "bgp", "hsls"
1054 - };
1055 +static int set_redistribute (const char *value,
1056 + void *data __attribute__((unused)),
1057 + set_plugin_parameter_addon addon __attribute__((unused))) {
1058 + const char *zebra_route_types[] = {"system","kernel","connect",
1059 + "static","rip","ripng","ospf",
1060 + "ospf6","isis","bgp","hsls"};
1061 unsigned int i;
1062
1063 for (i = 0; i < ARRAYSIZE(zebra_route_types); i++) {
1064 - if (!strcmp(value, zebra_route_types[i])) {
1065 - zebra_redistribute(i);
1066 - return 0;
1067 - }
1068 + if (!strcmp(value, zebra_route_types[i]))
1069 + if (zebra_redistribute (i)) return 1;
1070 }
1071 - return 1;
1072 +
1073 + return 0;
1074 }
1075
1076 -static int
1077 -set_exportroutes(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1078 -{
1079 +static int set_exportroutes (const char *value,
1080 + void *data __attribute__((unused)),
1081 + set_plugin_parameter_addon addon __attribute__((unused))) {
1082 if (!strcmp(value, "only")) {
1083 - orig_addroute_function = NULL;
1084 - orig_delroute_function = NULL;
1085 - olsr_addroute_function = zebra_add_olsr_v4_route;
1086 - olsr_delroute_function = zebra_del_olsr_v4_route;
1087 + olsr_addroute_function = zebra_add_route;
1088 + olsr_delroute_function = zebra_del_route;
1089 zebra_export_routes(1);
1090 - } else if (!strcmp(value, "additional")) {
1091 - orig_addroute_function = olsr_addroute_function;
1092 - orig_delroute_function = olsr_delroute_function;
1093 - olsr_addroute_function = zebra_add_olsr_v4_route;
1094 - olsr_delroute_function = zebra_del_olsr_v4_route;
1095 + }
1096 + else if (!strcmp(value, "additional")) {
1097 + olsr_addroute_function = zebra_add_route;
1098 + olsr_delroute_function = zebra_del_route;
1099 zebra_export_routes(1);
1100 - } else
1101 - zebra_export_routes(0);
1102 + }
1103 + else zebra_export_routes(0);
1104 return 0;
1105 }
1106
1107 -static int
1108 -set_distance(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1109 -{
1110 +static int set_distance(const char *value, void *data __attribute__((unused)),
1111 + set_plugin_parameter_addon addon __attribute__((unused))) {
1112 int distance;
1113
1114 - if (set_plugin_int(value, &distance, addon))
1115 - return 1;
1116 - if (distance < 0 || distance > 255)
1117 - return 1;
1118 + if (set_plugin_int(value, &distance, addon)) return 1;
1119 + if (distance < 0 || distance > 255) return 1;
1120 zebra_olsr_distance(distance);
1121 return 0;
1122 }
1123
1124 -static int
1125 -set_localpref(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1126 -{
1127 +static int set_localpref(const char *value, void *data __attribute__((unused)),
1128 + set_plugin_parameter_addon addon __attribute__((unused))) {
1129 int b;
1130
1131 - if (set_plugin_boolean(value, &b, addon))
1132 - return 1;
1133 - if (b)
1134 - zebra_olsr_localpref();
1135 + if (set_plugin_boolean(value, &b, addon)) return 1;
1136 + if (b) zebra_olsr_localpref();
1137 return 0;
1138 }
1139
1140 -int
1141 -olsrd_plugin_init(void)
1142 -{
1143 - if (olsr_cnf->ip_version != AF_INET) {
1144 - fputs("see the source - ipv6 so far not supported\n", stderr);
1145 +
1146 +int olsrd_plugin_init(void) {
1147 + if(olsr_cnf->ip_version != AF_INET) {
1148 + fputs("see the source - ipv6 so far not supported\n" ,stderr);
1149 return 1;
1150 }
1151
1152 - olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &zebra_check, NULL, 0);
1153 + olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC,
1154 + &zebra_parse, NULL, 0);
1155
1156 return 0;
1157 }
1158
1159 -static void
1160 -my_init(void)
1161 -{
1162 +static void my_init(void) {
1163 init_zebra();
1164 }
1165
1166 -static void
1167 -my_fini(void)
1168 -{
1169 +static void my_fini(void) {
1170 zebra_cleanup();
1171 }
1172
1173 -/*
1174 - * Local Variables:
1175 - * c-basic-offset: 2
1176 - * indent-tabs-mode: nil
1177 - * End:
1178 - */
1179 --- a/lib/quagga/src/quagga/zassert.h
1180 +++ /dev/null
1181 @@ -1,33 +0,0 @@
1182 -
1183 -/*
1184 - */
1185 -
1186 -#ifndef _QUAGGA_ASSERT_H
1187 -#define _QUAGGA_ASSERT_H
1188 -
1189 -extern void _zlog_assert_failed(const char *assertion, const char *file, unsigned int line, const char *function)
1190 - __attribute__ ((noreturn));
1191 -
1192 -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
1193 -#define __ASSERT_FUNCTION __func__
1194 -#elif defined(__GNUC__)
1195 -#define __ASSERT_FUNCTION __FUNCTION__
1196 -#else
1197 -#define __ASSERT_FUNCTION NULL
1198 -#endif
1199 -
1200 -#define zassert(EX) ((void)((EX) ? 0 : \
1201 - (_zlog_assert_failed(#EX, __FILE__, __LINE__, \
1202 - __ASSERT_FUNCTION), 0)))
1203 -
1204 -#undef assert
1205 -#define assert(EX) zassert(EX)
1206 -
1207 -#endif /* _QUAGGA_ASSERT_H */
1208 -
1209 -/*
1210 - * Local Variables:
1211 - * c-basic-offset: 2
1212 - * indent-tabs-mode: nil
1213 - * End:
1214 - */
1215 --- a/lib/quagga/src/quagga/zebra.h
1216 +++ /dev/null
1217 @@ -1,503 +0,0 @@
1218 -
1219 -/* Zebra common header.
1220 - Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
1221 -
1222 -This file is part of GNU Zebra.
1223 -
1224 -GNU Zebra is free software; you can redistribute it and/or modify it
1225 -under the terms of the GNU General Public License as published by the
1226 -Free Software Foundation; either version 2, or (at your option) any
1227 -later version.
1228 -
1229 -GNU Zebra is distributed in the hope that it will be useful, but
1230 -WITHOUT ANY WARRANTY; without even the implied warranty of
1231 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1232 -General Public License for more details.
1233 -
1234 -You should have received a copy of the GNU General Public License
1235 -along with GNU Zebra; see the file COPYING. If not, write to the Free
1236 -Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1237 -02111-1307, USA. */
1238 -
1239 -#ifndef _ZEBRA_H
1240 -#define _ZEBRA_H
1241 -
1242 -#ifdef HAVE_CONFIG_H
1243 -#include "config.h"
1244 -#endif /* HAVE_CONFIG_H */
1245 -
1246 -#ifdef SUNOS_5
1247 -#define _XPG4_2
1248 -#define __EXTENSIONS__
1249 -typedef unsigned int u_int32_t;
1250 -typedef unsigned short u_int16_t;
1251 -typedef unsigned char u_int8_t;
1252 -#endif /* SUNOS_5 */
1253 -
1254 -#ifndef HAVE_SOCKLEN_T
1255 -typedef int socklen_t;
1256 -#endif /* HAVE_SOCKLEN_T */
1257 -
1258 -#include <unistd.h>
1259 -#include <stdio.h>
1260 -#include <stdlib.h>
1261 -#include <ctype.h>
1262 -#include <errno.h>
1263 -#include <fcntl.h>
1264 -#include <signal.h>
1265 -#include <string.h>
1266 -#include <pwd.h>
1267 -#include <grp.h>
1268 -#ifdef HAVE_STROPTS_H
1269 -#include <stropts.h>
1270 -#endif /* HAVE_STROPTS_H */
1271 -#include <sys/fcntl.h>
1272 -#ifdef HAVE_SYS_SELECT_H
1273 -#include <sys/select.h>
1274 -#endif /* HAVE_SYS_SELECT_H */
1275 -#include <sys/stat.h>
1276 -#include <sys/time.h>
1277 -#include <sys/types.h>
1278 -#include <sys/param.h>
1279 -#ifdef HAVE_SYS_SYSCTL_H
1280 -#include <sys/sysctl.h>
1281 -#endif /* HAVE_SYS_SYSCTL_H */
1282 -#include <sys/ioctl.h>
1283 -#ifdef HAVE_SYS_CONF_H
1284 -#include <sys/conf.h>
1285 -#endif /* HAVE_SYS_CONF_H */
1286 -#ifdef HAVE_SYS_KSYM_H
1287 -#include <sys/ksym.h>
1288 -#endif /* HAVE_SYS_KSYM_H */
1289 -#include <syslog.h>
1290 -#include <time.h>
1291 -#include <sys/uio.h>
1292 -#include <sys/utsname.h>
1293 -#ifdef HAVE_RUSAGE
1294 -#include <sys/resource.h>
1295 -#endif /* HAVE_RUSAGE */
1296 -#ifdef HAVE_LIMITS_H
1297 -#include <limits.h>
1298 -#endif /* HAVE_LIMITS_H */
1299 -
1300 -/* machine dependent includes */
1301 -#ifdef SUNOS_5
1302 -#include <strings.h>
1303 -#endif /* SUNOS_5 */
1304 -
1305 -/* machine dependent includes */
1306 -#ifdef HAVE_LINUX_VERSION_H
1307 -#include <linux/version.h>
1308 -#endif /* HAVE_LINUX_VERSION_H */
1309 -
1310 -#ifdef HAVE_ASM_TYPES_H
1311 -#include <asm/types.h>
1312 -#endif /* HAVE_ASM_TYPES_H */
1313 -
1314 -/* misc include group */
1315 -#include <stdarg.h>
1316 -#if !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
1317 -
1318 -/* Not C99; do we need to define va_copy? */
1319 -#ifndef va_copy
1320 -#ifdef __va_copy
1321 -#define va_copy(DST,SRC) __va_copy(DST,SRC)
1322 -#else
1323 -
1324 -/* Now we are desperate; this should work on many typical platforms.
1325 - But this is slightly dangerous, because the standard does not require
1326 - va_copy to be a macro. */
1327 -#define va_copy(DST,SRC) memcpy(&(DST), &(SRC), sizeof(va_list))
1328 -#warning "Not C99 and no va_copy macro available, falling back to memcpy"
1329 -#endif /* __va_copy */
1330 -#endif /* !va_copy */
1331 -#endif /* !C99 */
1332 -
1333 -#ifdef HAVE_LCAPS
1334 -#include <sys/capability.h>
1335 -#include <sys/prctl.h>
1336 -#endif /* HAVE_LCAPS */
1337 -
1338 -/* network include group */
1339 -
1340 -#include <sys/socket.h>
1341 -
1342 -#ifdef HAVE_SYS_SOCKIO_H
1343 -#include <sys/sockio.h>
1344 -#endif /* HAVE_SYS_SOCKIO_H */
1345 -
1346 -#ifdef HAVE_NETINET_IN_H
1347 -#include <netinet/in.h>
1348 -#endif /* HAVE_NETINET_IN_H */
1349 -#include <netinet/in_systm.h>
1350 -#include <netinet/ip.h>
1351 -#include <netinet/tcp.h>
1352 -
1353 -#ifdef HAVE_NET_NETOPT_H
1354 -#include <net/netopt.h>
1355 -#endif /* HAVE_NET_NETOPT_H */
1356 -
1357 -#include <net/if.h>
1358 -
1359 -#ifdef HAVE_NET_IF_DL_H
1360 -#include <net/if_dl.h>
1361 -#endif /* HAVE_NET_IF_DL_H */
1362 -
1363 -#ifdef HAVE_NET_IF_VAR_H
1364 -#include <net/if_var.h>
1365 -#endif /* HAVE_NET_IF_VAR_H */
1366 -
1367 -#ifdef HAVE_NET_ROUTE_H
1368 -#include <net/route.h>
1369 -#endif /* HAVE_NET_ROUTE_H */
1370 -
1371 -#ifdef HAVE_NETLINK
1372 -#include <linux/netlink.h>
1373 -#include <linux/rtnetlink.h>
1374 -#else
1375 -#define RT_TABLE_MAIN 0
1376 -#endif /* HAVE_NETLINK */
1377 -
1378 -#ifdef HAVE_NETDB_H
1379 -#include <netdb.h>
1380 -#endif /* HAVE_NETDB_H */
1381 -
1382 -#include <arpa/inet.h>
1383 -#include <arpa/telnet.h>
1384 -
1385 -#ifdef HAVE_INET_ND_H
1386 -#include <inet/nd.h>
1387 -#endif /* HAVE_INET_ND_H */
1388 -
1389 -#ifdef HAVE_NETINET_IN_VAR_H
1390 -#include <netinet/in_var.h>
1391 -#endif /* HAVE_NETINET_IN_VAR_H */
1392 -
1393 -#ifdef HAVE_NETINET6_IN6_VAR_H
1394 -#include <netinet6/in6_var.h>
1395 -#endif /* HAVE_NETINET6_IN6_VAR_H */
1396 -
1397 -#ifdef HAVE_NETINET_IN6_VAR_H
1398 -#include <netinet/in6_var.h>
1399 -#endif /* HAVE_NETINET_IN6_VAR_H */
1400 -
1401 -#ifdef HAVE_NETINET6_IN_H
1402 -#include <netinet6/in.h>
1403 -#endif /* HAVE_NETINET6_IN_H */
1404 -
1405 -#ifdef HAVE_NETINET6_IP6_H
1406 -#include <netinet6/ip6.h>
1407 -#endif /* HAVE_NETINET6_IP6_H */
1408 -
1409 -#ifdef HAVE_NETINET_ICMP6_H
1410 -#include <netinet/icmp6.h>
1411 -#endif /* HAVE_NETINET_ICMP6_H */
1412 -
1413 -#ifdef HAVE_NETINET6_ND6_H
1414 -#include <netinet6/nd6.h>
1415 -#endif /* HAVE_NETINET6_ND6_H */
1416 -
1417 -/* Some systems do not define UINT32_MAX */
1418 -#ifndef UINT32_MAX
1419 -#define UINT32_MAX 0xFFFFFFFFU
1420 -#endif /* UINT32_MAX */
1421 -
1422 -#ifdef HAVE_LIBUTIL_H
1423 -#include <libutil.h>
1424 -#endif /* HAVE_LIBUTIL_H */
1425 -
1426 -#ifdef HAVE_GLIBC_BACKTRACE
1427 -#include <execinfo.h>
1428 -#endif /* HAVE_GLIBC_BACKTRACE */
1429 -
1430 -#ifdef BSDI_NRL
1431 -
1432 -#ifdef HAVE_NETINET6_IN6_H
1433 -#include <netinet6/in6.h>
1434 -#endif /* HAVE_NETINET6_IN6_H */
1435 -
1436 -#ifdef NRL
1437 -#include <netinet6/in6.h>
1438 -#endif /* NRL */
1439 -
1440 -#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
1441 -
1442 -#endif /* BSDI_NRL */
1443 -
1444 -/* Local includes: */
1445 -#if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
1446 -#define __attribute__(x)
1447 -#endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
1448 -
1449 -#include "zassert.h"
1450 -
1451 -#ifdef HAVE_BROKEN_CMSG_FIRSTHDR
1452 -
1453 -/* This bug is present in Solaris 8 and pre-patch Solaris 9 <sys/socket.h>;
1454 - please refer to http://bugzilla.quagga.net/show_bug.cgi?id=142 */
1455 -
1456 -/* Check that msg_controllen is large enough. */
1457 -#define ZCMSG_FIRSTHDR(mhdr) \
1458 - (((size_t)((mhdr)->msg_controllen) >= sizeof(struct cmsghdr)) ? \
1459 - CMSG_FIRSTHDR(mhdr) : (struct cmsghdr *)NULL)
1460 -
1461 -#warning "CMSG_FIRSTHDR is broken on this platform, using a workaround"
1462 -
1463 -#else /* HAVE_BROKEN_CMSG_FIRSTHDR */
1464 -#define ZCMSG_FIRSTHDR(M) CMSG_FIRSTHDR(M)
1465 -#endif /* HAVE_BROKEN_CMSG_FIRSTHDR */
1466 -
1467 -/*
1468 - * RFC 3542 defines several macros for using struct cmsghdr.
1469 - * Here, we define those that are not present
1470 - */
1471 -
1472 -/*
1473 - * Internal defines, for use only in this file.
1474 - * These are likely wrong on other than ILP32 machines, so warn.
1475 - */
1476 -#ifndef _CMSG_DATA_ALIGN
1477 -#define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
1478 -#endif /* _CMSG_DATA_ALIGN */
1479 -
1480 -#ifndef _CMSG_HDR_ALIGN
1481 -#define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
1482 -#endif /* _CMSG_HDR_ALIGN */
1483 -
1484 -/*
1485 - * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
1486 - * version.
1487 - */
1488 -#ifndef CMSG_SPACE
1489 -#define CMSG_SPACE(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + \
1490 - _CMSG_HDR_ALIGN(l))
1491 -#warning "assuming 4-byte alignment for CMSG_SPACE"
1492 -#endif /* CMSG_SPACE */
1493 -
1494 -#ifndef CMSG_LEN
1495 -#define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
1496 -#warning "assuming 4-byte alignment for CMSG_LEN"
1497 -#endif /* CMSG_LEN */
1498 -
1499 -/* The definition of struct in_pktinfo is missing in old version of
1500 - GLIBC 2.1 (Redhat 6.1). */
1501 -#if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO)
1502 -struct in_pktinfo {
1503 - int ipi_ifindex;
1504 - struct in_addr ipi_spec_dst;
1505 - struct in_addr ipi_addr;
1506 -};
1507 -#endif
1508 -
1509 -/*
1510 - * OSPF Fragmentation / fragmented writes
1511 - *
1512 - * ospfd can support writing fragmented packets, for cases where
1513 - * kernel will not fragment IP_HDRINCL and/or multicast destined
1514 - * packets (ie TTBOMK all kernels, BSD, SunOS, Linux). However,
1515 - * SunOS, probably BSD too, clobber the user supplied IP ID and IP
1516 - * flags fields, hence user-space fragmentation will not work.
1517 - * Only Linux is known to leave IP header unmolested.
1518 - * Further, fragmentation really should be done the kernel, which already
1519 - * supports it, and which avoids nasty IP ID state problems.
1520 - *
1521 - * Fragmentation of OSPF packets can be required on networks with router
1522 - * with many many interfaces active in one area, or on networks with links
1523 - * with low MTUs.
1524 - */
1525 -#ifdef GNU_LINUX
1526 -#define WANT_OSPF_WRITE_FRAGMENT
1527 -#endif
1528 -
1529 -/*
1530 - * IP_HDRINCL / struct ip byte order
1531 - *
1532 - * Linux: network byte order
1533 - * *BSD: network, except for length and offset. (cf Stevens)
1534 - * SunOS: nominally as per BSD. but bug: network order on LE.
1535 - * OpenBSD: network byte order, apart from older versions which are as per
1536 - * *BSD
1537 - */
1538 -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)\
1539 - || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
1540 - || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN))
1541 -#define HAVE_IP_HDRINCL_BSD_ORDER
1542 -#endif
1543 -
1544 -/* MAX / MIN are not commonly defined, but useful */
1545 -#ifndef MAX
1546 -#define MAX(a, b) ((a) > (b) ? (a) : (b))
1547 -#endif
1548 -#ifndef MIN
1549 -#define MIN(a, b) ((a) < (b) ? (a) : (b))
1550 -#endif
1551 -
1552 -/* For old definition. */
1553 -#ifndef IN6_ARE_ADDR_EQUAL
1554 -#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
1555 -#endif /* IN6_ARE_ADDR_EQUAL */
1556 -
1557 -/* Zebra message types. */
1558 -#define ZEBRA_INTERFACE_ADD 1
1559 -#define ZEBRA_INTERFACE_DELETE 2
1560 -#define ZEBRA_INTERFACE_ADDRESS_ADD 3
1561 -#define ZEBRA_INTERFACE_ADDRESS_DELETE 4
1562 -#define ZEBRA_INTERFACE_UP 5
1563 -#define ZEBRA_INTERFACE_DOWN 6
1564 -#define ZEBRA_IPV4_ROUTE_ADD 7
1565 -#define ZEBRA_IPV4_ROUTE_DELETE 8
1566 -#define ZEBRA_IPV6_ROUTE_ADD 9
1567 -#define ZEBRA_IPV6_ROUTE_DELETE 10
1568 -#define ZEBRA_REDISTRIBUTE_ADD 11
1569 -#define ZEBRA_REDISTRIBUTE_DELETE 12
1570 -#define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
1571 -#define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
1572 -#define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
1573 -#define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
1574 -#define ZEBRA_IPV4_IMPORT_LOOKUP 17
1575 -#define ZEBRA_IPV6_IMPORT_LOOKUP 18
1576 -#define ZEBRA_INTERFACE_RENAME 19
1577 -#define ZEBRA_ROUTER_ID_ADD 20
1578 -#define ZEBRA_ROUTER_ID_DELETE 21
1579 -#define ZEBRA_ROUTER_ID_UPDATE 22
1580 -#define ZEBRA_MESSAGE_MAX 23
1581 -
1582 -/* Zebra route's types. */
1583 -#define ZEBRA_ROUTE_SYSTEM 0
1584 -#define ZEBRA_ROUTE_KERNEL 1
1585 -#define ZEBRA_ROUTE_CONNECT 2
1586 -#define ZEBRA_ROUTE_STATIC 3
1587 -#define ZEBRA_ROUTE_RIP 4
1588 -#define ZEBRA_ROUTE_RIPNG 5
1589 -#define ZEBRA_ROUTE_OSPF 6
1590 -#define ZEBRA_ROUTE_OSPF6 7
1591 -#define ZEBRA_ROUTE_ISIS 8
1592 -#define ZEBRA_ROUTE_BGP 9
1593 -#define ZEBRA_ROUTE_HSLS 10
1594 -#define ZEBRA_ROUTE_OLSR 11
1595 -#define ZEBRA_ROUTE_MAX 12
1596 -
1597 -/* Zebra's family types. */
1598 -#define ZEBRA_FAMILY_IPV4 1
1599 -#define ZEBRA_FAMILY_IPV6 2
1600 -#define ZEBRA_FAMILY_MAX 3
1601 -
1602 -/* Error codes of zebra. */
1603 -#define ZEBRA_ERR_RTEXIST -1
1604 -#define ZEBRA_ERR_RTUNREACH -2
1605 -#define ZEBRA_ERR_EPERM -3
1606 -#define ZEBRA_ERR_RTNOEXIST -4
1607 -
1608 -/* Zebra message flags */
1609 -#define ZEBRA_FLAG_INTERNAL 0x01
1610 -#define ZEBRA_FLAG_SELFROUTE 0x02
1611 -#define ZEBRA_FLAG_BLACKHOLE 0x04
1612 -#define ZEBRA_FLAG_IBGP 0x08
1613 -#define ZEBRA_FLAG_SELECTED 0x10
1614 -#define ZEBRA_FLAG_CHANGED 0x20
1615 -#define ZEBRA_FLAG_STATIC 0x40
1616 -#define ZEBRA_FLAG_REJECT 0x80
1617 -
1618 -/* Zebra nexthop flags. */
1619 -#define ZEBRA_NEXTHOP_IFINDEX 1
1620 -#define ZEBRA_NEXTHOP_IFNAME 2
1621 -#define ZEBRA_NEXTHOP_IPV4 3
1622 -#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
1623 -#define ZEBRA_NEXTHOP_IPV4_IFNAME 5
1624 -#define ZEBRA_NEXTHOP_IPV6 6
1625 -#define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
1626 -#define ZEBRA_NEXTHOP_IPV6_IFNAME 8
1627 -#define ZEBRA_NEXTHOP_BLACKHOLE 9
1628 -
1629 -#ifndef INADDR_LOOPBACK
1630 -#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
1631 -#endif
1632 -
1633 -/* Address family numbers from RFC1700. */
1634 -#define AFI_IP 1
1635 -#define AFI_IP6 2
1636 -#define AFI_MAX 3
1637 -
1638 -/* Subsequent Address Family Identifier. */
1639 -#define SAFI_UNICAST 1
1640 -#define SAFI_MULTICAST 2
1641 -#define SAFI_UNICAST_MULTICAST 3
1642 -#define SAFI_MPLS_VPN 4
1643 -#define SAFI_MAX 5
1644 -
1645 -/* Filter direction. */
1646 -#define FILTER_IN 0
1647 -#define FILTER_OUT 1
1648 -#define FILTER_MAX 2
1649 -
1650 -/* Default Administrative Distance of each protocol. */
1651 -#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
1652 -#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
1653 -#define ZEBRA_STATIC_DISTANCE_DEFAULT 1
1654 -#define ZEBRA_RIP_DISTANCE_DEFAULT 120
1655 -#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
1656 -#define ZEBRA_OSPF_DISTANCE_DEFAULT 110
1657 -#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
1658 -#define ZEBRA_ISIS_DISTANCE_DEFAULT 115
1659 -#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
1660 -#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
1661 -
1662 -/* Flag manipulation macros. */
1663 -#define CHECK_FLAG(V,F) ((V) & (F))
1664 -#define SET_FLAG(V,F) (V) = (V) | (F)
1665 -#define UNSET_FLAG(V,F) (V) = (V) & ~(F)
1666 -
1667 -/* AFI and SAFI type. */
1668 -typedef u_int16_t afi_t;
1669 -typedef u_int8_t safi_t;
1670 -
1671 -/* Zebra types. */
1672 -typedef u_int16_t zebra_size_t;
1673 -typedef u_int8_t zebra_command_t;
1674 -
1675 -/* FIFO -- first in first out structure and macros. */
1676 -struct fifo {
1677 - struct fifo *next;
1678 - struct fifo *prev;
1679 -};
1680 -
1681 -#define FIFO_INIT(F) \
1682 - do { \
1683 - struct fifo *Xfifo = (struct fifo *)(F); \
1684 - Xfifo->next = Xfifo->prev = Xfifo; \
1685 - } while (0)
1686 -
1687 -#define FIFO_ADD(F,N) \
1688 - do { \
1689 - struct fifo *Xfifo = (struct fifo *)(F); \
1690 - struct fifo *Xnode = (struct fifo *)(N); \
1691 - Xnode->next = Xfifo; \
1692 - Xnode->prev = Xfifo->prev; \
1693 - Xfifo->prev = Xfifo->prev->next = Xnode; \
1694 - } while (0)
1695 -
1696 -#define FIFO_DEL(N) \
1697 - do { \
1698 - struct fifo *Xnode = (struct fifo *)(N); \
1699 - Xnode->prev->next = Xnode->next; \
1700 - Xnode->next->prev = Xnode->prev; \
1701 - } while (0)
1702 -
1703 -#define FIFO_HEAD(F) \
1704 - ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
1705 - ? NULL : (F)->next)
1706 -
1707 -#define FIFO_EMPTY(F) \
1708 - (((struct fifo *)(F))->next == (struct fifo *)(F))
1709 -
1710 -#define FIFO_TOP(F) \
1711 - (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
1712 -
1713 -#endif /* _ZEBRA_H */
1714 -
1715 -/*
1716 - * Local Variables:
1717 - * c-basic-offset: 2
1718 - * indent-tabs-mode: nil
1719 - * End:
1720 - */
1721 --- a/lib/quagga/src/quagga.c
1722 +++ b/lib/quagga/src/quagga.c
1723 @@ -1,866 +1,555 @@
1724 +/*
1725 + * OLSRd Quagga plugin
1726 + *
1727 + * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
1728 + * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
1729 + *
1730 + * This program is free software; you can redistribute it and/or modify
1731 + * it under the terms of the GNU General Public License version 2 as
1732 + * published by the Free Software Foundation or - at your option - under
1733 + * the terms of the GNU General Public Licence version 2 but can be
1734 + * linked to any BSD-Licenced Software with public available sourcecode
1735 + *
1736 + */
1737
1738 -/***************************************************************************
1739 - projekt : olsrd-quagga
1740 - file : quagga.c
1741 - usage : communication with the zebra-daemon
1742 - copyright : (C) 2006 by Immo 'FaUl' Wehrenberg
1743 - e-mail : immo@chaostreff-dortmund.de
1744 - ***************************************************************************/
1745 -
1746 -/***************************************************************************
1747 - * *
1748 - * This program is free software; you can redistribute it and/or modify *
1749 - * it under the terms of the GNU General Public License version 2 as *
1750 - * published by the Free Software Foundation. *
1751 - * *
1752 - ***************************************************************************/
1753 +/* -------------------------------------------------------------------------
1754 + * File : quagga.c
1755 + * Description : functions to interface to the zebra daemon
1756 + * ------------------------------------------------------------------------- */
1757
1758 -#ifdef MY_DEBUG
1759 -#include <stdio.h>
1760 -#endif
1761
1762 #define HAVE_SOCKLEN_T
1763
1764 +#include "quagga.h"
1765 +#include "olsr.h" /* olsr_exit
1766 + olsr_malloc */
1767 +#include "log.h" /* olsr_syslog */
1768 +
1769 #include <stdint.h>
1770 +#include <stdlib.h>
1771 +#include <unistd.h>
1772 +#include <string.h>
1773 +#include <fcntl.h>
1774 +#include <errno.h>
1775 #include <sys/types.h>
1776 #include <sys/socket.h>
1777 #include <netinet/in.h>
1778 -#include <fcntl.h>
1779 -#include <unistd.h>
1780 -
1781 -#include "quagga.h"
1782 -#include "olsr.h"
1783 -#include "log.h"
1784 -#include "defs.h"
1785 -#include "routing_table.h"
1786 -
1787 +#include <arpa/inet.h>
1788 #ifdef USE_UNIX_DOMAIN_SOCKET
1789 #include <sys/un.h>
1790 -#define ZEBRA_SOCKET "/var/run/quagga/zserv.api"
1791 #endif
1792
1793 -#define ZEBRA_IPV4_ROUTE_ADD 7
1794 -#define ZEBRA_IPV4_ROUTE_DELETE 8
1795 -#define ZEBRA_REDISTRIBUTE_ADD 11
1796 -#define ZEBRA_REDISTRIBUTE_DELETE 12
1797 -#define ZEBRA_MESSAGE_MAX 23
1798 -
1799 -#define ZEBRA_ROUTE_OLSR 11
1800 -#define ZEBRA_ROUTE_MAX 12
1801 -
1802 -#define ZEBRA_FLAG_SELECTED 0x10
1803 -
1804 -#define ZEBRA_NEXTHOP_IPV4 3
1805 -#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
1806 -
1807 -#define ZAPI_MESSAGE_NEXTHOP 0x01
1808 -#define ZAPI_MESSAGE_IFINDEX 0x02
1809 -#define ZAPI_MESSAGE_DISTANCE 0x04
1810 -#define ZAPI_MESSAGE_METRIC 0x08
1811 -
1812 -#define BUFSIZE 1024
1813 -
1814 -#define STATUS_CONNECTED 1
1815 -#define OPTION_EXPORT 1
1816
1817 +/* prototypes intern */
1818 static struct {
1819 - char status; // internal status
1820 - char options; // internal options
1821 - int sock; // Socket to zebra...
1822 + char status; // internal status
1823 + char options; // internal options
1824 + int sock; // Socket to zebra...
1825 char redistribute[ZEBRA_ROUTE_MAX];
1826 char distance;
1827 char flags;
1828 - struct ipv4_route *v4_rt; // routes currently exportet to zebra
1829 + struct zebra_route *v4_rt; // routes currently exportet to zebra
1830 } zebra;
1831
1832 -/* prototypes intern */
1833 -static unsigned char *try_read(ssize_t *);
1834 -static unsigned char *zebra_route_packet(struct ipv4_route r, ssize_t *);
1835 -static int parse_interface_add(unsigned char *, size_t);
1836 -static int parse_interface_delete(unsigned char *, size_t);
1837 -static int parse_interface_up(unsigned char *, size_t);
1838 -static int parse_interface_down(unsigned char *, size_t);
1839 -static int parse_interface_address_add(unsigned char *, size_t);
1840 -static int parse_interface_address_delete(unsigned char *, size_t);
1841 -static int parse_ipv4_route(unsigned char *, size_t, struct ipv4_route *);
1842 -static int ipv4_route_add(unsigned char *, size_t);
1843 -static int ipv4_route_delete(unsigned char *, size_t);
1844 -static int parse_ipv6_route_add(unsigned char *, size_t);
1845 -static void zebra_reconnect(void);
1846 -static void zebra_connect(void);
1847 -
1848 -static void free_ipv4_route(struct ipv4_route);
1849 -
1850 -/*
1851 -static void update_olsr_zebra_routes (struct ipv4_route*, struct ipv4_route*);
1852 -static struct ipv4_route *zebra_create_ipv4_route_table_entry (uint32_t,
1853 - uint32_t,
1854 - uint32_t);
1855 -static struct ipv4_route *zebra_create_ipv4_route_table (void);
1856 -static void zebra_free_ipv4_route_table (struct ipv4_route*);
1857 -*/
1858 -
1859 -/*static uint8_t masktoprefixlen (uint32_t);*/
1860 -
1861 -#ifdef MY_DEBUG
1862 -static void
1863 -dump_ipv4_route(struct ipv4_route r, char *c)
1864 -{
1865 - int i = 0, x = 0;
1866 -
1867 - puts(c);
1868 - printf("type: %d\n", r.type);
1869 - puts("flags:");
1870 - printf(" Internal: %s\n", r.flags & ZEBRA_FLAG_INTERNAL ? "yes" : "no");
1871 - printf(" Selfroute %s\n", r.flags & ZEBRA_FLAG_SELFROUTE ? "yes" : "no");
1872 - printf(" Blackhole %s\n", r.flags & ZEBRA_FLAG_BLACKHOLE ? "yes" : "no");
1873 - printf(" IBGP: %s\n", r.flags & ZEBRA_FLAG_IBGP ? "yes" : "no");
1874 - printf(" Selected: %s\n", r.flags & ZEBRA_FLAG_SELECTED ? "yes" : "no");
1875 - printf(" Changed: %s\n", r.flags & ZEBRA_FLAG_CHANGED ? "yes" : "no");
1876 - printf(" static: %s\n", r.flags & ZEBRA_FLAG_STATIC ? "yes" : "no");
1877 - printf(" reject: %s\n", r.flags & ZEBRA_FLAG_REJECT ? "yes" : "no");
1878 - puts("message:");
1879 - printf(" nexthop: %s\n", r.message & ZAPI_MESSAGE_NEXTHOP ? "yes" : "no");
1880 - printf(" ifindex: %s\n", r.message & ZAPI_MESSAGE_IFINDEX ? "yes" : "no");
1881 - printf(" distance: %s\n", r.message & ZAPI_MESSAGE_DISTANCE ? "yes" : "no");
1882 - printf(" metric: %s\n", r.message & ZAPI_MESSAGE_METRIC ? "yes" : "no");
1883 - printf("Prefixlen: %d\n", r.prefixlen);
1884 - printf("Prefix: %d", (unsigned char)r.prefix);
1885 - c = (char *)&r.prefix;
1886 - while (++i < (r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0)))
1887 - printf(".%d", (unsigned char)*(c + i));
1888 - while (i++ < 4)
1889 - printf(".0");
1890 - puts("");
1891 - i = 0;
1892 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
1893 - printf("nexthop-count: %d\n", r.nh_count);
1894 - while (i++ < r.nh_count) {
1895 - if (r.nexthops[i].type == ZEBRA_NEXTHOP_IPV4) {
1896 - c = (unsigned char *)&r.nexthops[i].payload.v4;
1897 - printf("Nexthop %d: %d", i, (unsigned char)*c);
1898 - while (++x < 4) {
1899 - printf(".%d", (unsigned char)c[x]);
1900 - }
1901 - puts("");
1902 - }
1903 - }
1904 - i = 0;
1905 - }
1906 - if (r.message & ZAPI_MESSAGE_IFINDEX) {
1907 -
1908 - printf("index-number: %d\n", r.ind_num);
1909 - while (i++ < r.ind_num)
1910 - printf("Index: %d: %d\n", i, r.index[i]);
1911 - i = 0;
1912 - if (r.message & ZAPI_MESSAGE_DISTANCE)
1913 - printf("Distance: %d\n", r.distance);
1914 - if (r.message & ZAPI_MESSAGE_METRIC)
1915 - printf("Metric: %d\n", r.metric);
1916 - puts("\n");
1917 - }
1918 -}
1919 +static void *my_realloc (void *, size_t, const char *);
1920 +static void zebra_connect (void);
1921 +static unsigned char *try_read (ssize_t *);
1922 +static int zebra_send_command (unsigned char *);
1923 +static unsigned char* zebra_route_packet (uint16_t, struct zebra_route *);
1924 +static unsigned char *zebra_redistribute_packet (unsigned char, unsigned char);
1925 +static struct zebra_route *zebra_parse_route (unsigned char *);
1926 +#if 0
1927 +static void zebra_reconnect (void);
1928 #endif
1929 +static void free_ipv4_route (struct zebra_route *);
1930 +
1931
1932 -void *
1933 -my_realloc(void *buf, size_t s, const char *c)
1934 -{
1935 - buf = realloc(buf, s);
1936 +static void *my_realloc (void *buf, size_t s, const char *c) {
1937 + buf = realloc (buf, s);
1938 if (!buf) {
1939 - OLSR_PRINTF(1, "(QUAGGA) OUT OF MEMORY: %s\n", strerror(errno));
1940 + OLSR_PRINTF (1, "(QUAGGA) OUT OF MEMORY: %s\n", strerror(errno));
1941 olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n");
1942 olsr_exit(c, EXIT_FAILURE);
1943 }
1944 return buf;
1945 }
1946
1947 -void
1948 -init_zebra(void)
1949 -{
1950 +
1951 +void init_zebra (void) {
1952 zebra_connect();
1953 - if (!(zebra.status & STATUS_CONNECTED))
1954 - olsr_exit("(QUAGGA) AIIIII, could not connect to zebra! is zebra running?", EXIT_FAILURE);
1955 + if (!(zebra.status&STATUS_CONNECTED))
1956 + olsr_exit ("(QUAGGA) AIIIII, could not connect to zebra! is zebra running?",
1957 + EXIT_FAILURE);
1958 }
1959
1960 -void
1961 -zebra_cleanup(void)
1962 -{
1963 +
1964 +void zebra_cleanup (void) {
1965 int i;
1966 struct rt_entry *tmp;
1967
1968 if (zebra.options & OPTION_EXPORT) {
1969 OLSR_FOR_ALL_RT_ENTRIES(tmp) {
1970 - zebra_del_olsr_v4_route(tmp);
1971 - }
1972 - OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
1973 + zebra_del_route(tmp);
1974 + } OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
1975 }
1976
1977 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1978 - if (zebra.redistribute[i])
1979 - zebra_disable_redistribute(i + 1);
1980 + if (zebra.redistribute[i]) zebra_disable_redistribute(i);
1981 }
1982
1983 -static void
1984 -zebra_reconnect(void)
1985 -{
1986 +
1987 +#if 0
1988 +static void zebra_reconnect (void) {
1989 struct rt_entry *tmp;
1990 int i;
1991
1992 zebra_connect();
1993 - if (!(zebra.status & STATUS_CONNECTED))
1994 - return; // try again next time
1995 + if (!(zebra.status & STATUS_CONNECTED)) return; // try again next time
1996
1997 if (zebra.options & OPTION_EXPORT) {
1998 OLSR_FOR_ALL_RT_ENTRIES(tmp) {
1999 - zebra_add_olsr_v4_route(tmp);
2000 - }
2001 - OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
2002 + zebra_add_route (tmp);
2003 + } OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
2004 }
2005
2006 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2007 - if (zebra.redistribute[i])
2008 - zebra_redistribute(i + 1);
2009 + if (zebra.redistribute[i]) zebra_redistribute(i + 1);
2010 /* Zebra sends us all routes of type it knows after
2011 zebra_redistribute(type) */
2012 }
2013 +#endif
2014 +
2015
2016 /* Connect to the zebra-daemon, returns a socket */
2017 -static void
2018 -zebra_connect(void)
2019 -{
2020 +static void zebra_connect (void) {
2021
2022 int ret;
2023
2024 #ifndef USE_UNIX_DOMAIN_SOCKET
2025 struct sockaddr_in i;
2026 - if (close(zebra.sock) < 0)
2027 - olsr_exit("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2028 + if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2029 +
2030
2031 - zebra.sock = socket(AF_INET, SOCK_STREAM, 0);
2032 + zebra.sock = socket (AF_INET,SOCK_STREAM, 0);
2033 #else
2034 struct sockaddr_un i;
2035 - if (close(zebra.sock) < 0)
2036 - olsr_exit("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2037 + if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2038
2039 - zebra.sock = socket(AF_UNIX, SOCK_STREAM, 0);
2040 + zebra.sock = socket (AF_UNIX,SOCK_STREAM, 0);
2041 #endif
2042
2043 - if (zebra.sock < 0)
2044 + if (zebra.sock <0 )
2045 olsr_exit("(QUAGGA) Could not create socket!", EXIT_FAILURE);
2046
2047 - memset(&i, 0, sizeof i);
2048 + memset (&i, 0, sizeof i);
2049 #ifndef USE_UNIX_DOMAIN_SOCKET
2050 i.sin_family = AF_INET;
2051 - i.sin_port = htons(ZEBRA_PORT);
2052 - i.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
2053 + i.sin_port = htons (ZEBRA_PORT);
2054 + i.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
2055 #else
2056 i.sun_family = AF_UNIX;
2057 - strscpy(i.sun_path, ZEBRA_SOCKET, sizeof(i.sun_path));
2058 + strcpy (i.sun_path, ZEBRA_SOCKET);
2059 #endif
2060
2061 - ret = connect(zebra.sock, (struct sockaddr *)&i, sizeof i);
2062 - if (ret < 0)
2063 - zebra.status &= ~STATUS_CONNECTED;
2064 - else
2065 - zebra.status |= STATUS_CONNECTED;
2066 + ret = connect (zebra.sock, (struct sockaddr *)&i, sizeof i);
2067 + if (ret < 0) zebra.status &= ~STATUS_CONNECTED;
2068 + else zebra.status |= STATUS_CONNECTED;
2069 }
2070
2071 +
2072 /* Sends a command to zebra, command is
2073 the command defined in zebra.h, options is the packet-payload,
2074 optlen the length, of the payload */
2075 -unsigned char
2076 -zebra_send_command(unsigned char command, unsigned char *options, int optlen)
2077 -{
2078 +static int zebra_send_command (unsigned char *options) {
2079
2080 - char *p, *pnt;
2081 + unsigned char *pnt;
2082 uint16_t len;
2083 int ret;
2084
2085 -#ifdef ZEBRA_HEADER_MARKER
2086 - uint16_t cmd;
2087 - uint16_t length = optlen + 6; /* length of option + command + packet_length +
2088 - marker + zserv-version */
2089 -#else
2090 - uint16_t length = optlen + 3; // length of option + command + packet_length
2091 -#endif
2092 -
2093 - if (!(zebra.status & STATUS_CONNECTED))
2094 - return 0;
2095 -
2096 - p = olsr_malloc(length, "zebra_send_command");
2097 - pnt = p;
2098 -
2099 - len = htons(length);
2100 + if (!(zebra.status & STATUS_CONNECTED)) return 0;
2101
2102 - memcpy(p, &len, 2);
2103 + pnt = options;
2104 + memcpy (&len, pnt, 2);
2105
2106 -#ifdef ZEBRA_HEADER_MARKER
2107 - p[2] = ZEBRA_HEADER_MARKER;
2108 - p[3] = ZSERV_VERSION;
2109 - cmd = htons(command);
2110 - memcpy(p + 4, &cmd, 2);
2111 -#else
2112 - p[2] = command;
2113 -#endif
2114 - memcpy(p + length - optlen, options, optlen);
2115 -
2116 - errno = 0;
2117 + len = ntohs(len);
2118
2119 do {
2120 - ret = write(zebra.sock, p, length);
2121 + ret = write (zebra.sock, pnt, len);
2122 if (ret < 0) {
2123 - if (errno == EINTR) {
2124 - errno = 0;
2125 - continue;
2126 - } else {
2127 - olsr_printf(1, "(QUAGGA) Disconnected from zebra\n");
2128 - zebra.status &= ~STATUS_CONNECTED;
2129 - free(pnt);
2130 - return -1;
2131 + if ((errno == EINTR) || (errno == EAGAIN)) {
2132 + errno = 0;
2133 + ret = 0;
2134 + continue;
2135 + }
2136 + else {
2137 + OLSR_PRINTF (1, "(QUAGGA) Disconnected from zebra\n");
2138 + zebra.status &= ~STATUS_CONNECTED;
2139 + free (options);
2140 + return -1;
2141 }
2142 }
2143 - p = p + ret;
2144 - }
2145 - while ((length -= ret));
2146 - free(pnt);
2147 + pnt = pnt+ret;
2148 + } while ((len -= ret));
2149 + free (options);
2150 return 0;
2151 }
2152
2153 +
2154 /* Creates a Route-Packet-Payload, needs address, netmask, nexthop,
2155 distance, and a pointer of an size_t */
2156 -static unsigned char *
2157 -zebra_route_packet(struct ipv4_route r, ssize_t * optlen)
2158 -{
2159 +static unsigned char* zebra_route_packet (uint16_t cmd, struct zebra_route *r) {
2160
2161 int count;
2162 + uint8_t len;
2163 + uint16_t size;
2164 + uint32_t ind, metric;
2165
2166 unsigned char *cmdopt, *t;
2167 - *optlen = 4; // first: type, flags, message, prefixlen
2168 - *optlen += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0); // + prefix
2169 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
2170 - if (r.nexthops->type == ZEBRA_NEXTHOP_IPV4 || r.nexthops->type == ZEBRA_NEXTHOP_IPV4_IFINDEX) {
2171 - *optlen += (sizeof r.nexthops->payload.v4 + sizeof r.nexthops->type) * r.nh_count + 1;
2172 - } else if (r.nexthops->type == 0)
2173 - *optlen += 5;
2174 - }
2175 - if (r.message & ZAPI_MESSAGE_IFINDEX)
2176 - *optlen += r.ind_num * sizeof *r.index + 1;
2177 - if (r.message & ZAPI_MESSAGE_DISTANCE)
2178 - (*optlen)++;
2179 - if (r.message & ZAPI_MESSAGE_METRIC)
2180 - *optlen += sizeof r.metric;
2181 -
2182 - cmdopt = olsr_malloc(*optlen, "zebra add_v4_route");
2183 -
2184 - t = cmdopt;
2185 - *t++ = r.type;
2186 - *t++ = r.flags;
2187 - *t++ = r.message;
2188 - *t++ = r.prefixlen;
2189 - for (count = 0; count < r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0); count++) {
2190 - *t++ = *((char *)&r.prefix + count); /* this is so sick!! */
2191 - }
2192 -
2193 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
2194 - *t++ = r.nh_count;
2195 - *t++ = r.nexthops->type;
2196 - if (r.nexthops->type == ZEBRA_NEXTHOP_IPV4 || r.nexthops->type == ZEBRA_NEXTHOP_IPV4_IFINDEX) {
2197 - for (count = 0; count != r.nh_count; count++) {
2198 - memcpy(t, &r.nexthops[count].payload.v4, sizeof r.nexthops->payload.v4);
2199 - t += sizeof r.nexthops->payload.v4;
2200 - }
2201 - } else if (r.nexthops->type == 0) {
2202 - *t++ = 0;
2203 - *t++ = 0;
2204 - *t++ = 0;
2205 - }
2206 - }
2207 - if (r.message & ZAPI_MESSAGE_IFINDEX) {
2208 - *t++ = r.ind_num;
2209 - memcpy(t, r.index, sizeof *r.index * r.ind_num);
2210 - t += sizeof r.index * r.ind_num;
2211 - }
2212 - if (r.message & ZAPI_MESSAGE_DISTANCE)
2213 - *t++ = r.distance;
2214 - if (r.message & ZAPI_MESSAGE_METRIC) {
2215 - memcpy(t, &r.metric, sizeof r.metric);
2216 - t += sizeof r.metric;
2217 - }
2218 - return cmdopt;
2219 -}
2220
2221 -/* adds a route to zebra-daemon */
2222 -int
2223 -zebra_add_v4_route(const struct ipv4_route r)
2224 -{
2225 -
2226 - unsigned char *cmdopt;
2227 - ssize_t optlen;
2228 - int retval;
2229 + cmdopt = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra add_v4_route");
2230
2231 - cmdopt = zebra_route_packet(r, &optlen);
2232 + t = &cmdopt[2];
2233 + *t++ = cmd;
2234 + *t++ = r->type;
2235 + *t++ = r->flags;
2236 + *t++ = r->message;
2237 + *t++ = r->prefixlen;
2238 + len = (r->prefixlen + 7) / 8;
2239 + memcpy (t, &r->prefix.v4.s_addr, len);
2240 + t = t + len;
2241
2242 - retval = zebra_send_command(ZEBRA_IPV4_ROUTE_ADD, cmdopt, optlen);
2243 - free(cmdopt);
2244 - return retval;
2245 + if (r->message & ZAPI_MESSAGE_NEXTHOP) {
2246 + *t++ = r->nexthop_num + r->ifindex_num;
2247 +
2248 + for (count = 0; count < r->nexthop_num; count++)
2249 + {
2250 + *t++ = ZEBRA_NEXTHOP_IPV4;
2251 + memcpy (t, &r->nexthop[count].v4.s_addr,
2252 + sizeof r->nexthop[count].v4.s_addr);
2253 + t += sizeof r->nexthop[count].v4.s_addr;
2254 + }
2255 + for (count = 0; count < r->ifindex_num; count++)
2256 + {
2257 + *t++ = ZEBRA_NEXTHOP_IFINDEX;
2258 + ind = htonl(r->ifindex[count]);
2259 + memcpy (t, &ind, sizeof ind);
2260 + t += sizeof ind;
2261 + }
2262 + }
2263 + if ((r->message & ZAPI_MESSAGE_DISTANCE) > 0)
2264 + *t++ = r->distance;
2265 + if ((r->message & ZAPI_MESSAGE_METRIC) > 0)
2266 + {
2267 + metric = htonl (r->metric);
2268 + memcpy (t, &metric, sizeof metric);
2269 + t += sizeof metric;
2270 + }
2271 + size = htons (t - cmdopt);
2272 + memcpy (cmdopt, &size, 2);
2273
2274 + return cmdopt;
2275 }
2276
2277 -/* deletes a route from the zebra-daemon */
2278 -int
2279 -zebra_delete_v4_route(struct ipv4_route r)
2280 -{
2281 -
2282 - unsigned char *cmdopt;
2283 - ssize_t optlen;
2284 - int retval;
2285 -
2286 - cmdopt = zebra_route_packet(r, &optlen);
2287 -
2288 - retval = zebra_send_command(ZEBRA_IPV4_ROUTE_DELETE, cmdopt, optlen);
2289 - free(cmdopt);
2290 -
2291 - return retval;
2292 -
2293 -}
2294
2295 /* Check wether there is data from zebra aviable */
2296 -void
2297 -zebra_check(void *foo __attribute__ ((unused)))
2298 -{
2299 +void zebra_parse (void* foo __attribute__((unused))) {
2300 unsigned char *data, *f;
2301 - ssize_t len, ret;
2302 + unsigned char command;
2303 + uint16_t length;
2304 + ssize_t len;
2305 + struct zebra_route *route;
2306
2307 if (!(zebra.status & STATUS_CONNECTED)) {
2308 - zebra_reconnect();
2309 +// zebra_reconnect();
2310 return;
2311 }
2312 - data = try_read(&len);
2313 + data = try_read (&len);
2314 if (data) {
2315 f = data;
2316 do {
2317 - ret = zebra_parse_packet(f, len);
2318 - if (!ret) // something wired happened
2319 - olsr_exit("(QUAGGA) Zero message length??? ", EXIT_FAILURE);
2320 - f += ret;
2321 - }
2322 - while ((f - data) < len);
2323 - free(data);
2324 + memcpy (&length, f, sizeof length);
2325 + length = ntohs (length);
2326 + if (!length) // something wired happened
2327 + olsr_exit ("(QUAGGA) Zero message length??? ", EXIT_FAILURE);
2328 + command = f[2];
2329 + switch (command) {
2330 + case ZEBRA_IPV4_ROUTE_ADD:
2331 + route = zebra_parse_route(f);
2332 + ip_prefix_list_add(&olsr_cnf->hna_entries, &route->prefix, route->prefixlen);
2333 + free_ipv4_route (route);
2334 + free (route);
2335 + break;
2336 + case ZEBRA_IPV4_ROUTE_DELETE:
2337 + route = zebra_parse_route(f);
2338 + ip_prefix_list_remove(&olsr_cnf->hna_entries, &route->prefix, route->prefixlen);
2339 + free_ipv4_route (route);
2340 + free (route);
2341 + break;
2342 + default:
2343 + break;
2344 + }
2345 + f += length;
2346 + } while ((f - data) < len);
2347 + free (data);
2348 }
2349 }
2350
2351 +
2352 // tries to read a packet from zebra_socket
2353 // if there is something to read - make sure to read whole packages
2354 -static unsigned char *
2355 -try_read(ssize_t * len)
2356 -{
2357 - unsigned char *buf = NULL;
2358 - ssize_t ret = 0, bsize = 0;
2359 - uint16_t length = 0, l = 0;
2360 - int sockstate;
2361 -
2362 - *len = 0;
2363 -
2364 - sockstate = fcntl(zebra.sock, F_GETFL, 0);
2365 - fcntl(zebra.sock, F_SETFL, sockstate | O_NONBLOCK);
2366 +static unsigned char *try_read (ssize_t *size) {
2367 + unsigned char *buf;
2368 + ssize_t bytes, bufsize;
2369 + uint16_t length, offset;
2370 + int sockstatus;
2371 +
2372 + /* initialize variables */
2373 + buf = NULL;
2374 + offset = 0;
2375 + *size = 0;
2376 + bufsize = 0;
2377 +
2378 + /* save socket status and set non-blocking for read */
2379 + sockstatus = fcntl (zebra.sock, F_GETFL);
2380 + fcntl (zebra.sock, F_SETFL, sockstatus|O_NONBLOCK);
2381
2382 + /* read whole packages */
2383 do {
2384 - if (*len == bsize) {
2385 - bsize += BUFSIZE;
2386 - buf = my_realloc(buf, bsize, "Zebra try_read");
2387 +
2388 + /* (re)allocate buffer */
2389 + if (*size == bufsize) {
2390 + bufsize += BUFSIZE;
2391 + buf = my_realloc (buf, bufsize, "Zebra try_read");
2392 }
2393 - ret = read(zebra.sock, buf + l, bsize - l);
2394 - if (!ret) { // nothing more to read, packet is broken, discard!
2395 - free(buf);
2396 +
2397 + /* read from socket */
2398 + bytes = read (zebra.sock, buf + *size, bufsize - *size);
2399 + /* handle broken packet */
2400 + if (!bytes) {
2401 + free (buf);
2402 return NULL;
2403 }
2404 -
2405 - if (ret < 0) {
2406 - if (errno != EAGAIN) { // oops - we got disconnected
2407 - olsr_printf(1, "(QUAGGA) Disconnected from zebra\n");
2408 + /* handle no data available */
2409 + if (bytes < 0) {
2410 + /* handle disconnect */
2411 + if (errno != EAGAIN) { // oops - we got disconnected
2412 + OLSR_PRINTF (1, "(QUAGGA) Disconnected from zebra\n");
2413 zebra.status &= ~STATUS_CONNECTED;
2414 }
2415 - free(buf);
2416 + free (buf);
2417 return NULL;
2418 }
2419
2420 - *len += ret;
2421 - while ((*len - l) > length) {
2422 - l += length;
2423 - memcpy(&length, buf + l, 2);
2424 - length = ntohs(length);
2425 - }
2426 - if (((*len) - l) == length)
2427 - break; // GOT FULL PACKAGE!!
2428 - if (*len < l) {
2429 - fcntl(zebra.sock, F_SETFL, sockstate);
2430 - continue;
2431 - }
2432 - }
2433 - while (1);
2434 -
2435 - fcntl(zebra.sock, F_SETFL, sockstate);
2436 - return buf;
2437 -}
2438 -
2439 -/* Parse a packet recived from zebra */
2440 -int
2441 -zebra_parse_packet(unsigned char *packet, ssize_t maxlen)
2442 -{
2443 -
2444 - uint16_t command;
2445 - int skip;
2446 -
2447 - /* Array of functions */
2448 - int (*foo[ZEBRA_MESSAGE_MAX]) (unsigned char *, size_t) = {
2449 - parse_interface_add, parse_interface_delete, parse_interface_address_add, parse_interface_address_delete, parse_interface_up,
2450 - parse_interface_down, ipv4_route_add, ipv4_route_delete, parse_ipv6_route_add};
2451 -
2452 - uint16_t length;
2453 - int ret;
2454 -
2455 -#ifdef MY_DEBUG
2456 - puts("DEBUG: zebra_parse_packet");
2457 -#endif
2458 -
2459 - memcpy(&length, packet, 2);
2460 - length = ntohs(length);
2461 -
2462 - if (maxlen < length) {
2463 - olsr_printf(1, "(QUAGGA) maxlen = %lu, packet_length = %d\n", (unsigned long)maxlen, length);
2464 - olsr_exit("(QUAGGA) programmer is an idiot", EXIT_FAILURE);
2465 - }
2466 -#ifdef ZEBRA_HEADER_MARKER
2467 - if (packet[2] == 255) { // found header marker!!
2468 - //packet[3] == ZSERV_VERSION: FIXME: HANDLE THIS!
2469 - memcpy(&command, packet + 4, sizeof command); // two bytes command now!
2470 - command = ntohs(command) - 1;
2471 - skip = 6;
2472 - }
2473 -#else
2474 - command = packet[2] - 1;
2475 - skip = 3;
2476 -#endif
2477 -
2478 - if (command < ZEBRA_MESSAGE_MAX && foo[command]) {
2479 - if (!(ret = foo[command] (packet + skip, length - skip)))
2480 - return length;
2481 - else
2482 - olsr_printf(1, "(QUAGGA) Parse error: %d\n", ret);
2483 - } else
2484 - olsr_printf(1, "(QUAGGA) Unknown packet type: %d\n", packet[2]);
2485 -
2486 - olsr_printf(1, "(Quagga) RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE");
2487 -
2488 - return length;
2489 -}
2490 -
2491 -static int
2492 -parse_interface_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2493 -{
2494 - //todo
2495 - return 0;
2496 -}
2497 -
2498 -static int
2499 -parse_interface_delete(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2500 -{
2501 - //todo
2502 - return 0;
2503 -}
2504 -
2505 -static int
2506 -parse_interface_address_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2507 -{
2508 -
2509 - //todo
2510 - return 0;
2511 -}
2512 -
2513 -static int
2514 -parse_interface_up(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2515 -{
2516 + *size += bytes;
2517
2518 - //todo
2519 - return 0;
2520 -}
2521 + /* detect zebra packet fragmentation */
2522 + do {
2523 + memcpy (&length, buf + offset, sizeof length);
2524 + length = ntohs (length);
2525 + offset += length;
2526 + } while (*size >= (ssize_t) (offset + sizeof length));
2527 + /* set blocking socket on fragmented packet */
2528 + if (*size != offset)
2529 + fcntl (zebra.sock, F_SETFL, sockstatus);
2530 +
2531 + } while (*size != offset);
2532
2533 -static int
2534 -parse_interface_down(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2535 -{
2536 + /* restore socket status */
2537 + fcntl (zebra.sock, F_SETFL, sockstatus);
2538
2539 - //todo
2540 - return 0;
2541 + return buf;
2542 }
2543
2544 -static int
2545 -parse_interface_address_delete(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2546 -{
2547 - //todo
2548 - return 0;
2549 -}
2550
2551 /* Parse an ipv4-route-packet recived from zebra
2552 */
2553 -static int
2554 -parse_ipv4_route(unsigned char *opt, size_t len, struct ipv4_route *r)
2555 -{
2556 +static struct zebra_route *zebra_parse_route (unsigned char *opt) {
2557 +
2558 + struct zebra_route *r;
2559 int c;
2560 -
2561 - if (len < 4)
2562 - return -1;
2563 -
2564 - r->type = *opt++;
2565 - r->flags = *opt++;
2566 - r->message = *opt++;
2567 - r->prefixlen = *opt++;
2568 - len -= 4;
2569 - r->prefix = 0;
2570 -
2571 - if ((int)len < r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0))
2572 - return -1;
2573 -
2574 - memcpy(&r->prefix, opt, r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0));
2575 - opt += r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0);
2576 + size_t size;
2577 + uint16_t length;
2578 + unsigned char *pnt;
2579 +
2580 + memcpy (&length, opt, sizeof length);
2581 + length = ntohs (length);
2582 +
2583 + r = olsr_malloc (sizeof *r , "zebra_parse_route");
2584 + pnt = &opt[3];
2585 + r->type = *pnt++;
2586 + r->flags = *pnt++;
2587 + r->message = *pnt++;
2588 + r->prefixlen = *pnt++;
2589 + r->prefix.v4.s_addr = 0;
2590 +
2591 + size = (r->prefixlen + 7) / 8;
2592 + memcpy (&r->prefix.v4.s_addr, pnt, size);
2593 + pnt += size;
2594
2595 if (r->message & ZAPI_MESSAGE_NEXTHOP) {
2596 - if (len < 1)
2597 - return -1;
2598 - r->nh_count = *opt++;
2599 - len--;
2600 - if (len < (sizeof(uint32_t) + 1) * r->nh_count)
2601 - return -1;
2602 - r->nexthops =
2603 - olsr_malloc((sizeof r->nexthops->type + sizeof r->nexthops->payload) * r->nh_count, "quagga: parse_ipv4_route_add");
2604 - for (c = 0; c < r->nh_count; c++) {
2605 - r->nexthops[c].type = *opt++;
2606 - memcpy(&r->nexthops[c].payload.v4, opt, sizeof(uint32_t));
2607 - opt += sizeof(uint32_t);
2608 - len -= sizeof(uint32_t) + 1;
2609 + r->nexthop_num = *pnt++;
2610 + r->nexthop = olsr_malloc ((sizeof *r->nexthop) * r->nexthop_num,
2611 + "quagga: zebra_parse_route");
2612 + for (c = 0; c < r->nexthop_num; c++) {
2613 + memcpy (&r->nexthop[c].v4.s_addr, pnt, sizeof r->nexthop[c].v4.s_addr);
2614 + pnt += sizeof r->nexthop[c].v4.s_addr;
2615 }
2616 }
2617
2618 if (r->message & ZAPI_MESSAGE_IFINDEX) {
2619 - if (len < 1)
2620 - return -1;
2621 - r->ind_num = *opt++;
2622 - if (len < sizeof(uint32_t) * r->ind_num)
2623 - return -1;
2624 - r->index = olsr_malloc(sizeof(uint32_t) * r->ind_num, "quagga: parse_ipv4_route_add");
2625 - memcpy(r->index, opt, r->ind_num * sizeof(uint32_t));
2626 - opt += sizeof(uint32_t) * r->ind_num;
2627 - len -= sizeof(uint32_t) * r->ind_num;
2628 + r->ifindex_num = *pnt++;
2629 + r->ifindex = olsr_malloc (sizeof (uint32_t) * r->ifindex_num,
2630 + "quagga: zebra_parse_route");
2631 + for (c = 0; c < r->ifindex_num; c++) {
2632 + memcpy (&r->ifindex[c], pnt, sizeof r->ifindex[c]);
2633 + r->ifindex[c] = ntohl (r->ifindex[c]);
2634 + pnt += sizeof r->ifindex[c];
2635 + }
2636 }
2637
2638 if (r->message & ZAPI_MESSAGE_DISTANCE) {
2639 - if (len < 1)
2640 - return -1;
2641 - r->distance = *opt++;
2642 - len--;
2643 + r->distance = *pnt++;
2644 }
2645
2646 - if (r->message & ZAPI_MESSAGE_METRIC) {
2647 - if (len < sizeof(uint32_t))
2648 - return -1;
2649 - memcpy(&r->metric, opt, sizeof(uint32_t));
2650 - }
2651 +// Quagga v0.98.6 BUG workaround: metric is always sent by zebra
2652 +// even without ZAPI_MESSAGE_METRIC message.
2653 +// if (r.message & ZAPI_MESSAGE_METRIC) {
2654 + memcpy (&r->metric, pnt, sizeof (uint32_t));
2655 + r->metric = ntohl (r->metric);
2656 + pnt += sizeof r->metric;
2657 +// }
2658 +
2659 + if (pnt - opt != length) { olsr_exit ("(QUAGGA) length does not match ??? ", EXIT_FAILURE);
2660 + }
2661
2662 - return 0;
2663 + return r;
2664 }
2665
2666 -static int
2667 -ipv4_route_add(unsigned char *opt, size_t len)
2668 -{
2669
2670 - struct ipv4_route r;
2671 - int f;
2672 +static unsigned char *zebra_redistribute_packet (unsigned char cmd, unsigned char type) {
2673 + unsigned char *data, *pnt;
2674 + uint16_t size;
2675
2676 - f = parse_ipv4_route(opt, len, &r);
2677 - if (f < 0)
2678 - return f;
2679 + data = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra_redistribute_packet");
2680
2681 - return add_hna4_route(r);
2682 -}
2683 -
2684 -static int
2685 -ipv4_route_delete(unsigned char *opt, size_t len)
2686 -{
2687 - struct ipv4_route r;
2688 - int f;
2689 -
2690 - f = parse_ipv4_route(opt, len, &r);
2691 - if (f < 0)
2692 - return f;
2693 -
2694 - return delete_hna4_route(r);
2695 + pnt = &data[2];
2696 + *pnt++ = cmd;
2697 + *pnt++ = type;
2698 + size = htons (pnt - data);
2699 + memcpy (data, &size, 2);
2700
2701 + return data;
2702 }
2703
2704 -static int
2705 -parse_ipv6_route_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2706 -{
2707 - //todo
2708 - return 0;
2709 -}
2710
2711 /* start redistribution FROM zebra */
2712 -int
2713 -zebra_redistribute(unsigned char type)
2714 -{
2715 -
2716 - if (type > ZEBRA_ROUTE_MAX)
2717 - return -1;
2718 - zebra.redistribute[type - 1] = 1;
2719 -
2720 - return zebra_send_command(ZEBRA_REDISTRIBUTE_ADD, &type, 1);
2721 -
2722 -}
2723 -
2724 -/* end redistribution FROM zebra */
2725 -int
2726 -zebra_disable_redistribute(unsigned char type)
2727 -{
2728 -
2729 - if (type > ZEBRA_ROUTE_MAX)
2730 - return -1;
2731 - zebra.redistribute[type - 1] = 0;
2732 +int zebra_redistribute (unsigned char type) {
2733
2734 - return zebra_send_command(ZEBRA_REDISTRIBUTE_DELETE, &type, 1);
2735 + if (zebra_send_command(zebra_redistribute_packet (ZEBRA_REDISTRIBUTE_ADD, type)) < 0)
2736 + olsr_exit("(QUAGGA) could not send redistribute add command", EXIT_FAILURE);
2737
2738 -}
2739 + if (type > ZEBRA_ROUTE_MAX-1) return -1;
2740 + zebra.redistribute[type] = 1;
2741
2742 -int
2743 -add_hna4_route(struct ipv4_route r)
2744 -{
2745 - union olsr_ip_addr net;
2746 -
2747 -#ifdef MY_DEBUG
2748 - dump_ipv4_route(r, "add_hna4_route");
2749 -#endif
2750 -
2751 - net.v4.s_addr = r.prefix;
2752 -
2753 - ip_prefix_list_add(&olsr_cnf->hna_entries, &net, r.prefixlen);
2754 - free_ipv4_route(r);
2755 return 0;
2756 +
2757 }
2758
2759 -int
2760 -delete_hna4_route(struct ipv4_route r)
2761 -{
2762
2763 - union olsr_ip_addr net;
2764 +/* end redistribution FROM zebra */
2765 +int zebra_disable_redistribute (unsigned char type) {
2766
2767 -#ifdef MY_DEBUG
2768 - dump_ipv4_route(r, "delete_hna4_route");
2769 -#endif
2770 + if (zebra_send_command(zebra_redistribute_packet (ZEBRA_REDISTRIBUTE_DELETE, type)) < 0)
2771 + olsr_exit("(QUAGGA) could not send redistribute delete command", EXIT_FAILURE);
2772
2773 - net.v4.s_addr = r.prefix;
2774 + if (type > ZEBRA_ROUTE_MAX-1) return -1;
2775 + zebra.redistribute[type] = 0;
2776
2777 - ip_prefix_list_remove(&olsr_cnf->hna_entries, &net, r.prefixlen) ? 0 : -1;
2778 - free_ipv4_route(r);
2779 return 0;
2780
2781 }
2782
2783 -static void
2784 -free_ipv4_route(struct ipv4_route r)
2785 -{
2786 -
2787 - if (r.message & ZAPI_MESSAGE_IFINDEX && r.ind_num)
2788 - free(r.index);
2789 - if (r.message & ZAPI_MESSAGE_NEXTHOP && r.nh_count)
2790 - free(r.nexthops);
2791 -
2792 -}
2793 -
2794 -/*
2795 -static uint8_t masktoprefixlen (uint32_t mask) {
2796 -
2797 - uint8_t prefixlen = 0;
2798
2799 - mask = htonl (mask);
2800 +static void free_ipv4_route (struct zebra_route *r) {
2801
2802 - if (mask) while (mask << ++prefixlen && prefixlen < 32);
2803 -
2804 - return prefixlen;
2805 + if(r->ifindex_num) free(r->ifindex);
2806 + if(r->nexthop_num) free(r->nexthop);
2807
2808 }
2809 -*/
2810
2811 -int
2812 -zebra_add_olsr_v4_route(const struct rt_entry *r)
2813 -{
2814
2815 - struct ipv4_route route;
2816 +int zebra_add_route (const struct rt_entry *r) {
2817 +
2818 + struct zebra_route route;
2819 int retval;
2820
2821 - route.index = NULL;
2822 - route.distance = 0;
2823 - route.type = ZEBRA_ROUTE_OLSR; // OLSR
2824 - route.message = ZAPI_MESSAGE_METRIC;
2825 + route.type = ZEBRA_ROUTE_OLSR;
2826 route.flags = zebra.flags;
2827 + route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC;
2828 route.prefixlen = r->rt_dst.prefix_len;
2829 - route.prefix = r->rt_dst.prefix.v4.s_addr;
2830 - if ((r->rt_best->rtp_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && route.prefixlen == 32)) {
2831 - route.message |= ZAPI_MESSAGE_IFINDEX | ZAPI_MESSAGE_NEXTHOP;
2832 - route.ind_num = 1;
2833 - route.index = olsr_malloc(sizeof *route.index, "zebra_add_olsr_v4_route");
2834 - *route.index = htonl(r->rt_best->rtp_nexthop.iif_index);
2835 - route.nexthops = olsr_malloc(sizeof route.nexthops->type + sizeof route.nexthops->payload, "zebra_add_olsr_v4_route");
2836 - route.nh_count = 1;
2837 - route.nexthops->type = 0;
2838 - } else {
2839 - route.message |= ZAPI_MESSAGE_NEXTHOP;
2840 - route.nh_count = 1;
2841 - route.nexthops =
2842 - olsr_malloc(route.nh_count * (sizeof route.nexthops->type + sizeof route.nexthops->payload), "zebra_add_olsr_v4_route");
2843 - route.nexthops->type = ZEBRA_NEXTHOP_IPV4;
2844 - route.nexthops->payload.v4 = r->rt_best->rtp_nexthop.gateway.v4.s_addr;
2845 + route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr;
2846 + route.ifindex_num = 0;
2847 + route.ifindex = NULL;
2848 + route.nexthop_num = 0;
2849 + route.nexthop = NULL;
2850 +
2851 + if (r->rt_best->rtp_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr &&
2852 + route.prefixlen == 32) {
2853 + return 0; /* Quagga BUG workaround: don't add routes with destination = gateway
2854 + see http://lists.olsr.org/pipermail/olsr-users/2006-June/001726.html */
2855 + route.ifindex_num++;
2856 + route.ifindex = olsr_malloc (sizeof *route.ifindex,
2857 + "zebra_add_route");
2858 + *route.ifindex = r->rt_best->rtp_nexthop.iif_index;
2859 + }
2860 + else {
2861 + route.nexthop_num++;
2862 + route.nexthop = olsr_malloc (sizeof *route.nexthop, "zebra_add_route");
2863 + route.nexthop->v4.s_addr = r->rt_best->rtp_nexthop.gateway.v4.s_addr;
2864 }
2865
2866 route.metric = r->rt_best->rtp_metric.hops;
2867 - route.metric = htonl(route.metric);
2868
2869 if (zebra.distance) {
2870 route.message |= ZAPI_MESSAGE_DISTANCE;
2871 route.distance = zebra.distance;
2872 }
2873
2874 - retval = zebra_add_v4_route(route);
2875 - free_ipv4_route(route);
2876 + retval = zebra_send_command (zebra_route_packet (ZEBRA_IPV4_ROUTE_ADD, &route));
2877 return retval;
2878 +
2879 }
2880
2881 -int
2882 -zebra_del_olsr_v4_route(const struct rt_entry *r)
2883 -{
2884 +int zebra_del_route (const struct rt_entry *r) {
2885
2886 - struct ipv4_route route;
2887 + struct zebra_route route;
2888 int retval;
2889 - route.index = NULL;
2890 - route.distance = 0;
2891 - route.type = ZEBRA_ROUTE_OLSR; // OLSR
2892 - route.message = ZAPI_MESSAGE_METRIC;
2893 +
2894 + route.type = ZEBRA_ROUTE_OLSR;
2895 route.flags = zebra.flags;
2896 + route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC;
2897 route.prefixlen = r->rt_dst.prefix_len;
2898 - route.prefix = r->rt_dst.prefix.v4.s_addr;
2899 - if ((r->rt_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && route.prefixlen == 32)) {
2900 - route.message |= ZAPI_MESSAGE_IFINDEX;
2901 - route.ind_num = 1;
2902 - route.index = olsr_malloc(sizeof *route.index, "zebra_add_olsr_v4_route");
2903 - *route.index = htonl(r->rt_nexthop.iif_index);
2904 - route.nexthops = olsr_malloc(sizeof route.nexthops->type + sizeof route.nexthops->payload, "zebra_add_olsr_v4_route");
2905 - route.nh_count = 1;
2906 - route.nexthops->type = 0;
2907 - } else {
2908 - route.message |= ZAPI_MESSAGE_NEXTHOP;
2909 - route.nh_count = 1;
2910 - route.nexthops =
2911 - olsr_malloc(route.nh_count * (sizeof route.nexthops->type + sizeof route.nexthops->payload), "zebra_add_olsr_v4_route");
2912 - route.nexthops->type = ZEBRA_NEXTHOP_IPV4;
2913 - route.nexthops->payload.v4 = r->rt_nexthop.gateway.v4.s_addr;
2914 + route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr;
2915 + route.ifindex_num = 0;
2916 + route.ifindex = NULL;
2917 + route.nexthop_num = 0;
2918 + route.nexthop = NULL;
2919 +
2920 + if (r->rt_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr &&
2921 + route.prefixlen == 32){
2922 + return 0; /* Quagga BUG workaround: don't delete routes with destination = gateway
2923 + see http://lists.olsr.org/pipermail/olsr-users/2006-June/001726.html */
2924 + route.ifindex_num++;
2925 + route.ifindex = olsr_malloc (sizeof *route.ifindex,
2926 + "zebra_del_route");
2927 + *route.ifindex = r->rt_nexthop.iif_index;
2928 + }
2929 + else {
2930 + route.nexthop_num++;
2931 + route.nexthop = olsr_malloc (sizeof *route.nexthop, "zebra_del_route");
2932 + route.nexthop->v4.s_addr = r->rt_nexthop.gateway.v4.s_addr;
2933 }
2934 +
2935 route.metric = 0;
2936
2937 if (zebra.distance) {
2938 @@ -868,36 +557,23 @@ zebra_del_olsr_v4_route(const struct rt_
2939 route.distance = zebra.distance;
2940 }
2941
2942 - retval = zebra_delete_v4_route(route);
2943
2944 - free_ipv4_route(route);
2945 + retval = zebra_send_command (zebra_route_packet (ZEBRA_IPV4_ROUTE_DELETE, &route));
2946 return retval;
2947 +
2948 }
2949
2950 -void
2951 -zebra_olsr_distance(unsigned char dist)
2952 -{
2953 +void zebra_olsr_distance (unsigned char dist) {
2954 zebra.distance = dist;
2955 }
2956
2957 -void
2958 -zebra_olsr_localpref(void)
2959 -{
2960 +void zebra_olsr_localpref (void) {
2961 zebra.flags &= ZEBRA_FLAG_SELECTED;
2962 }
2963
2964 -void
2965 -zebra_export_routes(unsigned char t)
2966 -{
2967 +void zebra_export_routes (unsigned char t) {
2968 if (t)
2969 zebra.options |= OPTION_EXPORT;
2970 else
2971 zebra.options &= ~OPTION_EXPORT;
2972 }
2973 -
2974 -/*
2975 - * Local Variables:
2976 - * c-basic-offset: 2
2977 - * indent-tabs-mode: nil
2978 - * End:
2979 - */
2980 --- a/lib/quagga/src/quagga.h
2981 +++ b/lib/quagga/src/quagga.h
2982 @@ -1,77 +1,102 @@
2983 +/*
2984 + * OLSRd Quagga plugin
2985 + *
2986 + * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
2987 + * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
2988 + *
2989 + * This program is free software; you can redistribute it and/or modify
2990 + * it under the terms of the GNU General Public License version 2 as
2991 + * published by the Free Software Foundation or - at your option - under
2992 + * the terms of the GNU General Public Licence version 2 but can be
2993 + * linked to any BSD-Licenced Software with public available sourcecode
2994 + *
2995 + */
2996 +
2997 +/* -------------------------------------------------------------------------
2998 + * File : quagga.h
2999 + * Description : header file for quagga.c
3000 + * ------------------------------------------------------------------------- */
3001
3002 -/***************************************************************************
3003 - projekt : olsrd-quagga
3004 - file : quagga.h
3005 - usage : header for quagga.c
3006 - copyright : (C) 2006 by Immo 'FaUl' Wehrenberg
3007 - e-mail : immo@chaostreff-dortmund.de
3008 - ***************************************************************************/
3009 -
3010 -/***************************************************************************
3011 - * *
3012 - * This program is free software; you can redistribute it and/or modify *
3013 - * it under the terms of the GNU General Public License version 2 as *
3014 - * published by the Free Software Foundation. *
3015 - * *
3016 - ***************************************************************************/
3017 +
3018 +#include "routing_table.h" /* rt_entry */
3019 +#include "olsr_types.h" /* olsr_ip_addr */
3020
3021 #include <stdint.h>
3022 -#include <stdio.h>
3023 #include <stdlib.h>
3024 -#include "routing_table.h"
3025 +
3026 #define HAVE_SOCKLEN_T
3027
3028 +/* Zebra port */
3029 #ifndef ZEBRA_PORT
3030 #define ZEBRA_PORT 2600
3031 #endif
3032
3033 +/* Zebra version */
3034 #ifdef ZEBRA_HEADER_MARKER
3035 #ifndef ZSERV_VERSION
3036 #define ZSERV_VERSION 1
3037 #endif
3038 #endif
3039
3040 -struct ipv4_route {
3041 - uint8_t type;
3042 - uint8_t flags;
3043 - uint8_t message;
3044 - uint8_t prefixlen;
3045 - uint32_t prefix;
3046 - uint8_t nh_count;
3047 - struct {
3048 - uint8_t type;
3049 - union {
3050 - uint32_t v4;
3051 - } payload;
3052 - } *nexthops;
3053 - uint8_t ind_num;
3054 - uint32_t *index;
3055 +/* Zebra socket */
3056 +#define ZEBRA_SOCKET "/var/run/quagga/zserv.api"
3057 +
3058 +/* Zebra packet size */
3059 +#define ZEBRA_MAX_PACKET_SIZ 4096
3060 +
3061 +/* Zebra message types */
3062 +#define ZEBRA_IPV4_ROUTE_ADD 7
3063 +#define ZEBRA_IPV4_ROUTE_DELETE 8
3064 +#define ZEBRA_REDISTRIBUTE_ADD 11
3065 +#define ZEBRA_REDISTRIBUTE_DELETE 12
3066 +#define ZEBRA_MESSAGE_MAX 23
3067 +
3068 +/* Zebra route types */
3069 +#define ZEBRA_ROUTE_OLSR 11
3070 +#define ZEBRA_ROUTE_MAX 13
3071 +
3072 +/* Zebra flags */
3073 +#define ZEBRA_FLAG_SELECTED 0x10
3074 +
3075 +/* Zebra nexthop flags */
3076 +#define ZEBRA_NEXTHOP_IFINDEX 1
3077 +#define ZEBRA_NEXTHOP_IPV4 3
3078 +
3079 +/* Zebra message flags */
3080 +#define ZAPI_MESSAGE_NEXTHOP 0x01
3081 +#define ZAPI_MESSAGE_IFINDEX 0x02
3082 +#define ZAPI_MESSAGE_DISTANCE 0x04
3083 +#define ZAPI_MESSAGE_METRIC 0x08
3084 +
3085 +/* Buffer size */
3086 +#define BUFSIZE 1024
3087 +
3088 +/* Quagga plugin flags */
3089 +#define STATUS_CONNECTED 1
3090 +#define OPTION_EXPORT 1
3091 +
3092 +
3093 +struct zebra_route {
3094 + unsigned char type;
3095 + unsigned char flags;
3096 + unsigned char message;
3097 + unsigned char prefixlen;
3098 + union olsr_ip_addr prefix;
3099 + unsigned char nexthop_num;
3100 + union olsr_ip_addr *nexthop;
3101 + unsigned char ifindex_num;
3102 + uint32_t *ifindex;
3103 uint32_t metric;
3104 uint8_t distance;
3105 - struct ipv4_route *next;
3106 };
3107
3108 -void init_zebra(void);
3109 -void zebra_cleanup(void);
3110 -unsigned char zebra_send_command(unsigned char, unsigned char *, int);
3111 -int zebra_add_v4_route(const struct ipv4_route r);
3112 -int zebra_delete_v4_route(const struct ipv4_route r);
3113 -void zebra_check(void *);
3114 -int zebra_parse_packet(unsigned char *, ssize_t);
3115 -int zebra_redistribute(unsigned char);
3116 -int zebra_disable_redistribute(unsigned char);
3117 -int add_hna4_route(struct ipv4_route);
3118 -int delete_hna4_route(struct ipv4_route);
3119 -void *my_realloc(void *, size_t, const char *);
3120 -int zebra_add_olsr_v4_route(const struct rt_entry *);
3121 -int zebra_del_olsr_v4_route(const struct rt_entry *);
3122 -void zebra_olsr_localpref(void);
3123 -void zebra_olsr_distance(unsigned char);
3124 +void init_zebra (void);
3125 +void zebra_cleanup (void);
3126 +void zebra_parse (void*);
3127 +int zebra_redistribute (unsigned char);
3128 +int zebra_disable_redistribute (unsigned char);
3129 +int zebra_add_route (const struct rt_entry *);
3130 +int zebra_del_route (const struct rt_entry *);
3131 +void zebra_olsr_localpref (void);
3132 +void zebra_olsr_distance (unsigned char);
3133 void zebra_export_routes(unsigned char);
3134 -
3135 -/*
3136 - * Local Variables:
3137 - * c-basic-offset: 2
3138 - * indent-tabs-mode: nil
3139 - * End:
3140 - */
3141 --- a/lib/quagga/test/foo.c
3142 +++ /dev/null
3143 @@ -1,20 +0,0 @@
3144 -#include "quagga.h"
3145 -
3146 -int
3147 -main(void)
3148 -{
3149 -
3150 - init_zebra();
3151 - zebra_redistribute(2);
3152 - // zebra_redistribute (1);
3153 - while (!sleep(1))
3154 - zebra_check();
3155 - return 0;
3156 -}
3157 -
3158 -/*
3159 - * Local Variables:
3160 - * c-basic-offset: 2
3161 - * indent-tabs-mode: nil
3162 - * End:
3163 - */
3164 --- a/lib/quagga/test/foo.pl
3165 +++ /dev/null
3166 @@ -1,19 +0,0 @@
3167 -#!/usr/bin/perl
3168 -
3169 -use IO::Socket;
3170 -
3171 -$command = 11; # 11 = redistribute_add , 13 = redistribute_default_add
3172 -
3173 -$proto = 2; # connected
3174 -
3175 -$remote = IO::Socket::INET->new (Proto => "tcp",
3176 - PeerAddr => "127.0.0.1",
3177 - PeerPort => "2600",
3178 - );
3179 -$remote->autoflush (1);
3180 -#print $remote pack ("nc", 3, 13);
3181 -print $remote pack ("nc",3,1);
3182 -print $remote pack ("ncc", 4,$command,2);
3183 -print $remote pack ("ncccccNcNcNN", 25, 7, 10, 16, 11, 25, 0xc0a80206, 0, 0, 1, 5, 1);
3184 -print <$remote>;
3185 -close $remote
3186 --- a/lib/quagga/test/quagga.try1.c
3187 +++ /dev/null
3188 @@ -1,728 +0,0 @@
3189 -
3190 -/*
3191 - * (C) 2006 by Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
3192 - *
3193 - * This code is covered by the GPLv2
3194 - *
3195 - */
3196 -
3197 -#include <stdint.h>
3198 -#ifdef MY_DEBUG
3199 -#include <stdio.h>
3200 -#endif
3201 -#include <sys/types.h>
3202 -#include <sys/socket.h>
3203 -#include <netinet/in.h>
3204 -#define HAVE_SOCKLEN_T
3205 -#include <quagga/zebra.h>
3206 -#include "quagga.h"
3207 -
3208 -#ifdef OLSR_PLUGIN
3209 -#include "olsr.h"
3210 -#include "log.h"
3211 -#include "defs.h"
3212 -#include "local_hna_set.h"
3213 -#endif
3214 -
3215 -#define ZAPI_MESSAGE_NEXTHOP 0x01
3216 -#define ZAPI_MESSAGE_IFINDEX 0x02
3217 -#define ZAPI_MESSAGE_DISTANCE 0x04
3218 -#define ZAPI_MESSAGE_METRIC 0x08
3219 -
3220 -#define STATUS_CONNECTED 1
3221 -#define BUFSIZE 1024
3222 -static char status = 0;
3223 -
3224 -static int zsock; // Socket to zebra...
3225 -struct ipv4_route *quagga_routes = 0; // routes currently exportet to zebra
3226 -
3227 -/* prototypes ntern */
3228 -static char *try_read(ssize_t *);
3229 -static char *zebra_route_packet(struct ipv4_route r, ssize_t *);
3230 -static int parse_interface_add(char *, size_t);
3231 -static int parse_interface_delete(char *, size_t);
3232 -static int parse_interface_up(char *, size_t);
3233 -static int parse_interface_down(char *, size_t);
3234 -static int parse_interface_address_add(char *, size_t);
3235 -static int parse_interface_address_delete(char *, size_t);
3236 -static int parse_ipv4_route(char *, size_t, struct ipv4_route *);
3237 -static int ipv4_route_add(char *, size_t);
3238 -static int ipv4_route_delete(char *, size_t);
3239 -static int parse_ipv6_route_add(char *, size_t);
3240 -static uint32_t prefixlentomask(uint8_t);
3241 -static void free_ipv4_route(struct ipv4_route);
3242 -static void update_olsr_zebra_routes(struct ipv4_route *, struct ipv4_route *);
3243 -static struct ipv4_route *zebra_create_ipv4_route_table_entry(uint32_t, uint32_t, uint32_t);
3244 -static struct ipv4_route *zebra_create_ipv4_route_table(void);
3245 -static void zebra_free_ipv4_route_table(struct ipv4_route *);
3246 -static uint8_t masktoprefixlen(uint32_t);
3247 -
3248 -#ifdef MY_DEBUG
3249 -static void
3250 -dump_ipv4_route(struct ipv4_route r, char *c)
3251 -{
3252 - int i = 0, x = 0;
3253 -
3254 - puts(c);
3255 - printf("type: %d\n", r.type);
3256 - puts("flags:");
3257 - printf(" Internal: %s\n", r.flags & ZEBRA_FLAG_INTERNAL ? "yes" : "no");
3258 - printf(" Selfroute %s\n", r.flags & ZEBRA_FLAG_SELFROUTE ? "yes" : "no");
3259 - printf(" Blackhole %s\n", r.flags & ZEBRA_FLAG_BLACKHOLE ? "yes" : "no");
3260 - printf(" IBGP: %s\n", r.flags & ZEBRA_FLAG_IBGP ? "yes" : "no");
3261 - printf(" Selected: %s\n", r.flags & ZEBRA_FLAG_SELECTED ? "yes" : "no");
3262 - printf(" Changed: %s\n", r.flags & ZEBRA_FLAG_CHANGED ? "yes" : "no");
3263 - printf(" static: %s\n", r.flags & ZEBRA_FLAG_STATIC ? "yes" : "no");
3264 - printf(" reject: %s\n", r.flags & ZEBRA_FLAG_REJECT ? "yes" : "no");
3265 - puts("message:");
3266 - printf(" nexthop: %s\n", r.message & ZAPI_MESSAGE_NEXTHOP ? "yes" : "no");
3267 - printf(" ifindex: %s\n", r.message & ZAPI_MESSAGE_IFINDEX ? "yes" : "no");
3268 - printf(" distance: %s\n", r.message & ZAPI_MESSAGE_DISTANCE ? "yes" : "no");
3269 - printf(" metric: %s\n", r.message & ZAPI_MESSAGE_METRIC ? "yes" : "no");
3270 - printf("Prefixlen: %d\n", r.prefixlen);
3271 - printf("Prefix: %d", (unsigned char)r.prefix);
3272 - c = (char *)&r.prefix;
3273 - while (++i < (r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0)))
3274 - printf(".%d", (unsigned char)*(c + i));
3275 - while (i++ < 4)
3276 - printf(".0");
3277 - puts("");
3278 - i = 0;
3279 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
3280 -
3281 - printf("nexthop-count: %d\n", r.nh_count);
3282 - while (i++ < r.nh_count) {
3283 - c = (unsigned char *)&r.nexthops[i];
3284 - printf("Nexthop %d: %d", i, (unsigned char)*c);
3285 - while (++x < 4) {
3286 - printf(".%d", (unsigned char)c[x]);
3287 - }
3288 - puts("");
3289 - }
3290 - i = 0;
3291 - }
3292 - if (r.message & ZAPI_MESSAGE_IFINDEX) {
3293 -
3294 - printf("index-number: %d\n", r.ind_num);
3295 - while (i++ < r.ind_num)
3296 - printf("Index: %d: %d\n", i, r.index[i]);
3297 - i = 0;
3298 - if (r.message & ZAPI_MESSAGE_DISTANCE)
3299 - printf("Distance: %d\n", r.distance);
3300 - if (r.message & ZAPI_MESSAGE_METRIC)
3301 - printf("Metric: %d\n", r.metric);
3302 - puts("\n");
3303 - }
3304 -}
3305 -#endif
3306 -
3307 -void *
3308 -my_realloc(void *buf, size_t s, const char *c)
3309 -{
3310 - buf = realloc(buf, s);
3311 - if (!buf) {
3312 -#ifdef OLSR_PLUGIN
3313 - OLSR_PRINTF(1, "OUT OF MEMORY: %s\n", strerror(errno));
3314 - olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n");
3315 - olsr_exit(c, EXIT_FAILURE);
3316 -#else
3317 - exit(EXIT_FAILURE);
3318 -#endif
3319 - }
3320 - return buf;
3321 -}
3322 -
3323 -#ifndef OLSR_PLUGIN
3324 -void *
3325 -olsr_malloc(size_t f, const char *c)
3326 -{
3327 - void *v = malloc(f);
3328 - return v;
3329 -}
3330 -#endif
3331 -
3332 -/* Connect to the zebra-daemon, returns a socket */
3333 -int
3334 -init_zebra()
3335 -{
3336 - struct sockaddr_in i;
3337 - int ret;
3338 -
3339 - zsock = socket(AF_INET, SOCK_STREAM, 0);
3340 - if (zsock < 0) // TODO: Could not create socket
3341 - return -1;
3342 - memset(&i, 0, sizeof i);
3343 - i.sin_family = AF_INET;
3344 - i.sin_port = htons(ZEBRA_PORT);
3345 - // i.sin_len = sizeof i;
3346 - i.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
3347 -
3348 - ret = connect(zsock, (struct sockaddr *)&i, sizeof i);
3349 - if (ret < 0) {
3350 - close(zsock);
3351 - return -1;
3352 - }
3353 - status |= STATUS_CONNECTED;
3354 - return zsock;
3355 -}
3356 -
3357 -/* Sends a command to zebra, command is
3358 - the command defined in zebra.h, options is the packet-payload,
3359 - optlen the length, of the payload */
3360 -char
3361 -zebra_send_command(unsigned char command, char *options, int optlen)
3362 -{
3363 -
3364 - char *p = olsr_malloc(optlen + 3, "zebra send_command");
3365 - uint16_t length = optlen + 3; // length of option + command + packet_length
3366 -
3367 - int ret;
3368 -
3369 - uint16_t len = htons(length);
3370 - memcpy(p, &len, 2);
3371 - p[2] = command;
3372 - memcpy(p + 3, options, optlen);
3373 -
3374 - do {
3375 - ret = write(zsock, p, length);
3376 - if (ret < 0) {
3377 - if (errno == EINTR)
3378 - continue;
3379 - } else
3380 - return -1;
3381 - p = p + ret;
3382 - }
3383 - while ((length -= ret));
3384 -
3385 - return 0;
3386 -}
3387 -
3388 -/* Creates a Route-Packet-Payload, needs address, netmask, nexthop,
3389 - distance, and a pointer of an size_t */
3390 -static char *
3391 -zebra_route_packet(struct ipv4_route r, ssize_t * optlen)
3392 -{
3393 -
3394 - char *cmdopt, *t;
3395 - *optlen = 9; // first: type, flags, message, prefixlen, nexthop number, nexthop)
3396 - *optlen += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0);
3397 -
3398 - cmdopt = olsr_malloc(*optlen, "zebra add_v4_route");
3399 - t = cmdopt;
3400 - *t++ = 10; // Type: olsr
3401 - *t++ = r.flags; // flags
3402 - *t++ = r.message; // message: contains nexthop
3403 - *t++ = r.prefixlen;
3404 - memcpy(t, &r.prefix, r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0));
3405 - *t += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0);
3406 - *t++ = r.nh_count;
3407 - memcpy(t, r.nexthops, r.nh_count * sizeof *r.nexthops);
3408 - return cmdopt;
3409 -}
3410 -
3411 -/* adds a route to zebra-daemon (needs socket from zebra,
3412 - address = prefix of the route
3413 - mask = netmask of the route
3414 - nexthop = nexthop of the route
3415 - distance = distance-value of the route
3416 -*/
3417 -int
3418 -zebra_add_v4_route(struct ipv4_route r)
3419 -{
3420 -
3421 - char *cmdopt;
3422 - ssize_t optlen;
3423 -
3424 - cmdopt = zebra_route_packet(r, &optlen);
3425 -
3426 - puts("DEBUG: zebra_route_packet returned");
3427 -
3428 - return zebra_send_command(ZEBRA_IPV4_ROUTE_ADD, cmdopt, optlen);
3429 -
3430 -}
3431 -
3432 -/* deletes a route from the zebra-daemon (
3433 - needs socket from zebra,
3434 - address = prefix of the route
3435 - mask = netmask of the route
3436 - nexthop = nexthop of the route
3437 - distance = distance-value of the route
3438 -*/
3439 -int
3440 -zebra_delete_v4_route(struct ipv4_route r)
3441 -{
3442 -
3443 - char *cmdopt;
3444 - ssize_t optlen;
3445 -
3446 - cmdopt = zebra_route_packet(r, &optlen);
3447 -
3448 - return zebra_send_command(ZEBRA_IPV4_ROUTE_DELETE, cmdopt, optlen);
3449 -
3450 -}
3451 -
3452 -/* Check wether there is data from zebra aviable */
3453 -void
3454 -zebra_check(void *foo)
3455 -{
3456 - char *data, *f;
3457 - ssize_t len, ret;
3458 -
3459 - if (!status & STATUS_CONNECTED) {
3460 - }
3461 - data = try_read(&len);
3462 - if (data) {
3463 - f = data;
3464 - do {
3465 - ret = zebra_parse_packet(f, len);
3466 - if (!ret) { //something wired happened
3467 - puts("DEBUG: IIIIIIIIIIRGS");
3468 - exit(EXIT_FAILURE);
3469 - }
3470 - f += ret;
3471 - }
3472 - while ((f - data) < len);
3473 - free(data);
3474 - }
3475 -}
3476 -
3477 -// tries to read a packet from zebra_socket
3478 -// if there is something to read - make sure to read whole packages
3479 -static char *
3480 -try_read(ssize_t * len)
3481 -{
3482 - char *buf = NULL;
3483 - ssize_t ret = 0, bsize = 0;
3484 - uint16_t length = 0, l = 0;
3485 - int sockstate;
3486 -
3487 - *len = 0;
3488 -
3489 - sockstate = fcntl(zsock, F_GETFL, 0);
3490 - fcntl(zsock, F_SETFL, sockstate | O_NONBLOCK);
3491 -
3492 - do {
3493 - if (*len == bsize) {
3494 - bsize += BUFSIZE;
3495 - buf = my_realloc(buf, bsize, "Zebra try_read");
3496 - }
3497 - ret = read(zsock, buf + l, bsize - l);
3498 - if (ret <= 0) {
3499 - if (errno == EAGAIN) {
3500 - errno = 0;
3501 - } else {
3502 - // TODO: errorhandling
3503 - ;
3504 - }
3505 - free(buf);
3506 - return NULL;
3507 - }
3508 - *len += ret;
3509 -
3510 - while ((*len - l) > length) {
3511 - // printf ("DEBUG: *len -l > length - %d - %d > %d\n", *len, l, length);
3512 - l += length;
3513 - memcpy(&length, buf + l, 2);
3514 - length = ntohs(length);
3515 - }
3516 - // printf ("DEBUG: *len, l, length: %d,%d,%d\n", *len, l, length);
3517 - if (((*len) - l) == length)
3518 - break; // GOT FULL PACKAGE!!
3519 - if (*len < l) {
3520 - // printf ("DEBUG: *len, l, length: %d,%d,%d\n", *len, l, length);
3521 - fcntl(zsock, F_SETFL, sockstate);
3522 - continue;
3523 - }
3524 - }
3525 - while (1);
3526 -
3527 - fcntl(zsock, F_SETFL, sockstate);
3528 - return buf;
3529 -}
3530 -
3531 -/* Parse a packet recived from zebra */
3532 -int
3533 -zebra_parse_packet(char *packet, ssize_t maxlen)
3534 -{
3535 -
3536 - /* Array of functions */
3537 - int (*foo[ZEBRA_MESSAGE_MAX]) (char *, size_t) = {
3538 - parse_interface_add, parse_interface_delete, parse_interface_address_add, parse_interface_address_delete, parse_interface_up,
3539 - parse_interface_down, ipv4_route_add, ipv4_route_delete, parse_ipv6_route_add};
3540 -
3541 - puts("DEBUG: zebra_parse_packet");
3542 - uint16_t length;
3543 -
3544 - int ret;
3545 - memcpy(&length, packet, 2);
3546 - length = ntohs(length);
3547 -
3548 - if (maxlen < length) {
3549 - puts("Error: programmer is an idiot");
3550 - printf("DEBUG: maxlen = %d, packet_length = %d\n", maxlen, length);
3551 - return maxlen;
3552 - }
3553 -
3554 - if (packet[2] - 1 < ZEBRA_MESSAGE_MAX && foo[packet[2] - 1]) {
3555 - if (!(ret = foo[packet[2] - 1] (packet + 3, length - 3)))
3556 - return length;
3557 - else
3558 - printf("DEBUG: Parse error: %d\n", ret);
3559 - } else
3560 - printf("Unknown packet type: %d\n", packet[2]);
3561 -
3562 - puts("Quagga: RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE");
3563 -
3564 - return length;
3565 -}
3566 -
3567 -static int
3568 -parse_interface_add(char *opt, size_t len)
3569 -{
3570 - //todo
3571 - return 0;
3572 -}
3573 -
3574 -static int
3575 -parse_interface_delete(char *opt, size_t len)
3576 -{
3577 - //todo
3578 - return 0;
3579 -}
3580 -
3581 -static int
3582 -parse_interface_address_add(char *opt, size_t len)
3583 -{
3584 -
3585 - //todo
3586 - return 0;
3587 -}
3588 -
3589 -static int
3590 -parse_interface_up(char *opt, size_t len)
3591 -{
3592 -
3593 - //todo
3594 - return 0;
3595 -}
3596 -
3597 -static int
3598 -parse_interface_down(char *opt, size_t len)
3599 -{
3600 -
3601 - //todo
3602 - return 0;
3603 -}
3604 -
3605 -static int
3606 -parse_interface_address_delete(char *opt, size_t len)
3607 -{
3608 - //todo
3609 - return 0;
3610 -}
3611 -
3612 -/* Parse an ipv4-route-packet recived from zebra
3613 - */
3614 -static int
3615 -parse_ipv4_route(char *opt, size_t len, struct ipv4_route *r)
3616 -{
3617 - // puts ("DEBUG: parse_ipv4_route");
3618 - if (len < 4)
3619 - return -1;
3620 -
3621 - r->type = *opt++;
3622 - r->flags = *opt++;
3623 - r->message = *opt++;
3624 - r->prefixlen = *opt++;
3625 - len -= 4;
3626 - r->prefix = 0;
3627 -
3628 - if ((int)len < r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0))
3629 - return -1;
3630 -
3631 - memcpy(&r->prefix, opt, r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0));
3632 - opt += r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0);
3633 -
3634 - if (r->message & ZAPI_MESSAGE_NEXTHOP) {
3635 - if (len < 1)
3636 - return -1;
3637 - r->nh_count = *opt++;
3638 - if (len < sizeof(uint32_t) * r->nh_count)
3639 - return -1;
3640 - r->nexthops = olsr_malloc(sizeof(uint32_t) * r->nh_count, "quagga: parse_ipv4_route_add");
3641 - memcpy(r->nexthops, opt, sizeof(uint32_t) * r->nh_count);
3642 - opt += sizeof(uint32_t) * r->nh_count;
3643 - len -= sizeof(uint32_t) * r->nh_count + 1;
3644 - }
3645 -
3646 - if (r->message & ZAPI_MESSAGE_IFINDEX) {
3647 - if (len < 1)
3648 - return -2;
3649 - r->ind_num = *opt++;
3650 - if (len < sizeof(uint32_t) * r->ind_num)
3651 - return -3;
3652 - r->index = olsr_malloc(sizeof(uint32_t) * r->ind_num, "quagga: parse_ipv4_route_add");
3653 - memcpy(r->index, opt, r->ind_num * sizeof(uint32_t));
3654 - opt += sizeof(uint32_t) * r->ind_num;
3655 - len -= sizeof(uint32_t) * r->ind_num;
3656 - }
3657 -
3658 - if (r->message & ZAPI_MESSAGE_DISTANCE)
3659 - // todo
3660 - ;
3661 -
3662 - if (r->message & ZAPI_MESSAGE_METRIC) {
3663 - if (len < sizeof(uint32_t))
3664 - return -4;
3665 - memcpy(&r->metric, opt, sizeof(uint32_t));
3666 - }
3667 -
3668 - return 0;
3669 -}
3670 -
3671 -static int
3672 -ipv4_route_add(char *opt, size_t len)
3673 -{
3674 -
3675 - struct ipv4_route r;
3676 - int f;
3677 -
3678 - // puts ("DEBUG: ipv4_route_add");
3679 -
3680 - f = parse_ipv4_route(opt, len, &r);
3681 - if (f < 0) {
3682 - printf("parse-error: %d\n", f);
3683 - return f;
3684 - }
3685 -
3686 - add_hna4_route(r);
3687 - return 0;
3688 -}
3689 -
3690 -static int
3691 -ipv4_route_delete(char *opt, size_t len)
3692 -{
3693 - struct ipv4_route r;
3694 - int f;
3695 -
3696 - f = parse_ipv4_route(opt, len, &r);
3697 - if (f < 0)
3698 - return f;
3699 -
3700 - return delete_hna4_route(r);
3701 - // OK, now delete that foo
3702 -
3703 -}
3704 -
3705 -static int
3706 -parse_ipv6_route_add(char *opt, size_t len)
3707 -{
3708 - //todo
3709 - return 0;
3710 -}
3711 -
3712 -/* start redistribution FROM zebra */
3713 -int
3714 -zebra_redistribute(unsigned char type)
3715 -{
3716 -
3717 - return zebra_send_command(ZEBRA_REDISTRIBUTE_ADD, &type, 1);
3718 -
3719 -}
3720 -
3721 -/* end redistribution FROM zebra */
3722 -int
3723 -zebra_disable_redistribute(unsigned char type)
3724 -{
3725 -
3726 - return zebra_send_command(ZEBRA_REDISTRIBUTE_DELETE, &type, 1);
3727 -
3728 -}
3729 -
3730 -static uint32_t
3731 -prefixlentomask(uint8_t prefix)
3732 -{
3733 - uint32_t mask;
3734 - mask = prefix_to_netmask4(prefix);
3735 - mask = ntohl(mask);
3736 - return mask;
3737 -}
3738 -
3739 -int
3740 -add_hna4_route(struct ipv4_route r)
3741 -{
3742 - union olsr_ip_addr net, mask;
3743 -
3744 -#ifdef MY_DEBUG
3745 - dump_ipv4_route(r, "add_hna4_route");
3746 -#endif
3747 -
3748 - mask.v4 = prefixlentomask(r.prefixlen);
3749 - net.v4 = r.prefix;
3750 -
3751 -#ifdef OLSR_PLUGIN
3752 - add_local_hna4_entry(&net, &mask);
3753 -#endif
3754 - free_ipv4_route(r);
3755 - return 0;
3756 -}
3757 -
3758 -int
3759 -delete_hna4_route(struct ipv4_route r)
3760 -{
3761 -
3762 - union olsr_ip_addr net, mask;
3763 -
3764 -#ifdef MY_DEBUG
3765 - dump_ipv4_route(r, "delete_hna4_route");
3766 -#endif
3767 -
3768 - mask.v4 = prefixlentomask(r.prefixlen);
3769 - net.v4 = r.prefix;
3770 -
3771 -#ifdef OLSR_PLUGIN
3772 - return remove_local_hna4_entry(&net, &mask) ? 0 : -1;
3773 -#endif
3774 -
3775 - free_ipv4_route(r);
3776 - return 0;
3777 -
3778 -}
3779 -
3780 -static void
3781 -free_ipv4_route(struct ipv4_route r)
3782 -{
3783 -
3784 - if (r.message & ZAPI_MESSAGE_IFINDEX && r.ind_num)
3785 - free(r.index);
3786 - if (r.message & ZAPI_MESSAGE_NEXTHOP && r.nh_count)
3787 - free(r.nexthops);
3788 -
3789 -}
3790 -
3791 -void
3792 -zebra_clear_routes(void)
3793 -{
3794 -
3795 - struct ipv4_route *t;
3796 -
3797 - t = quagga_routes;
3798 - while (t) {
3799 - zebra_delete_v4_route(*t);
3800 - t = t->next;
3801 - }
3802 - zebra_free_ipv4_route_table(quagga_routes);
3803 -
3804 - quagga_routes = NULL;
3805 -}
3806 -
3807 -void
3808 -zebra_update_hna(void *f)
3809 -{
3810 -
3811 - struct ipv4_route *a = zebra_create_ipv4_route_table();
3812 - update_olsr_zebra_routes(a, quagga_routes);
3813 - zebra_free_ipv4_route_table(quagga_routes);
3814 -
3815 - quagga_routes = a;
3816 -
3817 -}
3818 -
3819 -static struct ipv4_route *
3820 -zebra_create_ipv4_route_table(void)
3821 -{
3822 -
3823 - struct ipv4_route *r = 0, *t = 0 /* make compiler happy */ ;
3824 - int i;
3825 - struct hna_entry *e;
3826 - struct hna_net *n;
3827 -
3828 - for (i = 0; i < HASHSIZE; i++) {
3829 - e = hna_set[i].next;
3830 - for (; e != &hna_set[i]; e = e->next) {
3831 - n = e->networks.next;
3832 - for (; n != &e->networks; n = n->next) {
3833 - if (!r) {
3834 - r = zebra_create_ipv4_route_table_entry(n->A_network_addr.v4, n->A_netmask.v4, e->A_gateway_addr.v4);
3835 - t = r;
3836 - } else {
3837 - t->next = zebra_create_ipv4_route_table_entry(n->A_network_addr.v4, n->A_netmask.v4, e->A_gateway_addr.v4);
3838 - t = t->next;
3839 - }
3840 - }
3841 - }
3842 - }
3843 -
3844 - return r;
3845 -
3846 -}
3847 -
3848 -static struct ipv4_route *
3849 -zebra_create_ipv4_route_table_entry(uint32_t addr, uint32_t mask, uint32_t gw)
3850 -{
3851 -
3852 - struct ipv4_route *r;
3853 -
3854 - r = olsr_malloc(sizeof *r, "zebra_create_ipv4_route_table_entry");
3855 - memset(r, 0, sizeof *r);
3856 - r->prefix = addr;
3857 - r->prefixlen = masktoprefixlen(mask);
3858 - r->message |= ZAPI_MESSAGE_NEXTHOP;
3859 - r->nh_count = 1;
3860 - r->nexthops = olsr_malloc(sizeof(uint32_t), "zebra_create_ipv4_route_table_entry");
3861 - *r->nexthops = gw;
3862 - r->next = NULL;
3863 -
3864 - return r;
3865 -}
3866 -
3867 -static uint8_t
3868 -masktoprefixlen(uint32_t mask)
3869 -{
3870 -
3871 - uint8_t prefixlen = 0;
3872 -while (mask & (1 << ++prefixlen && prefixlen < 32); return prefixlen;}
3873 -
3874 - static void update_olsr_zebra_routes(struct ipv4_route *a, struct ipv4_route *r) {
3875 -
3876 - struct ipv4_route * t; if (!r) {
3877 - puts("no quagga_routing_table aviable"); for (; a; a = a->next) {
3878 - dump_ipv4_route(*a, "adding this route");
3879 - // zebra_add_v4_route(*r);
3880 - }
3881 - return;}
3882 -
3883 - while (a) {
3884 - for (t = r; t; t = t->next) {
3885 - if (a->prefix == t->prefix) if (a->prefixlen == t->prefixlen) if (*a->nexthops == *t->nexthops) {
3886 - goto foo;}
3887 - }
3888 - dump_ipv4_route(*a, "adding this route");
3889 - //zebra_add_v4_route(*a);
3890 - foo:
3891 - a = a->next;}
3892 -
3893 - while (r) {
3894 - for (t = a; t; t = t->next) {
3895 - if (r->prefix == t->prefix) if (r->prefixlen == t->prefixlen) if (*r->nexthops == *t->nexthops) {
3896 - goto bar;}
3897 - }
3898 - dump_ipv4_route(*r, "deleting this route");
3899 - //zebra_delete_v4_route(*r);
3900 - bar:
3901 - r = r->next;}
3902 -
3903 - }
3904 -
3905 - static void zebra_free_ipv4_route_table(struct ipv4_route *r) {
3906 - struct ipv4_route * n; if (!r) return; while ((n = r->next)) {
3907 - if (r->message & ZAPI_MESSAGE_NEXTHOP) free(r->nexthops); if (r->message & ZAPI_MESSAGE_IFINDEX) free(r->index); free(r);
3908 - r = n;}
3909 - }
3910 -
3911 -/*
3912 - * Local Variables:
3913 - * c-basic-offset: 2
3914 - * indent-tabs-mode: nil
3915 - * End:
3916 - */