1 diff -Naur olsrd-0.5.6-r5/lib/quagga/Makefile olsrd-0.5.6-r5.patched/lib/quagga/Makefile
2 --- olsrd-0.5.6-r5/lib/quagga/Makefile 2009-06-24 20:00:51.000000000 +0300
3 +++ olsrd-0.5.6-r5.patched/lib/quagga/Makefile 2009-07-04 16:38:27.000000000 +0300
5 PLUGIN_NAME = olsrd_quagga
10 include $(TOPDIR)/Makefile.inc
12 -#CPPFLAGS +=-DMY_DEBUG
14 CPPFLAGS +=-DUSE_UNIX_DOMAIN_SOCKET
16 -#uncomment the following line only if you are sure what you're doing, it will
17 -#probably break things!
18 -# CPPFLAGS +=-DZEBRA_HEADER_MARKER=255
22 default_target install clean:
23 - @echo "**** Quagga not supportet on Windows (so it would be pointless to build the Quagga Plugin)"
24 + @echo "*** Quagga not supported on Windows (so it would be pointless to build the Quagga plugin)"
28 default_target: $(PLUGIN_FULLNAME)
30 $(PLUGIN_FULLNAME): $(OBJS) version-script.txt
34 rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
37 diff -Naur olsrd-0.5.6-r5/lib/quagga/patches/quagga-0.98.6.diff olsrd-0.5.6-r5.patched/lib/quagga/patches/quagga-0.98.6.diff
38 --- olsrd-0.5.6-r5/lib/quagga/patches/quagga-0.98.6.diff 1970-01-01 02:00:00.000000000 +0200
39 +++ olsrd-0.5.6-r5.patched/lib/quagga/patches/quagga-0.98.6.diff 2009-07-04 16:38:26.000000000 +0300
41 +diff -Nur quagga-0.98.6/bgpd/bgp_vty.c quagga-0.98.6.patched/bgpd/bgp_vty.c
42 +--- quagga-0.98.6/bgpd/bgp_vty.c 2006-03-30 18:12:25.000000000 +0200
43 ++++ quagga-0.98.6.patched/bgpd/bgp_vty.c 2007-12-30 14:18:22.000000000 +0200
46 + This file is part of GNU Zebra.
48 ++This file was modified from the original on 30/12/2007
49 ++by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
51 + GNU Zebra is free software; you can redistribute it and/or modify it
52 + under the terms of the GNU General Public License as published by the
53 + Free Software Foundation; either version 2, or (at your option) any
54 +@@ -7793,8 +7796,12 @@
55 + return ZEBRA_ROUTE_STATIC;
56 + else if (strncmp (str, "r", 1) == 0)
57 + return ZEBRA_ROUTE_RIP;
58 +- else if (strncmp (str, "o", 1) == 0)
59 ++ else if (strncmp (str, "ol", 2) == 0)
60 ++ return ZEBRA_ROUTE_OLSR;
61 ++ else if (strncmp (str, "os", 2) == 0)
62 + return ZEBRA_ROUTE_OSPF;
63 ++ else if (strncmp (str, "ba", 2) == 0)
64 ++ return ZEBRA_ROUTE_BATMAN;
68 +@@ -7806,21 +7813,28 @@
69 + return ZEBRA_ROUTE_STATIC;
70 + else if (strncmp (str, "r", 1) == 0)
71 + return ZEBRA_ROUTE_RIPNG;
72 +- else if (strncmp (str, "o", 1) == 0)
73 ++ else if (strncmp (str, "os", 2) == 0)
74 + return ZEBRA_ROUTE_OSPF6;
75 ++ else if (strncmp (str, "ol", 2) == 0)
76 ++ return ZEBRA_ROUTE_OLSR;
77 ++ else if (strncmp (str, "ba", 2) == 0)
78 ++ return ZEBRA_ROUTE_BATMAN;
83 + DEFUN (bgp_redistribute_ipv4,
84 + bgp_redistribute_ipv4_cmd,
85 +- "redistribute (connected|kernel|ospf|rip|static)",
86 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman)",
87 + "Redistribute information from another routing protocol\n"
90 + "Open Shurtest Path First (OSPF)\n"
91 + "Routing Information Protocol (RIP)\n"
94 ++ "Optimized Link State Routing (OLSR)\n"
95 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
100 +@@ -7835,13 +7849,15 @@
102 + DEFUN (bgp_redistribute_ipv4_rmap,
103 + bgp_redistribute_ipv4_rmap_cmd,
104 +- "redistribute (connected|kernel|ospf|rip|static) route-map WORD",
105 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD",
106 + "Redistribute information from another routing protocol\n"
109 + "Open Shurtest Path First (OSPF)\n"
110 + "Routing Information Protocol (RIP)\n"
112 ++ "Optimized Link State Routing (OLSR)\n"
113 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
114 + "Route map reference\n"
115 + "Pointer to route-map entries\n")
117 +@@ -7860,13 +7876,15 @@
119 + DEFUN (bgp_redistribute_ipv4_metric,
120 + bgp_redistribute_ipv4_metric_cmd,
121 +- "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
122 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295>",
123 + "Redistribute information from another routing protocol\n"
126 + "Open Shurtest Path First (OSPF)\n"
127 + "Routing Information Protocol (RIP)\n"
129 ++ "Optimized Link State Routing (OLSR)\n"
130 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
131 + "Metric for redistributed routes\n"
132 + "Default metric\n")
134 +@@ -7887,13 +7905,15 @@
136 + DEFUN (bgp_redistribute_ipv4_rmap_metric,
137 + bgp_redistribute_ipv4_rmap_metric_cmd,
138 +- "redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
139 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD metric <0-4294967295>",
140 + "Redistribute information from another routing protocol\n"
143 + "Open Shurtest Path First (OSPF)\n"
144 + "Routing Information Protocol (RIP)\n"
146 ++ "Optimized Link State Routing (OLSR)\n"
147 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
148 + "Route map reference\n"
149 + "Pointer to route-map entries\n"
150 + "Metric for redistributed routes\n"
151 +@@ -7917,13 +7937,15 @@
153 + DEFUN (bgp_redistribute_ipv4_metric_rmap,
154 + bgp_redistribute_ipv4_metric_rmap_cmd,
155 +- "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
156 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295> route-map WORD",
157 + "Redistribute information from another routing protocol\n"
160 + "Open Shurtest Path First (OSPF)\n"
161 + "Routing Information Protocol (RIP)\n"
163 ++ "Optimized Link State Routing (OLSR)\n"
164 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
165 + "Metric for redistributed routes\n"
167 + "Route map reference\n"
168 +@@ -7947,14 +7969,17 @@
170 + DEFUN (no_bgp_redistribute_ipv4,
171 + no_bgp_redistribute_ipv4_cmd,
172 +- "no redistribute (connected|kernel|ospf|rip|static)",
173 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman)",
175 + "Redistribute information from another routing protocol\n"
178 + "Open Shurtest Path First (OSPF)\n"
179 + "Routing Information Protocol (RIP)\n"
180 +- "Static routes\n")
182 ++ "Optimized Link State Routing (OLSR)\n"
183 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
188 +@@ -7970,7 +7995,7 @@
190 + DEFUN (no_bgp_redistribute_ipv4_rmap,
191 + no_bgp_redistribute_ipv4_rmap_cmd,
192 +- "no redistribute (connected|kernel|ospf|rip|static) route-map WORD",
193 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD",
195 + "Redistribute information from another routing protocol\n"
197 +@@ -7978,6 +8003,8 @@
198 + "Open Shurtest Path First (OSPF)\n"
199 + "Routing Information Protocol (RIP)\n"
201 ++ "Optimized Link State Routing (OLSR)\n"
202 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
203 + "Route map reference\n"
204 + "Pointer to route-map entries\n")
206 +@@ -7996,7 +8023,7 @@
208 + DEFUN (no_bgp_redistribute_ipv4_metric,
209 + no_bgp_redistribute_ipv4_metric_cmd,
210 +- "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
211 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295>",
213 + "Redistribute information from another routing protocol\n"
215 +@@ -8004,6 +8031,8 @@
216 + "Open Shurtest Path First (OSPF)\n"
217 + "Routing Information Protocol (RIP)\n"
219 ++ "Optimized Link State Routing (OLSR)\n"
220 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
221 + "Metric for redistributed routes\n"
222 + "Default metric\n")
224 +@@ -8022,7 +8051,7 @@
226 + DEFUN (no_bgp_redistribute_ipv4_rmap_metric,
227 + no_bgp_redistribute_ipv4_rmap_metric_cmd,
228 +- "no redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
229 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD metric <0-4294967295>",
231 + "Redistribute information from another routing protocol\n"
233 +@@ -8030,6 +8059,8 @@
234 + "Open Shurtest Path First (OSPF)\n"
235 + "Routing Information Protocol (RIP)\n"
237 ++ "Optimized Link State Routing (OLSR)\n"
238 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
239 + "Route map reference\n"
240 + "Pointer to route-map entries\n"
241 + "Metric for redistributed routes\n"
242 +@@ -8051,7 +8082,7 @@
244 + ALIAS (no_bgp_redistribute_ipv4_rmap_metric,
245 + no_bgp_redistribute_ipv4_metric_rmap_cmd,
246 +- "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
247 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295> route-map WORD",
249 + "Redistribute information from another routing protocol\n"
251 +@@ -8059,6 +8090,8 @@
252 + "Open Shurtest Path First (OSPF)\n"
253 + "Routing Information Protocol (RIP)\n"
255 ++ "Optimized Link State Routing (OLSR)\n"
256 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
257 + "Metric for redistributed routes\n"
259 + "Route map reference\n"
260 +@@ -8067,13 +8100,16 @@
262 + DEFUN (bgp_redistribute_ipv6,
263 + bgp_redistribute_ipv6_cmd,
264 +- "redistribute (connected|kernel|ospf6|ripng|static)",
265 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman)",
266 + "Redistribute information from another routing protocol\n"
269 + "Open Shurtest Path First (OSPFv3)\n"
270 + "Routing Information Protocol (RIPng)\n"
271 +- "Static routes\n")
273 ++ "Optimized Link State Routing (OLSR)\n"
274 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
279 +@@ -8089,13 +8125,15 @@
281 + DEFUN (bgp_redistribute_ipv6_rmap,
282 + bgp_redistribute_ipv6_rmap_cmd,
283 +- "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
284 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD",
285 + "Redistribute information from another routing protocol\n"
288 + "Open Shurtest Path First (OSPFv3)\n"
289 + "Routing Information Protocol (RIPng)\n"
291 ++ "Optimized Link State Routing (OLSR)\n"
292 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
293 + "Route map reference\n"
294 + "Pointer to route-map entries\n")
296 +@@ -8114,13 +8152,15 @@
298 + DEFUN (bgp_redistribute_ipv6_metric,
299 + bgp_redistribute_ipv6_metric_cmd,
300 +- "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
301 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295>",
302 + "Redistribute information from another routing protocol\n"
305 + "Open Shurtest Path First (OSPFv3)\n"
306 + "Routing Information Protocol (RIPng)\n"
308 ++ "Optimized Link State Routing (OLSR)\n"
309 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
310 + "Metric for redistributed routes\n"
311 + "Default metric\n")
313 +@@ -8141,13 +8181,15 @@
315 + DEFUN (bgp_redistribute_ipv6_rmap_metric,
316 + bgp_redistribute_ipv6_rmap_metric_cmd,
317 +- "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
318 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD metric <0-4294967295>",
319 + "Redistribute information from another routing protocol\n"
322 + "Open Shurtest Path First (OSPFv3)\n"
323 + "Routing Information Protocol (RIPng)\n"
325 ++ "Optimized Link State Routing (OLSR)\n"
326 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
327 + "Route map reference\n"
328 + "Pointer to route-map entries\n"
329 + "Metric for redistributed routes\n"
330 +@@ -8171,13 +8213,15 @@
332 + DEFUN (bgp_redistribute_ipv6_metric_rmap,
333 + bgp_redistribute_ipv6_metric_rmap_cmd,
334 +- "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
335 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295> route-map WORD",
336 + "Redistribute information from another routing protocol\n"
339 + "Open Shurtest Path First (OSPFv3)\n"
340 + "Routing Information Protocol (RIPng)\n"
342 ++ "Optimized Link State Routing (OLSR)\n"
343 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
344 + "Metric for redistributed routes\n"
346 + "Route map reference\n"
347 +@@ -8201,14 +8245,17 @@
349 + DEFUN (no_bgp_redistribute_ipv6,
350 + no_bgp_redistribute_ipv6_cmd,
351 +- "no redistribute (connected|kernel|ospf6|ripng|static)",
352 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman)",
354 + "Redistribute information from another routing protocol\n"
357 + "Open Shurtest Path First (OSPFv3)\n"
358 + "Routing Information Protocol (RIPng)\n"
359 +- "Static routes\n")
361 ++ "Optimized Link State Routing (OLSR)\n"
362 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
367 +@@ -8224,7 +8271,7 @@
369 + DEFUN (no_bgp_redistribute_ipv6_rmap,
370 + no_bgp_redistribute_ipv6_rmap_cmd,
371 +- "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
372 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD",
374 + "Redistribute information from another routing protocol\n"
376 +@@ -8232,6 +8279,8 @@
377 + "Open Shurtest Path First (OSPFv3)\n"
378 + "Routing Information Protocol (RIPng)\n"
380 ++ "Optimized Link State Routing (OLSR)\n"
381 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
382 + "Route map reference\n"
383 + "Pointer to route-map entries\n")
385 +@@ -8250,7 +8299,7 @@
387 + DEFUN (no_bgp_redistribute_ipv6_metric,
388 + no_bgp_redistribute_ipv6_metric_cmd,
389 +- "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
390 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295>",
392 + "Redistribute information from another routing protocol\n"
394 +@@ -8258,6 +8307,8 @@
395 + "Open Shurtest Path First (OSPFv3)\n"
396 + "Routing Information Protocol (RIPng)\n"
398 ++ "Optimized Link State Routing (OLSR)\n"
399 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
400 + "Metric for redistributed routes\n"
401 + "Default metric\n")
403 +@@ -8276,7 +8327,7 @@
405 + DEFUN (no_bgp_redistribute_ipv6_rmap_metric,
406 + no_bgp_redistribute_ipv6_rmap_metric_cmd,
407 +- "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
408 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD metric <0-4294967295>",
410 + "Redistribute information from another routing protocol\n"
412 +@@ -8284,6 +8335,8 @@
413 + "Open Shurtest Path First (OSPFv3)\n"
414 + "Routing Information Protocol (RIPng)\n"
416 ++ "Optimized Link State Routing (OLSR)\n"
417 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
418 + "Route map reference\n"
419 + "Pointer to route-map entries\n"
420 + "Metric for redistributed routes\n"
421 +@@ -8305,7 +8358,7 @@
423 + ALIAS (no_bgp_redistribute_ipv6_rmap_metric,
424 + no_bgp_redistribute_ipv6_metric_rmap_cmd,
425 +- "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
426 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295> route-map WORD",
428 + "Redistribute information from another routing protocol\n"
430 +@@ -8313,6 +8366,8 @@
431 + "Open Shurtest Path First (OSPFv3)\n"
432 + "Routing Information Protocol (RIPng)\n"
434 ++ "Optimized Link State Routing (OLSR)\n"
435 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
436 + "Metric for redistributed routes\n"
438 + "Route map reference\n"
439 +@@ -8325,7 +8380,7 @@
442 + const char *str[] = { "system", "kernel", "connected", "static", "rip",
443 +- "ripng", "ospf", "ospf6", "isis", "bgp"};
444 ++ "ripng", "ospf", "ospf6", "isis", "bgp", "hsls", "olsr", "batman"};
446 + /* Unicast redistribution only. */
447 + if (safi != SAFI_UNICAST)
448 +diff -Nur quagga-0.98.6/lib/zebra.h quagga-0.98.6.patched/lib/zebra.h
449 +--- quagga-0.98.6/lib/zebra.h 2005-06-15 14:54:18.000000000 +0300
450 ++++ quagga-0.98.6.patched/lib/zebra.h 2007-12-30 14:18:22.000000000 +0200
453 + This file is part of GNU Zebra.
455 ++This file was modified from the original on 30/12/2007
456 ++by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
458 + GNU Zebra is free software; you can redistribute it and/or modify it
459 + under the terms of the GNU General Public License as published by the
460 + Free Software Foundation; either version 2, or (at your option) any
462 + #define ZEBRA_ROUTE_ISIS 8
463 + #define ZEBRA_ROUTE_BGP 9
464 + #define ZEBRA_ROUTE_HSLS 10
465 +-#define ZEBRA_ROUTE_MAX 11
466 ++#define ZEBRA_ROUTE_OLSR 11
467 ++#define ZEBRA_ROUTE_BATMAN 12
468 ++#define ZEBRA_ROUTE_MAX 13
470 + /* Zebra's family types. */
471 + #define ZEBRA_FAMILY_IPV4 1
472 +diff -Nur quagga-0.98.6/ospfd/ospf_vty.c quagga-0.98.6.patched/ospfd/ospf_vty.c
473 +--- quagga-0.98.6/ospfd/ospf_vty.c 2006-03-30 17:41:20.000000000 +0200
474 ++++ quagga-0.98.6.patched/ospfd/ospf_vty.c 2007-12-30 14:18:22.000000000 +0200
477 + * This file is part of GNU Zebra.
479 ++ * This file was modified from the original on 30/12/2007
480 ++ * by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
482 + * GNU Zebra is free software; you can redistribute it and/or modify it
483 + * under the terms of the GNU General Public License as published by the
484 + * Free Software Foundation; either version 2, or (at your option) any
485 +@@ -106,11 +109,15 @@
486 + *source = ZEBRA_ROUTE_STATIC;
487 + else if (strncmp (str, "r", 1) == 0)
488 + *source = ZEBRA_ROUTE_RIP;
489 +- else if (strncmp (str, "b", 1) == 0)
490 ++ else if (strncmp (str, "bg", 2) == 0)
491 + *source = ZEBRA_ROUTE_BGP;
492 ++ else if (strncmp (str, "ol", 2) == 0)
493 ++ *source = ZEBRA_ROUTE_OLSR;
494 ++ else if (strncmp (str, "ba", 2) == 0)
495 ++ *source = ZEBRA_ROUTE_BATMAN;
503 +@@ -5302,13 +5309,15 @@
505 + DEFUN (ospf_redistribute_source_metric_type,
506 + ospf_redistribute_source_metric_type_routemap_cmd,
507 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> metric-type (1|2) route-map WORD",
508 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> metric-type (1|2) route-map WORD",
509 + "Redistribute information from another routing protocol\n"
513 + "Routing Information Protocol (RIP)\n"
514 + "Border Gateway Protocol (BGP)\n"
515 ++ "Optimized Link State Routing (OLSR)\n"
516 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
517 + "Metric for redistributed routes\n"
518 + "OSPF default metric\n"
519 + "OSPF exterior metric type for redistributed routes\n"
520 +@@ -5346,13 +5355,15 @@
522 + ALIAS (ospf_redistribute_source_metric_type,
523 + ospf_redistribute_source_metric_type_cmd,
524 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> metric-type (1|2)",
525 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> metric-type (1|2)",
526 + "Redistribute information from another routing protocol\n"
530 + "Routing Information Protocol (RIP)\n"
531 + "Border Gateway Protocol (BGP)\n"
532 ++ "Optimized Link State Routing (OLSR)\n"
533 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
534 + "Metric for redistributed routes\n"
535 + "OSPF default metric\n"
536 + "OSPF exterior metric type for redistributed routes\n"
537 +@@ -5361,25 +5372,29 @@
539 + ALIAS (ospf_redistribute_source_metric_type,
540 + ospf_redistribute_source_metric_cmd,
541 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214>",
542 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214>",
543 + "Redistribute information from another routing protocol\n"
547 + "Routing Information Protocol (RIP)\n"
548 + "Border Gateway Protocol (BGP)\n"
549 ++ "Optimized Link State Routing (OLSR)\n"
550 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
551 + "Metric for redistributed routes\n"
552 + "OSPF default metric\n")
554 + DEFUN (ospf_redistribute_source_type_metric,
555 + ospf_redistribute_source_type_metric_routemap_cmd,
556 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) metric <0-16777214> route-map WORD",
557 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) metric <0-16777214> route-map WORD",
558 + "Redistribute information from another routing protocol\n"
562 + "Routing Information Protocol (RIP)\n"
563 + "Border Gateway Protocol (BGP)\n"
564 ++ "Optimized Link State Routing (OLSR)\n"
565 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
566 + "OSPF exterior metric type for redistributed routes\n"
567 + "Set OSPF External Type 1 metrics\n"
568 + "Set OSPF External Type 2 metrics\n"
569 +@@ -5417,13 +5432,15 @@
571 + ALIAS (ospf_redistribute_source_type_metric,
572 + ospf_redistribute_source_type_metric_cmd,
573 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) metric <0-16777214>",
574 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) metric <0-16777214>",
575 + "Redistribute information from another routing protocol\n"
579 + "Routing Information Protocol (RIP)\n"
580 + "Border Gateway Protocol (BGP)\n"
581 ++ "Optimized Link State Routing (OLSR)\n"
582 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
583 + "OSPF exterior metric type for redistributed routes\n"
584 + "Set OSPF External Type 1 metrics\n"
585 + "Set OSPF External Type 2 metrics\n"
586 +@@ -5432,7 +5449,7 @@
588 + ALIAS (ospf_redistribute_source_type_metric,
589 + ospf_redistribute_source_type_cmd,
590 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2)",
591 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2)",
592 + "Redistribute information from another routing protocol\n"
595 +@@ -5440,28 +5457,35 @@
596 + "Routing Information Protocol (RIP)\n"
597 + "Border Gateway Protocol (BGP)\n"
598 + "OSPF exterior metric type for redistributed routes\n"
599 ++ "Optimized Link State Routing (OLSR)\n"
600 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
601 + "Set OSPF External Type 1 metrics\n"
602 + "Set OSPF External Type 2 metrics\n")
604 + ALIAS (ospf_redistribute_source_type_metric,
605 + ospf_redistribute_source_cmd,
606 +- "redistribute (kernel|connected|static|rip|bgp)",
607 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman)",
608 + "Redistribute information from another routing protocol\n"
612 + "Routing Information Protocol (RIP)\n"
613 +- "Border Gateway Protocol (BGP)\n")
614 ++ "Border Gateway Protocol (BGP)\n"
615 ++ "Optimized Link State Routing (OLSR)\n"
616 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
619 + DEFUN (ospf_redistribute_source_metric_routemap,
620 + ospf_redistribute_source_metric_routemap_cmd,
621 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> route-map WORD",
622 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> route-map WORD",
623 + "Redistribute information from another routing protocol\n"
627 + "Routing Information Protocol (RIP)\n"
628 + "Border Gateway Protocol (BGP)\n"
629 ++ "Optimized Link State Routing (OLSR)\n"
630 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
631 + "Metric for redistributed routes\n"
632 + "OSPF default metric\n"
633 + "Route map reference\n"
634 +@@ -5490,13 +5514,15 @@
636 + DEFUN (ospf_redistribute_source_type_routemap,
637 + ospf_redistribute_source_type_routemap_cmd,
638 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) route-map WORD",
639 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) route-map WORD",
640 + "Redistribute information from another routing protocol\n"
644 + "Routing Information Protocol (RIP)\n"
645 + "Border Gateway Protocol (BGP)\n"
646 ++ "Optimized Link State Routing (OLSR)\n"
647 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
648 + "OSPF exterior metric type for redistributed routes\n"
649 + "Set OSPF External Type 1 metrics\n"
650 + "Set OSPF External Type 2 metrics\n"
651 +@@ -5526,13 +5552,15 @@
653 + DEFUN (ospf_redistribute_source_routemap,
654 + ospf_redistribute_source_routemap_cmd,
655 +- "redistribute (kernel|connected|static|rip|bgp) route-map WORD",
656 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) route-map WORD",
657 + "Redistribute information from another routing protocol\n"
661 + "Routing Information Protocol (RIP)\n"
662 + "Border Gateway Protocol (BGP)\n"
663 ++ "Optimized Link State Routing (OLSR)\n"
664 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
665 + "Route map reference\n"
666 + "Pointer to route-map entries\n")
668 +@@ -5553,14 +5581,17 @@
670 + DEFUN (no_ospf_redistribute_source,
671 + no_ospf_redistribute_source_cmd,
672 +- "no redistribute (kernel|connected|static|rip|bgp)",
673 ++ "no redistribute (kernel|connected|static|rip|bgp|olsr|batman)",
675 + "Redistribute information from another routing protocol\n"
679 + "Routing Information Protocol (RIP)\n"
680 +- "Border Gateway Protocol (BGP)\n")
681 ++ "Border Gateway Protocol (BGP)\n"
682 ++ "Optimized Link State Routing (OLSR)\n"
683 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
686 + struct ospf *ospf = vty->index;
688 +@@ -5574,7 +5605,7 @@
690 + DEFUN (ospf_distribute_list_out,
691 + ospf_distribute_list_out_cmd,
692 +- "distribute-list WORD out (kernel|connected|static|rip|bgp)",
693 ++ "distribute-list WORD out (kernel|connected|static|rip|bgp|olsr|batman)",
694 + "Filter networks in routing updates\n"
695 + "Access-list name\n"
697 +@@ -5582,7 +5613,10 @@
700 + "Routing Information Protocol (RIP)\n"
701 +- "Border Gateway Protocol (BGP)\n")
702 ++ "Border Gateway Protocol (BGP)\n"
703 ++ "Optimized Link State Routing (OLSR)\n"
704 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
707 + struct ospf *ospf = vty->index;
709 +@@ -5596,7 +5630,7 @@
711 + DEFUN (no_ospf_distribute_list_out,
712 + no_ospf_distribute_list_out_cmd,
713 +- "no distribute-list WORD out (kernel|connected|static|rip|bgp)",
714 ++ "no distribute-list WORD out (kernel|connected|static|rip|bgp|olsr|batman)",
716 + "Filter networks in routing updates\n"
717 + "Access-list name\n"
718 +@@ -5605,7 +5639,10 @@
721 + "Routing Information Protocol (RIP)\n"
722 +- "Border Gateway Protocol (BGP)\n")
723 ++ "Border Gateway Protocol (BGP)\n"
724 ++ "Optimized Link State Routing (OLSR)\n"
725 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
728 + struct ospf *ospf = vty->index;
730 +@@ -7121,7 +7158,8 @@
733 + const char *distribute_str[] = { "system", "kernel", "connected", "static",
734 +- "rip", "ripng", "ospf", "ospf6", "isis", "bgp"};
735 ++ "rip", "ripng", "ospf", "ospf6", "isis", "bgp",
736 ++ "hsls","olsr","batman"};
738 + config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf)
740 +diff -Nur quagga-0.98.6/zebra/redistribute.c quagga-0.98.6.patched/zebra/redistribute.c
741 +--- quagga-0.98.6/zebra/redistribute.c 2005-06-15 14:54:51.000000000 +0300
742 ++++ quagga-0.98.6.patched/zebra/redistribute.c 2007-12-30 14:18:22.000000000 +0200
745 + * This file is part of GNU Zebra.
747 ++ * This file was modified from the original on 30/12/2007
748 ++ * by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
750 + * GNU Zebra is free software; you can redistribute it and/or modify it
751 + * under the terms of the GNU General Public License as published by the
752 + * Free Software Foundation; either version 2, or (at your option) any
754 + case ZEBRA_ROUTE_OSPF:
755 + case ZEBRA_ROUTE_OSPF6:
756 + case ZEBRA_ROUTE_BGP:
757 ++ case ZEBRA_ROUTE_OLSR:
758 ++ case ZEBRA_ROUTE_BATMAN:
759 + if (! client->redist[type])
761 + client->redist[type] = 1;
763 + case ZEBRA_ROUTE_OSPF:
764 + case ZEBRA_ROUTE_OSPF6:
765 + case ZEBRA_ROUTE_BGP:
766 ++ case ZEBRA_ROUTE_OLSR:
767 ++ case ZEBRA_ROUTE_BATMAN:
768 + client->redist[type] = 0;
771 +diff -Nur quagga-0.98.6/zebra/zebra_vty.c quagga-0.98.6.patched/zebra/zebra_vty.c
772 +--- quagga-0.98.6/zebra/zebra_vty.c 2004-12-18 18:03:29.000000000 +0200
773 ++++ quagga-0.98.6.patched/zebra/zebra_vty.c 2007-12-30 14:25:48.000000000 +0200
776 + case ZEBRA_ROUTE_BGP:
778 ++ case ZEBRA_ROUTE_OLSR:
780 ++ case ZEBRA_ROUTE_BATMAN:
787 + case ZEBRA_ROUTE_BGP:
789 ++ case ZEBRA_ROUTE_HSLS:
791 ++ case ZEBRA_ROUTE_OLSR:
793 ++ case ZEBRA_ROUTE_BATMAN:
801 + #define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, " \
802 +- "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, " \
803 +- "> - selected route, * - FIB route%s%s"
804 ++ "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, H - HSLS, " \
805 ++ "L - OLSR, M - BATMAN, > - selected route, * - FIB route%s%s"
807 + DEFUN (show_ip_route,
811 + DEFUN (show_ip_route_protocol,
812 + show_ip_route_protocol_cmd,
813 +- "show ip route (bgp|connected|isis|kernel|ospf|rip|static)",
814 ++ "show ip route (bgp|connected|isis|kernel|ospf|rip|olsr|batman|static)",
817 + "IP routing table\n"
820 + "Open Shortest Path First (OSPF)\n"
821 + "Routing Information Protocol (RIP)\n"
822 ++ "Optimized Link State Routing (OLSR)\n"
823 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
827 +@@ -892,13 +904,13 @@
831 +- if (strncmp (argv[0], "b", 1) == 0)
832 ++ if (strncmp (argv[0], "bg", 2) == 0)
833 + type = ZEBRA_ROUTE_BGP;
834 + else if (strncmp (argv[0], "c", 1) == 0)
835 + type = ZEBRA_ROUTE_CONNECT;
836 + else if (strncmp (argv[0], "k", 1) ==0)
837 + type = ZEBRA_ROUTE_KERNEL;
838 +- else if (strncmp (argv[0], "o", 1) == 0)
839 ++ else if (strncmp (argv[0], "os", 2) == 0)
840 + type = ZEBRA_ROUTE_OSPF;
841 + else if (strncmp (argv[0], "i", 1) == 0)
842 + type = ZEBRA_ROUTE_ISIS;
843 +@@ -906,6 +918,10 @@
844 + type = ZEBRA_ROUTE_RIP;
845 + else if (strncmp (argv[0], "s", 1) == 0)
846 + type = ZEBRA_ROUTE_STATIC;
847 ++ else if (strncmp (argv[0], "ol", 2) == 0)
848 ++ type = ZEBRA_ROUTE_OLSR;
849 ++ else if (strncmp (argv[0], "ba", 2) == 0)
850 ++ type = ZEBRA_ROUTE_BATMAN;
853 + vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
854 +@@ -1732,7 +1748,7 @@
856 + DEFUN (show_ipv6_route_protocol,
857 + show_ipv6_route_protocol_cmd,
858 +- "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|static)",
859 ++ "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|olsr|batman|static)",
862 + "IP routing table\n"
863 +@@ -1742,6 +1758,8 @@
865 + "Open Shortest Path First (OSPFv3)\n"
866 + "Routing Information Protocol (RIPng)\n"
867 ++ "Optimized Link State Routing (OLSR)\n"
868 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
872 +@@ -1750,13 +1768,13 @@
876 +- if (strncmp (argv[0], "b", 1) == 0)
877 ++ if (strncmp (argv[0], "bg", 2) == 0)
878 + type = ZEBRA_ROUTE_BGP;
879 + else if (strncmp (argv[0], "c", 1) == 0)
880 + type = ZEBRA_ROUTE_CONNECT;
881 + else if (strncmp (argv[0], "k", 1) ==0)
882 + type = ZEBRA_ROUTE_KERNEL;
883 +- else if (strncmp (argv[0], "o", 1) == 0)
884 ++ else if (strncmp (argv[0], "os", 2) == 0)
885 + type = ZEBRA_ROUTE_OSPF6;
886 + else if (strncmp (argv[0], "i", 1) == 0)
887 + type = ZEBRA_ROUTE_ISIS;
888 +@@ -1764,7 +1782,11 @@
889 + type = ZEBRA_ROUTE_RIPNG;
890 + else if (strncmp (argv[0], "s", 1) == 0)
891 + type = ZEBRA_ROUTE_STATIC;
893 ++ else if (strncmp (argv[0], "ol", 2) == 0)
894 ++ type = ZEBRA_ROUTE_OLSR;
895 ++ else if (strncmp (argv[0], "ba", 2) == 0)
896 ++ type = ZEBRA_ROUTE_BATMAN;
899 + vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
900 + return CMD_WARNING;
901 diff -Naur olsrd-0.5.6-r5/lib/quagga/README_QUAGGA olsrd-0.5.6-r5.patched/lib/quagga/README_QUAGGA
902 --- olsrd-0.5.6-r5/lib/quagga/README_QUAGGA 2009-06-24 20:00:41.000000000 +0300
903 +++ olsrd-0.5.6-r5.patched/lib/quagga/README_QUAGGA 2009-07-04 16:38:26.000000000 +0300
905 ---------------------------------------------------------------------
906 QUAGGA PLUGIN FOR OLSRD
907 by Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
909 +addittions by: Sven-Ola Tuecke <sven-ola-aet-gmx.de>
910 + Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
911 ---------------------------------------------------------------------
913 -This is the Quagga Plugin for the OLSRD.
914 -It allowes olsrd to redistribute from various quagga-protocols
915 +This is the Quagga Plugin for OLSRd.
916 +It allows olsrd to redistribute from various quagga-protocols
917 as well as to export olsr-routes to quagga so that they can be
918 redistributed by the quagga-routing-daemons.
920 -Note Sven-Ola: You also need a source distribution of quagga-0.98.5
921 -or quagga-0.98.6 (that is the current stable). The quagga source tree
922 -needs to be patched with quagga-0.98.6-olsr.diff, compiled and installed
923 -via 'make install'. Because many people will otherwise have compile
924 -probs, I've added 2 include files in lib/quagga/src/quagga. If you
925 -want to use another version of quagga, make sure to remove these
926 -before you compile the olsrd_quagga plugin.
927 +You also need a source distribution of quagga-0.98.5 or quagga-0.98.6
928 +(that is the current stable). The quagga source tree needs to be
929 +patched with quagga-0.98.6.diff, compiled and installed via
932 ---------------------------------------------------------------------
933 PLUGIN PARAMETERS (PlParam)
935 May be used more then once
937 PlParam "ExportRoutes" "<only/both>"
938 - exportes olsr-routes to quagga or to both, quagga and kernel
939 + exports olsr-routes to quagga or to both, quagga and kernel
940 no routes are exported to quagga (normal behaviour) if not set.
942 -PlParam "LocalPref" "true"
943 +PlParam "LocalPref" "<true/false>"
944 sets the Zebra SELECTED-flag on the routes exported to zebra
945 which means these routes are prefered in any case.
947 PlParam "Distance" "0-255"
948 - allowes to set the administrative distance to routes exported
950 + allows to set the administrative distance to routes exported
953 ---------------------------------------------------------------------
955 ---------------------------------------------------------------------
957 -add in /etc/olsrd.conf:
958 +add in /usr/local/etc/olsrd.conf:
960 LoadPlugin "olsrd_quagga.so.0.2.2"
965 ---------------------------------------------------------------------
968 diff -Naur olsrd-0.5.6-r5/lib/quagga/src/olsrd_plugin.c olsrd-0.5.6-r5.patched/lib/quagga/src/olsrd_plugin.c
969 --- olsrd-0.5.6-r5/lib/quagga/src/olsrd_plugin.c 2009-06-24 20:00:51.000000000 +0300
970 +++ olsrd-0.5.6-r5.patched/lib/quagga/src/olsrd_plugin.c 2009-07-04 16:38:26.000000000 +0300
973 + * OLSRd Quagga plugin
975 + * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
976 + * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
978 + * This program is free software; you can redistribute it and/or modify
979 + * it under the terms of the GNU General Public License version 2 as
980 + * published by the Free Software Foundation or - at your option - under
981 + * the terms of the GNU General Public Licence version 2 but can be
982 + * linked to any BSD-Licenced Software with public available sourcecode
986 +/* -------------------------------------------------------------------------
987 + * File : olsrd_plugin.c
988 + * Description : functions to setup plugin
989 + * ------------------------------------------------------------------------- */
991 -/***************************************************************************
992 - projekt : olsrd-quagga
993 - file : olsrd_plugin.c
994 - usage : olsrd-plugin-handler-stuff
995 - copyright : (C) 2006 by Immo 'FaUl' Wehrenberg
996 - e-mail : immo@chaostreff-dortmund.de
997 - ***************************************************************************/
999 -/***************************************************************************
1001 - * This program is free software; you can redistribute it and/or modify *
1002 - * it under the terms of the GNU General Public License version 2 as *
1003 - * published by the Free Software Foundation. *
1005 - ***************************************************************************/
1010 #include "scheduler.h"
1013 -#include "kernel_routes.h"
1014 #include "net_olsr.h"
1016 #define PLUGIN_NAME "OLSRD quagga plugin"
1017 @@ -41,120 +43,94 @@
1018 static set_plugin_parameter set_distance;
1019 static set_plugin_parameter set_localpref;
1021 -static export_route_function orig_addroute_function;
1022 -static export_route_function orig_delroute_function;
1025 -olsrd_plugin_interface_version(void)
1027 +int olsrd_plugin_interface_version (void) {
1028 return PLUGIN_INTERFACE_VERSION;
1031 static const struct olsrd_plugin_parameters plugin_parameters[] = {
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 + { .name = "redistribute", .set_plugin_parameter = &set_redistribute, },
1037 + { .name = "ExportRoutes", .set_plugin_parameter = &set_exportroutes, },
1038 + { .name = "Distance", .set_plugin_parameter = &set_distance, },
1039 + { .name = "LocalPref", .set_plugin_parameter = &set_localpref, },
1043 -olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
1045 +void olsrd_get_plugin_parameters (const struct olsrd_plugin_parameters **params,
1047 *params = plugin_parameters;
1048 - *size = sizeof plugin_parameters / sizeof *plugin_parameters;
1049 + *size = ARRAYSIZE(plugin_parameters);
1053 -set_redistribute(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1055 - const char *zebra_route_types[] = { "system", "kernel", "connect",
1056 - "static", "rip", "ripng", "ospf",
1057 - "ospf6", "isis", "bgp", "hsls"
1059 +static int set_redistribute (const char *value,
1060 + void *data __attribute__((unused)),
1061 + set_plugin_parameter_addon addon __attribute__((unused))) {
1062 + const char *zebra_route_types[] = {"system","kernel","connect",
1063 + "static","rip","ripng","ospf",
1064 + "ospf6","isis","bgp","hsls"};
1067 for (i = 0; i < ARRAYSIZE(zebra_route_types); i++) {
1068 - if (!strcmp(value, zebra_route_types[i])) {
1069 - zebra_redistribute(i);
1072 + if (!strcmp(value, zebra_route_types[i]))
1073 + if (zebra_redistribute (i)) return 1;
1081 -set_exportroutes(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1083 +static int set_exportroutes (const char *value,
1084 + void *data __attribute__((unused)),
1085 + set_plugin_parameter_addon addon __attribute__((unused))) {
1086 if (!strcmp(value, "only")) {
1087 - orig_addroute_function = NULL;
1088 - orig_delroute_function = NULL;
1089 - olsr_addroute_function = zebra_add_olsr_v4_route;
1090 - olsr_delroute_function = zebra_del_olsr_v4_route;
1091 + olsr_addroute_function = zebra_add_route;
1092 + olsr_delroute_function = zebra_del_route;
1093 zebra_export_routes(1);
1094 - } else if (!strcmp(value, "additional")) {
1095 - orig_addroute_function = olsr_addroute_function;
1096 - orig_delroute_function = olsr_delroute_function;
1097 - olsr_addroute_function = zebra_add_olsr_v4_route;
1098 - olsr_delroute_function = zebra_del_olsr_v4_route;
1100 + else if (!strcmp(value, "additional")) {
1101 + olsr_addroute_function = zebra_add_route;
1102 + olsr_delroute_function = zebra_del_route;
1103 zebra_export_routes(1);
1105 - zebra_export_routes(0);
1107 + else zebra_export_routes(0);
1112 -set_distance(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1114 +static int set_distance(const char *value, void *data __attribute__((unused)),
1115 + set_plugin_parameter_addon addon __attribute__((unused))) {
1118 - if (set_plugin_int(value, &distance, addon))
1120 - if (distance < 0 || distance > 255)
1122 + if (set_plugin_int(value, &distance, addon)) return 1;
1123 + if (distance < 0 || distance > 255) return 1;
1124 zebra_olsr_distance(distance);
1129 -set_localpref(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1131 +static int set_localpref(const char *value, void *data __attribute__((unused)),
1132 + set_plugin_parameter_addon addon __attribute__((unused))) {
1135 - if (set_plugin_boolean(value, &b, addon))
1138 - zebra_olsr_localpref();
1139 + if (set_plugin_boolean(value, &b, addon)) return 1;
1140 + if (b) zebra_olsr_localpref();
1145 -olsrd_plugin_init(void)
1147 - if (olsr_cnf->ip_version != AF_INET) {
1148 - fputs("see the source - ipv6 so far not supported\n", stderr);
1150 +int olsrd_plugin_init(void) {
1151 + if(olsr_cnf->ip_version != AF_INET) {
1152 + fputs("see the source - ipv6 so far not supported\n" ,stderr);
1156 - olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &zebra_check, NULL, 0);
1157 + olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC,
1158 + &zebra_parse, NULL, 0);
1166 +static void my_init(void) {
1173 +static void my_fini(void) {
1178 - * Local Variables:
1179 - * c-basic-offset: 2
1180 - * indent-tabs-mode: nil
1183 diff -Naur olsrd-0.5.6-r5/lib/quagga/src/quagga/zassert.h olsrd-0.5.6-r5.patched/lib/quagga/src/quagga/zassert.h
1184 --- olsrd-0.5.6-r5/lib/quagga/src/quagga/zassert.h 2009-06-24 20:00:51.000000000 +0300
1185 +++ olsrd-0.5.6-r5.patched/lib/quagga/src/quagga/zassert.h 1970-01-01 02:00:00.000000000 +0200
1191 -#ifndef _QUAGGA_ASSERT_H
1192 -#define _QUAGGA_ASSERT_H
1194 -extern void _zlog_assert_failed(const char *assertion, const char *file, unsigned int line, const char *function)
1195 - __attribute__ ((noreturn));
1197 -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
1198 -#define __ASSERT_FUNCTION __func__
1199 -#elif defined(__GNUC__)
1200 -#define __ASSERT_FUNCTION __FUNCTION__
1202 -#define __ASSERT_FUNCTION NULL
1205 -#define zassert(EX) ((void)((EX) ? 0 : \
1206 - (_zlog_assert_failed(#EX, __FILE__, __LINE__, \
1207 - __ASSERT_FUNCTION), 0)))
1210 -#define assert(EX) zassert(EX)
1212 -#endif /* _QUAGGA_ASSERT_H */
1215 - * Local Variables:
1216 - * c-basic-offset: 2
1217 - * indent-tabs-mode: nil
1220 diff -Naur olsrd-0.5.6-r5/lib/quagga/src/quagga/zebra.h olsrd-0.5.6-r5.patched/lib/quagga/src/quagga/zebra.h
1221 --- olsrd-0.5.6-r5/lib/quagga/src/quagga/zebra.h 2009-06-24 20:00:51.000000000 +0300
1222 +++ olsrd-0.5.6-r5.patched/lib/quagga/src/quagga/zebra.h 1970-01-01 02:00:00.000000000 +0200
1225 -/* Zebra common header.
1226 - Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
1228 -This file is part of GNU Zebra.
1230 -GNU Zebra is free software; you can redistribute it and/or modify it
1231 -under the terms of the GNU General Public License as published by the
1232 -Free Software Foundation; either version 2, or (at your option) any
1235 -GNU Zebra is distributed in the hope that it will be useful, but
1236 -WITHOUT ANY WARRANTY; without even the implied warranty of
1237 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1238 -General Public License for more details.
1240 -You should have received a copy of the GNU General Public License
1241 -along with GNU Zebra; see the file COPYING. If not, write to the Free
1242 -Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1243 -02111-1307, USA. */
1248 -#ifdef HAVE_CONFIG_H
1249 -#include "config.h"
1250 -#endif /* HAVE_CONFIG_H */
1254 -#define __EXTENSIONS__
1255 -typedef unsigned int u_int32_t;
1256 -typedef unsigned short u_int16_t;
1257 -typedef unsigned char u_int8_t;
1258 -#endif /* SUNOS_5 */
1260 -#ifndef HAVE_SOCKLEN_T
1261 -typedef int socklen_t;
1262 -#endif /* HAVE_SOCKLEN_T */
1264 -#include <unistd.h>
1266 -#include <stdlib.h>
1270 -#include <signal.h>
1271 -#include <string.h>
1274 -#ifdef HAVE_STROPTS_H
1275 -#include <stropts.h>
1276 -#endif /* HAVE_STROPTS_H */
1277 -#include <sys/fcntl.h>
1278 -#ifdef HAVE_SYS_SELECT_H
1279 -#include <sys/select.h>
1280 -#endif /* HAVE_SYS_SELECT_H */
1281 -#include <sys/stat.h>
1282 -#include <sys/time.h>
1283 -#include <sys/types.h>
1284 -#include <sys/param.h>
1285 -#ifdef HAVE_SYS_SYSCTL_H
1286 -#include <sys/sysctl.h>
1287 -#endif /* HAVE_SYS_SYSCTL_H */
1288 -#include <sys/ioctl.h>
1289 -#ifdef HAVE_SYS_CONF_H
1290 -#include <sys/conf.h>
1291 -#endif /* HAVE_SYS_CONF_H */
1292 -#ifdef HAVE_SYS_KSYM_H
1293 -#include <sys/ksym.h>
1294 -#endif /* HAVE_SYS_KSYM_H */
1295 -#include <syslog.h>
1297 -#include <sys/uio.h>
1298 -#include <sys/utsname.h>
1300 -#include <sys/resource.h>
1301 -#endif /* HAVE_RUSAGE */
1302 -#ifdef HAVE_LIMITS_H
1303 -#include <limits.h>
1304 -#endif /* HAVE_LIMITS_H */
1306 -/* machine dependent includes */
1308 -#include <strings.h>
1309 -#endif /* SUNOS_5 */
1311 -/* machine dependent includes */
1312 -#ifdef HAVE_LINUX_VERSION_H
1313 -#include <linux/version.h>
1314 -#endif /* HAVE_LINUX_VERSION_H */
1316 -#ifdef HAVE_ASM_TYPES_H
1317 -#include <asm/types.h>
1318 -#endif /* HAVE_ASM_TYPES_H */
1320 -/* misc include group */
1321 -#include <stdarg.h>
1322 -#if !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
1324 -/* Not C99; do we need to define va_copy? */
1327 -#define va_copy(DST,SRC) __va_copy(DST,SRC)
1330 -/* Now we are desperate; this should work on many typical platforms.
1331 - But this is slightly dangerous, because the standard does not require
1332 - va_copy to be a macro. */
1333 -#define va_copy(DST,SRC) memcpy(&(DST), &(SRC), sizeof(va_list))
1334 -#warning "Not C99 and no va_copy macro available, falling back to memcpy"
1335 -#endif /* __va_copy */
1336 -#endif /* !va_copy */
1340 -#include <sys/capability.h>
1341 -#include <sys/prctl.h>
1342 -#endif /* HAVE_LCAPS */
1344 -/* network include group */
1346 -#include <sys/socket.h>
1348 -#ifdef HAVE_SYS_SOCKIO_H
1349 -#include <sys/sockio.h>
1350 -#endif /* HAVE_SYS_SOCKIO_H */
1352 -#ifdef HAVE_NETINET_IN_H
1353 -#include <netinet/in.h>
1354 -#endif /* HAVE_NETINET_IN_H */
1355 -#include <netinet/in_systm.h>
1356 -#include <netinet/ip.h>
1357 -#include <netinet/tcp.h>
1359 -#ifdef HAVE_NET_NETOPT_H
1360 -#include <net/netopt.h>
1361 -#endif /* HAVE_NET_NETOPT_H */
1363 -#include <net/if.h>
1365 -#ifdef HAVE_NET_IF_DL_H
1366 -#include <net/if_dl.h>
1367 -#endif /* HAVE_NET_IF_DL_H */
1369 -#ifdef HAVE_NET_IF_VAR_H
1370 -#include <net/if_var.h>
1371 -#endif /* HAVE_NET_IF_VAR_H */
1373 -#ifdef HAVE_NET_ROUTE_H
1374 -#include <net/route.h>
1375 -#endif /* HAVE_NET_ROUTE_H */
1377 -#ifdef HAVE_NETLINK
1378 -#include <linux/netlink.h>
1379 -#include <linux/rtnetlink.h>
1381 -#define RT_TABLE_MAIN 0
1382 -#endif /* HAVE_NETLINK */
1384 -#ifdef HAVE_NETDB_H
1386 -#endif /* HAVE_NETDB_H */
1388 -#include <arpa/inet.h>
1389 -#include <arpa/telnet.h>
1391 -#ifdef HAVE_INET_ND_H
1392 -#include <inet/nd.h>
1393 -#endif /* HAVE_INET_ND_H */
1395 -#ifdef HAVE_NETINET_IN_VAR_H
1396 -#include <netinet/in_var.h>
1397 -#endif /* HAVE_NETINET_IN_VAR_H */
1399 -#ifdef HAVE_NETINET6_IN6_VAR_H
1400 -#include <netinet6/in6_var.h>
1401 -#endif /* HAVE_NETINET6_IN6_VAR_H */
1403 -#ifdef HAVE_NETINET_IN6_VAR_H
1404 -#include <netinet/in6_var.h>
1405 -#endif /* HAVE_NETINET_IN6_VAR_H */
1407 -#ifdef HAVE_NETINET6_IN_H
1408 -#include <netinet6/in.h>
1409 -#endif /* HAVE_NETINET6_IN_H */
1411 -#ifdef HAVE_NETINET6_IP6_H
1412 -#include <netinet6/ip6.h>
1413 -#endif /* HAVE_NETINET6_IP6_H */
1415 -#ifdef HAVE_NETINET_ICMP6_H
1416 -#include <netinet/icmp6.h>
1417 -#endif /* HAVE_NETINET_ICMP6_H */
1419 -#ifdef HAVE_NETINET6_ND6_H
1420 -#include <netinet6/nd6.h>
1421 -#endif /* HAVE_NETINET6_ND6_H */
1423 -/* Some systems do not define UINT32_MAX */
1425 -#define UINT32_MAX 0xFFFFFFFFU
1426 -#endif /* UINT32_MAX */
1428 -#ifdef HAVE_LIBUTIL_H
1429 -#include <libutil.h>
1430 -#endif /* HAVE_LIBUTIL_H */
1432 -#ifdef HAVE_GLIBC_BACKTRACE
1433 -#include <execinfo.h>
1434 -#endif /* HAVE_GLIBC_BACKTRACE */
1438 -#ifdef HAVE_NETINET6_IN6_H
1439 -#include <netinet6/in6.h>
1440 -#endif /* HAVE_NETINET6_IN6_H */
1443 -#include <netinet6/in6.h>
1446 -#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
1448 -#endif /* BSDI_NRL */
1450 -/* Local includes: */
1451 -#if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
1452 -#define __attribute__(x)
1453 -#endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
1455 -#include "zassert.h"
1457 -#ifdef HAVE_BROKEN_CMSG_FIRSTHDR
1459 -/* This bug is present in Solaris 8 and pre-patch Solaris 9 <sys/socket.h>;
1460 - please refer to http://bugzilla.quagga.net/show_bug.cgi?id=142 */
1462 -/* Check that msg_controllen is large enough. */
1463 -#define ZCMSG_FIRSTHDR(mhdr) \
1464 - (((size_t)((mhdr)->msg_controllen) >= sizeof(struct cmsghdr)) ? \
1465 - CMSG_FIRSTHDR(mhdr) : (struct cmsghdr *)NULL)
1467 -#warning "CMSG_FIRSTHDR is broken on this platform, using a workaround"
1469 -#else /* HAVE_BROKEN_CMSG_FIRSTHDR */
1470 -#define ZCMSG_FIRSTHDR(M) CMSG_FIRSTHDR(M)
1471 -#endif /* HAVE_BROKEN_CMSG_FIRSTHDR */
1474 - * RFC 3542 defines several macros for using struct cmsghdr.
1475 - * Here, we define those that are not present
1479 - * Internal defines, for use only in this file.
1480 - * These are likely wrong on other than ILP32 machines, so warn.
1482 -#ifndef _CMSG_DATA_ALIGN
1483 -#define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
1484 -#endif /* _CMSG_DATA_ALIGN */
1486 -#ifndef _CMSG_HDR_ALIGN
1487 -#define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
1488 -#endif /* _CMSG_HDR_ALIGN */
1491 - * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
1495 -#define CMSG_SPACE(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + \
1496 - _CMSG_HDR_ALIGN(l))
1497 -#warning "assuming 4-byte alignment for CMSG_SPACE"
1498 -#endif /* CMSG_SPACE */
1501 -#define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
1502 -#warning "assuming 4-byte alignment for CMSG_LEN"
1503 -#endif /* CMSG_LEN */
1505 -/* The definition of struct in_pktinfo is missing in old version of
1506 - GLIBC 2.1 (Redhat 6.1). */
1507 -#if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO)
1508 -struct in_pktinfo {
1510 - struct in_addr ipi_spec_dst;
1511 - struct in_addr ipi_addr;
1516 - * OSPF Fragmentation / fragmented writes
1518 - * ospfd can support writing fragmented packets, for cases where
1519 - * kernel will not fragment IP_HDRINCL and/or multicast destined
1520 - * packets (ie TTBOMK all kernels, BSD, SunOS, Linux). However,
1521 - * SunOS, probably BSD too, clobber the user supplied IP ID and IP
1522 - * flags fields, hence user-space fragmentation will not work.
1523 - * Only Linux is known to leave IP header unmolested.
1524 - * Further, fragmentation really should be done the kernel, which already
1525 - * supports it, and which avoids nasty IP ID state problems.
1527 - * Fragmentation of OSPF packets can be required on networks with router
1528 - * with many many interfaces active in one area, or on networks with links
1532 -#define WANT_OSPF_WRITE_FRAGMENT
1536 - * IP_HDRINCL / struct ip byte order
1538 - * Linux: network byte order
1539 - * *BSD: network, except for length and offset. (cf Stevens)
1540 - * SunOS: nominally as per BSD. but bug: network order on LE.
1541 - * OpenBSD: network byte order, apart from older versions which are as per
1544 -#if defined(__NetBSD__) || defined(__FreeBSD__) \
1545 - || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
1546 - || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN))
1547 -#define HAVE_IP_HDRINCL_BSD_ORDER
1550 -/* MAX / MIN are not commonly defined, but useful */
1552 -#define MAX(a, b) ((a) > (b) ? (a) : (b))
1555 -#define MIN(a, b) ((a) < (b) ? (a) : (b))
1558 -/* For old definition. */
1559 -#ifndef IN6_ARE_ADDR_EQUAL
1560 -#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
1561 -#endif /* IN6_ARE_ADDR_EQUAL */
1563 -/* Zebra message types. */
1564 -#define ZEBRA_INTERFACE_ADD 1
1565 -#define ZEBRA_INTERFACE_DELETE 2
1566 -#define ZEBRA_INTERFACE_ADDRESS_ADD 3
1567 -#define ZEBRA_INTERFACE_ADDRESS_DELETE 4
1568 -#define ZEBRA_INTERFACE_UP 5
1569 -#define ZEBRA_INTERFACE_DOWN 6
1570 -#define ZEBRA_IPV4_ROUTE_ADD 7
1571 -#define ZEBRA_IPV4_ROUTE_DELETE 8
1572 -#define ZEBRA_IPV6_ROUTE_ADD 9
1573 -#define ZEBRA_IPV6_ROUTE_DELETE 10
1574 -#define ZEBRA_REDISTRIBUTE_ADD 11
1575 -#define ZEBRA_REDISTRIBUTE_DELETE 12
1576 -#define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
1577 -#define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
1578 -#define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
1579 -#define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
1580 -#define ZEBRA_IPV4_IMPORT_LOOKUP 17
1581 -#define ZEBRA_IPV6_IMPORT_LOOKUP 18
1582 -#define ZEBRA_INTERFACE_RENAME 19
1583 -#define ZEBRA_ROUTER_ID_ADD 20
1584 -#define ZEBRA_ROUTER_ID_DELETE 21
1585 -#define ZEBRA_ROUTER_ID_UPDATE 22
1586 -#define ZEBRA_MESSAGE_MAX 23
1588 -/* Zebra route's types. */
1589 -#define ZEBRA_ROUTE_SYSTEM 0
1590 -#define ZEBRA_ROUTE_KERNEL 1
1591 -#define ZEBRA_ROUTE_CONNECT 2
1592 -#define ZEBRA_ROUTE_STATIC 3
1593 -#define ZEBRA_ROUTE_RIP 4
1594 -#define ZEBRA_ROUTE_RIPNG 5
1595 -#define ZEBRA_ROUTE_OSPF 6
1596 -#define ZEBRA_ROUTE_OSPF6 7
1597 -#define ZEBRA_ROUTE_ISIS 8
1598 -#define ZEBRA_ROUTE_BGP 9
1599 -#define ZEBRA_ROUTE_HSLS 10
1600 -#define ZEBRA_ROUTE_OLSR 11
1601 -#define ZEBRA_ROUTE_MAX 12
1603 -/* Zebra's family types. */
1604 -#define ZEBRA_FAMILY_IPV4 1
1605 -#define ZEBRA_FAMILY_IPV6 2
1606 -#define ZEBRA_FAMILY_MAX 3
1608 -/* Error codes of zebra. */
1609 -#define ZEBRA_ERR_RTEXIST -1
1610 -#define ZEBRA_ERR_RTUNREACH -2
1611 -#define ZEBRA_ERR_EPERM -3
1612 -#define ZEBRA_ERR_RTNOEXIST -4
1614 -/* Zebra message flags */
1615 -#define ZEBRA_FLAG_INTERNAL 0x01
1616 -#define ZEBRA_FLAG_SELFROUTE 0x02
1617 -#define ZEBRA_FLAG_BLACKHOLE 0x04
1618 -#define ZEBRA_FLAG_IBGP 0x08
1619 -#define ZEBRA_FLAG_SELECTED 0x10
1620 -#define ZEBRA_FLAG_CHANGED 0x20
1621 -#define ZEBRA_FLAG_STATIC 0x40
1622 -#define ZEBRA_FLAG_REJECT 0x80
1624 -/* Zebra nexthop flags. */
1625 -#define ZEBRA_NEXTHOP_IFINDEX 1
1626 -#define ZEBRA_NEXTHOP_IFNAME 2
1627 -#define ZEBRA_NEXTHOP_IPV4 3
1628 -#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
1629 -#define ZEBRA_NEXTHOP_IPV4_IFNAME 5
1630 -#define ZEBRA_NEXTHOP_IPV6 6
1631 -#define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
1632 -#define ZEBRA_NEXTHOP_IPV6_IFNAME 8
1633 -#define ZEBRA_NEXTHOP_BLACKHOLE 9
1635 -#ifndef INADDR_LOOPBACK
1636 -#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
1639 -/* Address family numbers from RFC1700. */
1644 -/* Subsequent Address Family Identifier. */
1645 -#define SAFI_UNICAST 1
1646 -#define SAFI_MULTICAST 2
1647 -#define SAFI_UNICAST_MULTICAST 3
1648 -#define SAFI_MPLS_VPN 4
1651 -/* Filter direction. */
1652 -#define FILTER_IN 0
1653 -#define FILTER_OUT 1
1654 -#define FILTER_MAX 2
1656 -/* Default Administrative Distance of each protocol. */
1657 -#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
1658 -#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
1659 -#define ZEBRA_STATIC_DISTANCE_DEFAULT 1
1660 -#define ZEBRA_RIP_DISTANCE_DEFAULT 120
1661 -#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
1662 -#define ZEBRA_OSPF_DISTANCE_DEFAULT 110
1663 -#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
1664 -#define ZEBRA_ISIS_DISTANCE_DEFAULT 115
1665 -#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
1666 -#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
1668 -/* Flag manipulation macros. */
1669 -#define CHECK_FLAG(V,F) ((V) & (F))
1670 -#define SET_FLAG(V,F) (V) = (V) | (F)
1671 -#define UNSET_FLAG(V,F) (V) = (V) & ~(F)
1673 -/* AFI and SAFI type. */
1674 -typedef u_int16_t afi_t;
1675 -typedef u_int8_t safi_t;
1678 -typedef u_int16_t zebra_size_t;
1679 -typedef u_int8_t zebra_command_t;
1681 -/* FIFO -- first in first out structure and macros. */
1683 - struct fifo *next;
1684 - struct fifo *prev;
1687 -#define FIFO_INIT(F) \
1689 - struct fifo *Xfifo = (struct fifo *)(F); \
1690 - Xfifo->next = Xfifo->prev = Xfifo; \
1693 -#define FIFO_ADD(F,N) \
1695 - struct fifo *Xfifo = (struct fifo *)(F); \
1696 - struct fifo *Xnode = (struct fifo *)(N); \
1697 - Xnode->next = Xfifo; \
1698 - Xnode->prev = Xfifo->prev; \
1699 - Xfifo->prev = Xfifo->prev->next = Xnode; \
1702 -#define FIFO_DEL(N) \
1704 - struct fifo *Xnode = (struct fifo *)(N); \
1705 - Xnode->prev->next = Xnode->next; \
1706 - Xnode->next->prev = Xnode->prev; \
1709 -#define FIFO_HEAD(F) \
1710 - ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
1711 - ? NULL : (F)->next)
1713 -#define FIFO_EMPTY(F) \
1714 - (((struct fifo *)(F))->next == (struct fifo *)(F))
1716 -#define FIFO_TOP(F) \
1717 - (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
1719 -#endif /* _ZEBRA_H */
1722 - * Local Variables:
1723 - * c-basic-offset: 2
1724 - * indent-tabs-mode: nil
1727 diff -Naur olsrd-0.5.6-r5/lib/quagga/src/quagga.c olsrd-0.5.6-r5.patched/lib/quagga/src/quagga.c
1728 --- olsrd-0.5.6-r5/lib/quagga/src/quagga.c 2009-06-24 20:00:51.000000000 +0300
1729 +++ olsrd-0.5.6-r5.patched/lib/quagga/src/quagga.c 2009-07-04 16:38:26.000000000 +0300
1732 + * OLSRd Quagga plugin
1734 + * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
1735 + * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
1737 + * This program is free software; you can redistribute it and/or modify
1738 + * it under the terms of the GNU General Public License version 2 as
1739 + * published by the Free Software Foundation or - at your option - under
1740 + * the terms of the GNU General Public Licence version 2 but can be
1741 + * linked to any BSD-Licenced Software with public available sourcecode
1745 -/***************************************************************************
1746 - projekt : olsrd-quagga
1748 - usage : communication with the zebra-daemon
1749 - copyright : (C) 2006 by Immo 'FaUl' Wehrenberg
1750 - e-mail : immo@chaostreff-dortmund.de
1751 - ***************************************************************************/
1753 -/***************************************************************************
1755 - * This program is free software; you can redistribute it and/or modify *
1756 - * it under the terms of the GNU General Public License version 2 as *
1757 - * published by the Free Software Foundation. *
1759 - ***************************************************************************/
1760 +/* -------------------------------------------------------------------------
1762 + * Description : functions to interface to the zebra daemon
1763 + * ------------------------------------------------------------------------- */
1769 #define HAVE_SOCKLEN_T
1771 +#include "quagga.h"
1772 +#include "olsr.h" /* olsr_exit
1774 +#include "log.h" /* olsr_syslog */
1777 +#include <stdlib.h>
1778 +#include <unistd.h>
1779 +#include <string.h>
1782 #include <sys/types.h>
1783 #include <sys/socket.h>
1784 #include <netinet/in.h>
1787 -#include "quagga.h"
1791 -#include "routing_table.h"
1793 +#include <arpa/inet.h>
1794 #ifdef USE_UNIX_DOMAIN_SOCKET
1796 -#define ZEBRA_SOCKET "/var/run/quagga/zserv.api"
1799 -#define ZEBRA_IPV4_ROUTE_ADD 7
1800 -#define ZEBRA_IPV4_ROUTE_DELETE 8
1801 -#define ZEBRA_REDISTRIBUTE_ADD 11
1802 -#define ZEBRA_REDISTRIBUTE_DELETE 12
1803 -#define ZEBRA_MESSAGE_MAX 23
1805 -#define ZEBRA_ROUTE_OLSR 11
1806 -#define ZEBRA_ROUTE_MAX 12
1808 -#define ZEBRA_FLAG_SELECTED 0x10
1810 -#define ZEBRA_NEXTHOP_IPV4 3
1811 -#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
1813 -#define ZAPI_MESSAGE_NEXTHOP 0x01
1814 -#define ZAPI_MESSAGE_IFINDEX 0x02
1815 -#define ZAPI_MESSAGE_DISTANCE 0x04
1816 -#define ZAPI_MESSAGE_METRIC 0x08
1818 -#define BUFSIZE 1024
1820 -#define STATUS_CONNECTED 1
1821 -#define OPTION_EXPORT 1
1823 +/* prototypes intern */
1825 - char status; // internal status
1826 - char options; // internal options
1827 - int sock; // Socket to zebra...
1828 + char status; // internal status
1829 + char options; // internal options
1830 + int sock; // Socket to zebra...
1831 char redistribute[ZEBRA_ROUTE_MAX];
1834 - struct ipv4_route *v4_rt; // routes currently exportet to zebra
1835 + struct zebra_route *v4_rt; // routes currently exportet to zebra
1838 -/* prototypes intern */
1839 -static unsigned char *try_read(ssize_t *);
1840 -static unsigned char *zebra_route_packet(struct ipv4_route r, ssize_t *);
1841 -static int parse_interface_add(unsigned char *, size_t);
1842 -static int parse_interface_delete(unsigned char *, size_t);
1843 -static int parse_interface_up(unsigned char *, size_t);
1844 -static int parse_interface_down(unsigned char *, size_t);
1845 -static int parse_interface_address_add(unsigned char *, size_t);
1846 -static int parse_interface_address_delete(unsigned char *, size_t);
1847 -static int parse_ipv4_route(unsigned char *, size_t, struct ipv4_route *);
1848 -static int ipv4_route_add(unsigned char *, size_t);
1849 -static int ipv4_route_delete(unsigned char *, size_t);
1850 -static int parse_ipv6_route_add(unsigned char *, size_t);
1851 -static void zebra_reconnect(void);
1852 -static void zebra_connect(void);
1854 -static void free_ipv4_route(struct ipv4_route);
1857 -static void update_olsr_zebra_routes (struct ipv4_route*, struct ipv4_route*);
1858 -static struct ipv4_route *zebra_create_ipv4_route_table_entry (uint32_t,
1861 -static struct ipv4_route *zebra_create_ipv4_route_table (void);
1862 -static void zebra_free_ipv4_route_table (struct ipv4_route*);
1865 -/*static uint8_t masktoprefixlen (uint32_t);*/
1869 -dump_ipv4_route(struct ipv4_route r, char *c)
1874 - printf("type: %d\n", r.type);
1876 - printf(" Internal: %s\n", r.flags & ZEBRA_FLAG_INTERNAL ? "yes" : "no");
1877 - printf(" Selfroute %s\n", r.flags & ZEBRA_FLAG_SELFROUTE ? "yes" : "no");
1878 - printf(" Blackhole %s\n", r.flags & ZEBRA_FLAG_BLACKHOLE ? "yes" : "no");
1879 - printf(" IBGP: %s\n", r.flags & ZEBRA_FLAG_IBGP ? "yes" : "no");
1880 - printf(" Selected: %s\n", r.flags & ZEBRA_FLAG_SELECTED ? "yes" : "no");
1881 - printf(" Changed: %s\n", r.flags & ZEBRA_FLAG_CHANGED ? "yes" : "no");
1882 - printf(" static: %s\n", r.flags & ZEBRA_FLAG_STATIC ? "yes" : "no");
1883 - printf(" reject: %s\n", r.flags & ZEBRA_FLAG_REJECT ? "yes" : "no");
1885 - printf(" nexthop: %s\n", r.message & ZAPI_MESSAGE_NEXTHOP ? "yes" : "no");
1886 - printf(" ifindex: %s\n", r.message & ZAPI_MESSAGE_IFINDEX ? "yes" : "no");
1887 - printf(" distance: %s\n", r.message & ZAPI_MESSAGE_DISTANCE ? "yes" : "no");
1888 - printf(" metric: %s\n", r.message & ZAPI_MESSAGE_METRIC ? "yes" : "no");
1889 - printf("Prefixlen: %d\n", r.prefixlen);
1890 - printf("Prefix: %d", (unsigned char)r.prefix);
1891 - c = (char *)&r.prefix;
1892 - while (++i < (r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0)))
1893 - printf(".%d", (unsigned char)*(c + i));
1898 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
1899 - printf("nexthop-count: %d\n", r.nh_count);
1900 - while (i++ < r.nh_count) {
1901 - if (r.nexthops[i].type == ZEBRA_NEXTHOP_IPV4) {
1902 - c = (unsigned char *)&r.nexthops[i].payload.v4;
1903 - printf("Nexthop %d: %d", i, (unsigned char)*c);
1905 - printf(".%d", (unsigned char)c[x]);
1912 - if (r.message & ZAPI_MESSAGE_IFINDEX) {
1914 - printf("index-number: %d\n", r.ind_num);
1915 - while (i++ < r.ind_num)
1916 - printf("Index: %d: %d\n", i, r.index[i]);
1918 - if (r.message & ZAPI_MESSAGE_DISTANCE)
1919 - printf("Distance: %d\n", r.distance);
1920 - if (r.message & ZAPI_MESSAGE_METRIC)
1921 - printf("Metric: %d\n", r.metric);
1925 +static void *my_realloc (void *, size_t, const char *);
1926 +static void zebra_connect (void);
1927 +static unsigned char *try_read (ssize_t *);
1928 +static int zebra_send_command (unsigned char *);
1929 +static unsigned char* zebra_route_packet (uint16_t, struct zebra_route *);
1930 +static unsigned char *zebra_redistribute_packet (unsigned char, unsigned char);
1931 +static struct zebra_route *zebra_parse_route (unsigned char *);
1933 +static void zebra_reconnect (void);
1935 +static void free_ipv4_route (struct zebra_route *);
1939 -my_realloc(void *buf, size_t s, const char *c)
1941 - buf = realloc(buf, s);
1942 +static void *my_realloc (void *buf, size_t s, const char *c) {
1943 + buf = realloc (buf, s);
1945 - OLSR_PRINTF(1, "(QUAGGA) OUT OF MEMORY: %s\n", strerror(errno));
1946 + OLSR_PRINTF (1, "(QUAGGA) OUT OF MEMORY: %s\n", strerror(errno));
1947 olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n");
1948 olsr_exit(c, EXIT_FAILURE);
1957 +void init_zebra (void) {
1959 - if (!(zebra.status & STATUS_CONNECTED))
1960 - olsr_exit("(QUAGGA) AIIIII, could not connect to zebra! is zebra running?", EXIT_FAILURE);
1961 + if (!(zebra.status&STATUS_CONNECTED))
1962 + olsr_exit ("(QUAGGA) AIIIII, could not connect to zebra! is zebra running?",
1967 -zebra_cleanup(void)
1970 +void zebra_cleanup (void) {
1972 struct rt_entry *tmp;
1974 if (zebra.options & OPTION_EXPORT) {
1975 OLSR_FOR_ALL_RT_ENTRIES(tmp) {
1976 - zebra_del_olsr_v4_route(tmp);
1978 - OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
1979 + zebra_del_route(tmp);
1980 + } OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
1983 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1984 - if (zebra.redistribute[i])
1985 - zebra_disable_redistribute(i + 1);
1986 + if (zebra.redistribute[i]) zebra_disable_redistribute(i);
1990 -zebra_reconnect(void)
1994 +static void zebra_reconnect (void) {
1995 struct rt_entry *tmp;
1999 - if (!(zebra.status & STATUS_CONNECTED))
2000 - return; // try again next time
2001 + if (!(zebra.status & STATUS_CONNECTED)) return; // try again next time
2003 if (zebra.options & OPTION_EXPORT) {
2004 OLSR_FOR_ALL_RT_ENTRIES(tmp) {
2005 - zebra_add_olsr_v4_route(tmp);
2007 - OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
2008 + zebra_add_route (tmp);
2009 + } OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
2012 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2013 - if (zebra.redistribute[i])
2014 - zebra_redistribute(i + 1);
2015 + if (zebra.redistribute[i]) zebra_redistribute(i + 1);
2016 /* Zebra sends us all routes of type it knows after
2017 zebra_redistribute(type) */
2022 /* Connect to the zebra-daemon, returns a socket */
2024 -zebra_connect(void)
2026 +static void zebra_connect (void) {
2030 #ifndef USE_UNIX_DOMAIN_SOCKET
2031 struct sockaddr_in i;
2032 - if (close(zebra.sock) < 0)
2033 - olsr_exit("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2034 + if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2036 - zebra.sock = socket(AF_INET, SOCK_STREAM, 0);
2038 + zebra.sock = socket (AF_INET,SOCK_STREAM, 0);
2040 struct sockaddr_un i;
2041 - if (close(zebra.sock) < 0)
2042 - olsr_exit("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2043 + if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2045 - zebra.sock = socket(AF_UNIX, SOCK_STREAM, 0);
2046 + zebra.sock = socket (AF_UNIX,SOCK_STREAM, 0);
2049 - if (zebra.sock < 0)
2050 + if (zebra.sock <0 )
2051 olsr_exit("(QUAGGA) Could not create socket!", EXIT_FAILURE);
2053 - memset(&i, 0, sizeof i);
2054 + memset (&i, 0, sizeof i);
2055 #ifndef USE_UNIX_DOMAIN_SOCKET
2056 i.sin_family = AF_INET;
2057 - i.sin_port = htons(ZEBRA_PORT);
2058 - i.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
2059 + i.sin_port = htons (ZEBRA_PORT);
2060 + i.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
2062 i.sun_family = AF_UNIX;
2063 - strscpy(i.sun_path, ZEBRA_SOCKET, sizeof(i.sun_path));
2064 + strcpy (i.sun_path, ZEBRA_SOCKET);
2067 - ret = connect(zebra.sock, (struct sockaddr *)&i, sizeof i);
2069 - zebra.status &= ~STATUS_CONNECTED;
2071 - zebra.status |= STATUS_CONNECTED;
2072 + ret = connect (zebra.sock, (struct sockaddr *)&i, sizeof i);
2073 + if (ret < 0) zebra.status &= ~STATUS_CONNECTED;
2074 + else zebra.status |= STATUS_CONNECTED;
2078 /* Sends a command to zebra, command is
2079 the command defined in zebra.h, options is the packet-payload,
2080 optlen the length, of the payload */
2082 -zebra_send_command(unsigned char command, unsigned char *options, int optlen)
2084 +static int zebra_send_command (unsigned char *options) {
2087 + unsigned char *pnt;
2091 -#ifdef ZEBRA_HEADER_MARKER
2093 - uint16_t length = optlen + 6; /* length of option + command + packet_length +
2094 - marker + zserv-version */
2096 - uint16_t length = optlen + 3; // length of option + command + packet_length
2098 + if (!(zebra.status & STATUS_CONNECTED)) return 0;
2100 - if (!(zebra.status & STATUS_CONNECTED))
2103 + memcpy (&len, pnt, 2);
2105 - p = olsr_malloc(length, "zebra_send_command");
2108 - len = htons(length);
2110 - memcpy(p, &len, 2);
2112 -#ifdef ZEBRA_HEADER_MARKER
2113 - p[2] = ZEBRA_HEADER_MARKER;
2114 - p[3] = ZSERV_VERSION;
2115 - cmd = htons(command);
2116 - memcpy(p + 4, &cmd, 2);
2120 - memcpy(p + length - optlen, options, optlen);
2126 - ret = write(zebra.sock, p, length);
2127 + ret = write (zebra.sock, pnt, len);
2129 - if (errno == EINTR) {
2133 - olsr_printf(1, "(QUAGGA) Disconnected from zebra\n");
2134 - zebra.status &= ~STATUS_CONNECTED;
2137 + if ((errno == EINTR) || (errno == EAGAIN)) {
2143 + OLSR_PRINTF (1, "(QUAGGA) Disconnected from zebra\n");
2144 + zebra.status &= ~STATUS_CONNECTED;
2151 - while ((length -= ret));
2154 + } while ((len -= ret));
2160 /* Creates a Route-Packet-Payload, needs address, netmask, nexthop,
2161 distance, and a pointer of an size_t */
2162 -static unsigned char *
2163 -zebra_route_packet(struct ipv4_route r, ssize_t * optlen)
2165 +static unsigned char* zebra_route_packet (uint16_t cmd, struct zebra_route *r) {
2170 + uint32_t ind, metric;
2172 unsigned char *cmdopt, *t;
2173 - *optlen = 4; // first: type, flags, message, prefixlen
2174 - *optlen += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0); // + prefix
2175 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
2176 - if (r.nexthops->type == ZEBRA_NEXTHOP_IPV4 || r.nexthops->type == ZEBRA_NEXTHOP_IPV4_IFINDEX) {
2177 - *optlen += (sizeof r.nexthops->payload.v4 + sizeof r.nexthops->type) * r.nh_count + 1;
2178 - } else if (r.nexthops->type == 0)
2181 - if (r.message & ZAPI_MESSAGE_IFINDEX)
2182 - *optlen += r.ind_num * sizeof *r.index + 1;
2183 - if (r.message & ZAPI_MESSAGE_DISTANCE)
2185 - if (r.message & ZAPI_MESSAGE_METRIC)
2186 - *optlen += sizeof r.metric;
2188 - cmdopt = olsr_malloc(*optlen, "zebra add_v4_route");
2194 - *t++ = r.prefixlen;
2195 - for (count = 0; count < r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0); count++) {
2196 - *t++ = *((char *)&r.prefix + count); /* this is so sick!! */
2199 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
2200 - *t++ = r.nh_count;
2201 - *t++ = r.nexthops->type;
2202 - if (r.nexthops->type == ZEBRA_NEXTHOP_IPV4 || r.nexthops->type == ZEBRA_NEXTHOP_IPV4_IFINDEX) {
2203 - for (count = 0; count != r.nh_count; count++) {
2204 - memcpy(t, &r.nexthops[count].payload.v4, sizeof r.nexthops->payload.v4);
2205 - t += sizeof r.nexthops->payload.v4;
2207 - } else if (r.nexthops->type == 0) {
2213 - if (r.message & ZAPI_MESSAGE_IFINDEX) {
2215 - memcpy(t, r.index, sizeof *r.index * r.ind_num);
2216 - t += sizeof r.index * r.ind_num;
2218 - if (r.message & ZAPI_MESSAGE_DISTANCE)
2219 - *t++ = r.distance;
2220 - if (r.message & ZAPI_MESSAGE_METRIC) {
2221 - memcpy(t, &r.metric, sizeof r.metric);
2222 - t += sizeof r.metric;
2227 -/* adds a route to zebra-daemon */
2229 -zebra_add_v4_route(const struct ipv4_route r)
2232 - unsigned char *cmdopt;
2235 + cmdopt = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra add_v4_route");
2237 - cmdopt = zebra_route_packet(r, &optlen);
2242 + *t++ = r->message;
2243 + *t++ = r->prefixlen;
2244 + len = (r->prefixlen + 7) / 8;
2245 + memcpy (t, &r->prefix.v4.s_addr, len);
2248 - retval = zebra_send_command(ZEBRA_IPV4_ROUTE_ADD, cmdopt, optlen);
2251 + if (r->message & ZAPI_MESSAGE_NEXTHOP) {
2252 + *t++ = r->nexthop_num + r->ifindex_num;
2254 + for (count = 0; count < r->nexthop_num; count++)
2256 + *t++ = ZEBRA_NEXTHOP_IPV4;
2257 + memcpy (t, &r->nexthop[count].v4.s_addr,
2258 + sizeof r->nexthop[count].v4.s_addr);
2259 + t += sizeof r->nexthop[count].v4.s_addr;
2261 + for (count = 0; count < r->ifindex_num; count++)
2263 + *t++ = ZEBRA_NEXTHOP_IFINDEX;
2264 + ind = htonl(r->ifindex[count]);
2265 + memcpy (t, &ind, sizeof ind);
2269 + if ((r->message & ZAPI_MESSAGE_DISTANCE) > 0)
2270 + *t++ = r->distance;
2271 + if ((r->message & ZAPI_MESSAGE_METRIC) > 0)
2273 + metric = htonl (r->metric);
2274 + memcpy (t, &metric, sizeof metric);
2275 + t += sizeof metric;
2277 + size = htons (t - cmdopt);
2278 + memcpy (cmdopt, &size, 2);
2283 -/* deletes a route from the zebra-daemon */
2285 -zebra_delete_v4_route(struct ipv4_route r)
2288 - unsigned char *cmdopt;
2292 - cmdopt = zebra_route_packet(r, &optlen);
2294 - retval = zebra_send_command(ZEBRA_IPV4_ROUTE_DELETE, cmdopt, optlen);
2301 /* Check wether there is data from zebra aviable */
2303 -zebra_check(void *foo __attribute__ ((unused)))
2305 +void zebra_parse (void* foo __attribute__((unused))) {
2306 unsigned char *data, *f;
2308 + unsigned char command;
2311 + struct zebra_route *route;
2313 if (!(zebra.status & STATUS_CONNECTED)) {
2314 - zebra_reconnect();
2315 +// zebra_reconnect();
2318 - data = try_read(&len);
2319 + data = try_read (&len);
2323 - ret = zebra_parse_packet(f, len);
2324 - if (!ret) // something wired happened
2325 - olsr_exit("(QUAGGA) Zero message length??? ", EXIT_FAILURE);
2328 - while ((f - data) < len);
2330 + memcpy (&length, f, sizeof length);
2331 + length = ntohs (length);
2332 + if (!length) // something wired happened
2333 + olsr_exit ("(QUAGGA) Zero message length??? ", EXIT_FAILURE);
2335 + switch (command) {
2336 + case ZEBRA_IPV4_ROUTE_ADD:
2337 + route = zebra_parse_route(f);
2338 + ip_prefix_list_add(&olsr_cnf->hna_entries, &route->prefix, route->prefixlen);
2339 + free_ipv4_route (route);
2342 + case ZEBRA_IPV4_ROUTE_DELETE:
2343 + route = zebra_parse_route(f);
2344 + ip_prefix_list_remove(&olsr_cnf->hna_entries, &route->prefix, route->prefixlen);
2345 + free_ipv4_route (route);
2352 + } while ((f - data) < len);
2358 // tries to read a packet from zebra_socket
2359 // if there is something to read - make sure to read whole packages
2360 -static unsigned char *
2361 -try_read(ssize_t * len)
2363 - unsigned char *buf = NULL;
2364 - ssize_t ret = 0, bsize = 0;
2365 - uint16_t length = 0, l = 0;
2370 - sockstate = fcntl(zebra.sock, F_GETFL, 0);
2371 - fcntl(zebra.sock, F_SETFL, sockstate | O_NONBLOCK);
2372 +static unsigned char *try_read (ssize_t *size) {
2373 + unsigned char *buf;
2374 + ssize_t bytes, bufsize;
2375 + uint16_t length, offset;
2378 + /* initialize variables */
2384 + /* save socket status and set non-blocking for read */
2385 + sockstatus = fcntl (zebra.sock, F_GETFL);
2386 + fcntl (zebra.sock, F_SETFL, sockstatus|O_NONBLOCK);
2388 + /* read whole packages */
2390 - if (*len == bsize) {
2392 - buf = my_realloc(buf, bsize, "Zebra try_read");
2394 + /* (re)allocate buffer */
2395 + if (*size == bufsize) {
2396 + bufsize += BUFSIZE;
2397 + buf = my_realloc (buf, bufsize, "Zebra try_read");
2399 - ret = read(zebra.sock, buf + l, bsize - l);
2400 - if (!ret) { // nothing more to read, packet is broken, discard!
2403 + /* read from socket */
2404 + bytes = read (zebra.sock, buf + *size, bufsize - *size);
2405 + /* handle broken packet */
2412 - if (errno != EAGAIN) { // oops - we got disconnected
2413 - olsr_printf(1, "(QUAGGA) Disconnected from zebra\n");
2414 + /* handle no data available */
2416 + /* handle disconnect */
2417 + if (errno != EAGAIN) { // oops - we got disconnected
2418 + OLSR_PRINTF (1, "(QUAGGA) Disconnected from zebra\n");
2419 zebra.status &= ~STATUS_CONNECTED;
2427 - while ((*len - l) > length) {
2429 - memcpy(&length, buf + l, 2);
2430 - length = ntohs(length);
2432 - if (((*len) - l) == length)
2433 - break; // GOT FULL PACKAGE!!
2435 - fcntl(zebra.sock, F_SETFL, sockstate);
2441 - fcntl(zebra.sock, F_SETFL, sockstate);
2445 -/* Parse a packet recived from zebra */
2447 -zebra_parse_packet(unsigned char *packet, ssize_t maxlen)
2453 - /* Array of functions */
2454 - int (*foo[ZEBRA_MESSAGE_MAX]) (unsigned char *, size_t) = {
2455 - parse_interface_add, parse_interface_delete, parse_interface_address_add, parse_interface_address_delete, parse_interface_up,
2456 - parse_interface_down, ipv4_route_add, ipv4_route_delete, parse_ipv6_route_add};
2462 - puts("DEBUG: zebra_parse_packet");
2465 - memcpy(&length, packet, 2);
2466 - length = ntohs(length);
2468 - if (maxlen < length) {
2469 - olsr_printf(1, "(QUAGGA) maxlen = %lu, packet_length = %d\n", (unsigned long)maxlen, length);
2470 - olsr_exit("(QUAGGA) programmer is an idiot", EXIT_FAILURE);
2472 -#ifdef ZEBRA_HEADER_MARKER
2473 - if (packet[2] == 255) { // found header marker!!
2474 - //packet[3] == ZSERV_VERSION: FIXME: HANDLE THIS!
2475 - memcpy(&command, packet + 4, sizeof command); // two bytes command now!
2476 - command = ntohs(command) - 1;
2480 - command = packet[2] - 1;
2485 - if (command < ZEBRA_MESSAGE_MAX && foo[command]) {
2486 - if (!(ret = foo[command] (packet + skip, length - skip)))
2489 - olsr_printf(1, "(QUAGGA) Parse error: %d\n", ret);
2491 - olsr_printf(1, "(QUAGGA) Unknown packet type: %d\n", packet[2]);
2493 - olsr_printf(1, "(Quagga) RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE");
2499 -parse_interface_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2506 -parse_interface_delete(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2513 -parse_interface_address_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2521 -parse_interface_up(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2527 + /* detect zebra packet fragmentation */
2529 + memcpy (&length, buf + offset, sizeof length);
2530 + length = ntohs (length);
2532 + } while (*size >= (ssize_t) (offset + sizeof length));
2533 + /* set blocking socket on fragmented packet */
2534 + if (*size != offset)
2535 + fcntl (zebra.sock, F_SETFL, sockstatus);
2537 + } while (*size != offset);
2540 -parse_interface_down(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2542 + /* restore socket status */
2543 + fcntl (zebra.sock, F_SETFL, sockstatus);
2551 -parse_interface_address_delete(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2557 /* Parse an ipv4-route-packet recived from zebra
2560 -parse_ipv4_route(unsigned char *opt, size_t len, struct ipv4_route *r)
2562 +static struct zebra_route *zebra_parse_route (unsigned char *opt) {
2564 + struct zebra_route *r;
2571 - r->flags = *opt++;
2572 - r->message = *opt++;
2573 - r->prefixlen = *opt++;
2577 - if ((int)len < r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0))
2580 - memcpy(&r->prefix, opt, r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0));
2581 - opt += r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0);
2584 + unsigned char *pnt;
2586 + memcpy (&length, opt, sizeof length);
2587 + length = ntohs (length);
2589 + r = olsr_malloc (sizeof *r , "zebra_parse_route");
2592 + r->flags = *pnt++;
2593 + r->message = *pnt++;
2594 + r->prefixlen = *pnt++;
2595 + r->prefix.v4.s_addr = 0;
2597 + size = (r->prefixlen + 7) / 8;
2598 + memcpy (&r->prefix.v4.s_addr, pnt, size);
2601 if (r->message & ZAPI_MESSAGE_NEXTHOP) {
2604 - r->nh_count = *opt++;
2606 - if (len < (sizeof(uint32_t) + 1) * r->nh_count)
2609 - olsr_malloc((sizeof r->nexthops->type + sizeof r->nexthops->payload) * r->nh_count, "quagga: parse_ipv4_route_add");
2610 - for (c = 0; c < r->nh_count; c++) {
2611 - r->nexthops[c].type = *opt++;
2612 - memcpy(&r->nexthops[c].payload.v4, opt, sizeof(uint32_t));
2613 - opt += sizeof(uint32_t);
2614 - len -= sizeof(uint32_t) + 1;
2615 + r->nexthop_num = *pnt++;
2616 + r->nexthop = olsr_malloc ((sizeof *r->nexthop) * r->nexthop_num,
2617 + "quagga: zebra_parse_route");
2618 + for (c = 0; c < r->nexthop_num; c++) {
2619 + memcpy (&r->nexthop[c].v4.s_addr, pnt, sizeof r->nexthop[c].v4.s_addr);
2620 + pnt += sizeof r->nexthop[c].v4.s_addr;
2624 if (r->message & ZAPI_MESSAGE_IFINDEX) {
2627 - r->ind_num = *opt++;
2628 - if (len < sizeof(uint32_t) * r->ind_num)
2630 - r->index = olsr_malloc(sizeof(uint32_t) * r->ind_num, "quagga: parse_ipv4_route_add");
2631 - memcpy(r->index, opt, r->ind_num * sizeof(uint32_t));
2632 - opt += sizeof(uint32_t) * r->ind_num;
2633 - len -= sizeof(uint32_t) * r->ind_num;
2634 + r->ifindex_num = *pnt++;
2635 + r->ifindex = olsr_malloc (sizeof (uint32_t) * r->ifindex_num,
2636 + "quagga: zebra_parse_route");
2637 + for (c = 0; c < r->ifindex_num; c++) {
2638 + memcpy (&r->ifindex[c], pnt, sizeof r->ifindex[c]);
2639 + r->ifindex[c] = ntohl (r->ifindex[c]);
2640 + pnt += sizeof r->ifindex[c];
2644 if (r->message & ZAPI_MESSAGE_DISTANCE) {
2647 - r->distance = *opt++;
2649 + r->distance = *pnt++;
2652 - if (r->message & ZAPI_MESSAGE_METRIC) {
2653 - if (len < sizeof(uint32_t))
2655 - memcpy(&r->metric, opt, sizeof(uint32_t));
2657 +// Quagga v0.98.6 BUG workaround: metric is always sent by zebra
2658 +// even without ZAPI_MESSAGE_METRIC message.
2659 +// if (r.message & ZAPI_MESSAGE_METRIC) {
2660 + memcpy (&r->metric, pnt, sizeof (uint32_t));
2661 + r->metric = ntohl (r->metric);
2662 + pnt += sizeof r->metric;
2665 + if (pnt - opt != length) { olsr_exit ("(QUAGGA) length does not match ??? ", EXIT_FAILURE);
2673 -ipv4_route_add(unsigned char *opt, size_t len)
2676 - struct ipv4_route r;
2678 +static unsigned char *zebra_redistribute_packet (unsigned char cmd, unsigned char type) {
2679 + unsigned char *data, *pnt;
2682 - f = parse_ipv4_route(opt, len, &r);
2685 + data = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra_redistribute_packet");
2687 - return add_hna4_route(r);
2691 -ipv4_route_delete(unsigned char *opt, size_t len)
2693 - struct ipv4_route r;
2696 - f = parse_ipv4_route(opt, len, &r);
2700 - return delete_hna4_route(r);
2704 + size = htons (pnt - data);
2705 + memcpy (data, &size, 2);
2711 -parse_ipv6_route_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2717 /* start redistribution FROM zebra */
2719 -zebra_redistribute(unsigned char type)
2722 - if (type > ZEBRA_ROUTE_MAX)
2724 - zebra.redistribute[type - 1] = 1;
2726 - return zebra_send_command(ZEBRA_REDISTRIBUTE_ADD, &type, 1);
2730 -/* end redistribution FROM zebra */
2732 -zebra_disable_redistribute(unsigned char type)
2735 - if (type > ZEBRA_ROUTE_MAX)
2737 - zebra.redistribute[type - 1] = 0;
2738 +int zebra_redistribute (unsigned char type) {
2740 - return zebra_send_command(ZEBRA_REDISTRIBUTE_DELETE, &type, 1);
2741 + if (zebra_send_command(zebra_redistribute_packet (ZEBRA_REDISTRIBUTE_ADD, type)) < 0)
2742 + olsr_exit("(QUAGGA) could not send redistribute add command", EXIT_FAILURE);
2745 + if (type > ZEBRA_ROUTE_MAX-1) return -1;
2746 + zebra.redistribute[type] = 1;
2749 -add_hna4_route(struct ipv4_route r)
2751 - union olsr_ip_addr net;
2754 - dump_ipv4_route(r, "add_hna4_route");
2757 - net.v4.s_addr = r.prefix;
2759 - ip_prefix_list_add(&olsr_cnf->hna_entries, &net, r.prefixlen);
2760 - free_ipv4_route(r);
2766 -delete_hna4_route(struct ipv4_route r)
2769 - union olsr_ip_addr net;
2770 +/* end redistribution FROM zebra */
2771 +int zebra_disable_redistribute (unsigned char type) {
2774 - dump_ipv4_route(r, "delete_hna4_route");
2776 + if (zebra_send_command(zebra_redistribute_packet (ZEBRA_REDISTRIBUTE_DELETE, type)) < 0)
2777 + olsr_exit("(QUAGGA) could not send redistribute delete command", EXIT_FAILURE);
2779 - net.v4.s_addr = r.prefix;
2780 + if (type > ZEBRA_ROUTE_MAX-1) return -1;
2781 + zebra.redistribute[type] = 0;
2783 - ip_prefix_list_remove(&olsr_cnf->hna_entries, &net, r.prefixlen) ? 0 : -1;
2784 - free_ipv4_route(r);
2790 -free_ipv4_route(struct ipv4_route r)
2793 - if (r.message & ZAPI_MESSAGE_IFINDEX && r.ind_num)
2795 - if (r.message & ZAPI_MESSAGE_NEXTHOP && r.nh_count)
2801 -static uint8_t masktoprefixlen (uint32_t mask) {
2803 - uint8_t prefixlen = 0;
2805 - mask = htonl (mask);
2806 +static void free_ipv4_route (struct zebra_route *r) {
2808 - if (mask) while (mask << ++prefixlen && prefixlen < 32);
2811 + if(r->ifindex_num) free(r->ifindex);
2812 + if(r->nexthop_num) free(r->nexthop);
2818 -zebra_add_olsr_v4_route(const struct rt_entry *r)
2821 - struct ipv4_route route;
2822 +int zebra_add_route (const struct rt_entry *r) {
2824 + struct zebra_route route;
2827 - route.index = NULL;
2828 - route.distance = 0;
2829 - route.type = ZEBRA_ROUTE_OLSR; // OLSR
2830 - route.message = ZAPI_MESSAGE_METRIC;
2831 + route.type = ZEBRA_ROUTE_OLSR;
2832 route.flags = zebra.flags;
2833 + route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC;
2834 route.prefixlen = r->rt_dst.prefix_len;
2835 - route.prefix = r->rt_dst.prefix.v4.s_addr;
2836 - if ((r->rt_best->rtp_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && route.prefixlen == 32)) {
2837 - route.message |= ZAPI_MESSAGE_IFINDEX | ZAPI_MESSAGE_NEXTHOP;
2838 - route.ind_num = 1;
2839 - route.index = olsr_malloc(sizeof *route.index, "zebra_add_olsr_v4_route");
2840 - *route.index = htonl(r->rt_best->rtp_nexthop.iif_index);
2841 - route.nexthops = olsr_malloc(sizeof route.nexthops->type + sizeof route.nexthops->payload, "zebra_add_olsr_v4_route");
2842 - route.nh_count = 1;
2843 - route.nexthops->type = 0;
2845 - route.message |= ZAPI_MESSAGE_NEXTHOP;
2846 - route.nh_count = 1;
2848 - olsr_malloc(route.nh_count * (sizeof route.nexthops->type + sizeof route.nexthops->payload), "zebra_add_olsr_v4_route");
2849 - route.nexthops->type = ZEBRA_NEXTHOP_IPV4;
2850 - route.nexthops->payload.v4 = r->rt_best->rtp_nexthop.gateway.v4.s_addr;
2851 + route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr;
2852 + route.ifindex_num = 0;
2853 + route.ifindex = NULL;
2854 + route.nexthop_num = 0;
2855 + route.nexthop = NULL;
2857 + if (r->rt_best->rtp_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr &&
2858 + route.prefixlen == 32) {
2859 + return 0; /* Quagga BUG workaround: don't add routes with destination = gateway
2860 + see http://lists.olsr.org/pipermail/olsr-users/2006-June/001726.html */
2861 + route.ifindex_num++;
2862 + route.ifindex = olsr_malloc (sizeof *route.ifindex,
2863 + "zebra_add_route");
2864 + *route.ifindex = r->rt_best->rtp_nexthop.iif_index;
2867 + route.nexthop_num++;
2868 + route.nexthop = olsr_malloc (sizeof *route.nexthop, "zebra_add_route");
2869 + route.nexthop->v4.s_addr = r->rt_best->rtp_nexthop.gateway.v4.s_addr;
2872 route.metric = r->rt_best->rtp_metric.hops;
2873 - route.metric = htonl(route.metric);
2875 if (zebra.distance) {
2876 route.message |= ZAPI_MESSAGE_DISTANCE;
2877 route.distance = zebra.distance;
2880 - retval = zebra_add_v4_route(route);
2881 - free_ipv4_route(route);
2882 + retval = zebra_send_command (zebra_route_packet (ZEBRA_IPV4_ROUTE_ADD, &route));
2888 -zebra_del_olsr_v4_route(const struct rt_entry *r)
2890 +int zebra_del_route (const struct rt_entry *r) {
2892 - struct ipv4_route route;
2893 + struct zebra_route route;
2895 - route.index = NULL;
2896 - route.distance = 0;
2897 - route.type = ZEBRA_ROUTE_OLSR; // OLSR
2898 - route.message = ZAPI_MESSAGE_METRIC;
2900 + route.type = ZEBRA_ROUTE_OLSR;
2901 route.flags = zebra.flags;
2902 + route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC;
2903 route.prefixlen = r->rt_dst.prefix_len;
2904 - route.prefix = r->rt_dst.prefix.v4.s_addr;
2905 - if ((r->rt_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && route.prefixlen == 32)) {
2906 - route.message |= ZAPI_MESSAGE_IFINDEX;
2907 - route.ind_num = 1;
2908 - route.index = olsr_malloc(sizeof *route.index, "zebra_add_olsr_v4_route");
2909 - *route.index = htonl(r->rt_nexthop.iif_index);
2910 - route.nexthops = olsr_malloc(sizeof route.nexthops->type + sizeof route.nexthops->payload, "zebra_add_olsr_v4_route");
2911 - route.nh_count = 1;
2912 - route.nexthops->type = 0;
2914 - route.message |= ZAPI_MESSAGE_NEXTHOP;
2915 - route.nh_count = 1;
2917 - olsr_malloc(route.nh_count * (sizeof route.nexthops->type + sizeof route.nexthops->payload), "zebra_add_olsr_v4_route");
2918 - route.nexthops->type = ZEBRA_NEXTHOP_IPV4;
2919 - route.nexthops->payload.v4 = r->rt_nexthop.gateway.v4.s_addr;
2920 + route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr;
2921 + route.ifindex_num = 0;
2922 + route.ifindex = NULL;
2923 + route.nexthop_num = 0;
2924 + route.nexthop = NULL;
2926 + if (r->rt_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr &&
2927 + route.prefixlen == 32){
2928 + return 0; /* Quagga BUG workaround: don't delete routes with destination = gateway
2929 + see http://lists.olsr.org/pipermail/olsr-users/2006-June/001726.html */
2930 + route.ifindex_num++;
2931 + route.ifindex = olsr_malloc (sizeof *route.ifindex,
2932 + "zebra_del_route");
2933 + *route.ifindex = r->rt_nexthop.iif_index;
2936 + route.nexthop_num++;
2937 + route.nexthop = olsr_malloc (sizeof *route.nexthop, "zebra_del_route");
2938 + route.nexthop->v4.s_addr = r->rt_nexthop.gateway.v4.s_addr;
2943 if (zebra.distance) {
2944 @@ -867,36 +557,23 @@
2945 route.distance = zebra.distance;
2948 - retval = zebra_delete_v4_route(route);
2950 - free_ipv4_route(route);
2951 + retval = zebra_send_command (zebra_route_packet (ZEBRA_IPV4_ROUTE_DELETE, &route));
2957 -zebra_olsr_distance(unsigned char dist)
2959 +void zebra_olsr_distance (unsigned char dist) {
2960 zebra.distance = dist;
2964 -zebra_olsr_localpref(void)
2966 +void zebra_olsr_localpref (void) {
2967 zebra.flags &= ZEBRA_FLAG_SELECTED;
2971 -zebra_export_routes(unsigned char t)
2973 +void zebra_export_routes (unsigned char t) {
2975 zebra.options |= OPTION_EXPORT;
2977 zebra.options &= ~OPTION_EXPORT;
2981 - * Local Variables:
2982 - * c-basic-offset: 2
2983 - * indent-tabs-mode: nil
2986 diff -Naur olsrd-0.5.6-r5/lib/quagga/src/quagga.h olsrd-0.5.6-r5.patched/lib/quagga/src/quagga.h
2987 --- olsrd-0.5.6-r5/lib/quagga/src/quagga.h 2009-06-24 20:00:51.000000000 +0300
2988 +++ olsrd-0.5.6-r5.patched/lib/quagga/src/quagga.h 2009-07-04 16:38:26.000000000 +0300
2991 + * OLSRd Quagga plugin
2993 + * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
2994 + * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
2996 + * This program is free software; you can redistribute it and/or modify
2997 + * it under the terms of the GNU General Public License version 2 as
2998 + * published by the Free Software Foundation or - at your option - under
2999 + * the terms of the GNU General Public Licence version 2 but can be
3000 + * linked to any BSD-Licenced Software with public available sourcecode
3004 +/* -------------------------------------------------------------------------
3006 + * Description : header file for quagga.c
3007 + * ------------------------------------------------------------------------- */
3009 -/***************************************************************************
3010 - projekt : olsrd-quagga
3012 - usage : header for quagga.c
3013 - copyright : (C) 2006 by Immo 'FaUl' Wehrenberg
3014 - e-mail : immo@chaostreff-dortmund.de
3015 - ***************************************************************************/
3017 -/***************************************************************************
3019 - * This program is free software; you can redistribute it and/or modify *
3020 - * it under the terms of the GNU General Public License version 2 as *
3021 - * published by the Free Software Foundation. *
3023 - ***************************************************************************/
3025 +#include "routing_table.h" /* rt_entry */
3026 +#include "olsr_types.h" /* olsr_ip_addr */
3031 -#include "routing_table.h"
3033 #define HAVE_SOCKLEN_T
3037 #define ZEBRA_PORT 2600
3040 +/* Zebra version */
3041 #ifdef ZEBRA_HEADER_MARKER
3042 #ifndef ZSERV_VERSION
3043 #define ZSERV_VERSION 1
3047 -struct ipv4_route {
3051 - uint8_t prefixlen;
3063 +#define ZEBRA_SOCKET "/var/run/quagga/zserv.api"
3065 +/* Zebra packet size */
3066 +#define ZEBRA_MAX_PACKET_SIZ 4096
3068 +/* Zebra message types */
3069 +#define ZEBRA_IPV4_ROUTE_ADD 7
3070 +#define ZEBRA_IPV4_ROUTE_DELETE 8
3071 +#define ZEBRA_REDISTRIBUTE_ADD 11
3072 +#define ZEBRA_REDISTRIBUTE_DELETE 12
3073 +#define ZEBRA_MESSAGE_MAX 23
3075 +/* Zebra route types */
3076 +#define ZEBRA_ROUTE_OLSR 11
3077 +#define ZEBRA_ROUTE_MAX 13
3080 +#define ZEBRA_FLAG_SELECTED 0x10
3082 +/* Zebra nexthop flags */
3083 +#define ZEBRA_NEXTHOP_IFINDEX 1
3084 +#define ZEBRA_NEXTHOP_IPV4 3
3086 +/* Zebra message flags */
3087 +#define ZAPI_MESSAGE_NEXTHOP 0x01
3088 +#define ZAPI_MESSAGE_IFINDEX 0x02
3089 +#define ZAPI_MESSAGE_DISTANCE 0x04
3090 +#define ZAPI_MESSAGE_METRIC 0x08
3093 +#define BUFSIZE 1024
3095 +/* Quagga plugin flags */
3096 +#define STATUS_CONNECTED 1
3097 +#define OPTION_EXPORT 1
3100 +struct zebra_route {
3101 + unsigned char type;
3102 + unsigned char flags;
3103 + unsigned char message;
3104 + unsigned char prefixlen;
3105 + union olsr_ip_addr prefix;
3106 + unsigned char nexthop_num;
3107 + union olsr_ip_addr *nexthop;
3108 + unsigned char ifindex_num;
3109 + uint32_t *ifindex;
3112 - struct ipv4_route *next;
3115 -void init_zebra(void);
3116 -void zebra_cleanup(void);
3117 -unsigned char zebra_send_command(unsigned char, unsigned char *, int);
3118 -int zebra_add_v4_route(const struct ipv4_route r);
3119 -int zebra_delete_v4_route(const struct ipv4_route r);
3120 -void zebra_check(void *);
3121 -int zebra_parse_packet(unsigned char *, ssize_t);
3122 -int zebra_redistribute(unsigned char);
3123 -int zebra_disable_redistribute(unsigned char);
3124 -int add_hna4_route(struct ipv4_route);
3125 -int delete_hna4_route(struct ipv4_route);
3126 -void *my_realloc(void *, size_t, const char *);
3127 -int zebra_add_olsr_v4_route(const struct rt_entry *);
3128 -int zebra_del_olsr_v4_route(const struct rt_entry *);
3129 -void zebra_olsr_localpref(void);
3130 -void zebra_olsr_distance(unsigned char);
3131 +void init_zebra (void);
3132 +void zebra_cleanup (void);
3133 +void zebra_parse (void*);
3134 +int zebra_redistribute (unsigned char);
3135 +int zebra_disable_redistribute (unsigned char);
3136 +int zebra_add_route (const struct rt_entry *);
3137 +int zebra_del_route (const struct rt_entry *);
3138 +void zebra_olsr_localpref (void);
3139 +void zebra_olsr_distance (unsigned char);
3140 void zebra_export_routes(unsigned char);
3143 - * Local Variables:
3144 - * c-basic-offset: 2
3145 - * indent-tabs-mode: nil
3148 diff -Naur olsrd-0.5.6-r5/lib/quagga/test/foo.c olsrd-0.5.6-r5.patched/lib/quagga/test/foo.c
3149 --- olsrd-0.5.6-r5/lib/quagga/test/foo.c 2009-06-24 20:00:51.000000000 +0300
3150 +++ olsrd-0.5.6-r5.patched/lib/quagga/test/foo.c 1970-01-01 02:00:00.000000000 +0200
3152 -#include "quagga.h"
3159 - zebra_redistribute(2);
3160 - // zebra_redistribute (1);
3167 - * Local Variables:
3168 - * c-basic-offset: 2
3169 - * indent-tabs-mode: nil
3172 diff -Naur olsrd-0.5.6-r5/lib/quagga/test/foo.pl olsrd-0.5.6-r5.patched/lib/quagga/test/foo.pl
3173 --- olsrd-0.5.6-r5/lib/quagga/test/foo.pl 2009-06-24 20:00:41.000000000 +0300
3174 +++ olsrd-0.5.6-r5.patched/lib/quagga/test/foo.pl 1970-01-01 02:00:00.000000000 +0200
3180 -$command = 11; # 11 = redistribute_add , 13 = redistribute_default_add
3182 -$proto = 2; # connected
3184 -$remote = IO::Socket::INET->new (Proto => "tcp",
3185 - PeerAddr => "127.0.0.1",
3186 - PeerPort => "2600",
3188 -$remote->autoflush (1);
3189 -#print $remote pack ("nc", 3, 13);
3190 -print $remote pack ("nc",3,1);
3191 -print $remote pack ("ncc", 4,$command,2);
3192 -print $remote pack ("ncccccNcNcNN", 25, 7, 10, 16, 11, 25, 0xc0a80206, 0, 0, 1, 5, 1);
3195 diff -Naur olsrd-0.5.6-r5/lib/quagga/test/quagga.try1.c olsrd-0.5.6-r5.patched/lib/quagga/test/quagga.try1.c
3196 --- olsrd-0.5.6-r5/lib/quagga/test/quagga.try1.c 2009-06-24 20:00:51.000000000 +0300
3197 +++ olsrd-0.5.6-r5.patched/lib/quagga/test/quagga.try1.c 1970-01-01 02:00:00.000000000 +0200
3201 - * (C) 2006 by Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
3203 - * This code is covered by the GPLv2
3207 -#include <stdint.h>
3211 -#include <sys/types.h>
3212 -#include <sys/socket.h>
3213 -#include <netinet/in.h>
3214 -#define HAVE_SOCKLEN_T
3215 -#include <quagga/zebra.h>
3216 -#include "quagga.h"
3222 -#include "local_hna_set.h"
3225 -#define ZAPI_MESSAGE_NEXTHOP 0x01
3226 -#define ZAPI_MESSAGE_IFINDEX 0x02
3227 -#define ZAPI_MESSAGE_DISTANCE 0x04
3228 -#define ZAPI_MESSAGE_METRIC 0x08
3230 -#define STATUS_CONNECTED 1
3231 -#define BUFSIZE 1024
3232 -static char status = 0;
3234 -static int zsock; // Socket to zebra...
3235 -struct ipv4_route *quagga_routes = 0; // routes currently exportet to zebra
3237 -/* prototypes ntern */
3238 -static char *try_read(ssize_t *);
3239 -static char *zebra_route_packet(struct ipv4_route r, ssize_t *);
3240 -static int parse_interface_add(char *, size_t);
3241 -static int parse_interface_delete(char *, size_t);
3242 -static int parse_interface_up(char *, size_t);
3243 -static int parse_interface_down(char *, size_t);
3244 -static int parse_interface_address_add(char *, size_t);
3245 -static int parse_interface_address_delete(char *, size_t);
3246 -static int parse_ipv4_route(char *, size_t, struct ipv4_route *);
3247 -static int ipv4_route_add(char *, size_t);
3248 -static int ipv4_route_delete(char *, size_t);
3249 -static int parse_ipv6_route_add(char *, size_t);
3250 -static uint32_t prefixlentomask(uint8_t);
3251 -static void free_ipv4_route(struct ipv4_route);
3252 -static void update_olsr_zebra_routes(struct ipv4_route *, struct ipv4_route *);
3253 -static struct ipv4_route *zebra_create_ipv4_route_table_entry(uint32_t, uint32_t, uint32_t);
3254 -static struct ipv4_route *zebra_create_ipv4_route_table(void);
3255 -static void zebra_free_ipv4_route_table(struct ipv4_route *);
3256 -static uint8_t masktoprefixlen(uint32_t);
3260 -dump_ipv4_route(struct ipv4_route r, char *c)
3265 - printf("type: %d\n", r.type);
3267 - printf(" Internal: %s\n", r.flags & ZEBRA_FLAG_INTERNAL ? "yes" : "no");
3268 - printf(" Selfroute %s\n", r.flags & ZEBRA_FLAG_SELFROUTE ? "yes" : "no");
3269 - printf(" Blackhole %s\n", r.flags & ZEBRA_FLAG_BLACKHOLE ? "yes" : "no");
3270 - printf(" IBGP: %s\n", r.flags & ZEBRA_FLAG_IBGP ? "yes" : "no");
3271 - printf(" Selected: %s\n", r.flags & ZEBRA_FLAG_SELECTED ? "yes" : "no");
3272 - printf(" Changed: %s\n", r.flags & ZEBRA_FLAG_CHANGED ? "yes" : "no");
3273 - printf(" static: %s\n", r.flags & ZEBRA_FLAG_STATIC ? "yes" : "no");
3274 - printf(" reject: %s\n", r.flags & ZEBRA_FLAG_REJECT ? "yes" : "no");
3276 - printf(" nexthop: %s\n", r.message & ZAPI_MESSAGE_NEXTHOP ? "yes" : "no");
3277 - printf(" ifindex: %s\n", r.message & ZAPI_MESSAGE_IFINDEX ? "yes" : "no");
3278 - printf(" distance: %s\n", r.message & ZAPI_MESSAGE_DISTANCE ? "yes" : "no");
3279 - printf(" metric: %s\n", r.message & ZAPI_MESSAGE_METRIC ? "yes" : "no");
3280 - printf("Prefixlen: %d\n", r.prefixlen);
3281 - printf("Prefix: %d", (unsigned char)r.prefix);
3282 - c = (char *)&r.prefix;
3283 - while (++i < (r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0)))
3284 - printf(".%d", (unsigned char)*(c + i));
3289 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
3291 - printf("nexthop-count: %d\n", r.nh_count);
3292 - while (i++ < r.nh_count) {
3293 - c = (unsigned char *)&r.nexthops[i];
3294 - printf("Nexthop %d: %d", i, (unsigned char)*c);
3296 - printf(".%d", (unsigned char)c[x]);
3302 - if (r.message & ZAPI_MESSAGE_IFINDEX) {
3304 - printf("index-number: %d\n", r.ind_num);
3305 - while (i++ < r.ind_num)
3306 - printf("Index: %d: %d\n", i, r.index[i]);
3308 - if (r.message & ZAPI_MESSAGE_DISTANCE)
3309 - printf("Distance: %d\n", r.distance);
3310 - if (r.message & ZAPI_MESSAGE_METRIC)
3311 - printf("Metric: %d\n", r.metric);
3318 -my_realloc(void *buf, size_t s, const char *c)
3320 - buf = realloc(buf, s);
3323 - OLSR_PRINTF(1, "OUT OF MEMORY: %s\n", strerror(errno));
3324 - olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n");
3325 - olsr_exit(c, EXIT_FAILURE);
3327 - exit(EXIT_FAILURE);
3333 -#ifndef OLSR_PLUGIN
3335 -olsr_malloc(size_t f, const char *c)
3337 - void *v = malloc(f);
3342 -/* Connect to the zebra-daemon, returns a socket */
3346 - struct sockaddr_in i;
3349 - zsock = socket(AF_INET, SOCK_STREAM, 0);
3350 - if (zsock < 0) // TODO: Could not create socket
3352 - memset(&i, 0, sizeof i);
3353 - i.sin_family = AF_INET;
3354 - i.sin_port = htons(ZEBRA_PORT);
3355 - // i.sin_len = sizeof i;
3356 - i.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
3358 - ret = connect(zsock, (struct sockaddr *)&i, sizeof i);
3363 - status |= STATUS_CONNECTED;
3367 -/* Sends a command to zebra, command is
3368 - the command defined in zebra.h, options is the packet-payload,
3369 - optlen the length, of the payload */
3371 -zebra_send_command(unsigned char command, char *options, int optlen)
3374 - char *p = olsr_malloc(optlen + 3, "zebra send_command");
3375 - uint16_t length = optlen + 3; // length of option + command + packet_length
3379 - uint16_t len = htons(length);
3380 - memcpy(p, &len, 2);
3382 - memcpy(p + 3, options, optlen);
3385 - ret = write(zsock, p, length);
3387 - if (errno == EINTR)
3393 - while ((length -= ret));
3398 -/* Creates a Route-Packet-Payload, needs address, netmask, nexthop,
3399 - distance, and a pointer of an size_t */
3401 -zebra_route_packet(struct ipv4_route r, ssize_t * optlen)
3405 - *optlen = 9; // first: type, flags, message, prefixlen, nexthop number, nexthop)
3406 - *optlen += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0);
3408 - cmdopt = olsr_malloc(*optlen, "zebra add_v4_route");
3410 - *t++ = 10; // Type: olsr
3411 - *t++ = r.flags; // flags
3412 - *t++ = r.message; // message: contains nexthop
3413 - *t++ = r.prefixlen;
3414 - memcpy(t, &r.prefix, r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0));
3415 - *t += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0);
3416 - *t++ = r.nh_count;
3417 - memcpy(t, r.nexthops, r.nh_count * sizeof *r.nexthops);
3421 -/* adds a route to zebra-daemon (needs socket from zebra,
3422 - address = prefix of the route
3423 - mask = netmask of the route
3424 - nexthop = nexthop of the route
3425 - distance = distance-value of the route
3428 -zebra_add_v4_route(struct ipv4_route r)
3434 - cmdopt = zebra_route_packet(r, &optlen);
3436 - puts("DEBUG: zebra_route_packet returned");
3438 - return zebra_send_command(ZEBRA_IPV4_ROUTE_ADD, cmdopt, optlen);
3442 -/* deletes a route from the zebra-daemon (
3443 - needs socket from zebra,
3444 - address = prefix of the route
3445 - mask = netmask of the route
3446 - nexthop = nexthop of the route
3447 - distance = distance-value of the route
3450 -zebra_delete_v4_route(struct ipv4_route r)
3456 - cmdopt = zebra_route_packet(r, &optlen);
3458 - return zebra_send_command(ZEBRA_IPV4_ROUTE_DELETE, cmdopt, optlen);
3462 -/* Check wether there is data from zebra aviable */
3464 -zebra_check(void *foo)
3469 - if (!status & STATUS_CONNECTED) {
3471 - data = try_read(&len);
3475 - ret = zebra_parse_packet(f, len);
3476 - if (!ret) { //something wired happened
3477 - puts("DEBUG: IIIIIIIIIIRGS");
3478 - exit(EXIT_FAILURE);
3482 - while ((f - data) < len);
3487 -// tries to read a packet from zebra_socket
3488 -// if there is something to read - make sure to read whole packages
3490 -try_read(ssize_t * len)
3493 - ssize_t ret = 0, bsize = 0;
3494 - uint16_t length = 0, l = 0;
3499 - sockstate = fcntl(zsock, F_GETFL, 0);
3500 - fcntl(zsock, F_SETFL, sockstate | O_NONBLOCK);
3503 - if (*len == bsize) {
3505 - buf = my_realloc(buf, bsize, "Zebra try_read");
3507 - ret = read(zsock, buf + l, bsize - l);
3509 - if (errno == EAGAIN) {
3512 - // TODO: errorhandling
3520 - while ((*len - l) > length) {
3521 - // printf ("DEBUG: *len -l > length - %d - %d > %d\n", *len, l, length);
3523 - memcpy(&length, buf + l, 2);
3524 - length = ntohs(length);
3526 - // printf ("DEBUG: *len, l, length: %d,%d,%d\n", *len, l, length);
3527 - if (((*len) - l) == length)
3528 - break; // GOT FULL PACKAGE!!
3530 - // printf ("DEBUG: *len, l, length: %d,%d,%d\n", *len, l, length);
3531 - fcntl(zsock, F_SETFL, sockstate);
3537 - fcntl(zsock, F_SETFL, sockstate);
3541 -/* Parse a packet recived from zebra */
3543 -zebra_parse_packet(char *packet, ssize_t maxlen)
3546 - /* Array of functions */
3547 - int (*foo[ZEBRA_MESSAGE_MAX]) (char *, size_t) = {
3548 - parse_interface_add, parse_interface_delete, parse_interface_address_add, parse_interface_address_delete, parse_interface_up,
3549 - parse_interface_down, ipv4_route_add, ipv4_route_delete, parse_ipv6_route_add};
3551 - puts("DEBUG: zebra_parse_packet");
3555 - memcpy(&length, packet, 2);
3556 - length = ntohs(length);
3558 - if (maxlen < length) {
3559 - puts("Error: programmer is an idiot");
3560 - printf("DEBUG: maxlen = %d, packet_length = %d\n", maxlen, length);
3564 - if (packet[2] - 1 < ZEBRA_MESSAGE_MAX && foo[packet[2] - 1]) {
3565 - if (!(ret = foo[packet[2] - 1] (packet + 3, length - 3)))
3568 - printf("DEBUG: Parse error: %d\n", ret);
3570 - printf("Unknown packet type: %d\n", packet[2]);
3572 - puts("Quagga: RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE");
3578 -parse_interface_add(char *opt, size_t len)
3585 -parse_interface_delete(char *opt, size_t len)
3592 -parse_interface_address_add(char *opt, size_t len)
3600 -parse_interface_up(char *opt, size_t len)
3608 -parse_interface_down(char *opt, size_t len)
3616 -parse_interface_address_delete(char *opt, size_t len)
3622 -/* Parse an ipv4-route-packet recived from zebra
3625 -parse_ipv4_route(char *opt, size_t len, struct ipv4_route *r)
3627 - // puts ("DEBUG: parse_ipv4_route");
3632 - r->flags = *opt++;
3633 - r->message = *opt++;
3634 - r->prefixlen = *opt++;
3638 - if ((int)len < r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0))
3641 - memcpy(&r->prefix, opt, r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0));
3642 - opt += r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0);
3644 - if (r->message & ZAPI_MESSAGE_NEXTHOP) {
3647 - r->nh_count = *opt++;
3648 - if (len < sizeof(uint32_t) * r->nh_count)
3650 - r->nexthops = olsr_malloc(sizeof(uint32_t) * r->nh_count, "quagga: parse_ipv4_route_add");
3651 - memcpy(r->nexthops, opt, sizeof(uint32_t) * r->nh_count);
3652 - opt += sizeof(uint32_t) * r->nh_count;
3653 - len -= sizeof(uint32_t) * r->nh_count + 1;
3656 - if (r->message & ZAPI_MESSAGE_IFINDEX) {
3659 - r->ind_num = *opt++;
3660 - if (len < sizeof(uint32_t) * r->ind_num)
3662 - r->index = olsr_malloc(sizeof(uint32_t) * r->ind_num, "quagga: parse_ipv4_route_add");
3663 - memcpy(r->index, opt, r->ind_num * sizeof(uint32_t));
3664 - opt += sizeof(uint32_t) * r->ind_num;
3665 - len -= sizeof(uint32_t) * r->ind_num;
3668 - if (r->message & ZAPI_MESSAGE_DISTANCE)
3672 - if (r->message & ZAPI_MESSAGE_METRIC) {
3673 - if (len < sizeof(uint32_t))
3675 - memcpy(&r->metric, opt, sizeof(uint32_t));
3682 -ipv4_route_add(char *opt, size_t len)
3685 - struct ipv4_route r;
3688 - // puts ("DEBUG: ipv4_route_add");
3690 - f = parse_ipv4_route(opt, len, &r);
3692 - printf("parse-error: %d\n", f);
3696 - add_hna4_route(r);
3701 -ipv4_route_delete(char *opt, size_t len)
3703 - struct ipv4_route r;
3706 - f = parse_ipv4_route(opt, len, &r);
3710 - return delete_hna4_route(r);
3711 - // OK, now delete that foo
3716 -parse_ipv6_route_add(char *opt, size_t len)
3722 -/* start redistribution FROM zebra */
3724 -zebra_redistribute(unsigned char type)
3727 - return zebra_send_command(ZEBRA_REDISTRIBUTE_ADD, &type, 1);
3731 -/* end redistribution FROM zebra */
3733 -zebra_disable_redistribute(unsigned char type)
3736 - return zebra_send_command(ZEBRA_REDISTRIBUTE_DELETE, &type, 1);
3741 -prefixlentomask(uint8_t prefix)
3744 - mask = prefix_to_netmask4(prefix);
3745 - mask = ntohl(mask);
3750 -add_hna4_route(struct ipv4_route r)
3752 - union olsr_ip_addr net, mask;
3755 - dump_ipv4_route(r, "add_hna4_route");
3758 - mask.v4 = prefixlentomask(r.prefixlen);
3759 - net.v4 = r.prefix;
3762 - add_local_hna4_entry(&net, &mask);
3764 - free_ipv4_route(r);
3769 -delete_hna4_route(struct ipv4_route r)
3772 - union olsr_ip_addr net, mask;
3775 - dump_ipv4_route(r, "delete_hna4_route");
3778 - mask.v4 = prefixlentomask(r.prefixlen);
3779 - net.v4 = r.prefix;
3782 - return remove_local_hna4_entry(&net, &mask) ? 0 : -1;
3785 - free_ipv4_route(r);
3791 -free_ipv4_route(struct ipv4_route r)
3794 - if (r.message & ZAPI_MESSAGE_IFINDEX && r.ind_num)
3796 - if (r.message & ZAPI_MESSAGE_NEXTHOP && r.nh_count)
3802 -zebra_clear_routes(void)
3805 - struct ipv4_route *t;
3807 - t = quagga_routes;
3809 - zebra_delete_v4_route(*t);
3812 - zebra_free_ipv4_route_table(quagga_routes);
3814 - quagga_routes = NULL;
3818 -zebra_update_hna(void *f)
3821 - struct ipv4_route *a = zebra_create_ipv4_route_table();
3822 - update_olsr_zebra_routes(a, quagga_routes);
3823 - zebra_free_ipv4_route_table(quagga_routes);
3825 - quagga_routes = a;
3829 -static struct ipv4_route *
3830 -zebra_create_ipv4_route_table(void)
3833 - struct ipv4_route *r = 0, *t = 0 /* make compiler happy */ ;
3835 - struct hna_entry *e;
3836 - struct hna_net *n;
3838 - for (i = 0; i < HASHSIZE; i++) {
3839 - e = hna_set[i].next;
3840 - for (; e != &hna_set[i]; e = e->next) {
3841 - n = e->networks.next;
3842 - for (; n != &e->networks; n = n->next) {
3844 - r = zebra_create_ipv4_route_table_entry(n->A_network_addr.v4, n->A_netmask.v4, e->A_gateway_addr.v4);
3847 - t->next = zebra_create_ipv4_route_table_entry(n->A_network_addr.v4, n->A_netmask.v4, e->A_gateway_addr.v4);
3858 -static struct ipv4_route *
3859 -zebra_create_ipv4_route_table_entry(uint32_t addr, uint32_t mask, uint32_t gw)
3862 - struct ipv4_route *r;
3864 - r = olsr_malloc(sizeof *r, "zebra_create_ipv4_route_table_entry");
3865 - memset(r, 0, sizeof *r);
3867 - r->prefixlen = masktoprefixlen(mask);
3868 - r->message |= ZAPI_MESSAGE_NEXTHOP;
3870 - r->nexthops = olsr_malloc(sizeof(uint32_t), "zebra_create_ipv4_route_table_entry");
3871 - *r->nexthops = gw;
3878 -masktoprefixlen(uint32_t mask)
3881 - uint8_t prefixlen = 0;
3882 -while (mask & (1 << ++prefixlen && prefixlen < 32); return prefixlen;}
3884 - static void update_olsr_zebra_routes(struct ipv4_route *a, struct ipv4_route *r) {
3886 - struct ipv4_route * t; if (!r) {
3887 - puts("no quagga_routing_table aviable"); for (; a; a = a->next) {
3888 - dump_ipv4_route(*a, "adding this route");
3889 - // zebra_add_v4_route(*r);
3894 - for (t = r; t; t = t->next) {
3895 - if (a->prefix == t->prefix) if (a->prefixlen == t->prefixlen) if (*a->nexthops == *t->nexthops) {
3898 - dump_ipv4_route(*a, "adding this route");
3899 - //zebra_add_v4_route(*a);
3904 - for (t = a; t; t = t->next) {
3905 - if (r->prefix == t->prefix) if (r->prefixlen == t->prefixlen) if (*r->nexthops == *t->nexthops) {
3908 - dump_ipv4_route(*r, "deleting this route");
3909 - //zebra_delete_v4_route(*r);
3915 - static void zebra_free_ipv4_route_table(struct ipv4_route *r) {
3916 - struct ipv4_route * n; if (!r) return; while ((n = r->next)) {
3917 - if (r->message & ZAPI_MESSAGE_NEXTHOP) free(r->nexthops); if (r->message & ZAPI_MESSAGE_IFINDEX) free(r->index); free(r);
3922 - * Local Variables:
3923 - * c-basic-offset: 2
3924 - * indent-tabs-mode: nil