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 int 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", 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) {
286 struct ipaddr_str addrbuf;
291 abuf_json_mark_object(true, false, abuf, name);
293 abuf_json_string(abuf, "state", "down");
294 abuf_json_mark_object(false, false, abuf, NULL);
298 abuf_json_string(abuf, "state", "up");
300 abuf_json_string(abuf, "ipv4Address", ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
301 abuf_json_string(abuf, "ipv4Netmask", ip4_to_string(&addrbuf, rifs->int_netmask.sin_addr));
302 abuf_json_string(abuf, "ipv4Broadcast", ip4_to_string(&addrbuf, rifs->int_broadaddr.sin_addr));
303 abuf_json_string(abuf, "mode", OLSR_IF_MODE[rifs->mode]);
305 abuf_json_string(abuf, "ipv6Address", ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
306 abuf_json_string(abuf, "ipv6Multicast", ip6_to_string(&addrbuf, &rifs->int6_multaddr.sin6_addr));
308 abuf_json_ip_address(abuf, "ipAddress", &rifs->ip_addr);
309 abuf_json_boolean(abuf, "emulatedInterface", rifs->is_hcif);
311 abuf_json_int(abuf, "olsrSocket", rifs->olsr_socket);
312 abuf_json_int(abuf, "sendSocket", rifs->send_socket);
314 abuf_json_int(abuf, "metric", rifs->int_metric);
315 abuf_json_int(abuf, "mtu", rifs->int_mtu);
316 abuf_json_int(abuf, "flags", rifs->int_flags);
317 abuf_json_int(abuf, "index", rifs->if_index);
318 abuf_json_boolean(abuf, "wireless", rifs->is_wireless);
319 abuf_json_string(abuf, "name", rifs->int_name);
320 abuf_json_int(abuf, "seqNum", rifs->olsr_seqnum);
323 abuf_json_int(abuf, "helloTime", rifs->hello_gen_timer ? (long) (rifs->hello_gen_timer->timer_clock - now_times) : 0);
324 abuf_json_int(abuf, "hnaTime", rifs->hna_gen_timer ? (long) (rifs->hna_gen_timer->timer_clock - now_times) : 0);
325 abuf_json_int(abuf, "midTime", rifs->mid_gen_timer ? (long) (rifs->mid_gen_timer->timer_clock - now_times) : 0);
326 abuf_json_int(abuf, "tcTime", rifs->tc_gen_timer ? (long) (rifs->tc_gen_timer->timer_clock - now_times) : 0);
333 abuf_json_boolean(abuf, "icmpRedirectBackup", rifs->nic_state.redirect);
336 abuf_json_boolean(abuf, "spoofFilterBackup", rifs->nic_state.spoof);
338 #endif /* __linux__ */
340 abuf_json_int(abuf, "helloEmissionInterval", rifs->hello_etime);
341 abuf_json_mark_object(true, false, abuf, "validityTimes");
342 abuf_json_int(abuf, "hello", me_to_reltime(rifs->valtimes.hello));
343 abuf_json_int(abuf, "tc", me_to_reltime(rifs->valtimes.tc));
344 abuf_json_int(abuf, "mid", me_to_reltime(rifs->valtimes.mid));
345 abuf_json_int(abuf, "hna", me_to_reltime(rifs->valtimes.hna));
346 abuf_json_mark_object(false, false, abuf, NULL);
348 abuf_json_int(abuf, "forwardingTimeout", rifs->fwdtimer);
351 abuf_json_int(abuf, "sgwZeroBwTimeout", rifs->sgw_sgw_zero_bw_timeout);
360 abuf_json_int(abuf, "ttlIndex", rifs->ttl_index);
363 abuf_json_boolean(abuf, "immediateSendTc", rifs->immediate_send_tc);
365 abuf_json_mark_object(false, false, abuf, NULL);
369 static void ipc_print_gateway_entry(struct autobuf *abuf, bool ipv6, struct gateway_entry * current_gw, struct gateway_entry * gw) {
375 tc = olsr_lookup_tc_entry(&gw->originator);
377 abuf_json_boolean(abuf, "selected", current_gw && (current_gw == gw));
378 abuf_json_boolean(abuf, "selectable", isGwSelectable(gw, ipv6));
379 abuf_json_ip_address(abuf, "originator", &gw->originator);
380 abuf_json_ip_address(abuf, "prefix", &gw->external_prefix.prefix);
381 abuf_json_int(abuf, "prefixLen", gw->external_prefix.prefix_len);
382 abuf_json_int(abuf, "uplink", gw->uplink);
383 abuf_json_int(abuf, "downlink", gw->downlink);
384 abuf_json_int(abuf, "cost", gw->path_cost);
385 abuf_json_boolean(abuf, "IPv4", gw->ipv4);
386 abuf_json_boolean(abuf, "IPv4-NAT", gw->ipv4nat);
387 abuf_json_boolean(abuf, "IPv6", gw->ipv6);
388 abuf_json_int(abuf, "expireTime", gw->expire_timer ? (gw->expire_timer->timer_clock - now_times) : 0);
389 abuf_json_int(abuf, "cleanupTime", gw->cleanup_timer ? (gw->cleanup_timer->timer_clock - now_times) : 0);
391 abuf_json_int(abuf, "pathcost", !tc ? ROUTE_COST_BROKEN : tc->path_cost);
392 abuf_json_int(abuf, "hops", !tc ? 0 : tc->hops);
394 #endif /* __linux__ */
396 static void ipc_print_neighbors_internal(struct autobuf *abuf, bool list_2hop) {
397 struct neighbor_entry *neigh;
402 abuf_json_mark_object(true, true, abuf, "neighbors");
404 abuf_json_mark_object(true, true, abuf, "2hop");
408 OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
409 struct neighbor_2_list_entry *list_2;
412 abuf_json_mark_array_entry(true, abuf);
414 abuf_json_ip_address(abuf, "ipAddress", &neigh->neighbor_main_addr);
415 abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
416 abuf_json_int(abuf, "willingness", neigh->willingness);
417 abuf_json_boolean(abuf, "isMultiPointRelay", neigh->is_mpr);
418 abuf_json_boolean(abuf, "wasMultiPointRelay", neigh->was_mpr);
419 abuf_json_boolean(abuf, "multiPointRelaySelector", olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
420 abuf_json_boolean(abuf, "skip", neigh->skip);
421 abuf_json_int(abuf, "neighbor2nocov", neigh->neighbor_2_nocov);
422 abuf_json_int(abuf, "linkcount", neigh->linkcount);
425 abuf_json_mark_object(true, true, abuf, "twoHopNeighbors");
429 for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
430 if (list_2hop && list_2->neighbor_2) {
431 abuf_json_mark_array_entry(true, abuf);
432 abuf_json_ip_address(abuf, "ipAddress", list_2->neighbor_2 ? &list_2->neighbor_2->neighbor_2_addr : NULL);
433 abuf_json_mark_array_entry(false, abuf);
439 abuf_json_mark_object(false, true, abuf, NULL);
441 abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
443 abuf_json_mark_array_entry(false, abuf);
444 } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
445 abuf_json_mark_object(false, true, abuf, NULL);
448 void ipc_print_neighbors(struct autobuf *abuf) {
449 ipc_print_neighbors_internal(abuf, false);
452 void ipc_print_links(struct autobuf *abuf) {
453 struct link_entry *my_link;
455 abuf_json_mark_object(true, true, abuf, "links");
457 OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
458 struct lqtextbuffer lqBuffer;
459 const char* lqString = get_link_entry_text(my_link, '\t', &lqBuffer);
460 char * nlqString = strrchr(lqString, '\t');
467 abuf_json_mark_array_entry(true, abuf);
469 abuf_json_ip_address(abuf, "localIP", &my_link->local_iface_addr);
470 abuf_json_ip_address(abuf, "remoteIP", &my_link->neighbor_iface_addr);
471 abuf_json_string(abuf, "olsrInterface", (my_link->inter && my_link->inter->int_name) ? my_link->inter->int_name : "");
472 abuf_json_string(abuf, "ifName", my_link->if_name ? my_link->if_name : "");
473 abuf_json_int(abuf, "validityTime", my_link->link_timer ? (long) (my_link->link_timer->timer_clock - now_times) : 0);
474 abuf_json_int(abuf, "symmetryTime", my_link->link_sym_timer ? (long) (my_link->link_sym_timer->timer_clock - now_times) : 0);
475 abuf_json_int(abuf, "asymmetryTime", my_link->ASYM_time);
476 abuf_json_int(abuf, "vtime", (long) my_link->vtime);
477 // neighbor (no need to print, can be looked up via neighbours)
478 abuf_json_string(abuf, "currentLinkStatus", linkTypeToString(lookup_link_status(my_link)));
479 abuf_json_string(abuf, "previousLinkStatus", linkTypeToString(my_link->prev_status));
481 abuf_json_float(abuf, "hysteresis", my_link->L_link_quality);
482 abuf_json_boolean(abuf, "pending", my_link->L_link_pending != 0);
483 abuf_json_int(abuf, "lostLinkTime", (long) my_link->L_LOST_LINK_time);
484 abuf_json_int(abuf, "helloTime", my_link->link_hello_timer ? (long) (my_link->link_hello_timer->timer_clock - now_times) : 0);
485 abuf_json_int(abuf, "lastHelloTime", (long) my_link->last_htime);
486 abuf_json_boolean(abuf, "seqnoValid", my_link->olsr_seqno_valid);
487 abuf_json_int(abuf, "seqno", my_link->olsr_seqno);
489 abuf_json_int(abuf, "lossHelloInterval", (long) my_link->loss_helloint);
490 abuf_json_int(abuf, "lossTime", my_link->link_loss_timer ? (long) (my_link->link_loss_timer->timer_clock - now_times) : 0);
492 abuf_json_int(abuf, "lossMultiplier", (long) my_link->loss_link_multiplier);
494 abuf_json_int(abuf, "linkCost", MIN(my_link->linkcost, LINK_COST_BROKEN));
496 abuf_json_float(abuf, "linkQuality", atof(lqString));
497 abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
499 abuf_json_mark_array_entry(false, abuf);
500 } OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
501 abuf_json_mark_object(false, true, abuf, NULL);
504 void ipc_print_routes(struct autobuf *abuf) {
507 abuf_json_mark_object(true, true, abuf, "routes");
509 /* Walk the route table */
510 OLSR_FOR_ALL_RT_ENTRIES(rt) {
511 struct lqtextbuffer costbuffer;
514 abuf_json_mark_array_entry(true, abuf);
515 abuf_json_ip_address(abuf, "destination", &rt->rt_dst.prefix);
516 abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
517 abuf_json_ip_address(abuf, "gateway", &rt->rt_best->rtp_nexthop.gateway);
518 abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
519 abuf_json_float(abuf, "etx", atof(get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &costbuffer)));
520 abuf_json_int(abuf, "rtpMetricCost", MIN(ROUTE_COST_BROKEN, rt->rt_best->rtp_metric.cost));
521 abuf_json_string(abuf, "networkInterface", if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
522 abuf_json_mark_array_entry(false, abuf);
524 } OLSR_FOR_ALL_RT_ENTRIES_END(rt);
526 abuf_json_mark_object(false, true, abuf, NULL);
529 void ipc_print_topology(struct autobuf *abuf) {
532 abuf_json_mark_object(true, true, abuf, "topology");
535 OLSR_FOR_ALL_TC_ENTRIES(tc) {
536 struct tc_edge_entry *tc_edge;
537 OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
538 if (tc_edge->edge_inv) {
539 struct lqtextbuffer lqbuffer;
540 const char* lqString = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer);
541 char * nlqString = strrchr(lqString, '\t');
548 abuf_json_mark_array_entry(true, abuf);
551 abuf_json_ip_address(abuf, "lastHopIP", &tc->addr);
553 abuf_json_int(abuf, "pathCost", MIN(tc->path_cost, ROUTE_COST_BROKEN));
559 abuf_json_int(abuf, "validityTime", tc->validity_timer ? (tc->validity_timer->timer_clock - now_times) : 0);
560 abuf_json_int(abuf, "refCount", tc->refcount);
561 abuf_json_int(abuf, "msgSeq", tc->msg_seq);
562 abuf_json_int(abuf, "msgHops", tc->msg_hops);
563 abuf_json_int(abuf, "hops", tc->hops);
564 abuf_json_int(abuf, "ansn", tc->ansn);
565 abuf_json_int(abuf, "tcIgnored", tc->ignored);
567 abuf_json_int(abuf, "errSeq", tc->err_seq);
568 abuf_json_boolean(abuf, "errSeqValid", tc->err_seq_valid);
571 abuf_json_ip_address(abuf, "destinationIP", &tc_edge->T_dest_addr);
573 abuf_json_int(abuf, "tcEdgeCost", MIN(LINK_COST_BROKEN, tc_edge->cost));
574 abuf_json_int(abuf, "ansnEdge", tc_edge->ansn);
575 abuf_json_float(abuf, "linkQuality", atof(lqString));
576 abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
578 abuf_json_mark_array_entry(false, abuf);
580 } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
581 } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
583 abuf_json_mark_object(false, true, abuf, NULL);
586 void ipc_print_hna(struct autobuf *abuf) {
587 struct ip_prefix_list *hna;
588 struct hna_entry *tmp_hna;
590 abuf_json_mark_object(true, true, abuf, "hna");
592 /* Announced HNA entries */
593 for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
594 print_hna_array_entry( //
596 &olsr_cnf->main_addr, //
598 hna->net.prefix_len, //
602 OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
603 struct hna_net *tmp_net;
605 /* Check all networks */
606 for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
607 print_hna_array_entry( //
609 &tmp_hna->A_gateway_addr, //
610 &tmp_net->hna_prefix.prefix, //
611 tmp_net->hna_prefix.prefix_len, //
612 tmp_net->hna_net_timer ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0);
614 } OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
616 abuf_json_mark_object(false, true, abuf, NULL);
619 void ipc_print_mid(struct autobuf *abuf) {
622 abuf_json_mark_object(true, true, abuf, "mid");
625 for (idx = 0; idx < HASHSIZE; idx++) {
626 struct mid_entry * entry = mid_set[idx].next;
628 while (entry != &mid_set[idx]) {
629 abuf_json_mark_array_entry(true, abuf);
630 abuf_json_ip_address(abuf, "ipAddress", &entry->main_addr);
631 abuf_json_int(abuf, "validityTime", entry->mid_timer ? (entry->mid_timer->timer_clock - now_times) : 0);
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);
807 abuf_json_boolean(abuf, "allowNoInt", olsr_cnf->allow_no_interfaces);
808 abuf_json_int(abuf, "tosValue", olsr_cnf->tos);
809 abuf_json_int(abuf, "rtProto", olsr_cnf->rt_proto);
810 abuf_json_int(abuf, "rtTable", olsr_cnf->rt_table);
811 abuf_json_int(abuf, "rtTableDefault", olsr_cnf->rt_table_default);
812 abuf_json_int(abuf, "rtTableTunnel", olsr_cnf->rt_table_tunnel);
813 abuf_json_int(abuf, "rtTablePriority", olsr_cnf->rt_table_pri);
814 abuf_json_int(abuf, "rtTableTunnelPriority", olsr_cnf->rt_table_tunnel_pri);
815 abuf_json_int(abuf, "rtTableDefauiltOlsrPriority", olsr_cnf->rt_table_defaultolsr_pri);
816 abuf_json_int(abuf, "rtTableDefaultPriority", olsr_cnf->rt_table_default_pri);
817 abuf_json_int(abuf, "willingness", olsr_cnf->willingness);
818 abuf_json_boolean(abuf, "willingnessAuto", olsr_cnf->willingness_auto);
819 // ipc_connections: later
820 abuf_json_boolean(abuf, "useHysteresis", olsr_cnf->use_hysteresis);
821 abuf_json_string(abuf, "fibMetric", FIB_METRIC_TXT[olsr_cnf->fib_metric]);
822 abuf_json_string(abuf, "fibMetricDefault", FIB_METRIC_TXT[olsr_cnf->fib_metric_default]);
823 abuf_json_float(abuf, "hystScaling", olsr_cnf->hysteresis_param.scaling);
824 abuf_json_float(abuf, "hystThrLow", olsr_cnf->hysteresis_param.thr_low);
825 abuf_json_float(abuf, "hystThrHigh", olsr_cnf->hysteresis_param.thr_high);
829 struct ip_prefix_list *hna;
831 abuf_json_mark_object(true, true, abuf, "hna");
833 /* Announced HNA entries */
834 for (hna = olsr_cnf->hna_entries; hna; hna = hna->next) {
835 print_hna_array_entry( //
837 &olsr_cnf->main_addr, //
839 hna->net.prefix_len, //
842 abuf_json_mark_object(false, true, abuf, NULL);
845 // interface_defaults: later
847 abuf_json_float(abuf, "pollrate", olsr_cnf->pollrate);
848 abuf_json_float(abuf, "nicChgsPollInt", olsr_cnf->nic_chgs_pollrate);
849 abuf_json_boolean(abuf, "clearScreen", olsr_cnf->clear_screen);
850 abuf_json_int(abuf, "tcRedundancy", olsr_cnf->tc_redundancy);
851 abuf_json_int(abuf, "mprCoverage", olsr_cnf->mpr_coverage);
852 abuf_json_int(abuf, "linkQualityLevel", olsr_cnf->lq_level);
853 abuf_json_boolean(abuf, "linkQualityFishEye", olsr_cnf->lq_fish);
854 abuf_json_float(abuf, "linkQualityAging", olsr_cnf->lq_aging);
855 abuf_json_string(abuf, "linkQualityAlgorithm", olsr_cnf->lq_algorithm);
857 abuf_json_float(abuf, "minTCVTime", olsr_cnf->min_tc_vtime);
859 abuf_json_boolean(abuf, "setIpForward", olsr_cnf->set_ip_forward);
861 abuf_json_string(abuf, "lockFile", olsr_cnf->lock_file);
862 abuf_json_boolean(abuf, "useNiit", olsr_cnf->use_niit);
864 abuf_json_boolean(abuf, "smartGateway", olsr_cnf->smart_gw_active);
865 abuf_json_boolean(abuf, "smartGatewayAlwaysRemoveServerTunnel", olsr_cnf->smart_gw_always_remove_server_tunnel);
866 abuf_json_boolean(abuf, "smartGatewayAllowNAT", olsr_cnf->smart_gw_allow_nat);
867 abuf_json_boolean(abuf, "smartGatewayUplinkNAT", olsr_cnf->smart_gw_uplink_nat);
868 abuf_json_int(abuf, "smartGatewayUseCount", olsr_cnf->smart_gw_use_count);
869 abuf_json_int(abuf, "smartGatewayTakeDownPercentage", olsr_cnf->smart_gw_takedown_percentage);
870 abuf_json_string(abuf, "smartGatewayInstanceId", olsr_cnf->smart_gw_instance_id);
871 abuf_json_string(abuf, "smartGatewayPolicyRoutingScript", olsr_cnf->smart_gw_policyrouting_script);
872 // smart_gw_egress_interfaces
874 struct sgw_egress_if * egressif = olsr_cnf->smart_gw_egress_interfaces;
876 abuf_json_mark_object(true, true, abuf, "smartGatewayEgressInterfaces");
878 abuf_json_mark_array_entry(true, abuf);
879 abuf_json_string(abuf, "interface", egressif->name);
880 abuf_json_mark_array_entry(false, abuf);
882 egressif = egressif->next;
884 abuf_json_mark_object(false, true, abuf, NULL);
886 abuf_json_int(abuf, "smartGatewayEgressInterfacesCount", olsr_cnf->smart_gw_egress_interfaces_count);
887 abuf_json_string(abuf, "smartGatewayEgressFile", olsr_cnf->smart_gw_egress_file);
888 abuf_json_int(abuf, "smartGatewayEgressFilePeriod", olsr_cnf->smart_gw_egress_file_period);
889 abuf_json_string(abuf, "smartGatewayStatusFile", olsr_cnf->smart_gw_status_file);
890 abuf_json_int(abuf, "smartGatewayTablesOffset", olsr_cnf->smart_gw_offset_tables);
891 abuf_json_int(abuf, "smartGatewayRulesOffset", olsr_cnf->smart_gw_offset_rules);
892 abuf_json_int(abuf, "smartGatewayPeriod", olsr_cnf->smart_gw_period);
893 abuf_json_int(abuf, "smartGatewayStableCount", olsr_cnf->smart_gw_stablecount);
894 abuf_json_int(abuf, "smartGatewayThreshold", olsr_cnf->smart_gw_thresh);
895 abuf_json_int(abuf, "smartGatewayWeightExitLinkUp", olsr_cnf->smart_gw_weight_exitlink_up);
896 abuf_json_int(abuf, "smartGatewayWeightExitLinkDown", olsr_cnf->smart_gw_weight_exitlink_down);
897 abuf_json_int(abuf, "smartGatewayWeightEtx", olsr_cnf->smart_gw_weight_etx);
898 abuf_json_int(abuf, "smartGatewayDividerEtx", olsr_cnf->smart_gw_divider_etx);
899 abuf_json_int(abuf, "smartGatewayMaxCostMaxEtx", olsr_cnf->smart_gw_path_max_cost_etx_max);
900 abuf_json_string(abuf, "smartGatewayUplink", GW_UPLINK_TXT[olsr_cnf->smart_gw_type]);
901 abuf_json_int(abuf, "smartGatewayUplinkKbps", olsr_cnf->smart_gw_uplink);
902 abuf_json_int(abuf, "smartGatewayDownlinkKbps", olsr_cnf->smart_gw_downlink);
903 abuf_json_boolean(abuf, "smartGatewayBandwidthZero", olsr_cnf->smart_gateway_bandwidth_zero);
904 abuf_json_ip_address(abuf, "smartGatewayPrefix", &olsr_cnf->smart_gw_prefix.prefix);
905 abuf_json_int(abuf, "smartGatewayPrefixLength", olsr_cnf->smart_gw_prefix.prefix_len);
908 abuf_json_ip_address(abuf, "mainIp", &olsr_cnf->main_addr);
909 abuf_json_ip_address(abuf, "unicastSourceIpAddress", &olsr_cnf->unicast_src_ip);
910 abuf_json_boolean(abuf, "srcIpRoutes", olsr_cnf->use_src_ip_routes);
913 abuf_json_int(abuf, "maxPrefixLength", olsr_cnf->maxplen);
914 abuf_json_int(abuf, "ipSize", olsr_cnf->ipsize);
915 abuf_json_boolean(abuf, "delgw", olsr_cnf->del_gws);
916 abuf_json_float(abuf, "willingnessUpdateInterval", olsr_cnf->will_int);
917 abuf_json_float(abuf, "maxSendMessageJitter", olsr_cnf->max_jitter);
918 abuf_json_int(abuf, "exitValue", olsr_cnf->exit_value);
919 abuf_json_float(abuf, "maxTcValidTime", olsr_cnf->max_tc_vtime);
921 abuf_json_int(abuf, "niit4to6InterfaceIndex", olsr_cnf->niit4to6_if_index);
922 abuf_json_int(abuf, "niit6to4InterfaceIndex", olsr_cnf->niit6to4_if_index);
925 abuf_json_boolean(abuf, "hasIpv4Gateway", olsr_cnf->has_ipv4_gateway);
926 abuf_json_boolean(abuf, "hasIpv6Gateway", olsr_cnf->has_ipv6_gateway);
928 abuf_json_int(abuf, "ioctlSocket", olsr_cnf->ioctl_s);
930 abuf_json_int(abuf, "routeNetlinkSocket", olsr_cnf->rtnl_s);
931 abuf_json_int(abuf, "routeMonitorSocket", olsr_cnf->rt_monitor_socket);
932 #endif /* __linux__ */
934 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
935 abuf_json_int(abuf, "routeChangeSocket", olsr_cnf->rts);
936 #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ */
937 abuf_json_float(abuf, "linkQualityNatThreshold", olsr_cnf->lq_nat_thresh);
941 abuf_json_int(abuf, "brokenLinkCost", LINK_COST_BROKEN);
942 abuf_json_int(abuf, "brokenRouteCost", ROUTE_COST_BROKEN);
945 // IpcConnect section
946 abuf_json_int(abuf, "ipcConnectMaxConnections", olsr_cnf->ipc_connections);
948 struct ip_prefix_list *ipc_nets;
950 abuf_json_mark_object(true, true, abuf, "ipcConnectAllowed");
951 for (ipc_nets = olsr_cnf->ipc_nets; ipc_nets; ipc_nets = ipc_nets->next) {
952 print_ipc_net_array_entry(abuf, ipc_nets);
954 abuf_json_mark_object(false, true, abuf, NULL);
958 // plugins section: use /plugins
961 // InterfaceDefaults section
962 print_interface_config(abuf, "interfaceDefaults", olsr_cnf->interface_defaults);
965 // Interface(s) section: use /interfaces
969 #if defined _WIN32 || defined _WIN64
970 abuf_json_string(abuf, "os", "Windows");
971 #elif defined __gnu_linux__
972 abuf_json_string(abuf, "os", "GNU/Linux");
973 #elif defined __ANDROID__
974 abuf_json_string(abuf, "os", "Android");
975 #elif defined __APPLE__
976 abuf_json_string(abuf, "os", "Mac OS X");
977 #elif defined __NetBSD__
978 abuf_json_string(abuf, "os", "NetBSD");
979 #elif defined __OpenBSD__
980 abuf_json_string(abuf, "os", "OpenBSD");
981 #elif defined __FreeBSD__ || defined __FreeBSD_kernel__
982 abuf_json_string(abuf, "os", "FreeBSD");
983 #else /* OS detection */
984 abuf_json_string(abuf, "os", "Undefined");
985 #endif /* OS detection */
987 abuf_json_int(abuf, "startTime", start_time.tv_sec);
989 abuf_json_mark_object(false, false, abuf, NULL);
992 void ipc_print_plugins(struct autobuf *abuf) {
993 abuf_json_mark_object(true, true, abuf, "plugins");
994 if (olsr_cnf->plugins) {
995 struct plugin_entry *plugin;
997 for (plugin = olsr_cnf->plugins; plugin; plugin = plugin->next) {
998 struct plugin_param *param;
1000 abuf_json_mark_array_entry(true, abuf);
1001 abuf_json_string(abuf, "plugin", plugin->name);
1002 for (param = plugin->params; param; param = param->next) {
1003 abuf_json_string(abuf, param->key, param->value);
1005 abuf_json_mark_array_entry(false, abuf);
1008 abuf_json_mark_object(false, true, abuf, NULL);