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