3 * The olsr.org Optimized Link-State Routing daemon(olsrd)
4 * Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org)
5 * includes code by Bruno Randolf
6 * includes code by Andreas Lopatic
7 * includes code by Sven-Ola Tuecke
8 * includes code by Lorenz Schori
9 * includes bugs by Markus Kittenberger
10 * includes bugs by Hans-Christoph Steiner
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
17 * * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
23 * * Neither the name of olsr.org, olsrd nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
40 * Visit http://www.olsr.org for more information.
42 * If you find this software useful feel free to make a donation
43 * to the project. For more information see the website or contact
44 * the copyright holders.
49 * Dynamic linked library for the olsr.org olsr daemon
53 #include <sys/types.h>
54 #include <sys/socket.h>
56 #include <sys/select.h>
58 #include <netinet/in.h>
59 #include <arpa/inet.h>
71 #include "olsr_types.h"
72 #include "neighbor_table.h"
73 #include "two_hop_neighbor_table.h"
74 #include "mpr_selector_set.h"
80 #include "lq_plugin.h"
81 #include "common/autobuf.h"
84 #include "olsrd_jsoninfo.h"
85 #include "olsrd_plugin.h"
88 #define close(x) closesocket(x)
91 static int ipc_socket;
93 /* IPC initialization function */
94 static int plugin_ipc_init(void);
96 static void abuf_json_open_array(struct autobuf *abuf, const char* header);
97 static void abuf_json_close_array(struct autobuf *abuf);
98 static void abuf_json_open_array_entry(struct autobuf *abuf);
99 static void abuf_json_close_array_entry(struct autobuf *abuf);
100 static void abuf_json_boolean(struct autobuf *abuf, const char* key, int value);
101 static void abuf_json_key_string(struct autobuf *abuf, const char* key, const char* value);
102 static void abuf_json_key_int(struct autobuf *abuf, const char* key, int value);
103 static void abuf_json_key_float(struct autobuf *abuf, const char* key, float value);
105 static void send_info(unsigned int /*send_what*/, int /*socket*/);
106 static void ipc_action(int, void *, unsigned int);
107 static void ipc_print_neighbors(struct autobuf *, bool);
108 static void ipc_print_links(struct autobuf *);
109 static void ipc_print_routes(struct autobuf *);
110 static void ipc_print_topology(struct autobuf *);
111 static void ipc_print_hna(struct autobuf *);
112 static void ipc_print_mid(struct autobuf *);
113 static void ipc_print_gateways(struct autobuf *);
114 static void ipc_print_config(struct autobuf *);
115 static void ipc_print_interfaces(struct autobuf *);
117 #define TXT_IPC_BUFSIZE 256
119 #define SIW_NEIGHBORS 0x0001
120 #define SIW_LINKS 0x0002
121 #define SIW_ROUTES 0x0004
122 #define SIW_HNA 0x0008
123 #define SIW_MID 0x0010
124 #define SIW_TOPOLOGY 0x0020
125 #define SIW_GATEWAYS 0x0040
126 #define SIW_INTERFACES 0x0080
127 #define SIW_CONFIG 0x0100
128 #define SIW_TWOHOP 0x0200
130 /* ALL = neigh link route hna mid topo */
131 #define SIW_ALL 0x003F
133 #define MAX_CLIENTS 3
135 static char *outbuffer[MAX_CLIENTS];
136 static size_t outbuffer_size[MAX_CLIENTS];
137 static size_t outbuffer_written[MAX_CLIENTS];
138 static int outbuffer_socket[MAX_CLIENTS];
139 static int outbuffer_count;
141 static struct timer_entry *writetimer_entry;
144 /* JSON support functions */
147 /* JSON does not tolerate commas dangling at the end of arrays, so we need to
148 * count which entry number we're at in order to make sure we don't tack a
149 * dangling comma on at the end */
150 static int entrynumber = 0;
151 static int arrayentrynumber = 0;
154 abuf_json_open_array(struct autobuf *abuf, const char* header)
156 arrayentrynumber = 0;
157 abuf_appendf(abuf, "{\"%s\": [\n", header);
161 abuf_json_close_array(struct autobuf *abuf)
163 abuf_appendf(abuf, "]}\n");
167 abuf_json_open_array_entry(struct autobuf *abuf)
170 if (arrayentrynumber)
171 abuf_appendf(abuf, ",\n{");
173 abuf_appendf(abuf, "{");
178 abuf_json_close_array_entry(struct autobuf *abuf)
180 abuf_appendf(abuf, "}");
184 abuf_json_boolean(struct autobuf *abuf, const char* key, int value)
187 abuf_appendf(abuf, ",\n");
189 abuf_appendf(abuf, "\n");
190 abuf_appendf(abuf, "\t\"%s\": %s", key, value ? "true" : "false");
195 abuf_json_key_string(struct autobuf *abuf, const char* key, const char* value)
198 abuf_appendf(abuf, ",\n");
200 abuf_appendf(abuf, "\n");
201 abuf_appendf(abuf, "\t\"%s\": \"%s\"", key, value);
206 abuf_json_key_int(struct autobuf *abuf, const char* key, int value)
209 abuf_appendf(abuf, ",\n");
211 abuf_appendf(abuf, "\n");
212 abuf_appendf(abuf, "\t\"%s\": %i", key, value);
217 abuf_json_key_float(struct autobuf *abuf, const char* key, float value)
220 abuf_appendf(abuf, ",\n");
221 abuf_appendf(abuf, "\t\"%s\": %g,\n", key, value);
227 *Do initialization here
229 *This function is called by the my_init
230 *function in uolsrd_plugin.c
233 olsrd_plugin_init(void)
235 /* Initial IPC value */
243 * destructor - called at unload
246 olsr_plugin_exit(void)
248 if (ipc_socket != -1)
253 plugin_ipc_init(void)
255 union olsr_sockaddr sst;
259 /* Init ipc socket */
260 if ((ipc_socket = socket(olsr_cnf->ip_version, SOCK_STREAM, 0)) == -1) {
262 olsr_printf(1, "(JSONINFO) socket()=%s\n", strerror(errno));
266 if (setsockopt(ipc_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0) {
268 olsr_printf(1, "(JSONINFO) setsockopt()=%s\n", strerror(errno));
272 #if (defined __FreeBSD__ || defined __FreeBSD_kernel__) && defined SO_NOSIGPIPE
273 if (setsockopt(ipc_socket, SOL_SOCKET, SO_NOSIGPIPE, (char *)&yes, sizeof(yes)) < 0) {
274 perror("SO_REUSEADDR failed");
278 /* Bind the socket */
280 /* complete the socket structure */
281 memset(&sst, 0, sizeof(sst));
282 if (olsr_cnf->ip_version == AF_INET) {
283 sst.in4.sin_family = AF_INET;
284 addrlen = sizeof(struct sockaddr_in);
286 sst.in4.sin_len = addrlen;
288 sst.in4.sin_addr.s_addr = jsoninfo_listen_ip.v4.s_addr;
289 sst.in4.sin_port = htons(ipc_port);
291 sst.in6.sin6_family = AF_INET6;
292 addrlen = sizeof(struct sockaddr_in6);
294 sst.in6.sin6_len = addrlen;
296 sst.in6.sin6_addr = jsoninfo_listen_ip.v6;
297 sst.in6.sin6_port = htons(ipc_port);
300 /* bind the socket to the port number */
301 if (bind(ipc_socket, &sst.in, addrlen) == -1) {
303 olsr_printf(1, "(JSONINFO) bind()=%s\n", strerror(errno));
308 /* show that we are willing to listen */
309 if (listen(ipc_socket, 1) == -1) {
311 olsr_printf(1, "(JSONINFO) listen()=%s\n", strerror(errno));
316 /* Register with olsrd */
317 add_olsr_socket(ipc_socket, &ipc_action, NULL, NULL, SP_PR_READ);
320 olsr_printf(2, "(JSONINFO) listening on port %d\n", ipc_port);
327 ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __attribute__ ((unused)))
329 union olsr_sockaddr pin;
331 char addr[INET6_ADDRSTRLEN];
334 unsigned int send_what = 0;
337 socklen_t addrlen = sizeof(pin);
339 if ((ipc_connection = accept(fd, &pin.in, &addrlen)) == -1) {
341 olsr_printf(1, "(JSONINFO) accept()=%s\n", strerror(errno));
346 tv.tv_sec = tv.tv_usec = 0;
347 if (olsr_cnf->ip_version == AF_INET) {
348 if (inet_ntop(olsr_cnf->ip_version, &pin.in4.sin_addr, addr, INET6_ADDRSTRLEN) == NULL)
350 if (!ip4equal(&pin.in4.sin_addr, &jsoninfo_accept_ip.v4) && jsoninfo_accept_ip.v4.s_addr != INADDR_ANY) {
351 #ifdef JSONINFO_ALLOW_LOCALHOST
352 if (pin.in4.sin_addr.s_addr != INADDR_LOOPBACK) {
354 olsr_printf(1, "(JSONINFO) From host(%s) not allowed!\n", addr);
355 close(ipc_connection);
357 #ifdef JSONINFO_ALLOW_LOCALHOST
362 if (inet_ntop(olsr_cnf->ip_version, &pin.in6.sin6_addr, addr, INET6_ADDRSTRLEN) == NULL)
364 /* Use in6addr_any (::) in olsr.conf to allow anybody. */
365 if (!ip6equal(&in6addr_any, &jsoninfo_accept_ip.v6) && !ip6equal(&pin.in6.sin6_addr, &jsoninfo_accept_ip.v6)) {
366 olsr_printf(1, "(JSONINFO) From host(%s) not allowed!\n", addr);
367 close(ipc_connection);
373 olsr_printf(2, "(JSONINFO) Connect from %s\n", addr);
376 /* purge read buffer to prevent blocking on linux */
378 FD_SET((unsigned int)ipc_connection, &rfds); /* Win32 needs the cast here */
379 if (0 <= select(ipc_connection + 1, &rfds, NULL, NULL, &tv)) {
381 ssize_t s = recv(ipc_connection, (void *)&requ, sizeof(requ), 0); /* Win32 needs the cast here */
384 /* print out every combinations of requested tabled
385 * 3++ letter abbreviations are matched */
386 if (0 != strstr(requ, "/all")) send_what = SIW_ALL;
387 else { /*already included in /all*/
388 if (0 != strstr(requ, "/neighbors")) send_what |= SIW_NEIGHBORS;
389 if (0 != strstr(requ, "/links")) send_what |= SIW_LINKS;
390 if (0 != strstr(requ, "/routes")) send_what |= SIW_ROUTES;
391 if (0 != strstr(requ, "/hna")) send_what |= SIW_HNA;
392 if (0 != strstr(requ, "/mid")) send_what |= SIW_MID;
393 if (0 != strstr(requ, "/topology")) send_what |= SIW_TOPOLOGY;
395 if (0 != strstr(requ, "/gateways")) send_what |= SIW_GATEWAYS;
396 if (0 != strstr(requ, "/config")) send_what |= SIW_CONFIG;
397 if (0 != strstr(requ, "/interfaces")) send_what |= SIW_INTERFACES;
398 if (0 != strstr(requ, "/twohop")) send_what |= SIW_TWOHOP;
400 if ( send_what == 0 ) send_what = SIW_ALL;
403 send_info(send_what, ipc_connection);
407 ipc_print_neighbors(struct autobuf *abuf, bool list_2hop)
409 struct ipaddr_str buf1;
410 struct neighbor_entry *neigh;
411 struct neighbor_2_list_entry *list_2;
414 //abuf_puts(abuf, "Table: Neighbors\nIP address\tSYM\tMPR\tMPRS\tWill.");
417 abuf_puts(abuf,"\n\t2hop interface adrress\n");
419 abuf_puts(abuf, "\t2 Hop Neighbors\n");
422 abuf_json_open_array(abuf, "twohop");
424 abuf_json_open_array(abuf, "neighbors");
427 OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
429 "%s\t%s\t%s\t%s\t%d\t",
430 olsr_ip_to_string(&buf1, &neigh->neighbor_main_addr),
431 (neigh->status == SYM) ? "YES" : "NO",
432 neigh->is_mpr ? "YES" : "NO",
433 olsr_lookup_mprs_set(&neigh->neighbor_main_addr) ? "YES" : "NO",
437 for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
441 olsr_ip_to_string(&buf1, &list_2->neighbor_2->neighbor_2_addr));
446 abuf_appendf(abuf, "%d\n", thop_cnt);
449 OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
450 abuf_json_close_array(abuf);
454 ipc_print_links(struct autobuf *abuf)
456 struct ipaddr_str buf1, buf2;
457 struct lqtextbuffer lqbuffer1, lqbuffer2;
459 struct link_entry *my_link = NULL;
461 abuf_json_open_array(abuf, "links");
462 //abuf_puts(abuf, "Table: Links\nLocal IP\tRemote IP\tVTime\tLQ\tNLQ\tCost\n");
465 OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
466 int diff = (unsigned int)(my_link->link_timer->timer_clock - now_times);
469 "%s\t%s\t%d.%03d\t%s\t%s\t\n",
470 olsr_ip_to_string(&buf1, &my_link->local_iface_addr),
471 olsr_ip_to_string(&buf2, &my_link->neighbor_iface_addr),
472 diff/1000, abs(diff%1000),
473 get_link_entry_text(my_link, '\t', &lqbuffer1),
474 get_linkcost_text(my_link->linkcost, false, &lqbuffer2));
476 OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
478 abuf_json_close_array(abuf);
482 ipc_print_routes(struct autobuf *abuf)
484 struct ipaddr_str buf1, buf2;
486 struct lqtextbuffer lqbuffer;
488 //abuf_puts(abuf, "Table: Routes\nDestination\tGateway IP\tMetric\tETX\tInterface\n");
489 abuf_json_open_array(abuf, "routes");
491 /* Walk the route table */
492 OLSR_FOR_ALL_RT_ENTRIES(rt) {
494 "%s/%d\t%s\t%d\t%s\t%s\t\n",
495 olsr_ip_to_string(&buf1, &rt->rt_dst.prefix),
496 rt->rt_dst.prefix_len,
497 olsr_ip_to_string(&buf2, &rt->rt_best->rtp_nexthop.gateway),
498 rt->rt_best->rtp_metric.hops,
499 get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &lqbuffer),
500 if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
502 OLSR_FOR_ALL_RT_ENTRIES_END(rt);
504 abuf_json_close_array(abuf);
509 ipc_print_topology(struct autobuf *abuf)
513 abuf_json_open_array(abuf, "topology");
514 //abuf_puts(abuf, "Table: Topology\nDest. IP\tLast hop IP\tLQ\tNLQ\tCost\tVTime\n");
517 OLSR_FOR_ALL_TC_ENTRIES(tc) {
518 struct tc_edge_entry *tc_edge;
519 OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
520 if (tc_edge->edge_inv) {
521 struct ipaddr_str dstbuf, addrbuf;
522 struct lqtextbuffer lqbuffer1, lqbuffer2;
523 uint32_t vt = tc->validity_timer != NULL ? (tc->validity_timer->timer_clock - now_times) : 0;
524 int diff = (int)(vt);
525 abuf_appendf(abuf, "%s\t%s\t%s\t%s\t%d.%03d\n", olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr),
526 olsr_ip_to_string(&addrbuf, &tc->addr),
527 get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer1),
528 get_linkcost_text(tc_edge->cost, false, &lqbuffer2),
529 diff/1000, diff%1000);
532 OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
534 OLSR_FOR_ALL_TC_ENTRIES_END(tc);
536 abuf_json_close_array(abuf);
540 ipc_print_hna(struct autobuf *abuf)
542 struct ip_prefix_list *hna;
543 struct hna_entry *tmp_hna;
544 struct hna_net *tmp_net;
545 struct ipaddr_str buf, mainaddrbuf;
547 abuf_json_open_array(abuf, "hna");
548 //abuf_puts(abuf, "Table: HNA\nDestination\tGateway\tVTime\n");
550 /* Announced HNA entries */
551 if (olsr_cnf->ip_version == AF_INET) {
552 for (hna = olsr_cnf->hna_entries; hna != NULL; hna = hna->next) {
555 olsr_ip_to_string(&buf, &hna->net.prefix),
557 olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
560 for (hna = olsr_cnf->hna_entries; hna != NULL; hna = hna->next) {
563 olsr_ip_to_string(&buf, &hna->net.prefix),
565 olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
570 OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
572 /* Check all networks */
573 for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
574 uint32_t vt = tmp_net->hna_net_timer != NULL ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0;
575 int diff = (int)(vt);
577 "%s/%d\t%s\t\%d.%03d\n",
578 olsr_ip_to_string(&buf, &tmp_net->hna_prefix.prefix),
579 tmp_net->hna_prefix.prefix_len,
580 olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr),
581 diff/1000, abs(diff%1000));
584 OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
586 abuf_json_close_array(abuf);
590 ipc_print_mid(struct autobuf *abuf)
593 unsigned short is_first;
594 struct mid_entry *entry;
595 struct mid_address *alias;
597 abuf_json_open_array(abuf, "mid");
598 //abuf_puts(abuf, "Table: MID\nIP address\tAlias\tVTime\n");
601 for (idx = 0; idx < HASHSIZE; idx++) {
602 entry = mid_set[idx].next;
604 while (entry != &mid_set[idx]) {
605 struct ipaddr_str buf, buf2;
606 alias = entry->aliases;
610 uint32_t vt = alias->vtime - now_times;
611 int diff = (int)(vt);
613 abuf_appendf(abuf, "%s\t%s\t%d.%03d\n",
614 olsr_ip_to_string(&buf, &entry->main_addr),
615 olsr_ip_to_string(&buf2, &alias->alias),
616 diff/1000, abs(diff%1000));
617 alias = alias->next_alias;
623 abuf_json_close_array(abuf);
627 ipc_print_gateways(struct autobuf *abuf)
630 abuf_json_key_string(abuf, "error", "Gateway mode is only supported in Linux");
632 static const char IPV4[] = "ipv4";
633 static const char IPV4_NAT[] = "ipv4(n)";
634 static const char IPV6[] = "ipv6";
635 static const char NONE[] = "-";
637 struct ipaddr_str buf;
638 struct gateway_entry *gw;
639 struct lqtextbuffer lqbuf;
641 // Status IP ETX Hopcount Uplink-Speed Downlink-Speed ipv4/ipv4-nat/- ipv6/- ipv6-prefix/-
642 abuf_json_open_array(abuf, "gateways");
643 //abuf_puts(abuf, "Table: Gateways\nStatus\tGateway IP\tETX\tHopcnt\tUplink\tDownlnk\tIPv4\tIPv6\tPrefix\n");
644 OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
645 char v4 = '-', v6 = '-';
646 bool autoV4 = false, autoV6 = false;
647 const char *v4type = NONE, *v6type = NONE;
650 if ((tc = olsr_lookup_tc_entry(&gw->originator)) == NULL) {
654 if (gw == olsr_get_ipv4_inet_gateway(&autoV4)) {
655 v4 = autoV4 ? 'a' : 's';
656 } else if (gw->ipv4 && (olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit)
657 && (olsr_cnf->smart_gw_allow_nat || !gw->ipv4nat)) {
661 if (gw == olsr_get_ipv6_inet_gateway(&autoV6)) {
662 v6 = autoV6 ? 'a' : 's';
663 } else if (gw->ipv6 && olsr_cnf->ip_version == AF_INET6) {
668 v4type = gw->ipv4nat ? IPV4_NAT : IPV4;
674 abuf_appendf(abuf, "%c%c\t%s\t%s\t%d\t%u\t%u\t%s\t%s\t%s\n",
675 v4, v6, olsr_ip_to_string(&buf, &gw->originator),
676 get_linkcost_text(tc->path_cost, true, &lqbuf), tc->hops,
677 gw->uplink, gw->downlink, v4type, v6type,
678 gw->external_prefix.prefix_len == 0 ? NONE : olsr_ip_prefix_to_string(&gw->external_prefix));
680 OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
681 abuf_json_close_array(abuf);
686 ipc_print_config(struct autobuf *abuf)
688 olsrd_write_cnf_autobuf(abuf, olsr_cnf);
692 ipc_print_interfaces(struct autobuf *abuf)
694 const struct olsr_if *ifs;
695 abuf_json_open_array(abuf, "interfaces");
696 //abuf_puts(abuf, "Table: Interfaces\nName\tState\tMTU\tWLAN\tSrc-Adress\tMask\tDst-Adress\n");
697 for (ifs = olsr_cnf->interfaces; ifs != NULL; ifs = ifs->next) {
698 const struct interface *const rifs = ifs->interf;
699 abuf_json_open_array_entry(abuf);
700 abuf_json_key_string(abuf, "name", ifs->name);
702 abuf_json_key_string(abuf, "state", "down");
704 abuf_json_key_string(abuf, "state", "up");
705 abuf_json_key_int(abuf, "mtu", rifs->int_mtu);
706 abuf_json_boolean(abuf, "wireless", rifs->is_wireless);
708 if (olsr_cnf->ip_version == AF_INET) {
709 struct ipaddr_str addrbuf, maskbuf, bcastbuf;
710 abuf_json_key_string(abuf, "ipv4Address",
711 ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
712 abuf_json_key_string(abuf, "netmask",
713 ip4_to_string(&maskbuf, rifs->int_netmask.sin_addr));
714 abuf_json_key_string(abuf, "broadcast",
715 ip4_to_string(&bcastbuf, rifs->int_broadaddr.sin_addr));
717 struct ipaddr_str addrbuf, maskbuf;
718 abuf_json_key_string(abuf, "ipv6Address",
719 ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
720 abuf_json_key_string(abuf, "multicast",
721 ip6_to_string(&maskbuf, &rifs->int6_multaddr.sin6_addr));
724 abuf_json_close_array_entry(abuf);
726 abuf_json_close_array(abuf);
731 jsoninfo_write_data(void *foo __attribute__ ((unused)))
734 int result, i, j, max;
739 for (i=0; i<outbuffer_count; i++) {
740 /* And we cast here since we get a warning on Win32 */
741 FD_SET((unsigned int)(outbuffer_socket[i]), &set);
743 if (outbuffer_socket[i] > max) {
744 max = outbuffer_socket[i];
751 result = select(max + 1, NULL, &set, NULL, &tv);
756 for (i=0; i<outbuffer_count; i++) {
757 if (FD_ISSET(outbuffer_socket[i], &set)) {
758 result = send(outbuffer_socket[i],
759 outbuffer[i] + outbuffer_written[i],
760 outbuffer_size[i] - outbuffer_written[i],
763 outbuffer_written[i] += result;
766 if (result <= 0 || outbuffer_written[i] == outbuffer_size[i]) {
767 /* close this socket and cleanup*/
768 close(outbuffer_socket[i]);
771 for (j=i+1; j<outbuffer_count; j++) {
772 outbuffer[j-1] = outbuffer[j];
773 outbuffer_size[j-1] = outbuffer_size[j];
774 outbuffer_socket[j-1] = outbuffer_socket[j];
775 outbuffer_written[j-1] = outbuffer_written[j];
781 if (outbuffer_count == 0) {
782 olsr_stop_timer(writetimer_entry);
787 send_info(unsigned int send_what, int the_socket)
791 abuf_init(&abuf, 4096);
793 /* Print minimal http header */
794 abuf_puts(&abuf, "HTTP/1.0 200 OK\n");
795 abuf_puts(&abuf, "Content-type: text/plain\n\n");
797 /* Print tables to IPC socket */
799 if ((send_what & SIW_LINKS) == SIW_LINKS)
800 ipc_print_links(&abuf);
801 if ((send_what & SIW_NEIGHBORS) == SIW_NEIGHBORS)
802 ipc_print_neighbors(&abuf,false);
803 if ((send_what & SIW_TOPOLOGY) == SIW_TOPOLOGY)
804 ipc_print_topology(&abuf);
805 if ((send_what & SIW_HNA) == SIW_HNA)
806 ipc_print_hna(&abuf);
807 if ((send_what & SIW_MID) == SIW_MID)
808 ipc_print_mid(&abuf);
809 if ((send_what & SIW_ROUTES) == SIW_ROUTES)
810 ipc_print_routes(&abuf);
811 if ((send_what & SIW_GATEWAYS) == SIW_GATEWAYS)
812 ipc_print_gateways(&abuf);
813 if ((send_what & SIW_CONFIG) == SIW_CONFIG)
814 ipc_print_config(&abuf);
815 if ((send_what & SIW_INTERFACES) == SIW_INTERFACES)
816 ipc_print_interfaces(&abuf);
817 if ((send_what & SIW_TWOHOP) == SIW_TWOHOP)
818 ipc_print_neighbors(&abuf,true);
820 outbuffer[outbuffer_count] = olsr_malloc(abuf.len, "txt output buffer");
821 outbuffer_size[outbuffer_count] = abuf.len;
822 outbuffer_written[outbuffer_count] = 0;
823 outbuffer_socket[outbuffer_count] = the_socket;
825 memcpy(outbuffer[outbuffer_count], abuf.buf, abuf.len);
828 if (outbuffer_count == 1) {
829 writetimer_entry = olsr_start_timer(100,
832 &jsoninfo_write_data,
845 * indent-tabs-mode: nil