2 * The olsr.org Optimized Link-State Routing daemon(olsrd)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 * Visit http://www.olsr.org for more information.
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.
42 #include "olsrd_jsoninfo.h"
49 #include "builddata.h"
50 #include "neighbor_table.h"
51 #include "mpr_selector_set.h"
53 #include "routing_table.h"
54 #include "lq_plugin.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"
63 struct timeval start_time;
65 void plugin_init(const char *plugin_name) {
67 gettimeofday(&start_time, NULL);
69 if (!strlen(uuidfile)) {
70 strscpy(uuidfile, "uuid.txt", sizeof(uuidfile));
72 read_uuid_from_file(plugin_name, uuidfile);
75 bool isCommand(const char *str, unsigned long long siw) {
146 case SIW_NEIGHBORS_FREIFUNK:
154 return !strcmp(str, cmd);
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";
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);
166 abuf_json_int(abuf, "systemTime", time(NULL));
167 abuf_json_int(abuf, "timeSinceStartup", now_times);
169 abuf_json_string(abuf, "uuid", uuid);
173 void output_end(struct autobuf *abuf) {
174 abuf_json_mark_output(false, abuf);
175 abuf_puts(abuf, "\n");
178 void output_error(struct autobuf *abuf, unsigned int status, const char * req, bool http_headers) {
179 struct autobuf abufInternal;
181 if (http_headers || (status == INFO_HTTP_OK)) {
185 abuf_init(&abufInternal, 1024);
190 case INFO_HTTP_NOTFOUND:
191 abuf_appendf(&abufInternal, "Invalid request '%s'", req);
192 abuf_json_string(abuf, "error", abufInternal.buf);
195 case INFO_HTTP_NOCONTENT:
196 abuf_json_string(abuf, "error", "no content");
200 abuf_appendf(&abufInternal, "Unknown status %d for request '%s'", status, req);
201 abuf_json_string(abuf, "error", abufInternal.buf);
208 static void print_msg_params(struct autobuf *abuf, struct olsr_msg_params *params, const char * name) {
213 abuf_json_mark_object(true, false, abuf, name);
214 abuf_json_float(abuf, "emissionInterval", params->emission_interval);
215 abuf_json_float(abuf, "validityTime", params->validity_time);
216 abuf_json_mark_object(false, false, abuf, NULL);
219 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) {
222 abuf_json_mark_array_entry(true, abuf);
223 abuf_json_ip_address(abuf, "gateway", gw);
224 abuf_json_ip_address(abuf, "destination", ip);
225 abuf_json_int(abuf, "genmask", prefix_len);
226 abuf_json_int(abuf, "validityTime", validityTime);
227 abuf_json_mark_array_entry(false, abuf);
230 static void print_link_quality_multipliers_array_entry(struct autobuf *abuf, struct olsr_lq_mult *mult) {
234 abuf_json_mark_array_entry(true, abuf);
235 abuf_json_ip_address(abuf, "route", &mult->addr);
236 abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
237 abuf_json_mark_array_entry(false, abuf);
240 static void print_ipc_net_array_entry(struct autobuf *abuf, struct ip_prefix_list *ipc_nets) {
244 abuf_json_mark_array_entry(true, abuf);
245 abuf_json_boolean(abuf, "host", (ipc_nets->net.prefix_len == olsr_cnf->maxplen));
246 abuf_json_ip_address(abuf, "ipAddress", &ipc_nets->net.prefix);
247 abuf_json_int(abuf, "genmask", ipc_nets->net.prefix_len);
248 abuf_json_mark_array_entry(false, abuf);
251 static void print_interface_config(struct autobuf *abuf, const char * name, struct if_config_options* id) {
255 abuf_json_mark_object(true, false, abuf, name);
257 struct olsr_lq_mult *mult;
259 abuf_json_ip_address(abuf, "ipv4Broadcast", &id->ipv4_multicast);
260 abuf_json_ip_address(abuf, "ipv6Multicast", &id->ipv6_multicast);
262 abuf_json_ip_address(abuf, "ipv4Source", &id->ipv4_src);
263 abuf_json_ip_address(abuf, "ipv6Source", &id->ipv6_src.prefix);
264 abuf_json_int(abuf, "ipv6SourcePrefixLength", id->ipv6_src.prefix_len);
266 abuf_json_string(abuf, "mode", ((id->mode < IF_MODE_MESH) || (id->mode >= IF_MODE_CNT)) ? "" : OLSR_IF_MODE[id->mode]);
268 abuf_json_int(abuf, "weightValue", id->weight.value);
269 abuf_json_boolean(abuf, "weightFixed", id->weight.fixed);
270 print_msg_params(abuf, &id->hello_params, "hello");
271 print_msg_params(abuf, &id->tc_params, "tc");
272 print_msg_params(abuf, &id->mid_params, "mid");
273 print_msg_params(abuf, &id->hna_params, "hna");
274 abuf_json_mark_object(true, true, abuf, "linkQualityMultipliers");
275 for (mult = olsr_cnf->interface_defaults->lq_mult; mult != NULL ; mult = mult->next) {
276 print_link_quality_multipliers_array_entry(abuf, mult);
278 abuf_json_mark_object(false, true, abuf, NULL);
279 abuf_json_int(abuf, "linkQualityMultipliersCount", id->orig_lq_mult_cnt);
280 abuf_json_boolean(abuf, "autoDetectChanges", id->autodetect_chg);
282 abuf_json_mark_object(false, false, abuf, NULL);
285 static void print_interface_olsr(struct autobuf *abuf, const char * name, struct interface_olsr * rifs) {
289 abuf_json_mark_object(true, false, abuf, name);
290 abuf_json_boolean(abuf, "up", rifs != NULL);
292 abuf_json_mark_object(false, false, abuf, NULL);
296 abuf_json_ip_address46(abuf, "ipv4Address", &rifs->int_addr.sin_addr, AF_INET);
297 abuf_json_ip_address46(abuf, "ipv4Netmask", &rifs->int_netmask.sin_addr, AF_INET);
298 abuf_json_ip_address46(abuf, "ipv4Broadcast", &rifs->int_broadaddr.sin_addr, AF_INET);
299 abuf_json_string(abuf, "mode", ((rifs->mode < IF_MODE_MESH) || (rifs->mode >= IF_MODE_CNT)) ? "" : OLSR_IF_MODE[rifs->mode]);
301 abuf_json_ip_address46(abuf, "ipv6Address", &rifs->int6_addr.sin6_addr, AF_INET6);
302 abuf_json_ip_address46(abuf, "ipv6Multicast", &rifs->int6_multaddr.sin6_addr, AF_INET6);
304 abuf_json_ip_address(abuf, "ipAddress", &rifs->ip_addr);
305 abuf_json_boolean(abuf, "emulatedInterface", rifs->is_hcif);
307 abuf_json_int(abuf, "olsrSocket", rifs->olsr_socket);
308 abuf_json_int(abuf, "sendSocket", rifs->send_socket);
310 abuf_json_int(abuf, "metric", rifs->int_metric);
311 abuf_json_int(abuf, "mtu", rifs->int_mtu);
312 abuf_json_int(abuf, "flags", rifs->int_flags);
313 abuf_json_int(abuf, "index", rifs->if_index);
314 abuf_json_boolean(abuf, "wireless", rifs->is_wireless);
315 abuf_json_string(abuf, "name", rifs->int_name);
316 abuf_json_int(abuf, "seqNum", rifs->olsr_seqnum);
319 abuf_json_mark_object(true, false, abuf, "messageTimes");
320 abuf_json_int(abuf, "hello", rifs->hello_gen_timer ? (long) (rifs->hello_gen_timer->timer_clock - now_times) : 0);
321 abuf_json_int(abuf, "tc", rifs->tc_gen_timer ? (long) (rifs->tc_gen_timer->timer_clock - now_times) : 0);
322 abuf_json_int(abuf, "mid", rifs->mid_gen_timer ? (long) (rifs->mid_gen_timer->timer_clock - now_times) : 0);
323 abuf_json_int(abuf, "hna", rifs->hna_gen_timer ? (long) (rifs->hna_gen_timer->timer_clock - now_times) : 0);
324 abuf_json_mark_object(false, false, abuf, NULL);
331 abuf_json_boolean(abuf, "icmpRedirectBackup", rifs->nic_state.redirect);
334 abuf_json_boolean(abuf, "spoofFilterBackup", rifs->nic_state.spoof);
336 #endif /* __linux__ */
338 abuf_json_int(abuf, "helloEmissionInterval", rifs->hello_etime);
339 abuf_json_mark_object(true, false, abuf, "validityTimes");
340 abuf_json_int(abuf, "hello", me_to_reltime(rifs->valtimes.hello));
341 abuf_json_int(abuf, "tc", me_to_reltime(rifs->valtimes.tc));
342 abuf_json_int(abuf, "mid", me_to_reltime(rifs->valtimes.mid));
343 abuf_json_int(abuf, "hna", me_to_reltime(rifs->valtimes.hna));
344 abuf_json_mark_object(false, false, abuf, NULL);
346 abuf_json_int(abuf, "forwardingTimeout", rifs->fwdtimer);
349 abuf_json_int(abuf, "sgwZeroBwTimeout", rifs->sgw_sgw_zero_bw_timeout);
358 abuf_json_int(abuf, "ttlIndex", rifs->ttl_index);
361 abuf_json_boolean(abuf, "immediateSendTc", rifs->immediate_send_tc);
363 abuf_json_mark_object(false, false, abuf, NULL);
367 static void ipc_print_gateway_entry(struct autobuf *abuf, bool ipv6, struct gateway_entry * current_gw, struct gateway_entry * gw) {
373 tc = olsr_lookup_tc_entry(&gw->originator);
375 abuf_json_boolean(abuf, "selected", current_gw && (current_gw == gw));
376 abuf_json_boolean(abuf, "selectable", isGwSelectable(gw, ipv6));
377 abuf_json_ip_address(abuf, "originator", &gw->originator);
378 abuf_json_ip_address(abuf, "prefix", &gw->external_prefix.prefix);
379 abuf_json_int(abuf, "prefixLen", gw->external_prefix.prefix_len);
380 abuf_json_int(abuf, "uplink", gw->uplink);
381 abuf_json_int(abuf, "downlink", gw->downlink);
382 abuf_json_int(abuf, "cost", gw->path_cost);
383 abuf_json_boolean(abuf, "IPv4", gw->ipv4);
384 abuf_json_boolean(abuf, "IPv4-NAT", gw->ipv4nat);
385 abuf_json_boolean(abuf, "IPv6", gw->ipv6);
386 abuf_json_int(abuf, "expireTime", gw->expire_timer ? (gw->expire_timer->timer_clock - now_times) : 0);
387 abuf_json_int(abuf, "cleanupTime", gw->cleanup_timer ? (gw->cleanup_timer->timer_clock - now_times) : 0);
389 abuf_json_int(abuf, "pathcost", !tc ? ROUTE_COST_BROKEN : tc->path_cost);
390 abuf_json_int(abuf, "hops", !tc ? 0 : tc->hops);
392 #endif /* __linux__ */
394 static void ipc_print_neighbors_internal(struct autobuf *abuf, bool list_2hop) {
395 struct neighbor_entry *neigh;
400 abuf_json_mark_object(true, true, abuf, "neighbors");
402 abuf_json_mark_object(true, true, abuf, "2hop");
406 OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
407 struct neighbor_2_list_entry *list_2;
410 abuf_json_mark_array_entry(true, abuf);
412 abuf_json_ip_address(abuf, "ipAddress", &neigh->neighbor_main_addr);
413 abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
414 abuf_json_int(abuf, "willingness", neigh->willingness);
415 abuf_json_boolean(abuf, "isMultiPointRelay", neigh->is_mpr);
416 abuf_json_boolean(abuf, "wasMultiPointRelay", neigh->was_mpr);
417 abuf_json_boolean(abuf, "multiPointRelaySelector", olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
418 abuf_json_boolean(abuf, "skip", neigh->skip);
419 abuf_json_int(abuf, "neighbor2nocov", neigh->neighbor_2_nocov);
420 abuf_json_int(abuf, "linkcount", neigh->linkcount);
423 abuf_json_mark_object(true, true, abuf, "twoHopNeighbors");
427 for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
428 if (list_2hop && list_2->neighbor_2) {
429 abuf_json_ip_address(abuf, NULL, &list_2->neighbor_2->neighbor_2_addr);
435 abuf_json_mark_object(false, true, abuf, NULL);
437 abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
439 abuf_json_mark_array_entry(false, abuf);
440 } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
441 abuf_json_mark_object(false, true, abuf, NULL);
444 void ipc_print_neighbors(struct autobuf *abuf) {
445 ipc_print_neighbors_internal(abuf, false);
448 void ipc_print_links(struct autobuf *abuf) {
449 struct link_entry *my_link;
451 abuf_json_mark_object(true, true, abuf, "links");
453 OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
454 struct lqtextbuffer lqBuffer;
455 const char* lqString = get_link_entry_text(my_link, '\t', &lqBuffer);
456 char * nlqString = strrchr(lqString, '\t');
463 abuf_json_mark_array_entry(true, abuf);
465 abuf_json_ip_address(abuf, "localIP", &my_link->local_iface_addr);
466 abuf_json_ip_address(abuf, "remoteIP", &my_link->neighbor_iface_addr);
467 abuf_json_string(abuf, "olsrInterface", (my_link->inter && my_link->inter->int_name) ? my_link->inter->int_name : "");
468 abuf_json_string(abuf, "ifName", my_link->if_name ? my_link->if_name : "");
469 abuf_json_int(abuf, "validityTime", my_link->link_timer ? (long) (my_link->link_timer->timer_clock - now_times) : 0);
470 abuf_json_int(abuf, "symmetryTime", my_link->link_sym_timer ? (long) (my_link->link_sym_timer->timer_clock - now_times) : 0);
471 abuf_json_int(abuf, "asymmetryTime", my_link->ASYM_time);
472 abuf_json_int(abuf, "vtime", (long) my_link->vtime);
473 // neighbor (no need to print, can be looked up via neighbours)
474 abuf_json_string(abuf, "currentLinkStatus", linkTypeToString(lookup_link_status(my_link)));
475 abuf_json_string(abuf, "previousLinkStatus", linkTypeToString(my_link->prev_status));
477 abuf_json_float(abuf, "hysteresis", my_link->L_link_quality);
478 abuf_json_boolean(abuf, "pending", my_link->L_link_pending != 0);
479 abuf_json_int(abuf, "lostLinkTime", (long) my_link->L_LOST_LINK_time);
480 abuf_json_int(abuf, "helloTime", my_link->link_hello_timer ? (long) (my_link->link_hello_timer->timer_clock - now_times) : 0);
481 abuf_json_int(abuf, "lastHelloTime", (long) my_link->last_htime);
482 abuf_json_boolean(abuf, "seqnoValid", my_link->olsr_seqno_valid);
483 abuf_json_int(abuf, "seqno", my_link->olsr_seqno);
485 abuf_json_int(abuf, "lossHelloInterval", (long) my_link->loss_helloint);
486 abuf_json_int(abuf, "lossTime", my_link->link_loss_timer ? (long) (my_link->link_loss_timer->timer_clock - now_times) : 0);
488 abuf_json_int(abuf, "lossMultiplier", (long) my_link->loss_link_multiplier);
490 abuf_json_int(abuf, "linkCost", MIN(my_link->linkcost, LINK_COST_BROKEN));
492 abuf_json_float(abuf, "linkQuality", atof(lqString));
493 abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
495 abuf_json_mark_array_entry(false, abuf);
496 } OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
497 abuf_json_mark_object(false, true, abuf, NULL);
500 void ipc_print_routes(struct autobuf *abuf) {
503 abuf_json_mark_object(true, true, abuf, "routes");
505 /* Walk the route table */
506 OLSR_FOR_ALL_RT_ENTRIES(rt) {
507 struct lqtextbuffer costbuffer;
510 abuf_json_mark_array_entry(true, abuf);
511 abuf_json_ip_address(abuf, "destination", &rt->rt_dst.prefix);
512 abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
513 abuf_json_ip_address(abuf, "gateway", &rt->rt_best->rtp_nexthop.gateway);
514 abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
515 abuf_json_float(abuf, "etx", atof(get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &costbuffer)));
516 abuf_json_int(abuf, "rtpMetricCost", MIN(ROUTE_COST_BROKEN, rt->rt_best->rtp_metric.cost));
517 abuf_json_string(abuf, "networkInterface", if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
518 abuf_json_mark_array_entry(false, abuf);
520 } OLSR_FOR_ALL_RT_ENTRIES_END(rt);
522 abuf_json_mark_object(false, true, abuf, NULL);
525 void ipc_print_topology(struct autobuf *abuf) {
528 abuf_json_mark_object(true, true, abuf, "topology");
531 OLSR_FOR_ALL_TC_ENTRIES(tc) {
532 struct tc_edge_entry *tc_edge;
533 OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
534 if (tc_edge->edge_inv) {
535 struct lqtextbuffer lqbuffer;
536 const char* lqString = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer);
537 char * nlqString = strrchr(lqString, '\t');
544 abuf_json_mark_array_entry(true, abuf);
547 abuf_json_ip_address(abuf, "lastHopIP", &tc->addr);
549 abuf_json_int(abuf, "pathCost", MIN(tc->path_cost, ROUTE_COST_BROKEN));
555 abuf_json_int(abuf, "validityTime", tc->validity_timer ? (tc->validity_timer->timer_clock - now_times) : 0);
556 abuf_json_int(abuf, "refCount", tc->refcount);
557 abuf_json_int(abuf, "msgSeq", tc->msg_seq);
558 abuf_json_int(abuf, "msgHops", tc->msg_hops);
559 abuf_json_int(abuf, "hops", tc->hops);
560 abuf_json_int(abuf, "ansn", tc->ansn);
561 abuf_json_int(abuf, "tcIgnored", tc->ignored);
563 abuf_json_int(abuf, "errSeq", tc->err_seq);
564 abuf_json_boolean(abuf, "errSeqValid", tc->err_seq_valid);
567 abuf_json_ip_address(abuf, "destinationIP", &tc_edge->T_dest_addr);
569 abuf_json_int(abuf, "tcEdgeCost", MIN(LINK_COST_BROKEN, tc_edge->cost));
570 abuf_json_int(abuf, "ansnEdge", tc_edge->ansn);
571 abuf_json_float(abuf, "linkQuality", atof(lqString));
572 abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
574 abuf_json_mark_array_entry(false, abuf);
576 } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
577 } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
579 abuf_json_mark_object(false, true, abuf, NULL);
582 void ipc_print_hna(struct autobuf *abuf) {
583 struct ip_prefix_list *hna;
584 struct hna_entry *tmp_hna;
586 abuf_json_mark_object(true, true, abuf, "hna");
588 /* Announced HNA entries */
589 for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
590 print_hna_array_entry( //
592 &olsr_cnf->main_addr, //
594 hna->net.prefix_len, //
598 OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
599 struct hna_net *tmp_net;
601 /* Check all networks */
602 for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
603 print_hna_array_entry( //
605 &tmp_hna->A_gateway_addr, //
606 &tmp_net->hna_prefix.prefix, //
607 tmp_net->hna_prefix.prefix_len, //
608 tmp_net->hna_net_timer ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0);
610 } OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
612 abuf_json_mark_object(false, true, abuf, NULL);
615 void ipc_print_mid(struct autobuf *abuf) {
618 abuf_json_mark_object(true, true, abuf, "mid");
621 for (idx = 0; idx < HASHSIZE; idx++) {
622 struct mid_entry * entry = mid_set[idx].next;
624 while (entry != &mid_set[idx]) {
625 abuf_json_mark_array_entry(true, abuf);
627 abuf_json_mark_object(true, false, abuf, "main");
628 abuf_json_ip_address(abuf, "ipAddress", &entry->main_addr);
629 abuf_json_int(abuf, "validityTime", entry->mid_timer ? (entry->mid_timer->timer_clock - now_times) : 0);
630 abuf_json_mark_object(false, false, abuf, NULL); // main
633 struct mid_address * alias = entry->aliases;
635 abuf_json_mark_object(true, true, abuf, "aliases");
637 abuf_json_mark_array_entry(true, abuf);
638 abuf_json_ip_address(abuf, "ipAddress", &alias->alias);
639 abuf_json_int(abuf, "validityTime", alias->vtime - now_times);
640 abuf_json_mark_array_entry(false, abuf);
642 alias = alias->next_alias;
644 abuf_json_mark_object(false, true, abuf, NULL); // aliases
646 abuf_json_mark_array_entry(false, abuf); // entry
651 abuf_json_mark_object(false, true, abuf, NULL); // mid
656 static void ipc_print_gateways_ipvx(struct autobuf *abuf, bool ipv6) {
659 abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
661 if (olsr_cnf->smart_gw_active) {
662 struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
663 struct gateway_entry * gw;
664 OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
665 if ((!ipv6 && !gw->ipv4) || (ipv6 && !gw->ipv6)) {
666 /* gw does not advertise the requested IP version */
670 abuf_json_mark_array_entry(true, abuf);
671 ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
672 abuf_json_mark_array_entry(false, abuf);
673 } OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
676 abuf_json_mark_object(false, true, abuf, NULL);
678 #endif /* __linux__ */
680 void ipc_print_gateways(struct autobuf *abuf) {
682 abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
683 #else /* __linux__ */
684 abuf_json_mark_object(true, false, abuf, "gateways");
686 ipc_print_gateways_ipvx(abuf, false);
687 ipc_print_gateways_ipvx(abuf, true);
689 abuf_json_mark_object(false, false, abuf, NULL);
690 #endif /* __linux__ */
695 /** interface names for smart gateway tunnel interfaces, IPv4 */
696 extern struct interfaceName * sgwTunnel4InterfaceNames;
698 /** interface names for smart gateway tunnel interfaces, IPv6 */
699 extern struct interfaceName * sgwTunnel6InterfaceNames;
702 * Construct the sgw table for a given ip version
704 * @param abuf the string buffer
705 * @param ipv6 true for IPv6, false for IPv4
706 * @param fmtv the format for printing
708 static void sgw_ipvx(struct autobuf *abuf, bool ipv6) {
709 struct interfaceName * sgwTunnelInterfaceNames;
713 sgwTunnelInterfaceNames = !ipv6 ? sgwTunnel4InterfaceNames : sgwTunnel6InterfaceNames;
715 abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
717 if (olsr_cnf->smart_gw_active && sgwTunnelInterfaceNames) {
718 struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
720 for (i = 0; i < olsr_cnf->smart_gw_use_count; i++) {
721 struct interfaceName * node = &sgwTunnelInterfaceNames[i];
722 struct gateway_entry * gw = node->gw;
728 abuf_json_mark_array_entry(true, abuf);
729 ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
730 abuf_json_ip_address(abuf, "destination", &gw->originator);
731 abuf_json_string(abuf, "tunnel", node->name);
732 abuf_json_int(abuf, "tableNr", node->tableNr);
733 abuf_json_int(abuf, "ruleNr", node->ruleNr);
734 abuf_json_int(abuf, "bypassRuleNr", node->bypassRuleNr);
735 abuf_json_mark_array_entry(false, abuf);
739 abuf_json_mark_object(false, true, abuf, NULL);
741 #endif /* __linux__ */
743 void ipc_print_sgw(struct autobuf *abuf) {
745 abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
747 abuf_json_mark_object(true, false, abuf, "sgw");
749 sgw_ipvx(abuf, false);
750 sgw_ipvx(abuf, true);
752 abuf_json_mark_object(false, false, abuf, NULL);
753 #endif /* __linux__ */
756 void ipc_print_version(struct autobuf *abuf) {
757 abuf_json_mark_object(true, false, abuf, "version");
759 abuf_json_string(abuf, "version", olsrd_version);
761 abuf_json_string(abuf, "date", build_date);
762 abuf_json_string(abuf, "host", build_host);
763 abuf_json_string(abuf, "gitDescriptor", git_descriptor);
764 abuf_json_string(abuf, "gitSha", git_sha);
765 abuf_json_string(abuf, "releaseVersion", release_version);
766 abuf_json_string(abuf, "sourceHash", source_hash);
768 abuf_json_mark_object(false, false, abuf, NULL);
771 void ipc_print_olsrd_conf(struct autobuf *abuf) {
772 olsrd_write_cnf_autobuf(abuf, olsr_cnf);
775 void ipc_print_interfaces(struct autobuf *abuf) {
778 abuf_json_mark_object(true, true, abuf, "interfaces");
779 for (ifs = olsr_cnf->interfaces; ifs != NULL ; ifs = ifs->next) {
780 abuf_json_mark_array_entry(true, abuf);
781 abuf_json_string(abuf, "name", ifs->name);
782 abuf_json_boolean(abuf, "configured", ifs->configured);
783 abuf_json_boolean(abuf, "hostEmulation", ifs->host_emul);
784 abuf_json_ip_address(abuf, "hostEmulationAddress", &ifs->hemu_ip);
785 print_interface_olsr(abuf, "olsrInterface", ifs->interf);
786 print_interface_config(abuf, "InterfaceConfiguration", ifs->cnf);
787 print_interface_config(abuf, "InterfaceConfigurationDefaults", ifs->cnfi);
788 abuf_json_mark_array_entry(false, abuf);
790 abuf_json_mark_object(false, true, abuf, NULL); // interfaces
793 void ipc_print_twohop(struct autobuf *abuf) {
794 ipc_print_neighbors_internal(abuf, true);
797 void ipc_print_config(struct autobuf *abuf) {
798 abuf_json_mark_object(true, false, abuf, "config");
800 abuf_json_string(abuf, "configurationFile", olsr_cnf->configuration_file);
801 abuf_json_int(abuf, "olsrPort", olsr_cnf->olsrport);
802 abuf_json_int(abuf, "debugLevel", olsr_cnf->debug_level);
803 abuf_json_boolean(abuf, "noFork", olsr_cnf->no_fork);
804 abuf_json_string(abuf, "pidFile", olsr_cnf->pidfile);
805 abuf_json_boolean(abuf, "hostEmulation", olsr_cnf->host_emul);
806 abuf_json_int(abuf, "ipVersion", (olsr_cnf->ip_version == AF_INET) ? 4 : 6);
807 abuf_json_boolean(abuf, "allowNoInt", olsr_cnf->allow_no_interfaces);
808 abuf_json_int(abuf, "tosValue", olsr_cnf->tos);
810 abuf_json_int(abuf, "rtProto", olsr_cnf->rt_proto);
811 abuf_json_mark_object(true, false, abuf, "rtTable");
812 abuf_json_int(abuf, "main", olsr_cnf->rt_table);
813 abuf_json_int(abuf, "default", olsr_cnf->rt_table_default);
814 abuf_json_int(abuf, "tunnel", olsr_cnf->rt_table_tunnel);
815 abuf_json_int(abuf, "priority", olsr_cnf->rt_table_pri);
816 abuf_json_int(abuf, "tunnelPriority", olsr_cnf->rt_table_tunnel_pri);
817 abuf_json_int(abuf, "defaultOlsrPriority", olsr_cnf->rt_table_defaultolsr_pri);
818 abuf_json_int(abuf, "defaultPriority", olsr_cnf->rt_table_default_pri);
819 abuf_json_mark_object(false, false, abuf, NULL);
821 abuf_json_mark_object(true, false, abuf, "willingness");
822 abuf_json_int(abuf, "willingness", olsr_cnf->willingness);
823 abuf_json_boolean(abuf, "auto", olsr_cnf->willingness_auto);
824 abuf_json_float(abuf, "updateInterval", olsr_cnf->will_int);
825 abuf_json_mark_object(false, false, abuf, NULL);
828 // ipc_connections: later
830 abuf_json_mark_object(true, false, abuf, "fib");
831 abuf_json_string(abuf, "metric", ((olsr_cnf->fib_metric < FIBM_FLAT) || (olsr_cnf->fib_metric >= FIBM_CNT)) ? "" : FIB_METRIC_TXT[olsr_cnf->fib_metric]);
832 abuf_json_string(abuf, "metricDefault", FIB_METRIC_TXT[olsr_cnf->fib_metric_default]);
833 abuf_json_mark_object(false, false, abuf, NULL);
836 abuf_json_mark_object(true, false, abuf, "hysteresis");
837 abuf_json_boolean(abuf, "enabled", olsr_cnf->use_hysteresis);
838 abuf_json_float(abuf, "scaling", olsr_cnf->hysteresis_param.scaling);
839 abuf_json_float(abuf, "thresholdLow", olsr_cnf->hysteresis_param.thr_low);
840 abuf_json_float(abuf, "thresholdHigh", olsr_cnf->hysteresis_param.thr_high);
841 abuf_json_mark_object(false, false, abuf, NULL);
846 struct ip_prefix_list *hna;
848 abuf_json_mark_object(true, true, abuf, "hna");
850 /* Announced HNA entries */
851 for (hna = olsr_cnf->hna_entries; hna; hna = hna->next) {
852 print_hna_array_entry( //
854 &olsr_cnf->main_addr, //
856 hna->net.prefix_len, //
859 abuf_json_mark_object(false, true, abuf, NULL);
862 // interface_defaults: later
864 abuf_json_float(abuf, "pollrate", olsr_cnf->pollrate);
865 abuf_json_float(abuf, "nicChgsPollInt", olsr_cnf->nic_chgs_pollrate);
866 abuf_json_boolean(abuf, "clearScreen", olsr_cnf->clear_screen);
867 abuf_json_int(abuf, "tcRedundancy", olsr_cnf->tc_redundancy);
868 abuf_json_int(abuf, "mprCoverage", olsr_cnf->mpr_coverage);
871 abuf_json_mark_object(true, false, abuf, "linkQuality");
872 abuf_json_int(abuf, "level", olsr_cnf->lq_level);
873 abuf_json_boolean(abuf, "fishEye", olsr_cnf->lq_fish);
874 abuf_json_float(abuf, "aging", olsr_cnf->lq_aging);
875 abuf_json_string(abuf, "algorithm", olsr_cnf->lq_algorithm);
876 abuf_json_mark_object(false, false, abuf, NULL);
878 abuf_json_float(abuf, "minTCVTime", olsr_cnf->min_tc_vtime);
880 abuf_json_boolean(abuf, "setIpForward", olsr_cnf->set_ip_forward);
882 abuf_json_string(abuf, "lockFile", olsr_cnf->lock_file);
883 abuf_json_boolean(abuf, "useNiit", olsr_cnf->use_niit);
885 abuf_json_mark_object(true, false, abuf, "smartGateway");
886 abuf_json_boolean(abuf, "enabled", olsr_cnf->smart_gw_active);
887 abuf_json_boolean(abuf, "alwaysRemoveServerTunnel", olsr_cnf->smart_gw_always_remove_server_tunnel);
888 abuf_json_boolean(abuf, "allowNAT", olsr_cnf->smart_gw_allow_nat);
889 abuf_json_boolean(abuf, "uplinkNAT", olsr_cnf->smart_gw_uplink_nat);
890 abuf_json_int(abuf, "useCount", olsr_cnf->smart_gw_use_count);
891 abuf_json_int(abuf, "takeDownPercentage", olsr_cnf->smart_gw_takedown_percentage);
892 abuf_json_string(abuf, "instanceId", olsr_cnf->smart_gw_instance_id);
893 abuf_json_string(abuf, "policyRoutingScript", olsr_cnf->smart_gw_policyrouting_script);
895 abuf_json_mark_object(true, false, abuf, "egress");
896 // smart_gw_egress_interfaces
898 struct sgw_egress_if * egressif = olsr_cnf->smart_gw_egress_interfaces;
900 abuf_json_mark_object(true, true, abuf, "interfaces");
902 abuf_json_string(abuf, NULL, egressif->name);
903 egressif = egressif->next;
905 abuf_json_mark_object(false, true, abuf, NULL);
907 abuf_json_int(abuf, "interfacesCount", olsr_cnf->smart_gw_egress_interfaces_count);
908 abuf_json_string(abuf, "file", olsr_cnf->smart_gw_egress_file);
909 abuf_json_int(abuf, "filePeriod", olsr_cnf->smart_gw_egress_file_period);
910 abuf_json_mark_object(false, false, abuf, NULL);
912 abuf_json_string(abuf, "statusFile", olsr_cnf->smart_gw_status_file);
913 abuf_json_int(abuf, "tablesOffset", olsr_cnf->smart_gw_offset_tables);
914 abuf_json_int(abuf, "rulesOffset", olsr_cnf->smart_gw_offset_rules);
915 abuf_json_int(abuf, "period", olsr_cnf->smart_gw_period);
916 abuf_json_int(abuf, "stableCount", olsr_cnf->smart_gw_stablecount);
917 abuf_json_int(abuf, "threshold", olsr_cnf->smart_gw_thresh);
919 abuf_json_mark_object(true, false, abuf, "costsCalculation");
920 abuf_json_int(abuf, "exitLinkUp", olsr_cnf->smart_gw_weight_exitlink_up);
921 abuf_json_int(abuf, "exitLinkDown", olsr_cnf->smart_gw_weight_exitlink_down);
922 abuf_json_int(abuf, "etx", olsr_cnf->smart_gw_weight_etx);
923 abuf_json_int(abuf, "dividerEtx", olsr_cnf->smart_gw_divider_etx);
924 abuf_json_mark_object(false, false, abuf, NULL);
926 abuf_json_int(abuf, "maxCostMaxEtx", olsr_cnf->smart_gw_path_max_cost_etx_max);
927 abuf_json_string(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]);
929 abuf_json_mark_object(true, false, abuf, "bandwidth");
930 abuf_json_int(abuf, "uplinkKbps", olsr_cnf->smart_gw_uplink);
931 abuf_json_int(abuf, "downlinkKbps", olsr_cnf->smart_gw_downlink);
932 abuf_json_mark_object(false, false, abuf, NULL);
934 abuf_json_mark_object(true, false, abuf, "prefix");
935 abuf_json_ip_address(abuf, "prefix", &olsr_cnf->smart_gw_prefix.prefix);
936 abuf_json_int(abuf, "length", olsr_cnf->smart_gw_prefix.prefix_len);
937 abuf_json_mark_object(false, false, abuf, NULL);
939 abuf_json_mark_object(false, false, abuf, NULL);
942 abuf_json_ip_address(abuf, "mainIp", &olsr_cnf->main_addr);
943 abuf_json_ip_address(abuf, "unicastSourceIpAddress", &olsr_cnf->unicast_src_ip);
944 abuf_json_boolean(abuf, "srcIpRoutes", olsr_cnf->use_src_ip_routes);
947 abuf_json_int(abuf, "maxPrefixLength", olsr_cnf->maxplen);
948 abuf_json_int(abuf, "ipSize", olsr_cnf->ipsize);
949 abuf_json_boolean(abuf, "delgw", olsr_cnf->del_gws);
950 abuf_json_float(abuf, "maxSendMessageJitter", olsr_cnf->max_jitter);
951 abuf_json_int(abuf, "exitValue", olsr_cnf->exit_value);
952 abuf_json_float(abuf, "maxTcValidTime", olsr_cnf->max_tc_vtime);
954 abuf_json_int(abuf, "niit4to6InterfaceIndex", olsr_cnf->niit4to6_if_index);
955 abuf_json_int(abuf, "niit6to4InterfaceIndex", olsr_cnf->niit6to4_if_index);
958 abuf_json_boolean(abuf, "hasIpv4Gateway", olsr_cnf->has_ipv4_gateway);
959 abuf_json_boolean(abuf, "hasIpv6Gateway", olsr_cnf->has_ipv6_gateway);
961 abuf_json_int(abuf, "ioctlSocket", olsr_cnf->ioctl_s);
963 abuf_json_int(abuf, "routeNetlinkSocket", olsr_cnf->rtnl_s);
964 abuf_json_int(abuf, "routeMonitorSocket", olsr_cnf->rt_monitor_socket);
965 #endif /* __linux__ */
967 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
968 abuf_json_int(abuf, "routeChangeSocket", olsr_cnf->rts);
969 #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ */
970 abuf_json_float(abuf, "linkQualityNatThreshold", olsr_cnf->lq_nat_thresh);
974 abuf_json_int(abuf, "brokenLinkCost", LINK_COST_BROKEN);
975 abuf_json_int(abuf, "brokenRouteCost", ROUTE_COST_BROKEN);
978 // IpcConnect section
979 abuf_json_int(abuf, "ipcConnectMaxConnections", olsr_cnf->ipc_connections);
981 struct ip_prefix_list *ipc_nets;
983 abuf_json_mark_object(true, true, abuf, "ipcConnectAllowed");
984 for (ipc_nets = olsr_cnf->ipc_nets; ipc_nets; ipc_nets = ipc_nets->next) {
985 print_ipc_net_array_entry(abuf, ipc_nets);
987 abuf_json_mark_object(false, true, abuf, NULL);
991 // plugins section: use /plugins
994 // InterfaceDefaults section
995 print_interface_config(abuf, "interfaceDefaults", olsr_cnf->interface_defaults);
998 // Interface(s) section: use /interfaces
1002 #if defined _WIN32 || defined _WIN64
1003 abuf_json_string(abuf, "os", "Windows");
1004 #elif defined __gnu_linux__
1005 abuf_json_string(abuf, "os", "GNU/Linux");
1006 #elif defined __ANDROID__
1007 abuf_json_string(abuf, "os", "Android");
1008 #elif defined __APPLE__
1009 abuf_json_string(abuf, "os", "Mac OS X");
1010 #elif defined __NetBSD__
1011 abuf_json_string(abuf, "os", "NetBSD");
1012 #elif defined __OpenBSD__
1013 abuf_json_string(abuf, "os", "OpenBSD");
1014 #elif defined __FreeBSD__ || defined __FreeBSD_kernel__
1015 abuf_json_string(abuf, "os", "FreeBSD");
1016 #else /* OS detection */
1017 abuf_json_string(abuf, "os", "Undefined");
1018 #endif /* OS detection */
1020 abuf_json_int(abuf, "startTime", start_time.tv_sec);
1022 abuf_json_mark_object(false, false, abuf, NULL);
1025 void ipc_print_plugins(struct autobuf *abuf) {
1026 abuf_json_mark_object(true, true, abuf, "plugins");
1027 if (olsr_cnf->plugins) {
1028 struct plugin_entry *plugin;
1030 for (plugin = olsr_cnf->plugins; plugin; plugin = plugin->next) {
1031 struct plugin_param *param;
1033 abuf_json_mark_array_entry(true, abuf);
1034 abuf_json_string(abuf, "plugin", plugin->name);
1036 abuf_json_mark_object(true, false, abuf, "parameters");
1037 for (param = plugin->params; param; param = param->next) {
1038 abuf_json_string(abuf, param->key, param->value);
1040 abuf_json_mark_object(false, false, abuf, NULL);
1042 abuf_json_mark_array_entry(false, abuf);
1045 abuf_json_mark_object(false, true, abuf, NULL);