remove the need for C99 math (closes: #1579)
[openwrt/svn-archive/archive.git] / net / olsrd / patches / 120-olsrd-dyngwplain.patch
1 diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/Makefile olsrd-0.4.10/lib/dyn_gw_plain/Makefile
2 --- olsrd-0.4.10.orig/lib/dyn_gw_plain/Makefile 1970-01-01 01:00:00.000000000 +0100
3 +++ olsrd-0.4.10/lib/dyn_gw_plain/Makefile 2006-12-01 08:26:58.000000000 +0100
4 @@ -0,0 +1,57 @@
5 +# The olsr.org Optimized Link-State Routing daemon(olsrd)
6 +# Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
7 +# All rights reserved.
8 +#
9 +# Redistribution and use in source and binary forms, with or without
10 +# modification, are permitted provided that the following conditions
11 +# are met:
12 +#
13 +# * Redistributions of source code must retain the above copyright
14 +# notice, this list of conditions and the following disclaimer.
15 +# * Redistributions in binary form must reproduce the above copyright
16 +# notice, this list of conditions and the following disclaimer in
17 +# the documentation and/or other materials provided with the
18 +# distribution.
19 +# * Neither the name of olsr.org, olsrd nor the names of its
20 +# contributors may be used to endorse or promote products derived
21 +# from this software without specific prior written permission.
22 +#
23 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 +# POSSIBILITY OF SUCH DAMAGE.
35 +#
36 +# Visit http://www.olsr.org for more information.
37 +#
38 +# If you find this software useful feel free to make a donation
39 +# to the project. For more information see the website or contact
40 +# the copyright holders.
41 +#
42 +# $Id: olsrd-dyngwplain.patch,v 1.5 2006/12/04 08:33:46 sven-ola Exp $
43 +
44 +OLSRD_PLUGIN = true
45 +PLUGIN_NAME = olsrd_dyn_gw_plain
46 +PLUGIN_VER = 0.4
47 +
48 +TOPDIR = ../..
49 +include $(TOPDIR)/Makefile.inc
50 +
51 +default_target: $(PLUGIN_FULLNAME)
52 +
53 +$(PLUGIN_FULLNAME): $(OBJS)
54 + $(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(LIBS)
55 +
56 +install: $(PLUGIN_FULLNAME)
57 + $(STRIP) $(PLUGIN_FULLNAME)
58 + $(INSTALL_LIB)
59 +
60 +clean:
61 + rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
62 diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/README_DYN_GW_PLAIN olsrd-0.4.10/lib/dyn_gw_plain/README_DYN_GW_PLAIN
63 --- olsrd-0.4.10.orig/lib/dyn_gw_plain/README_DYN_GW_PLAIN 1970-01-01 01:00:00.000000000 +0100
64 +++ olsrd-0.4.10/lib/dyn_gw_plain/README_DYN_GW_PLAIN 2006-12-01 08:26:58.000000000 +0100
65 @@ -0,0 +1,17 @@
66 +DYNAMIC INTERNET GATEWAY PLAIN PLUGIN FOR olsr.org olsrd
67 +by Andreas Tønnesen(andreto@olsr.org)
68 +additions by Sven-Ola Tuecke
69 +
70 +This plugin is without Ping/libthread. It is the plain dyn_gw!
71 +
72 +HOW TO USE
73 +
74 +Add an entry like this to your olsrd configuration file:
75 +
76 +LoadPlugin "olsrd_dyn_gw_plain.so.0.4"
77 +{
78 +}
79 +
80 +ABOUT
81 +
82 +Plugin is IPv4 only.
83 diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.c olsrd-0.4.10/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.c
84 --- olsrd-0.4.10.orig/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.c 1970-01-01 01:00:00.000000000 +0100
85 +++ olsrd-0.4.10/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.c 2006-12-01 08:26:58.000000000 +0100
86 @@ -0,0 +1,186 @@
87 +/*
88 + * The olsr.org Optimized Link-State Routing daemon(olsrd)
89 + * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
90 + * All rights reserved.
91 + *
92 + * Redistribution and use in source and binary forms, with or without
93 + * modification, are permitted provided that the following conditions
94 + * are met:
95 + *
96 + * * Redistributions of source code must retain the above copyright
97 + * notice, this list of conditions and the following disclaimer.
98 + * * Redistributions in binary form must reproduce the above copyright
99 + * notice, this list of conditions and the following disclaimer in
100 + * the documentation and/or other materials provided with the
101 + * distribution.
102 + * * Neither the name of olsr.org, olsrd nor the names of its
103 + * contributors may be used to endorse or promote products derived
104 + * from this software without specific prior written permission.
105 + *
106 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
107 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
108 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
109 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
110 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
111 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
112 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
113 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
114 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
115 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
116 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
117 + * POSSIBILITY OF SUCH DAMAGE.
118 + *
119 + * Visit http://www.olsr.org for more information.
120 + *
121 + * If you find this software useful feel free to make a donation
122 + * to the project. For more information see the website or contact
123 + * the copyright holders.
124 + */
125 +
126 +#include "olsr_types.h"
127 +#include "olsrd_dyn_gw_plain.h"
128 +#include "scheduler.h"
129 +#include "olsr.h"
130 +#include "local_hna_set.h"
131 +#include <stdio.h>
132 +#include <string.h>
133 +#include <stdlib.h>
134 +#include <net/route.h>
135 +#include <linux/in_route.h>
136 +#include <unistd.h>
137 +#include <errno.h>
138 +
139 +#define DEBUGLEV 1
140 +
141 +static int has_inet_gateway;
142 +
143 +/**
144 + * Plugin interface version
145 + * Used by main olsrd to check plugin interface version
146 + */
147 +int
148 +olsrd_plugin_interface_version()
149 +{
150 + return OLSRD_PLUGIN_INTERFACE_VERSION;
151 +}
152 +
153 +/**
154 + * Register parameters from config file
155 + * Called for all plugin parameters
156 + */
157 +int
158 +olsrd_plugin_register_param(char *key, char *value)
159 +{
160 + return 1;
161 +}
162 +
163 +/**
164 + * Initialize plugin
165 + * Called after all parameters are passed
166 + */
167 +int
168 +olsrd_plugin_init()
169 +{
170 + gw_net.v4 = INET_NET;
171 + gw_netmask.v4 = INET_PREFIX;
172 +
173 + has_inet_gateway = 0;
174 +
175 + /* Remove all local Inet HNA entries */
176 + while(remove_local_hna4_entry(&gw_net, &gw_netmask)) {
177 + olsr_printf(DEBUGLEV, "HNA Internet gateway deleted\n");
178 + }
179 +
180 + /* Register the GW check */
181 + olsr_register_scheduler_event(&olsr_event, NULL, 3, 4, NULL);
182 +
183 + return 1;
184 +}
185 +
186 +int
187 +check_gw(union olsr_ip_addr *net, union olsr_ip_addr *mask)
188 +{
189 + char buff[1024], iface[16];
190 + olsr_u32_t gate_addr, dest_addr, netmask;
191 + unsigned int iflags;
192 + int num, metric, refcnt, use;
193 + int retval = 0;
194 +
195 + FILE *fp = fopen(PROCENTRY_ROUTE, "r");
196 +
197 + if (!fp)
198 + {
199 + perror(PROCENTRY_ROUTE);
200 + olsr_printf(DEBUGLEV, "INET (IPv4) not configured in this system.\n");
201 + return -1;
202 + }
203 +
204 + rewind(fp);
205 +
206 + /*
207 + olsr_printf(DEBUGLEV, "Genmask Destination Gateway "
208 + "Flags Metric Ref Use Iface\n");
209 + /**/
210 + while (fgets(buff, 1023, fp))
211 + {
212 + num = sscanf(buff, "%16s %128X %128X %X %d %d %d %128X \n",
213 + iface, &dest_addr, &gate_addr,
214 + &iflags, &refcnt, &use, &metric, &netmask);
215 +
216 + if (num < 8)
217 + {
218 + continue;
219 + }
220 +
221 + /*
222 + olsr_printf(DEBUGLEV, "%-15s ", olsr_ip_to_string((union olsr_ip_addr *)&netmask));
223 +
224 + olsr_printf(DEBUGLEV, "%-15s ", olsr_ip_to_string((union olsr_ip_addr *)&dest_addr));
225 +
226 + olsr_printf(DEBUGLEV, "%-15s %-6d %-2d %7d %s\n",
227 + olsr_ip_to_string((union olsr_ip_addr *)&gate_addr),
228 + metric, refcnt, use, iface);
229 + /**/
230 +
231 + if(//(iflags & RTF_GATEWAY) &&
232 + (iflags & RTF_UP) &&
233 + (metric == 0) &&
234 + (netmask == mask->v4) &&
235 + (dest_addr == net->v4))
236 + {
237 + olsr_printf(DEBUGLEV, "INTERNET GATEWAY VIA %s detected in routing table.\n", iface);
238 + retval=1;
239 + }
240 +
241 + }
242 +
243 + fclose(fp);
244 +
245 + if(retval == 0)
246 + {
247 + olsr_printf(DEBUGLEV, "No Internet GWs detected...\n");
248 + }
249 +
250 + return retval;
251 +}
252 +
253 +/**
254 + * Scheduled event to update the hna table,
255 + * called from olsrd main thread to keep the hna table thread-safe
256 + */
257 +void olsr_event(void* foo)
258 +{
259 + int res = check_gw(&gw_net, &gw_netmask);
260 + if (1 == res && 0 == has_inet_gateway) {
261 + olsr_printf(DEBUGLEV, "Adding OLSR local HNA entry for Internet\n");
262 + add_local_hna4_entry(&gw_net, &gw_netmask);
263 + has_inet_gateway = 1;
264 + }
265 + else if (0 == res && 1 == has_inet_gateway) {
266 + /* Remove all local Inet HNA entries */
267 + while(remove_local_hna4_entry(&gw_net, &gw_netmask)) {
268 + olsr_printf(DEBUGLEV, "Removing OLSR local HNA entry for Internet\n");
269 + }
270 + has_inet_gateway = 0;
271 + }
272 +}
273 diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.h olsrd-0.4.10/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.h
274 --- olsrd-0.4.10.orig/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.h 1970-01-01 01:00:00.000000000 +0100
275 +++ olsrd-0.4.10/lib/dyn_gw_plain/src/olsrd_dyn_gw_plain.h 2006-12-01 08:26:58.000000000 +0100
276 @@ -0,0 +1,59 @@
277 +/*
278 + * The olsr.org Optimized Link-State Routing daemon(olsrd)
279 + * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
280 + * All rights reserved.
281 + *
282 + * Redistribution and use in source and binary forms, with or without
283 + * modification, are permitted provided that the following conditions
284 + * are met:
285 + *
286 + * * Redistributions of source code must retain the above copyright
287 + * notice, this list of conditions and the following disclaimer.
288 + * * Redistributions in binary form must reproduce the above copyright
289 + * notice, this list of conditions and the following disclaimer in
290 + * the documentation and/or other materials provided with the
291 + * distribution.
292 + * * Neither the name of olsr.org, olsrd nor the names of its
293 + * contributors may be used to endorse or promote products derived
294 + * from this software without specific prior written permission.
295 + *
296 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
297 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
298 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
299 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
300 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
301 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
302 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
303 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
304 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
305 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
306 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
307 + * POSSIBILITY OF SUCH DAMAGE.
308 + *
309 + * Visit http://www.olsr.org for more information.
310 + *
311 + * If you find this software useful feel free to make a donation
312 + * to the project. For more information see the website or contact
313 + * the copyright holders.
314 + */
315 +
316 +#ifndef _OLSRD_PLUGIN_TEST
317 +#define _OLSRD_PLUGIN_TEST
318 +
319 +#include "olsrd_plugin.h"
320 +#include "olsr.h"
321 +
322 +#define INET_NET 0
323 +#define INET_PREFIX 0
324 +
325 +#define PROCENTRY_ROUTE "/proc/net/route"
326 +
327 +union olsr_ip_addr gw_net;
328 +union olsr_ip_addr gw_netmask;
329 +
330 +int check_gw(union olsr_ip_addr *net, union olsr_ip_addr *mask);
331 +
332 +/* Event function to register with the scheduler */
333 +void olsr_event(void* foo);
334 +
335 +#endif
336 diff -Nur olsrd-0.4.10.orig/lib/dyn_gw_plain/version-script.txt olsrd-0.4.10/lib/dyn_gw_plain/version-script.txt
337 --- olsrd-0.4.10.orig/lib/dyn_gw_plain/version-script.txt 1970-01-01 01:00:00.000000000 +0100
338 +++ olsrd-0.4.10/lib/dyn_gw_plain/version-script.txt 2006-12-01 08:26:58.000000000 +0100
339 @@ -0,0 +1,10 @@
340 +VERS_1.0
341 +{
342 + global:
343 + olsrd_plugin_interface_version;
344 + olsrd_plugin_register_param;
345 + olsrd_plugin_init;
346 +
347 + local:
348 + *;
349 +};
350 diff -Nur olsrd-0.4.10.orig/Makefile olsrd-0.4.10/Makefile
351 --- olsrd-0.4.10.orig/Makefile 2006-01-04 09:45:38.000000000 +0100
352 +++ olsrd-0.4.10/Makefile 2006-12-01 08:26:58.000000000 +0100
353 @@ -144,6 +144,11 @@
354 $(MAKE) -C lib/dyn_gw
355 $(MAKE) -C lib/dyn_gw install
356
357 +dyn_gw_plain:
358 + $(MAKE) -C lib/dyn_gw_plain clean
359 + $(MAKE) -C lib/dyn_gw_plain
360 + $(MAKE) -C lib/dyn_gw_plain install
361 +
362 powerinfo:
363 $(MAKE) -C lib/powerinfo clean
364 $(MAKE) -C lib/powerinfo