remove the need for C99 math (closes: #1579)
[openwrt/svn-archive/archive.git] / net / olsrd / patches / 140-olsrd-txtinfo.patch
1 diff -Nur olsrd-0.4.10.orig/lib/txtinfo/Makefile olsrd-0.4.10/lib/txtinfo/Makefile
2 --- olsrd-0.4.10.orig/lib/txtinfo/Makefile 1970-01-01 01:00:00.000000000 +0100
3 +++ olsrd-0.4.10/lib/txtinfo/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-txtinfo.patch,v 1.5 2006/12/04 08:33:46 sven-ola Exp $
43 +
44 +OLSRD_PLUGIN = true
45 +PLUGIN_NAME = olsrd_txtinfo
46 +PLUGIN_VER = 0.1
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/txtinfo/README_TXTINFO olsrd-0.4.10/lib/txtinfo/README_TXTINFO
63 --- olsrd-0.4.10.orig/lib/txtinfo/README_TXTINFO 1970-01-01 01:00:00.000000000 +0100
64 +++ olsrd-0.4.10/lib/txtinfo/README_TXTINFO 2006-12-01 08:26:58.000000000 +0100
65 @@ -0,0 +1,16 @@
66 +LoadPlugin "olsrd_txtinfo.so.0.1"
67 +{
68 + PlParam "accept" "10.247.200.4"
69 +}
70 +
71 +ABOUT
72 +
73 +telnet 127.0.0.1 2006
74 +or
75 +wget localhost:2006 -qO -
76 +
77 +installation:
78 +make
79 +make install
80 +
81 +- Lorenz Schori
82 diff -Nur olsrd-0.4.10.orig/lib/txtinfo/src/olsrd_plugin.c olsrd-0.4.10/lib/txtinfo/src/olsrd_plugin.c
83 --- olsrd-0.4.10.orig/lib/txtinfo/src/olsrd_plugin.c 1970-01-01 01:00:00.000000000 +0100
84 +++ olsrd-0.4.10/lib/txtinfo/src/olsrd_plugin.c 2006-12-01 08:26:58.000000000 +0100
85 @@ -0,0 +1,142 @@
86 +/*
87 + * The olsr.org Optimized Link-State Routing daemon(olsrd)
88 + * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
89 + * All rights reserved.
90 + *
91 + * Redistribution and use in source and binary forms, with or without
92 + * modification, are permitted provided that the following conditions
93 + * are met:
94 + *
95 + * * Redistributions of source code must retain the above copyright
96 + * notice, this list of conditions and the following disclaimer.
97 + * * Redistributions in binary form must reproduce the above copyright
98 + * notice, this list of conditions and the following disclaimer in
99 + * the documentation and/or other materials provided with the
100 + * distribution.
101 + * * Neither the name of olsr.org, olsrd nor the names of its
102 + * contributors may be used to endorse or promote products derived
103 + * from this software without specific prior written permission.
104 + *
105 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
106 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
107 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
108 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
109 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
110 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
111 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
112 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
113 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
114 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
115 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
116 + * POSSIBILITY OF SUCH DAMAGE.
117 + *
118 + * Visit http://www.olsr.org for more information.
119 + *
120 + * If you find this software useful feel free to make a donation
121 + * to the project. For more information see the website or contact
122 + * the copyright holders.
123 + *
124 + * $Id: olsrd-txtinfo.patch,v 1.5 2006/12/04 08:33:46 sven-ola Exp $
125 + */
126 +
127 +/*
128 + * Dynamic linked library for the olsr.org olsr daemon
129 + */
130 +
131 +
132 +#include <stdio.h>
133 +#include <string.h>
134 +#include <stdlib.h>
135 +#include <arpa/inet.h>
136 +#include <sys/types.h>
137 +#include <netinet/in.h>
138 +
139 +#include "olsrd_plugin.h"
140 +#include "olsrd_txtinfo.h"
141 +
142 +
143 +#define PLUGIN_NAME "OLSRD txtinfo plugin"
144 +#define PLUGIN_VERSION "0.1"
145 +#define PLUGIN_AUTHOR "Lorenz Schori"
146 +#define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
147 +#define PLUGIN_INTERFACE_VERSION 4
148 +
149 +
150 +struct in_addr ipc_accept_ip;
151 +int ipc_port;
152 +int nompr;
153 +
154 +
155 +static void __attribute__ ((constructor))
156 +my_init(void);
157 +
158 +static void __attribute__ ((destructor))
159 +my_fini(void);
160 +
161 +
162 +/**
163 + *Constructor
164 + */
165 +static void
166 +my_init()
167 +{
168 + /* Print plugin info to stdout */
169 + printf("%s\n", MOD_DESC);
170 +
171 + /* defaults for parameters */
172 + ipc_port = 2006;
173 + ipc_accept_ip.s_addr = htonl(INADDR_LOOPBACK);
174 +
175 + /* highlite neighbours by default */
176 + nompr = 0;
177 +}
178 +
179 +
180 +/**
181 + *Destructor
182 + */
183 +static void
184 +my_fini()
185 +{
186 + /* Calls the destruction function
187 + * olsr_plugin_exit()
188 + * This function should be present in your
189 + * sourcefile and all data destruction
190 + * should happen there - NOT HERE!
191 + */
192 + olsr_plugin_exit();
193 +}
194 +
195 +
196 +int
197 +olsrd_plugin_interface_version()
198 +{
199 + return PLUGIN_INTERFACE_VERSION;
200 +}
201 +
202 +
203 +int
204 +olsrd_plugin_register_param(char *key, char *value)
205 +{
206 + if(!strcmp(key, "port"))
207 + {
208 + ipc_port = atoi(value);
209 + printf("(TXTINFO) listening on port: %d\n", ipc_port);
210 + }
211 +
212 + if(!strcmp(key, "accept"))
213 + {
214 + inet_aton(value, &ipc_accept_ip);
215 + printf("(TXTINFO) accept only: %s\n", inet_ntoa(ipc_accept_ip));
216 + }
217 +/*
218 + if(!strcmp(key, "hilitemprneighbours"))
219 + {
220 + if(!strcmp(value, "false") || !strcmp(value, "0"))
221 + {
222 + nompr=1;
223 + }
224 + }
225 + */
226 + return 1;
227 +}
228 diff -Nur olsrd-0.4.10.orig/lib/txtinfo/src/olsrd_txtinfo.c olsrd-0.4.10/lib/txtinfo/src/olsrd_txtinfo.c
229 --- olsrd-0.4.10.orig/lib/txtinfo/src/olsrd_txtinfo.c 1970-01-01 01:00:00.000000000 +0100
230 +++ olsrd-0.4.10/lib/txtinfo/src/olsrd_txtinfo.c 2006-12-01 08:26:58.000000000 +0100
231 @@ -0,0 +1,542 @@
232 +/*
233 + * The olsr.org Optimized Link-State Routing daemon(olsrd)
234 + * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
235 + * includes code by Bruno Randolf
236 + * includes code by Andreas Lopatic
237 + * includes code by Sven-Ola Tuecke
238 + * includes code by Lorenz Schori
239 + * All rights reserved.
240 + *
241 + * Redistribution and use in source and binary forms, with or without
242 + * modification, are permitted provided that the following conditions
243 + * are met:
244 + *
245 + * * Redistributions of source code must retain the above copyright
246 + * notice, this list of conditions and the following disclaimer.
247 + * * Redistributions in binary form must reproduce the above copyright
248 + * notice, this list of conditions and the following disclaimer in
249 + * the documentation and/or other materials provided with the
250 + * distribution.
251 + * * Neither the name of olsr.org, olsrd nor the names of its
252 + * contributors may be used to endorse or promote products derived
253 + * from this software without specific prior written permission.
254 + *
255 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
256 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
257 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
258 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
259 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
260 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
261 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
262 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
263 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
264 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
265 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
266 + * POSSIBILITY OF SUCH DAMAGE.
267 + *
268 + * Visit http://www.olsr.org for more information.
269 + *
270 + * If you find this software useful feel free to make a donation
271 + * to the project. For more information see the website or contact
272 + * the copyright holders.
273 + *
274 + * $Id: olsrd-txtinfo.patch,v 1.5 2006/12/04 08:33:46 sven-ola Exp $
275 + */
276 +
277 +/*
278 + * Dynamic linked library for the olsr.org olsr daemon
279 + */
280 +
281 +
282 +#include <sys/types.h>
283 +#include <sys/socket.h>
284 +#include <sys/select.h>
285 +#include <netinet/in.h>
286 +#include <arpa/inet.h>
287 +#include <sys/time.h>
288 +#include <time.h>
289 +#include <math.h>
290 +#include <stdio.h>
291 +#include <string.h>
292 +#include <stdlib.h>
293 +#include <stdarg.h>
294 +#include <unistd.h>
295 +#include <errno.h>
296 +
297 +#include "olsr.h"
298 +#include "olsr_types.h"
299 +#include "neighbor_table.h"
300 +#include "two_hop_neighbor_table.h"
301 +#include "mpr_selector_set.h"
302 +#include "tc_set.h"
303 +#include "hna_set.h"
304 +#include "mid_set.h"
305 +#include "link_set.h"
306 +#include "socket_parser.h"
307 +
308 +#include "olsrd_txtinfo.h"
309 +#include "olsrd_plugin.h"
310 +
311 +
312 +#ifdef WIN32
313 +#define close(x) closesocket(x)
314 +#endif
315 +
316 +
317 +static int ipc_socket;
318 +static int ipc_open;
319 +static int ipc_connection;
320 +static int ipc_socket_up;
321 +
322 +
323 +/* IPC initialization function */
324 +static int
325 +plugin_ipc_init(void);
326 +
327 +static void
328 +send_info(int neighonly);
329 +
330 +static void
331 +ipc_action(int);
332 +
333 +static void inline
334 +ipc_print_neigh_link(void);
335 +
336 +static void inline
337 +ipc_print_routes(void);
338 +
339 +static void inline
340 +ipc_print_topology(void);
341 +
342 +static void inline
343 +ipc_print_hna(void);
344 +
345 +#define TXT_IPC_BUFSIZE 256
346 +static int
347 +ipc_sendf(const char* format, ...);
348 +
349 +/**
350 + *Do initialization here
351 + *
352 + *This function is called by the my_init
353 + *function in uolsrd_plugin.c
354 + */
355 +int
356 +olsrd_plugin_init()
357 +{
358 + /* Initial IPC value */
359 + ipc_open = 0;
360 + ipc_socket_up = 0;
361 +
362 + plugin_ipc_init();
363 + return 1;
364 +}
365 +
366 +
367 +/**
368 + * destructor - called at unload
369 + */
370 +void
371 +olsr_plugin_exit()
372 +{
373 + if(ipc_open)
374 + close(ipc_socket);
375 +}
376 +
377 +
378 +
379 +static int
380 +plugin_ipc_init()
381 +{
382 + struct sockaddr_in sin;
383 + olsr_u32_t yes = 1;
384 +
385 + /* Init ipc socket */
386 + if ((ipc_socket = socket(AF_INET, SOCK_STREAM, 0)) == -1)
387 + {
388 +#ifndef NODEBUG
389 + olsr_printf(1, "(TXTINFO) socket()=%s\n", strerror(errno));
390 +#endif
391 + return 0;
392 + }
393 + else
394 + {
395 + if (setsockopt(ipc_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0)
396 + {
397 +#ifndef NODEBUG
398 + olsr_printf(1, "(TXTINFO) setsockopt()=%s\n", strerror(errno));
399 +#endif
400 + return 0;
401 + }
402 +
403 +#if defined __FreeBSD__ && defined SO_NOSIGPIPE
404 + if (setsockopt(ipc_socket, SOL_SOCKET, SO_NOSIGPIPE, (char *)&yes, sizeof(yes)) < 0)
405 + {
406 + perror("SO_REUSEADDR failed");
407 + return 0;
408 + }
409 +#endif
410 +
411 + /* Bind the socket */
412 +
413 + /* complete the socket structure */
414 + memset(&sin, 0, sizeof(sin));
415 + sin.sin_family = AF_INET;
416 + sin.sin_addr.s_addr = INADDR_ANY;
417 + sin.sin_port = htons(ipc_port);
418 +
419 + /* bind the socket to the port number */
420 + if (bind(ipc_socket, (struct sockaddr *) &sin, sizeof(sin)) == -1)
421 + {
422 +#ifndef NODEBUG
423 + olsr_printf(1, "(TXTINFO) bind()=%s\n", strerror(errno));
424 +#endif
425 + return 0;
426 + }
427 +
428 + /* show that we are willing to listen */
429 + if (listen(ipc_socket, 1) == -1)
430 + {
431 +#ifndef NODEBUG
432 + olsr_printf(1, "(TXTINFO) listen()=%s\n", strerror(errno));
433 +#endif
434 + return 0;
435 + }
436 +
437 + /* Register with olsrd */
438 + add_olsr_socket(ipc_socket, &ipc_action);
439 +
440 +#ifndef NODEBUG
441 + olsr_printf(2, "(TXTINFO) listening on port %d\n",ipc_port);
442 +#endif
443 + ipc_socket_up = 1;
444 + }
445 +
446 + return 1;
447 +}
448 +
449 +
450 +static void
451 +ipc_action(int fd)
452 +{
453 + struct sockaddr_in pin;
454 + socklen_t addrlen;
455 + char *addr;
456 +
457 + addrlen = sizeof(struct sockaddr_in);
458 +
459 + if(ipc_open)
460 + return;
461 +
462 + if ((ipc_connection = accept(fd, (struct sockaddr *) &pin, &addrlen)) == -1)
463 + {
464 +#ifndef NODEBUG
465 + olsr_printf(1, "(TXTINFO) accept()=%s\n", strerror(errno));
466 +#endif
467 + exit(1);
468 + }
469 + else
470 + {
471 + addr = inet_ntoa(pin.sin_addr);
472 + if(ntohl(pin.sin_addr.s_addr) != ntohl(ipc_accept_ip.s_addr))
473 + {
474 + olsr_printf(1, "(TXTINFO) From host(%s) not allowed!\n", addr);
475 + close(ipc_connection);
476 + return;
477 + }
478 + else
479 + {
480 + ipc_open = 1;
481 +#ifndef NODEBUG
482 + olsr_printf(2, "(TXTINFO) Connect from %s\n",addr);
483 +#endif
484 +
485 + /* purge read buffer to prevent blocking on linux*/
486 + fd_set rfds;
487 + FD_ZERO(&rfds);
488 + FD_SET(ipc_connection, &rfds);
489 + struct timeval tv = {0,0};
490 + int neighonly = 0;
491 + if(select(ipc_connection+1, &rfds, NULL, NULL, &tv)) {
492 + char requ[128];
493 + ssize_t s = recv(ipc_connection, &requ, sizeof(requ), 0);
494 + if (0 < s) {
495 + requ[s] = 0;
496 + /* To print out neighbours only on the Freifunk Status
497 + * page the normal output is somewhat lengthy. The
498 + * header parsing is sufficient for standard wget.
499 + */
500 + neighonly = (0 != strstr(requ, "/neighbours"));
501 + }
502 + }
503 +
504 + send_info(neighonly);
505 +
506 + close(ipc_connection);
507 + ipc_open = 0;
508 + }
509 + }
510 +}
511 +
512 +static void inline
513 +ipc_print_neigh_link(void)
514 +{
515 + struct neighbor_entry *neigh;
516 + struct neighbor_2_list_entry *list_2;
517 + struct link_entry *link = NULL;
518 + int index, thop_cnt;
519 +
520 + ipc_sendf("Table: Links\nLocal IP\tremote IP\tHysteresis\tLinkQuality\tlost\ttotal\tNLQ\tETX\n");
521 +
522 + /* Link set */
523 + link = link_set;
524 + while(link)
525 + {
526 + ipc_sendf( "%s\t%s\t%0.2f\t%0.2f\t%d\t%d\t%0.2f\t%0.2f\t\n",
527 + olsr_ip_to_string(&link->local_iface_addr),
528 + olsr_ip_to_string(&link->neighbor_iface_addr),
529 + link->L_link_quality,
530 + link->loss_link_quality,
531 + link->lost_packets,
532 + link->total_packets,
533 + link->neigh_link_quality,
534 + (link->loss_link_quality * link->neigh_link_quality) ? 1.0 / (link->loss_link_quality * link->neigh_link_quality) : 0.0);
535 + link = link->next;
536 + }
537 + ipc_sendf("\nTable: Neighbors\nIP address\tSYM\tMPR\tMPRS\tWillingness\t2 Hop Neighbors\n");
538 +
539 + /* Neighbors */
540 + for(index=0;index<HASHSIZE;index++)
541 + {
542 + for(neigh = neighbortable[index].next;
543 + neigh != &neighbortable[index];
544 + neigh = neigh->next)
545 + {
546 + ipc_sendf(
547 + "%s\t%s\t%s\t%s\t%d\t",
548 + olsr_ip_to_string(&neigh->neighbor_main_addr),
549 + (neigh->status == SYM) ? "YES" : "NO",
550 + neigh->is_mpr ? "YES" : "NO",
551 + olsr_lookup_mprs_set(&neigh->neighbor_main_addr) ? "YES" : "NO",
552 + neigh->willingness);
553 +
554 + thop_cnt = 0;
555 +
556 + for(list_2 = neigh->neighbor_2_list.next;
557 + list_2 != &neigh->neighbor_2_list;
558 + list_2 = list_2->next)
559 + {
560 + //size += sprintf(&buf[size], "<option>%s</option>\n", olsr_ip_to_string(&list_2->neighbor_2->neighbor_2_addr));
561 + thop_cnt ++;
562 + }
563 + ipc_sendf("%d\n", thop_cnt);
564 + }
565 + }
566 +
567 + ipc_sendf("\n");
568 +}
569 +
570 +
571 +static void inline
572 +ipc_print_routes(void)
573 +{
574 + int size = 0, index;
575 + struct rt_entry *routes;
576 +
577 + ipc_sendf("Table: Routes\nDestination\tGateway\tMetric\tETX\tInterface\tType\n");
578 +
579 + /* Neighbors */
580 + for(index = 0;index < HASHSIZE;index++)
581 + {
582 + for(routes = routingtable[index].next;
583 + routes != &routingtable[index];
584 + routes = routes->next)
585 + {
586 + size = 0;
587 + ipc_sendf( "%s\t%s\t%d\t%.2f\t%s\tHOST\n",
588 + olsr_ip_to_string(&routes->rt_dst),
589 + olsr_ip_to_string(&routes->rt_router),
590 + routes->rt_metric,
591 + routes->rt_etx,
592 + routes->rt_if->int_name);
593 + }
594 + }
595 +
596 + /* HNA */
597 + for(index = 0;index < HASHSIZE;index++)
598 + {
599 + for(routes = hna_routes[index].next;
600 + routes != &hna_routes[index];
601 + routes = routes->next)
602 + {
603 + ipc_sendf("%s\t%s\t%d\t%s\t\tHNA\n",
604 + olsr_ip_to_string(&routes->rt_dst),
605 + olsr_ip_to_string(&routes->rt_router),
606 + routes->rt_metric,
607 + routes->rt_if->int_name);
608 + }
609 + }
610 +
611 + ipc_sendf("\n");
612 +
613 +}
614 +
615 +static void inline
616 +ipc_print_topology(void)
617 +{
618 + olsr_u8_t index;
619 + struct tc_entry *entry;
620 + struct topo_dst *dst_entry;
621 +
622 +
623 + ipc_sendf("Table: Topology\nDestination IP\tLast hop IP\tLQ\tILQ\tETX\n");
624 +
625 + /* Topology */
626 + for(index=0;index<HASHSIZE;index++)
627 + {
628 + /* For all TC entries */
629 + entry = tc_table[index].next;
630 + while(entry != &tc_table[index])
631 + {
632 + /* For all destination entries of that TC entry */
633 + dst_entry = entry->destinations.next;
634 + while(dst_entry != &entry->destinations)
635 + {
636 + ipc_sendf( "%s\t%s\t%0.2f\t%0.2f\t%0.2f\n",
637 + olsr_ip_to_string(&dst_entry->T_dest_addr),
638 + olsr_ip_to_string(&entry->T_last_addr),
639 + dst_entry->link_quality,
640 + dst_entry->inverse_link_quality,
641 + (dst_entry->link_quality * dst_entry->inverse_link_quality) ? 1.0 / (dst_entry->link_quality * dst_entry->inverse_link_quality) : 0.0);
642 +
643 + dst_entry = dst_entry->next;
644 + }
645 + entry = entry->next;
646 + }
647 + }
648 +
649 + ipc_sendf("\n");
650 +}
651 +
652 +static void inline
653 +ipc_print_hna(void)
654 +{
655 + int size;
656 + olsr_u8_t index;
657 + struct hna_entry *tmp_hna;
658 + struct hna_net *tmp_net;
659 +
660 + size = 0;
661 +
662 + ipc_sendf("Table: HNA\nNetwork\tNetmask\tGateway\n");
663 +
664 + /* Announced HNA entries */
665 + struct hna4_entry *hna4;
666 + for(hna4 = olsr_cnf->hna4_entries; hna4; hna4 = hna4->next)
667 + {
668 + ipc_sendf("%s\t%s\t%s\n",
669 + olsr_ip_to_string((union olsr_ip_addr *)&hna4->net),
670 + olsr_ip_to_string((union olsr_ip_addr *)&hna4->netmask),
671 + olsr_ip_to_string((union olsr_ip_addr *)&main_addr));
672 + }
673 + struct hna6_entry *hna6;
674 + for(hna6 = olsr_cnf->hna6_entries; hna6; hna6 = hna6->next)
675 + {
676 + ipc_sendf("%s\t%d\t%s\n",
677 + olsr_ip_to_string((union olsr_ip_addr *)&hna6->net),
678 + hna6->prefix_len,
679 + olsr_ip_to_string((union olsr_ip_addr *)&main_addr));
680 + }
681 +
682 + /* HNA entries */
683 + for(index=0;index<HASHSIZE;index++)
684 + {
685 + tmp_hna = hna_set[index].next;
686 + /* Check all entrys */
687 + while(tmp_hna != &hna_set[index])
688 + {
689 + /* Check all networks */
690 + tmp_net = tmp_hna->networks.next;
691 +
692 + while(tmp_net != &tmp_hna->networks)
693 + {
694 + if (AF_INET == olsr_cnf->ip_version) {
695 + ipc_sendf("%s\t%s\t%s\n",
696 + olsr_ip_to_string(&tmp_net->A_network_addr),
697 + olsr_ip_to_string((union olsr_ip_addr *)&tmp_net->A_netmask.v4),
698 + olsr_ip_to_string(&tmp_hna->A_gateway_addr));
699 + }
700 + else {
701 + ipc_sendf("%s\t%d\t%s\n",
702 + olsr_ip_to_string(&tmp_net->A_network_addr),
703 + tmp_net->A_netmask.v6,
704 + olsr_ip_to_string(&tmp_hna->A_gateway_addr));
705 + }
706 + tmp_net = tmp_net->next;
707 + }
708 +
709 + tmp_hna = tmp_hna->next;
710 + }
711 + }
712 +
713 + ipc_sendf("\n");
714 +
715 +}
716 +
717 +
718 +static void
719 +send_info(int neighonly)
720 +{
721 +
722 + /* Print minimal http header */
723 + ipc_sendf("HTTP/1.0 200 OK\n");
724 + ipc_sendf("Content-type: text/plain\n\n");
725 +
726 + /* Print tables to IPC socket */
727 +
728 + /* links + Neighbors */
729 + ipc_print_neigh_link();
730 +
731 + /* topology */
732 + if (!neighonly) ipc_print_topology();
733 +
734 + /* hna */
735 + if (!neighonly) ipc_print_hna();
736 +
737 + /* routes */
738 + if (!neighonly) ipc_print_routes();
739 +}
740 +
741 +/*
742 + * In a bigger mesh, there are probs with the fixed
743 + * bufsize. Because the Content-Length header is
744 + * optional, the sprintf() is changed to a more
745 + * scalable solution here.
746 + */
747 +
748 +static int
749 +ipc_sendf(const char* format, ...)
750 +{
751 + char txtnetbuf[TXT_IPC_BUFSIZE];
752 +
753 + va_list arg;
754 + int rv;
755 +#if defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __MacOSX__
756 + int flags = 0;
757 +#else
758 + int flags = MSG_NOSIGNAL;
759 +#endif
760 + va_start(arg, format);
761 + rv = vsnprintf(txtnetbuf, sizeof(txtnetbuf), format, arg);
762 + va_end(arg);
763 + if(ipc_socket_up) {
764 + if (0 > send(ipc_connection, txtnetbuf, rv, flags)) {
765 +#ifndef NODEBUG
766 + olsr_printf(1, "(TXTINFO) Failed sending data to client!\n");
767 +#endif
768 + close(ipc_connection);
769 + return - 1;
770 + }
771 + }
772 + return rv;
773 +}
774 diff -Nur olsrd-0.4.10.orig/lib/txtinfo/src/olsrd_txtinfo.h olsrd-0.4.10/lib/txtinfo/src/olsrd_txtinfo.h
775 --- olsrd-0.4.10.orig/lib/txtinfo/src/olsrd_txtinfo.h 1970-01-01 01:00:00.000000000 +0100
776 +++ olsrd-0.4.10/lib/txtinfo/src/olsrd_txtinfo.h 2006-12-01 08:26:58.000000000 +0100
777 @@ -0,0 +1,62 @@
778 +/*
779 + * The olsr.org Optimized Link-State Routing daemon(olsrd)
780 + * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
781 + * includes code by Bruno Randolf
782 + * All rights reserved.
783 + *
784 + * Redistribution and use in source and binary forms, with or without
785 + * modification, are permitted provided that the following conditions
786 + * are met:
787 + *
788 + * * Redistributions of source code must retain the above copyright
789 + * notice, this list of conditions and the following disclaimer.
790 + * * Redistributions in binary form must reproduce the above copyright
791 + * notice, this list of conditions and the following disclaimer in
792 + * the documentation and/or other materials provided with the
793 + * distribution.
794 + * * Neither the name of olsr.org, olsrd nor the names of its
795 + * contributors may be used to endorse or promote products derived
796 + * from this software without specific prior written permission.
797 + *
798 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
799 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
800 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
801 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
802 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
803 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
804 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
805 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
806 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
807 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
808 + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
809 + * POSSIBILITY OF SUCH DAMAGE.
810 + *
811 + * Visit http://www.olsr.org for more information.
812 + *
813 + * If you find this software useful feel free to make a donation
814 + * to the project. For more information see the website or contact
815 + * the copyright holders.
816 + *
817 + * $Id: olsrd-txtinfo.patch,v 1.5 2006/12/04 08:33:46 sven-ola Exp $
818 + */
819 +
820 +/*
821 + * Dynamic linked library for the olsr.org olsr daemon
822 + */
823 +
824 +#ifndef _OLSRD_DOT_DRAW
825 +#define _OLSRD_DOT_DRAW
826 +
827 +
828 +extern struct in_addr ipc_accept_ip;
829 +extern int ipc_port;
830 +extern int nompr;
831 +
832 +
833 +int
834 +olsrd_plugin_init(void);
835 +
836 +void
837 +olsr_plugin_exit(void);
838 +
839 +#endif
840 diff -Nur olsrd-0.4.10.orig/lib/txtinfo/version-script.txt olsrd-0.4.10/lib/txtinfo/version-script.txt
841 --- olsrd-0.4.10.orig/lib/txtinfo/version-script.txt 1970-01-01 01:00:00.000000000 +0100
842 +++ olsrd-0.4.10/lib/txtinfo/version-script.txt 2006-12-01 08:26:58.000000000 +0100
843 @@ -0,0 +1,10 @@
844 +VERS_1.0
845 +{
846 + global:
847 + olsrd_plugin_interface_version;
848 + olsrd_plugin_register_param;
849 + olsrd_plugin_init;
850 +
851 + local:
852 + *;
853 +};