2 * The olsr.org Optimized Link-State Routing daemon (olsrd)
4 * (c) by the OLSR project
6 * See our Git repository to find out who worked on this file
7 * and thus is a copyright holder on it.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
15 * * Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
21 * * Neither the name of olsr.org, olsrd nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
38 * Visit http://www.olsr.org for more information.
40 * If you find this software useful feel free to make a donation
41 * to the project. For more information see the website or contact
42 * the copyright holders.
46 #include "olsrd_jsoninfo.h"
53 #include "builddata.h"
54 #include "neighbor_table.h"
55 #include "mpr_selector_set.h"
57 #include "routing_table.h"
58 #include "lq_plugin.h"
60 #include "gateway_costs.h"
61 #include "olsrd_plugin.h"
62 #include "info/info_types.h"
63 #include "info/http_headers.h"
64 #include "info/json_helpers.h"
65 #include "gateway_default_handler.h"
66 #include "egressTypes.h"
71 static struct json_session json_session;
73 struct timeval start_time;
75 static int read_uuid_from_file(const char * name, const char *file) {
84 memset(uuid, 0, sizeof(uuid));
87 olsr_printf(1, "(%s) Reading UUID from '%s'\n", name, file);
89 olsr_printf(1, "(%s) Could not open '%s': %s\n", name, file, strerror(errno));
92 chars = fread(uuid, 1, sizeof(uuid) - 1, f);
94 uuid[chars] = '\0'; /* null-terminate the string */
96 /* we only use the first line of the file */
97 end = strchr(uuid, '\n');
102 olsr_printf(1, "(%s) Could not read UUID from '%s': %s\n", name, file, strerror(errno));
110 void plugin_init(const char *plugin_name) {
112 gettimeofday(&start_time, NULL);
114 if (!strlen(uuidfile)) {
115 strscpy(uuidfile, "uuid.txt", sizeof(uuidfile));
117 read_uuid_from_file(plugin_name, uuidfile);
120 unsigned long long get_supported_commands_mask(void) {
121 return SIW_ALL | SIW_OLSRD_CONF;
124 bool isCommand(const char *str, unsigned long long siw) {
135 case SIW_RUNTIME_ALL:
139 case SIW_STARTUP_ALL:
195 case SIW_NEIGHBORS_FREIFUNK:
203 return !strcmp(str, cmd);
206 const char * determine_mime_type(unsigned int send_what) {
207 return (send_what & SIW_OLSRD_CONF) ? "text/plain; charset=utf-8" : "application/json; charset=utf-8";
210 void output_start(struct autobuf *abuf) {
211 /* global variables for tracking when to put a comma in for JSON */
212 abuf_json_reset_entry_number_and_depth(&json_session, pretty);
213 abuf_json_mark_output(&json_session, true, abuf);
215 abuf_json_int(&json_session, abuf, "systemTime", time(NULL));
216 abuf_json_int(&json_session, abuf, "timeSinceStartup", now_times);
218 abuf_json_string(&json_session, abuf, "uuid", uuid);
222 void output_end(struct autobuf *abuf) {
223 abuf_json_mark_output(&json_session, false, abuf);
224 abuf_puts(abuf, "\n");
225 abuf_json_reset_entry_number_and_depth(&json_session, pretty);
228 void output_error(struct autobuf *abuf, unsigned int status, const char * req __attribute__((unused)), bool http_headers) {
229 if (http_headers || (status == INFO_HTTP_OK)) {
233 /* !http_headers && !INFO_HTTP_OK */
237 if (status == INFO_HTTP_NOCONTENT) {
240 abuf_json_string(&json_session, abuf, "error", httpStatusToReply(status));
246 static void print_msg_params(struct json_session *session, struct autobuf *abuf, struct olsr_msg_params *params, const char * name) {
252 abuf_json_mark_object(session, true, false, abuf, name);
253 abuf_json_float(session, abuf, "emissionInterval", params->emission_interval);
254 abuf_json_float(session, abuf, "validityTime", params->validity_time);
255 abuf_json_mark_object(session, false, false, abuf, NULL);
258 static void print_hna_array_entry(struct json_session *session, struct autobuf *abuf, union olsr_ip_addr *gw, union olsr_ip_addr *ip, uint8_t prefix_len, long long validityTime) {
262 abuf_json_mark_array_entry(session, true, abuf);
263 abuf_json_ip_address(session, abuf, "gateway", gw);
264 abuf_json_ip_address(session, abuf, "destination", ip);
265 abuf_json_int(session, abuf, "genmask", prefix_len);
266 abuf_json_int(session, abuf, "validityTime", validityTime);
267 abuf_json_mark_array_entry(session, false, abuf);
270 static void print_link_quality_multipliers_array_entry(struct json_session *session, struct autobuf *abuf, struct olsr_lq_mult *mult) {
275 abuf_json_mark_array_entry(session, true, abuf);
276 abuf_json_ip_address(session, abuf, "route", &mult->addr);
277 abuf_json_float(session, abuf, "multiplier", mult->value / 65535.0);
278 abuf_json_mark_array_entry(session, false, abuf);
281 static void print_ipc_net_array_entry(struct json_session *session, struct autobuf *abuf, struct ip_prefix_list *ipc_nets) {
286 abuf_json_mark_array_entry(session, true, abuf);
287 abuf_json_boolean(session, abuf, "host", (ipc_nets->net.prefix_len == olsr_cnf->maxplen));
288 abuf_json_ip_address(session, abuf, "ipAddress", &ipc_nets->net.prefix);
289 abuf_json_int(session, abuf, "genmask", ipc_nets->net.prefix_len);
290 abuf_json_mark_array_entry(session, false, abuf);
293 static void print_interface_config(struct json_session *session, struct autobuf *abuf, const char * name, struct if_config_options* id) {
298 abuf_json_mark_object(session, true, false, abuf, name);
300 struct olsr_lq_mult *mult;
302 abuf_json_ip_address(session, abuf, "ipv4Broadcast", &id->ipv4_multicast);
303 abuf_json_ip_address(session, abuf, "ipv6Multicast", &id->ipv6_multicast);
305 abuf_json_ip_address(session, abuf, "ipv4Source", &id->ipv4_src);
306 abuf_json_ip_address(session, abuf, "ipv6Source", &id->ipv6_src.prefix);
307 abuf_json_int(session, abuf, "ipv6SourcePrefixLength", id->ipv6_src.prefix_len);
309 abuf_json_string(session, abuf, "mode", ((id->mode < IF_MODE_MESH) || (id->mode >= IF_MODE_CNT)) ? "" : OLSR_IF_MODE[id->mode]);
311 abuf_json_int(session, abuf, "weightValue", id->weight.value);
312 abuf_json_boolean(session, abuf, "weightFixed", id->weight.fixed);
313 print_msg_params(session, abuf, &id->hello_params, "hello");
314 print_msg_params(session, abuf, &id->tc_params, "tc");
315 print_msg_params(session, abuf, &id->mid_params, "mid");
316 print_msg_params(session, abuf, &id->hna_params, "hna");
317 abuf_json_mark_object(session, true, true, abuf, "linkQualityMultipliers");
318 for (mult = olsr_cnf->interface_defaults->lq_mult; mult != NULL ; mult = mult->next) {
319 print_link_quality_multipliers_array_entry(session, abuf, mult);
321 abuf_json_mark_object(session, false, true, abuf, NULL);
322 abuf_json_int(session, abuf, "linkQualityMultipliersCount", id->orig_lq_mult_cnt);
323 abuf_json_boolean(session, abuf, "autoDetectChanges", id->autodetect_chg);
325 abuf_json_mark_object(session, false, false, abuf, NULL);
328 static void print_interface_olsr(struct json_session *session, struct autobuf *abuf, const char * name, struct interface_olsr * rifs) {
333 abuf_json_mark_object(session, true, false, abuf, name);
334 abuf_json_boolean(session, abuf, "up", rifs != NULL);
336 abuf_json_mark_object(session, false, false, abuf, NULL);
340 abuf_json_ip_address46(session, abuf, "ipv4Address", &rifs->int_addr.sin_addr, AF_INET);
341 abuf_json_ip_address46(session, abuf, "ipv4Netmask", &rifs->int_netmask.sin_addr, AF_INET);
342 abuf_json_ip_address46(session, abuf, "ipv4Broadcast", &rifs->int_broadaddr.sin_addr, AF_INET);
343 abuf_json_string(session, abuf, "mode", ((rifs->mode < IF_MODE_MESH) || (rifs->mode >= IF_MODE_CNT)) ? "" : OLSR_IF_MODE[rifs->mode]);
345 abuf_json_ip_address46(session, abuf, "ipv6Address", &rifs->int6_addr.sin6_addr, AF_INET6);
346 abuf_json_ip_address46(session, abuf, "ipv6Multicast", &rifs->int6_multaddr.sin6_addr, AF_INET6);
348 abuf_json_ip_address(session, abuf, "ipAddress", &rifs->ip_addr);
349 abuf_json_boolean(session, abuf, "emulatedInterface", rifs->is_hcif);
351 abuf_json_int(session, abuf, "olsrSocket", rifs->olsr_socket);
352 abuf_json_int(session, abuf, "sendSocket", rifs->send_socket);
354 abuf_json_int(session, abuf, "metric", rifs->int_metric);
355 abuf_json_int(session, abuf, "mtu", rifs->int_mtu);
356 abuf_json_int(session, abuf, "flags", rifs->int_flags);
357 abuf_json_int(session, abuf, "index", rifs->if_index);
358 abuf_json_boolean(session, abuf, "wireless", rifs->is_wireless);
359 abuf_json_string(session, abuf, "name", rifs->int_name);
360 abuf_json_int(session, abuf, "seqNum", rifs->olsr_seqnum);
363 abuf_json_mark_object(session, true, false, abuf, "messageTimes");
364 abuf_json_int(session, abuf, "hello", rifs->hello_gen_timer ? (long) (rifs->hello_gen_timer->timer_clock - now_times) : 0);
365 abuf_json_int(session, abuf, "tc", rifs->tc_gen_timer ? (long) (rifs->tc_gen_timer->timer_clock - now_times) : 0);
366 abuf_json_int(session, abuf, "mid", rifs->mid_gen_timer ? (long) (rifs->mid_gen_timer->timer_clock - now_times) : 0);
367 abuf_json_int(session, abuf, "hna", rifs->hna_gen_timer ? (long) (rifs->hna_gen_timer->timer_clock - now_times) : 0);
368 abuf_json_mark_object(session, false, false, abuf, NULL);
375 abuf_json_boolean(session, abuf, "icmpRedirectBackup", rifs->nic_state.redirect);
378 abuf_json_boolean(session, abuf, "spoofFilterBackup", rifs->nic_state.spoof);
380 #endif /* __linux__ */
382 abuf_json_int(session, abuf, "helloEmissionInterval", rifs->hello_etime);
383 abuf_json_mark_object(session, true, false, abuf, "validityTimes");
384 abuf_json_int(session, abuf, "hello", me_to_reltime(rifs->valtimes.hello));
385 abuf_json_int(session, abuf, "tc", me_to_reltime(rifs->valtimes.tc));
386 abuf_json_int(session, abuf, "mid", me_to_reltime(rifs->valtimes.mid));
387 abuf_json_int(session, abuf, "hna", me_to_reltime(rifs->valtimes.hna));
388 abuf_json_mark_object(session, false, false, abuf, NULL);
390 abuf_json_int(session, abuf, "forwardingTimeout", rifs->fwdtimer);
393 abuf_json_int(session, abuf, "sgwZeroBwTimeout", rifs->sgw_sgw_zero_bw_timeout);
402 abuf_json_int(session, abuf, "ttlIndex", rifs->ttl_index);
405 abuf_json_boolean(session, abuf, "immediateSendTc", rifs->immediate_send_tc);
407 abuf_json_mark_object(session, false, false, abuf, NULL);
411 static void ipc_print_gateway_entry(struct json_session *session, struct autobuf *abuf, bool ipv6, struct gateway_entry * current_gw, struct gateway_entry * gw) {
417 tc = olsr_lookup_tc_entry(&gw->originator);
419 abuf_json_boolean(session, abuf, "selected", current_gw && (current_gw == gw));
420 abuf_json_boolean(session, abuf, "selectable", isGwSelectable(gw, ipv6));
421 abuf_json_ip_address(session, abuf, "originator", &gw->originator);
422 abuf_json_ip_address(session, abuf, "prefix", &gw->external_prefix.prefix);
423 abuf_json_int(session, abuf, "prefixLen", gw->external_prefix.prefix_len);
424 abuf_json_int(session, abuf, "uplink", gw->uplink);
425 abuf_json_int(session, abuf, "downlink", gw->downlink);
426 abuf_json_float(session, abuf, "cost", get_gwcost_scaled(gw->path_cost));
427 abuf_json_boolean(session, abuf, "IPv4", gw->ipv4);
428 abuf_json_boolean(session, abuf, "IPv4-NAT", gw->ipv4nat);
429 abuf_json_boolean(session, abuf, "IPv6", gw->ipv6);
430 abuf_json_int(session, abuf, "expireTime", gw->expire_timer ? (gw->expire_timer->timer_clock - now_times) : 0);
431 abuf_json_int(session, abuf, "cleanupTime", gw->cleanup_timer ? (gw->cleanup_timer->timer_clock - now_times) : 0);
433 abuf_json_float(session, abuf, "pathcost", get_linkcost_scaled(!tc ? ROUTE_COST_BROKEN : tc->path_cost, true));
434 abuf_json_int(session, abuf, "hops", !tc ? 0 : tc->hops);
436 #endif /* __linux__ */
438 static void ipc_print_neighbors_internal(struct json_session *session, struct autobuf *abuf, bool list_2hop) {
439 struct neighbor_entry *neigh;
444 abuf_json_mark_object(session, true, true, abuf, "neighbors");
446 abuf_json_mark_object(session, true, true, abuf, "2hop");
450 OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
451 struct neighbor_2_list_entry *list_2;
454 abuf_json_mark_array_entry(session, true, abuf);
456 abuf_json_ip_address(session, abuf, "ipAddress", &neigh->neighbor_main_addr);
457 abuf_json_boolean(session, abuf, "symmetric", (neigh->status == SYM));
458 abuf_json_int(session, abuf, "willingness", neigh->willingness);
459 abuf_json_boolean(session, abuf, "isMultiPointRelay", neigh->is_mpr);
460 abuf_json_boolean(session, abuf, "wasMultiPointRelay", neigh->was_mpr);
461 abuf_json_boolean(session, abuf, "multiPointRelaySelector", olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
462 abuf_json_boolean(session, abuf, "skip", neigh->skip);
463 abuf_json_int(session, abuf, "neighbor2nocov", neigh->neighbor_2_nocov);
464 abuf_json_int(session, abuf, "linkcount", neigh->linkcount);
467 abuf_json_mark_object(session, true, true, abuf, "twoHopNeighbors");
471 for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
472 if (list_2hop && list_2->neighbor_2) {
473 abuf_json_ip_address(session, abuf, NULL, &list_2->neighbor_2->neighbor_2_addr);
479 abuf_json_mark_object(session, false, true, abuf, NULL);
481 abuf_json_int(session, abuf, "twoHopNeighborCount", thop_cnt);
483 abuf_json_mark_array_entry(session, false, abuf);
484 } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
485 abuf_json_mark_object(session, false, true, abuf, NULL);
488 void ipc_print_neighbors(struct autobuf *abuf) {
489 ipc_print_neighbors_internal(&json_session, abuf, false);
492 void ipc_print_links(struct autobuf *abuf) {
493 struct link_entry *my_link;
495 abuf_json_mark_object(&json_session, true, true, abuf, "links");
497 OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
498 struct lqtextbuffer lqBuffer;
499 const char* lqString = get_link_entry_text(my_link, '\t', &lqBuffer);
500 char * nlqString = strrchr(lqString, '\t');
507 abuf_json_mark_array_entry(&json_session, true, abuf);
509 abuf_json_ip_address(&json_session, abuf, "localIP", &my_link->local_iface_addr);
510 abuf_json_ip_address(&json_session, abuf, "remoteIP", &my_link->neighbor_iface_addr);
511 abuf_json_string(&json_session, abuf, "olsrInterface", (my_link->inter && my_link->inter->int_name) ? my_link->inter->int_name : "");
512 abuf_json_string(&json_session, abuf, "ifName", my_link->if_name ? my_link->if_name : "");
513 abuf_json_int(&json_session, abuf, "validityTime", my_link->link_timer ? (long) (my_link->link_timer->timer_clock - now_times) : 0);
514 abuf_json_int(&json_session, abuf, "symmetryTime", my_link->link_sym_timer ? (long) (my_link->link_sym_timer->timer_clock - now_times) : 0);
515 abuf_json_int(&json_session, abuf, "asymmetryTime", my_link->ASYM_time);
516 abuf_json_int(&json_session, abuf, "vtime", (long) my_link->vtime);
517 // neighbor (no need to print, can be looked up via neighbours)
518 abuf_json_string(&json_session, abuf, "currentLinkStatus", linkTypeToString(lookup_link_status(my_link)));
519 abuf_json_string(&json_session, abuf, "previousLinkStatus", linkTypeToString(my_link->prev_status));
521 abuf_json_float(&json_session, abuf, "hysteresis", my_link->L_link_quality);
522 abuf_json_boolean(&json_session, abuf, "pending", my_link->L_link_pending != 0);
523 abuf_json_int(&json_session, abuf, "lostLinkTime", (long) my_link->L_LOST_LINK_time);
524 abuf_json_int(&json_session, abuf, "helloTime", my_link->link_hello_timer ? (long) (my_link->link_hello_timer->timer_clock - now_times) : 0);
525 abuf_json_int(&json_session, abuf, "lastHelloTime", (long) my_link->last_htime);
526 abuf_json_boolean(&json_session, abuf, "seqnoValid", my_link->olsr_seqno_valid);
527 abuf_json_int(&json_session, abuf, "seqno", my_link->olsr_seqno);
529 abuf_json_int(&json_session, abuf, "lossHelloInterval", (long) my_link->loss_helloint);
530 abuf_json_int(&json_session, abuf, "lossTime", my_link->link_loss_timer ? (long) (my_link->link_loss_timer->timer_clock - now_times) : 0);
532 abuf_json_int(&json_session, abuf, "lossMultiplier", (long) my_link->loss_link_multiplier);
534 abuf_json_float(&json_session, abuf, "linkCost", get_linkcost_scaled(my_link->linkcost, false));
536 abuf_json_float(&json_session, abuf, "linkQuality", atof(lqString));
537 abuf_json_float(&json_session, abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
539 abuf_json_mark_array_entry(&json_session, false, abuf);
540 } OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
541 abuf_json_mark_object(&json_session, false, true, abuf, NULL);
544 void ipc_print_routes(struct autobuf *abuf) {
547 abuf_json_mark_object(&json_session, true, true, abuf, "routes");
549 /* Walk the route table */
550 OLSR_FOR_ALL_RT_ENTRIES(rt) {
552 abuf_json_mark_array_entry(&json_session, true, abuf);
553 abuf_json_ip_address(&json_session, abuf, "destination", &rt->rt_dst.prefix);
554 abuf_json_int(&json_session, abuf, "genmask", rt->rt_dst.prefix_len);
555 abuf_json_ip_address(&json_session, abuf, "gateway", &rt->rt_best->rtp_nexthop.gateway);
556 abuf_json_int(&json_session, abuf, "metric", rt->rt_best->rtp_metric.hops);
557 abuf_json_float(&json_session, abuf, "etx", get_linkcost_scaled(rt->rt_best->rtp_metric.cost, true));
558 abuf_json_float(&json_session, abuf, "rtpMetricCost", get_linkcost_scaled(rt->rt_best->rtp_metric.cost, true));
559 abuf_json_string(&json_session, abuf, "networkInterface", if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
560 abuf_json_mark_array_entry(&json_session, false, abuf);
562 } OLSR_FOR_ALL_RT_ENTRIES_END(rt);
564 abuf_json_mark_object(&json_session, false, true, abuf, NULL);
567 void ipc_print_topology(struct autobuf *abuf) {
570 abuf_json_mark_object(&json_session, true, true, abuf, "topology");
573 OLSR_FOR_ALL_TC_ENTRIES(tc) {
574 struct tc_edge_entry *tc_edge;
575 OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
576 if (tc_edge->edge_inv) {
577 struct lqtextbuffer lqbuffer;
578 const char* lqString = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer);
579 char * nlqString = strrchr(lqString, '\t');
586 abuf_json_mark_array_entry(&json_session, true, abuf);
589 abuf_json_ip_address(&json_session, abuf, "lastHopIP", &tc->addr);
591 abuf_json_float(&json_session, abuf, "pathCost", get_linkcost_scaled(tc->path_cost, true));
597 abuf_json_int(&json_session, abuf, "validityTime", tc->validity_timer ? (tc->validity_timer->timer_clock - now_times) : 0);
598 abuf_json_int(&json_session, abuf, "refCount", tc->refcount);
599 abuf_json_int(&json_session, abuf, "msgSeq", tc->msg_seq);
600 abuf_json_int(&json_session, abuf, "msgHops", tc->msg_hops);
601 abuf_json_int(&json_session, abuf, "hops", tc->hops);
602 abuf_json_int(&json_session, abuf, "ansn", tc->ansn);
603 abuf_json_int(&json_session, abuf, "tcIgnored", tc->ignored);
605 abuf_json_int(&json_session, abuf, "errSeq", tc->err_seq);
606 abuf_json_boolean(&json_session, abuf, "errSeqValid", tc->err_seq_valid);
609 abuf_json_ip_address(&json_session, abuf, "destinationIP", &tc_edge->T_dest_addr);
611 abuf_json_float(&json_session, abuf, "tcEdgeCost", get_linkcost_scaled(tc_edge->cost, true));
612 abuf_json_int(&json_session, abuf, "ansnEdge", tc_edge->ansn);
613 abuf_json_float(&json_session, abuf, "linkQuality", atof(lqString));
614 abuf_json_float(&json_session, abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
616 abuf_json_mark_array_entry(&json_session, false, abuf);
618 } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
619 } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
621 abuf_json_mark_object(&json_session, false, true, abuf, NULL);
624 void ipc_print_hna(struct autobuf *abuf) {
625 struct ip_prefix_list *hna;
626 struct hna_entry *tmp_hna;
628 abuf_json_mark_object(&json_session, true, true, abuf, "hna");
630 /* Announced HNA entries */
631 for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
632 print_hna_array_entry( //
635 &olsr_cnf->main_addr, //
637 hna->net.prefix_len, //
641 OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
642 struct hna_net *tmp_net;
644 /* Check all networks */
645 for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
646 print_hna_array_entry( //
649 &tmp_hna->A_gateway_addr, //
650 &tmp_net->hna_prefix.prefix, //
651 tmp_net->hna_prefix.prefix_len, //
652 tmp_net->hna_net_timer ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0);
654 } OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
656 abuf_json_mark_object(&json_session, false, true, abuf, NULL);
659 void ipc_print_mid(struct autobuf *abuf) {
662 abuf_json_mark_object(&json_session, true, true, abuf, "mid");
665 for (idx = 0; idx < HASHSIZE; idx++) {
666 struct mid_entry * entry = mid_set[idx].next;
668 while (entry != &mid_set[idx]) {
669 abuf_json_mark_array_entry(&json_session, true, abuf);
671 abuf_json_mark_object(&json_session, true, false, abuf, "main");
672 abuf_json_ip_address(&json_session, abuf, "ipAddress", &entry->main_addr);
673 abuf_json_int(&json_session, abuf, "validityTime", entry->mid_timer ? (entry->mid_timer->timer_clock - now_times) : 0);
674 abuf_json_mark_object(&json_session, false, false, abuf, NULL); // main
677 struct mid_address * alias = entry->aliases;
679 abuf_json_mark_object(&json_session, true, true, abuf, "aliases");
681 abuf_json_mark_array_entry(&json_session, true, abuf);
682 abuf_json_ip_address(&json_session, abuf, "ipAddress", &alias->alias);
683 abuf_json_int(&json_session, abuf, "validityTime", alias->vtime - now_times);
684 abuf_json_mark_array_entry(&json_session, false, abuf);
686 alias = alias->next_alias;
688 abuf_json_mark_object(&json_session, false, true, abuf, NULL); // aliases
690 abuf_json_mark_array_entry(&json_session, false, abuf); // entry
695 abuf_json_mark_object(&json_session, false, true, abuf, NULL); // mid
700 static void ipc_print_gateways_ipvx(struct json_session *session, struct autobuf *abuf, bool ipv6) {
703 abuf_json_mark_object(session, true, true, abuf, ipv6 ? "ipv6" : "ipv4");
705 if (olsr_cnf->smart_gw_active) {
706 struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
707 struct gateway_entry * gw;
708 OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
709 if ((!ipv6 && !gw->ipv4) || (ipv6 && !gw->ipv6)) {
710 /* gw does not advertise the requested IP version */
714 abuf_json_mark_array_entry(session, true, abuf);
715 ipc_print_gateway_entry(session, abuf, ipv6, current_gw, gw);
716 abuf_json_mark_array_entry(session, false, abuf);
717 } OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
720 abuf_json_mark_object(session, false, true, abuf, NULL);
722 #endif /* __linux__ */
724 void ipc_print_gateways(struct autobuf *abuf) {
726 abuf_json_string(&json_session, abuf, "error", "Gateway mode is only supported in Linux");
727 #else /* __linux__ */
728 abuf_json_mark_object(&json_session, true, false, abuf, "gateways");
730 ipc_print_gateways_ipvx(&json_session, abuf, false);
731 ipc_print_gateways_ipvx(&json_session, abuf, true);
733 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
734 #endif /* __linux__ */
739 /** interface names for smart gateway tunnel interfaces, IPv4 */
740 extern struct interfaceName * sgwTunnel4InterfaceNames;
742 /** interface names for smart gateway tunnel interfaces, IPv6 */
743 extern struct interfaceName * sgwTunnel6InterfaceNames;
746 * Construct the sgw table for a given ip version
748 * @param abuf the string buffer
749 * @param ipv6 true for IPv6, false for IPv4
750 * @param fmtv the format for printing
752 static void sgw_ipvx(struct json_session *session, struct autobuf *abuf, bool ipv6) {
753 struct interfaceName * sgwTunnelInterfaceNames;
757 sgwTunnelInterfaceNames = !ipv6 ? sgwTunnel4InterfaceNames : sgwTunnel6InterfaceNames;
759 abuf_json_mark_object(session, true, true, abuf, ipv6 ? "ipv6" : "ipv4");
761 if (olsr_cnf->smart_gw_active && sgwTunnelInterfaceNames) {
762 struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
764 for (i = 0; i < olsr_cnf->smart_gw_use_count; i++) {
765 struct interfaceName * node = &sgwTunnelInterfaceNames[i];
766 struct gateway_entry * gw = node->gw;
772 abuf_json_mark_array_entry(session, true, abuf);
773 ipc_print_gateway_entry(session, abuf, ipv6, current_gw, gw);
774 abuf_json_ip_address(session, abuf, "destination", &gw->originator);
775 abuf_json_string(session, abuf, "tunnel", node->name);
776 abuf_json_int(session, abuf, "tableNr", node->tableNr);
777 abuf_json_int(session, abuf, "ruleNr", node->ruleNr);
778 abuf_json_int(session, abuf, "bypassRuleNr", node->bypassRuleNr);
779 abuf_json_mark_array_entry(session, false, abuf);
783 abuf_json_mark_object(session, false, true, abuf, NULL);
786 static void sgw_egress_bw(struct json_session *session, struct autobuf * abuf, const char * key, struct egress_if_bw * bw) {
787 abuf_json_mark_object(session, true, false, abuf, key);
789 abuf_json_int(session, abuf, "egressUk", bw->egressUk);
790 abuf_json_int(session, abuf, "egressDk", bw->egressDk);
791 abuf_json_float(session, abuf, "pathCost", get_linkcost_scaled(bw->path_cost, true));
792 abuf_json_ip_address(session, abuf, "network", &bw->network.prefix);
793 abuf_json_int(session, abuf, "networkLength", bw->network.prefix_len);
794 abuf_json_ip_address(session, abuf, "gateway", &bw->gateway);
795 abuf_json_boolean(session, abuf, "networkSet", bw->networkSet);
796 abuf_json_boolean(session, abuf, "gatewaySet", bw->gatewaySet);
797 abuf_json_float(session, abuf, "costs", get_gwcost_scaled(bw->costs));
799 abuf_json_mark_object(session, false, false, abuf, NULL);
802 static void sgw_egress_route_info(struct json_session *session, struct autobuf * abuf, const char * key, struct sgw_route_info * ri) {
803 abuf_json_mark_object(session, true, false, abuf, key);
805 abuf_json_boolean(session, abuf, "active", ri->active);
806 abuf_json_int(session, abuf, "family", ri->route.family);
807 abuf_json_int(session, abuf, "rtTable", ri->route.rttable);
808 abuf_json_int(session, abuf, "flags", ri->route.flags);
809 abuf_json_int(session, abuf, "scope", ri->route.scope);
810 abuf_json_int(session, abuf, "ifIndex", ri->route.if_index);
811 abuf_json_int(session, abuf, "metric", ri->route.metric);
812 abuf_json_int(session, abuf, "protocol", ri->route.protocol);
813 abuf_json_boolean(session, abuf, "srcSet", ri->route.srcSet);
814 abuf_json_boolean(session, abuf, "gwSet", ri->route.gwSet);
815 abuf_json_boolean(session, abuf, "dstSet", ri->route.dstSet);
816 abuf_json_boolean(session, abuf, "delSimilar", ri->route.del_similar);
817 abuf_json_boolean(session, abuf, "blackhole", ri->route.blackhole);
818 abuf_json_ip_address(session, abuf, "srcStore", &ri->route.srcStore);
819 abuf_json_ip_address(session, abuf, "gwStore", &ri->route.gwStore);
820 abuf_json_ip_address(session, abuf, "dstStore", &ri->route.dstStore.prefix);
821 abuf_json_int(session, abuf, "dstStoreLength", ri->route.dstStore.prefix_len);
823 abuf_json_mark_object(session, false, false, abuf, NULL);
826 static void sgw_egress(struct json_session *session, struct autobuf * abuf) {
827 struct sgw_egress_if * egress_if;
829 abuf_json_mark_object(session, true, true, abuf, "egress");
831 egress_if = olsr_cnf->smart_gw_egress_interfaces;
833 abuf_json_mark_array_entry(session, true, abuf);
835 abuf_json_boolean(session, abuf, "selected", isEgressSelected(egress_if));
836 abuf_json_string(session, abuf, "name", egress_if->name);
837 abuf_json_int(session, abuf, "ifIndex", egress_if->if_index);
838 abuf_json_int(session, abuf, "tableNr", egress_if->tableNr);
839 abuf_json_int(session, abuf, "ruleNr", egress_if->ruleNr);
840 abuf_json_int(session, abuf, "bypassRuleNr", egress_if->bypassRuleNr);
841 abuf_json_boolean(session, abuf, "upPrevious", egress_if->upPrevious);
842 abuf_json_boolean(session, abuf, "upCurrent", egress_if->upCurrent);
843 abuf_json_boolean(session, abuf, "upChanged", egress_if->upChanged);
844 sgw_egress_bw(session, abuf, "bwPrevious", &egress_if->bwPrevious);
845 sgw_egress_bw(session, abuf, "bwCurrent", &egress_if->bwCurrent);
846 abuf_json_boolean(session, abuf, "bwCostsChanged", egress_if->bwCostsChanged);
847 abuf_json_boolean(session, abuf, "bwNetworkChanged", egress_if->bwNetworkChanged);
848 abuf_json_boolean(session, abuf, "bwGatewayChanged", egress_if->bwGatewayChanged);
849 abuf_json_boolean(session, abuf, "bwChanged", egress_if->bwChanged);
850 sgw_egress_route_info(session, abuf, "networkRouteCurrent", &egress_if->networkRouteCurrent);
851 sgw_egress_route_info(session, abuf, "egressRouteCurrent", &egress_if->egressRouteCurrent);
852 abuf_json_boolean(session, abuf, "inEgressFile", egress_if->inEgressFile);
854 abuf_json_mark_array_entry(session, false, abuf);
855 egress_if = egress_if->next;
858 abuf_json_mark_object(session, false, true, abuf, NULL);
860 #endif /* __linux__ */
862 void ipc_print_sgw(struct autobuf *abuf) {
864 abuf_json_string(&json_session, abuf, "error", "Gateway mode is only supported in Linux");
866 abuf_json_mark_object(&json_session, true, false, abuf, "sgw");
868 sgw_egress(&json_session, abuf);
869 sgw_ipvx(&json_session, abuf, false);
870 sgw_ipvx(&json_session, abuf, true);
872 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
873 #endif /* __linux__ */
876 void ipc_print_version(struct autobuf *abuf) {
877 abuf_json_mark_object(&json_session, true, false, abuf, "version");
879 abuf_json_string(&json_session, abuf, "version", olsrd_version);
881 abuf_json_string(&json_session, abuf, "date", build_date);
882 abuf_json_string(&json_session, abuf, "host", build_host);
883 abuf_json_string(&json_session, abuf, "gitDescriptor", git_descriptor);
884 abuf_json_string(&json_session, abuf, "gitSha", git_sha);
885 abuf_json_string(&json_session, abuf, "releaseVersion", release_version);
886 abuf_json_string(&json_session, abuf, "sourceHash", source_hash);
888 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
891 void ipc_print_olsrd_conf(struct autobuf *abuf) {
892 olsrd_write_cnf_autobuf(abuf, olsr_cnf);
895 void ipc_print_interfaces(struct autobuf *abuf) {
898 abuf_json_mark_object(&json_session, true, true, abuf, "interfaces");
899 for (ifs = olsr_cnf->interfaces; ifs != NULL ; ifs = ifs->next) {
900 abuf_json_mark_array_entry(&json_session, true, abuf);
901 abuf_json_string(&json_session, abuf, "name", ifs->name);
902 abuf_json_boolean(&json_session, abuf, "configured", ifs->configured);
903 abuf_json_boolean(&json_session, abuf, "hostEmulation", ifs->host_emul);
904 abuf_json_ip_address(&json_session, abuf, "hostEmulationAddress", &ifs->hemu_ip);
905 print_interface_olsr(&json_session, abuf, "olsrInterface", ifs->interf);
906 print_interface_config(&json_session, abuf, "InterfaceConfiguration", ifs->cnf);
907 print_interface_config(&json_session, abuf, "InterfaceConfigurationDefaults", ifs->cnfi);
908 abuf_json_mark_array_entry(&json_session, false, abuf);
910 abuf_json_mark_object(&json_session, false, true, abuf, NULL); // interfaces
913 void ipc_print_twohop(struct autobuf *abuf) {
914 ipc_print_neighbors_internal(&json_session, abuf, true);
917 void ipc_print_config(struct autobuf *abuf) {
918 abuf_json_mark_object(&json_session, true, false, abuf, "config");
920 abuf_json_string(&json_session, abuf, "configurationFile", olsr_cnf->configuration_file);
921 abuf_json_int(&json_session, abuf, "olsrPort", olsr_cnf->olsrport);
922 abuf_json_int(&json_session, abuf, "debugLevel", olsr_cnf->debug_level);
923 abuf_json_boolean(&json_session, abuf, "noFork", olsr_cnf->no_fork);
924 abuf_json_string(&json_session, abuf, "pidFile", olsr_cnf->pidfile);
925 abuf_json_boolean(&json_session, abuf, "hostEmulation", olsr_cnf->host_emul);
926 abuf_json_int(&json_session, abuf, "ipVersion", (olsr_cnf->ip_version == AF_INET) ? 4 : 6);
927 abuf_json_boolean(&json_session, abuf, "allowNoInt", olsr_cnf->allow_no_interfaces);
928 abuf_json_int(&json_session, abuf, "tosValue", olsr_cnf->tos);
930 abuf_json_int(&json_session, abuf, "rtProto", olsr_cnf->rt_proto);
931 abuf_json_mark_object(&json_session, true, false, abuf, "rtTable");
932 abuf_json_int(&json_session, abuf, "main", olsr_cnf->rt_table);
933 abuf_json_int(&json_session, abuf, "default", olsr_cnf->rt_table_default);
934 abuf_json_int(&json_session, abuf, "tunnel", olsr_cnf->rt_table_tunnel);
935 abuf_json_int(&json_session, abuf, "priority", olsr_cnf->rt_table_pri);
936 abuf_json_int(&json_session, abuf, "tunnelPriority", olsr_cnf->rt_table_tunnel_pri);
937 abuf_json_int(&json_session, abuf, "defaultOlsrPriority", olsr_cnf->rt_table_defaultolsr_pri);
938 abuf_json_int(&json_session, abuf, "defaultPriority", olsr_cnf->rt_table_default_pri);
939 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
941 abuf_json_mark_object(&json_session, true, false, abuf, "willingness");
942 abuf_json_int(&json_session, abuf, "willingness", olsr_cnf->willingness);
943 abuf_json_boolean(&json_session, abuf, "auto", olsr_cnf->willingness_auto);
944 abuf_json_float(&json_session, abuf, "updateInterval", olsr_cnf->will_int);
945 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
948 // ipc_connections: later
950 abuf_json_mark_object(&json_session, true, false, abuf, "fib");
951 abuf_json_string(&json_session, abuf, "metric", ((olsr_cnf->fib_metric < FIBM_FLAT) || (olsr_cnf->fib_metric >= FIBM_CNT)) ? "" : FIB_METRIC_TXT[olsr_cnf->fib_metric]);
952 abuf_json_string(&json_session, abuf, "metricDefault", FIB_METRIC_TXT[olsr_cnf->fib_metric_default]);
953 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
956 abuf_json_mark_object(&json_session, true, false, abuf, "hysteresis");
957 abuf_json_boolean(&json_session, abuf, "enabled", olsr_cnf->use_hysteresis);
958 abuf_json_float(&json_session, abuf, "scaling", olsr_cnf->hysteresis_param.scaling);
959 abuf_json_float(&json_session, abuf, "thresholdLow", olsr_cnf->hysteresis_param.thr_low);
960 abuf_json_float(&json_session, abuf, "thresholdHigh", olsr_cnf->hysteresis_param.thr_high);
961 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
966 struct ip_prefix_list *hna;
968 abuf_json_mark_object(&json_session, true, true, abuf, "hna");
970 /* Announced HNA entries */
971 for (hna = olsr_cnf->hna_entries; hna; hna = hna->next) {
972 print_hna_array_entry( //
975 &olsr_cnf->main_addr, //
977 hna->net.prefix_len, //
980 abuf_json_mark_object(&json_session, false, true, abuf, NULL);
983 // interface_defaults: later
985 abuf_json_float(&json_session, abuf, "pollrate", olsr_cnf->pollrate);
986 abuf_json_float(&json_session, abuf, "nicChgsPollInt", olsr_cnf->nic_chgs_pollrate);
987 abuf_json_boolean(&json_session, abuf, "clearScreen", olsr_cnf->clear_screen);
988 abuf_json_int(&json_session, abuf, "tcRedundancy", olsr_cnf->tc_redundancy);
989 abuf_json_int(&json_session, abuf, "mprCoverage", olsr_cnf->mpr_coverage);
992 abuf_json_mark_object(&json_session, true, false, abuf, "linkQuality");
993 abuf_json_int(&json_session, abuf, "level", olsr_cnf->lq_level);
994 abuf_json_boolean(&json_session, abuf, "fishEye", olsr_cnf->lq_fish);
995 abuf_json_float(&json_session, abuf, "aging", olsr_cnf->lq_aging);
996 abuf_json_string(&json_session, abuf, "algorithm", olsr_cnf->lq_algorithm);
997 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
999 abuf_json_float(&json_session, abuf, "minTCVTime", olsr_cnf->min_tc_vtime);
1001 abuf_json_boolean(&json_session, abuf, "setIpForward", olsr_cnf->set_ip_forward);
1003 abuf_json_string(&json_session, abuf, "lockFile", olsr_cnf->lock_file);
1004 abuf_json_boolean(&json_session, abuf, "useNiit", olsr_cnf->use_niit);
1006 abuf_json_mark_object(&json_session, true, false, abuf, "smartGateway");
1007 abuf_json_boolean(&json_session, abuf, "enabled", olsr_cnf->smart_gw_active);
1008 abuf_json_boolean(&json_session, abuf, "alwaysRemoveServerTunnel", olsr_cnf->smart_gw_always_remove_server_tunnel);
1009 abuf_json_boolean(&json_session, abuf, "allowNAT", olsr_cnf->smart_gw_allow_nat);
1010 abuf_json_boolean(&json_session, abuf, "uplinkNAT", olsr_cnf->smart_gw_uplink_nat);
1011 abuf_json_int(&json_session, abuf, "useCount", olsr_cnf->smart_gw_use_count);
1012 abuf_json_int(&json_session, abuf, "takeDownPercentage", olsr_cnf->smart_gw_takedown_percentage);
1013 abuf_json_string(&json_session, abuf, "instanceId", olsr_cnf->smart_gw_instance_id);
1014 abuf_json_string(&json_session, abuf, "policyRoutingScript", olsr_cnf->smart_gw_policyrouting_script);
1016 abuf_json_mark_object(&json_session, true, false, abuf, "egress");
1017 // smart_gw_egress_interfaces
1019 struct sgw_egress_if * egressif = olsr_cnf->smart_gw_egress_interfaces;
1021 abuf_json_mark_object(&json_session, true, true, abuf, "interfaces");
1023 abuf_json_string(&json_session, abuf, NULL, egressif->name);
1024 egressif = egressif->next;
1026 abuf_json_mark_object(&json_session, false, true, abuf, NULL);
1028 abuf_json_int(&json_session, abuf, "interfacesCount", olsr_cnf->smart_gw_egress_interfaces_count);
1029 abuf_json_string(&json_session, abuf, "file", olsr_cnf->smart_gw_egress_file);
1030 abuf_json_int(&json_session, abuf, "filePeriod", olsr_cnf->smart_gw_egress_file_period);
1031 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
1033 abuf_json_string(&json_session, abuf, "statusFile", olsr_cnf->smart_gw_status_file);
1034 abuf_json_int(&json_session, abuf, "tablesOffset", olsr_cnf->smart_gw_offset_tables);
1035 abuf_json_int(&json_session, abuf, "rulesOffset", olsr_cnf->smart_gw_offset_rules);
1036 abuf_json_int(&json_session, abuf, "period", olsr_cnf->smart_gw_period);
1037 abuf_json_int(&json_session, abuf, "stableCount", olsr_cnf->smart_gw_stablecount);
1038 abuf_json_int(&json_session, abuf, "threshold", olsr_cnf->smart_gw_thresh);
1040 abuf_json_mark_object(&json_session, true, false, abuf, "costsCalculation");
1041 abuf_json_int(&json_session, abuf, "exitLinkUp", olsr_cnf->smart_gw_weight_exitlink_up);
1042 abuf_json_int(&json_session, abuf, "exitLinkDown", olsr_cnf->smart_gw_weight_exitlink_down);
1043 abuf_json_int(&json_session, abuf, "etx", olsr_cnf->smart_gw_weight_etx);
1044 abuf_json_int(&json_session, abuf, "dividerEtx", olsr_cnf->smart_gw_divider_etx);
1045 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
1047 abuf_json_int(&json_session, abuf, "maxCostMaxEtx", olsr_cnf->smart_gw_path_max_cost_etx_max);
1048 abuf_json_string(&json_session, abuf, "uplink", ((olsr_cnf->smart_gw_type < GW_UPLINK_NONE) || (olsr_cnf->smart_gw_type >= GW_UPLINK_CNT)) ? "" : GW_UPLINK_TXT[olsr_cnf->smart_gw_type]);
1050 abuf_json_mark_object(&json_session, true, false, abuf, "bandwidth");
1051 abuf_json_int(&json_session, abuf, "uplinkKbps", olsr_cnf->smart_gw_uplink);
1052 abuf_json_int(&json_session, abuf, "downlinkKbps", olsr_cnf->smart_gw_downlink);
1053 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
1055 abuf_json_mark_object(&json_session, true, false, abuf, "prefix");
1056 abuf_json_ip_address(&json_session, abuf, "prefix", &olsr_cnf->smart_gw_prefix.prefix);
1057 abuf_json_int(&json_session, abuf, "length", olsr_cnf->smart_gw_prefix.prefix_len);
1058 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
1060 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
1063 abuf_json_ip_address(&json_session, abuf, "mainIp", &olsr_cnf->main_addr);
1064 abuf_json_ip_address(&json_session, abuf, "unicastSourceIpAddress", &olsr_cnf->unicast_src_ip);
1065 abuf_json_boolean(&json_session, abuf, "srcIpRoutes", olsr_cnf->use_src_ip_routes);
1068 abuf_json_int(&json_session, abuf, "maxPrefixLength", olsr_cnf->maxplen);
1069 abuf_json_int(&json_session, abuf, "ipSize", olsr_cnf->ipsize);
1070 abuf_json_boolean(&json_session, abuf, "delgw", olsr_cnf->del_gws);
1071 abuf_json_float(&json_session, abuf, "maxSendMessageJitter", olsr_cnf->max_jitter);
1072 abuf_json_int(&json_session, abuf, "exitValue", olsr_cnf->exit_value);
1073 abuf_json_float(&json_session, abuf, "maxTcValidTime", olsr_cnf->max_tc_vtime);
1075 abuf_json_int(&json_session, abuf, "niit4to6InterfaceIndex", olsr_cnf->niit4to6_if_index);
1076 abuf_json_int(&json_session, abuf, "niit6to4InterfaceIndex", olsr_cnf->niit6to4_if_index);
1079 abuf_json_boolean(&json_session, abuf, "hasIpv4Gateway", olsr_cnf->has_ipv4_gateway);
1080 abuf_json_boolean(&json_session, abuf, "hasIpv6Gateway", olsr_cnf->has_ipv6_gateway);
1082 abuf_json_int(&json_session, abuf, "ioctlSocket", olsr_cnf->ioctl_s);
1084 abuf_json_int(&json_session, abuf, "routeNetlinkSocket", olsr_cnf->rtnl_s);
1085 abuf_json_int(&json_session, abuf, "routeMonitorSocket", olsr_cnf->rt_monitor_socket);
1086 #endif /* __linux__ */
1088 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
1089 abuf_json_int(&json_session, abuf, "routeChangeSocket", olsr_cnf->rts);
1090 #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ */
1091 abuf_json_float(&json_session, abuf, "linkQualityNatThreshold", olsr_cnf->lq_nat_thresh);
1095 abuf_json_int(&json_session, abuf, "brokenLinkCost", LINK_COST_BROKEN);
1096 abuf_json_int(&json_session, abuf, "brokenRouteCost", ROUTE_COST_BROKEN);
1099 // IpcConnect section
1100 abuf_json_int(&json_session, abuf, "ipcConnectMaxConnections", olsr_cnf->ipc_connections);
1102 struct ip_prefix_list *ipc_nets;
1104 abuf_json_mark_object(&json_session, true, true, abuf, "ipcConnectAllowed");
1105 for (ipc_nets = olsr_cnf->ipc_nets; ipc_nets; ipc_nets = ipc_nets->next) {
1106 print_ipc_net_array_entry(&json_session, abuf, ipc_nets);
1108 abuf_json_mark_object(&json_session, false, true, abuf, NULL);
1112 // plugins section: use /plugins
1115 // InterfaceDefaults section
1116 print_interface_config(&json_session, abuf, "interfaceDefaults", olsr_cnf->interface_defaults);
1119 // Interface(s) section: use /interfaces
1123 #if defined _WIN32 || defined _WIN64
1124 abuf_json_string(&json_session, abuf, "os", "Windows");
1125 #elif defined __gnu_linux__
1126 abuf_json_string(&json_session, abuf, "os", "GNU/Linux");
1127 #elif defined __ANDROID__
1128 abuf_json_string(&json_session, abuf, "os", "Android");
1129 #elif defined __APPLE__
1130 abuf_json_string(&json_session, abuf, "os", "Mac OS X");
1131 #elif defined __NetBSD__
1132 abuf_json_string(&json_session, abuf, "os", "NetBSD");
1133 #elif defined __OpenBSD__
1134 abuf_json_string(&json_session, abuf, "os", "OpenBSD");
1135 #elif defined __FreeBSD__ || defined __FreeBSD_kernel__
1136 abuf_json_string(&json_session, abuf, "os", "FreeBSD");
1137 #else /* OS detection */
1138 abuf_json_string(&json_session, abuf, "os", "Undefined");
1139 #endif /* OS detection */
1141 abuf_json_int(&json_session, abuf, "startTime", start_time.tv_sec);
1143 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
1146 void ipc_print_plugins(struct autobuf *abuf) {
1147 abuf_json_mark_object(&json_session, true, true, abuf, "plugins");
1148 if (olsr_cnf->plugins) {
1149 struct plugin_entry *plugin;
1151 for (plugin = olsr_cnf->plugins; plugin; plugin = plugin->next) {
1152 struct plugin_param *param;
1154 abuf_json_mark_array_entry(&json_session, true, abuf);
1155 abuf_json_string(&json_session, abuf, "plugin", plugin->name);
1157 abuf_json_mark_object(&json_session, true, false, abuf, "parameters");
1158 for (param = plugin->params; param; param = param->next) {
1159 abuf_json_string(&json_session, abuf, param->key, param->value);
1161 abuf_json_mark_object(&json_session, false, false, abuf, NULL);
1163 abuf_json_mark_array_entry(&json_session, false, abuf);
1166 abuf_json_mark_object(&json_session, false, true, abuf, NULL);