[packages] olsrd: Add support for new zebra protocol version used by Quagga 0.99.21
[packages.git] / net / olsrd / patches / 120-quagga-0.99.21.patch
1 --- a/lib/quagga/src/common.h
2 +++ b/lib/quagga/src/common.h
3 @@ -2,7 +2,7 @@
4   * OLSRd Quagga plugin
5   *
6   * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
7 - * Copyright (C) 2007-2010 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
8 + * Copyright (C) 2007-2012 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
9   *
10   * This program is free software; you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License version 2 as
12 @@ -21,7 +21,7 @@
13  
14  /* Zebra route types */
15  #define ZEBRA_ROUTE_OLSR               11
16 -#define ZEBRA_ROUTE_MAX                        13
17 +#define ZEBRA_ROUTE_MAX                        14
18  
19  struct zebra {
20    unsigned char status;
21 --- a/lib/quagga/src/packet.c
22 +++ b/lib/quagga/src/packet.c
23 @@ -2,7 +2,7 @@
24   * OLSRd Quagga plugin
25   *
26   * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
27 - * Copyright (C) 2007-2010 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
28 + * Copyright (C) 2007-2012 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
29   *
30   * This program is free software; you can redistribute it and/or modify
31   * it under the terms of the GNU General Public License version 2 as
32 @@ -28,24 +28,43 @@ unsigned char
33  {
34    int count;
35    uint8_t len;
36 -  uint16_t size;
37 +  uint16_t size, safi;
38    uint32_t ind, metric;
39    unsigned char *cmdopt, *t;
40  
41    cmdopt = olsr_malloc(ZEBRA_MAX_PACKET_SIZ, "QUAGGA: New route packet");
42  
43    t = &cmdopt[2];
44 -  if (zebra.version) {
45 -    *t++ = ZEBRA_HEADER_MARKER;
46 -    *t++ = zebra.version;
47 -    cmd = htons(cmd);
48 -    memcpy(t, &cmd, sizeof cmd);
49 -    t += sizeof cmd;
50 -  } else
51 +  switch (zebra.version) {
52 +    case 0:
53        *t++ = (unsigned char) cmd;
54 +      break;
55 +    case 1:
56 +    case 2:
57 +      *t++ = ZEBRA_HEADER_MARKER;
58 +      *t++ = zebra.version;
59 +      cmd = htons(cmd);
60 +      memcpy(t, &cmd, sizeof cmd);
61 +      t += sizeof cmd;
62 +      break;
63 +    default:
64 +      break;
65 +  }
66    *t++ = r->type;
67    *t++ = r->flags;
68    *t++ = r->message;
69 +  switch (zebra.version) {
70 +    case 0:
71 +    case 1:
72 +      break;
73 +    case 2:
74 +      safi = htons(r->safi);
75 +      memcpy(t, &safi, sizeof safi);
76 +      t += sizeof safi;
77 +      break;
78 +    default:
79 +      break;
80 +  }
81    *t++ = r->prefixlen;
82    len = (r->prefixlen + 7) / 8;
83    if (olsr_cnf->ip_version == AF_INET)
84 @@ -97,14 +116,21 @@ unsigned char
85    data = olsr_malloc(ZEBRA_MAX_PACKET_SIZ , "QUAGGA: New redistribute packet");
86  
87    pnt = &data[2];
88 -  if (zebra.version) {
89 -    *pnt++ = ZEBRA_HEADER_MARKER;
90 -    *pnt++ = zebra.version;
91 -    cmd = htons(cmd);
92 -    memcpy(pnt, &cmd, sizeof cmd);
93 -    pnt += sizeof cmd;
94 -  } else
95 +  switch (zebra.version) {
96 +    case 0:
97        *pnt++ = (unsigned char) cmd;
98 +      break;
99 +    case 1:
100 +    case 2:
101 +      *pnt++ = ZEBRA_HEADER_MARKER;
102 +      *pnt++ = zebra.version;
103 +      cmd = htons(cmd);
104 +      memcpy(pnt, &cmd, sizeof cmd);
105 +      pnt += sizeof cmd;
106 +      break;
107 +    default:
108 +      break;
109 +  }
110    *pnt++ = type;
111    size = htons(pnt - data);
112    memcpy(data, &size, sizeof size);
113 --- a/lib/quagga/src/packet.h
114 +++ b/lib/quagga/src/packet.h
115 @@ -2,7 +2,7 @@
116   * OLSRd Quagga plugin
117   *
118   * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
119 - * Copyright (C) 2007-2010 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
120 + * Copyright (C) 2007-2012 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
121   *
122   * This program is free software; you can redistribute it and/or modify
123   * it under the terms of the GNU General Public License version 2 as
124 @@ -32,6 +32,7 @@
125  #define ZEBRA_IPV6_ROUTE_DELETE         10
126  #define ZEBRA_REDISTRIBUTE_ADD         11
127  #define ZEBRA_REDISTRIBUTE_DELETE      12
128 +#define ZEBRA_HELLO                    23
129  
130  /* Zebra nexthop flags */
131  #define ZEBRA_NEXTHOP_IFINDEX          1
132 @@ -44,6 +45,9 @@
133  #define ZAPI_MESSAGE_DISTANCE          0x04
134  #define ZAPI_MESSAGE_METRIC            0x08
135  
136 +/* Subsequent Address Family Identifier */
137 +#define SAFI_UNICAST                    1
138 +
139  /* Zebra flags */
140  #define ZEBRA_FLAG_SELECTED            0x10
141  
142 @@ -51,6 +55,7 @@ struct zroute {
143    unsigned char type;
144    unsigned char flags;
145    unsigned char message;
146 +  uint16_t safi;
147    unsigned char prefixlen;
148    union olsr_ip_addr prefix;
149    unsigned char nexthop_num;
150 --- a/lib/quagga/src/parse.c
151 +++ b/lib/quagga/src/parse.c
152 @@ -2,7 +2,7 @@
153   * OLSRd Quagga plugin
154   *
155   * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
156 - * Copyright (C) 2007-2010 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
157 + * Copyright (C) 2007-2012 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
158   *
159   * This program is free software; you can redistribute it and/or modify
160   * it under the terms of the GNU General Public License version 2 as
161 @@ -52,7 +52,17 @@ static struct zroute
162    length = ntohs (length);
163  
164    r = olsr_malloc(sizeof *r, "QUAGGA: New zebra route");
165 -  pnt = (zebra.version ? &opt[6] : &opt[3]);
166 +  switch (zebra.version) {
167 +    case 0:
168 +      pnt = &opt[3];
169 +      break;
170 +    case 1:
171 +    case 2:
172 +      pnt = &opt[6];
173 +      break;
174 +    default:
175 +      break;
176 +  }
177    r->type = *pnt++;
178    r->flags = *pnt++;
179    r->message = *pnt++;
180 @@ -68,6 +78,7 @@ static struct zroute
181    switch (zebra.version) {
182      case 0:
183      case 1:
184 +    case 2:
185        if (r->message & ZAPI_MESSAGE_NEXTHOP) {
186          r->nexthop_num = *pnt++;
187          r->nexthop = olsr_malloc((sizeof *r->nexthop) * r->nexthop_num, "QUAGGA: New zebra route nexthop");
188 @@ -137,13 +148,20 @@ zparse(void *foo __attribute__ ((unused)
189        length = ntohs (length);
190        if (!length) // something weired happened
191          olsr_exit("(QUAGGA) Zero message length!", EXIT_FAILURE);
192 -      if (zebra.version) {
193 -        if ((f[2] != ZEBRA_HEADER_MARKER) || (f[3] != zebra.version))
194 -          olsr_exit("(QUAGGA) Invalid zebra header received!", EXIT_FAILURE);
195 -        memcpy(&command, &f[4], sizeof command);
196 -        command = ntohs (command);
197 -      } else
198 +      switch (zebra.version) {
199 +        case 0:
200            command = f[2];
201 +          break;
202 +        case 1:
203 +        case 2:
204 +          if ((f[2] != ZEBRA_HEADER_MARKER) || (f[3] != zebra.version))
205 +            olsr_exit("(QUAGGA) Invalid zebra header received!", EXIT_FAILURE);
206 +          memcpy(&command, &f[4], sizeof command);
207 +          command = ntohs (command);
208 +          break;
209 +        default:
210 +          break;
211 +      }
212        if (olsr_cnf->ip_version == AF_INET) {
213          switch (command) {
214            case ZEBRA_IPV4_ROUTE_ADD:
215 --- a/lib/quagga/src/plugin.c
216 +++ b/lib/quagga/src/plugin.c
217 @@ -2,7 +2,7 @@
218   * OLSRd Quagga plugin
219   *
220   * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
221 - * Copyright (C) 2007-2010 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
222 + * Copyright (C) 2007-2012 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
223   *
224   * This program is free software; you can redistribute it and/or modify
225   * it under the terms of the GNU General Public License version 2 as
226 @@ -50,7 +50,7 @@ zplugin_redistribute(const char *value,
227  {
228    const char *zroute_types[] = { "system", "kernel", "connect",
229      "static", "rip", "ripng", "ospf", "ospf6", "isis", "bgp",
230 -    "hsls", "olsr", "batman"
231 +    "hsls", "olsr", "batman", "babel"
232    };
233    unsigned int i;
234  
235 @@ -144,7 +144,7 @@ zplugin_version(const char *value, void
236  
237    if (set_plugin_int(value, &version, addon))
238      return 1;
239 -  if (version < 0 || version > 1)
240 +  if (version < 0 || version > 2)
241      return 1;
242    zebra.version = version;
243  
244 --- a/lib/quagga/src/quagga.c
245 +++ b/lib/quagga/src/quagga.c
246 @@ -2,7 +2,7 @@
247   * OLSRd Quagga plugin
248   *
249   * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
250 - * Copyright (C) 2007-2011 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
251 + * Copyright (C) 2007-2012 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
252   *
253   * This program is free software; you can redistribute it and/or modify
254   * it under the terms of the GNU General Public License version 2 as
255 @@ -63,6 +63,7 @@ zebra_addroute(const struct rt_entry *r)
256    route.type = ZEBRA_ROUTE_OLSR;
257    route.flags = zebra.flags;
258    route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC;
259 +  route.safi = SAFI_UNICAST;
260    route.prefixlen = r->rt_dst.prefix_len;
261    if (olsr_cnf->ip_version == AF_INET)
262      route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr;
263 @@ -112,6 +113,7 @@ zebra_delroute(const struct rt_entry *r)
264    route.type = ZEBRA_ROUTE_OLSR;
265    route.flags = zebra.flags;
266    route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC;
267 +  route.safi = SAFI_UNICAST;
268    route.prefixlen = r->rt_dst.prefix_len;
269    if (olsr_cnf->ip_version == AF_INET)
270      route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr;
271 @@ -164,6 +166,15 @@ zebra_redistribute(uint16_t cmd)
272  
273  }
274  
275 +void
276 +zebra_hello(uint16_t cmd)
277 +{
278 +
279 +  if (zclient_write(zpacket_redistribute(cmd, ZEBRA_ROUTE_OLSR)) < 0)
280 +    olsr_exit("(QUAGGA) Could not write hello packet!", EXIT_FAILURE);
281 +
282 +}
283 +
284  /*
285   * Local Variables:
286   * c-basic-offset: 2
287 --- a/lib/quagga/src/client.c
288 +++ b/lib/quagga/src/client.c
289 @@ -2,7 +2,7 @@
290   * OLSRd Quagga plugin
291   *
292   * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
293 - * Copyright (C) 2007-2010 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
294 + * Copyright (C) 2007-2012 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
295   *
296   * This program is free software; you can redistribute it and/or modify
297   * it under the terms of the GNU General Public License version 2 as
298 @@ -95,6 +95,7 @@ zclient_reconnect(void)
299    if (!(zebra.status & STATUS_CONNECTED))
300      return;                     // try again next time
301  
302 +  zebra_hello(ZEBRA_HELLO);
303    if (zebra.options & OPTION_EXPORT) {
304      OLSR_FOR_ALL_RT_ENTRIES(tmp) {
305        zebra_addroute(tmp);
306 --- a/lib/quagga/README_QUAGGA
307 +++ b/lib/quagga/README_QUAGGA
308 @@ -11,9 +11,9 @@ It allows olsrd to redistribute from var
309  as well as to export olsr-routes to quagga so that they can be
310  redistributed by the quagga-routing-daemons.
311  
312 -You also need a source distribution of quagga-0.98.6 or quagga-0.99.15.
313 +You also need a source distribution of quagga-0.98.6 or quagga-0.99.21.
314  The quagga source tree needs to be patched with quagga-0.98.6.diff or
315 -quagga-0.99.15.diff, respectively, compiled and installed via
316 +quagga-0.99.21.diff, respectively, compiled and installed via
317  'make install'.
318  
319  ---------------------------------------------------------------------
320 @@ -48,7 +48,10 @@ PlParam "Port" "<port>"
321  
322  PlParam "Version" "<version>"
323          sets the version of packet format to communicate with zebra.
324 -       use "0" for Quagga 0.98.x and "1" for Quagga 0.99.x.
325 +       use:
326 +          "0" for Quagga 0.98.x
327 +          "1" for Quagga 0.99.17 up to 0.99.20.1
328 +          "2" for Quagga 0.99.21 and above
329         defaults to "0".
330  
331  ---------------------------------------------------------------------
332 @@ -65,9 +68,9 @@ LoadPlugin "olsrd_quagga.so.0.2.2"
333         PlParam "Distance" "125" 
334         PlParam "LocalPref" "false"
335         PlParam "SockPath" "/var/run/zserv.api"
336 -       PlParam "Version" "1"
337 +       PlParam "Version" "2"
338  }
339  
340  
341  ---------------------------------------------------------------------
342 -EOF / 10.03.2010
343 +EOF / 31.05.2012
344 --- a/lib/quagga/src/quagga.h
345 +++ b/lib/quagga/src/quagga.h
346 @@ -2,7 +2,7 @@
347   * OLSRd Quagga plugin
348   *
349   * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de>
350 - * Copyright (C) 2007-2010 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
351 + * Copyright (C) 2007-2012 Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
352   *
353   * This program is free software; you can redistribute it and/or modify
354   * it under the terms of the GNU General Public License version 2 as
355 @@ -31,6 +31,7 @@ void zebra_fini(void);
356  int zebra_addroute(const struct rt_entry *);
357  int zebra_delroute(const struct rt_entry *);
358  void zebra_redistribute(uint16_t cmd);
359 +void zebra_hello(uint16_t cmd);
360  
361  /*
362   * Local Variables: