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