jsoninfo / sgw: isGwSelectable function is common, use it as such
[olsrd.git] / lib / jsoninfo / src / olsrd_jsoninfo.c
1 /*
2  * The olsr.org Optimized Link-State Routing daemon(olsrd)
3  * Copyright (c) 2004
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  *   notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  *   notice, this list of conditions and the following disclaimer in
15  *   the documentation and/or other materials provided with the
16  *   distribution.
17  * * Neither the name of olsr.org, olsrd nor the names of its
18  *   contributors may be used to endorse or promote products derived
19  *   from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Visit http://www.olsr.org for more information.
35  *
36  * If you find this software useful feel free to make a donation
37  * to the project. For more information see the website or contact
38  * the copyright holders.
39  *
40  */
41
42 #include "olsrd_jsoninfo.h"
43
44 #include <unistd.h>
45 #include <ctype.h>
46 #include <libgen.h>
47
48 #include "ipcalc.h"
49 #include "builddata.h"
50 #include "neighbor_table.h"
51 #include "mpr_selector_set.h"
52 #include "routing_table.h"
53 #include "mid_set.h"
54 #include "gateway.h"
55 #include "egressTypes.h"
56 #include "olsrd_jsoninfo_helpers.h"
57 #include "olsrd_plugin.h"
58 #include "../../info/info_types.h"
59 #include "gateway_default_handler.h"
60
61 struct timeval start_time;
62
63 void plugin_init(const char *plugin_name) {
64   /* Get start time */
65   gettimeofday(&start_time, NULL);
66
67   if (!strlen(uuidfile))
68     strscpy(uuidfile, "uuid.txt", sizeof(uuidfile));
69   read_uuid_from_file(plugin_name, uuidfile);
70 }
71
72 bool isCommand(const char *str, unsigned int siw) {
73   const char * cmd;
74   switch (siw) {
75     case SIW_OLSRD_CONF:
76       cmd = "/olsrd.conf";
77       break;
78
79     case SIW_ALL:
80       cmd = "/all";
81       break;
82
83     case SIW_RUNTIME_ALL:
84       cmd = "/runtime";
85       break;
86
87     case SIW_STARTUP_ALL:
88       cmd = "/startup";
89       break;
90
91     case SIW_NEIGHBORS:
92       cmd = "/neighbors";
93       break;
94
95     case SIW_LINKS:
96       cmd = "/links";
97       break;
98
99     case SIW_ROUTES:
100       cmd = "/routes";
101       break;
102
103     case SIW_HNA:
104       cmd = "/hna";
105       break;
106
107     case SIW_MID:
108       cmd = "/mid";
109       break;
110
111     case SIW_TOPOLOGY:
112       cmd = "/topology";
113       break;
114
115     case SIW_GATEWAYS:
116       cmd = "/gateways";
117       break;
118
119     case SIW_INTERFACES:
120       cmd = "/interfaces";
121       break;
122
123     case SIW_2HOP:
124       cmd = "/2hop";
125       break;
126
127     case SIW_SGW:
128       cmd = "/sgw";
129       break;
130
131     case SIW_VERSION:
132       cmd = "/version";
133       break;
134
135     case SIW_CONFIG:
136       cmd = "/config";
137       break;
138
139     case SIW_PLUGINS:
140       cmd = "/plugins";
141       break;
142
143     case SIW_NEIGHBORS_FREIFUNK:
144       cmd = "/neighbours";
145       break;
146
147     default:
148       return false;
149   }
150
151   return !strcmp(str, cmd);
152 }
153
154 const char * determine_mime_type(unsigned int send_what) {
155   return (send_what & SIW_ALL) ? "application/json; charset=utf-8" : "text/plain; charset=utf-8";
156 }
157
158 void output_start(struct autobuf *abuf) {
159   /* global variables for tracking when to put a comma in for JSON */
160   abuf_json_reset_entry_number_and_depth();
161   abuf_json_mark_output(true, abuf);
162
163   abuf_json_int(abuf, "systemTime", time(NULL));
164   abuf_json_int(abuf, "timeSinceStartup", now_times);
165   if (*uuid)
166     abuf_json_string(abuf, "uuid", uuid);
167 }
168
169 void output_end(struct autobuf *abuf) {
170   abuf_json_mark_output(false, abuf);
171   abuf_puts(abuf, "\n");
172 }
173
174 static void ipc_print_neighbors_internal(struct autobuf *abuf, bool list_2hop) {
175   struct ipaddr_str buf1, buf2;
176   struct neighbor_entry *neigh;
177   struct neighbor_2_list_entry *list_2;
178
179   if (!list_2hop)
180     abuf_json_mark_object(true, true, abuf, "neighbors");
181   else
182     abuf_json_mark_object(true, true, abuf, "2hop");
183
184   /* Neighbors */
185   OLSR_FOR_ALL_NBR_ENTRIES(neigh)
186       {
187         abuf_json_mark_array_entry(true, abuf);
188
189         abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&buf1, &neigh->neighbor_main_addr));
190         abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
191         abuf_json_int(abuf, "willingness", neigh->willingness);
192         abuf_json_boolean(abuf, "isMultiPointRelay", neigh->is_mpr);
193         abuf_json_boolean(abuf, "wasMultiPointRelay", neigh->was_mpr);
194         abuf_json_boolean(abuf, "multiPointRelaySelector", olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
195         abuf_json_boolean(abuf, "skip", neigh->skip);
196         abuf_json_int(abuf, "neighbor2nocov", neigh->neighbor_2_nocov);
197         abuf_json_int(abuf, "linkcount", neigh->linkcount);
198
199         if (!list_2hop) {
200           int thop_cnt = 0;
201           for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
202             thop_cnt++;
203           }
204           abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
205         } else {
206           abuf_json_mark_object(true, true, abuf, "twoHopNeighbors");
207           for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
208             abuf_json_mark_array_entry(true, abuf);
209             abuf_json_string(abuf, "ipAddress", list_2->neighbor_2 ? olsr_ip_to_string(&buf2, &list_2->neighbor_2->neighbor_2_addr) : "");
210             abuf_json_mark_array_entry(false, abuf);
211           }
212           abuf_json_mark_object(false, true, abuf, false);
213         }
214
215         abuf_json_mark_array_entry(false, abuf);
216       }OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
217   abuf_json_mark_object(false, true, abuf, NULL);
218 }
219
220 void ipc_print_neighbors(struct autobuf *abuf) {
221   ipc_print_neighbors_internal(abuf, false);
222 }
223
224 void ipc_print_links(struct autobuf *abuf) {
225   struct link_entry *my_link;
226
227   abuf_json_mark_object(true, true, abuf, "links");
228
229   OLSR_FOR_ALL_LINK_ENTRIES(my_link)
230       {
231         struct ipaddr_str localAddr;
232         struct ipaddr_str remoteAddr;
233         struct lqtextbuffer lqBuffer;
234         const char* lqString = get_link_entry_text(my_link, '\t', &lqBuffer);
235         char * nlqString = strrchr(lqString, '\t');
236
237         if (nlqString) {
238           *nlqString = '\0';
239           nlqString++;
240         }
241
242         abuf_json_mark_array_entry(true, abuf);
243
244         abuf_json_string(abuf, "localIP", olsr_ip_to_string(&localAddr, &my_link->local_iface_addr));
245         abuf_json_string(abuf, "remoteIP", olsr_ip_to_string(&remoteAddr, &my_link->neighbor_iface_addr));
246         abuf_json_string(abuf, "olsrInterface", (my_link->inter && my_link->inter->int_name) ? my_link->inter->int_name : "");
247         abuf_json_string(abuf, "ifName", my_link->if_name ? my_link->if_name : "");
248         abuf_json_int(abuf, "validityTime", my_link->link_timer ? (long) (my_link->link_timer->timer_clock - now_times) : 0);
249         abuf_json_int(abuf, "symmetryTime", my_link->link_sym_timer ? (long) (my_link->link_sym_timer->timer_clock - now_times) : 0);
250         abuf_json_int(abuf, "asymmetryTime", my_link->ASYM_time);
251         abuf_json_int(abuf, "vtime", (long) my_link->vtime);
252         // neighbor (no need to print, can be looked up via neighbours)
253         abuf_json_string(abuf, "currentLinkStatus", linkTypeToString(lookup_link_status(my_link)));
254         abuf_json_string(abuf, "previousLinkStatus", linkTypeToString(my_link->prev_status));
255
256         abuf_json_float(abuf, "linkQuality", atof(lqString));
257         abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
258         abuf_json_boolean(abuf, "pending", my_link->L_link_pending != 0);
259         abuf_json_int(abuf, "lostLinkTime", (long) my_link->L_LOST_LINK_time);
260         abuf_json_int(abuf, "helloTime", my_link->link_hello_timer ? (long) (my_link->link_hello_timer->timer_clock - now_times) : 0);
261         abuf_json_int(abuf, "lastHelloTime", (long) my_link->last_htime);
262         abuf_json_boolean(abuf, "seqnoValid", my_link->olsr_seqno_valid);
263         abuf_json_int(abuf, "seqno", my_link->olsr_seqno);
264
265         abuf_json_int(abuf, "lossHelloInterval", (long) my_link->loss_helloint);
266         abuf_json_int(abuf, "lossTime", my_link->link_loss_timer ? (long) (my_link->link_loss_timer->timer_clock - now_times) : 0);
267
268         abuf_json_int(abuf, "lossMultiplier", (long) my_link->loss_link_multiplier);
269
270         abuf_json_int(abuf, "linkCost", MIN(my_link->linkcost, LINK_COST_BROKEN));
271
272         abuf_json_mark_array_entry(false, abuf);
273       }OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
274   abuf_json_mark_object(false, true, abuf, NULL);
275 }
276
277 void ipc_print_routes(struct autobuf *abuf) {
278   struct ipaddr_str buf1, buf2;
279   struct rt_entry *rt;
280
281   abuf_json_mark_object(true, true, abuf, "routes");
282
283   /* Walk the route table */
284   OLSR_FOR_ALL_RT_ENTRIES(rt)
285       {
286         abuf_json_mark_array_entry(true, abuf);
287         abuf_json_string(abuf, "destination", olsr_ip_to_string(&buf1, &rt->rt_dst.prefix));
288         abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
289         abuf_json_string(abuf, "gateway", olsr_ip_to_string(&buf2, &rt->rt_best->rtp_nexthop.gateway));
290         abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
291         if (rt->rt_best->rtp_metric.cost >= ROUTE_COST_BROKEN)
292           abuf_json_int(abuf, "rtpMetricCost", ROUTE_COST_BROKEN);
293         else
294           abuf_json_int(abuf, "rtpMetricCost", rt->rt_best->rtp_metric.cost);
295         abuf_json_string(abuf, "networkInterface", if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
296         abuf_json_mark_array_entry(false, abuf);
297       }OLSR_FOR_ALL_RT_ENTRIES_END(rt);
298
299   abuf_json_mark_object(false, true, abuf, NULL);
300 }
301
302 void ipc_print_topology(struct autobuf *abuf) {
303   struct tc_entry *tc;
304
305   abuf_json_mark_object(true, true, abuf, "topology");
306
307   /* Topology */
308   OLSR_FOR_ALL_TC_ENTRIES(tc)
309       {
310         struct tc_edge_entry *tc_edge;
311         OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge)
312             {
313               if (tc_edge->edge_inv) {
314                 struct ipaddr_str dstbuf, addrbuf;
315                 struct lqtextbuffer lqbuffer1;
316                 uint32_t vt = tc->validity_timer != NULL ? (tc->validity_timer->timer_clock - now_times) : 0;
317                 int diff = (int) (vt);
318                 const char* lqs;
319                 abuf_json_mark_array_entry(true, abuf);
320                 abuf_json_string(abuf, "destinationIP", olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr));
321                 abuf_json_string(abuf, "lastHopIP", olsr_ip_to_string(&addrbuf, &tc->addr));
322                 lqs = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer1);
323                 abuf_json_float(abuf, "linkQuality", atof(lqs));
324                 abuf_json_float(abuf, "neighborLinkQuality", atof(strrchr(lqs, '\t')));
325                 if (tc_edge->cost >= LINK_COST_BROKEN)
326                   abuf_json_int(abuf, "tcEdgeCost", LINK_COST_BROKEN);
327                 else
328                   abuf_json_int(abuf, "tcEdgeCost", tc_edge->cost);
329                 abuf_json_int(abuf, "validityTime", diff);
330                 abuf_json_mark_array_entry(false, abuf);
331               }
332             }OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
333       }OLSR_FOR_ALL_TC_ENTRIES_END(tc);
334
335   abuf_json_mark_object(false, true, abuf, NULL);
336 }
337
338 void ipc_print_hna(struct autobuf *abuf) {
339   struct ip_prefix_list *hna;
340   struct hna_entry *tmp_hna;
341
342   abuf_json_mark_object(true, true, abuf, "hna");
343
344   /* Announced HNA entries */
345   {
346     struct ipaddr_str mainaddrbuf;
347     struct ipaddr_str prefixbuf;
348
349     olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr);
350
351     for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
352       abuf_json_mark_array_entry(true, abuf);
353       abuf_json_string(abuf, "gateway", mainaddrbuf.buf);
354       abuf_json_string(abuf, "destination", olsr_ip_to_string(&prefixbuf, &hna->net.prefix));
355       abuf_json_int(abuf, "genmask", hna->net.prefix_len);
356       abuf_json_int(abuf, "validityTime", 0);
357       abuf_json_mark_array_entry(false, abuf);
358     }
359   }
360
361   OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna)
362         {
363           struct hna_net *tmp_net;
364
365           /* Check all networks */
366           for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
367             struct ipaddr_str mainaddrbuf;
368             struct ipaddr_str prefixbuf;
369             uint32_t vt = tmp_net->hna_net_timer ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0;
370
371             abuf_json_mark_array_entry(true, abuf);
372             abuf_json_string(abuf, "gateway", olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr));
373             abuf_json_string(abuf, "destination", olsr_ip_to_string(&prefixbuf, &tmp_net->hna_prefix.prefix));
374             abuf_json_int(abuf, "genmask", tmp_net->hna_prefix.prefix_len);
375             abuf_json_int(abuf, "validityTime", (long) vt);
376             abuf_json_mark_array_entry(false, abuf);
377           }
378         }OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
379
380   abuf_json_mark_object(false, true, abuf, NULL);
381 }
382
383 void ipc_print_mid(struct autobuf *abuf) {
384   int idx;
385   struct mid_entry *entry;
386   struct mid_address *alias;
387
388   abuf_json_mark_object(true, true, abuf, "mid");
389
390   /* MID */
391   for (idx = 0; idx < HASHSIZE; idx++) {
392     entry = mid_set[idx].next;
393
394     while (entry != &mid_set[idx]) {
395       struct ipaddr_str buf, buf2;
396       abuf_json_mark_array_entry(true, abuf);
397       abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&buf, &entry->main_addr));
398
399       abuf_json_mark_object(true, true, abuf, "aliases");
400       alias = entry->aliases;
401       while (alias) {
402         uint32_t vt = alias->vtime - now_times;
403         int diff = (int) (vt);
404
405         abuf_json_mark_array_entry(true, abuf);
406         abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&buf2, &alias->alias));
407         abuf_json_int(abuf, "validityTime", diff);
408         abuf_json_mark_array_entry(false, abuf);
409
410         alias = alias->next_alias;
411       }
412       abuf_json_mark_object(false, true, abuf, NULL); // aliases
413       abuf_json_mark_array_entry(false, abuf);
414       entry = entry->next;
415     }
416   }
417   abuf_json_mark_object(false, true, abuf, NULL); // mid
418 }
419
420 #ifdef __linux__
421
422 static void ipc_print_gateway_entry(struct autobuf *abuf, bool ipv6, struct gateway_entry * current_gw, struct gateway_entry * gw) {
423   struct tc_entry* tc = olsr_lookup_tc_entry(&gw->originator);
424
425   abuf_json_boolean(abuf, "selected", current_gw && (current_gw == gw));
426   abuf_json_boolean(abuf, "selectable", isGwSelectable(gw, ipv6));
427   abuf_json_ip_address(abuf, "originator", &gw->originator);
428   abuf_json_ip_address(abuf, "prefix", &gw->external_prefix.prefix);
429   abuf_json_int(abuf, "prefixLen", gw->external_prefix.prefix_len);
430   abuf_json_int(abuf, "uplink", gw->uplink);
431   abuf_json_int(abuf, "downlink", gw->downlink);
432   abuf_json_int(abuf, "pathcost", !tc ? ROUTE_COST_BROKEN : tc->path_cost);
433   abuf_json_boolean(abuf, "IPv4", gw->ipv4);
434   abuf_json_boolean(abuf, "IPv4-NAT", gw->ipv4nat);
435   abuf_json_boolean(abuf, "IPv6", gw->ipv6);
436   abuf_json_int(abuf, "cost", gw->path_cost);
437   abuf_json_int(abuf, "hops", !tc ? 0 : tc->hops);
438 }
439
440 static void ipc_print_gateways_ipvx(struct autobuf *abuf, bool ipv6) {
441   abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
442
443   if (olsr_cnf->smart_gw_active) {
444     struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
445     struct gateway_entry * gw;
446     OLSR_FOR_ALL_GATEWAY_ENTRIES(gw)
447         {
448           if (!(!ipv6 && gw->ipv4) && !(ipv6 && gw->ipv6)) {
449             continue;
450           }
451
452           abuf_json_mark_array_entry(true, abuf);
453           ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
454           abuf_json_mark_array_entry(false, abuf);
455         }OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
456   }
457
458   abuf_json_mark_object(false, true, abuf, NULL);
459 }
460 #endif /* __linux__ */
461
462 void ipc_print_gateways(struct autobuf *abuf) {
463 #ifndef __linux__
464   abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
465 #else /* __linux__ */
466   abuf_json_mark_object(true, false, abuf, "gateways");
467
468   ipc_print_gateways_ipvx(abuf, false);
469   ipc_print_gateways_ipvx(abuf, true);
470
471   abuf_json_mark_object(false, false, abuf, NULL);
472 #endif /* __linux__ */
473 }
474
475 #ifdef __linux__
476
477 /** interface names for smart gateway tunnel interfaces, IPv4 */
478 extern struct interfaceName * sgwTunnel4InterfaceNames;
479
480 /** interface names for smart gateway tunnel interfaces, IPv6 */
481 extern struct interfaceName * sgwTunnel6InterfaceNames;
482
483 /**
484  * Construct the sgw table for a given ip version
485  *
486  * @param abuf the string buffer
487  * @param ipv6 true for IPv6, false for IPv4
488  * @param fmtv the format for printing
489  */
490 static void sgw_ipvx(struct autobuf *abuf, bool ipv6) {
491   struct interfaceName * sgwTunnelInterfaceNames = !ipv6 ? sgwTunnel4InterfaceNames : sgwTunnel6InterfaceNames;
492
493   abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
494
495   if (olsr_cnf->smart_gw_active && sgwTunnelInterfaceNames) {
496     struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
497     int i;
498     for (i = 0; i < olsr_cnf->smart_gw_use_count; i++) {
499       struct interfaceName * node = &sgwTunnelInterfaceNames[i];
500       struct gateway_entry * gw = node->gw;
501
502       if (!gw) {
503         continue;
504       }
505
506       abuf_json_mark_array_entry(true, abuf);
507       ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
508       abuf_json_ip_address(abuf, "destination", &gw->originator);
509       abuf_json_string(abuf, "tunnel", node->name);
510       abuf_json_int(abuf, "tableNr", node->tableNr);
511       abuf_json_int(abuf, "ruleNr", node->ruleNr);
512       abuf_json_int(abuf, "bypassRuleNr", node->bypassRuleNr);
513       abuf_json_mark_array_entry(false, abuf);
514     }
515   }
516
517   abuf_json_mark_object(false, true, abuf, NULL);
518 }
519 #endif /* __linux__ */
520
521 void ipc_print_sgw(struct autobuf *abuf) {
522 #ifndef __linux__
523   abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
524 #else
525   abuf_json_mark_object(true, false, abuf, "sgw");
526
527   sgw_ipvx(abuf, false);
528   sgw_ipvx(abuf, true);
529
530   abuf_json_mark_object(false, false, abuf, NULL);
531 #endif /* __linux__ */
532 }
533
534 void ipc_print_version(struct autobuf *abuf) {
535   abuf_json_mark_object(true, false, abuf, "version");
536
537   abuf_json_string(abuf, "version", olsrd_version);
538   abuf_json_string(abuf, "date", build_date);
539   abuf_json_string(abuf, "host", build_host);
540
541   abuf_json_mark_object(false, false, abuf, NULL);
542 }
543
544 void ipc_print_olsrd_conf(struct autobuf *abuf) {
545   olsrd_write_cnf_autobuf(abuf, olsr_cnf);
546 }
547
548 void ipc_print_interfaces(struct autobuf *abuf) {
549 #ifdef __linux__
550   int linklen;
551   char path[PATH_MAX], linkpath[PATH_MAX];
552 #endif /* __linux__ */
553   char ipv6_buf[INET6_ADDRSTRLEN]; /* buffer for IPv6 inet_htop */
554   struct olsr_lq_mult *mult;
555   const struct olsr_if *ifs;
556   abuf_json_mark_object(true, true, abuf, "interfaces");
557   for (ifs = olsr_cnf->interfaces; ifs != NULL ; ifs = ifs->next) {
558     const struct interface_olsr * const rifs = ifs->interf;
559     abuf_json_mark_array_entry(true, abuf);
560     abuf_json_string(abuf, "name", ifs->name);
561
562     abuf_json_mark_object(true, true, abuf, "linkQualityMultipliers");
563     for (mult = ifs->cnf->lq_mult; mult != NULL ; mult = mult->next) {
564       abuf_json_mark_array_entry(true, abuf);
565       abuf_json_string(abuf, "route", inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
566       abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
567       abuf_json_mark_array_entry(false, abuf);
568     }
569     abuf_json_mark_object(false, true, abuf, NULL);
570
571     if (!rifs) {
572       abuf_json_string(abuf, "state", "down");
573     } else {
574       abuf_json_string(abuf, "state", "up");
575       abuf_json_string(abuf, "nameFromKernel", rifs->int_name);
576       abuf_json_int(abuf, "interfaceMode", rifs->mode);
577       abuf_json_boolean(abuf, "emulatedHostClientInterface", rifs->is_hcif);
578       abuf_json_boolean(abuf, "sendTcImmediately", rifs->immediate_send_tc);
579       abuf_json_int(abuf, "fishEyeTtlIndex", rifs->ttl_index);
580       abuf_json_int(abuf, "olsrForwardingTimeout", rifs->fwdtimer);
581       abuf_json_int(abuf, "olsrMessageSequenceNumber", rifs->olsr_seqnum);
582       abuf_json_int(abuf, "olsrInterfaceMetric", rifs->int_metric);
583       abuf_json_int(abuf, "olsrMTU", rifs->int_mtu);
584       abuf_json_int(abuf, "helloEmissionInterval", rifs->hello_etime);
585       abuf_json_int(abuf, "helloValidityTime", me_to_reltime(rifs->valtimes.hello));
586       abuf_json_int(abuf, "tcValidityTime", me_to_reltime(rifs->valtimes.tc));
587       abuf_json_int(abuf, "midValidityTime", me_to_reltime(rifs->valtimes.mid));
588       abuf_json_int(abuf, "hnaValidityTime", me_to_reltime(rifs->valtimes.hna));
589       abuf_json_boolean(abuf, "wireless", rifs->is_wireless);
590
591 #ifdef __linux__
592       abuf_json_boolean(abuf, "icmpRedirect", rifs->nic_state.redirect);
593       abuf_json_boolean(abuf, "spoofFilter", rifs->nic_state.spoof);
594 #endif /* __linux__ */
595
596       if (olsr_cnf->ip_version == AF_INET) {
597         struct ipaddr_str addrbuf, maskbuf, bcastbuf;
598         abuf_json_string(abuf, "ipv4Address", ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
599         abuf_json_string(abuf, "netmask", ip4_to_string(&maskbuf, rifs->int_netmask.sin_addr));
600         abuf_json_string(abuf, "broadcast", ip4_to_string(&bcastbuf, rifs->int_broadaddr.sin_addr));
601       } else {
602         struct ipaddr_str addrbuf, maskbuf;
603         abuf_json_string(abuf, "ipv6Address", ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
604         abuf_json_string(abuf, "multicast", ip6_to_string(&maskbuf, &rifs->int6_multaddr.sin6_addr));
605       }
606     }
607 #ifdef __linux__
608     snprintf(path, PATH_MAX, "/sys/class/net/%s/device/driver/module", ifs->name);
609     linklen = readlink(path, linkpath, PATH_MAX - 1);
610     if (linklen > 1) {
611       linkpath[linklen] = '\0';
612       abuf_json_string(abuf, "kernelModule", basename(linkpath));
613     }
614
615     abuf_json_sys_class_net(abuf, "addressLength", ifs->name, "addr_len");
616     abuf_json_sys_class_net(abuf, "carrier", ifs->name, "carrier");
617     abuf_json_sys_class_net(abuf, "dormant", ifs->name, "dormant");
618     abuf_json_sys_class_net(abuf, "features", ifs->name, "features");
619     abuf_json_sys_class_net(abuf, "flags", ifs->name, "flags");
620     abuf_json_sys_class_net(abuf, "linkMode", ifs->name, "link_mode");
621     abuf_json_sys_class_net(abuf, "macAddress", ifs->name, "address");
622     abuf_json_sys_class_net(abuf, "ethernetMTU", ifs->name, "mtu");
623     abuf_json_sys_class_net(abuf, "operationalState", ifs->name, "operstate");
624     abuf_json_sys_class_net(abuf, "txQueueLength", ifs->name, "tx_queue_len");
625     abuf_json_sys_class_net(abuf, "collisions", ifs->name, "statistics/collisions");
626     abuf_json_sys_class_net(abuf, "multicastPackets", ifs->name, "statistics/multicast");
627     abuf_json_sys_class_net(abuf, "rxBytes", ifs->name, "statistics/rx_bytes");
628     abuf_json_sys_class_net(abuf, "rxCompressed", ifs->name, "statistics/rx_compressed");
629     abuf_json_sys_class_net(abuf, "rxCrcErrors", ifs->name, "statistics/rx_crc_errors");
630     abuf_json_sys_class_net(abuf, "rxDropped", ifs->name, "statistics/rx_dropped");
631     abuf_json_sys_class_net(abuf, "rxErrors", ifs->name, "statistics/rx_errors");
632     abuf_json_sys_class_net(abuf, "rxFifoErrors", ifs->name, "statistics/rx_fifo_errors");
633     abuf_json_sys_class_net(abuf, "rxFrameErrors", ifs->name, "statistics/rx_frame_errors");
634     abuf_json_sys_class_net(abuf, "rxLengthErrors", ifs->name, "statistics/rx_length_errors");
635     abuf_json_sys_class_net(abuf, "rxMissedErrors", ifs->name, "statistics/rx_missed_errors");
636     abuf_json_sys_class_net(abuf, "rxOverErrors", ifs->name, "statistics/rx_over_errors");
637     abuf_json_sys_class_net(abuf, "rxPackets", ifs->name, "statistics/rx_packets");
638     abuf_json_sys_class_net(abuf, "txAbortedErrors", ifs->name, "statistics/tx_aborted_errors");
639     abuf_json_sys_class_net(abuf, "txBytes", ifs->name, "statistics/tx_bytes");
640     abuf_json_sys_class_net(abuf, "txCarrierErrors", ifs->name, "statistics/tx_carrier_errors");
641     abuf_json_sys_class_net(abuf, "txCompressed", ifs->name, "statistics/tx_compressed");
642     abuf_json_sys_class_net(abuf, "txDropped", ifs->name, "statistics/tx_dropped");
643     abuf_json_sys_class_net(abuf, "txErrors", ifs->name, "statistics/tx_errors");
644     abuf_json_sys_class_net(abuf, "txFifoErrors", ifs->name, "statistics/tx_fifo_errors");
645     abuf_json_sys_class_net(abuf, "txHeartbeatErrors", ifs->name, "statistics/tx_heartbeat_errors");
646     abuf_json_sys_class_net(abuf, "txPackets", ifs->name, "statistics/tx_packets");
647     abuf_json_sys_class_net(abuf, "txWindowErrors", ifs->name, "statistics/tx_window_errors");
648     abuf_json_sys_class_net(abuf, "beaconing", ifs->name, "wireless/beacon");
649     abuf_json_sys_class_net(abuf, "encryptionKey", ifs->name, "wireless/crypt");
650     abuf_json_sys_class_net(abuf, "fragmentationThreshold", ifs->name, "wireless/fragment");
651     abuf_json_sys_class_net(abuf, "signalLevel", ifs->name, "wireless/level");
652     abuf_json_sys_class_net(abuf, "linkQuality", ifs->name, "wireless/link");
653     abuf_json_sys_class_net(abuf, "misc", ifs->name, "wireless/misc");
654     abuf_json_sys_class_net(abuf, "noiseLevel", ifs->name, "wireless/noise");
655     abuf_json_sys_class_net(abuf, "nwid", ifs->name, "wireless/nwid");
656     abuf_json_sys_class_net(abuf, "wirelessRetries", ifs->name, "wireless/retries");
657     abuf_json_sys_class_net(abuf, "wirelessStatus", ifs->name, "wireless/status");
658 #endif /* __linux__ */
659     abuf_json_mark_array_entry(false, abuf);
660   }
661   abuf_json_mark_object(false, true, abuf, NULL);
662 }
663
664 void ipc_print_twohop(struct autobuf *abuf) {
665   ipc_print_neighbors_internal(abuf, true);
666 }
667
668 void ipc_print_config(struct autobuf *abuf) {
669   struct ip_prefix_list *hna;
670   struct ipaddr_str buf, mainaddrbuf;
671   struct ip_prefix_list *ipcn;
672   struct olsr_lq_mult *mult;
673   char ipv6_buf[INET6_ADDRSTRLEN]; /* buffer for IPv6 inet_htop */
674
675   abuf_json_mark_object(true, false, abuf, "config");
676
677   abuf_json_int(abuf, "olsrPort", olsr_cnf->olsrport);
678   abuf_json_int(abuf, "debugLevel", olsr_cnf->debug_level);
679   abuf_json_boolean(abuf, "noFork", olsr_cnf->no_fork);
680   abuf_json_boolean(abuf, "hostEmulation", olsr_cnf->host_emul);
681   abuf_json_int(abuf, "ipVersion", olsr_cnf->ip_version);
682   abuf_json_boolean(abuf, "allowNoInterfaces", olsr_cnf->allow_no_interfaces);
683   abuf_json_int(abuf, "typeOfService", olsr_cnf->tos);
684   abuf_json_int(abuf, "rtProto", olsr_cnf->rt_proto);
685   abuf_json_int(abuf, "rtTable", olsr_cnf->rt_table);
686   abuf_json_int(abuf, "rtTableDefault", olsr_cnf->rt_table_default);
687   abuf_json_int(abuf, "rtTableTunnel", olsr_cnf->rt_table_tunnel);
688   abuf_json_int(abuf, "rtTablePriority", olsr_cnf->rt_table_pri);
689   abuf_json_int(abuf, "rtTableTunnelPriority", olsr_cnf->rt_table_tunnel_pri);
690   abuf_json_int(abuf, "rtTableDefauiltOlsrPriority", olsr_cnf->rt_table_defaultolsr_pri);
691   abuf_json_int(abuf, "rtTableDefaultPriority", olsr_cnf->rt_table_default_pri);
692   abuf_json_int(abuf, "willingness", olsr_cnf->willingness);
693   abuf_json_boolean(abuf, "willingnessAuto", olsr_cnf->willingness_auto);
694
695   abuf_json_int(abuf, "brokenLinkCost", LINK_COST_BROKEN);
696   abuf_json_int(abuf, "brokenRouteCost", ROUTE_COST_BROKEN);
697
698   abuf_json_string(abuf, "fibMetrics", FIB_METRIC_TXT[olsr_cnf->fib_metric]);
699
700   abuf_json_string(abuf, "defaultIpv6Multicast", inet_ntop(AF_INET6, &olsr_cnf->interface_defaults->ipv6_multicast.v6, ipv6_buf, sizeof(ipv6_buf)));
701   if (olsr_cnf->interface_defaults->ipv4_multicast.v4.s_addr)
702     abuf_json_string(abuf, "defaultIpv4Broadcast", inet_ntoa(olsr_cnf->interface_defaults->ipv4_multicast.v4));
703   else
704     abuf_json_string(abuf, "defaultIpv4Broadcast", "auto");
705
706   if (olsr_cnf->interface_defaults->mode == IF_MODE_ETHER)
707     abuf_json_string(abuf, "defaultInterfaceMode", "ether");
708   else
709     abuf_json_string(abuf, "defaultInterfaceMode", "mesh");
710
711   abuf_json_float(abuf, "defaultHelloEmissionInterval", olsr_cnf->interface_defaults->hello_params.emission_interval);
712   abuf_json_float(abuf, "defaultHelloValidityTime", olsr_cnf->interface_defaults->hello_params.validity_time);
713   abuf_json_float(abuf, "defaultTcEmissionInterval", olsr_cnf->interface_defaults->tc_params.emission_interval);
714   abuf_json_float(abuf, "defaultTcValidityTime", olsr_cnf->interface_defaults->tc_params.validity_time);
715   abuf_json_float(abuf, "defaultMidEmissionInterval", olsr_cnf->interface_defaults->mid_params.emission_interval);
716   abuf_json_float(abuf, "defaultMidValidityTime", olsr_cnf->interface_defaults->mid_params.validity_time);
717   abuf_json_float(abuf, "defaultHnaEmissionInterval", olsr_cnf->interface_defaults->hna_params.emission_interval);
718   abuf_json_float(abuf, "defaultHnaValidityTime", olsr_cnf->interface_defaults->hna_params.validity_time);
719   abuf_json_boolean(abuf, "defaultAutoDetectChanges", olsr_cnf->interface_defaults->autodetect_chg);
720
721   abuf_json_mark_object(true, true, abuf, "defaultLinkQualityMultipliers");
722   for (mult = olsr_cnf->interface_defaults->lq_mult; mult != NULL ; mult = mult->next) {
723     abuf_json_mark_array_entry(true, abuf);
724     abuf_json_string(abuf, "route", inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
725     abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
726     abuf_json_mark_array_entry(false, abuf);
727   }
728   abuf_json_mark_object(false, true, abuf, NULL);
729
730   abuf_json_mark_object(true, true, abuf, "hna");
731   for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
732     abuf_json_mark_array_entry(true, abuf);
733     abuf_json_string(abuf, "destination", olsr_ip_to_string(&buf, &hna->net.prefix));
734     abuf_json_int(abuf, "genmask", hna->net.prefix_len);
735     abuf_json_string(abuf, "gateway", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
736     abuf_json_mark_array_entry(false, abuf);
737   }
738   abuf_json_mark_object(false, true, abuf, NULL);
739
740   abuf_json_int(abuf, "totalIpcConnectionsAllowed", olsr_cnf->ipc_connections);
741   abuf_json_mark_object(true, true, abuf, "ipcAllowedAddresses");
742   if (olsr_cnf->ipc_connections) {
743     for (ipcn = olsr_cnf->ipc_nets; ipcn != NULL ; ipcn = ipcn->next) {
744       abuf_json_mark_array_entry(true, abuf);
745       abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&mainaddrbuf, &ipcn->net.prefix));
746       abuf_json_int(abuf, "netmask", ipcn->net.prefix_len);
747       abuf_json_mark_array_entry(false, abuf);
748     }
749   }
750   abuf_json_mark_object(false, true, abuf, NULL);
751
752   // keep all time in ms, so convert these two, which are in seconds
753   abuf_json_int(abuf, "pollRate", olsr_cnf->pollrate * 1000);
754   abuf_json_int(abuf, "nicChangePollInterval", olsr_cnf->nic_chgs_pollrate * 1000);
755   abuf_json_boolean(abuf, "clearScreen", olsr_cnf->clear_screen);
756   abuf_json_int(abuf, "tcRedundancy", olsr_cnf->tc_redundancy);
757   abuf_json_int(abuf, "mprCoverage", olsr_cnf->mpr_coverage);
758
759   if (!olsr_cnf->lq_level) {
760     abuf_json_boolean(abuf, "useHysteresis", olsr_cnf->use_hysteresis);
761     if (olsr_cnf->use_hysteresis) {
762       abuf_json_float(abuf, "hysteresisScaling", olsr_cnf->hysteresis_param.scaling);
763       abuf_json_float(abuf, "hysteresisLowThreshold", olsr_cnf->hysteresis_param.thr_low);
764       abuf_json_float(abuf, "hysteresisHighThreshold", olsr_cnf->hysteresis_param.thr_high);
765     }
766   }
767   abuf_json_int(abuf, "linkQualityLevel", olsr_cnf->lq_level);
768   abuf_json_float(abuf, "linkQualityAging", olsr_cnf->lq_aging);
769   abuf_json_boolean(abuf, "linkQualityFisheye", olsr_cnf->lq_fish);
770   abuf_json_string(abuf, "linkQualityAlgorithm", olsr_cnf->lq_algorithm);
771   // keep all time in ms, so convert this from seconds
772   abuf_json_int(abuf, "minTcValidTime", olsr_cnf->min_tc_vtime * 1000);
773   abuf_json_boolean(abuf, "setIpForward", olsr_cnf->set_ip_forward);
774   abuf_json_string(abuf, "lockFile", olsr_cnf->lock_file);
775   abuf_json_boolean(abuf, "useNiit", olsr_cnf->use_niit);
776
777 #ifdef __linux__
778   abuf_json_boolean(abuf, "smartGateway", olsr_cnf->smart_gw_active);
779   if (olsr_cnf->smart_gw_active) {
780     abuf_json_boolean(abuf, "smartGatewayAlwaysRemoveServerTunnel", olsr_cnf->smart_gw_always_remove_server_tunnel);
781     abuf_json_int(abuf, "smartGatewayUseCount", olsr_cnf->smart_gw_use_count);
782     abuf_json_string(abuf, "smartGatewayInstanceId", olsr_cnf->smart_gw_instance_id);
783     abuf_json_string(abuf, "smartGatewayPolicyRoutingScript", olsr_cnf->smart_gw_policyrouting_script);
784     {
785       struct autobuf egressbuf;
786       struct sgw_egress_if * egressif = olsr_cnf->smart_gw_egress_interfaces;
787
788       abuf_init(&egressbuf, (olsr_cnf->smart_gw_egress_interfaces_count * IFNAMSIZ) /* interface names */
789       + (olsr_cnf->smart_gw_egress_interfaces_count - 1) /* commas */);
790       while (egressif) {
791         if (egressbuf.len) {
792           abuf_puts(&egressbuf, ",");
793         }
794         abuf_appendf(&egressbuf, "%s", egressif->name);
795         egressif = egressif->next;
796       }
797       abuf_json_string(abuf, "smartGatewayEgressInterfaces", egressbuf.buf);
798       abuf_free(&egressbuf);
799     }
800     abuf_json_int(abuf, "smartGatewayTablesOffset", olsr_cnf->smart_gw_offset_tables);
801     abuf_json_int(abuf, "smartGatewayRulesOffset", olsr_cnf->smart_gw_offset_rules);
802     abuf_json_boolean(abuf, "smartGatewayAllowNat", olsr_cnf->smart_gw_allow_nat);
803     abuf_json_boolean(abuf, "smartGatewayUplinkNat", olsr_cnf->smart_gw_uplink_nat);
804     abuf_json_int(abuf, "smartGatewayPeriod", olsr_cnf->smart_gw_period);
805     abuf_json_int(abuf, "smartGatewayStableCount", olsr_cnf->smart_gw_stablecount);
806     abuf_json_int(abuf, "smartGatewayThreshold", olsr_cnf->smart_gw_thresh);
807     abuf_json_int(abuf, "smartGatewayUplink", olsr_cnf->smart_gw_uplink);
808     abuf_json_int(abuf, "smartGatewayDownlink", olsr_cnf->smart_gw_downlink);
809     abuf_json_int(abuf, "smartGatewayType", olsr_cnf->smart_gw_type);
810     abuf_json_string(abuf, "smartGatewayPrefix", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->smart_gw_prefix.prefix));
811     abuf_json_int(abuf, "smartGatewayPrefixLength", olsr_cnf->smart_gw_prefix.prefix_len);
812   }
813 #endif /* __linux__ */
814
815   abuf_json_string(abuf, "mainIpAddress", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
816   abuf_json_string(abuf, "unicastSourceIpAddress", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->unicast_src_ip));
817
818   abuf_json_boolean(abuf, "useSourceIpRoutes", olsr_cnf->use_src_ip_routes);
819
820   abuf_json_int(abuf, "maxPrefixLength", olsr_cnf->maxplen);
821   abuf_json_int(abuf, "ipSize", olsr_cnf->ipsize);
822   abuf_json_boolean(abuf, "deleteInternetGatewaysAtStartup", olsr_cnf->del_gws);
823   // keep all time in ms, so convert this from seconds
824   abuf_json_int(abuf, "willingnessUpdateInterval", olsr_cnf->will_int * 1000);
825   abuf_json_float(abuf, "maxSendMessageJitter", olsr_cnf->max_jitter);
826   abuf_json_int(abuf, "exitValue", olsr_cnf->exit_value);
827   // keep all time in ms, so convert this from seconds
828   abuf_json_int(abuf, "maxTcValidTime", olsr_cnf->max_tc_vtime * 1000);
829
830   abuf_json_int(abuf, "niit4to6InterfaceIndex", olsr_cnf->niit4to6_if_index);
831   abuf_json_int(abuf, "niit6to4InterfaceIndex", olsr_cnf->niit6to4_if_index);
832
833   abuf_json_boolean(abuf, "hasIpv4Gateway", olsr_cnf->has_ipv4_gateway);
834   abuf_json_boolean(abuf, "hasIpv6Gateway", olsr_cnf->has_ipv6_gateway);
835
836   abuf_json_int(abuf, "ioctlSocket", olsr_cnf->ioctl_s);
837 #ifdef __linux__
838   abuf_json_int(abuf, "routeNetlinkSocket", olsr_cnf->rtnl_s);
839   abuf_json_int(abuf, "routeMonitorSocket", olsr_cnf->rt_monitor_socket);
840 #endif /* __linux__ */
841
842 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
843   abuf_json_int(abuf, "routeChangeSocket", olsr_cnf->rts);
844 #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ */
845   abuf_json_float(abuf, "linkQualityNatThreshold", olsr_cnf->lq_nat_thresh);
846
847   abuf_json_string(abuf, "olsrdVersion", olsrd_version);
848   abuf_json_string(abuf, "olsrdBuildDate", build_date);
849   abuf_json_string(abuf, "olsrdBuildHost", build_host);
850
851 #if defined _WIN32 || defined _WIN64
852   abuf_json_string(abuf, "os", "Windows");
853 #elif defined __gnu_linux__
854   abuf_json_string(abuf, "os", "GNU/Linux");
855 #elif defined __ANDROID__
856   abuf_json_string(abuf, "os", "Android");
857 #elif defined __APPLE__
858   abuf_json_string(abuf, "os", "Mac OS X");
859 #elif defined __NetBSD__
860   abuf_json_string(abuf, "os", "NetBSD");
861 #elif defined __OpenBSD__
862   abuf_json_string(abuf, "os", "OpenBSD");
863 #elif defined __FreeBSD__ || defined __FreeBSD_kernel__
864   abuf_json_string(abuf, "os", "FreeBSD");
865 #else /* OS detection */
866   abuf_json_string(abuf, "os", "Undefined");
867 #endif /* OS detection */
868
869   abuf_json_int(abuf, "startTime", start_time.tv_sec);
870
871   abuf_json_mark_object(false, false, abuf, NULL);
872 }
873
874 void ipc_print_plugins(struct autobuf *abuf) {
875   struct plugin_entry *pentry;
876   struct plugin_param *pparam;
877   abuf_json_mark_object(true, true, abuf, "plugins");
878   if (olsr_cnf->plugins)
879     for (pentry = olsr_cnf->plugins; pentry; pentry = pentry->next) {
880       abuf_json_mark_array_entry(true, abuf);
881       abuf_json_string(abuf, "plugin", pentry->name);
882       for (pparam = pentry->params; pparam; pparam = pparam->next) {
883         int i, keylen = strlen(pparam->key);
884         char key[keylen + 1];
885         long value;
886         char valueTest[256];
887         strcpy(key, pparam->key);
888         for (i = 0; i < keylen; i++)
889           key[i] = tolower(key[i]);
890
891         // test if a int/long and set as such in JSON
892         value = atol(pparam->value);
893         snprintf(valueTest, 255, "%li", value);
894         if (!strcmp(valueTest, pparam->value))
895           abuf_json_int(abuf, key, value);
896         else
897           abuf_json_string(abuf, key, pparam->value);
898       }
899       abuf_json_mark_array_entry(false, abuf);
900     }
901   abuf_json_mark_object(false, true, abuf, NULL);
902 }