1 --- a/lib/quagga/Makefile
2 +++ b/lib/quagga/Makefile
4 PLUGIN_NAME = olsrd_quagga
9 include $(TOPDIR)/Makefile.inc
11 -#CPPFLAGS +=-DMY_DEBUG
13 CPPFLAGS +=-DUSE_UNIX_DOMAIN_SOCKET
15 -#uncomment the following line only if you are sure what you're doing, it will
16 -#probably break things!
17 -# CPPFLAGS +=-DZEBRA_HEADER_MARKER=255
21 default_target install clean:
22 - @echo "**** Quagga not supportet on Windows (so it would be pointless to build the Quagga Plugin)"
23 + @echo "*** Quagga not supported on Windows (so it would be pointless to build the Quagga plugin)"
27 default_target: $(PLUGIN_FULLNAME)
29 $(PLUGIN_FULLNAME): $(OBJS) version-script.txt
33 rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
37 +++ b/lib/quagga/patches/quagga-0.98.6.diff
39 +diff -Nur quagga-0.98.6/bgpd/bgp_vty.c quagga-0.98.6.patched/bgpd/bgp_vty.c
40 +--- quagga-0.98.6/bgpd/bgp_vty.c 2006-03-30 18:12:25.000000000 +0200
41 ++++ quagga-0.98.6.patched/bgpd/bgp_vty.c 2007-12-30 14:18:22.000000000 +0200
44 + This file is part of GNU Zebra.
46 ++This file was modified from the original on 30/12/2007
47 ++by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
49 + GNU Zebra is free software; you can redistribute it and/or modify it
50 + under the terms of the GNU General Public License as published by the
51 + Free Software Foundation; either version 2, or (at your option) any
52 +@@ -7793,8 +7796,12 @@
53 + return ZEBRA_ROUTE_STATIC;
54 + else if (strncmp (str, "r", 1) == 0)
55 + return ZEBRA_ROUTE_RIP;
56 +- else if (strncmp (str, "o", 1) == 0)
57 ++ else if (strncmp (str, "ol", 2) == 0)
58 ++ return ZEBRA_ROUTE_OLSR;
59 ++ else if (strncmp (str, "os", 2) == 0)
60 + return ZEBRA_ROUTE_OSPF;
61 ++ else if (strncmp (str, "ba", 2) == 0)
62 ++ return ZEBRA_ROUTE_BATMAN;
66 +@@ -7806,21 +7813,28 @@
67 + return ZEBRA_ROUTE_STATIC;
68 + else if (strncmp (str, "r", 1) == 0)
69 + return ZEBRA_ROUTE_RIPNG;
70 +- else if (strncmp (str, "o", 1) == 0)
71 ++ else if (strncmp (str, "os", 2) == 0)
72 + return ZEBRA_ROUTE_OSPF6;
73 ++ else if (strncmp (str, "ol", 2) == 0)
74 ++ return ZEBRA_ROUTE_OLSR;
75 ++ else if (strncmp (str, "ba", 2) == 0)
76 ++ return ZEBRA_ROUTE_BATMAN;
81 + DEFUN (bgp_redistribute_ipv4,
82 + bgp_redistribute_ipv4_cmd,
83 +- "redistribute (connected|kernel|ospf|rip|static)",
84 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman)",
85 + "Redistribute information from another routing protocol\n"
88 + "Open Shurtest Path First (OSPF)\n"
89 + "Routing Information Protocol (RIP)\n"
92 ++ "Optimized Link State Routing (OLSR)\n"
93 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
98 +@@ -7835,13 +7849,15 @@
100 + DEFUN (bgp_redistribute_ipv4_rmap,
101 + bgp_redistribute_ipv4_rmap_cmd,
102 +- "redistribute (connected|kernel|ospf|rip|static) route-map WORD",
103 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD",
104 + "Redistribute information from another routing protocol\n"
107 + "Open Shurtest Path First (OSPF)\n"
108 + "Routing Information Protocol (RIP)\n"
110 ++ "Optimized Link State Routing (OLSR)\n"
111 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
112 + "Route map reference\n"
113 + "Pointer to route-map entries\n")
115 +@@ -7860,13 +7876,15 @@
117 + DEFUN (bgp_redistribute_ipv4_metric,
118 + bgp_redistribute_ipv4_metric_cmd,
119 +- "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
120 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295>",
121 + "Redistribute information from another routing protocol\n"
124 + "Open Shurtest Path First (OSPF)\n"
125 + "Routing Information Protocol (RIP)\n"
127 ++ "Optimized Link State Routing (OLSR)\n"
128 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
129 + "Metric for redistributed routes\n"
130 + "Default metric\n")
132 +@@ -7887,13 +7905,15 @@
134 + DEFUN (bgp_redistribute_ipv4_rmap_metric,
135 + bgp_redistribute_ipv4_rmap_metric_cmd,
136 +- "redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
137 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD metric <0-4294967295>",
138 + "Redistribute information from another routing protocol\n"
141 + "Open Shurtest Path First (OSPF)\n"
142 + "Routing Information Protocol (RIP)\n"
144 ++ "Optimized Link State Routing (OLSR)\n"
145 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
146 + "Route map reference\n"
147 + "Pointer to route-map entries\n"
148 + "Metric for redistributed routes\n"
149 +@@ -7917,13 +7937,15 @@
151 + DEFUN (bgp_redistribute_ipv4_metric_rmap,
152 + bgp_redistribute_ipv4_metric_rmap_cmd,
153 +- "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
154 ++ "redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295> route-map WORD",
155 + "Redistribute information from another routing protocol\n"
158 + "Open Shurtest Path First (OSPF)\n"
159 + "Routing Information Protocol (RIP)\n"
161 ++ "Optimized Link State Routing (OLSR)\n"
162 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
163 + "Metric for redistributed routes\n"
165 + "Route map reference\n"
166 +@@ -7947,14 +7969,17 @@
168 + DEFUN (no_bgp_redistribute_ipv4,
169 + no_bgp_redistribute_ipv4_cmd,
170 +- "no redistribute (connected|kernel|ospf|rip|static)",
171 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman)",
173 + "Redistribute information from another routing protocol\n"
176 + "Open Shurtest Path First (OSPF)\n"
177 + "Routing Information Protocol (RIP)\n"
178 +- "Static routes\n")
180 ++ "Optimized Link State Routing (OLSR)\n"
181 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
186 +@@ -7970,7 +7995,7 @@
188 + DEFUN (no_bgp_redistribute_ipv4_rmap,
189 + no_bgp_redistribute_ipv4_rmap_cmd,
190 +- "no redistribute (connected|kernel|ospf|rip|static) route-map WORD",
191 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD",
193 + "Redistribute information from another routing protocol\n"
195 +@@ -7978,6 +8003,8 @@
196 + "Open Shurtest Path First (OSPF)\n"
197 + "Routing Information Protocol (RIP)\n"
199 ++ "Optimized Link State Routing (OLSR)\n"
200 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
201 + "Route map reference\n"
202 + "Pointer to route-map entries\n")
204 +@@ -7996,7 +8023,7 @@
206 + DEFUN (no_bgp_redistribute_ipv4_metric,
207 + no_bgp_redistribute_ipv4_metric_cmd,
208 +- "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
209 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295>",
211 + "Redistribute information from another routing protocol\n"
213 +@@ -8004,6 +8031,8 @@
214 + "Open Shurtest Path First (OSPF)\n"
215 + "Routing Information Protocol (RIP)\n"
217 ++ "Optimized Link State Routing (OLSR)\n"
218 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
219 + "Metric for redistributed routes\n"
220 + "Default metric\n")
222 +@@ -8022,7 +8051,7 @@
224 + DEFUN (no_bgp_redistribute_ipv4_rmap_metric,
225 + no_bgp_redistribute_ipv4_rmap_metric_cmd,
226 +- "no redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
227 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD metric <0-4294967295>",
229 + "Redistribute information from another routing protocol\n"
231 +@@ -8030,6 +8059,8 @@
232 + "Open Shurtest Path First (OSPF)\n"
233 + "Routing Information Protocol (RIP)\n"
235 ++ "Optimized Link State Routing (OLSR)\n"
236 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
237 + "Route map reference\n"
238 + "Pointer to route-map entries\n"
239 + "Metric for redistributed routes\n"
240 +@@ -8051,7 +8082,7 @@
242 + ALIAS (no_bgp_redistribute_ipv4_rmap_metric,
243 + no_bgp_redistribute_ipv4_metric_rmap_cmd,
244 +- "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
245 ++ "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295> route-map WORD",
247 + "Redistribute information from another routing protocol\n"
249 +@@ -8059,6 +8090,8 @@
250 + "Open Shurtest Path First (OSPF)\n"
251 + "Routing Information Protocol (RIP)\n"
253 ++ "Optimized Link State Routing (OLSR)\n"
254 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
255 + "Metric for redistributed routes\n"
257 + "Route map reference\n"
258 +@@ -8067,13 +8100,16 @@
260 + DEFUN (bgp_redistribute_ipv6,
261 + bgp_redistribute_ipv6_cmd,
262 +- "redistribute (connected|kernel|ospf6|ripng|static)",
263 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman)",
264 + "Redistribute information from another routing protocol\n"
267 + "Open Shurtest Path First (OSPFv3)\n"
268 + "Routing Information Protocol (RIPng)\n"
269 +- "Static routes\n")
271 ++ "Optimized Link State Routing (OLSR)\n"
272 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
277 +@@ -8089,13 +8125,15 @@
279 + DEFUN (bgp_redistribute_ipv6_rmap,
280 + bgp_redistribute_ipv6_rmap_cmd,
281 +- "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
282 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD",
283 + "Redistribute information from another routing protocol\n"
286 + "Open Shurtest Path First (OSPFv3)\n"
287 + "Routing Information Protocol (RIPng)\n"
289 ++ "Optimized Link State Routing (OLSR)\n"
290 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
291 + "Route map reference\n"
292 + "Pointer to route-map entries\n")
294 +@@ -8114,13 +8152,15 @@
296 + DEFUN (bgp_redistribute_ipv6_metric,
297 + bgp_redistribute_ipv6_metric_cmd,
298 +- "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
299 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295>",
300 + "Redistribute information from another routing protocol\n"
303 + "Open Shurtest Path First (OSPFv3)\n"
304 + "Routing Information Protocol (RIPng)\n"
306 ++ "Optimized Link State Routing (OLSR)\n"
307 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
308 + "Metric for redistributed routes\n"
309 + "Default metric\n")
311 +@@ -8141,13 +8181,15 @@
313 + DEFUN (bgp_redistribute_ipv6_rmap_metric,
314 + bgp_redistribute_ipv6_rmap_metric_cmd,
315 +- "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
316 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD metric <0-4294967295>",
317 + "Redistribute information from another routing protocol\n"
320 + "Open Shurtest Path First (OSPFv3)\n"
321 + "Routing Information Protocol (RIPng)\n"
323 ++ "Optimized Link State Routing (OLSR)\n"
324 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
325 + "Route map reference\n"
326 + "Pointer to route-map entries\n"
327 + "Metric for redistributed routes\n"
328 +@@ -8171,13 +8213,15 @@
330 + DEFUN (bgp_redistribute_ipv6_metric_rmap,
331 + bgp_redistribute_ipv6_metric_rmap_cmd,
332 +- "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
333 ++ "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295> route-map WORD",
334 + "Redistribute information from another routing protocol\n"
337 + "Open Shurtest Path First (OSPFv3)\n"
338 + "Routing Information Protocol (RIPng)\n"
340 ++ "Optimized Link State Routing (OLSR)\n"
341 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
342 + "Metric for redistributed routes\n"
344 + "Route map reference\n"
345 +@@ -8201,14 +8245,17 @@
347 + DEFUN (no_bgp_redistribute_ipv6,
348 + no_bgp_redistribute_ipv6_cmd,
349 +- "no redistribute (connected|kernel|ospf6|ripng|static)",
350 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman)",
352 + "Redistribute information from another routing protocol\n"
355 + "Open Shurtest Path First (OSPFv3)\n"
356 + "Routing Information Protocol (RIPng)\n"
357 +- "Static routes\n")
359 ++ "Optimized Link State Routing (OLSR)\n"
360 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
365 +@@ -8224,7 +8271,7 @@
367 + DEFUN (no_bgp_redistribute_ipv6_rmap,
368 + no_bgp_redistribute_ipv6_rmap_cmd,
369 +- "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
370 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD",
372 + "Redistribute information from another routing protocol\n"
374 +@@ -8232,6 +8279,8 @@
375 + "Open Shurtest Path First (OSPFv3)\n"
376 + "Routing Information Protocol (RIPng)\n"
378 ++ "Optimized Link State Routing (OLSR)\n"
379 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
380 + "Route map reference\n"
381 + "Pointer to route-map entries\n")
383 +@@ -8250,7 +8299,7 @@
385 + DEFUN (no_bgp_redistribute_ipv6_metric,
386 + no_bgp_redistribute_ipv6_metric_cmd,
387 +- "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
388 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295>",
390 + "Redistribute information from another routing protocol\n"
392 +@@ -8258,6 +8307,8 @@
393 + "Open Shurtest Path First (OSPFv3)\n"
394 + "Routing Information Protocol (RIPng)\n"
396 ++ "Optimized Link State Routing (OLSR)\n"
397 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
398 + "Metric for redistributed routes\n"
399 + "Default metric\n")
401 +@@ -8276,7 +8327,7 @@
403 + DEFUN (no_bgp_redistribute_ipv6_rmap_metric,
404 + no_bgp_redistribute_ipv6_rmap_metric_cmd,
405 +- "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
406 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD metric <0-4294967295>",
408 + "Redistribute information from another routing protocol\n"
410 +@@ -8284,6 +8335,8 @@
411 + "Open Shurtest Path First (OSPFv3)\n"
412 + "Routing Information Protocol (RIPng)\n"
414 ++ "Optimized Link State Routing (OLSR)\n"
415 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
416 + "Route map reference\n"
417 + "Pointer to route-map entries\n"
418 + "Metric for redistributed routes\n"
419 +@@ -8305,7 +8358,7 @@
421 + ALIAS (no_bgp_redistribute_ipv6_rmap_metric,
422 + no_bgp_redistribute_ipv6_metric_rmap_cmd,
423 +- "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
424 ++ "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295> route-map WORD",
426 + "Redistribute information from another routing protocol\n"
428 +@@ -8313,6 +8366,8 @@
429 + "Open Shurtest Path First (OSPFv3)\n"
430 + "Routing Information Protocol (RIPng)\n"
432 ++ "Optimized Link State Routing (OLSR)\n"
433 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
434 + "Metric for redistributed routes\n"
436 + "Route map reference\n"
437 +@@ -8325,7 +8380,7 @@
440 + const char *str[] = { "system", "kernel", "connected", "static", "rip",
441 +- "ripng", "ospf", "ospf6", "isis", "bgp"};
442 ++ "ripng", "ospf", "ospf6", "isis", "bgp", "hsls", "olsr", "batman"};
444 + /* Unicast redistribution only. */
445 + if (safi != SAFI_UNICAST)
446 +diff -Nur quagga-0.98.6/lib/zebra.h quagga-0.98.6.patched/lib/zebra.h
447 +--- quagga-0.98.6/lib/zebra.h 2005-06-15 14:54:18.000000000 +0300
448 ++++ quagga-0.98.6.patched/lib/zebra.h 2007-12-30 14:18:22.000000000 +0200
451 + This file is part of GNU Zebra.
453 ++This file was modified from the original on 30/12/2007
454 ++by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
456 + GNU Zebra is free software; you can redistribute it and/or modify it
457 + under the terms of the GNU General Public License as published by the
458 + Free Software Foundation; either version 2, or (at your option) any
460 + #define ZEBRA_ROUTE_ISIS 8
461 + #define ZEBRA_ROUTE_BGP 9
462 + #define ZEBRA_ROUTE_HSLS 10
463 +-#define ZEBRA_ROUTE_MAX 11
464 ++#define ZEBRA_ROUTE_OLSR 11
465 ++#define ZEBRA_ROUTE_BATMAN 12
466 ++#define ZEBRA_ROUTE_MAX 13
468 + /* Zebra's family types. */
469 + #define ZEBRA_FAMILY_IPV4 1
470 +diff -Nur quagga-0.98.6/ospfd/ospf_vty.c quagga-0.98.6.patched/ospfd/ospf_vty.c
471 +--- quagga-0.98.6/ospfd/ospf_vty.c 2006-03-30 17:41:20.000000000 +0200
472 ++++ quagga-0.98.6.patched/ospfd/ospf_vty.c 2007-12-30 14:18:22.000000000 +0200
475 + * This file is part of GNU Zebra.
477 ++ * This file was modified from the original on 30/12/2007
478 ++ * by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
480 + * GNU Zebra is free software; you can redistribute it and/or modify it
481 + * under the terms of the GNU General Public License as published by the
482 + * Free Software Foundation; either version 2, or (at your option) any
483 +@@ -106,11 +109,15 @@
484 + *source = ZEBRA_ROUTE_STATIC;
485 + else if (strncmp (str, "r", 1) == 0)
486 + *source = ZEBRA_ROUTE_RIP;
487 +- else if (strncmp (str, "b", 1) == 0)
488 ++ else if (strncmp (str, "bg", 2) == 0)
489 + *source = ZEBRA_ROUTE_BGP;
490 ++ else if (strncmp (str, "ol", 2) == 0)
491 ++ *source = ZEBRA_ROUTE_OLSR;
492 ++ else if (strncmp (str, "ba", 2) == 0)
493 ++ *source = ZEBRA_ROUTE_BATMAN;
501 +@@ -5302,13 +5309,15 @@
503 + DEFUN (ospf_redistribute_source_metric_type,
504 + ospf_redistribute_source_metric_type_routemap_cmd,
505 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> metric-type (1|2) route-map WORD",
506 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> metric-type (1|2) route-map WORD",
507 + "Redistribute information from another routing protocol\n"
511 + "Routing Information Protocol (RIP)\n"
512 + "Border Gateway Protocol (BGP)\n"
513 ++ "Optimized Link State Routing (OLSR)\n"
514 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
515 + "Metric for redistributed routes\n"
516 + "OSPF default metric\n"
517 + "OSPF exterior metric type for redistributed routes\n"
518 +@@ -5346,13 +5355,15 @@
520 + ALIAS (ospf_redistribute_source_metric_type,
521 + ospf_redistribute_source_metric_type_cmd,
522 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> metric-type (1|2)",
523 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> metric-type (1|2)",
524 + "Redistribute information from another routing protocol\n"
528 + "Routing Information Protocol (RIP)\n"
529 + "Border Gateway Protocol (BGP)\n"
530 ++ "Optimized Link State Routing (OLSR)\n"
531 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
532 + "Metric for redistributed routes\n"
533 + "OSPF default metric\n"
534 + "OSPF exterior metric type for redistributed routes\n"
535 +@@ -5361,25 +5372,29 @@
537 + ALIAS (ospf_redistribute_source_metric_type,
538 + ospf_redistribute_source_metric_cmd,
539 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214>",
540 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214>",
541 + "Redistribute information from another routing protocol\n"
545 + "Routing Information Protocol (RIP)\n"
546 + "Border Gateway Protocol (BGP)\n"
547 ++ "Optimized Link State Routing (OLSR)\n"
548 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
549 + "Metric for redistributed routes\n"
550 + "OSPF default metric\n")
552 + DEFUN (ospf_redistribute_source_type_metric,
553 + ospf_redistribute_source_type_metric_routemap_cmd,
554 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) metric <0-16777214> route-map WORD",
555 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) metric <0-16777214> route-map WORD",
556 + "Redistribute information from another routing protocol\n"
560 + "Routing Information Protocol (RIP)\n"
561 + "Border Gateway Protocol (BGP)\n"
562 ++ "Optimized Link State Routing (OLSR)\n"
563 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
564 + "OSPF exterior metric type for redistributed routes\n"
565 + "Set OSPF External Type 1 metrics\n"
566 + "Set OSPF External Type 2 metrics\n"
567 +@@ -5417,13 +5432,15 @@
569 + ALIAS (ospf_redistribute_source_type_metric,
570 + ospf_redistribute_source_type_metric_cmd,
571 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) metric <0-16777214>",
572 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) metric <0-16777214>",
573 + "Redistribute information from another routing protocol\n"
577 + "Routing Information Protocol (RIP)\n"
578 + "Border Gateway Protocol (BGP)\n"
579 ++ "Optimized Link State Routing (OLSR)\n"
580 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
581 + "OSPF exterior metric type for redistributed routes\n"
582 + "Set OSPF External Type 1 metrics\n"
583 + "Set OSPF External Type 2 metrics\n"
584 +@@ -5432,7 +5449,7 @@
586 + ALIAS (ospf_redistribute_source_type_metric,
587 + ospf_redistribute_source_type_cmd,
588 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2)",
589 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2)",
590 + "Redistribute information from another routing protocol\n"
593 +@@ -5440,28 +5457,35 @@
594 + "Routing Information Protocol (RIP)\n"
595 + "Border Gateway Protocol (BGP)\n"
596 + "OSPF exterior metric type for redistributed routes\n"
597 ++ "Optimized Link State Routing (OLSR)\n"
598 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
599 + "Set OSPF External Type 1 metrics\n"
600 + "Set OSPF External Type 2 metrics\n")
602 + ALIAS (ospf_redistribute_source_type_metric,
603 + ospf_redistribute_source_cmd,
604 +- "redistribute (kernel|connected|static|rip|bgp)",
605 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman)",
606 + "Redistribute information from another routing protocol\n"
610 + "Routing Information Protocol (RIP)\n"
611 +- "Border Gateway Protocol (BGP)\n")
612 ++ "Border Gateway Protocol (BGP)\n"
613 ++ "Optimized Link State Routing (OLSR)\n"
614 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
617 + DEFUN (ospf_redistribute_source_metric_routemap,
618 + ospf_redistribute_source_metric_routemap_cmd,
619 +- "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> route-map WORD",
620 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> route-map WORD",
621 + "Redistribute information from another routing protocol\n"
625 + "Routing Information Protocol (RIP)\n"
626 + "Border Gateway Protocol (BGP)\n"
627 ++ "Optimized Link State Routing (OLSR)\n"
628 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
629 + "Metric for redistributed routes\n"
630 + "OSPF default metric\n"
631 + "Route map reference\n"
632 +@@ -5490,13 +5514,15 @@
634 + DEFUN (ospf_redistribute_source_type_routemap,
635 + ospf_redistribute_source_type_routemap_cmd,
636 +- "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) route-map WORD",
637 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) route-map WORD",
638 + "Redistribute information from another routing protocol\n"
642 + "Routing Information Protocol (RIP)\n"
643 + "Border Gateway Protocol (BGP)\n"
644 ++ "Optimized Link State Routing (OLSR)\n"
645 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
646 + "OSPF exterior metric type for redistributed routes\n"
647 + "Set OSPF External Type 1 metrics\n"
648 + "Set OSPF External Type 2 metrics\n"
649 +@@ -5526,13 +5552,15 @@
651 + DEFUN (ospf_redistribute_source_routemap,
652 + ospf_redistribute_source_routemap_cmd,
653 +- "redistribute (kernel|connected|static|rip|bgp) route-map WORD",
654 ++ "redistribute (kernel|connected|static|rip|bgp|olsr|batman) route-map WORD",
655 + "Redistribute information from another routing protocol\n"
659 + "Routing Information Protocol (RIP)\n"
660 + "Border Gateway Protocol (BGP)\n"
661 ++ "Optimized Link State Routing (OLSR)\n"
662 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
663 + "Route map reference\n"
664 + "Pointer to route-map entries\n")
666 +@@ -5553,14 +5581,17 @@
668 + DEFUN (no_ospf_redistribute_source,
669 + no_ospf_redistribute_source_cmd,
670 +- "no redistribute (kernel|connected|static|rip|bgp)",
671 ++ "no redistribute (kernel|connected|static|rip|bgp|olsr|batman)",
673 + "Redistribute information from another routing protocol\n"
677 + "Routing Information Protocol (RIP)\n"
678 +- "Border Gateway Protocol (BGP)\n")
679 ++ "Border Gateway Protocol (BGP)\n"
680 ++ "Optimized Link State Routing (OLSR)\n"
681 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
684 + struct ospf *ospf = vty->index;
686 +@@ -5574,7 +5605,7 @@
688 + DEFUN (ospf_distribute_list_out,
689 + ospf_distribute_list_out_cmd,
690 +- "distribute-list WORD out (kernel|connected|static|rip|bgp)",
691 ++ "distribute-list WORD out (kernel|connected|static|rip|bgp|olsr|batman)",
692 + "Filter networks in routing updates\n"
693 + "Access-list name\n"
695 +@@ -5582,7 +5613,10 @@
698 + "Routing Information Protocol (RIP)\n"
699 +- "Border Gateway Protocol (BGP)\n")
700 ++ "Border Gateway Protocol (BGP)\n"
701 ++ "Optimized Link State Routing (OLSR)\n"
702 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
705 + struct ospf *ospf = vty->index;
707 +@@ -5596,7 +5630,7 @@
709 + DEFUN (no_ospf_distribute_list_out,
710 + no_ospf_distribute_list_out_cmd,
711 +- "no distribute-list WORD out (kernel|connected|static|rip|bgp)",
712 ++ "no distribute-list WORD out (kernel|connected|static|rip|bgp|olsr|batman)",
714 + "Filter networks in routing updates\n"
715 + "Access-list name\n"
716 +@@ -5605,7 +5639,10 @@
719 + "Routing Information Protocol (RIP)\n"
720 +- "Border Gateway Protocol (BGP)\n")
721 ++ "Border Gateway Protocol (BGP)\n"
722 ++ "Optimized Link State Routing (OLSR)\n"
723 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
726 + struct ospf *ospf = vty->index;
728 +@@ -7121,7 +7158,8 @@
731 + const char *distribute_str[] = { "system", "kernel", "connected", "static",
732 +- "rip", "ripng", "ospf", "ospf6", "isis", "bgp"};
733 ++ "rip", "ripng", "ospf", "ospf6", "isis", "bgp",
734 ++ "hsls","olsr","batman"};
736 + config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf)
738 +diff -Nur quagga-0.98.6/zebra/redistribute.c quagga-0.98.6.patched/zebra/redistribute.c
739 +--- quagga-0.98.6/zebra/redistribute.c 2005-06-15 14:54:51.000000000 +0300
740 ++++ quagga-0.98.6.patched/zebra/redistribute.c 2007-12-30 14:18:22.000000000 +0200
743 + * This file is part of GNU Zebra.
745 ++ * This file was modified from the original on 30/12/2007
746 ++ * by Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
748 + * GNU Zebra is free software; you can redistribute it and/or modify it
749 + * under the terms of the GNU General Public License as published by the
750 + * Free Software Foundation; either version 2, or (at your option) any
752 + case ZEBRA_ROUTE_OSPF:
753 + case ZEBRA_ROUTE_OSPF6:
754 + case ZEBRA_ROUTE_BGP:
755 ++ case ZEBRA_ROUTE_OLSR:
756 ++ case ZEBRA_ROUTE_BATMAN:
757 + if (! client->redist[type])
759 + client->redist[type] = 1;
761 + case ZEBRA_ROUTE_OSPF:
762 + case ZEBRA_ROUTE_OSPF6:
763 + case ZEBRA_ROUTE_BGP:
764 ++ case ZEBRA_ROUTE_OLSR:
765 ++ case ZEBRA_ROUTE_BATMAN:
766 + client->redist[type] = 0;
769 +diff -Nur quagga-0.98.6/zebra/zebra_vty.c quagga-0.98.6.patched/zebra/zebra_vty.c
770 +--- quagga-0.98.6/zebra/zebra_vty.c 2004-12-18 18:03:29.000000000 +0200
771 ++++ quagga-0.98.6.patched/zebra/zebra_vty.c 2007-12-30 14:25:48.000000000 +0200
774 + case ZEBRA_ROUTE_BGP:
776 ++ case ZEBRA_ROUTE_OLSR:
778 ++ case ZEBRA_ROUTE_BATMAN:
785 + case ZEBRA_ROUTE_BGP:
787 ++ case ZEBRA_ROUTE_HSLS:
789 ++ case ZEBRA_ROUTE_OLSR:
791 ++ case ZEBRA_ROUTE_BATMAN:
799 + #define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, " \
800 +- "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, " \
801 +- "> - selected route, * - FIB route%s%s"
802 ++ "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, H - HSLS, " \
803 ++ "L - OLSR, M - BATMAN, > - selected route, * - FIB route%s%s"
805 + DEFUN (show_ip_route,
809 + DEFUN (show_ip_route_protocol,
810 + show_ip_route_protocol_cmd,
811 +- "show ip route (bgp|connected|isis|kernel|ospf|rip|static)",
812 ++ "show ip route (bgp|connected|isis|kernel|ospf|rip|olsr|batman|static)",
815 + "IP routing table\n"
818 + "Open Shortest Path First (OSPF)\n"
819 + "Routing Information Protocol (RIP)\n"
820 ++ "Optimized Link State Routing (OLSR)\n"
821 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
825 +@@ -892,13 +904,13 @@
829 +- if (strncmp (argv[0], "b", 1) == 0)
830 ++ if (strncmp (argv[0], "bg", 2) == 0)
831 + type = ZEBRA_ROUTE_BGP;
832 + else if (strncmp (argv[0], "c", 1) == 0)
833 + type = ZEBRA_ROUTE_CONNECT;
834 + else if (strncmp (argv[0], "k", 1) ==0)
835 + type = ZEBRA_ROUTE_KERNEL;
836 +- else if (strncmp (argv[0], "o", 1) == 0)
837 ++ else if (strncmp (argv[0], "os", 2) == 0)
838 + type = ZEBRA_ROUTE_OSPF;
839 + else if (strncmp (argv[0], "i", 1) == 0)
840 + type = ZEBRA_ROUTE_ISIS;
841 +@@ -906,6 +918,10 @@
842 + type = ZEBRA_ROUTE_RIP;
843 + else if (strncmp (argv[0], "s", 1) == 0)
844 + type = ZEBRA_ROUTE_STATIC;
845 ++ else if (strncmp (argv[0], "ol", 2) == 0)
846 ++ type = ZEBRA_ROUTE_OLSR;
847 ++ else if (strncmp (argv[0], "ba", 2) == 0)
848 ++ type = ZEBRA_ROUTE_BATMAN;
851 + vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
852 +@@ -1732,7 +1748,7 @@
854 + DEFUN (show_ipv6_route_protocol,
855 + show_ipv6_route_protocol_cmd,
856 +- "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|static)",
857 ++ "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|olsr|batman|static)",
860 + "IP routing table\n"
861 +@@ -1742,6 +1758,8 @@
863 + "Open Shortest Path First (OSPFv3)\n"
864 + "Routing Information Protocol (RIPng)\n"
865 ++ "Optimized Link State Routing (OLSR)\n"
866 ++ "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n"
870 +@@ -1750,13 +1768,13 @@
874 +- if (strncmp (argv[0], "b", 1) == 0)
875 ++ if (strncmp (argv[0], "bg", 2) == 0)
876 + type = ZEBRA_ROUTE_BGP;
877 + else if (strncmp (argv[0], "c", 1) == 0)
878 + type = ZEBRA_ROUTE_CONNECT;
879 + else if (strncmp (argv[0], "k", 1) ==0)
880 + type = ZEBRA_ROUTE_KERNEL;
881 +- else if (strncmp (argv[0], "o", 1) == 0)
882 ++ else if (strncmp (argv[0], "os", 2) == 0)
883 + type = ZEBRA_ROUTE_OSPF6;
884 + else if (strncmp (argv[0], "i", 1) == 0)
885 + type = ZEBRA_ROUTE_ISIS;
886 +@@ -1764,7 +1782,11 @@
887 + type = ZEBRA_ROUTE_RIPNG;
888 + else if (strncmp (argv[0], "s", 1) == 0)
889 + type = ZEBRA_ROUTE_STATIC;
891 ++ else if (strncmp (argv[0], "ol", 2) == 0)
892 ++ type = ZEBRA_ROUTE_OLSR;
893 ++ else if (strncmp (argv[0], "ba", 2) == 0)
894 ++ type = ZEBRA_ROUTE_BATMAN;
897 + vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
898 + return CMD_WARNING;
899 --- a/lib/quagga/README_QUAGGA
900 +++ b/lib/quagga/README_QUAGGA
902 ---------------------------------------------------------------------
903 QUAGGA PLUGIN FOR OLSRD
904 by Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
906 +addittions by: Sven-Ola Tuecke <sven-ola-aet-gmx.de>
907 + Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
908 ---------------------------------------------------------------------
910 -This is the Quagga Plugin for the OLSRD.
911 -It allowes olsrd to redistribute from various quagga-protocols
912 +This is the Quagga Plugin for OLSRd.
913 +It allows olsrd to redistribute from various quagga-protocols
914 as well as to export olsr-routes to quagga so that they can be
915 redistributed by the quagga-routing-daemons.
917 -Note Sven-Ola: You also need a source distribution of quagga-0.98.5
918 -or quagga-0.98.6 (that is the current stable). The quagga source tree
919 -needs to be patched with quagga-0.98.6-olsr.diff, compiled and installed
920 -via 'make install'. Because many people will otherwise have compile
921 -probs, I've added 2 include files in lib/quagga/src/quagga. If you
922 -want to use another version of quagga, make sure to remove these
923 -before you compile the olsrd_quagga plugin.
924 +You also need a source distribution of quagga-0.98.5 or quagga-0.98.6
925 +(that is the current stable). The quagga source tree needs to be
926 +patched with quagga-0.98.6.diff, compiled and installed via
929 ---------------------------------------------------------------------
930 PLUGIN PARAMETERS (PlParam)
932 May be used more then once
934 PlParam "ExportRoutes" "<only/both>"
935 - exportes olsr-routes to quagga or to both, quagga and kernel
936 + exports olsr-routes to quagga or to both, quagga and kernel
937 no routes are exported to quagga (normal behaviour) if not set.
939 -PlParam "LocalPref" "true"
940 +PlParam "LocalPref" "<true/false>"
941 sets the Zebra SELECTED-flag on the routes exported to zebra
942 which means these routes are prefered in any case.
944 PlParam "Distance" "0-255"
945 - allowes to set the administrative distance to routes exported
947 + allows to set the administrative distance to routes exported
950 ---------------------------------------------------------------------
952 ---------------------------------------------------------------------
954 -add in /etc/olsrd.conf:
955 +add in /usr/local/etc/olsrd.conf:
957 LoadPlugin "olsrd_quagga.so.0.2.2"
962 ---------------------------------------------------------------------
965 --- a/lib/quagga/src/olsrd_plugin.c
966 +++ b/lib/quagga/src/olsrd_plugin.c
969 + * OLSRd Quagga plugin
971 + * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
972 + * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
974 + * This program is free software; you can redistribute it and/or modify
975 + * it under the terms of the GNU General Public License version 2 as
976 + * published by the Free Software Foundation or - at your option - under
977 + * the terms of the GNU General Public Licence version 2 but can be
978 + * linked to any BSD-Licenced Software with public available sourcecode
982 +/* -------------------------------------------------------------------------
983 + * File : olsrd_plugin.c
984 + * Description : functions to setup plugin
985 + * ------------------------------------------------------------------------- */
987 -/***************************************************************************
988 - projekt : olsrd-quagga
989 - file : olsrd_plugin.c
990 - usage : olsrd-plugin-handler-stuff
991 - copyright : (C) 2006 by Immo 'FaUl' Wehrenberg
992 - e-mail : immo@chaostreff-dortmund.de
993 - ***************************************************************************/
995 -/***************************************************************************
997 - * This program is free software; you can redistribute it and/or modify *
998 - * it under the terms of the GNU General Public License version 2 as *
999 - * published by the Free Software Foundation. *
1001 - ***************************************************************************/
1006 #include "scheduler.h"
1009 -#include "kernel_routes.h"
1010 #include "net_olsr.h"
1012 #define PLUGIN_NAME "OLSRD quagga plugin"
1013 @@ -41,120 +43,94 @@
1014 static set_plugin_parameter set_distance;
1015 static set_plugin_parameter set_localpref;
1017 -static export_route_function orig_addroute_function;
1018 -static export_route_function orig_delroute_function;
1021 -olsrd_plugin_interface_version(void)
1023 +int olsrd_plugin_interface_version (void) {
1024 return PLUGIN_INTERFACE_VERSION;
1027 static const struct olsrd_plugin_parameters plugin_parameters[] = {
1028 - {.name = "redistribute",.set_plugin_parameter = &set_redistribute,},
1029 - {.name = "ExportRoutes",.set_plugin_parameter = &set_exportroutes,},
1030 - {.name = "Distance",.set_plugin_parameter = &set_distance,},
1031 - {.name = "LocalPref",.set_plugin_parameter = &set_localpref,},
1032 + { .name = "redistribute", .set_plugin_parameter = &set_redistribute, },
1033 + { .name = "ExportRoutes", .set_plugin_parameter = &set_exportroutes, },
1034 + { .name = "Distance", .set_plugin_parameter = &set_distance, },
1035 + { .name = "LocalPref", .set_plugin_parameter = &set_localpref, },
1039 -olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
1041 +void olsrd_get_plugin_parameters (const struct olsrd_plugin_parameters **params,
1043 *params = plugin_parameters;
1044 - *size = sizeof plugin_parameters / sizeof *plugin_parameters;
1045 + *size = ARRAYSIZE(plugin_parameters);
1049 -set_redistribute(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1051 - const char *zebra_route_types[] = { "system", "kernel", "connect",
1052 - "static", "rip", "ripng", "ospf",
1053 - "ospf6", "isis", "bgp", "hsls"
1055 +static int set_redistribute (const char *value,
1056 + void *data __attribute__((unused)),
1057 + set_plugin_parameter_addon addon __attribute__((unused))) {
1058 + const char *zebra_route_types[] = {"system","kernel","connect",
1059 + "static","rip","ripng","ospf",
1060 + "ospf6","isis","bgp","hsls"};
1063 for (i = 0; i < ARRAYSIZE(zebra_route_types); i++) {
1064 - if (!strcmp(value, zebra_route_types[i])) {
1065 - zebra_redistribute(i);
1068 + if (!strcmp(value, zebra_route_types[i]))
1069 + if (zebra_redistribute (i)) return 1;
1077 -set_exportroutes(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1079 +static int set_exportroutes (const char *value,
1080 + void *data __attribute__((unused)),
1081 + set_plugin_parameter_addon addon __attribute__((unused))) {
1082 if (!strcmp(value, "only")) {
1083 - orig_addroute_function = NULL;
1084 - orig_delroute_function = NULL;
1085 - olsr_addroute_function = zebra_add_olsr_v4_route;
1086 - olsr_delroute_function = zebra_del_olsr_v4_route;
1087 + olsr_addroute_function = zebra_add_route;
1088 + olsr_delroute_function = zebra_del_route;
1089 zebra_export_routes(1);
1090 - } else if (!strcmp(value, "additional")) {
1091 - orig_addroute_function = olsr_addroute_function;
1092 - orig_delroute_function = olsr_delroute_function;
1093 - olsr_addroute_function = zebra_add_olsr_v4_route;
1094 - olsr_delroute_function = zebra_del_olsr_v4_route;
1096 + else if (!strcmp(value, "additional")) {
1097 + olsr_addroute_function = zebra_add_route;
1098 + olsr_delroute_function = zebra_del_route;
1099 zebra_export_routes(1);
1101 - zebra_export_routes(0);
1103 + else zebra_export_routes(0);
1108 -set_distance(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1110 +static int set_distance(const char *value, void *data __attribute__((unused)),
1111 + set_plugin_parameter_addon addon __attribute__((unused))) {
1114 - if (set_plugin_int(value, &distance, addon))
1116 - if (distance < 0 || distance > 255)
1118 + if (set_plugin_int(value, &distance, addon)) return 1;
1119 + if (distance < 0 || distance > 255) return 1;
1120 zebra_olsr_distance(distance);
1125 -set_localpref(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused)))
1127 +static int set_localpref(const char *value, void *data __attribute__((unused)),
1128 + set_plugin_parameter_addon addon __attribute__((unused))) {
1131 - if (set_plugin_boolean(value, &b, addon))
1134 - zebra_olsr_localpref();
1135 + if (set_plugin_boolean(value, &b, addon)) return 1;
1136 + if (b) zebra_olsr_localpref();
1141 -olsrd_plugin_init(void)
1143 - if (olsr_cnf->ip_version != AF_INET) {
1144 - fputs("see the source - ipv6 so far not supported\n", stderr);
1146 +int olsrd_plugin_init(void) {
1147 + if(olsr_cnf->ip_version != AF_INET) {
1148 + fputs("see the source - ipv6 so far not supported\n" ,stderr);
1152 - olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &zebra_check, NULL, 0);
1153 + olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC,
1154 + &zebra_parse, NULL, 0);
1162 +static void my_init(void) {
1169 +static void my_fini(void) {
1174 - * Local Variables:
1175 - * c-basic-offset: 2
1176 - * indent-tabs-mode: nil
1179 --- a/lib/quagga/src/quagga/zassert.h
1186 -#ifndef _QUAGGA_ASSERT_H
1187 -#define _QUAGGA_ASSERT_H
1189 -extern void _zlog_assert_failed(const char *assertion, const char *file, unsigned int line, const char *function)
1190 - __attribute__ ((noreturn));
1192 -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
1193 -#define __ASSERT_FUNCTION __func__
1194 -#elif defined(__GNUC__)
1195 -#define __ASSERT_FUNCTION __FUNCTION__
1197 -#define __ASSERT_FUNCTION NULL
1200 -#define zassert(EX) ((void)((EX) ? 0 : \
1201 - (_zlog_assert_failed(#EX, __FILE__, __LINE__, \
1202 - __ASSERT_FUNCTION), 0)))
1205 -#define assert(EX) zassert(EX)
1207 -#endif /* _QUAGGA_ASSERT_H */
1210 - * Local Variables:
1211 - * c-basic-offset: 2
1212 - * indent-tabs-mode: nil
1215 --- a/lib/quagga/src/quagga/zebra.h
1219 -/* Zebra common header.
1220 - Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
1222 -This file is part of GNU Zebra.
1224 -GNU Zebra is free software; you can redistribute it and/or modify it
1225 -under the terms of the GNU General Public License as published by the
1226 -Free Software Foundation; either version 2, or (at your option) any
1229 -GNU Zebra is distributed in the hope that it will be useful, but
1230 -WITHOUT ANY WARRANTY; without even the implied warranty of
1231 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1232 -General Public License for more details.
1234 -You should have received a copy of the GNU General Public License
1235 -along with GNU Zebra; see the file COPYING. If not, write to the Free
1236 -Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1237 -02111-1307, USA. */
1242 -#ifdef HAVE_CONFIG_H
1243 -#include "config.h"
1244 -#endif /* HAVE_CONFIG_H */
1248 -#define __EXTENSIONS__
1249 -typedef unsigned int u_int32_t;
1250 -typedef unsigned short u_int16_t;
1251 -typedef unsigned char u_int8_t;
1252 -#endif /* SUNOS_5 */
1254 -#ifndef HAVE_SOCKLEN_T
1255 -typedef int socklen_t;
1256 -#endif /* HAVE_SOCKLEN_T */
1258 -#include <unistd.h>
1260 -#include <stdlib.h>
1264 -#include <signal.h>
1265 -#include <string.h>
1268 -#ifdef HAVE_STROPTS_H
1269 -#include <stropts.h>
1270 -#endif /* HAVE_STROPTS_H */
1271 -#include <sys/fcntl.h>
1272 -#ifdef HAVE_SYS_SELECT_H
1273 -#include <sys/select.h>
1274 -#endif /* HAVE_SYS_SELECT_H */
1275 -#include <sys/stat.h>
1276 -#include <sys/time.h>
1277 -#include <sys/types.h>
1278 -#include <sys/param.h>
1279 -#ifdef HAVE_SYS_SYSCTL_H
1280 -#include <sys/sysctl.h>
1281 -#endif /* HAVE_SYS_SYSCTL_H */
1282 -#include <sys/ioctl.h>
1283 -#ifdef HAVE_SYS_CONF_H
1284 -#include <sys/conf.h>
1285 -#endif /* HAVE_SYS_CONF_H */
1286 -#ifdef HAVE_SYS_KSYM_H
1287 -#include <sys/ksym.h>
1288 -#endif /* HAVE_SYS_KSYM_H */
1289 -#include <syslog.h>
1291 -#include <sys/uio.h>
1292 -#include <sys/utsname.h>
1294 -#include <sys/resource.h>
1295 -#endif /* HAVE_RUSAGE */
1296 -#ifdef HAVE_LIMITS_H
1297 -#include <limits.h>
1298 -#endif /* HAVE_LIMITS_H */
1300 -/* machine dependent includes */
1302 -#include <strings.h>
1303 -#endif /* SUNOS_5 */
1305 -/* machine dependent includes */
1306 -#ifdef HAVE_LINUX_VERSION_H
1307 -#include <linux/version.h>
1308 -#endif /* HAVE_LINUX_VERSION_H */
1310 -#ifdef HAVE_ASM_TYPES_H
1311 -#include <asm/types.h>
1312 -#endif /* HAVE_ASM_TYPES_H */
1314 -/* misc include group */
1315 -#include <stdarg.h>
1316 -#if !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
1318 -/* Not C99; do we need to define va_copy? */
1321 -#define va_copy(DST,SRC) __va_copy(DST,SRC)
1324 -/* Now we are desperate; this should work on many typical platforms.
1325 - But this is slightly dangerous, because the standard does not require
1326 - va_copy to be a macro. */
1327 -#define va_copy(DST,SRC) memcpy(&(DST), &(SRC), sizeof(va_list))
1328 -#warning "Not C99 and no va_copy macro available, falling back to memcpy"
1329 -#endif /* __va_copy */
1330 -#endif /* !va_copy */
1334 -#include <sys/capability.h>
1335 -#include <sys/prctl.h>
1336 -#endif /* HAVE_LCAPS */
1338 -/* network include group */
1340 -#include <sys/socket.h>
1342 -#ifdef HAVE_SYS_SOCKIO_H
1343 -#include <sys/sockio.h>
1344 -#endif /* HAVE_SYS_SOCKIO_H */
1346 -#ifdef HAVE_NETINET_IN_H
1347 -#include <netinet/in.h>
1348 -#endif /* HAVE_NETINET_IN_H */
1349 -#include <netinet/in_systm.h>
1350 -#include <netinet/ip.h>
1351 -#include <netinet/tcp.h>
1353 -#ifdef HAVE_NET_NETOPT_H
1354 -#include <net/netopt.h>
1355 -#endif /* HAVE_NET_NETOPT_H */
1357 -#include <net/if.h>
1359 -#ifdef HAVE_NET_IF_DL_H
1360 -#include <net/if_dl.h>
1361 -#endif /* HAVE_NET_IF_DL_H */
1363 -#ifdef HAVE_NET_IF_VAR_H
1364 -#include <net/if_var.h>
1365 -#endif /* HAVE_NET_IF_VAR_H */
1367 -#ifdef HAVE_NET_ROUTE_H
1368 -#include <net/route.h>
1369 -#endif /* HAVE_NET_ROUTE_H */
1371 -#ifdef HAVE_NETLINK
1372 -#include <linux/netlink.h>
1373 -#include <linux/rtnetlink.h>
1375 -#define RT_TABLE_MAIN 0
1376 -#endif /* HAVE_NETLINK */
1378 -#ifdef HAVE_NETDB_H
1380 -#endif /* HAVE_NETDB_H */
1382 -#include <arpa/inet.h>
1383 -#include <arpa/telnet.h>
1385 -#ifdef HAVE_INET_ND_H
1386 -#include <inet/nd.h>
1387 -#endif /* HAVE_INET_ND_H */
1389 -#ifdef HAVE_NETINET_IN_VAR_H
1390 -#include <netinet/in_var.h>
1391 -#endif /* HAVE_NETINET_IN_VAR_H */
1393 -#ifdef HAVE_NETINET6_IN6_VAR_H
1394 -#include <netinet6/in6_var.h>
1395 -#endif /* HAVE_NETINET6_IN6_VAR_H */
1397 -#ifdef HAVE_NETINET_IN6_VAR_H
1398 -#include <netinet/in6_var.h>
1399 -#endif /* HAVE_NETINET_IN6_VAR_H */
1401 -#ifdef HAVE_NETINET6_IN_H
1402 -#include <netinet6/in.h>
1403 -#endif /* HAVE_NETINET6_IN_H */
1405 -#ifdef HAVE_NETINET6_IP6_H
1406 -#include <netinet6/ip6.h>
1407 -#endif /* HAVE_NETINET6_IP6_H */
1409 -#ifdef HAVE_NETINET_ICMP6_H
1410 -#include <netinet/icmp6.h>
1411 -#endif /* HAVE_NETINET_ICMP6_H */
1413 -#ifdef HAVE_NETINET6_ND6_H
1414 -#include <netinet6/nd6.h>
1415 -#endif /* HAVE_NETINET6_ND6_H */
1417 -/* Some systems do not define UINT32_MAX */
1419 -#define UINT32_MAX 0xFFFFFFFFU
1420 -#endif /* UINT32_MAX */
1422 -#ifdef HAVE_LIBUTIL_H
1423 -#include <libutil.h>
1424 -#endif /* HAVE_LIBUTIL_H */
1426 -#ifdef HAVE_GLIBC_BACKTRACE
1427 -#include <execinfo.h>
1428 -#endif /* HAVE_GLIBC_BACKTRACE */
1432 -#ifdef HAVE_NETINET6_IN6_H
1433 -#include <netinet6/in6.h>
1434 -#endif /* HAVE_NETINET6_IN6_H */
1437 -#include <netinet6/in6.h>
1440 -#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
1442 -#endif /* BSDI_NRL */
1444 -/* Local includes: */
1445 -#if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
1446 -#define __attribute__(x)
1447 -#endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
1449 -#include "zassert.h"
1451 -#ifdef HAVE_BROKEN_CMSG_FIRSTHDR
1453 -/* This bug is present in Solaris 8 and pre-patch Solaris 9 <sys/socket.h>;
1454 - please refer to http://bugzilla.quagga.net/show_bug.cgi?id=142 */
1456 -/* Check that msg_controllen is large enough. */
1457 -#define ZCMSG_FIRSTHDR(mhdr) \
1458 - (((size_t)((mhdr)->msg_controllen) >= sizeof(struct cmsghdr)) ? \
1459 - CMSG_FIRSTHDR(mhdr) : (struct cmsghdr *)NULL)
1461 -#warning "CMSG_FIRSTHDR is broken on this platform, using a workaround"
1463 -#else /* HAVE_BROKEN_CMSG_FIRSTHDR */
1464 -#define ZCMSG_FIRSTHDR(M) CMSG_FIRSTHDR(M)
1465 -#endif /* HAVE_BROKEN_CMSG_FIRSTHDR */
1468 - * RFC 3542 defines several macros for using struct cmsghdr.
1469 - * Here, we define those that are not present
1473 - * Internal defines, for use only in this file.
1474 - * These are likely wrong on other than ILP32 machines, so warn.
1476 -#ifndef _CMSG_DATA_ALIGN
1477 -#define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
1478 -#endif /* _CMSG_DATA_ALIGN */
1480 -#ifndef _CMSG_HDR_ALIGN
1481 -#define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
1482 -#endif /* _CMSG_HDR_ALIGN */
1485 - * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
1489 -#define CMSG_SPACE(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + \
1490 - _CMSG_HDR_ALIGN(l))
1491 -#warning "assuming 4-byte alignment for CMSG_SPACE"
1492 -#endif /* CMSG_SPACE */
1495 -#define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
1496 -#warning "assuming 4-byte alignment for CMSG_LEN"
1497 -#endif /* CMSG_LEN */
1499 -/* The definition of struct in_pktinfo is missing in old version of
1500 - GLIBC 2.1 (Redhat 6.1). */
1501 -#if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO)
1502 -struct in_pktinfo {
1504 - struct in_addr ipi_spec_dst;
1505 - struct in_addr ipi_addr;
1510 - * OSPF Fragmentation / fragmented writes
1512 - * ospfd can support writing fragmented packets, for cases where
1513 - * kernel will not fragment IP_HDRINCL and/or multicast destined
1514 - * packets (ie TTBOMK all kernels, BSD, SunOS, Linux). However,
1515 - * SunOS, probably BSD too, clobber the user supplied IP ID and IP
1516 - * flags fields, hence user-space fragmentation will not work.
1517 - * Only Linux is known to leave IP header unmolested.
1518 - * Further, fragmentation really should be done the kernel, which already
1519 - * supports it, and which avoids nasty IP ID state problems.
1521 - * Fragmentation of OSPF packets can be required on networks with router
1522 - * with many many interfaces active in one area, or on networks with links
1526 -#define WANT_OSPF_WRITE_FRAGMENT
1530 - * IP_HDRINCL / struct ip byte order
1532 - * Linux: network byte order
1533 - * *BSD: network, except for length and offset. (cf Stevens)
1534 - * SunOS: nominally as per BSD. but bug: network order on LE.
1535 - * OpenBSD: network byte order, apart from older versions which are as per
1538 -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)\
1539 - || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
1540 - || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN))
1541 -#define HAVE_IP_HDRINCL_BSD_ORDER
1544 -/* MAX / MIN are not commonly defined, but useful */
1546 -#define MAX(a, b) ((a) > (b) ? (a) : (b))
1549 -#define MIN(a, b) ((a) < (b) ? (a) : (b))
1552 -/* For old definition. */
1553 -#ifndef IN6_ARE_ADDR_EQUAL
1554 -#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
1555 -#endif /* IN6_ARE_ADDR_EQUAL */
1557 -/* Zebra message types. */
1558 -#define ZEBRA_INTERFACE_ADD 1
1559 -#define ZEBRA_INTERFACE_DELETE 2
1560 -#define ZEBRA_INTERFACE_ADDRESS_ADD 3
1561 -#define ZEBRA_INTERFACE_ADDRESS_DELETE 4
1562 -#define ZEBRA_INTERFACE_UP 5
1563 -#define ZEBRA_INTERFACE_DOWN 6
1564 -#define ZEBRA_IPV4_ROUTE_ADD 7
1565 -#define ZEBRA_IPV4_ROUTE_DELETE 8
1566 -#define ZEBRA_IPV6_ROUTE_ADD 9
1567 -#define ZEBRA_IPV6_ROUTE_DELETE 10
1568 -#define ZEBRA_REDISTRIBUTE_ADD 11
1569 -#define ZEBRA_REDISTRIBUTE_DELETE 12
1570 -#define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
1571 -#define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
1572 -#define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
1573 -#define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
1574 -#define ZEBRA_IPV4_IMPORT_LOOKUP 17
1575 -#define ZEBRA_IPV6_IMPORT_LOOKUP 18
1576 -#define ZEBRA_INTERFACE_RENAME 19
1577 -#define ZEBRA_ROUTER_ID_ADD 20
1578 -#define ZEBRA_ROUTER_ID_DELETE 21
1579 -#define ZEBRA_ROUTER_ID_UPDATE 22
1580 -#define ZEBRA_MESSAGE_MAX 23
1582 -/* Zebra route's types. */
1583 -#define ZEBRA_ROUTE_SYSTEM 0
1584 -#define ZEBRA_ROUTE_KERNEL 1
1585 -#define ZEBRA_ROUTE_CONNECT 2
1586 -#define ZEBRA_ROUTE_STATIC 3
1587 -#define ZEBRA_ROUTE_RIP 4
1588 -#define ZEBRA_ROUTE_RIPNG 5
1589 -#define ZEBRA_ROUTE_OSPF 6
1590 -#define ZEBRA_ROUTE_OSPF6 7
1591 -#define ZEBRA_ROUTE_ISIS 8
1592 -#define ZEBRA_ROUTE_BGP 9
1593 -#define ZEBRA_ROUTE_HSLS 10
1594 -#define ZEBRA_ROUTE_OLSR 11
1595 -#define ZEBRA_ROUTE_MAX 12
1597 -/* Zebra's family types. */
1598 -#define ZEBRA_FAMILY_IPV4 1
1599 -#define ZEBRA_FAMILY_IPV6 2
1600 -#define ZEBRA_FAMILY_MAX 3
1602 -/* Error codes of zebra. */
1603 -#define ZEBRA_ERR_RTEXIST -1
1604 -#define ZEBRA_ERR_RTUNREACH -2
1605 -#define ZEBRA_ERR_EPERM -3
1606 -#define ZEBRA_ERR_RTNOEXIST -4
1608 -/* Zebra message flags */
1609 -#define ZEBRA_FLAG_INTERNAL 0x01
1610 -#define ZEBRA_FLAG_SELFROUTE 0x02
1611 -#define ZEBRA_FLAG_BLACKHOLE 0x04
1612 -#define ZEBRA_FLAG_IBGP 0x08
1613 -#define ZEBRA_FLAG_SELECTED 0x10
1614 -#define ZEBRA_FLAG_CHANGED 0x20
1615 -#define ZEBRA_FLAG_STATIC 0x40
1616 -#define ZEBRA_FLAG_REJECT 0x80
1618 -/* Zebra nexthop flags. */
1619 -#define ZEBRA_NEXTHOP_IFINDEX 1
1620 -#define ZEBRA_NEXTHOP_IFNAME 2
1621 -#define ZEBRA_NEXTHOP_IPV4 3
1622 -#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
1623 -#define ZEBRA_NEXTHOP_IPV4_IFNAME 5
1624 -#define ZEBRA_NEXTHOP_IPV6 6
1625 -#define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
1626 -#define ZEBRA_NEXTHOP_IPV6_IFNAME 8
1627 -#define ZEBRA_NEXTHOP_BLACKHOLE 9
1629 -#ifndef INADDR_LOOPBACK
1630 -#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
1633 -/* Address family numbers from RFC1700. */
1638 -/* Subsequent Address Family Identifier. */
1639 -#define SAFI_UNICAST 1
1640 -#define SAFI_MULTICAST 2
1641 -#define SAFI_UNICAST_MULTICAST 3
1642 -#define SAFI_MPLS_VPN 4
1645 -/* Filter direction. */
1646 -#define FILTER_IN 0
1647 -#define FILTER_OUT 1
1648 -#define FILTER_MAX 2
1650 -/* Default Administrative Distance of each protocol. */
1651 -#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
1652 -#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
1653 -#define ZEBRA_STATIC_DISTANCE_DEFAULT 1
1654 -#define ZEBRA_RIP_DISTANCE_DEFAULT 120
1655 -#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
1656 -#define ZEBRA_OSPF_DISTANCE_DEFAULT 110
1657 -#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
1658 -#define ZEBRA_ISIS_DISTANCE_DEFAULT 115
1659 -#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
1660 -#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
1662 -/* Flag manipulation macros. */
1663 -#define CHECK_FLAG(V,F) ((V) & (F))
1664 -#define SET_FLAG(V,F) (V) = (V) | (F)
1665 -#define UNSET_FLAG(V,F) (V) = (V) & ~(F)
1667 -/* AFI and SAFI type. */
1668 -typedef u_int16_t afi_t;
1669 -typedef u_int8_t safi_t;
1672 -typedef u_int16_t zebra_size_t;
1673 -typedef u_int8_t zebra_command_t;
1675 -/* FIFO -- first in first out structure and macros. */
1677 - struct fifo *next;
1678 - struct fifo *prev;
1681 -#define FIFO_INIT(F) \
1683 - struct fifo *Xfifo = (struct fifo *)(F); \
1684 - Xfifo->next = Xfifo->prev = Xfifo; \
1687 -#define FIFO_ADD(F,N) \
1689 - struct fifo *Xfifo = (struct fifo *)(F); \
1690 - struct fifo *Xnode = (struct fifo *)(N); \
1691 - Xnode->next = Xfifo; \
1692 - Xnode->prev = Xfifo->prev; \
1693 - Xfifo->prev = Xfifo->prev->next = Xnode; \
1696 -#define FIFO_DEL(N) \
1698 - struct fifo *Xnode = (struct fifo *)(N); \
1699 - Xnode->prev->next = Xnode->next; \
1700 - Xnode->next->prev = Xnode->prev; \
1703 -#define FIFO_HEAD(F) \
1704 - ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
1705 - ? NULL : (F)->next)
1707 -#define FIFO_EMPTY(F) \
1708 - (((struct fifo *)(F))->next == (struct fifo *)(F))
1710 -#define FIFO_TOP(F) \
1711 - (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
1713 -#endif /* _ZEBRA_H */
1716 - * Local Variables:
1717 - * c-basic-offset: 2
1718 - * indent-tabs-mode: nil
1721 --- a/lib/quagga/src/quagga.c
1722 +++ b/lib/quagga/src/quagga.c
1725 + * OLSRd Quagga plugin
1727 + * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
1728 + * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
1730 + * This program is free software; you can redistribute it and/or modify
1731 + * it under the terms of the GNU General Public License version 2 as
1732 + * published by the Free Software Foundation or - at your option - under
1733 + * the terms of the GNU General Public Licence version 2 but can be
1734 + * linked to any BSD-Licenced Software with public available sourcecode
1738 -/***************************************************************************
1739 - projekt : olsrd-quagga
1741 - usage : communication with the zebra-daemon
1742 - copyright : (C) 2006 by Immo 'FaUl' Wehrenberg
1743 - e-mail : immo@chaostreff-dortmund.de
1744 - ***************************************************************************/
1746 -/***************************************************************************
1748 - * This program is free software; you can redistribute it and/or modify *
1749 - * it under the terms of the GNU General Public License version 2 as *
1750 - * published by the Free Software Foundation. *
1752 - ***************************************************************************/
1753 +/* -------------------------------------------------------------------------
1755 + * Description : functions to interface to the zebra daemon
1756 + * ------------------------------------------------------------------------- */
1762 #define HAVE_SOCKLEN_T
1764 +#include "quagga.h"
1765 +#include "olsr.h" /* olsr_exit
1767 +#include "log.h" /* olsr_syslog */
1770 +#include <stdlib.h>
1771 +#include <unistd.h>
1772 +#include <string.h>
1775 #include <sys/types.h>
1776 #include <sys/socket.h>
1777 #include <netinet/in.h>
1779 -#include <unistd.h>
1781 -#include "quagga.h"
1785 -#include "routing_table.h"
1787 +#include <arpa/inet.h>
1788 #ifdef USE_UNIX_DOMAIN_SOCKET
1790 -#define ZEBRA_SOCKET "/var/run/quagga/zserv.api"
1793 -#define ZEBRA_IPV4_ROUTE_ADD 7
1794 -#define ZEBRA_IPV4_ROUTE_DELETE 8
1795 -#define ZEBRA_REDISTRIBUTE_ADD 11
1796 -#define ZEBRA_REDISTRIBUTE_DELETE 12
1797 -#define ZEBRA_MESSAGE_MAX 23
1799 -#define ZEBRA_ROUTE_OLSR 11
1800 -#define ZEBRA_ROUTE_MAX 12
1802 -#define ZEBRA_FLAG_SELECTED 0x10
1804 -#define ZEBRA_NEXTHOP_IPV4 3
1805 -#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
1807 -#define ZAPI_MESSAGE_NEXTHOP 0x01
1808 -#define ZAPI_MESSAGE_IFINDEX 0x02
1809 -#define ZAPI_MESSAGE_DISTANCE 0x04
1810 -#define ZAPI_MESSAGE_METRIC 0x08
1812 -#define BUFSIZE 1024
1814 -#define STATUS_CONNECTED 1
1815 -#define OPTION_EXPORT 1
1817 +/* prototypes intern */
1819 - char status; // internal status
1820 - char options; // internal options
1821 - int sock; // Socket to zebra...
1822 + char status; // internal status
1823 + char options; // internal options
1824 + int sock; // Socket to zebra...
1825 char redistribute[ZEBRA_ROUTE_MAX];
1828 - struct ipv4_route *v4_rt; // routes currently exportet to zebra
1829 + struct zebra_route *v4_rt; // routes currently exportet to zebra
1832 -/* prototypes intern */
1833 -static unsigned char *try_read(ssize_t *);
1834 -static unsigned char *zebra_route_packet(struct ipv4_route r, ssize_t *);
1835 -static int parse_interface_add(unsigned char *, size_t);
1836 -static int parse_interface_delete(unsigned char *, size_t);
1837 -static int parse_interface_up(unsigned char *, size_t);
1838 -static int parse_interface_down(unsigned char *, size_t);
1839 -static int parse_interface_address_add(unsigned char *, size_t);
1840 -static int parse_interface_address_delete(unsigned char *, size_t);
1841 -static int parse_ipv4_route(unsigned char *, size_t, struct ipv4_route *);
1842 -static int ipv4_route_add(unsigned char *, size_t);
1843 -static int ipv4_route_delete(unsigned char *, size_t);
1844 -static int parse_ipv6_route_add(unsigned char *, size_t);
1845 -static void zebra_reconnect(void);
1846 -static void zebra_connect(void);
1848 -static void free_ipv4_route(struct ipv4_route);
1851 -static void update_olsr_zebra_routes (struct ipv4_route*, struct ipv4_route*);
1852 -static struct ipv4_route *zebra_create_ipv4_route_table_entry (uint32_t,
1855 -static struct ipv4_route *zebra_create_ipv4_route_table (void);
1856 -static void zebra_free_ipv4_route_table (struct ipv4_route*);
1859 -/*static uint8_t masktoprefixlen (uint32_t);*/
1863 -dump_ipv4_route(struct ipv4_route r, char *c)
1868 - printf("type: %d\n", r.type);
1870 - printf(" Internal: %s\n", r.flags & ZEBRA_FLAG_INTERNAL ? "yes" : "no");
1871 - printf(" Selfroute %s\n", r.flags & ZEBRA_FLAG_SELFROUTE ? "yes" : "no");
1872 - printf(" Blackhole %s\n", r.flags & ZEBRA_FLAG_BLACKHOLE ? "yes" : "no");
1873 - printf(" IBGP: %s\n", r.flags & ZEBRA_FLAG_IBGP ? "yes" : "no");
1874 - printf(" Selected: %s\n", r.flags & ZEBRA_FLAG_SELECTED ? "yes" : "no");
1875 - printf(" Changed: %s\n", r.flags & ZEBRA_FLAG_CHANGED ? "yes" : "no");
1876 - printf(" static: %s\n", r.flags & ZEBRA_FLAG_STATIC ? "yes" : "no");
1877 - printf(" reject: %s\n", r.flags & ZEBRA_FLAG_REJECT ? "yes" : "no");
1879 - printf(" nexthop: %s\n", r.message & ZAPI_MESSAGE_NEXTHOP ? "yes" : "no");
1880 - printf(" ifindex: %s\n", r.message & ZAPI_MESSAGE_IFINDEX ? "yes" : "no");
1881 - printf(" distance: %s\n", r.message & ZAPI_MESSAGE_DISTANCE ? "yes" : "no");
1882 - printf(" metric: %s\n", r.message & ZAPI_MESSAGE_METRIC ? "yes" : "no");
1883 - printf("Prefixlen: %d\n", r.prefixlen);
1884 - printf("Prefix: %d", (unsigned char)r.prefix);
1885 - c = (char *)&r.prefix;
1886 - while (++i < (r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0)))
1887 - printf(".%d", (unsigned char)*(c + i));
1892 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
1893 - printf("nexthop-count: %d\n", r.nh_count);
1894 - while (i++ < r.nh_count) {
1895 - if (r.nexthops[i].type == ZEBRA_NEXTHOP_IPV4) {
1896 - c = (unsigned char *)&r.nexthops[i].payload.v4;
1897 - printf("Nexthop %d: %d", i, (unsigned char)*c);
1899 - printf(".%d", (unsigned char)c[x]);
1906 - if (r.message & ZAPI_MESSAGE_IFINDEX) {
1908 - printf("index-number: %d\n", r.ind_num);
1909 - while (i++ < r.ind_num)
1910 - printf("Index: %d: %d\n", i, r.index[i]);
1912 - if (r.message & ZAPI_MESSAGE_DISTANCE)
1913 - printf("Distance: %d\n", r.distance);
1914 - if (r.message & ZAPI_MESSAGE_METRIC)
1915 - printf("Metric: %d\n", r.metric);
1919 +static void *my_realloc (void *, size_t, const char *);
1920 +static void zebra_connect (void);
1921 +static unsigned char *try_read (ssize_t *);
1922 +static int zebra_send_command (unsigned char *);
1923 +static unsigned char* zebra_route_packet (uint16_t, struct zebra_route *);
1924 +static unsigned char *zebra_redistribute_packet (unsigned char, unsigned char);
1925 +static struct zebra_route *zebra_parse_route (unsigned char *);
1927 +static void zebra_reconnect (void);
1929 +static void free_ipv4_route (struct zebra_route *);
1933 -my_realloc(void *buf, size_t s, const char *c)
1935 - buf = realloc(buf, s);
1936 +static void *my_realloc (void *buf, size_t s, const char *c) {
1937 + buf = realloc (buf, s);
1939 - OLSR_PRINTF(1, "(QUAGGA) OUT OF MEMORY: %s\n", strerror(errno));
1940 + OLSR_PRINTF (1, "(QUAGGA) OUT OF MEMORY: %s\n", strerror(errno));
1941 olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n");
1942 olsr_exit(c, EXIT_FAILURE);
1951 +void init_zebra (void) {
1953 - if (!(zebra.status & STATUS_CONNECTED))
1954 - olsr_exit("(QUAGGA) AIIIII, could not connect to zebra! is zebra running?", EXIT_FAILURE);
1955 + if (!(zebra.status&STATUS_CONNECTED))
1956 + olsr_exit ("(QUAGGA) AIIIII, could not connect to zebra! is zebra running?",
1961 -zebra_cleanup(void)
1964 +void zebra_cleanup (void) {
1966 struct rt_entry *tmp;
1968 if (zebra.options & OPTION_EXPORT) {
1969 OLSR_FOR_ALL_RT_ENTRIES(tmp) {
1970 - zebra_del_olsr_v4_route(tmp);
1972 - OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
1973 + zebra_del_route(tmp);
1974 + } OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
1977 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1978 - if (zebra.redistribute[i])
1979 - zebra_disable_redistribute(i + 1);
1980 + if (zebra.redistribute[i]) zebra_disable_redistribute(i);
1984 -zebra_reconnect(void)
1988 +static void zebra_reconnect (void) {
1989 struct rt_entry *tmp;
1993 - if (!(zebra.status & STATUS_CONNECTED))
1994 - return; // try again next time
1995 + if (!(zebra.status & STATUS_CONNECTED)) return; // try again next time
1997 if (zebra.options & OPTION_EXPORT) {
1998 OLSR_FOR_ALL_RT_ENTRIES(tmp) {
1999 - zebra_add_olsr_v4_route(tmp);
2001 - OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
2002 + zebra_add_route (tmp);
2003 + } OLSR_FOR_ALL_RT_ENTRIES_END(tmp);
2006 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2007 - if (zebra.redistribute[i])
2008 - zebra_redistribute(i + 1);
2009 + if (zebra.redistribute[i]) zebra_redistribute(i + 1);
2010 /* Zebra sends us all routes of type it knows after
2011 zebra_redistribute(type) */
2016 /* Connect to the zebra-daemon, returns a socket */
2018 -zebra_connect(void)
2020 +static void zebra_connect (void) {
2024 #ifndef USE_UNIX_DOMAIN_SOCKET
2025 struct sockaddr_in i;
2026 - if (close(zebra.sock) < 0)
2027 - olsr_exit("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2028 + if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2031 - zebra.sock = socket(AF_INET, SOCK_STREAM, 0);
2032 + zebra.sock = socket (AF_INET,SOCK_STREAM, 0);
2034 struct sockaddr_un i;
2035 - if (close(zebra.sock) < 0)
2036 - olsr_exit("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2037 + if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE);
2039 - zebra.sock = socket(AF_UNIX, SOCK_STREAM, 0);
2040 + zebra.sock = socket (AF_UNIX,SOCK_STREAM, 0);
2043 - if (zebra.sock < 0)
2044 + if (zebra.sock <0 )
2045 olsr_exit("(QUAGGA) Could not create socket!", EXIT_FAILURE);
2047 - memset(&i, 0, sizeof i);
2048 + memset (&i, 0, sizeof i);
2049 #ifndef USE_UNIX_DOMAIN_SOCKET
2050 i.sin_family = AF_INET;
2051 - i.sin_port = htons(ZEBRA_PORT);
2052 - i.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
2053 + i.sin_port = htons (ZEBRA_PORT);
2054 + i.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
2056 i.sun_family = AF_UNIX;
2057 - strscpy(i.sun_path, ZEBRA_SOCKET, sizeof(i.sun_path));
2058 + strcpy (i.sun_path, ZEBRA_SOCKET);
2061 - ret = connect(zebra.sock, (struct sockaddr *)&i, sizeof i);
2063 - zebra.status &= ~STATUS_CONNECTED;
2065 - zebra.status |= STATUS_CONNECTED;
2066 + ret = connect (zebra.sock, (struct sockaddr *)&i, sizeof i);
2067 + if (ret < 0) zebra.status &= ~STATUS_CONNECTED;
2068 + else zebra.status |= STATUS_CONNECTED;
2072 /* Sends a command to zebra, command is
2073 the command defined in zebra.h, options is the packet-payload,
2074 optlen the length, of the payload */
2076 -zebra_send_command(unsigned char command, unsigned char *options, int optlen)
2078 +static int zebra_send_command (unsigned char *options) {
2081 + unsigned char *pnt;
2085 -#ifdef ZEBRA_HEADER_MARKER
2087 - uint16_t length = optlen + 6; /* length of option + command + packet_length +
2088 - marker + zserv-version */
2090 - uint16_t length = optlen + 3; // length of option + command + packet_length
2093 - if (!(zebra.status & STATUS_CONNECTED))
2096 - p = olsr_malloc(length, "zebra_send_command");
2099 - len = htons(length);
2100 + if (!(zebra.status & STATUS_CONNECTED)) return 0;
2102 - memcpy(p, &len, 2);
2104 + memcpy (&len, pnt, 2);
2106 -#ifdef ZEBRA_HEADER_MARKER
2107 - p[2] = ZEBRA_HEADER_MARKER;
2108 - p[3] = ZSERV_VERSION;
2109 - cmd = htons(command);
2110 - memcpy(p + 4, &cmd, 2);
2114 - memcpy(p + length - optlen, options, optlen);
2120 - ret = write(zebra.sock, p, length);
2121 + ret = write (zebra.sock, pnt, len);
2123 - if (errno == EINTR) {
2127 - olsr_printf(1, "(QUAGGA) Disconnected from zebra\n");
2128 - zebra.status &= ~STATUS_CONNECTED;
2131 + if ((errno == EINTR) || (errno == EAGAIN)) {
2137 + OLSR_PRINTF (1, "(QUAGGA) Disconnected from zebra\n");
2138 + zebra.status &= ~STATUS_CONNECTED;
2145 - while ((length -= ret));
2148 + } while ((len -= ret));
2154 /* Creates a Route-Packet-Payload, needs address, netmask, nexthop,
2155 distance, and a pointer of an size_t */
2156 -static unsigned char *
2157 -zebra_route_packet(struct ipv4_route r, ssize_t * optlen)
2159 +static unsigned char* zebra_route_packet (uint16_t cmd, struct zebra_route *r) {
2164 + uint32_t ind, metric;
2166 unsigned char *cmdopt, *t;
2167 - *optlen = 4; // first: type, flags, message, prefixlen
2168 - *optlen += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0); // + prefix
2169 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
2170 - if (r.nexthops->type == ZEBRA_NEXTHOP_IPV4 || r.nexthops->type == ZEBRA_NEXTHOP_IPV4_IFINDEX) {
2171 - *optlen += (sizeof r.nexthops->payload.v4 + sizeof r.nexthops->type) * r.nh_count + 1;
2172 - } else if (r.nexthops->type == 0)
2175 - if (r.message & ZAPI_MESSAGE_IFINDEX)
2176 - *optlen += r.ind_num * sizeof *r.index + 1;
2177 - if (r.message & ZAPI_MESSAGE_DISTANCE)
2179 - if (r.message & ZAPI_MESSAGE_METRIC)
2180 - *optlen += sizeof r.metric;
2182 - cmdopt = olsr_malloc(*optlen, "zebra add_v4_route");
2188 - *t++ = r.prefixlen;
2189 - for (count = 0; count < r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0); count++) {
2190 - *t++ = *((char *)&r.prefix + count); /* this is so sick!! */
2193 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
2194 - *t++ = r.nh_count;
2195 - *t++ = r.nexthops->type;
2196 - if (r.nexthops->type == ZEBRA_NEXTHOP_IPV4 || r.nexthops->type == ZEBRA_NEXTHOP_IPV4_IFINDEX) {
2197 - for (count = 0; count != r.nh_count; count++) {
2198 - memcpy(t, &r.nexthops[count].payload.v4, sizeof r.nexthops->payload.v4);
2199 - t += sizeof r.nexthops->payload.v4;
2201 - } else if (r.nexthops->type == 0) {
2207 - if (r.message & ZAPI_MESSAGE_IFINDEX) {
2209 - memcpy(t, r.index, sizeof *r.index * r.ind_num);
2210 - t += sizeof r.index * r.ind_num;
2212 - if (r.message & ZAPI_MESSAGE_DISTANCE)
2213 - *t++ = r.distance;
2214 - if (r.message & ZAPI_MESSAGE_METRIC) {
2215 - memcpy(t, &r.metric, sizeof r.metric);
2216 - t += sizeof r.metric;
2221 -/* adds a route to zebra-daemon */
2223 -zebra_add_v4_route(const struct ipv4_route r)
2226 - unsigned char *cmdopt;
2229 + cmdopt = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra add_v4_route");
2231 - cmdopt = zebra_route_packet(r, &optlen);
2236 + *t++ = r->message;
2237 + *t++ = r->prefixlen;
2238 + len = (r->prefixlen + 7) / 8;
2239 + memcpy (t, &r->prefix.v4.s_addr, len);
2242 - retval = zebra_send_command(ZEBRA_IPV4_ROUTE_ADD, cmdopt, optlen);
2245 + if (r->message & ZAPI_MESSAGE_NEXTHOP) {
2246 + *t++ = r->nexthop_num + r->ifindex_num;
2248 + for (count = 0; count < r->nexthop_num; count++)
2250 + *t++ = ZEBRA_NEXTHOP_IPV4;
2251 + memcpy (t, &r->nexthop[count].v4.s_addr,
2252 + sizeof r->nexthop[count].v4.s_addr);
2253 + t += sizeof r->nexthop[count].v4.s_addr;
2255 + for (count = 0; count < r->ifindex_num; count++)
2257 + *t++ = ZEBRA_NEXTHOP_IFINDEX;
2258 + ind = htonl(r->ifindex[count]);
2259 + memcpy (t, &ind, sizeof ind);
2263 + if ((r->message & ZAPI_MESSAGE_DISTANCE) > 0)
2264 + *t++ = r->distance;
2265 + if ((r->message & ZAPI_MESSAGE_METRIC) > 0)
2267 + metric = htonl (r->metric);
2268 + memcpy (t, &metric, sizeof metric);
2269 + t += sizeof metric;
2271 + size = htons (t - cmdopt);
2272 + memcpy (cmdopt, &size, 2);
2277 -/* deletes a route from the zebra-daemon */
2279 -zebra_delete_v4_route(struct ipv4_route r)
2282 - unsigned char *cmdopt;
2286 - cmdopt = zebra_route_packet(r, &optlen);
2288 - retval = zebra_send_command(ZEBRA_IPV4_ROUTE_DELETE, cmdopt, optlen);
2295 /* Check wether there is data from zebra aviable */
2297 -zebra_check(void *foo __attribute__ ((unused)))
2299 +void zebra_parse (void* foo __attribute__((unused))) {
2300 unsigned char *data, *f;
2302 + unsigned char command;
2305 + struct zebra_route *route;
2307 if (!(zebra.status & STATUS_CONNECTED)) {
2308 - zebra_reconnect();
2309 +// zebra_reconnect();
2312 - data = try_read(&len);
2313 + data = try_read (&len);
2317 - ret = zebra_parse_packet(f, len);
2318 - if (!ret) // something wired happened
2319 - olsr_exit("(QUAGGA) Zero message length??? ", EXIT_FAILURE);
2322 - while ((f - data) < len);
2324 + memcpy (&length, f, sizeof length);
2325 + length = ntohs (length);
2326 + if (!length) // something wired happened
2327 + olsr_exit ("(QUAGGA) Zero message length??? ", EXIT_FAILURE);
2329 + switch (command) {
2330 + case ZEBRA_IPV4_ROUTE_ADD:
2331 + route = zebra_parse_route(f);
2332 + ip_prefix_list_add(&olsr_cnf->hna_entries, &route->prefix, route->prefixlen);
2333 + free_ipv4_route (route);
2336 + case ZEBRA_IPV4_ROUTE_DELETE:
2337 + route = zebra_parse_route(f);
2338 + ip_prefix_list_remove(&olsr_cnf->hna_entries, &route->prefix, route->prefixlen);
2339 + free_ipv4_route (route);
2346 + } while ((f - data) < len);
2352 // tries to read a packet from zebra_socket
2353 // if there is something to read - make sure to read whole packages
2354 -static unsigned char *
2355 -try_read(ssize_t * len)
2357 - unsigned char *buf = NULL;
2358 - ssize_t ret = 0, bsize = 0;
2359 - uint16_t length = 0, l = 0;
2364 - sockstate = fcntl(zebra.sock, F_GETFL, 0);
2365 - fcntl(zebra.sock, F_SETFL, sockstate | O_NONBLOCK);
2366 +static unsigned char *try_read (ssize_t *size) {
2367 + unsigned char *buf;
2368 + ssize_t bytes, bufsize;
2369 + uint16_t length, offset;
2372 + /* initialize variables */
2378 + /* save socket status and set non-blocking for read */
2379 + sockstatus = fcntl (zebra.sock, F_GETFL);
2380 + fcntl (zebra.sock, F_SETFL, sockstatus|O_NONBLOCK);
2382 + /* read whole packages */
2384 - if (*len == bsize) {
2386 - buf = my_realloc(buf, bsize, "Zebra try_read");
2388 + /* (re)allocate buffer */
2389 + if (*size == bufsize) {
2390 + bufsize += BUFSIZE;
2391 + buf = my_realloc (buf, bufsize, "Zebra try_read");
2393 - ret = read(zebra.sock, buf + l, bsize - l);
2394 - if (!ret) { // nothing more to read, packet is broken, discard!
2397 + /* read from socket */
2398 + bytes = read (zebra.sock, buf + *size, bufsize - *size);
2399 + /* handle broken packet */
2406 - if (errno != EAGAIN) { // oops - we got disconnected
2407 - olsr_printf(1, "(QUAGGA) Disconnected from zebra\n");
2408 + /* handle no data available */
2410 + /* handle disconnect */
2411 + if (errno != EAGAIN) { // oops - we got disconnected
2412 + OLSR_PRINTF (1, "(QUAGGA) Disconnected from zebra\n");
2413 zebra.status &= ~STATUS_CONNECTED;
2421 - while ((*len - l) > length) {
2423 - memcpy(&length, buf + l, 2);
2424 - length = ntohs(length);
2426 - if (((*len) - l) == length)
2427 - break; // GOT FULL PACKAGE!!
2429 - fcntl(zebra.sock, F_SETFL, sockstate);
2435 - fcntl(zebra.sock, F_SETFL, sockstate);
2439 -/* Parse a packet recived from zebra */
2441 -zebra_parse_packet(unsigned char *packet, ssize_t maxlen)
2447 - /* Array of functions */
2448 - int (*foo[ZEBRA_MESSAGE_MAX]) (unsigned char *, size_t) = {
2449 - parse_interface_add, parse_interface_delete, parse_interface_address_add, parse_interface_address_delete, parse_interface_up,
2450 - parse_interface_down, ipv4_route_add, ipv4_route_delete, parse_ipv6_route_add};
2456 - puts("DEBUG: zebra_parse_packet");
2459 - memcpy(&length, packet, 2);
2460 - length = ntohs(length);
2462 - if (maxlen < length) {
2463 - olsr_printf(1, "(QUAGGA) maxlen = %lu, packet_length = %d\n", (unsigned long)maxlen, length);
2464 - olsr_exit("(QUAGGA) programmer is an idiot", EXIT_FAILURE);
2466 -#ifdef ZEBRA_HEADER_MARKER
2467 - if (packet[2] == 255) { // found header marker!!
2468 - //packet[3] == ZSERV_VERSION: FIXME: HANDLE THIS!
2469 - memcpy(&command, packet + 4, sizeof command); // two bytes command now!
2470 - command = ntohs(command) - 1;
2474 - command = packet[2] - 1;
2478 - if (command < ZEBRA_MESSAGE_MAX && foo[command]) {
2479 - if (!(ret = foo[command] (packet + skip, length - skip)))
2482 - olsr_printf(1, "(QUAGGA) Parse error: %d\n", ret);
2484 - olsr_printf(1, "(QUAGGA) Unknown packet type: %d\n", packet[2]);
2486 - olsr_printf(1, "(Quagga) RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE");
2492 -parse_interface_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2499 -parse_interface_delete(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2506 -parse_interface_address_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2514 -parse_interface_up(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2521 + /* detect zebra packet fragmentation */
2523 + memcpy (&length, buf + offset, sizeof length);
2524 + length = ntohs (length);
2526 + } while (*size >= (ssize_t) (offset + sizeof length));
2527 + /* set blocking socket on fragmented packet */
2528 + if (*size != offset)
2529 + fcntl (zebra.sock, F_SETFL, sockstatus);
2531 + } while (*size != offset);
2534 -parse_interface_down(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2536 + /* restore socket status */
2537 + fcntl (zebra.sock, F_SETFL, sockstatus);
2545 -parse_interface_address_delete(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2551 /* Parse an ipv4-route-packet recived from zebra
2554 -parse_ipv4_route(unsigned char *opt, size_t len, struct ipv4_route *r)
2556 +static struct zebra_route *zebra_parse_route (unsigned char *opt) {
2558 + struct zebra_route *r;
2565 - r->flags = *opt++;
2566 - r->message = *opt++;
2567 - r->prefixlen = *opt++;
2571 - if ((int)len < r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0))
2574 - memcpy(&r->prefix, opt, r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0));
2575 - opt += r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0);
2578 + unsigned char *pnt;
2580 + memcpy (&length, opt, sizeof length);
2581 + length = ntohs (length);
2583 + r = olsr_malloc (sizeof *r , "zebra_parse_route");
2586 + r->flags = *pnt++;
2587 + r->message = *pnt++;
2588 + r->prefixlen = *pnt++;
2589 + r->prefix.v4.s_addr = 0;
2591 + size = (r->prefixlen + 7) / 8;
2592 + memcpy (&r->prefix.v4.s_addr, pnt, size);
2595 if (r->message & ZAPI_MESSAGE_NEXTHOP) {
2598 - r->nh_count = *opt++;
2600 - if (len < (sizeof(uint32_t) + 1) * r->nh_count)
2603 - olsr_malloc((sizeof r->nexthops->type + sizeof r->nexthops->payload) * r->nh_count, "quagga: parse_ipv4_route_add");
2604 - for (c = 0; c < r->nh_count; c++) {
2605 - r->nexthops[c].type = *opt++;
2606 - memcpy(&r->nexthops[c].payload.v4, opt, sizeof(uint32_t));
2607 - opt += sizeof(uint32_t);
2608 - len -= sizeof(uint32_t) + 1;
2609 + r->nexthop_num = *pnt++;
2610 + r->nexthop = olsr_malloc ((sizeof *r->nexthop) * r->nexthop_num,
2611 + "quagga: zebra_parse_route");
2612 + for (c = 0; c < r->nexthop_num; c++) {
2613 + memcpy (&r->nexthop[c].v4.s_addr, pnt, sizeof r->nexthop[c].v4.s_addr);
2614 + pnt += sizeof r->nexthop[c].v4.s_addr;
2618 if (r->message & ZAPI_MESSAGE_IFINDEX) {
2621 - r->ind_num = *opt++;
2622 - if (len < sizeof(uint32_t) * r->ind_num)
2624 - r->index = olsr_malloc(sizeof(uint32_t) * r->ind_num, "quagga: parse_ipv4_route_add");
2625 - memcpy(r->index, opt, r->ind_num * sizeof(uint32_t));
2626 - opt += sizeof(uint32_t) * r->ind_num;
2627 - len -= sizeof(uint32_t) * r->ind_num;
2628 + r->ifindex_num = *pnt++;
2629 + r->ifindex = olsr_malloc (sizeof (uint32_t) * r->ifindex_num,
2630 + "quagga: zebra_parse_route");
2631 + for (c = 0; c < r->ifindex_num; c++) {
2632 + memcpy (&r->ifindex[c], pnt, sizeof r->ifindex[c]);
2633 + r->ifindex[c] = ntohl (r->ifindex[c]);
2634 + pnt += sizeof r->ifindex[c];
2638 if (r->message & ZAPI_MESSAGE_DISTANCE) {
2641 - r->distance = *opt++;
2643 + r->distance = *pnt++;
2646 - if (r->message & ZAPI_MESSAGE_METRIC) {
2647 - if (len < sizeof(uint32_t))
2649 - memcpy(&r->metric, opt, sizeof(uint32_t));
2651 +// Quagga v0.98.6 BUG workaround: metric is always sent by zebra
2652 +// even without ZAPI_MESSAGE_METRIC message.
2653 +// if (r.message & ZAPI_MESSAGE_METRIC) {
2654 + memcpy (&r->metric, pnt, sizeof (uint32_t));
2655 + r->metric = ntohl (r->metric);
2656 + pnt += sizeof r->metric;
2659 + if (pnt - opt != length) { olsr_exit ("(QUAGGA) length does not match ??? ", EXIT_FAILURE);
2667 -ipv4_route_add(unsigned char *opt, size_t len)
2670 - struct ipv4_route r;
2672 +static unsigned char *zebra_redistribute_packet (unsigned char cmd, unsigned char type) {
2673 + unsigned char *data, *pnt;
2676 - f = parse_ipv4_route(opt, len, &r);
2679 + data = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra_redistribute_packet");
2681 - return add_hna4_route(r);
2685 -ipv4_route_delete(unsigned char *opt, size_t len)
2687 - struct ipv4_route r;
2690 - f = parse_ipv4_route(opt, len, &r);
2694 - return delete_hna4_route(r);
2698 + size = htons (pnt - data);
2699 + memcpy (data, &size, 2);
2705 -parse_ipv6_route_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused)))
2711 /* start redistribution FROM zebra */
2713 -zebra_redistribute(unsigned char type)
2716 - if (type > ZEBRA_ROUTE_MAX)
2718 - zebra.redistribute[type - 1] = 1;
2720 - return zebra_send_command(ZEBRA_REDISTRIBUTE_ADD, &type, 1);
2724 -/* end redistribution FROM zebra */
2726 -zebra_disable_redistribute(unsigned char type)
2729 - if (type > ZEBRA_ROUTE_MAX)
2731 - zebra.redistribute[type - 1] = 0;
2732 +int zebra_redistribute (unsigned char type) {
2734 - return zebra_send_command(ZEBRA_REDISTRIBUTE_DELETE, &type, 1);
2735 + if (zebra_send_command(zebra_redistribute_packet (ZEBRA_REDISTRIBUTE_ADD, type)) < 0)
2736 + olsr_exit("(QUAGGA) could not send redistribute add command", EXIT_FAILURE);
2739 + if (type > ZEBRA_ROUTE_MAX-1) return -1;
2740 + zebra.redistribute[type] = 1;
2743 -add_hna4_route(struct ipv4_route r)
2745 - union olsr_ip_addr net;
2748 - dump_ipv4_route(r, "add_hna4_route");
2751 - net.v4.s_addr = r.prefix;
2753 - ip_prefix_list_add(&olsr_cnf->hna_entries, &net, r.prefixlen);
2754 - free_ipv4_route(r);
2760 -delete_hna4_route(struct ipv4_route r)
2763 - union olsr_ip_addr net;
2764 +/* end redistribution FROM zebra */
2765 +int zebra_disable_redistribute (unsigned char type) {
2768 - dump_ipv4_route(r, "delete_hna4_route");
2770 + if (zebra_send_command(zebra_redistribute_packet (ZEBRA_REDISTRIBUTE_DELETE, type)) < 0)
2771 + olsr_exit("(QUAGGA) could not send redistribute delete command", EXIT_FAILURE);
2773 - net.v4.s_addr = r.prefix;
2774 + if (type > ZEBRA_ROUTE_MAX-1) return -1;
2775 + zebra.redistribute[type] = 0;
2777 - ip_prefix_list_remove(&olsr_cnf->hna_entries, &net, r.prefixlen) ? 0 : -1;
2778 - free_ipv4_route(r);
2784 -free_ipv4_route(struct ipv4_route r)
2787 - if (r.message & ZAPI_MESSAGE_IFINDEX && r.ind_num)
2789 - if (r.message & ZAPI_MESSAGE_NEXTHOP && r.nh_count)
2795 -static uint8_t masktoprefixlen (uint32_t mask) {
2797 - uint8_t prefixlen = 0;
2799 - mask = htonl (mask);
2800 +static void free_ipv4_route (struct zebra_route *r) {
2802 - if (mask) while (mask << ++prefixlen && prefixlen < 32);
2805 + if(r->ifindex_num) free(r->ifindex);
2806 + if(r->nexthop_num) free(r->nexthop);
2812 -zebra_add_olsr_v4_route(const struct rt_entry *r)
2815 - struct ipv4_route route;
2816 +int zebra_add_route (const struct rt_entry *r) {
2818 + struct zebra_route route;
2821 - route.index = NULL;
2822 - route.distance = 0;
2823 - route.type = ZEBRA_ROUTE_OLSR; // OLSR
2824 - route.message = ZAPI_MESSAGE_METRIC;
2825 + route.type = ZEBRA_ROUTE_OLSR;
2826 route.flags = zebra.flags;
2827 + route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC;
2828 route.prefixlen = r->rt_dst.prefix_len;
2829 - route.prefix = r->rt_dst.prefix.v4.s_addr;
2830 - if ((r->rt_best->rtp_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && route.prefixlen == 32)) {
2831 - route.message |= ZAPI_MESSAGE_IFINDEX | ZAPI_MESSAGE_NEXTHOP;
2832 - route.ind_num = 1;
2833 - route.index = olsr_malloc(sizeof *route.index, "zebra_add_olsr_v4_route");
2834 - *route.index = htonl(r->rt_best->rtp_nexthop.iif_index);
2835 - route.nexthops = olsr_malloc(sizeof route.nexthops->type + sizeof route.nexthops->payload, "zebra_add_olsr_v4_route");
2836 - route.nh_count = 1;
2837 - route.nexthops->type = 0;
2839 - route.message |= ZAPI_MESSAGE_NEXTHOP;
2840 - route.nh_count = 1;
2842 - olsr_malloc(route.nh_count * (sizeof route.nexthops->type + sizeof route.nexthops->payload), "zebra_add_olsr_v4_route");
2843 - route.nexthops->type = ZEBRA_NEXTHOP_IPV4;
2844 - route.nexthops->payload.v4 = r->rt_best->rtp_nexthop.gateway.v4.s_addr;
2845 + route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr;
2846 + route.ifindex_num = 0;
2847 + route.ifindex = NULL;
2848 + route.nexthop_num = 0;
2849 + route.nexthop = NULL;
2851 + if (r->rt_best->rtp_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr &&
2852 + route.prefixlen == 32) {
2853 + return 0; /* Quagga BUG workaround: don't add routes with destination = gateway
2854 + see http://lists.olsr.org/pipermail/olsr-users/2006-June/001726.html */
2855 + route.ifindex_num++;
2856 + route.ifindex = olsr_malloc (sizeof *route.ifindex,
2857 + "zebra_add_route");
2858 + *route.ifindex = r->rt_best->rtp_nexthop.iif_index;
2861 + route.nexthop_num++;
2862 + route.nexthop = olsr_malloc (sizeof *route.nexthop, "zebra_add_route");
2863 + route.nexthop->v4.s_addr = r->rt_best->rtp_nexthop.gateway.v4.s_addr;
2866 route.metric = r->rt_best->rtp_metric.hops;
2867 - route.metric = htonl(route.metric);
2869 if (zebra.distance) {
2870 route.message |= ZAPI_MESSAGE_DISTANCE;
2871 route.distance = zebra.distance;
2874 - retval = zebra_add_v4_route(route);
2875 - free_ipv4_route(route);
2876 + retval = zebra_send_command (zebra_route_packet (ZEBRA_IPV4_ROUTE_ADD, &route));
2882 -zebra_del_olsr_v4_route(const struct rt_entry *r)
2884 +int zebra_del_route (const struct rt_entry *r) {
2886 - struct ipv4_route route;
2887 + struct zebra_route route;
2889 - route.index = NULL;
2890 - route.distance = 0;
2891 - route.type = ZEBRA_ROUTE_OLSR; // OLSR
2892 - route.message = ZAPI_MESSAGE_METRIC;
2894 + route.type = ZEBRA_ROUTE_OLSR;
2895 route.flags = zebra.flags;
2896 + route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC;
2897 route.prefixlen = r->rt_dst.prefix_len;
2898 - route.prefix = r->rt_dst.prefix.v4.s_addr;
2899 - if ((r->rt_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && route.prefixlen == 32)) {
2900 - route.message |= ZAPI_MESSAGE_IFINDEX;
2901 - route.ind_num = 1;
2902 - route.index = olsr_malloc(sizeof *route.index, "zebra_add_olsr_v4_route");
2903 - *route.index = htonl(r->rt_nexthop.iif_index);
2904 - route.nexthops = olsr_malloc(sizeof route.nexthops->type + sizeof route.nexthops->payload, "zebra_add_olsr_v4_route");
2905 - route.nh_count = 1;
2906 - route.nexthops->type = 0;
2908 - route.message |= ZAPI_MESSAGE_NEXTHOP;
2909 - route.nh_count = 1;
2911 - olsr_malloc(route.nh_count * (sizeof route.nexthops->type + sizeof route.nexthops->payload), "zebra_add_olsr_v4_route");
2912 - route.nexthops->type = ZEBRA_NEXTHOP_IPV4;
2913 - route.nexthops->payload.v4 = r->rt_nexthop.gateway.v4.s_addr;
2914 + route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr;
2915 + route.ifindex_num = 0;
2916 + route.ifindex = NULL;
2917 + route.nexthop_num = 0;
2918 + route.nexthop = NULL;
2920 + if (r->rt_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr &&
2921 + route.prefixlen == 32){
2922 + return 0; /* Quagga BUG workaround: don't delete routes with destination = gateway
2923 + see http://lists.olsr.org/pipermail/olsr-users/2006-June/001726.html */
2924 + route.ifindex_num++;
2925 + route.ifindex = olsr_malloc (sizeof *route.ifindex,
2926 + "zebra_del_route");
2927 + *route.ifindex = r->rt_nexthop.iif_index;
2930 + route.nexthop_num++;
2931 + route.nexthop = olsr_malloc (sizeof *route.nexthop, "zebra_del_route");
2932 + route.nexthop->v4.s_addr = r->rt_nexthop.gateway.v4.s_addr;
2937 if (zebra.distance) {
2938 @@ -868,36 +557,23 @@
2939 route.distance = zebra.distance;
2942 - retval = zebra_delete_v4_route(route);
2944 - free_ipv4_route(route);
2945 + retval = zebra_send_command (zebra_route_packet (ZEBRA_IPV4_ROUTE_DELETE, &route));
2951 -zebra_olsr_distance(unsigned char dist)
2953 +void zebra_olsr_distance (unsigned char dist) {
2954 zebra.distance = dist;
2958 -zebra_olsr_localpref(void)
2960 +void zebra_olsr_localpref (void) {
2961 zebra.flags &= ZEBRA_FLAG_SELECTED;
2965 -zebra_export_routes(unsigned char t)
2967 +void zebra_export_routes (unsigned char t) {
2969 zebra.options |= OPTION_EXPORT;
2971 zebra.options &= ~OPTION_EXPORT;
2975 - * Local Variables:
2976 - * c-basic-offset: 2
2977 - * indent-tabs-mode: nil
2980 --- a/lib/quagga/src/quagga.h
2981 +++ b/lib/quagga/src/quagga.h
2984 + * OLSRd Quagga plugin
2986 + * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
2987 + * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
2989 + * This program is free software; you can redistribute it and/or modify
2990 + * it under the terms of the GNU General Public License version 2 as
2991 + * published by the Free Software Foundation or - at your option - under
2992 + * the terms of the GNU General Public Licence version 2 but can be
2993 + * linked to any BSD-Licenced Software with public available sourcecode
2997 +/* -------------------------------------------------------------------------
2999 + * Description : header file for quagga.c
3000 + * ------------------------------------------------------------------------- */
3002 -/***************************************************************************
3003 - projekt : olsrd-quagga
3005 - usage : header for quagga.c
3006 - copyright : (C) 2006 by Immo 'FaUl' Wehrenberg
3007 - e-mail : immo@chaostreff-dortmund.de
3008 - ***************************************************************************/
3010 -/***************************************************************************
3012 - * This program is free software; you can redistribute it and/or modify *
3013 - * it under the terms of the GNU General Public License version 2 as *
3014 - * published by the Free Software Foundation. *
3016 - ***************************************************************************/
3018 +#include "routing_table.h" /* rt_entry */
3019 +#include "olsr_types.h" /* olsr_ip_addr */
3024 -#include "routing_table.h"
3026 #define HAVE_SOCKLEN_T
3030 #define ZEBRA_PORT 2600
3033 +/* Zebra version */
3034 #ifdef ZEBRA_HEADER_MARKER
3035 #ifndef ZSERV_VERSION
3036 #define ZSERV_VERSION 1
3040 -struct ipv4_route {
3044 - uint8_t prefixlen;
3056 +#define ZEBRA_SOCKET "/var/run/quagga/zserv.api"
3058 +/* Zebra packet size */
3059 +#define ZEBRA_MAX_PACKET_SIZ 4096
3061 +/* Zebra message types */
3062 +#define ZEBRA_IPV4_ROUTE_ADD 7
3063 +#define ZEBRA_IPV4_ROUTE_DELETE 8
3064 +#define ZEBRA_REDISTRIBUTE_ADD 11
3065 +#define ZEBRA_REDISTRIBUTE_DELETE 12
3066 +#define ZEBRA_MESSAGE_MAX 23
3068 +/* Zebra route types */
3069 +#define ZEBRA_ROUTE_OLSR 11
3070 +#define ZEBRA_ROUTE_MAX 13
3073 +#define ZEBRA_FLAG_SELECTED 0x10
3075 +/* Zebra nexthop flags */
3076 +#define ZEBRA_NEXTHOP_IFINDEX 1
3077 +#define ZEBRA_NEXTHOP_IPV4 3
3079 +/* Zebra message flags */
3080 +#define ZAPI_MESSAGE_NEXTHOP 0x01
3081 +#define ZAPI_MESSAGE_IFINDEX 0x02
3082 +#define ZAPI_MESSAGE_DISTANCE 0x04
3083 +#define ZAPI_MESSAGE_METRIC 0x08
3086 +#define BUFSIZE 1024
3088 +/* Quagga plugin flags */
3089 +#define STATUS_CONNECTED 1
3090 +#define OPTION_EXPORT 1
3093 +struct zebra_route {
3094 + unsigned char type;
3095 + unsigned char flags;
3096 + unsigned char message;
3097 + unsigned char prefixlen;
3098 + union olsr_ip_addr prefix;
3099 + unsigned char nexthop_num;
3100 + union olsr_ip_addr *nexthop;
3101 + unsigned char ifindex_num;
3102 + uint32_t *ifindex;
3105 - struct ipv4_route *next;
3108 -void init_zebra(void);
3109 -void zebra_cleanup(void);
3110 -unsigned char zebra_send_command(unsigned char, unsigned char *, int);
3111 -int zebra_add_v4_route(const struct ipv4_route r);
3112 -int zebra_delete_v4_route(const struct ipv4_route r);
3113 -void zebra_check(void *);
3114 -int zebra_parse_packet(unsigned char *, ssize_t);
3115 -int zebra_redistribute(unsigned char);
3116 -int zebra_disable_redistribute(unsigned char);
3117 -int add_hna4_route(struct ipv4_route);
3118 -int delete_hna4_route(struct ipv4_route);
3119 -void *my_realloc(void *, size_t, const char *);
3120 -int zebra_add_olsr_v4_route(const struct rt_entry *);
3121 -int zebra_del_olsr_v4_route(const struct rt_entry *);
3122 -void zebra_olsr_localpref(void);
3123 -void zebra_olsr_distance(unsigned char);
3124 +void init_zebra (void);
3125 +void zebra_cleanup (void);
3126 +void zebra_parse (void*);
3127 +int zebra_redistribute (unsigned char);
3128 +int zebra_disable_redistribute (unsigned char);
3129 +int zebra_add_route (const struct rt_entry *);
3130 +int zebra_del_route (const struct rt_entry *);
3131 +void zebra_olsr_localpref (void);
3132 +void zebra_olsr_distance (unsigned char);
3133 void zebra_export_routes(unsigned char);
3136 - * Local Variables:
3137 - * c-basic-offset: 2
3138 - * indent-tabs-mode: nil
3141 --- a/lib/quagga/test/foo.c
3144 -#include "quagga.h"
3151 - zebra_redistribute(2);
3152 - // zebra_redistribute (1);
3159 - * Local Variables:
3160 - * c-basic-offset: 2
3161 - * indent-tabs-mode: nil
3164 --- a/lib/quagga/test/foo.pl
3171 -$command = 11; # 11 = redistribute_add , 13 = redistribute_default_add
3173 -$proto = 2; # connected
3175 -$remote = IO::Socket::INET->new (Proto => "tcp",
3176 - PeerAddr => "127.0.0.1",
3177 - PeerPort => "2600",
3179 -$remote->autoflush (1);
3180 -#print $remote pack ("nc", 3, 13);
3181 -print $remote pack ("nc",3,1);
3182 -print $remote pack ("ncc", 4,$command,2);
3183 -print $remote pack ("ncccccNcNcNN", 25, 7, 10, 16, 11, 25, 0xc0a80206, 0, 0, 1, 5, 1);
3186 --- a/lib/quagga/test/quagga.try1.c
3191 - * (C) 2006 by Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
3193 - * This code is covered by the GPLv2
3197 -#include <stdint.h>
3201 -#include <sys/types.h>
3202 -#include <sys/socket.h>
3203 -#include <netinet/in.h>
3204 -#define HAVE_SOCKLEN_T
3205 -#include <quagga/zebra.h>
3206 -#include "quagga.h"
3212 -#include "local_hna_set.h"
3215 -#define ZAPI_MESSAGE_NEXTHOP 0x01
3216 -#define ZAPI_MESSAGE_IFINDEX 0x02
3217 -#define ZAPI_MESSAGE_DISTANCE 0x04
3218 -#define ZAPI_MESSAGE_METRIC 0x08
3220 -#define STATUS_CONNECTED 1
3221 -#define BUFSIZE 1024
3222 -static char status = 0;
3224 -static int zsock; // Socket to zebra...
3225 -struct ipv4_route *quagga_routes = 0; // routes currently exportet to zebra
3227 -/* prototypes ntern */
3228 -static char *try_read(ssize_t *);
3229 -static char *zebra_route_packet(struct ipv4_route r, ssize_t *);
3230 -static int parse_interface_add(char *, size_t);
3231 -static int parse_interface_delete(char *, size_t);
3232 -static int parse_interface_up(char *, size_t);
3233 -static int parse_interface_down(char *, size_t);
3234 -static int parse_interface_address_add(char *, size_t);
3235 -static int parse_interface_address_delete(char *, size_t);
3236 -static int parse_ipv4_route(char *, size_t, struct ipv4_route *);
3237 -static int ipv4_route_add(char *, size_t);
3238 -static int ipv4_route_delete(char *, size_t);
3239 -static int parse_ipv6_route_add(char *, size_t);
3240 -static uint32_t prefixlentomask(uint8_t);
3241 -static void free_ipv4_route(struct ipv4_route);
3242 -static void update_olsr_zebra_routes(struct ipv4_route *, struct ipv4_route *);
3243 -static struct ipv4_route *zebra_create_ipv4_route_table_entry(uint32_t, uint32_t, uint32_t);
3244 -static struct ipv4_route *zebra_create_ipv4_route_table(void);
3245 -static void zebra_free_ipv4_route_table(struct ipv4_route *);
3246 -static uint8_t masktoprefixlen(uint32_t);
3250 -dump_ipv4_route(struct ipv4_route r, char *c)
3255 - printf("type: %d\n", r.type);
3257 - printf(" Internal: %s\n", r.flags & ZEBRA_FLAG_INTERNAL ? "yes" : "no");
3258 - printf(" Selfroute %s\n", r.flags & ZEBRA_FLAG_SELFROUTE ? "yes" : "no");
3259 - printf(" Blackhole %s\n", r.flags & ZEBRA_FLAG_BLACKHOLE ? "yes" : "no");
3260 - printf(" IBGP: %s\n", r.flags & ZEBRA_FLAG_IBGP ? "yes" : "no");
3261 - printf(" Selected: %s\n", r.flags & ZEBRA_FLAG_SELECTED ? "yes" : "no");
3262 - printf(" Changed: %s\n", r.flags & ZEBRA_FLAG_CHANGED ? "yes" : "no");
3263 - printf(" static: %s\n", r.flags & ZEBRA_FLAG_STATIC ? "yes" : "no");
3264 - printf(" reject: %s\n", r.flags & ZEBRA_FLAG_REJECT ? "yes" : "no");
3266 - printf(" nexthop: %s\n", r.message & ZAPI_MESSAGE_NEXTHOP ? "yes" : "no");
3267 - printf(" ifindex: %s\n", r.message & ZAPI_MESSAGE_IFINDEX ? "yes" : "no");
3268 - printf(" distance: %s\n", r.message & ZAPI_MESSAGE_DISTANCE ? "yes" : "no");
3269 - printf(" metric: %s\n", r.message & ZAPI_MESSAGE_METRIC ? "yes" : "no");
3270 - printf("Prefixlen: %d\n", r.prefixlen);
3271 - printf("Prefix: %d", (unsigned char)r.prefix);
3272 - c = (char *)&r.prefix;
3273 - while (++i < (r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0)))
3274 - printf(".%d", (unsigned char)*(c + i));
3279 - if (r.message & ZAPI_MESSAGE_NEXTHOP) {
3281 - printf("nexthop-count: %d\n", r.nh_count);
3282 - while (i++ < r.nh_count) {
3283 - c = (unsigned char *)&r.nexthops[i];
3284 - printf("Nexthop %d: %d", i, (unsigned char)*c);
3286 - printf(".%d", (unsigned char)c[x]);
3292 - if (r.message & ZAPI_MESSAGE_IFINDEX) {
3294 - printf("index-number: %d\n", r.ind_num);
3295 - while (i++ < r.ind_num)
3296 - printf("Index: %d: %d\n", i, r.index[i]);
3298 - if (r.message & ZAPI_MESSAGE_DISTANCE)
3299 - printf("Distance: %d\n", r.distance);
3300 - if (r.message & ZAPI_MESSAGE_METRIC)
3301 - printf("Metric: %d\n", r.metric);
3308 -my_realloc(void *buf, size_t s, const char *c)
3310 - buf = realloc(buf, s);
3313 - OLSR_PRINTF(1, "OUT OF MEMORY: %s\n", strerror(errno));
3314 - olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n");
3315 - olsr_exit(c, EXIT_FAILURE);
3317 - exit(EXIT_FAILURE);
3323 -#ifndef OLSR_PLUGIN
3325 -olsr_malloc(size_t f, const char *c)
3327 - void *v = malloc(f);
3332 -/* Connect to the zebra-daemon, returns a socket */
3336 - struct sockaddr_in i;
3339 - zsock = socket(AF_INET, SOCK_STREAM, 0);
3340 - if (zsock < 0) // TODO: Could not create socket
3342 - memset(&i, 0, sizeof i);
3343 - i.sin_family = AF_INET;
3344 - i.sin_port = htons(ZEBRA_PORT);
3345 - // i.sin_len = sizeof i;
3346 - i.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
3348 - ret = connect(zsock, (struct sockaddr *)&i, sizeof i);
3353 - status |= STATUS_CONNECTED;
3357 -/* Sends a command to zebra, command is
3358 - the command defined in zebra.h, options is the packet-payload,
3359 - optlen the length, of the payload */
3361 -zebra_send_command(unsigned char command, char *options, int optlen)
3364 - char *p = olsr_malloc(optlen + 3, "zebra send_command");
3365 - uint16_t length = optlen + 3; // length of option + command + packet_length
3369 - uint16_t len = htons(length);
3370 - memcpy(p, &len, 2);
3372 - memcpy(p + 3, options, optlen);
3375 - ret = write(zsock, p, length);
3377 - if (errno == EINTR)
3383 - while ((length -= ret));
3388 -/* Creates a Route-Packet-Payload, needs address, netmask, nexthop,
3389 - distance, and a pointer of an size_t */
3391 -zebra_route_packet(struct ipv4_route r, ssize_t * optlen)
3395 - *optlen = 9; // first: type, flags, message, prefixlen, nexthop number, nexthop)
3396 - *optlen += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0);
3398 - cmdopt = olsr_malloc(*optlen, "zebra add_v4_route");
3400 - *t++ = 10; // Type: olsr
3401 - *t++ = r.flags; // flags
3402 - *t++ = r.message; // message: contains nexthop
3403 - *t++ = r.prefixlen;
3404 - memcpy(t, &r.prefix, r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0));
3405 - *t += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0);
3406 - *t++ = r.nh_count;
3407 - memcpy(t, r.nexthops, r.nh_count * sizeof *r.nexthops);
3411 -/* adds a route to zebra-daemon (needs socket from zebra,
3412 - address = prefix of the route
3413 - mask = netmask of the route
3414 - nexthop = nexthop of the route
3415 - distance = distance-value of the route
3418 -zebra_add_v4_route(struct ipv4_route r)
3424 - cmdopt = zebra_route_packet(r, &optlen);
3426 - puts("DEBUG: zebra_route_packet returned");
3428 - return zebra_send_command(ZEBRA_IPV4_ROUTE_ADD, cmdopt, optlen);
3432 -/* deletes a route from the zebra-daemon (
3433 - needs socket from zebra,
3434 - address = prefix of the route
3435 - mask = netmask of the route
3436 - nexthop = nexthop of the route
3437 - distance = distance-value of the route
3440 -zebra_delete_v4_route(struct ipv4_route r)
3446 - cmdopt = zebra_route_packet(r, &optlen);
3448 - return zebra_send_command(ZEBRA_IPV4_ROUTE_DELETE, cmdopt, optlen);
3452 -/* Check wether there is data from zebra aviable */
3454 -zebra_check(void *foo)
3459 - if (!status & STATUS_CONNECTED) {
3461 - data = try_read(&len);
3465 - ret = zebra_parse_packet(f, len);
3466 - if (!ret) { //something wired happened
3467 - puts("DEBUG: IIIIIIIIIIRGS");
3468 - exit(EXIT_FAILURE);
3472 - while ((f - data) < len);
3477 -// tries to read a packet from zebra_socket
3478 -// if there is something to read - make sure to read whole packages
3480 -try_read(ssize_t * len)
3483 - ssize_t ret = 0, bsize = 0;
3484 - uint16_t length = 0, l = 0;
3489 - sockstate = fcntl(zsock, F_GETFL, 0);
3490 - fcntl(zsock, F_SETFL, sockstate | O_NONBLOCK);
3493 - if (*len == bsize) {
3495 - buf = my_realloc(buf, bsize, "Zebra try_read");
3497 - ret = read(zsock, buf + l, bsize - l);
3499 - if (errno == EAGAIN) {
3502 - // TODO: errorhandling
3510 - while ((*len - l) > length) {
3511 - // printf ("DEBUG: *len -l > length - %d - %d > %d\n", *len, l, length);
3513 - memcpy(&length, buf + l, 2);
3514 - length = ntohs(length);
3516 - // printf ("DEBUG: *len, l, length: %d,%d,%d\n", *len, l, length);
3517 - if (((*len) - l) == length)
3518 - break; // GOT FULL PACKAGE!!
3520 - // printf ("DEBUG: *len, l, length: %d,%d,%d\n", *len, l, length);
3521 - fcntl(zsock, F_SETFL, sockstate);
3527 - fcntl(zsock, F_SETFL, sockstate);
3531 -/* Parse a packet recived from zebra */
3533 -zebra_parse_packet(char *packet, ssize_t maxlen)
3536 - /* Array of functions */
3537 - int (*foo[ZEBRA_MESSAGE_MAX]) (char *, size_t) = {
3538 - parse_interface_add, parse_interface_delete, parse_interface_address_add, parse_interface_address_delete, parse_interface_up,
3539 - parse_interface_down, ipv4_route_add, ipv4_route_delete, parse_ipv6_route_add};
3541 - puts("DEBUG: zebra_parse_packet");
3545 - memcpy(&length, packet, 2);
3546 - length = ntohs(length);
3548 - if (maxlen < length) {
3549 - puts("Error: programmer is an idiot");
3550 - printf("DEBUG: maxlen = %d, packet_length = %d\n", maxlen, length);
3554 - if (packet[2] - 1 < ZEBRA_MESSAGE_MAX && foo[packet[2] - 1]) {
3555 - if (!(ret = foo[packet[2] - 1] (packet + 3, length - 3)))
3558 - printf("DEBUG: Parse error: %d\n", ret);
3560 - printf("Unknown packet type: %d\n", packet[2]);
3562 - puts("Quagga: RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE");
3568 -parse_interface_add(char *opt, size_t len)
3575 -parse_interface_delete(char *opt, size_t len)
3582 -parse_interface_address_add(char *opt, size_t len)
3590 -parse_interface_up(char *opt, size_t len)
3598 -parse_interface_down(char *opt, size_t len)
3606 -parse_interface_address_delete(char *opt, size_t len)
3612 -/* Parse an ipv4-route-packet recived from zebra
3615 -parse_ipv4_route(char *opt, size_t len, struct ipv4_route *r)
3617 - // puts ("DEBUG: parse_ipv4_route");
3622 - r->flags = *opt++;
3623 - r->message = *opt++;
3624 - r->prefixlen = *opt++;
3628 - if ((int)len < r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0))
3631 - memcpy(&r->prefix, opt, r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0));
3632 - opt += r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0);
3634 - if (r->message & ZAPI_MESSAGE_NEXTHOP) {
3637 - r->nh_count = *opt++;
3638 - if (len < sizeof(uint32_t) * r->nh_count)
3640 - r->nexthops = olsr_malloc(sizeof(uint32_t) * r->nh_count, "quagga: parse_ipv4_route_add");
3641 - memcpy(r->nexthops, opt, sizeof(uint32_t) * r->nh_count);
3642 - opt += sizeof(uint32_t) * r->nh_count;
3643 - len -= sizeof(uint32_t) * r->nh_count + 1;
3646 - if (r->message & ZAPI_MESSAGE_IFINDEX) {
3649 - r->ind_num = *opt++;
3650 - if (len < sizeof(uint32_t) * r->ind_num)
3652 - r->index = olsr_malloc(sizeof(uint32_t) * r->ind_num, "quagga: parse_ipv4_route_add");
3653 - memcpy(r->index, opt, r->ind_num * sizeof(uint32_t));
3654 - opt += sizeof(uint32_t) * r->ind_num;
3655 - len -= sizeof(uint32_t) * r->ind_num;
3658 - if (r->message & ZAPI_MESSAGE_DISTANCE)
3662 - if (r->message & ZAPI_MESSAGE_METRIC) {
3663 - if (len < sizeof(uint32_t))
3665 - memcpy(&r->metric, opt, sizeof(uint32_t));
3672 -ipv4_route_add(char *opt, size_t len)
3675 - struct ipv4_route r;
3678 - // puts ("DEBUG: ipv4_route_add");
3680 - f = parse_ipv4_route(opt, len, &r);
3682 - printf("parse-error: %d\n", f);
3686 - add_hna4_route(r);
3691 -ipv4_route_delete(char *opt, size_t len)
3693 - struct ipv4_route r;
3696 - f = parse_ipv4_route(opt, len, &r);
3700 - return delete_hna4_route(r);
3701 - // OK, now delete that foo
3706 -parse_ipv6_route_add(char *opt, size_t len)
3712 -/* start redistribution FROM zebra */
3714 -zebra_redistribute(unsigned char type)
3717 - return zebra_send_command(ZEBRA_REDISTRIBUTE_ADD, &type, 1);
3721 -/* end redistribution FROM zebra */
3723 -zebra_disable_redistribute(unsigned char type)
3726 - return zebra_send_command(ZEBRA_REDISTRIBUTE_DELETE, &type, 1);
3731 -prefixlentomask(uint8_t prefix)
3734 - mask = prefix_to_netmask4(prefix);
3735 - mask = ntohl(mask);
3740 -add_hna4_route(struct ipv4_route r)
3742 - union olsr_ip_addr net, mask;
3745 - dump_ipv4_route(r, "add_hna4_route");
3748 - mask.v4 = prefixlentomask(r.prefixlen);
3749 - net.v4 = r.prefix;
3752 - add_local_hna4_entry(&net, &mask);
3754 - free_ipv4_route(r);
3759 -delete_hna4_route(struct ipv4_route r)
3762 - union olsr_ip_addr net, mask;
3765 - dump_ipv4_route(r, "delete_hna4_route");
3768 - mask.v4 = prefixlentomask(r.prefixlen);
3769 - net.v4 = r.prefix;
3772 - return remove_local_hna4_entry(&net, &mask) ? 0 : -1;
3775 - free_ipv4_route(r);
3781 -free_ipv4_route(struct ipv4_route r)
3784 - if (r.message & ZAPI_MESSAGE_IFINDEX && r.ind_num)
3786 - if (r.message & ZAPI_MESSAGE_NEXTHOP && r.nh_count)
3792 -zebra_clear_routes(void)
3795 - struct ipv4_route *t;
3797 - t = quagga_routes;
3799 - zebra_delete_v4_route(*t);
3802 - zebra_free_ipv4_route_table(quagga_routes);
3804 - quagga_routes = NULL;
3808 -zebra_update_hna(void *f)
3811 - struct ipv4_route *a = zebra_create_ipv4_route_table();
3812 - update_olsr_zebra_routes(a, quagga_routes);
3813 - zebra_free_ipv4_route_table(quagga_routes);
3815 - quagga_routes = a;
3819 -static struct ipv4_route *
3820 -zebra_create_ipv4_route_table(void)
3823 - struct ipv4_route *r = 0, *t = 0 /* make compiler happy */ ;
3825 - struct hna_entry *e;
3826 - struct hna_net *n;
3828 - for (i = 0; i < HASHSIZE; i++) {
3829 - e = hna_set[i].next;
3830 - for (; e != &hna_set[i]; e = e->next) {
3831 - n = e->networks.next;
3832 - for (; n != &e->networks; n = n->next) {
3834 - r = zebra_create_ipv4_route_table_entry(n->A_network_addr.v4, n->A_netmask.v4, e->A_gateway_addr.v4);
3837 - t->next = zebra_create_ipv4_route_table_entry(n->A_network_addr.v4, n->A_netmask.v4, e->A_gateway_addr.v4);
3848 -static struct ipv4_route *
3849 -zebra_create_ipv4_route_table_entry(uint32_t addr, uint32_t mask, uint32_t gw)
3852 - struct ipv4_route *r;
3854 - r = olsr_malloc(sizeof *r, "zebra_create_ipv4_route_table_entry");
3855 - memset(r, 0, sizeof *r);
3857 - r->prefixlen = masktoprefixlen(mask);
3858 - r->message |= ZAPI_MESSAGE_NEXTHOP;
3860 - r->nexthops = olsr_malloc(sizeof(uint32_t), "zebra_create_ipv4_route_table_entry");
3861 - *r->nexthops = gw;
3868 -masktoprefixlen(uint32_t mask)
3871 - uint8_t prefixlen = 0;
3872 -while (mask & (1 << ++prefixlen && prefixlen < 32); return prefixlen;}
3874 - static void update_olsr_zebra_routes(struct ipv4_route *a, struct ipv4_route *r) {
3876 - struct ipv4_route * t; if (!r) {
3877 - puts("no quagga_routing_table aviable"); for (; a; a = a->next) {
3878 - dump_ipv4_route(*a, "adding this route");
3879 - // zebra_add_v4_route(*r);
3884 - for (t = r; t; t = t->next) {
3885 - if (a->prefix == t->prefix) if (a->prefixlen == t->prefixlen) if (*a->nexthops == *t->nexthops) {
3888 - dump_ipv4_route(*a, "adding this route");
3889 - //zebra_add_v4_route(*a);
3894 - for (t = a; t; t = t->next) {
3895 - if (r->prefix == t->prefix) if (r->prefixlen == t->prefixlen) if (*r->nexthops == *t->nexthops) {
3898 - dump_ipv4_route(*r, "deleting this route");
3899 - //zebra_delete_v4_route(*r);
3905 - static void zebra_free_ipv4_route_table(struct ipv4_route *r) {
3906 - struct ipv4_route * n; if (!r) return; while ((n = r->next)) {
3907 - if (r->message & ZAPI_MESSAGE_NEXTHOP) free(r->nexthops); if (r->message & ZAPI_MESSAGE_IFINDEX) free(r->index); free(r);
3912 - * Local Variables:
3913 - * c-basic-offset: 2
3914 - * indent-tabs-mode: nil