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