2 * The olsr.org Optimized Link-State Routing daemon(olsrd)
3 * Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org)
4 * includes code by Bruno Randolf
5 * includes code by Andreas Lopatic
6 * includes code by Sven-Ola Tuecke
7 * includes code by Lorenz Schori
8 * includes bugs by Markus Kittenberger
9 * includes bugs by Hans-Christoph Steiner
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * * Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * * Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in
20 * the documentation and/or other materials provided with the
22 * * Neither the name of olsr.org, olsrd nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
39 * Visit http://www.olsr.org for more information.
41 * If you find this software useful feel free to make a donation
42 * to the project. For more information see the website or contact
43 * the copyright holders.
48 * Dynamic linked library for the olsr.org olsr daemon
52 #include <sys/types.h>
53 #include <sys/socket.h>
55 #include <sys/select.h>
57 #include <netinet/in.h>
58 #include <arpa/inet.h>
72 #endif /* __linux__ */
76 #include "builddata.h"
77 #include "olsr_types.h"
78 #include "neighbor_table.h"
79 #include "two_hop_neighbor_table.h"
80 #include "mpr_selector_set.h"
86 #include "lq_plugin.h"
87 #include "common/autobuf.h"
90 #include "olsrd_jsoninfo.h"
91 #include "olsrd_plugin.h"
94 #define close(x) closesocket(x)
97 static int ipc_socket;
99 /* IPC initialization function */
100 static int plugin_ipc_init(void);
102 static int read_uuid_from_file(const char *file);
104 static void abuf_json_open_object(struct autobuf *abuf, const char* header);
105 static void abuf_json_close_object(struct autobuf *abuf);
106 static void abuf_json_open_array(struct autobuf *abuf, const char* header);
107 static void abuf_json_close_array(struct autobuf *abuf);
108 static void abuf_json_open_array_entry(struct autobuf *abuf);
109 static void abuf_json_close_array_entry(struct autobuf *abuf);
110 static void abuf_json_boolean(struct autobuf *abuf, const char* key, int value);
111 static void abuf_json_string(struct autobuf *abuf, const char* key, const char* value);
112 static void abuf_json_int(struct autobuf *abuf, const char* key, long value);
113 static void abuf_json_float(struct autobuf *abuf, const char* key, float value);
115 static void send_info(unsigned int /*send_what*/, int /*socket*/);
116 static void ipc_action(int, void *, unsigned int);
117 static void ipc_print_neighbors(struct autobuf *);
118 static void ipc_print_links(struct autobuf *);
119 static void ipc_print_routes(struct autobuf *);
120 static void ipc_print_topology(struct autobuf *);
121 static void ipc_print_hna(struct autobuf *);
122 static void ipc_print_mid(struct autobuf *);
123 static void ipc_print_gateways(struct autobuf *);
124 static void ipc_print_config(struct autobuf *);
125 static void ipc_print_interfaces(struct autobuf *);
126 static void ipc_print_plugins(struct autobuf *);
127 static void ipc_print_olsrd_conf(struct autobuf *abuf);
129 #define TXT_IPC_BUFSIZE 256
131 /* these provide all of the runtime status info */
132 #define SIW_NEIGHBORS 0x0001
133 #define SIW_LINKS 0x0002
134 #define SIW_ROUTES 0x0004
135 #define SIW_HNA 0x0008
136 #define SIW_MID 0x0010
137 #define SIW_TOPOLOGY 0x0020
138 #define SIW_GATEWAYS 0x0040
139 #define SIW_INTERFACES 0x0080
140 #define SIW_RUNTIME_ALL 0x00FF
142 /* these only change at olsrd startup */
143 #define SIW_CONFIG 0x0100
144 #define SIW_PLUGINS 0x0200
145 #define SIW_STARTUP_ALL 0x0F00
147 /* this is everything in JSON format */
148 #define SIW_ALL 0x0FFF
150 /* this data is not JSON format but olsrd.conf format */
151 #define SIW_OLSRD_CONF 0x1000
153 #define MAX_CLIENTS 3
155 static char *outbuffer[MAX_CLIENTS];
156 static size_t outbuffer_size[MAX_CLIENTS];
157 static size_t outbuffer_written[MAX_CLIENTS];
158 static int outbuffer_socket[MAX_CLIENTS];
159 static int outbuffer_count;
161 char uuid[UUIDLEN + 1];
162 char uuidfile[FILENAME_MAX];
164 static struct timeval start_time;
165 static struct timer_entry *writetimer_entry;
168 /* JSON support functions */
170 /* JSON does not allow commas dangling at the end of arrays, so we need to
171 * count which entry number we're at in order to make sure we don't tack a
172 * dangling comma on at the end */
173 static int entrynumber[5] = {0,0,0,0,0};
174 static int currentjsondepth = 0;
177 abuf_json_open_object(struct autobuf *abuf, const char* header)
179 abuf_appendf(abuf, "\"%s\": {", header);
180 entrynumber[currentjsondepth]++;
182 entrynumber[currentjsondepth] = 0;
186 abuf_json_close_object(struct autobuf *abuf)
188 abuf_appendf(abuf, "\t}\n");
193 abuf_json_open_array(struct autobuf *abuf, const char* header)
195 if (entrynumber[currentjsondepth])
196 abuf_appendf(abuf, ",\n\t");
197 abuf_appendf(abuf, "\"%s\": [\n", header);
198 entrynumber[currentjsondepth]++;
200 entrynumber[currentjsondepth] = 0;
204 abuf_json_close_array(struct autobuf *abuf)
206 abuf_appendf(abuf, "]\n");
207 entrynumber[currentjsondepth] = 0;
212 abuf_json_open_array_entry(struct autobuf *abuf)
214 if (entrynumber[currentjsondepth])
215 abuf_appendf(abuf, ",\n{");
217 abuf_appendf(abuf, "{");
218 entrynumber[currentjsondepth]++;
220 entrynumber[currentjsondepth] = 0;
224 abuf_json_close_array_entry(struct autobuf *abuf)
226 abuf_appendf(abuf, "}");
227 entrynumber[currentjsondepth] = 0;
232 abuf_json_insert_comma(struct autobuf *abuf)
234 if (entrynumber[currentjsondepth])
235 abuf_appendf(abuf, ",\n");
237 abuf_appendf(abuf, "\n");
238 entrynumber[currentjsondepth]++;
242 abuf_json_boolean(struct autobuf *abuf, const char* key, int value)
244 abuf_json_insert_comma(abuf);
245 abuf_appendf(abuf, "\t\"%s\": %s", key, value ? "true" : "false");
249 abuf_json_string(struct autobuf *abuf, const char* key, const char* value)
251 abuf_json_insert_comma(abuf);
252 abuf_appendf(abuf, "\t\"%s\": \"%s\"", key, value);
256 abuf_json_int(struct autobuf *abuf, const char* key, long value)
258 abuf_json_insert_comma(abuf);
259 abuf_appendf(abuf, "\t\"%s\": %li", key, value);
263 abuf_json_float(struct autobuf *abuf, const char* key, float value)
265 abuf_json_insert_comma(abuf);
266 abuf_appendf(abuf, "\t\"%s\": %.03f", key, (double)value);
271 /* Linux specific functions for getting system info */
274 static int get_string_from_file(const char* filename, char* buf, int len)
277 int fd = open(filename, O_RDONLY);
279 bytes = read(fd, buf, len);
281 buf[bytes-1] = '\0'; // remove trailing \n
290 abuf_json_sysdata(struct autobuf *abuf, const char* key, const char* syspath)
295 ret = get_string_from_file(syspath, buf, 256);
297 abuf_json_string(abuf, key, buf);
302 abuf_json_sys_class_net(struct autobuf *abuf, const char* key,
303 const char* ifname, const char* datapoint)
306 snprintf(filename, 255, "/sys/class/net/%s/%s", ifname, datapoint);
307 abuf_json_sysdata(abuf, key, filename);
310 #endif /* __linux__ */
315 *Do initialization here
317 *This function is called by the my_init
318 *function in uolsrd_plugin.c
321 olsrd_plugin_init(void)
323 /* Initial IPC value */
327 gettimeofday(&start_time, NULL);
329 if (!strlen(uuidfile))
330 strscpy(uuidfile, "uuid.txt", sizeof(uuidfile));
331 read_uuid_from_file(uuidfile);
338 * destructor - called at unload
341 olsr_plugin_exit(void)
343 if (ipc_socket != -1)
348 plugin_ipc_init(void)
350 union olsr_sockaddr sst;
354 /* Init ipc socket */
355 if ((ipc_socket = socket(olsr_cnf->ip_version, SOCK_STREAM, 0)) == -1) {
357 olsr_printf(1, "(JSONINFO) socket()=%s\n", strerror(errno));
361 if (setsockopt(ipc_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0) {
363 olsr_printf(1, "(JSONINFO) setsockopt()=%s\n", strerror(errno));
367 #if (defined __FreeBSD__ || defined __FreeBSD_kernel__) && defined SO_NOSIGPIPE
368 if (setsockopt(ipc_socket, SOL_SOCKET, SO_NOSIGPIPE, (char *)&yes, sizeof(yes)) < 0) {
369 perror("SO_REUSEADDR failed");
372 #endif /* (defined __FreeBSD__ || defined __FreeBSD_kernel__) && defined SO_NOSIGPIPE */
373 /* Bind the socket */
375 /* complete the socket structure */
376 memset(&sst, 0, sizeof(sst));
377 if (olsr_cnf->ip_version == AF_INET) {
378 sst.in4.sin_family = AF_INET;
379 addrlen = sizeof(struct sockaddr_in);
381 sst.in4.sin_len = addrlen;
382 #endif /* SIN6_LEN */
383 sst.in4.sin_addr.s_addr = jsoninfo_listen_ip.v4.s_addr;
384 sst.in4.sin_port = htons(ipc_port);
386 sst.in6.sin6_family = AF_INET6;
387 addrlen = sizeof(struct sockaddr_in6);
389 sst.in6.sin6_len = addrlen;
390 #endif /* SIN6_LEN */
391 sst.in6.sin6_addr = jsoninfo_listen_ip.v6;
392 sst.in6.sin6_port = htons(ipc_port);
395 /* bind the socket to the port number */
396 if (bind(ipc_socket, &sst.in, addrlen) == -1) {
398 olsr_printf(1, "(JSONINFO) bind()=%s\n", strerror(errno));
403 /* show that we are willing to listen */
404 if (listen(ipc_socket, 1) == -1) {
406 olsr_printf(1, "(JSONINFO) listen()=%s\n", strerror(errno));
411 /* Register with olsrd */
412 add_olsr_socket(ipc_socket, &ipc_action, NULL, NULL, SP_PR_READ);
415 olsr_printf(2, "(JSONINFO) listening on port %d\n", ipc_port);
422 read_uuid_from_file(const char *file)
429 memset(uuid, 0, sizeof(uuid));
431 f = fopen(file, "r");
432 olsr_printf(1, "(JSONINFO) Reading UUID from '%s'\n", file);
434 olsr_printf(1, "(JSONINFO) Could not open '%s': %s\n",
435 file, strerror(errno));
438 chars = fread(uuid, 1, UUIDLEN, f);
440 uuid[chars] = '\0'; /* null-terminate the string */
442 /* we only use the first line of the file */
443 end = strchr(uuid, '\n');
448 olsr_printf(1, "(JSONINFO) Could not read UUID from '%s': %s\n",
449 file, strerror(errno));
458 ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __attribute__ ((unused)))
460 union olsr_sockaddr pin;
462 char addr[INET6_ADDRSTRLEN];
465 unsigned int send_what = 0;
468 socklen_t addrlen = sizeof(pin);
470 if ((ipc_connection = accept(fd, &pin.in, &addrlen)) == -1) {
472 olsr_printf(1, "(JSONINFO) accept()=%s\n", strerror(errno));
477 tv.tv_sec = tv.tv_usec = 0;
478 if (olsr_cnf->ip_version == AF_INET) {
479 if (inet_ntop(olsr_cnf->ip_version, &pin.in4.sin_addr, addr, INET6_ADDRSTRLEN) == NULL)
481 if (!ip4equal(&pin.in4.sin_addr, &jsoninfo_accept_ip.v4) && jsoninfo_accept_ip.v4.s_addr != INADDR_ANY) {
482 #ifdef JSONINFO_ALLOW_LOCALHOST
483 if (pin.in4.sin_addr.s_addr != INADDR_LOOPBACK) {
484 #endif /* JSONINFO_ALLOW_LOCALHOST */
485 olsr_printf(1, "(JSONINFO) From host(%s) not allowed!\n", addr);
486 close(ipc_connection);
488 #ifdef JSONINFO_ALLOW_LOCALHOST
490 #endif /* JSONINFO_ALLOW_LOCALHOST */
493 if (inet_ntop(olsr_cnf->ip_version, &pin.in6.sin6_addr, addr, INET6_ADDRSTRLEN) == NULL)
495 /* Use in6addr_any (::) in olsr.conf to allow anybody. */
496 if (!ip6equal(&in6addr_any, &jsoninfo_accept_ip.v6) && !ip6equal(&pin.in6.sin6_addr, &jsoninfo_accept_ip.v6)) {
497 olsr_printf(1, "(JSONINFO) From host(%s) not allowed!\n", addr);
498 close(ipc_connection);
504 olsr_printf(2, "(JSONINFO) Connect from %s\n", addr);
507 /* purge read buffer to prevent blocking on linux */
509 FD_SET((unsigned int)ipc_connection, &rfds); /* Win32 needs the cast here */
510 if (0 <= select(ipc_connection + 1, &rfds, NULL, NULL, &tv)) {
512 ssize_t s = recv(ipc_connection, (void *)&requ, sizeof(requ), 0); /* Win32 needs the cast here */
515 /* print out the requested tables */
516 if (0 != strstr(requ, "/olsrd.conf"))
517 send_what |= SIW_OLSRD_CONF;
518 else if (0 != strstr(requ, "/all"))
521 // these are the two overarching categories
522 if (0 != strstr(requ, "/runtime")) send_what |= SIW_RUNTIME_ALL;
523 if (0 != strstr(requ, "/startup")) send_what |= SIW_STARTUP_ALL;
524 // these are the individual sections
525 if (0 != strstr(requ, "/neighbors")) send_what |= SIW_NEIGHBORS;
526 if (0 != strstr(requ, "/links")) send_what |= SIW_LINKS;
527 if (0 != strstr(requ, "/routes")) send_what |= SIW_ROUTES;
528 if (0 != strstr(requ, "/hna")) send_what |= SIW_HNA;
529 if (0 != strstr(requ, "/mid")) send_what |= SIW_MID;
530 if (0 != strstr(requ, "/topology")) send_what |= SIW_TOPOLOGY;
531 if (0 != strstr(requ, "/gateways")) send_what |= SIW_GATEWAYS;
532 if (0 != strstr(requ, "/interfaces")) send_what |= SIW_INTERFACES;
533 if (0 != strstr(requ, "/config")) send_what |= SIW_CONFIG;
534 if (0 != strstr(requ, "/plugins")) send_what |= SIW_PLUGINS;
537 if ( send_what == 0 ) send_what = SIW_ALL;
540 send_info(send_what, ipc_connection);
544 ipc_print_neighbors(struct autobuf *abuf)
546 struct ipaddr_str buf1;
547 struct neighbor_entry *neigh;
548 struct neighbor_2_list_entry *list_2;
551 abuf_json_open_array(abuf, "neighbors");
554 OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
555 abuf_json_open_array_entry(abuf);
556 abuf_json_string(abuf, "ipv4Address",
557 olsr_ip_to_string(&buf1, &neigh->neighbor_main_addr));
558 abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
559 abuf_json_boolean(abuf, "multiPointRelay", neigh->is_mpr);
560 abuf_json_boolean(abuf, "multiPointRelaySelector",
561 olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
562 abuf_json_int(abuf, "willingness", neigh->willingness);
563 abuf_appendf(abuf, ",\n");
566 if (neigh->neighbor_2_list.next) {
567 abuf_appendf(abuf, "\t\"twoHopNeighbors\": [");
568 for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
570 abuf_appendf(abuf, ", ");
573 olsr_ip_to_string(&buf1, &list_2->neighbor_2->neighbor_2_addr));
577 abuf_appendf(abuf, "]");
578 abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
579 abuf_json_close_array_entry(abuf);
581 OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
582 abuf_json_close_array(abuf);
586 ipc_print_links(struct autobuf *abuf)
588 struct ipaddr_str buf1, buf2;
589 struct lqtextbuffer lqbuffer1;
591 struct link_entry *my_link = NULL;
593 abuf_json_open_array(abuf, "links");
594 OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
596 int diff = (unsigned int)(my_link->link_timer->timer_clock - now_times);
598 abuf_json_open_array_entry(abuf);
599 abuf_json_string(abuf, "localIP",
600 olsr_ip_to_string(&buf1, &my_link->local_iface_addr));
601 abuf_json_string(abuf, "remoteIP",
602 olsr_ip_to_string(&buf2, &my_link->neighbor_iface_addr));
603 abuf_json_int(abuf, "validityTime", diff);
604 lqs = get_link_entry_text(my_link, '\t', &lqbuffer1);
605 abuf_json_float(abuf, "linkQuality", atof(lqs));
606 abuf_json_float(abuf, "neighborLinkQuality", atof(strrchr(lqs, '\t')));
607 if (my_link->linkcost >= LINK_COST_BROKEN)
608 abuf_json_int(abuf, "linkCost", LINK_COST_BROKEN);
610 abuf_json_int(abuf, "linkCost", my_link->linkcost);
611 abuf_json_close_array_entry(abuf);
613 OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
614 abuf_json_close_array(abuf);
618 ipc_print_routes(struct autobuf *abuf)
620 struct ipaddr_str buf1, buf2;
623 abuf_json_open_array(abuf, "routes");
625 /* Walk the route table */
626 OLSR_FOR_ALL_RT_ENTRIES(rt) {
627 abuf_json_open_array_entry(abuf);
628 abuf_json_string(abuf, "destination",
629 olsr_ip_to_string(&buf1, &rt->rt_dst.prefix));
630 abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
631 abuf_json_string(abuf, "gateway",
632 olsr_ip_to_string(&buf2, &rt->rt_best->rtp_nexthop.gateway));
633 abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
634 if (rt->rt_best->rtp_metric.cost >= ROUTE_COST_BROKEN)
635 abuf_json_int(abuf, "rtpMetricCost", ROUTE_COST_BROKEN);
637 abuf_json_int(abuf, "rtpMetricCost", rt->rt_best->rtp_metric.cost);
638 abuf_json_string(abuf, "networkInterface",
639 if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
640 abuf_json_close_array_entry(abuf);
642 OLSR_FOR_ALL_RT_ENTRIES_END(rt);
644 abuf_json_close_array(abuf);
648 ipc_print_topology(struct autobuf *abuf)
652 abuf_json_open_array(abuf, "topology");
655 OLSR_FOR_ALL_TC_ENTRIES(tc) {
656 struct tc_edge_entry *tc_edge;
657 OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
658 if (tc_edge->edge_inv) {
659 struct ipaddr_str dstbuf, addrbuf;
660 struct lqtextbuffer lqbuffer1;
661 uint32_t vt = tc->validity_timer != NULL ? (tc->validity_timer->timer_clock - now_times) : 0;
662 int diff = (int)(vt);
664 abuf_json_open_array_entry(abuf);
665 abuf_json_string(abuf, "destinationIP",
666 olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr));
667 abuf_json_string(abuf, "lastHopIP",
668 olsr_ip_to_string(&addrbuf, &tc->addr));
669 lqs = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer1);
670 abuf_json_float(abuf, "linkQuality", atof(lqs));
671 abuf_json_float(abuf, "neighborLinkQuality", atof(strrchr(lqs, '\t')));
672 if (tc_edge->cost >= LINK_COST_BROKEN)
673 abuf_json_int(abuf, "tcEdgeCost", LINK_COST_BROKEN);
675 abuf_json_int(abuf, "tcEdgeCost", tc_edge->cost);
676 abuf_json_int(abuf, "validityTime", diff);
677 abuf_json_close_array_entry(abuf);
680 OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
682 OLSR_FOR_ALL_TC_ENTRIES_END(tc);
684 abuf_json_close_array(abuf);
688 ipc_print_hna(struct autobuf *abuf)
690 struct hna_entry *tmp_hna;
691 struct hna_net *tmp_net;
692 struct ipaddr_str buf, mainaddrbuf;
694 abuf_json_open_array(abuf, "hna");
696 OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
698 /* Check all networks */
699 for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
700 uint32_t vt = tmp_net->hna_net_timer != NULL ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0;
701 int diff = (int)(vt);
702 abuf_json_open_array_entry(abuf);
703 abuf_json_string(abuf, "destination",
704 olsr_ip_to_string(&buf, &tmp_net->hna_prefix.prefix)),
705 abuf_json_int(abuf, "genmask", tmp_net->hna_prefix.prefix_len);
706 abuf_json_string(abuf, "gateway",
707 olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr));
708 abuf_json_int(abuf, "validityTime", diff);
709 abuf_json_close_array_entry(abuf);
712 OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
714 abuf_json_close_array(abuf);
718 ipc_print_mid(struct autobuf *abuf)
721 struct mid_entry *entry;
722 struct mid_address *alias;
724 abuf_json_open_array(abuf, "mid");
727 for (idx = 0; idx < HASHSIZE; idx++) {
728 entry = mid_set[idx].next;
730 while (entry != &mid_set[idx]) {
731 struct ipaddr_str buf, buf2;
732 abuf_json_open_array_entry(abuf);
733 abuf_json_string(abuf, "ipAddress",
734 olsr_ip_to_string(&buf, &entry->main_addr));
736 abuf_json_open_array(abuf, "aliases");
737 alias = entry->aliases;
739 uint32_t vt = alias->vtime - now_times;
740 int diff = (int)(vt);
742 abuf_json_open_array_entry(abuf);
743 abuf_json_string(abuf, "ipAddress",
744 olsr_ip_to_string(&buf2, &alias->alias));
745 abuf_json_int(abuf, "validityTime", diff);
746 abuf_json_close_array_entry(abuf);
748 alias = alias->next_alias;
750 abuf_json_close_array(abuf); // aliases
751 abuf_json_close_array_entry(abuf);
755 abuf_json_close_array(abuf); // mid
759 ipc_print_gateways(struct autobuf *abuf)
762 abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
763 #else /* __linux__ */
765 struct ipaddr_str buf;
766 struct gateway_entry *gw;
768 abuf_json_open_array(abuf, "gateways");
769 OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
770 const char *v4 = "", *v6 = "";
771 bool autoV4 = false, autoV6 = false;
772 const char *ipType = "";
775 if ((tc = olsr_lookup_tc_entry(&gw->originator)) == NULL) {
779 if (gw == olsr_get_inet_gateway(false)) {
781 } else if (gw->ipv4 && (olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit)
782 && (olsr_cnf->smart_gw_allow_nat || !gw->ipv4nat)) {
786 if (gw == olsr_get_inet_gateway(true)) {
788 } else if (gw->ipv6 && olsr_cnf->ip_version == AF_INET6) {
792 abuf_json_open_array_entry(abuf);
795 abuf_json_string(abuf, "ipv4Status", v4);
796 } else if (gw->ipv6) {
798 abuf_json_string(abuf, "ipv6Status", v6);
800 abuf_json_string(abuf, "ipType", ipType);
801 abuf_json_boolean(abuf, "ipv4", gw->ipv4);
802 abuf_json_boolean(abuf, "ipv4Nat", gw->ipv4nat);
803 abuf_json_boolean(abuf, "ipv6", gw->ipv6);
804 abuf_json_boolean(abuf, "autoIpv4", autoV4);
805 abuf_json_boolean(abuf, "autoIpv6", autoV6);
806 abuf_json_string(abuf, "ipAddress",
807 olsr_ip_to_string(&buf, &gw->originator));
808 if (tc->path_cost >= ROUTE_COST_BROKEN)
809 abuf_json_int(abuf, "tcPathCost", ROUTE_COST_BROKEN);
811 abuf_json_int(abuf, "tcPathCost", tc->path_cost);
812 abuf_json_int(abuf, "hopCount", tc->hops);
813 abuf_json_int(abuf, "uplinkSpeed", gw->uplink);
814 abuf_json_int(abuf, "downlinkSpeed", gw->downlink);
815 if(gw->external_prefix.prefix_len == 0)
816 abuf_json_string(abuf, "externalPrefix",
817 olsr_ip_prefix_to_string(&gw->external_prefix));
818 abuf_json_close_array_entry(abuf);
820 OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
821 abuf_json_close_array(abuf);
822 #endif /* __linux__ */
827 ipc_print_plugins(struct autobuf *abuf)
829 struct plugin_entry *pentry;
830 struct plugin_param *pparam;
831 abuf_json_open_array(abuf, "plugins");
832 if (olsr_cnf->plugins)
833 for (pentry = olsr_cnf->plugins; pentry; pentry = pentry->next) {
834 abuf_json_open_array_entry(abuf);
835 abuf_json_string(abuf, "plugin", pentry->name);
836 for (pparam = pentry->params; pparam; pparam = pparam->next) {
837 int i, keylen = strlen(pparam->key);
838 char key[keylen + 1];
841 strcpy(key, pparam->key);
842 for (i = 0; i < keylen; i++)
843 key[i] = tolower(key[i]);
845 // test if a int/long and set as such in JSON
846 value = atol(pparam->value);
847 snprintf(valueTest, 255, "%li", value);
848 if (strcmp(valueTest, pparam->value) == 0)
849 abuf_json_int(abuf, key, value);
851 abuf_json_string(abuf, key, pparam->value);
853 abuf_json_close_array_entry(abuf);
855 abuf_json_close_array(abuf);
860 ipc_print_config(struct autobuf *abuf)
862 struct ip_prefix_list *hna;
863 struct ipaddr_str buf, mainaddrbuf;
864 struct ip_prefix_list *ipcn;
865 struct olsr_lq_mult *mult;
866 char ipv6_buf[INET6_ADDRSTRLEN]; /* buffer for IPv6 inet_htop */
868 abuf_json_open_object(abuf, "config");
870 abuf_json_int(abuf, "olsrPort", olsr_cnf->olsrport);
871 abuf_json_int(abuf, "debugLevel", olsr_cnf->debug_level);
872 abuf_json_boolean(abuf, "noFork", olsr_cnf->no_fork);
873 abuf_json_boolean(abuf, "hostEmulation", olsr_cnf->host_emul);
874 abuf_json_int(abuf, "ipVersion", olsr_cnf->ip_version);
875 abuf_json_boolean(abuf, "allowNoInterfaces", olsr_cnf->allow_no_interfaces);
876 abuf_json_int(abuf, "typeOfService", olsr_cnf->tos);
877 abuf_json_int(abuf, "rtProto", olsr_cnf->rt_proto);
878 abuf_json_int(abuf, "rtTable", olsr_cnf->rt_table);
879 abuf_json_int(abuf, "rtTableDefault", olsr_cnf->rt_table_default);
880 abuf_json_int(abuf, "rtTableTunnel", olsr_cnf->rt_table_tunnel);
881 abuf_json_int(abuf, "rtTablePriority", olsr_cnf->rt_table_pri);
882 abuf_json_int(abuf, "rtTableTunnelPriority", olsr_cnf->rt_table_tunnel_pri);
883 abuf_json_int(abuf, "rtTableDefauiltOlsrPriority", olsr_cnf->rt_table_defaultolsr_pri);
884 abuf_json_int(abuf, "rtTableDefaultPriority", olsr_cnf->rt_table_default_pri);
885 abuf_json_int(abuf, "willingness", olsr_cnf->willingness);
886 abuf_json_boolean(abuf, "willingnessAuto", olsr_cnf->willingness_auto);
888 abuf_json_int(abuf, "brokenLinkCost", LINK_COST_BROKEN);
889 abuf_json_int(abuf, "brokenRouteCost", ROUTE_COST_BROKEN);
891 abuf_json_string(abuf, "fibMetrics", FIB_METRIC_TXT[olsr_cnf->fib_metric]);
893 abuf_json_string(abuf, "defaultIpv6Multicast",
894 inet_ntop(AF_INET6, &olsr_cnf->interface_defaults->ipv6_multicast.v6,
895 ipv6_buf, sizeof(ipv6_buf)));
896 if (olsr_cnf->interface_defaults->ipv4_multicast.v4.s_addr)
897 abuf_json_string(abuf, "defaultIpv4Broadcast",
898 inet_ntoa(olsr_cnf->interface_defaults->ipv4_multicast.v4));
900 abuf_json_string(abuf, "defaultIpv4Broadcast", "auto");
902 if (olsr_cnf->interface_defaults->mode==IF_MODE_ETHER)
903 abuf_json_string(abuf, "defaultInterfaceMode", "ether");
905 abuf_json_string(abuf, "defaultInterfaceMode", "mesh");
907 abuf_json_float(abuf, "defaultHelloEmissionInterval",
908 olsr_cnf->interface_defaults->hello_params.emission_interval);
909 abuf_json_float(abuf, "defaultHelloValidityTime",
910 olsr_cnf->interface_defaults->hello_params.validity_time);
911 abuf_json_float(abuf, "defaultTcEmissionInterval",
912 olsr_cnf->interface_defaults->tc_params.emission_interval);
913 abuf_json_float(abuf, "defaultTcValidityTime",
914 olsr_cnf->interface_defaults->tc_params.validity_time);
915 abuf_json_float(abuf, "defaultMidEmissionInterval",
916 olsr_cnf->interface_defaults->mid_params.emission_interval);
917 abuf_json_float(abuf, "defaultMidValidityTime",
918 olsr_cnf->interface_defaults->mid_params.validity_time);
919 abuf_json_float(abuf, "defaultHnaEmissionInterval",
920 olsr_cnf->interface_defaults->hna_params.emission_interval);
921 abuf_json_float(abuf, "defaultHnaValidityTime",
922 olsr_cnf->interface_defaults->hna_params.validity_time);
923 abuf_json_boolean(abuf, "defaultAutoDetectChanges",
924 olsr_cnf->interface_defaults->autodetect_chg);
926 abuf_json_open_array(abuf, "defaultLinkQualityMultipliers");
927 for (mult = olsr_cnf->interface_defaults->lq_mult; mult != NULL; mult = mult->next) {
928 abuf_json_open_array_entry(abuf);
929 abuf_json_string(abuf, "route",
930 inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
931 abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
932 abuf_json_close_array_entry(abuf);
934 abuf_json_close_array(abuf);
936 abuf_json_open_array(abuf, "hna");
937 for (hna = olsr_cnf->hna_entries; hna != NULL; hna = hna->next) {
938 abuf_json_open_array_entry(abuf);
939 abuf_json_string(abuf, "destination",
940 olsr_ip_to_string(&buf, &hna->net.prefix));
941 abuf_json_int(abuf, "genmask", hna->net.prefix_len);
942 abuf_json_string(abuf, "gateway",
943 olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
944 abuf_json_close_array_entry(abuf);
946 abuf_json_close_array(abuf);
949 abuf_json_int(abuf, "totalIpcConnectionsAllowed", olsr_cnf->ipc_connections);
950 abuf_json_open_array(abuf, "ipcAllowedAddresses");
951 if (olsr_cnf->ipc_connections) {
952 for (ipcn = olsr_cnf->ipc_nets; ipcn != NULL; ipcn = ipcn->next) {
953 abuf_json_open_array_entry(abuf);
954 abuf_json_string(abuf, "ipAddress",
955 olsr_ip_to_string(&mainaddrbuf, &ipcn->net.prefix));
956 abuf_json_int(abuf, "netmask", ipcn->net.prefix_len);
957 abuf_json_close_array_entry(abuf);
960 abuf_json_close_array(abuf);
962 // keep all time in ms, so convert these two, which are in seconds
963 abuf_json_int(abuf, "pollRate", olsr_cnf->pollrate * 1000);
964 abuf_json_int(abuf, "nicChangePollInterval", olsr_cnf->nic_chgs_pollrate * 1000);
965 abuf_json_boolean(abuf, "clearScreen", olsr_cnf->clear_screen);
966 abuf_json_int(abuf, "tcRedundancy", olsr_cnf->tc_redundancy);
967 abuf_json_int(abuf, "mprCoverage", olsr_cnf->mpr_coverage);
969 if (olsr_cnf->lq_level == 0) {
970 abuf_json_boolean(abuf, "useHysteresis", olsr_cnf->use_hysteresis);
971 if (olsr_cnf->use_hysteresis) {
972 abuf_json_float(abuf, "hysteresisScaling", olsr_cnf->hysteresis_param.scaling);
973 abuf_json_float(abuf, "hysteresisLowThreshold", olsr_cnf->hysteresis_param.thr_low);
974 abuf_json_float(abuf, "hysteresisHighThreshold", olsr_cnf->hysteresis_param.thr_high);
977 abuf_json_int(abuf, "linkQualityLevel", olsr_cnf->lq_level);
978 abuf_json_float(abuf, "linkQualityAging", olsr_cnf->lq_aging);
979 abuf_json_boolean(abuf, "linkQualityFisheye", olsr_cnf->lq_fish);
980 abuf_json_string(abuf, "linkQualityAlgorithm", olsr_cnf->lq_algorithm);
981 // keep all time in ms, so convert this from seconds
982 abuf_json_int(abuf, "minTcValidTime", olsr_cnf->min_tc_vtime * 1000);
983 abuf_json_boolean(abuf, "setIpForward", olsr_cnf->set_ip_forward);
984 abuf_json_string(abuf, "lockFile", olsr_cnf->lock_file);
985 abuf_json_boolean(abuf, "useNiit", olsr_cnf->use_niit);
988 abuf_json_boolean(abuf, "smartGateway", olsr_cnf->smart_gw_active);
989 if (olsr_cnf->smart_gw_active) {
990 abuf_json_boolean(abuf, "smartGatewayAlwaysRemoveServerTunnel", olsr_cnf->smart_gw_always_remove_server_tunnel);
991 abuf_json_int(abuf, "smartGatewayUseCount", olsr_cnf->smart_gw_use_count);
992 abuf_json_string(abuf, "smartGatewayPolicyRoutingScript", olsr_cnf->smart_gw_policyrouting_script);
994 struct autobuf egressbuf;
995 struct sgw_egress_if * egressif = olsr_cnf->smart_gw_egress_interfaces;
997 abuf_init(&egressbuf, (olsr_cnf->smart_gw_egress_interfaces_count * IFNAMSIZ) /* interface names */
998 + (olsr_cnf->smart_gw_egress_interfaces_count - 1) /* commas */);
1000 if (egressbuf.len) {
1001 abuf_puts(&egressbuf, ",");
1003 abuf_appendf(&egressbuf, "%s", egressif->name);
1004 egressif = egressif->next;
1006 abuf_json_string(abuf, "smartGatewayEgressInterfaces", egressbuf.buf);
1007 abuf_free(&egressbuf);
1009 abuf_json_int(abuf, "smartGatewayMarkOffsetEgress", olsr_cnf->smart_gw_mark_offset_egress);
1010 abuf_json_int(abuf, "smartGatewayMarkOffsetTunnels", olsr_cnf->smart_gw_mark_offset_tunnels);
1011 abuf_json_boolean(abuf, "smartGatewayAllowNat", olsr_cnf->smart_gw_allow_nat);
1012 abuf_json_boolean(abuf, "smartGatewayUplinkNat", olsr_cnf->smart_gw_uplink_nat);
1013 abuf_json_int(abuf, "smartGatewayPeriod", olsr_cnf->smart_gw_period);
1014 abuf_json_int(abuf, "smartGatewayStableCount", olsr_cnf->smart_gw_stablecount);
1015 abuf_json_int(abuf, "smartGatewayThreshold", olsr_cnf->smart_gw_thresh);
1016 abuf_json_int(abuf, "smartGatewayUplink", olsr_cnf->smart_gw_uplink);
1017 abuf_json_int(abuf, "smartGatewayDownlink", olsr_cnf->smart_gw_downlink);
1018 abuf_json_int(abuf, "smartGatewayType", olsr_cnf->smart_gw_type);
1019 abuf_json_string(abuf, "smartGatewayPrefix",
1020 olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->smart_gw_prefix.prefix));
1021 abuf_json_int(abuf, "smartGatewayPrefixLength", olsr_cnf->smart_gw_prefix.prefix_len);
1023 #endif /* __linux__ */
1025 abuf_json_string(abuf, "mainIpAddress",
1026 olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
1027 abuf_json_string(abuf, "unicastSourceIpAddress",
1028 olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->unicast_src_ip));
1030 abuf_json_boolean(abuf, "useSourceIpRoutes", olsr_cnf->use_src_ip_routes);
1032 abuf_json_int(abuf, "maxPrefixLength", olsr_cnf->maxplen);
1033 abuf_json_int(abuf, "ipSize", olsr_cnf->ipsize);
1034 abuf_json_boolean(abuf, "deleteInternetGatewaysAtStartup", olsr_cnf->del_gws);
1035 // keep all time in ms, so convert this from seconds
1036 abuf_json_int(abuf, "willingnessUpdateInterval", olsr_cnf->will_int * 1000);
1037 abuf_json_float(abuf, "maxSendMessageJitter", olsr_cnf->max_jitter);
1038 abuf_json_int(abuf, "exitValue", olsr_cnf->exit_value);
1039 // keep all time in ms, so convert this from seconds
1040 abuf_json_int(abuf, "maxTcValidTime", olsr_cnf->max_tc_vtime * 1000);
1042 abuf_json_int(abuf, "niit4to6InterfaceIndex", olsr_cnf->niit4to6_if_index);
1043 abuf_json_int(abuf, "niit6to4InterfaceIndex", olsr_cnf->niit6to4_if_index);
1045 abuf_json_boolean(abuf, "hasIpv4Gateway", olsr_cnf->has_ipv4_gateway);
1046 abuf_json_boolean(abuf, "hasIpv6Gateway", olsr_cnf->has_ipv6_gateway);
1048 abuf_json_int(abuf, "ioctlSocket", olsr_cnf->ioctl_s);
1050 abuf_json_int(abuf, "routeNetlinkSocket", olsr_cnf->rtnl_s);
1051 abuf_json_int(abuf, "routeMonitorSocket", olsr_cnf->rt_monitor_socket);
1052 #endif /* __linux__ */
1054 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
1055 abuf_json_int(abuf, "routeChangeSocket", olsr_cnf->rts);
1056 #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ */
1057 abuf_json_float(abuf, "linkQualityNatThreshold", olsr_cnf->lq_nat_thresh);
1059 abuf_json_string(abuf, "olsrdVersion", olsrd_version);
1060 abuf_json_string(abuf, "olsrdBuildDate", build_date);
1061 abuf_json_string(abuf, "olsrdBuildHost", build_host);
1063 #if defined _WIN32 || defined _WIN64
1064 abuf_json_string(abuf, "os", "Windows");
1065 #elif defined __gnu_linux__
1066 abuf_json_string(abuf, "os", "GNU/Linux");
1067 #elif defined __ANDROID__
1068 abuf_json_string(abuf, "os", "Android");
1069 #elif defined __APPLE__
1070 abuf_json_string(abuf, "os", "Mac OS X");
1071 #elif defined __NetBSD__
1072 abuf_json_string(abuf, "os", "NetBSD");
1073 #elif defined __OpenBSD__
1074 abuf_json_string(abuf, "os", "OpenBSD");
1075 #elif defined __FreeBSD__ || defined __FreeBSD_kernel__
1076 abuf_json_string(abuf, "os", "FreeBSD");
1077 #else /* OS detection */
1078 abuf_json_string(abuf, "os", "Undefined");
1079 #endif /* OS detection */
1081 abuf_json_int(abuf, "startTime", start_time.tv_sec);
1083 abuf_json_close_object(abuf);
1087 ipc_print_interfaces(struct autobuf *abuf)
1091 char path[PATH_MAX], linkpath[PATH_MAX];
1092 #endif /* __linux__ */
1093 char ipv6_buf[INET6_ADDRSTRLEN]; /* buffer for IPv6 inet_htop */
1094 struct olsr_lq_mult *mult;
1095 const struct olsr_if *ifs;
1096 abuf_json_open_array(abuf, "interfaces");
1097 for (ifs = olsr_cnf->interfaces; ifs != NULL; ifs = ifs->next) {
1098 const struct interface *const rifs = ifs->interf;
1099 abuf_json_open_array_entry(abuf);
1100 abuf_json_string(abuf, "name", ifs->name);
1102 abuf_json_open_array(abuf, "linkQualityMultipliers");
1103 for (mult = ifs->cnf->lq_mult; mult != NULL; mult = mult->next) {
1104 abuf_json_open_array_entry(abuf);
1105 abuf_json_string(abuf, "route",
1106 inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
1107 abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
1108 abuf_json_close_array_entry(abuf);
1110 abuf_json_close_array(abuf);
1113 abuf_json_string(abuf, "state", "down");
1115 abuf_json_string(abuf, "state", "up");
1116 abuf_json_string(abuf, "nameFromKernel", rifs->int_name);
1117 abuf_json_int(abuf, "interfaceMode", rifs->mode);
1118 abuf_json_boolean(abuf, "emulatedHostClientInterface", rifs->is_hcif);
1119 abuf_json_boolean(abuf, "sendTcImmediately", rifs->immediate_send_tc);
1120 abuf_json_int(abuf, "fishEyeTtlIndex", rifs->ttl_index);
1121 abuf_json_int(abuf, "olsrForwardingTimeout", rifs->fwdtimer);
1122 abuf_json_int(abuf, "olsrMessageSequenceNumber", rifs->olsr_seqnum);
1123 abuf_json_int(abuf, "olsrInterfaceMetric", rifs->int_metric);
1124 abuf_json_int(abuf, "olsrMTU", rifs->int_mtu);
1125 abuf_json_int(abuf, "helloEmissionInterval", rifs->hello_etime);
1126 abuf_json_int(abuf, "helloValidityTime", rifs->valtimes.hello);
1127 abuf_json_int(abuf, "tcValidityTime", rifs->valtimes.tc);
1128 abuf_json_int(abuf, "midValidityTime", rifs->valtimes.mid);
1129 abuf_json_int(abuf, "hnaValidityTime", rifs->valtimes.hna);
1130 abuf_json_boolean(abuf, "wireless", rifs->is_wireless);
1133 abuf_json_boolean(abuf, "icmpRedirect", rifs->nic_state.redirect);
1134 abuf_json_boolean(abuf, "spoofFilter", rifs->nic_state.spoof);
1135 #endif /* __linux__ */
1137 if (olsr_cnf->ip_version == AF_INET) {
1138 struct ipaddr_str addrbuf, maskbuf, bcastbuf;
1139 abuf_json_string(abuf, "ipv4Address",
1140 ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
1141 abuf_json_string(abuf, "netmask",
1142 ip4_to_string(&maskbuf, rifs->int_netmask.sin_addr));
1143 abuf_json_string(abuf, "broadcast",
1144 ip4_to_string(&bcastbuf, rifs->int_broadaddr.sin_addr));
1146 struct ipaddr_str addrbuf, maskbuf;
1147 abuf_json_string(abuf, "ipv6Address",
1148 ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
1149 abuf_json_string(abuf, "multicast",
1150 ip6_to_string(&maskbuf, &rifs->int6_multaddr.sin6_addr));
1154 snprintf(path, PATH_MAX, "/sys/class/net/%s/device/driver/module", ifs->name);
1155 linklen = readlink(path, linkpath, PATH_MAX - 1);
1157 linkpath[linklen] = '\0';
1158 abuf_json_string(abuf, "kernelModule", basename(linkpath));
1161 abuf_json_sys_class_net(abuf, "addressLength", ifs->name, "addr_len");
1162 abuf_json_sys_class_net(abuf, "carrier", ifs->name, "carrier");
1163 abuf_json_sys_class_net(abuf, "dormant", ifs->name, "dormant");
1164 abuf_json_sys_class_net(abuf, "features", ifs->name, "features");
1165 abuf_json_sys_class_net(abuf, "flags", ifs->name, "flags");
1166 abuf_json_sys_class_net(abuf, "linkMode", ifs->name, "link_mode");
1167 abuf_json_sys_class_net(abuf, "macAddress", ifs->name, "address");
1168 abuf_json_sys_class_net(abuf, "ethernetMTU", ifs->name, "mtu");
1169 abuf_json_sys_class_net(abuf, "operationalState", ifs->name, "operstate");
1170 abuf_json_sys_class_net(abuf, "txQueueLength", ifs->name, "tx_queue_len");
1171 abuf_json_sys_class_net(abuf, "collisions", ifs->name, "statistics/collisions");
1172 abuf_json_sys_class_net(abuf, "multicastPackets", ifs->name, "statistics/multicast");
1173 abuf_json_sys_class_net(abuf, "rxBytes", ifs->name, "statistics/rx_bytes");
1174 abuf_json_sys_class_net(abuf, "rxCompressed", ifs->name, "statistics/rx_compressed");
1175 abuf_json_sys_class_net(abuf, "rxCrcErrors", ifs->name, "statistics/rx_crc_errors");
1176 abuf_json_sys_class_net(abuf, "rxDropped", ifs->name, "statistics/rx_dropped");
1177 abuf_json_sys_class_net(abuf, "rxErrors", ifs->name, "statistics/rx_errors");
1178 abuf_json_sys_class_net(abuf, "rxFifoErrors", ifs->name, "statistics/rx_fifo_errors");
1179 abuf_json_sys_class_net(abuf, "rxFrameErrors", ifs->name, "statistics/rx_frame_errors");
1180 abuf_json_sys_class_net(abuf, "rxLengthErrors", ifs->name, "statistics/rx_length_errors");
1181 abuf_json_sys_class_net(abuf, "rxMissedErrors", ifs->name, "statistics/rx_missed_errors");
1182 abuf_json_sys_class_net(abuf, "rxOverErrors", ifs->name, "statistics/rx_over_errors");
1183 abuf_json_sys_class_net(abuf, "rxPackets", ifs->name, "statistics/rx_packets");
1184 abuf_json_sys_class_net(abuf, "txAbortedErrors", ifs->name, "statistics/tx_aborted_errors");
1185 abuf_json_sys_class_net(abuf, "txBytes", ifs->name, "statistics/tx_bytes");
1186 abuf_json_sys_class_net(abuf, "txCarrierErrors", ifs->name, "statistics/tx_carrier_errors");
1187 abuf_json_sys_class_net(abuf, "txCompressed", ifs->name, "statistics/tx_compressed");
1188 abuf_json_sys_class_net(abuf, "txDropped", ifs->name, "statistics/tx_dropped");
1189 abuf_json_sys_class_net(abuf, "txErrors", ifs->name, "statistics/tx_errors");
1190 abuf_json_sys_class_net(abuf, "txFifoErrors", ifs->name, "statistics/tx_fifo_errors");
1191 abuf_json_sys_class_net(abuf, "txHeartbeatErrors", ifs->name, "statistics/tx_heartbeat_errors");
1192 abuf_json_sys_class_net(abuf, "txPackets", ifs->name, "statistics/tx_packets");
1193 abuf_json_sys_class_net(abuf, "txWindowErrors", ifs->name, "statistics/tx_window_errors");
1194 abuf_json_sys_class_net(abuf, "beaconing", ifs->name, "wireless/beacon");
1195 abuf_json_sys_class_net(abuf, "encryptionKey", ifs->name, "wireless/crypt");
1196 abuf_json_sys_class_net(abuf, "fragmentationThreshold", ifs->name, "wireless/fragment");
1197 abuf_json_sys_class_net(abuf, "signalLevel", ifs->name, "wireless/level");
1198 abuf_json_sys_class_net(abuf, "linkQuality", ifs->name, "wireless/link");
1199 abuf_json_sys_class_net(abuf, "misc", ifs->name, "wireless/misc");
1200 abuf_json_sys_class_net(abuf, "noiseLevel", ifs->name, "wireless/noise");
1201 abuf_json_sys_class_net(abuf, "nwid", ifs->name, "wireless/nwid");
1202 abuf_json_sys_class_net(abuf, "wirelessRetries", ifs->name, "wireless/retries");
1203 abuf_json_sys_class_net(abuf, "wirelessStatus", ifs->name, "wireless/status");
1204 #endif /* __linux__ */
1205 abuf_json_close_array_entry(abuf);
1207 abuf_json_close_array(abuf);
1212 ipc_print_olsrd_conf(struct autobuf *abuf)
1214 olsrd_write_cnf_autobuf(abuf, olsr_cnf);
1219 jsoninfo_write_data(void *foo __attribute__ ((unused)))
1222 int result, i, j, max;
1227 for (i=0; i<outbuffer_count; i++) {
1228 /* And we cast here since we get a warning on Win32 */
1229 FD_SET((unsigned int)(outbuffer_socket[i]), &set);
1231 if (outbuffer_socket[i] > max) {
1232 max = outbuffer_socket[i];
1239 result = select(max + 1, NULL, &set, NULL, &tv);
1244 for (i=0; i<outbuffer_count; i++) {
1245 if (FD_ISSET(outbuffer_socket[i], &set)) {
1246 result = send(outbuffer_socket[i],
1247 outbuffer[i] + outbuffer_written[i],
1248 outbuffer_size[i] - outbuffer_written[i],
1251 outbuffer_written[i] += result;
1254 if (result <= 0 || outbuffer_written[i] == outbuffer_size[i]) {
1255 /* close this socket and cleanup*/
1256 close(outbuffer_socket[i]);
1257 free (outbuffer[i]);
1259 for (j=i+1; j<outbuffer_count; j++) {
1260 outbuffer[j-1] = outbuffer[j];
1261 outbuffer_size[j-1] = outbuffer_size[j];
1262 outbuffer_socket[j-1] = outbuffer_socket[j];
1263 outbuffer_written[j-1] = outbuffer_written[j];
1269 if (outbuffer_count == 0) {
1270 olsr_stop_timer(writetimer_entry);
1275 send_info(unsigned int send_what, int the_socket)
1277 struct autobuf abuf;
1279 /* global variables for tracking when to put a comma in for JSON */
1281 currentjsondepth = 0;
1283 abuf_init(&abuf, 32768);
1285 // only add if outputing JSON
1286 if (send_what & SIW_ALL) abuf_puts(&abuf, "{");
1288 if ((send_what & SIW_LINKS) == SIW_LINKS) ipc_print_links(&abuf);
1289 if ((send_what & SIW_NEIGHBORS) == SIW_NEIGHBORS) ipc_print_neighbors(&abuf);
1290 if ((send_what & SIW_TOPOLOGY) == SIW_TOPOLOGY) ipc_print_topology(&abuf);
1291 if ((send_what & SIW_HNA) == SIW_HNA) ipc_print_hna(&abuf);
1292 if ((send_what & SIW_MID) == SIW_MID) ipc_print_mid(&abuf);
1293 if ((send_what & SIW_ROUTES) == SIW_ROUTES) ipc_print_routes(&abuf);
1294 if ((send_what & SIW_GATEWAYS) == SIW_GATEWAYS) ipc_print_gateways(&abuf);
1295 if ((send_what & SIW_INTERFACES) == SIW_INTERFACES) ipc_print_interfaces(&abuf);
1296 if ((send_what & SIW_CONFIG) == SIW_CONFIG) {
1297 if (send_what != SIW_CONFIG) abuf_puts(&abuf, ",");
1298 ipc_print_config(&abuf);
1300 if ((send_what & SIW_PLUGINS) == SIW_PLUGINS) ipc_print_plugins(&abuf);
1302 /* output overarching meta data last so we can use abuf_json_* functions, they add a comma at the beginning */
1303 if (send_what & SIW_ALL) {
1304 abuf_json_int(&abuf, "systemTime", time(NULL));
1305 abuf_json_int(&abuf, "timeSinceStartup", now_times);
1307 abuf_json_string(&abuf, "uuid", uuid);
1308 abuf_puts(&abuf, "}\n");
1311 /* this outputs the olsrd.conf text directly, not JSON */
1312 if ((send_what & SIW_OLSRD_CONF) == SIW_OLSRD_CONF) {
1313 ipc_print_olsrd_conf(&abuf);
1316 outbuffer[outbuffer_count] = olsr_malloc(abuf.len, "txt output buffer");
1317 outbuffer_size[outbuffer_count] = abuf.len;
1318 outbuffer_written[outbuffer_count] = 0;
1319 outbuffer_socket[outbuffer_count] = the_socket;
1321 memcpy(outbuffer[outbuffer_count], abuf.buf, abuf.len);
1324 if (outbuffer_count == 1) {
1325 writetimer_entry = olsr_start_timer(100,
1327 OLSR_TIMER_PERIODIC,
1328 &jsoninfo_write_data,
1341 * indent-tabs-mode: nil