jsoninfo: use print_link_quality_multipliers_array_entry in /interfaces
[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 "mid_set.h"
53 #include "routing_table.h"
54 #include "lq_plugin.h"
55 #include "gateway.h"
56 #include "olsrd_plugin.h"
57 #include "../../info/info_types.h"
58 #include "../../info/http_headers.h"
59 #include "gateway_default_handler.h"
60 #include "egressTypes.h"
61 #include "olsrd_jsoninfo_helpers.h"
62
63 static void print_link_quality_multipliers_array_entry(struct autobuf *abuf, struct olsr_lq_mult *mult);
64
65 struct timeval start_time;
66
67 void plugin_init(const char *plugin_name) {
68   /* Get start time */
69   gettimeofday(&start_time, NULL);
70
71   if (!strlen(uuidfile)) {
72     strscpy(uuidfile, "uuid.txt", sizeof(uuidfile));
73   }
74   read_uuid_from_file(plugin_name, uuidfile);
75 }
76
77 bool isCommand(const char *str, unsigned int siw) {
78   const char * cmd;
79   switch (siw) {
80     case SIW_OLSRD_CONF:
81       cmd = "/olsrd.conf";
82       break;
83
84     case SIW_ALL:
85       cmd = "/all";
86       break;
87
88     case SIW_RUNTIME_ALL:
89       cmd = "/runtime";
90       break;
91
92     case SIW_STARTUP_ALL:
93       cmd = "/startup";
94       break;
95
96     case SIW_NEIGHBORS:
97       cmd = "/neighbors";
98       break;
99
100     case SIW_LINKS:
101       cmd = "/links";
102       break;
103
104     case SIW_ROUTES:
105       cmd = "/routes";
106       break;
107
108     case SIW_HNA:
109       cmd = "/hna";
110       break;
111
112     case SIW_MID:
113       cmd = "/mid";
114       break;
115
116     case SIW_TOPOLOGY:
117       cmd = "/topology";
118       break;
119
120     case SIW_GATEWAYS:
121       cmd = "/gateways";
122       break;
123
124     case SIW_INTERFACES:
125       cmd = "/interfaces";
126       break;
127
128     case SIW_2HOP:
129       cmd = "/2hop";
130       break;
131
132     case SIW_SGW:
133       cmd = "/sgw";
134       break;
135
136     case SIW_VERSION:
137       cmd = "/version";
138       break;
139
140     case SIW_CONFIG:
141       cmd = "/config";
142       break;
143
144     case SIW_PLUGINS:
145       cmd = "/plugins";
146       break;
147
148     case SIW_NEIGHBORS_FREIFUNK:
149       cmd = "/neighbours";
150       break;
151
152     default:
153       return false;
154   }
155
156   return !strcmp(str, cmd);
157 }
158
159 const char * determine_mime_type(unsigned int send_what) {
160   return (send_what & SIW_OLSRD_CONF) ? "text/plain; charset=utf-8" : "application/json; charset=utf-8";
161 }
162
163 void output_start(struct autobuf *abuf) {
164   /* global variables for tracking when to put a comma in for JSON */
165   abuf_json_reset_entry_number_and_depth();
166   abuf_json_mark_output(true, abuf);
167
168   abuf_json_int(abuf, "systemTime", time(NULL));
169   abuf_json_int(abuf, "timeSinceStartup", now_times);
170   if (*uuid) {
171     abuf_json_string(abuf, "uuid", uuid);
172   }
173 }
174
175 void output_end(struct autobuf *abuf) {
176   abuf_json_mark_output(false, abuf);
177   abuf_puts(abuf, "\n");
178 }
179
180 void output_error(struct autobuf *abuf, unsigned int status, const char * req, bool http_headers) {
181   struct autobuf abufInternal;
182
183   if (http_headers || (status == INFO_HTTP_OK)) {
184     return;
185   }
186
187   abuf_init(&abufInternal, 1024);
188
189   output_start(abuf);
190
191   switch (status) {
192     case INFO_HTTP_NOTFOUND:
193       abuf_appendf(&abufInternal, "Invalid request '%s'", req);
194       abuf_json_string(abuf, "error", abufInternal.buf);
195       break;
196
197     case INFO_HTTP_NOCONTENT:
198       abuf_json_string(abuf, "error", "no content");
199       break;
200
201     default:
202       abuf_appendf(&abufInternal, "Unknown status %d for request '%s'", status, req);
203       abuf_json_string(abuf, "error", abufInternal.buf);
204       break;
205   }
206
207   output_end(abuf);
208 }
209
210 static void ipc_print_neighbors_internal(struct autobuf *abuf, bool list_2hop) {
211   struct neighbor_entry *neigh;
212
213   if (!list_2hop) {
214     abuf_json_mark_object(true, true, abuf, "neighbors");
215   } else {
216     abuf_json_mark_object(true, true, abuf, "2hop");
217   }
218
219   /* Neighbors */
220   OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
221     struct neighbor_2_list_entry *list_2;
222     int thop_cnt = 0;
223
224     abuf_json_mark_array_entry(true, abuf);
225
226     abuf_json_ip_address(abuf, "ipAddress", &neigh->neighbor_main_addr);
227     abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
228     abuf_json_int(abuf, "willingness", neigh->willingness);
229     abuf_json_boolean(abuf, "isMultiPointRelay", neigh->is_mpr);
230     abuf_json_boolean(abuf, "wasMultiPointRelay", neigh->was_mpr);
231     abuf_json_boolean(abuf, "multiPointRelaySelector", olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
232     abuf_json_boolean(abuf, "skip", neigh->skip);
233     abuf_json_int(abuf, "neighbor2nocov", neigh->neighbor_2_nocov);
234     abuf_json_int(abuf, "linkcount", neigh->linkcount);
235
236     if (list_2hop) {
237       abuf_json_mark_object(true, true, abuf, "twoHopNeighbors");
238     }
239
240     thop_cnt = 0;
241     for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
242       if (list_2hop && list_2->neighbor_2) {
243         abuf_json_mark_array_entry(true, abuf);
244         abuf_json_ip_address(abuf, "ipAddress", list_2->neighbor_2 ? &list_2->neighbor_2->neighbor_2_addr : NULL);
245         abuf_json_mark_array_entry(false, abuf);
246       }
247       thop_cnt++;
248     }
249
250     if (list_2hop) {
251       abuf_json_mark_object(false, true, abuf, NULL);
252     }
253     abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
254
255     abuf_json_mark_array_entry(false, abuf);
256   } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
257   abuf_json_mark_object(false, true, abuf, NULL);
258 }
259
260 void ipc_print_neighbors(struct autobuf *abuf) {
261   ipc_print_neighbors_internal(abuf, false);
262 }
263
264 void ipc_print_links(struct autobuf *abuf) {
265   struct link_entry *my_link;
266
267   abuf_json_mark_object(true, true, abuf, "links");
268
269   OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
270     struct lqtextbuffer lqBuffer;
271     const char* lqString = get_link_entry_text(my_link, '\t', &lqBuffer);
272     char * nlqString = strrchr(lqString, '\t');
273
274     if (nlqString) {
275       *nlqString = '\0';
276       nlqString++;
277     }
278
279     abuf_json_mark_array_entry(true, abuf);
280
281     abuf_json_ip_address(abuf, "localIP", &my_link->local_iface_addr);
282     abuf_json_ip_address(abuf, "remoteIP", &my_link->neighbor_iface_addr);
283     abuf_json_string(abuf, "olsrInterface", (my_link->inter && my_link->inter->int_name) ? my_link->inter->int_name : "");
284     abuf_json_string(abuf, "ifName", my_link->if_name ? my_link->if_name : "");
285     abuf_json_int(abuf, "validityTime", my_link->link_timer ? (long) (my_link->link_timer->timer_clock - now_times) : 0);
286     abuf_json_int(abuf, "symmetryTime", my_link->link_sym_timer ? (long) (my_link->link_sym_timer->timer_clock - now_times) : 0);
287     abuf_json_int(abuf, "asymmetryTime", my_link->ASYM_time);
288     abuf_json_int(abuf, "vtime", (long) my_link->vtime);
289     // neighbor (no need to print, can be looked up via neighbours)
290     abuf_json_string(abuf, "currentLinkStatus", linkTypeToString(lookup_link_status(my_link)));
291     abuf_json_string(abuf, "previousLinkStatus", linkTypeToString(my_link->prev_status));
292
293     abuf_json_float(abuf, "hysteresis", my_link->L_link_quality);
294     abuf_json_boolean(abuf, "pending", my_link->L_link_pending != 0);
295     abuf_json_int(abuf, "lostLinkTime", (long) my_link->L_LOST_LINK_time);
296     abuf_json_int(abuf, "helloTime", my_link->link_hello_timer ? (long) (my_link->link_hello_timer->timer_clock - now_times) : 0);
297     abuf_json_int(abuf, "lastHelloTime", (long) my_link->last_htime);
298     abuf_json_boolean(abuf, "seqnoValid", my_link->olsr_seqno_valid);
299     abuf_json_int(abuf, "seqno", my_link->olsr_seqno);
300
301     abuf_json_int(abuf, "lossHelloInterval", (long) my_link->loss_helloint);
302     abuf_json_int(abuf, "lossTime", my_link->link_loss_timer ? (long) (my_link->link_loss_timer->timer_clock - now_times) : 0);
303
304     abuf_json_int(abuf, "lossMultiplier", (long) my_link->loss_link_multiplier);
305
306     abuf_json_int(abuf, "linkCost", MIN(my_link->linkcost, LINK_COST_BROKEN));
307
308     abuf_json_float(abuf, "linkQuality", atof(lqString));
309     abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
310
311     abuf_json_mark_array_entry(false, abuf);
312   } OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
313   abuf_json_mark_object(false, true, abuf, NULL);
314 }
315
316 void ipc_print_routes(struct autobuf *abuf) {
317   struct rt_entry *rt;
318
319   abuf_json_mark_object(true, true, abuf, "routes");
320
321   /* Walk the route table */
322   OLSR_FOR_ALL_RT_ENTRIES(rt) {
323     struct lqtextbuffer costbuffer;
324
325     if (rt->rt_best) {
326       abuf_json_mark_array_entry(true, abuf);
327       abuf_json_ip_address(abuf, "destination", &rt->rt_dst.prefix);
328       abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
329       abuf_json_ip_address(abuf, "gateway", &rt->rt_best->rtp_nexthop.gateway);
330       abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
331       abuf_json_float(abuf, "etx", atof(get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &costbuffer)));
332       abuf_json_int(abuf, "rtpMetricCost", MIN(ROUTE_COST_BROKEN, rt->rt_best->rtp_metric.cost));
333       abuf_json_string(abuf, "networkInterface", if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
334       abuf_json_mark_array_entry(false, abuf);
335     }
336   } OLSR_FOR_ALL_RT_ENTRIES_END(rt);
337
338   abuf_json_mark_object(false, true, abuf, NULL);
339 }
340
341 void ipc_print_topology(struct autobuf *abuf) {
342   struct tc_entry *tc;
343
344   abuf_json_mark_object(true, true, abuf, "topology");
345
346   /* Topology */
347   OLSR_FOR_ALL_TC_ENTRIES(tc) {
348     struct tc_edge_entry *tc_edge;
349     OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
350       if (tc_edge->edge_inv) {
351         struct lqtextbuffer lqbuffer;
352         const char* lqString = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer);
353         char * nlqString = strrchr(lqString, '\t');
354
355         if (nlqString) {
356           *nlqString = '\0';
357           nlqString++;
358         }
359
360         abuf_json_mark_array_entry(true, abuf);
361
362         // vertex_node
363         abuf_json_ip_address(abuf, "lastHopIP", &tc->addr);
364         // cand_tree_node
365         abuf_json_int(abuf, "pathCost", MIN(tc->path_cost, ROUTE_COST_BROKEN));
366         // path_list_node
367         // edge_tree
368         // prefix_tree
369         // next_hop
370         // edge_gc_timer
371         abuf_json_int(abuf, "validityTime", tc->validity_timer ? (tc->validity_timer->timer_clock - now_times) : 0);
372         abuf_json_int(abuf, "refCount", tc->refcount);
373         abuf_json_int(abuf, "msgSeq", tc->msg_seq);
374         abuf_json_int(abuf, "msgHops", tc->msg_hops);
375         abuf_json_int(abuf, "hops", tc->hops);
376         abuf_json_int(abuf, "ansn", tc->ansn);
377         abuf_json_int(abuf, "tcIgnored", tc->ignored);
378
379         abuf_json_int(abuf, "errSeq", tc->err_seq);
380         abuf_json_boolean(abuf, "errSeqValid", tc->err_seq_valid);
381
382         // edge_node
383         abuf_json_ip_address(abuf, "destinationIP", &tc_edge->T_dest_addr);
384         // tc
385         abuf_json_int(abuf, "tcEdgeCost", MIN(LINK_COST_BROKEN, tc_edge->cost));
386         abuf_json_int(abuf, "ansnEdge", tc_edge->ansn);
387         abuf_json_float(abuf, "linkQuality", atof(lqString));
388         abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
389
390         abuf_json_mark_array_entry(false, abuf);
391       }
392     } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
393   } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
394
395   abuf_json_mark_object(false, true, abuf, NULL);
396 }
397
398 static void print_hna_array_entry(struct autobuf *abuf, union olsr_ip_addr *gw, union olsr_ip_addr *ip, uint8_t prefix_len, long long validityTime) {
399   abuf_json_mark_array_entry(true, abuf);
400   abuf_json_ip_address(abuf, "gateway", gw);
401   abuf_json_ip_address(abuf, "destination", ip);
402   abuf_json_int(abuf, "genmask", prefix_len);
403   abuf_json_int(abuf, "validityTime", validityTime);
404   abuf_json_mark_array_entry(false, abuf);
405 }
406
407 void ipc_print_hna(struct autobuf *abuf) {
408   struct ip_prefix_list *hna;
409   struct hna_entry *tmp_hna;
410
411   abuf_json_mark_object(true, true, abuf, "hna");
412
413   /* Announced HNA entries */
414   for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
415     print_hna_array_entry( //
416         abuf, //
417         &olsr_cnf->main_addr, //
418         &hna->net.prefix, //
419         hna->net.prefix_len, //
420         0);
421   }
422
423   OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
424     struct hna_net *tmp_net;
425
426     /* Check all networks */
427     for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
428       print_hna_array_entry( //
429           abuf, //
430           &tmp_hna->A_gateway_addr, //
431           &tmp_net->hna_prefix.prefix, //
432           tmp_net->hna_prefix.prefix_len, //
433           tmp_net->hna_net_timer ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0);
434     }
435   } OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
436
437   abuf_json_mark_object(false, true, abuf, NULL);
438 }
439
440 void ipc_print_mid(struct autobuf *abuf) {
441   int idx;
442
443   abuf_json_mark_object(true, true, abuf, "mid");
444
445   /* MID */
446   for (idx = 0; idx < HASHSIZE; idx++) {
447     struct mid_entry * entry = mid_set[idx].next;
448
449     while (entry != &mid_set[idx]) {
450       abuf_json_mark_array_entry(true, abuf);
451       abuf_json_ip_address(abuf, "ipAddress", &entry->main_addr);
452       abuf_json_int(abuf, "validityTime", entry->mid_timer ? (entry->mid_timer->timer_clock - now_times) : 0);
453       {
454         struct mid_address * alias = entry->aliases;
455
456         abuf_json_mark_object(true, true, abuf, "aliases");
457         while (alias) {
458           abuf_json_mark_array_entry(true, abuf);
459           abuf_json_ip_address(abuf, "ipAddress", &alias->alias);
460           abuf_json_int(abuf, "validityTime", alias->vtime - now_times);
461           abuf_json_mark_array_entry(false, abuf);
462
463           alias = alias->next_alias;
464         }
465         abuf_json_mark_object(false, true, abuf, NULL); // aliases
466       }
467       abuf_json_mark_array_entry(false, abuf); // entry
468
469       entry = entry->next;
470     }
471   }
472   abuf_json_mark_object(false, true, abuf, NULL); // mid
473 }
474
475 #ifdef __linux__
476
477 static void ipc_print_gateway_entry(struct autobuf *abuf, bool ipv6, struct gateway_entry * current_gw, struct gateway_entry * gw) {
478   struct tc_entry* tc = olsr_lookup_tc_entry(&gw->originator);
479
480   abuf_json_boolean(abuf, "selected", current_gw && (current_gw == gw));
481   abuf_json_boolean(abuf, "selectable", isGwSelectable(gw, ipv6));
482   abuf_json_ip_address(abuf, "originator", &gw->originator);
483   abuf_json_ip_address(abuf, "prefix", &gw->external_prefix.prefix);
484   abuf_json_int(abuf, "prefixLen", gw->external_prefix.prefix_len);
485   abuf_json_int(abuf, "uplink", gw->uplink);
486   abuf_json_int(abuf, "downlink", gw->downlink);
487   abuf_json_int(abuf, "cost", gw->path_cost);
488   abuf_json_boolean(abuf, "IPv4", gw->ipv4);
489   abuf_json_boolean(abuf, "IPv4-NAT", gw->ipv4nat);
490   abuf_json_boolean(abuf, "IPv6", gw->ipv6);
491   abuf_json_int(abuf, "expireTime", gw->expire_timer ? (gw->expire_timer->timer_clock - now_times) : 0);
492   abuf_json_int(abuf, "cleanupTime", gw->cleanup_timer ? (gw->cleanup_timer->timer_clock - now_times) : 0);
493
494   abuf_json_int(abuf, "pathcost", !tc ? ROUTE_COST_BROKEN : tc->path_cost);
495   abuf_json_int(abuf, "hops", !tc ? 0 : tc->hops);
496 }
497
498 static void ipc_print_gateways_ipvx(struct autobuf *abuf, bool ipv6) {
499   abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
500
501   if (olsr_cnf->smart_gw_active) {
502     struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
503     struct gateway_entry * gw;
504     OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
505       if ((!ipv6 && !gw->ipv4) || (ipv6 && !gw->ipv6)) {
506         /* gw does not advertise the requested IP version */
507         continue;
508       }
509
510       abuf_json_mark_array_entry(true, abuf);
511       ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
512       abuf_json_mark_array_entry(false, abuf);
513     } OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
514   }
515
516   abuf_json_mark_object(false, true, abuf, NULL);
517 }
518 #endif /* __linux__ */
519
520 void ipc_print_gateways(struct autobuf *abuf) {
521 #ifndef __linux__
522   abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
523 #else /* __linux__ */
524   abuf_json_mark_object(true, false, abuf, "gateways");
525
526   ipc_print_gateways_ipvx(abuf, false);
527   ipc_print_gateways_ipvx(abuf, true);
528
529   abuf_json_mark_object(false, false, abuf, NULL);
530 #endif /* __linux__ */
531 }
532
533 #ifdef __linux__
534
535 /** interface names for smart gateway tunnel interfaces, IPv4 */
536 extern struct interfaceName * sgwTunnel4InterfaceNames;
537
538 /** interface names for smart gateway tunnel interfaces, IPv6 */
539 extern struct interfaceName * sgwTunnel6InterfaceNames;
540
541 /**
542  * Construct the sgw table for a given ip version
543  *
544  * @param abuf the string buffer
545  * @param ipv6 true for IPv6, false for IPv4
546  * @param fmtv the format for printing
547  */
548 static void sgw_ipvx(struct autobuf *abuf, bool ipv6) {
549   struct interfaceName * sgwTunnelInterfaceNames = !ipv6 ? sgwTunnel4InterfaceNames : sgwTunnel6InterfaceNames;
550
551   abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
552
553   if (olsr_cnf->smart_gw_active && sgwTunnelInterfaceNames) {
554     struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
555     int i;
556     for (i = 0; i < olsr_cnf->smart_gw_use_count; i++) {
557       struct interfaceName * node = &sgwTunnelInterfaceNames[i];
558       struct gateway_entry * gw = node->gw;
559
560       if (!gw) {
561         continue;
562       }
563
564       abuf_json_mark_array_entry(true, abuf);
565       ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
566       abuf_json_ip_address(abuf, "destination", &gw->originator);
567       abuf_json_string(abuf, "tunnel", node->name);
568       abuf_json_int(abuf, "tableNr", node->tableNr);
569       abuf_json_int(abuf, "ruleNr", node->ruleNr);
570       abuf_json_int(abuf, "bypassRuleNr", node->bypassRuleNr);
571       abuf_json_mark_array_entry(false, abuf);
572     }
573   }
574
575   abuf_json_mark_object(false, true, abuf, NULL);
576 }
577 #endif /* __linux__ */
578
579 void ipc_print_sgw(struct autobuf *abuf) {
580 #ifndef __linux__
581   abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
582 #else
583   abuf_json_mark_object(true, false, abuf, "sgw");
584
585   sgw_ipvx(abuf, false);
586   sgw_ipvx(abuf, true);
587
588   abuf_json_mark_object(false, false, abuf, NULL);
589 #endif /* __linux__ */
590 }
591
592 void ipc_print_version(struct autobuf *abuf) {
593   abuf_json_mark_object(true, false, abuf, "version");
594
595   abuf_json_string(abuf, "version", olsrd_version);
596
597   abuf_json_string(abuf, "date", build_date);
598   abuf_json_string(abuf, "host", build_host);
599   abuf_json_string(abuf, "gitDescriptor", git_descriptor);
600   abuf_json_string(abuf, "gitSha", git_sha);
601   abuf_json_string(abuf, "releaseVersion", release_version);
602   abuf_json_string(abuf, "sourceHash", source_hash);
603
604   abuf_json_mark_object(false, false, abuf, NULL);
605 }
606
607 void ipc_print_olsrd_conf(struct autobuf *abuf) {
608   olsrd_write_cnf_autobuf(abuf, olsr_cnf);
609 }
610
611 void ipc_print_interfaces(struct autobuf *abuf) {
612 #ifdef __linux__
613   int linklen;
614   char path[PATH_MAX];
615   char linkpath[PATH_MAX];
616 #endif /* __linux__ */
617   const struct olsr_if *ifs;
618
619   abuf_json_mark_object(true, true, abuf, "interfaces");
620   for (ifs = olsr_cnf->interfaces; ifs != NULL ; ifs = ifs->next) {
621     struct olsr_lq_mult *mult;
622     const struct interface_olsr * const rifs = ifs->interf;
623
624     abuf_json_mark_array_entry(true, abuf);
625     abuf_json_string(abuf, "name", ifs->name);
626
627     abuf_json_mark_object(true, true, abuf, "linkQualityMultipliers");
628     for (mult = ifs->cnf->lq_mult; mult != NULL ; mult = mult->next) {
629       print_link_quality_multipliers_array_entry(abuf, mult);
630     }
631     abuf_json_mark_object(false, true, abuf, NULL); // linkQualityMultipliers
632
633     if (!rifs) {
634       abuf_json_string(abuf, "state", "down");
635     } else {
636       abuf_json_string(abuf, "state", "up");
637       abuf_json_string(abuf, "nameFromKernel", rifs->int_name);
638       abuf_json_int(abuf, "interfaceMode", rifs->mode);
639       abuf_json_boolean(abuf, "emulatedHostClientInterface", rifs->is_hcif);
640       abuf_json_boolean(abuf, "sendTcImmediately", rifs->immediate_send_tc);
641       abuf_json_int(abuf, "fishEyeTtlIndex", rifs->ttl_index);
642       abuf_json_int(abuf, "olsrForwardingTimeout", rifs->fwdtimer);
643       abuf_json_int(abuf, "olsrMessageSequenceNumber", rifs->olsr_seqnum);
644       abuf_json_int(abuf, "olsrInterfaceMetric", rifs->int_metric);
645       abuf_json_int(abuf, "olsrMTU", rifs->int_mtu);
646       abuf_json_int(abuf, "helloEmissionInterval", rifs->hello_etime);
647       abuf_json_int(abuf, "helloValidityTime", me_to_reltime(rifs->valtimes.hello));
648       abuf_json_int(abuf, "tcValidityTime", me_to_reltime(rifs->valtimes.tc));
649       abuf_json_int(abuf, "midValidityTime", me_to_reltime(rifs->valtimes.mid));
650       abuf_json_int(abuf, "hnaValidityTime", me_to_reltime(rifs->valtimes.hna));
651       abuf_json_boolean(abuf, "wireless", rifs->is_wireless);
652
653 #ifdef __linux__
654       abuf_json_boolean(abuf, "icmpRedirect", rifs->nic_state.redirect);
655       abuf_json_boolean(abuf, "spoofFilter", rifs->nic_state.spoof);
656 #endif /* __linux__ */
657
658       if (olsr_cnf->ip_version == AF_INET) {
659         struct ipaddr_str addrbuf;
660         struct ipaddr_str maskbuf;
661         struct ipaddr_str bcastbuf;
662
663         abuf_json_string(abuf, "ipv4Address", ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
664         abuf_json_string(abuf, "netmask", ip4_to_string(&maskbuf, rifs->int_netmask.sin_addr));
665         abuf_json_string(abuf, "broadcast", ip4_to_string(&bcastbuf, rifs->int_broadaddr.sin_addr));
666       } else {
667         struct ipaddr_str addrbuf;
668         struct ipaddr_str maskbuf;
669
670         abuf_json_string(abuf, "ipv6Address", ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
671         abuf_json_string(abuf, "multicast", ip6_to_string(&maskbuf, &rifs->int6_multaddr.sin6_addr));
672       }
673     }
674 #ifdef __linux__
675     snprintf(path, PATH_MAX, "/sys/class/net/%s/device/driver/module", ifs->name);
676     linklen = readlink(path, linkpath, PATH_MAX - 1);
677     if (linklen > 1) {
678       linkpath[linklen] = '\0';
679       abuf_json_string(abuf, "kernelModule", basename(linkpath));
680     }
681
682     abuf_json_sys_class_net(abuf, "addressLength", ifs->name, "addr_len");
683     abuf_json_sys_class_net(abuf, "carrier", ifs->name, "carrier");
684     abuf_json_sys_class_net(abuf, "dormant", ifs->name, "dormant");
685     abuf_json_sys_class_net(abuf, "features", ifs->name, "features");
686     abuf_json_sys_class_net(abuf, "flags", ifs->name, "flags");
687     abuf_json_sys_class_net(abuf, "linkMode", ifs->name, "link_mode");
688     abuf_json_sys_class_net(abuf, "macAddress", ifs->name, "address");
689     abuf_json_sys_class_net(abuf, "ethernetMTU", ifs->name, "mtu");
690     abuf_json_sys_class_net(abuf, "operationalState", ifs->name, "operstate");
691     abuf_json_sys_class_net(abuf, "txQueueLength", ifs->name, "tx_queue_len");
692     abuf_json_sys_class_net(abuf, "collisions", ifs->name, "statistics/collisions");
693     abuf_json_sys_class_net(abuf, "multicastPackets", ifs->name, "statistics/multicast");
694     abuf_json_sys_class_net(abuf, "rxBytes", ifs->name, "statistics/rx_bytes");
695     abuf_json_sys_class_net(abuf, "rxCompressed", ifs->name, "statistics/rx_compressed");
696     abuf_json_sys_class_net(abuf, "rxCrcErrors", ifs->name, "statistics/rx_crc_errors");
697     abuf_json_sys_class_net(abuf, "rxDropped", ifs->name, "statistics/rx_dropped");
698     abuf_json_sys_class_net(abuf, "rxErrors", ifs->name, "statistics/rx_errors");
699     abuf_json_sys_class_net(abuf, "rxFifoErrors", ifs->name, "statistics/rx_fifo_errors");
700     abuf_json_sys_class_net(abuf, "rxFrameErrors", ifs->name, "statistics/rx_frame_errors");
701     abuf_json_sys_class_net(abuf, "rxLengthErrors", ifs->name, "statistics/rx_length_errors");
702     abuf_json_sys_class_net(abuf, "rxMissedErrors", ifs->name, "statistics/rx_missed_errors");
703     abuf_json_sys_class_net(abuf, "rxOverErrors", ifs->name, "statistics/rx_over_errors");
704     abuf_json_sys_class_net(abuf, "rxPackets", ifs->name, "statistics/rx_packets");
705     abuf_json_sys_class_net(abuf, "txAbortedErrors", ifs->name, "statistics/tx_aborted_errors");
706     abuf_json_sys_class_net(abuf, "txBytes", ifs->name, "statistics/tx_bytes");
707     abuf_json_sys_class_net(abuf, "txCarrierErrors", ifs->name, "statistics/tx_carrier_errors");
708     abuf_json_sys_class_net(abuf, "txCompressed", ifs->name, "statistics/tx_compressed");
709     abuf_json_sys_class_net(abuf, "txDropped", ifs->name, "statistics/tx_dropped");
710     abuf_json_sys_class_net(abuf, "txErrors", ifs->name, "statistics/tx_errors");
711     abuf_json_sys_class_net(abuf, "txFifoErrors", ifs->name, "statistics/tx_fifo_errors");
712     abuf_json_sys_class_net(abuf, "txHeartbeatErrors", ifs->name, "statistics/tx_heartbeat_errors");
713     abuf_json_sys_class_net(abuf, "txPackets", ifs->name, "statistics/tx_packets");
714     abuf_json_sys_class_net(abuf, "txWindowErrors", ifs->name, "statistics/tx_window_errors");
715     abuf_json_sys_class_net(abuf, "beaconing", ifs->name, "wireless/beacon");
716     abuf_json_sys_class_net(abuf, "encryptionKey", ifs->name, "wireless/crypt");
717     abuf_json_sys_class_net(abuf, "fragmentationThreshold", ifs->name, "wireless/fragment");
718     abuf_json_sys_class_net(abuf, "signalLevel", ifs->name, "wireless/level");
719     abuf_json_sys_class_net(abuf, "linkQuality", ifs->name, "wireless/link");
720     abuf_json_sys_class_net(abuf, "misc", ifs->name, "wireless/misc");
721     abuf_json_sys_class_net(abuf, "noiseLevel", ifs->name, "wireless/noise");
722     abuf_json_sys_class_net(abuf, "nwid", ifs->name, "wireless/nwid");
723     abuf_json_sys_class_net(abuf, "wirelessRetries", ifs->name, "wireless/retries");
724     abuf_json_sys_class_net(abuf, "wirelessStatus", ifs->name, "wireless/status");
725 #endif /* __linux__ */
726     abuf_json_mark_array_entry(false, abuf);
727   }
728   abuf_json_mark_object(false, true, abuf, NULL); // interfaces
729 }
730
731 void ipc_print_twohop(struct autobuf *abuf) {
732   ipc_print_neighbors_internal(abuf, true);
733 }
734
735 static void print_msg_params(struct autobuf *abuf, struct olsr_msg_params *params, const char * name) {
736   assert(abuf);
737   assert(params);
738   assert(name);
739
740   abuf_json_mark_object(true, false, abuf, name);
741   abuf_json_float(abuf, "emissionInterval", params->emission_interval);
742   abuf_json_float(abuf, "validityTime", params->validity_time);
743   abuf_json_mark_object(false, false, abuf, NULL);
744 }
745
746 static void print_link_quality_multipliers_array_entry(struct autobuf *abuf, struct olsr_lq_mult *mult) {
747   assert(abuf);
748   assert(mult);
749
750   abuf_json_mark_array_entry(true, abuf);
751   abuf_json_ip_address(abuf, "route", &mult->addr);
752   abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
753   abuf_json_mark_array_entry(false, abuf);
754 }
755
756 static void print_ipc_net_array_entry(struct autobuf *abuf, struct ip_prefix_list *ipc_nets) {
757   abuf_json_mark_array_entry(true, abuf);
758   abuf_json_boolean(abuf, "host", (ipc_nets->net.prefix_len == olsr_cnf->maxplen));
759   abuf_json_ip_address(abuf, "ipAddress", &ipc_nets->net.prefix);
760   abuf_json_int(abuf, "genmask", ipc_nets->net.prefix_len);
761   abuf_json_mark_array_entry(false, abuf);
762 }
763
764 void ipc_print_config(struct autobuf *abuf) {
765   abuf_json_mark_object(true, false, abuf, "config");
766
767   abuf_json_string(abuf, "configurationFile", olsr_cnf->configuration_file);
768   abuf_json_int(abuf, "olsrPort", olsr_cnf->olsrport);
769   abuf_json_int(abuf, "debugLevel", olsr_cnf->debug_level);
770   abuf_json_boolean(abuf, "noFork", olsr_cnf->no_fork);
771   abuf_json_string(abuf, "pidFile", olsr_cnf->pidfile);
772   abuf_json_boolean(abuf, "hostEmulation", olsr_cnf->host_emul);
773   abuf_json_int(abuf, "ipVersion", olsr_cnf->ip_version);
774   abuf_json_boolean(abuf, "allowNoInt", olsr_cnf->allow_no_interfaces);
775   abuf_json_int(abuf, "tosValue", olsr_cnf->tos);
776   abuf_json_int(abuf, "rtProto", olsr_cnf->rt_proto);
777   abuf_json_int(abuf, "rtTable", olsr_cnf->rt_table);
778   abuf_json_int(abuf, "rtTableDefault", olsr_cnf->rt_table_default);
779   abuf_json_int(abuf, "rtTableTunnel", olsr_cnf->rt_table_tunnel);
780   abuf_json_int(abuf, "rtTablePriority", olsr_cnf->rt_table_pri);
781   abuf_json_int(abuf, "rtTableTunnelPriority", olsr_cnf->rt_table_tunnel_pri);
782   abuf_json_int(abuf, "rtTableDefauiltOlsrPriority", olsr_cnf->rt_table_defaultolsr_pri);
783   abuf_json_int(abuf, "rtTableDefaultPriority", olsr_cnf->rt_table_default_pri);
784   abuf_json_int(abuf, "willingness", olsr_cnf->willingness);
785   abuf_json_boolean(abuf, "willingnessAuto", olsr_cnf->willingness_auto);
786   // ipc_connections: later
787   abuf_json_boolean(abuf, "useHysteresis", olsr_cnf->use_hysteresis);
788   abuf_json_string(abuf, "fibMetric", FIB_METRIC_TXT[olsr_cnf->fib_metric]);
789   abuf_json_string(abuf, "fibMetricDefault", FIB_METRIC_TXT[olsr_cnf->fib_metric_default]);
790   abuf_json_float(abuf, "hystScaling", olsr_cnf->hysteresis_param.scaling);
791   abuf_json_float(abuf, "hystThrLow", olsr_cnf->hysteresis_param.thr_low);
792   abuf_json_float(abuf, "hystThrHigh", olsr_cnf->hysteresis_param.thr_high);
793   // plugins: later
794   // hna_entries
795   {
796     struct ip_prefix_list *hna;
797
798     abuf_json_mark_object(true, true, abuf, "hna");
799
800     /* Announced HNA entries */
801     for (hna = olsr_cnf->hna_entries; hna; hna = hna->next) {
802         print_hna_array_entry( //
803             abuf, //
804             &olsr_cnf->main_addr, //
805             &hna->net.prefix, //
806             hna->net.prefix_len, //
807             0);
808     }
809     abuf_json_mark_object(false, true, abuf, NULL);
810   }
811   // ipc_nets: later
812   // interface_defaults: later
813   // interfaces: later
814   abuf_json_float(abuf, "pollrate", olsr_cnf->pollrate);
815   abuf_json_float(abuf, "nicChgsPollInt", olsr_cnf->nic_chgs_pollrate);
816   abuf_json_boolean(abuf, "clearScreen", olsr_cnf->clear_screen);
817   abuf_json_int(abuf, "tcRedundancy", olsr_cnf->tc_redundancy);
818   abuf_json_int(abuf, "mprCoverage", olsr_cnf->mpr_coverage);
819   abuf_json_int(abuf, "linkQualityLevel", olsr_cnf->lq_level);
820   abuf_json_boolean(abuf, "linkQualityFishEye", olsr_cnf->lq_fish);
821   abuf_json_float(abuf, "linkQualityAging", olsr_cnf->lq_aging);
822   abuf_json_string(abuf, "linkQualityAlgorithm", olsr_cnf->lq_algorithm);
823
824   abuf_json_float(abuf, "minTCVTime", olsr_cnf->min_tc_vtime);
825
826   abuf_json_boolean(abuf, "setIpForward", olsr_cnf->set_ip_forward);
827
828   abuf_json_string(abuf, "lockFile", olsr_cnf->lock_file);
829   abuf_json_boolean(abuf, "useNiit", olsr_cnf->use_niit);
830
831   abuf_json_boolean(abuf, "smartGateway", olsr_cnf->smart_gw_active);
832   abuf_json_boolean(abuf, "smartGatewayAlwaysRemoveServerTunnel", olsr_cnf->smart_gw_always_remove_server_tunnel);
833   abuf_json_boolean(abuf, "smartGatewayAllowNAT", olsr_cnf->smart_gw_allow_nat);
834   abuf_json_boolean(abuf, "smartGatewayUplinkNAT", olsr_cnf->smart_gw_uplink_nat);
835   abuf_json_int(abuf, "smartGatewayUseCount", olsr_cnf->smart_gw_use_count);
836   abuf_json_int(abuf, "smartGatewayTakeDownPercentage", olsr_cnf->smart_gw_takedown_percentage);
837   abuf_json_string(abuf, "smartGatewayInstanceId", olsr_cnf->smart_gw_instance_id);
838   abuf_json_string(abuf, "smartGatewayPolicyRoutingScript", olsr_cnf->smart_gw_policyrouting_script);
839   // smart_gw_egress_interfaces
840   {
841     struct sgw_egress_if * egressif = olsr_cnf->smart_gw_egress_interfaces;
842
843     abuf_json_mark_object(true, true, abuf, "smartGatewayEgressInterfaces");
844     while (egressif) {
845       abuf_json_mark_array_entry(true, abuf);
846       abuf_json_string(abuf, "interface", egressif->name);
847       abuf_json_mark_array_entry(false, abuf);
848
849       egressif = egressif->next;
850     }
851     abuf_json_mark_object(false, true, abuf, NULL);
852   }
853   abuf_json_int(abuf, "smartGatewayEgressInterfacesCount", olsr_cnf->smart_gw_egress_interfaces_count);
854   abuf_json_string(abuf, "smartGatewayEgressFile", olsr_cnf->smart_gw_egress_file);
855   abuf_json_int(abuf, "smartGatewayEgressFilePeriod", olsr_cnf->smart_gw_egress_file_period);
856   abuf_json_string(abuf, "smartGatewayStatusFile", olsr_cnf->smart_gw_status_file);
857   abuf_json_int(abuf, "smartGatewayTablesOffset", olsr_cnf->smart_gw_offset_tables);
858   abuf_json_int(abuf, "smartGatewayRulesOffset", olsr_cnf->smart_gw_offset_rules);
859   abuf_json_int(abuf, "smartGatewayPeriod", olsr_cnf->smart_gw_period);
860   abuf_json_int(abuf, "smartGatewayStableCount", olsr_cnf->smart_gw_stablecount);
861   abuf_json_int(abuf, "smartGatewayThreshold", olsr_cnf->smart_gw_thresh);
862   abuf_json_int(abuf, "smartGatewayWeightExitLinkUp", olsr_cnf->smart_gw_weight_exitlink_up);
863   abuf_json_int(abuf, "smartGatewayWeightExitLinkDown", olsr_cnf->smart_gw_weight_exitlink_down);
864   abuf_json_int(abuf, "smartGatewayWeightEtx", olsr_cnf->smart_gw_weight_etx);
865   abuf_json_int(abuf, "smartGatewayDividerEtx", olsr_cnf->smart_gw_divider_etx);
866   abuf_json_int(abuf, "smartGatewayMaxCostMaxEtx", olsr_cnf->smart_gw_path_max_cost_etx_max);
867   abuf_json_string(abuf, "smartGatewayUplink", GW_UPLINK_TXT[olsr_cnf->smart_gw_type]);
868   abuf_json_int(abuf, "smartGatewayUplinkKbps", olsr_cnf->smart_gw_uplink);
869   abuf_json_int(abuf, "smartGatewayDownlinkKbps", olsr_cnf->smart_gw_downlink);
870   abuf_json_boolean(abuf, "smartGatewayBandwidthZero", olsr_cnf->smart_gateway_bandwidth_zero);
871   abuf_json_ip_address(abuf, "smartGatewayPrefix", &olsr_cnf->smart_gw_prefix.prefix);
872   abuf_json_int(abuf, "smartGatewayPrefixLength", olsr_cnf->smart_gw_prefix.prefix_len);
873
874
875   abuf_json_ip_address(abuf, "mainIp", &olsr_cnf->main_addr);
876   abuf_json_ip_address(abuf, "unicastSourceIpAddress", &olsr_cnf->unicast_src_ip);
877   abuf_json_boolean(abuf, "srcIpRoutes", olsr_cnf->use_src_ip_routes);
878
879
880   abuf_json_int(abuf, "maxPrefixLength", olsr_cnf->maxplen);
881   abuf_json_int(abuf, "ipSize", olsr_cnf->ipsize);
882   abuf_json_boolean(abuf, "delgw", olsr_cnf->del_gws);
883   abuf_json_float(abuf, "willingnessUpdateInterval", olsr_cnf->will_int);
884   abuf_json_float(abuf, "maxSendMessageJitter", olsr_cnf->max_jitter);
885   abuf_json_int(abuf, "exitValue", olsr_cnf->exit_value);
886   abuf_json_float(abuf, "maxTcValidTime", olsr_cnf->max_tc_vtime);
887
888   abuf_json_int(abuf, "niit4to6InterfaceIndex", olsr_cnf->niit4to6_if_index);
889   abuf_json_int(abuf, "niit6to4InterfaceIndex", olsr_cnf->niit6to4_if_index);
890
891
892   abuf_json_boolean(abuf, "hasIpv4Gateway", olsr_cnf->has_ipv4_gateway);
893   abuf_json_boolean(abuf, "hasIpv6Gateway", olsr_cnf->has_ipv6_gateway);
894
895   abuf_json_int(abuf, "ioctlSocket", olsr_cnf->ioctl_s);
896 #ifdef __linux__
897   abuf_json_int(abuf, "routeNetlinkSocket", olsr_cnf->rtnl_s);
898   abuf_json_int(abuf, "routeMonitorSocket", olsr_cnf->rt_monitor_socket);
899 #endif /* __linux__ */
900
901 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
902   abuf_json_int(abuf, "routeChangeSocket", olsr_cnf->rts);
903 #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ */
904   abuf_json_float(abuf, "linkQualityNatThreshold", olsr_cnf->lq_nat_thresh);
905
906
907   // Other settings
908   abuf_json_int(abuf, "brokenLinkCost", LINK_COST_BROKEN);
909   abuf_json_int(abuf, "brokenRouteCost", ROUTE_COST_BROKEN);
910
911
912   // IpcConnect section
913   abuf_json_int(abuf, "ipcConnectMaxConnections", olsr_cnf->ipc_connections);
914   {
915     struct ip_prefix_list *ipc_nets;
916
917     abuf_json_mark_object(true, true, abuf, "ipcConnectAllowed");
918     for (ipc_nets = olsr_cnf->ipc_nets; ipc_nets; ipc_nets = ipc_nets->next) {
919       print_ipc_net_array_entry(abuf, ipc_nets);
920     }
921     abuf_json_mark_object(false, true, abuf, NULL);
922   }
923
924
925   // plugins section: use /plugins
926
927
928   // InterfaceDefaults section
929   abuf_json_mark_object(true, false, abuf, "interfaceDefaults");
930   {
931     struct if_config_options* id = olsr_cnf->interface_defaults;
932     struct olsr_lq_mult *mult;
933
934     abuf_json_ip_address(abuf, "ipv4Broadcast", &id->ipv4_multicast);
935     abuf_json_ip_address(abuf, "ipv6Multicast", &id->ipv6_multicast);
936
937     abuf_json_ip_address(abuf, "ipv4Source", &id->ipv4_src);
938     abuf_json_ip_address(abuf, "ipv6Source", &id->ipv6_src.prefix);
939     abuf_json_int(abuf, "ipv6SourcePrefixLength", id->ipv6_src.prefix_len);
940
941     abuf_json_string(abuf, "mode", OLSR_IF_MODE[id->mode]);
942
943     abuf_json_int(abuf, "weightValue", id->weight.value);
944     abuf_json_boolean(abuf, "weightFixed", id->weight.fixed);
945     print_msg_params(abuf, &id->hello_params, "hello");
946     print_msg_params(abuf, &id->tc_params, "tc");
947     print_msg_params(abuf, &id->mid_params, "mid");
948     print_msg_params(abuf, &id->hna_params, "hna");
949     abuf_json_mark_object(true, true, abuf, "linkQualityMultipliers");
950     for (mult = olsr_cnf->interface_defaults->lq_mult; mult != NULL ; mult = mult->next) {
951       print_link_quality_multipliers_array_entry(abuf, mult);
952     }
953     abuf_json_mark_object(false, true, abuf, NULL);
954     abuf_json_int(abuf, "linkQualityMultipliersCount", id->orig_lq_mult_cnt);
955     abuf_json_boolean(abuf, "autoDetectChanges", id->autodetect_chg);
956   }
957   abuf_json_mark_object(false, false, abuf, NULL);
958
959
960   // Interface(s) section: use /interfaces
961
962
963   // OS section
964 #if defined _WIN32 || defined _WIN64
965   abuf_json_string(abuf, "os", "Windows");
966 #elif defined __gnu_linux__
967   abuf_json_string(abuf, "os", "GNU/Linux");
968 #elif defined __ANDROID__
969   abuf_json_string(abuf, "os", "Android");
970 #elif defined __APPLE__
971   abuf_json_string(abuf, "os", "Mac OS X");
972 #elif defined __NetBSD__
973   abuf_json_string(abuf, "os", "NetBSD");
974 #elif defined __OpenBSD__
975   abuf_json_string(abuf, "os", "OpenBSD");
976 #elif defined __FreeBSD__ || defined __FreeBSD_kernel__
977   abuf_json_string(abuf, "os", "FreeBSD");
978 #else /* OS detection */
979   abuf_json_string(abuf, "os", "Undefined");
980 #endif /* OS detection */
981
982   abuf_json_int(abuf, "startTime", start_time.tv_sec);
983
984   abuf_json_mark_object(false, false, abuf, NULL);
985 }
986
987 void ipc_print_plugins(struct autobuf *abuf) {
988   abuf_json_mark_object(true, true, abuf, "plugins");
989   if (olsr_cnf->plugins) {
990     struct plugin_entry *plugin;
991
992     for (plugin = olsr_cnf->plugins; plugin; plugin = plugin->next) {
993       struct plugin_param *param;
994
995       abuf_json_mark_array_entry(true, abuf);
996       abuf_json_string(abuf, "plugin", plugin->name);
997       for (param = plugin->params; param; param = param->next) {
998         abuf_json_string(abuf, param->key, param->value);
999       }
1000       abuf_json_mark_array_entry(false, abuf);
1001     }
1002   }
1003   abuf_json_mark_object(false, true, abuf, NULL);
1004 }