remove the need for C99 math (closes: #1579)
[openwrt/svn-archive/archive.git] / net / olsrd / patches / 180-olsrd-bmf-fixes.patch
1 diff -Nur olsrd-0.4.10.orig/lib/bmf/src/Bmf.c olsrd-0.4.10/lib/bmf/src/Bmf.c
2 --- olsrd-0.4.10.orig/lib/bmf/src/Bmf.c 2006-11-29 12:45:19.000000000 +0100
3 +++ olsrd-0.4.10/lib/bmf/src/Bmf.c 2006-11-29 12:47:49.000000000 +0100
4 @@ -114,7 +114,15 @@
5
6 /* Only forward multicast or local broadcast packets */
7 COPY_IP(&destIp, &ipData->ip_dst);
8 - if (! IsMulticast(&destIp) && ! IsLocalBroadcast(&destIp, intf))
9 + if (! IsMulticast(&destIp)
10 +#ifdef SVEN_OLA_DISABLED
11 + /*
12 + * Sven-Ola@gmx.de: In a bigger mesh, there are a lot of
13 + * accidential bcast sources. Disabled to save bandwidth
14 + */
15 + && ! IsLocalBroadcast(&destIp, intf)
16 +#endif
17 + )
18 {
19 return;
20 }
21 @@ -128,9 +136,10 @@
22 COPY_IP(&srcIp, &ipData->ip_src);
23 olsr_printf(
24 9,
25 - "%s: pkt of %d bytes incoming on \"%s\": %s->%s\n",
26 + "%s: pkt of %d bytes ttl=%d incoming on \"%s\": %s->%s\n",
27 PLUGIN_NAME_SHORT,
28 ethPktLen,
29 + GetIpTtl(ethPkt),
30 intf->ifName,
31 olsr_ip_to_string(&srcIp),
32 olsr_ip_to_string(&destIp));
33 @@ -191,6 +200,7 @@
34 struct TEncapHeader* encapHdr = (struct TEncapHeader*) buffer;
35 memset (encapHdr, 0, ENCAP_HDR_LEN);
36 encapHdr->crc32 = htonl(crc32);
37 + encapHdr->encapttl = GetIpTtl(ethPkt);
38
39 /* If this packet is captured on an OLSR interface from an OLSR neighbor,
40 * check with OLSR if I am MPR for that neighbor */
41 @@ -248,7 +258,7 @@
42 /* If the TTL is <= 0, do not forward this packet */
43 if (GetIpTtl(ethPkt) <= 0)
44 {
45 - OLSR_PRINTF(
46 + olsr_printf(
47 9,
48 "%s: --> not forwarding on \"%s\": TTL=0\n",
49 PLUGIN_NAME_SHORT,
50 @@ -272,10 +282,11 @@
51 }
52 else
53 {
54 - OLSR_PRINTF(
55 + olsr_printf(
56 9,
57 - "%s: --> forwarded to \"%s\"\n",
58 + "%s: --> forwarded(capt) ttl=%d to \"%s\"\n",
59 PLUGIN_NAME_SHORT,
60 + GetIpTtl(ethPkt),
61 fwIntf->ifName);
62 }
63 }
64 @@ -291,6 +302,7 @@
65 if (isToOlsrIntf && !iAmNotMpr)
66 {
67 int nBytesWritten;
68 + unsigned char ttl;
69
70 /* Change encapsulated source MAC address to that of sending interface */
71 memcpy(ethPkt + IFHWADDRLEN, fwIntf->macAddr, IFHWADDRLEN);
72 @@ -298,6 +310,10 @@
73 /* Destination address is local broadcast */
74 encapDest.sin_addr.s_addr = ((struct sockaddr_in*)&fwIntf->olsrIntf->int_broadaddr)->sin_addr.s_addr;
75
76 + /* SVEN_OLA: Normal TTL of this socket will be 64 if unset */
77 + ttl = GetIpTtl(ethPkt);
78 + if (0 <= (nBytesWritten = setsockopt(fwIntf->encapsulatingSkfd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))))
79 +
80 nBytesWritten = sendto(
81 fwIntf->encapsulatingSkfd,
82 buffer,
83 @@ -306,6 +322,18 @@
84 (struct sockaddr*) &encapDest,
85 sizeof(encapDest));
86
87 + /*
88 + * Sven-Ola@gmx.de: Very primitive testing of forward error correction
89 + */
90 + if (nBytesWritten == len)
91 + nBytesWritten = sendto(
92 + fwIntf->encapsulatingSkfd,
93 + buffer,
94 + len,
95 + MSG_DONTROUTE,
96 + (struct sockaddr*) &encapDest,
97 + sizeof(encapDest));
98 +
99 if (nBytesWritten != len)
100 {
101 olsr_printf(
102 @@ -318,10 +346,11 @@
103 }
104 else
105 {
106 - OLSR_PRINTF(
107 + olsr_printf(
108 9,
109 - "%s: --> encapsulated and forwarded to \"%s\"\n",
110 + "%s: --> encapsulated and forwarded ttl=%d to \"%s\"\n",
111 PLUGIN_NAME_SHORT,
112 + GetIpTtl(ethPkt),
113 fwIntf->ifName);
114 } /* if (nBytesWritten != len) */
115 } /* else if (isToOlsrIntf && !iAmNotMpr) */
116 @@ -329,7 +358,7 @@
117 else /* (!isFromOlsrIntf || isToOlsrIntf) && (!isToOlsrIntf || iAmNotMpr) */
118 if (!isFromOlsrIntf && !isToOlsrIntf)
119 {
120 - OLSR_PRINTF(
121 + olsr_printf(
122 9,
123 "%s: --> not forwarding from \"%s\" to \"%s\": both non-OLSR interfaces\n",
124 PLUGIN_NAME_SHORT,
125 @@ -339,7 +368,7 @@
126
127 else /* (!isFromOlsrIntf || isToOlsrIntf) && (!isToOlsrIntf || iAmNotMpr) && (isFromOlsrIntf || isToOlsrIntf) */
128 {
129 - OLSR_PRINTF(
130 + olsr_printf(
131 9,
132 "%s: --> not forwarding from \"%s\" to \"%s\": I am not selected as MPR by %s\n",
133 PLUGIN_NAME_SHORT,
134 @@ -402,17 +431,21 @@
135
136 ipData = (struct ip*) (ethPkt + IP_HDR_OFFSET);
137
138 - OLSR_PRINTF(
139 + olsr_printf(
140 9,
141 - "%s: encapsulated pkt of %d bytes incoming on \"%s\": %s->",
142 + "%s: encapsulated pkt of %d bytes ttl=%d incoming on \"%s\": %s->",
143 PLUGIN_NAME_SHORT,
144 ethPktLen,
145 + GetIpTtl(ethPkt),
146 intf->ifName,
147 inet_ntoa(ipData->ip_src));
148 - OLSR_PRINTF(
149 + olsr_printf(
150 9,
151 - "%s, forwarded by %s\n",
152 - inet_ntoa(ipData->ip_dst), /* not possible to call inet_ntoa twice in same printf */
153 + "%s, ",
154 + inet_ntoa(ipData->ip_dst)); /* not possible to call inet_ntoa twice in same printf */
155 + olsr_printf(
156 + 9,
157 + "forwarded by %s\n",
158 olsr_ip_to_string(fromIp));
159
160 /* Get encapsulation header */
161 @@ -421,7 +454,7 @@
162 /* Check if this packet was seen recently */
163 if (CheckAndMarkRecentPacket(Hash16(ntohl(encapHdr->crc32))))
164 {
165 - OLSR_PRINTF(
166 + olsr_printf(
167 9,
168 "%s: --> discarding: packet is duplicate\n",
169 PLUGIN_NAME_SHORT);
170 @@ -448,12 +481,28 @@
171 }
172 else
173 {
174 - OLSR_PRINTF(
175 + olsr_printf(
176 9,
177 - "%s: --> unpacked and forwarded to \"%s\"\n",
178 + "%s: --> unpacked and forwarded ttl=%d to \"%s\"\n",
179 PLUGIN_NAME_SHORT,
180 + GetIpTtl(ethPkt),
181 EtherTunTapIfName);
182 }
183 +
184 + /*
185 + * Sven-Ola@gmx.de: The original implemenation make a wave
186 + * through the complete mesh for every packet. Packets are
187 + * discarded if any device has seen it (most bad case). We
188 + * Want some "local" distribution mode, so I've added some
189 + * hopcounter here - derived from the original ttl
190 + */
191 + if (0 == encapHdr->encapttl || 0 == --encapHdr->encapttl) {
192 + olsr_printf(
193 + 9,
194 + "%s: --> dicarding encapsulated: TTL=0\n",
195 + PLUGIN_NAME_SHORT);
196 + return;
197 + }
198
199 /* Lookup main address of forwarding node */
200 forwarder = mid_lookup_main_addr(fromIp);
201 @@ -489,7 +538,7 @@
202 /* If the TTL is <= 0, do not forward this packet */
203 if (GetIpTtl(ethPkt) <= 0)
204 {
205 - OLSR_PRINTF(
206 + olsr_printf(
207 9,
208 "%s: --> not forwarding on \"%s\": TTL=0\n",
209 PLUGIN_NAME_SHORT,
210 @@ -509,10 +558,12 @@
211 }
212 else
213 {
214 - OLSR_PRINTF(
215 + olsr_printf(
216 9,
217 - "%s: --> unpacked and forwarded to \"%s\"\n",
218 + "%s: --> unpacked and forwarded ttl=%d, sttl=%d to \"%s\"\n",
219 PLUGIN_NAME_SHORT,
220 + GetIpTtl(ethPkt),
221 + sttl.ttl,
222 fwIntf->ifName);
223 }
224 }
225 @@ -551,17 +602,18 @@
226 }
227 else
228 {
229 - OLSR_PRINTF(
230 + olsr_printf(
231 9,
232 - "%s: --> forwarded to \"%s\"\n",
233 + "%s: --> forwarded(encrec) ttl=%d to \"%s\"\n",
234 PLUGIN_NAME_SHORT,
235 + GetIpTtl(ethPkt),
236 fwIntf->ifName);
237 }
238 } /* else if (iAmMpr) */
239 else /* fwIntf->olsrIntf != NULL && !iAmMpr */
240 {
241 /* fwIntf is an OLSR interface and I am not selected as MPR */
242 - OLSR_PRINTF(
243 + olsr_printf(
244 9,
245 "%s: --> not forwarding to \"%s\": I am not selected as MPR by %s\n",
246 PLUGIN_NAME_SHORT,
247 @@ -690,7 +742,15 @@
248 {
249 union olsr_ip_addr destIp;
250 COPY_IP(&destIp, &ipData->ip_dst);
251 - if (IsMulticast(&destIp) || IsLocalBroadcast(&destIp, currIf))
252 + if (IsMulticast(&destIp)
253 +#ifdef SVEN_OLA_DISABLED
254 + /*
255 + * Sven-Ola@gmx.de: In a bigger mesh, there are a lot of
256 + * accidential bcast sources. Disabled to save bandwidth
257 + */
258 + || IsLocalBroadcast(&destIp, currIf)
259 +#endif
260 + )
261 {
262 if (! IsOlsrOrBmfPacket(currIf, ethPkt, nBytes))
263 {
264 @@ -701,8 +761,15 @@
265 }
266 }
267 }
268 - else if (pktAddr.sll_pkttype == PACKET_MULTICAST ||
269 - pktAddr.sll_pkttype == PACKET_BROADCAST)
270 + else if (pktAddr.sll_pkttype == PACKET_MULTICAST
271 +#ifdef SVEN_OLA_DISABLED
272 + /*
273 + * Sven-Ola@gmx.de: In a bigger mesh, there are a lot of
274 + * accidential bcast sources. Disabled to save bandwidth
275 + */
276 + || pktAddr.sll_pkttype == PACKET_BROADCAST
277 +#endif
278 + )
279 {
280 /* An inbound multicast or broadcast packet was captured */
281 BmfPacketCaptured(currIf, buffer, nBytes + ENCAP_HDR_LEN);
282 diff -Nur olsrd-0.4.10.orig/lib/bmf/src/NetworkInterfaces.c olsrd-0.4.10/lib/bmf/src/NetworkInterfaces.c
283 --- olsrd-0.4.10.orig/lib/bmf/src/NetworkInterfaces.c 2006-11-29 12:45:19.000000000 +0100
284 +++ olsrd-0.4.10/lib/bmf/src/NetworkInterfaces.c 2006-11-29 12:47:49.000000000 +0100
285 @@ -568,7 +568,7 @@
286 newIf->next = BmfInterfaces;
287 BmfInterfaces = newIf;
288
289 - OLSR_PRINTF(
290 + olsr_printf(
291 9,
292 "%s: opened %s interface \"%s\"\n",
293 PLUGIN_NAME_SHORT,
294 @@ -738,7 +738,7 @@
295 nClosed++;
296 }
297
298 - OLSR_PRINTF(
299 + olsr_printf(
300 9,
301 "%s: closed %s interface \"%s\"\n",
302 PLUGIN_NAME_SHORT,
303 @@ -756,7 +756,7 @@
304 close(EtherTunTapFd);
305 nClosed++;
306
307 - OLSR_PRINTF(9, "%s: closed \"%s\"\n", PLUGIN_NAME_SHORT, EtherTunTapIfName);
308 + olsr_printf(9, "%s: closed \"%s\"\n", PLUGIN_NAME_SHORT, EtherTunTapIfName);
309 }
310
311 BmfInterfaces = NULL;
312 diff -Nur olsrd-0.4.10.orig/lib/bmf/src/Packet.c olsrd-0.4.10/lib/bmf/src/Packet.c
313 --- olsrd-0.4.10.orig/lib/bmf/src/Packet.c 2006-11-29 12:45:19.000000000 +0100
314 +++ olsrd-0.4.10/lib/bmf/src/Packet.c 2006-11-29 12:50:35.000000000 +0100
315 @@ -46,6 +46,8 @@
316 #include <assert.h> /* assert() */
317 #include <sys/types.h> /* u_int32_t */
318 #include <netinet/in.h> /* ntohs(), htons() */
319 +/* Fixes (k)ubuntu linux-kernel-headers package */
320 +#include <asm/byteorder.h>
321 #include <linux/ip.h>
322
323 /* -------------------------------------------------------------------------
324 diff -Nur olsrd-0.4.10.orig/lib/bmf/src/Packet.h olsrd-0.4.10/lib/bmf/src/Packet.h
325 --- olsrd-0.4.10.orig/lib/bmf/src/Packet.h 2006-11-29 12:45:19.000000000 +0100
326 +++ olsrd-0.4.10/lib/bmf/src/Packet.h 2006-11-29 12:47:49.000000000 +0100
327 @@ -66,7 +66,8 @@
328 u_int32_t crc32;
329 u_int32_t futureExpansion1;
330 u_int32_t futureExpansion2;
331 - u_int32_t futureExpansion3;
332 + u_int8_t futureExpansion3[3];
333 + u_int8_t encapttl;
334 } __attribute__((__packed__));
335
336 #define ENCAP_HDR_LEN sizeof(struct TEncapHeader)