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) {
220 abuf_json_mark_array_entry(true, abuf);
221 abuf_json_ip_address(abuf, "gateway", gw);
222 abuf_json_ip_address(abuf, "destination", ip);
223 abuf_json_int(abuf, "genmask", prefix_len);
224 abuf_json_int(abuf, "validityTime", validityTime);
225 abuf_json_mark_array_entry(false, abuf);
228 static void print_link_quality_multipliers_array_entry(struct autobuf *abuf, struct olsr_lq_mult *mult) {
232 abuf_json_mark_array_entry(true, abuf);
233 abuf_json_ip_address(abuf, "route", &mult->addr);
234 abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
235 abuf_json_mark_array_entry(false, abuf);
238 static void print_ipc_net_array_entry(struct autobuf *abuf, struct ip_prefix_list *ipc_nets) {
239 abuf_json_mark_array_entry(true, abuf);
240 abuf_json_boolean(abuf, "host", (ipc_nets->net.prefix_len == olsr_cnf->maxplen));
241 abuf_json_ip_address(abuf, "ipAddress", &ipc_nets->net.prefix);
242 abuf_json_int(abuf, "genmask", ipc_nets->net.prefix_len);
243 abuf_json_mark_array_entry(false, abuf);
246 static void print_interface_config(struct autobuf *abuf, const char * name, struct if_config_options* id) {
247 abuf_json_mark_object(true, false, abuf, name);
249 struct olsr_lq_mult *mult;
251 abuf_json_ip_address(abuf, "ipv4Broadcast", &id->ipv4_multicast);
252 abuf_json_ip_address(abuf, "ipv6Multicast", &id->ipv6_multicast);
254 abuf_json_ip_address(abuf, "ipv4Source", &id->ipv4_src);
255 abuf_json_ip_address(abuf, "ipv6Source", &id->ipv6_src.prefix);
256 abuf_json_int(abuf, "ipv6SourcePrefixLength", id->ipv6_src.prefix_len);
258 abuf_json_string(abuf, "mode", OLSR_IF_MODE[id->mode]);
260 abuf_json_int(abuf, "weightValue", id->weight.value);
261 abuf_json_boolean(abuf, "weightFixed", id->weight.fixed);
262 print_msg_params(abuf, &id->hello_params, "hello");
263 print_msg_params(abuf, &id->tc_params, "tc");
264 print_msg_params(abuf, &id->mid_params, "mid");
265 print_msg_params(abuf, &id->hna_params, "hna");
266 abuf_json_mark_object(true, true, abuf, "linkQualityMultipliers");
267 for (mult = olsr_cnf->interface_defaults->lq_mult; mult != NULL ; mult = mult->next) {
268 print_link_quality_multipliers_array_entry(abuf, mult);
270 abuf_json_mark_object(false, true, abuf, NULL);
271 abuf_json_int(abuf, "linkQualityMultipliersCount", id->orig_lq_mult_cnt);
272 abuf_json_boolean(abuf, "autoDetectChanges", id->autodetect_chg);
274 abuf_json_mark_object(false, false, abuf, NULL);
277 static void print_interface_olsr(struct autobuf *abuf, const char * name, struct interface_olsr * rifs) {
278 struct ipaddr_str addrbuf;
280 abuf_json_mark_object(true, false, abuf, name);
282 abuf_json_string(abuf, "state", "down");
283 abuf_json_mark_object(false, false, abuf, NULL);
287 abuf_json_string(abuf, "state", "up");
289 abuf_json_string(abuf, "ipv4Address", ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
290 abuf_json_string(abuf, "ipv4Netmask", ip4_to_string(&addrbuf, rifs->int_netmask.sin_addr));
291 abuf_json_string(abuf, "ipv4Broadcast", ip4_to_string(&addrbuf, rifs->int_broadaddr.sin_addr));
292 abuf_json_string(abuf, "mode", OLSR_IF_MODE[rifs->mode]);
294 abuf_json_string(abuf, "ipv6Address", ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
295 abuf_json_string(abuf, "ipv6Multicast", ip6_to_string(&addrbuf, &rifs->int6_multaddr.sin6_addr));
297 abuf_json_ip_address(abuf, "ipAddress", &rifs->ip_addr);
298 abuf_json_boolean(abuf, "emulatedInterface", rifs->is_hcif);
300 abuf_json_int(abuf, "olsrSocket", rifs->olsr_socket);
301 abuf_json_int(abuf, "sendSocket", rifs->send_socket);
303 abuf_json_int(abuf, "metric", rifs->int_metric);
304 abuf_json_int(abuf, "mtu", rifs->int_mtu);
305 abuf_json_int(abuf, "flags", rifs->int_flags);
306 abuf_json_int(abuf, "index", rifs->if_index);
307 abuf_json_boolean(abuf, "wireless", rifs->is_wireless);
308 abuf_json_string(abuf, "name", rifs->int_name);
309 abuf_json_int(abuf, "seqNum", rifs->olsr_seqnum);
312 abuf_json_int(abuf, "helloTime", rifs->hello_gen_timer ? (long) (rifs->hello_gen_timer->timer_clock - now_times) : 0);
313 abuf_json_int(abuf, "hnaTime", rifs->hna_gen_timer ? (long) (rifs->hna_gen_timer->timer_clock - now_times) : 0);
314 abuf_json_int(abuf, "midTime", rifs->mid_gen_timer ? (long) (rifs->mid_gen_timer->timer_clock - now_times) : 0);
315 abuf_json_int(abuf, "tcTime", rifs->tc_gen_timer ? (long) (rifs->tc_gen_timer->timer_clock - now_times) : 0);
322 abuf_json_boolean(abuf, "icmpRedirectBackup", rifs->nic_state.redirect);
325 abuf_json_boolean(abuf, "spoofFilterBackup", rifs->nic_state.spoof);
327 #endif /* __linux__ */
329 abuf_json_int(abuf, "helloEmissionInterval", rifs->hello_etime);
330 abuf_json_mark_object(true, false, abuf, "validityTimes");
331 abuf_json_int(abuf, "hello", me_to_reltime(rifs->valtimes.hello));
332 abuf_json_int(abuf, "tc", me_to_reltime(rifs->valtimes.tc));
333 abuf_json_int(abuf, "mid", me_to_reltime(rifs->valtimes.mid));
334 abuf_json_int(abuf, "hna", me_to_reltime(rifs->valtimes.hna));
335 abuf_json_mark_object(false, false, abuf, NULL);
337 abuf_json_int(abuf, "forwardingTimeout", rifs->fwdtimer);
340 abuf_json_int(abuf, "sgwZeroBwTimeout", rifs->sgw_sgw_zero_bw_timeout);
349 abuf_json_int(abuf, "ttlIndex", rifs->ttl_index);
352 abuf_json_boolean(abuf, "immediateSendTc", rifs->immediate_send_tc);
354 abuf_json_mark_object(false, false, abuf, NULL);
358 static void ipc_print_gateway_entry(struct autobuf *abuf, bool ipv6, struct gateway_entry * current_gw, struct gateway_entry * gw) {
359 struct tc_entry* tc = olsr_lookup_tc_entry(&gw->originator);
361 abuf_json_boolean(abuf, "selected", current_gw && (current_gw == gw));
362 abuf_json_boolean(abuf, "selectable", isGwSelectable(gw, ipv6));
363 abuf_json_ip_address(abuf, "originator", &gw->originator);
364 abuf_json_ip_address(abuf, "prefix", &gw->external_prefix.prefix);
365 abuf_json_int(abuf, "prefixLen", gw->external_prefix.prefix_len);
366 abuf_json_int(abuf, "uplink", gw->uplink);
367 abuf_json_int(abuf, "downlink", gw->downlink);
368 abuf_json_int(abuf, "cost", gw->path_cost);
369 abuf_json_boolean(abuf, "IPv4", gw->ipv4);
370 abuf_json_boolean(abuf, "IPv4-NAT", gw->ipv4nat);
371 abuf_json_boolean(abuf, "IPv6", gw->ipv6);
372 abuf_json_int(abuf, "expireTime", gw->expire_timer ? (gw->expire_timer->timer_clock - now_times) : 0);
373 abuf_json_int(abuf, "cleanupTime", gw->cleanup_timer ? (gw->cleanup_timer->timer_clock - now_times) : 0);
375 abuf_json_int(abuf, "pathcost", !tc ? ROUTE_COST_BROKEN : tc->path_cost);
376 abuf_json_int(abuf, "hops", !tc ? 0 : tc->hops);
378 #endif /* __linux__ */
380 static void ipc_print_neighbors_internal(struct autobuf *abuf, bool list_2hop) {
381 struct neighbor_entry *neigh;
384 abuf_json_mark_object(true, true, abuf, "neighbors");
386 abuf_json_mark_object(true, true, abuf, "2hop");
390 OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
391 struct neighbor_2_list_entry *list_2;
394 abuf_json_mark_array_entry(true, abuf);
396 abuf_json_ip_address(abuf, "ipAddress", &neigh->neighbor_main_addr);
397 abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
398 abuf_json_int(abuf, "willingness", neigh->willingness);
399 abuf_json_boolean(abuf, "isMultiPointRelay", neigh->is_mpr);
400 abuf_json_boolean(abuf, "wasMultiPointRelay", neigh->was_mpr);
401 abuf_json_boolean(abuf, "multiPointRelaySelector", olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
402 abuf_json_boolean(abuf, "skip", neigh->skip);
403 abuf_json_int(abuf, "neighbor2nocov", neigh->neighbor_2_nocov);
404 abuf_json_int(abuf, "linkcount", neigh->linkcount);
407 abuf_json_mark_object(true, true, abuf, "twoHopNeighbors");
411 for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
412 if (list_2hop && list_2->neighbor_2) {
413 abuf_json_mark_array_entry(true, abuf);
414 abuf_json_ip_address(abuf, "ipAddress", list_2->neighbor_2 ? &list_2->neighbor_2->neighbor_2_addr : NULL);
415 abuf_json_mark_array_entry(false, abuf);
421 abuf_json_mark_object(false, true, abuf, NULL);
423 abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
425 abuf_json_mark_array_entry(false, abuf);
426 } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
427 abuf_json_mark_object(false, true, abuf, NULL);
430 void ipc_print_neighbors(struct autobuf *abuf) {
431 ipc_print_neighbors_internal(abuf, false);
434 void ipc_print_links(struct autobuf *abuf) {
435 struct link_entry *my_link;
437 abuf_json_mark_object(true, true, abuf, "links");
439 OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
440 struct lqtextbuffer lqBuffer;
441 const char* lqString = get_link_entry_text(my_link, '\t', &lqBuffer);
442 char * nlqString = strrchr(lqString, '\t');
449 abuf_json_mark_array_entry(true, abuf);
451 abuf_json_ip_address(abuf, "localIP", &my_link->local_iface_addr);
452 abuf_json_ip_address(abuf, "remoteIP", &my_link->neighbor_iface_addr);
453 abuf_json_string(abuf, "olsrInterface", (my_link->inter && my_link->inter->int_name) ? my_link->inter->int_name : "");
454 abuf_json_string(abuf, "ifName", my_link->if_name ? my_link->if_name : "");
455 abuf_json_int(abuf, "validityTime", my_link->link_timer ? (long) (my_link->link_timer->timer_clock - now_times) : 0);
456 abuf_json_int(abuf, "symmetryTime", my_link->link_sym_timer ? (long) (my_link->link_sym_timer->timer_clock - now_times) : 0);
457 abuf_json_int(abuf, "asymmetryTime", my_link->ASYM_time);
458 abuf_json_int(abuf, "vtime", (long) my_link->vtime);
459 // neighbor (no need to print, can be looked up via neighbours)
460 abuf_json_string(abuf, "currentLinkStatus", linkTypeToString(lookup_link_status(my_link)));
461 abuf_json_string(abuf, "previousLinkStatus", linkTypeToString(my_link->prev_status));
463 abuf_json_float(abuf, "hysteresis", my_link->L_link_quality);
464 abuf_json_boolean(abuf, "pending", my_link->L_link_pending != 0);
465 abuf_json_int(abuf, "lostLinkTime", (long) my_link->L_LOST_LINK_time);
466 abuf_json_int(abuf, "helloTime", my_link->link_hello_timer ? (long) (my_link->link_hello_timer->timer_clock - now_times) : 0);
467 abuf_json_int(abuf, "lastHelloTime", (long) my_link->last_htime);
468 abuf_json_boolean(abuf, "seqnoValid", my_link->olsr_seqno_valid);
469 abuf_json_int(abuf, "seqno", my_link->olsr_seqno);
471 abuf_json_int(abuf, "lossHelloInterval", (long) my_link->loss_helloint);
472 abuf_json_int(abuf, "lossTime", my_link->link_loss_timer ? (long) (my_link->link_loss_timer->timer_clock - now_times) : 0);
474 abuf_json_int(abuf, "lossMultiplier", (long) my_link->loss_link_multiplier);
476 abuf_json_int(abuf, "linkCost", MIN(my_link->linkcost, LINK_COST_BROKEN));
478 abuf_json_float(abuf, "linkQuality", atof(lqString));
479 abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
481 abuf_json_mark_array_entry(false, abuf);
482 } OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
483 abuf_json_mark_object(false, true, abuf, NULL);
486 void ipc_print_routes(struct autobuf *abuf) {
489 abuf_json_mark_object(true, true, abuf, "routes");
491 /* Walk the route table */
492 OLSR_FOR_ALL_RT_ENTRIES(rt) {
493 struct lqtextbuffer costbuffer;
496 abuf_json_mark_array_entry(true, abuf);
497 abuf_json_ip_address(abuf, "destination", &rt->rt_dst.prefix);
498 abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
499 abuf_json_ip_address(abuf, "gateway", &rt->rt_best->rtp_nexthop.gateway);
500 abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
501 abuf_json_float(abuf, "etx", atof(get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &costbuffer)));
502 abuf_json_int(abuf, "rtpMetricCost", MIN(ROUTE_COST_BROKEN, rt->rt_best->rtp_metric.cost));
503 abuf_json_string(abuf, "networkInterface", if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
504 abuf_json_mark_array_entry(false, abuf);
506 } OLSR_FOR_ALL_RT_ENTRIES_END(rt);
508 abuf_json_mark_object(false, true, abuf, NULL);
511 void ipc_print_topology(struct autobuf *abuf) {
514 abuf_json_mark_object(true, true, abuf, "topology");
517 OLSR_FOR_ALL_TC_ENTRIES(tc) {
518 struct tc_edge_entry *tc_edge;
519 OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
520 if (tc_edge->edge_inv) {
521 struct lqtextbuffer lqbuffer;
522 const char* lqString = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer);
523 char * nlqString = strrchr(lqString, '\t');
530 abuf_json_mark_array_entry(true, abuf);
533 abuf_json_ip_address(abuf, "lastHopIP", &tc->addr);
535 abuf_json_int(abuf, "pathCost", MIN(tc->path_cost, ROUTE_COST_BROKEN));
541 abuf_json_int(abuf, "validityTime", tc->validity_timer ? (tc->validity_timer->timer_clock - now_times) : 0);
542 abuf_json_int(abuf, "refCount", tc->refcount);
543 abuf_json_int(abuf, "msgSeq", tc->msg_seq);
544 abuf_json_int(abuf, "msgHops", tc->msg_hops);
545 abuf_json_int(abuf, "hops", tc->hops);
546 abuf_json_int(abuf, "ansn", tc->ansn);
547 abuf_json_int(abuf, "tcIgnored", tc->ignored);
549 abuf_json_int(abuf, "errSeq", tc->err_seq);
550 abuf_json_boolean(abuf, "errSeqValid", tc->err_seq_valid);
553 abuf_json_ip_address(abuf, "destinationIP", &tc_edge->T_dest_addr);
555 abuf_json_int(abuf, "tcEdgeCost", MIN(LINK_COST_BROKEN, tc_edge->cost));
556 abuf_json_int(abuf, "ansnEdge", tc_edge->ansn);
557 abuf_json_float(abuf, "linkQuality", atof(lqString));
558 abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
560 abuf_json_mark_array_entry(false, abuf);
562 } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
563 } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
565 abuf_json_mark_object(false, true, abuf, NULL);
568 void ipc_print_hna(struct autobuf *abuf) {
569 struct ip_prefix_list *hna;
570 struct hna_entry *tmp_hna;
572 abuf_json_mark_object(true, true, abuf, "hna");
574 /* Announced HNA entries */
575 for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
576 print_hna_array_entry( //
578 &olsr_cnf->main_addr, //
580 hna->net.prefix_len, //
584 OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
585 struct hna_net *tmp_net;
587 /* Check all networks */
588 for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
589 print_hna_array_entry( //
591 &tmp_hna->A_gateway_addr, //
592 &tmp_net->hna_prefix.prefix, //
593 tmp_net->hna_prefix.prefix_len, //
594 tmp_net->hna_net_timer ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0);
596 } OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
598 abuf_json_mark_object(false, true, abuf, NULL);
601 void ipc_print_mid(struct autobuf *abuf) {
604 abuf_json_mark_object(true, true, abuf, "mid");
607 for (idx = 0; idx < HASHSIZE; idx++) {
608 struct mid_entry * entry = mid_set[idx].next;
610 while (entry != &mid_set[idx]) {
611 abuf_json_mark_array_entry(true, abuf);
612 abuf_json_ip_address(abuf, "ipAddress", &entry->main_addr);
613 abuf_json_int(abuf, "validityTime", entry->mid_timer ? (entry->mid_timer->timer_clock - now_times) : 0);
615 struct mid_address * alias = entry->aliases;
617 abuf_json_mark_object(true, true, abuf, "aliases");
619 abuf_json_mark_array_entry(true, abuf);
620 abuf_json_ip_address(abuf, "ipAddress", &alias->alias);
621 abuf_json_int(abuf, "validityTime", alias->vtime - now_times);
622 abuf_json_mark_array_entry(false, abuf);
624 alias = alias->next_alias;
626 abuf_json_mark_object(false, true, abuf, NULL); // aliases
628 abuf_json_mark_array_entry(false, abuf); // entry
633 abuf_json_mark_object(false, true, abuf, NULL); // mid
638 static void ipc_print_gateways_ipvx(struct autobuf *abuf, bool ipv6) {
639 abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
641 if (olsr_cnf->smart_gw_active) {
642 struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
643 struct gateway_entry * gw;
644 OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
645 if ((!ipv6 && !gw->ipv4) || (ipv6 && !gw->ipv6)) {
646 /* gw does not advertise the requested IP version */
650 abuf_json_mark_array_entry(true, abuf);
651 ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
652 abuf_json_mark_array_entry(false, abuf);
653 } OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
656 abuf_json_mark_object(false, true, abuf, NULL);
658 #endif /* __linux__ */
660 void ipc_print_gateways(struct autobuf *abuf) {
662 abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
663 #else /* __linux__ */
664 abuf_json_mark_object(true, false, abuf, "gateways");
666 ipc_print_gateways_ipvx(abuf, false);
667 ipc_print_gateways_ipvx(abuf, true);
669 abuf_json_mark_object(false, false, abuf, NULL);
670 #endif /* __linux__ */
675 /** interface names for smart gateway tunnel interfaces, IPv4 */
676 extern struct interfaceName * sgwTunnel4InterfaceNames;
678 /** interface names for smart gateway tunnel interfaces, IPv6 */
679 extern struct interfaceName * sgwTunnel6InterfaceNames;
682 * Construct the sgw table for a given ip version
684 * @param abuf the string buffer
685 * @param ipv6 true for IPv6, false for IPv4
686 * @param fmtv the format for printing
688 static void sgw_ipvx(struct autobuf *abuf, bool ipv6) {
689 struct interfaceName * sgwTunnelInterfaceNames = !ipv6 ? sgwTunnel4InterfaceNames : sgwTunnel6InterfaceNames;
691 abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
693 if (olsr_cnf->smart_gw_active && sgwTunnelInterfaceNames) {
694 struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
696 for (i = 0; i < olsr_cnf->smart_gw_use_count; i++) {
697 struct interfaceName * node = &sgwTunnelInterfaceNames[i];
698 struct gateway_entry * gw = node->gw;
704 abuf_json_mark_array_entry(true, abuf);
705 ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
706 abuf_json_ip_address(abuf, "destination", &gw->originator);
707 abuf_json_string(abuf, "tunnel", node->name);
708 abuf_json_int(abuf, "tableNr", node->tableNr);
709 abuf_json_int(abuf, "ruleNr", node->ruleNr);
710 abuf_json_int(abuf, "bypassRuleNr", node->bypassRuleNr);
711 abuf_json_mark_array_entry(false, abuf);
715 abuf_json_mark_object(false, true, abuf, NULL);
717 #endif /* __linux__ */
719 void ipc_print_sgw(struct autobuf *abuf) {
721 abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
723 abuf_json_mark_object(true, false, abuf, "sgw");
725 sgw_ipvx(abuf, false);
726 sgw_ipvx(abuf, true);
728 abuf_json_mark_object(false, false, abuf, NULL);
729 #endif /* __linux__ */
732 void ipc_print_version(struct autobuf *abuf) {
733 abuf_json_mark_object(true, false, abuf, "version");
735 abuf_json_string(abuf, "version", olsrd_version);
737 abuf_json_string(abuf, "date", build_date);
738 abuf_json_string(abuf, "host", build_host);
739 abuf_json_string(abuf, "gitDescriptor", git_descriptor);
740 abuf_json_string(abuf, "gitSha", git_sha);
741 abuf_json_string(abuf, "releaseVersion", release_version);
742 abuf_json_string(abuf, "sourceHash", source_hash);
744 abuf_json_mark_object(false, false, abuf, NULL);
747 void ipc_print_olsrd_conf(struct autobuf *abuf) {
748 olsrd_write_cnf_autobuf(abuf, olsr_cnf);
751 void ipc_print_interfaces(struct autobuf *abuf) {
754 abuf_json_mark_object(true, true, abuf, "interfaces");
755 for (ifs = olsr_cnf->interfaces; ifs != NULL ; ifs = ifs->next) {
756 abuf_json_mark_array_entry(true, abuf);
757 abuf_json_string(abuf, "name", ifs->name);
758 abuf_json_boolean(abuf, "configured", ifs->configured);
759 abuf_json_boolean(abuf, "hostEmulation", ifs->host_emul);
760 abuf_json_ip_address(abuf, "hostEmulationAddress", &ifs->hemu_ip);
761 print_interface_olsr(abuf, "olsrInterface", ifs->interf);
762 print_interface_config(abuf, "InterfaceConfiguration", ifs->cnf);
763 print_interface_config(abuf, "InterfaceConfigurationDefaults", ifs->cnfi);
764 abuf_json_mark_array_entry(false, abuf);
766 abuf_json_mark_object(false, true, abuf, NULL); // interfaces
769 void ipc_print_twohop(struct autobuf *abuf) {
770 ipc_print_neighbors_internal(abuf, true);
773 void ipc_print_config(struct autobuf *abuf) {
774 abuf_json_mark_object(true, false, abuf, "config");
776 abuf_json_string(abuf, "configurationFile", olsr_cnf->configuration_file);
777 abuf_json_int(abuf, "olsrPort", olsr_cnf->olsrport);
778 abuf_json_int(abuf, "debugLevel", olsr_cnf->debug_level);
779 abuf_json_boolean(abuf, "noFork", olsr_cnf->no_fork);
780 abuf_json_string(abuf, "pidFile", olsr_cnf->pidfile);
781 abuf_json_boolean(abuf, "hostEmulation", olsr_cnf->host_emul);
782 abuf_json_int(abuf, "ipVersion", olsr_cnf->ip_version);
783 abuf_json_boolean(abuf, "allowNoInt", olsr_cnf->allow_no_interfaces);
784 abuf_json_int(abuf, "tosValue", olsr_cnf->tos);
785 abuf_json_int(abuf, "rtProto", olsr_cnf->rt_proto);
786 abuf_json_int(abuf, "rtTable", olsr_cnf->rt_table);
787 abuf_json_int(abuf, "rtTableDefault", olsr_cnf->rt_table_default);
788 abuf_json_int(abuf, "rtTableTunnel", olsr_cnf->rt_table_tunnel);
789 abuf_json_int(abuf, "rtTablePriority", olsr_cnf->rt_table_pri);
790 abuf_json_int(abuf, "rtTableTunnelPriority", olsr_cnf->rt_table_tunnel_pri);
791 abuf_json_int(abuf, "rtTableDefauiltOlsrPriority", olsr_cnf->rt_table_defaultolsr_pri);
792 abuf_json_int(abuf, "rtTableDefaultPriority", olsr_cnf->rt_table_default_pri);
793 abuf_json_int(abuf, "willingness", olsr_cnf->willingness);
794 abuf_json_boolean(abuf, "willingnessAuto", olsr_cnf->willingness_auto);
795 // ipc_connections: later
796 abuf_json_boolean(abuf, "useHysteresis", olsr_cnf->use_hysteresis);
797 abuf_json_string(abuf, "fibMetric", FIB_METRIC_TXT[olsr_cnf->fib_metric]);
798 abuf_json_string(abuf, "fibMetricDefault", FIB_METRIC_TXT[olsr_cnf->fib_metric_default]);
799 abuf_json_float(abuf, "hystScaling", olsr_cnf->hysteresis_param.scaling);
800 abuf_json_float(abuf, "hystThrLow", olsr_cnf->hysteresis_param.thr_low);
801 abuf_json_float(abuf, "hystThrHigh", olsr_cnf->hysteresis_param.thr_high);
805 struct ip_prefix_list *hna;
807 abuf_json_mark_object(true, true, abuf, "hna");
809 /* Announced HNA entries */
810 for (hna = olsr_cnf->hna_entries; hna; hna = hna->next) {
811 print_hna_array_entry( //
813 &olsr_cnf->main_addr, //
815 hna->net.prefix_len, //
818 abuf_json_mark_object(false, true, abuf, NULL);
821 // interface_defaults: later
823 abuf_json_float(abuf, "pollrate", olsr_cnf->pollrate);
824 abuf_json_float(abuf, "nicChgsPollInt", olsr_cnf->nic_chgs_pollrate);
825 abuf_json_boolean(abuf, "clearScreen", olsr_cnf->clear_screen);
826 abuf_json_int(abuf, "tcRedundancy", olsr_cnf->tc_redundancy);
827 abuf_json_int(abuf, "mprCoverage", olsr_cnf->mpr_coverage);
828 abuf_json_int(abuf, "linkQualityLevel", olsr_cnf->lq_level);
829 abuf_json_boolean(abuf, "linkQualityFishEye", olsr_cnf->lq_fish);
830 abuf_json_float(abuf, "linkQualityAging", olsr_cnf->lq_aging);
831 abuf_json_string(abuf, "linkQualityAlgorithm", olsr_cnf->lq_algorithm);
833 abuf_json_float(abuf, "minTCVTime", olsr_cnf->min_tc_vtime);
835 abuf_json_boolean(abuf, "setIpForward", olsr_cnf->set_ip_forward);
837 abuf_json_string(abuf, "lockFile", olsr_cnf->lock_file);
838 abuf_json_boolean(abuf, "useNiit", olsr_cnf->use_niit);
840 abuf_json_boolean(abuf, "smartGateway", olsr_cnf->smart_gw_active);
841 abuf_json_boolean(abuf, "smartGatewayAlwaysRemoveServerTunnel", olsr_cnf->smart_gw_always_remove_server_tunnel);
842 abuf_json_boolean(abuf, "smartGatewayAllowNAT", olsr_cnf->smart_gw_allow_nat);
843 abuf_json_boolean(abuf, "smartGatewayUplinkNAT", olsr_cnf->smart_gw_uplink_nat);
844 abuf_json_int(abuf, "smartGatewayUseCount", olsr_cnf->smart_gw_use_count);
845 abuf_json_int(abuf, "smartGatewayTakeDownPercentage", olsr_cnf->smart_gw_takedown_percentage);
846 abuf_json_string(abuf, "smartGatewayInstanceId", olsr_cnf->smart_gw_instance_id);
847 abuf_json_string(abuf, "smartGatewayPolicyRoutingScript", olsr_cnf->smart_gw_policyrouting_script);
848 // smart_gw_egress_interfaces
850 struct sgw_egress_if * egressif = olsr_cnf->smart_gw_egress_interfaces;
852 abuf_json_mark_object(true, true, abuf, "smartGatewayEgressInterfaces");
854 abuf_json_mark_array_entry(true, abuf);
855 abuf_json_string(abuf, "interface", egressif->name);
856 abuf_json_mark_array_entry(false, abuf);
858 egressif = egressif->next;
860 abuf_json_mark_object(false, true, abuf, NULL);
862 abuf_json_int(abuf, "smartGatewayEgressInterfacesCount", olsr_cnf->smart_gw_egress_interfaces_count);
863 abuf_json_string(abuf, "smartGatewayEgressFile", olsr_cnf->smart_gw_egress_file);
864 abuf_json_int(abuf, "smartGatewayEgressFilePeriod", olsr_cnf->smart_gw_egress_file_period);
865 abuf_json_string(abuf, "smartGatewayStatusFile", olsr_cnf->smart_gw_status_file);
866 abuf_json_int(abuf, "smartGatewayTablesOffset", olsr_cnf->smart_gw_offset_tables);
867 abuf_json_int(abuf, "smartGatewayRulesOffset", olsr_cnf->smart_gw_offset_rules);
868 abuf_json_int(abuf, "smartGatewayPeriod", olsr_cnf->smart_gw_period);
869 abuf_json_int(abuf, "smartGatewayStableCount", olsr_cnf->smart_gw_stablecount);
870 abuf_json_int(abuf, "smartGatewayThreshold", olsr_cnf->smart_gw_thresh);
871 abuf_json_int(abuf, "smartGatewayWeightExitLinkUp", olsr_cnf->smart_gw_weight_exitlink_up);
872 abuf_json_int(abuf, "smartGatewayWeightExitLinkDown", olsr_cnf->smart_gw_weight_exitlink_down);
873 abuf_json_int(abuf, "smartGatewayWeightEtx", olsr_cnf->smart_gw_weight_etx);
874 abuf_json_int(abuf, "smartGatewayDividerEtx", olsr_cnf->smart_gw_divider_etx);
875 abuf_json_int(abuf, "smartGatewayMaxCostMaxEtx", olsr_cnf->smart_gw_path_max_cost_etx_max);
876 abuf_json_string(abuf, "smartGatewayUplink", GW_UPLINK_TXT[olsr_cnf->smart_gw_type]);
877 abuf_json_int(abuf, "smartGatewayUplinkKbps", olsr_cnf->smart_gw_uplink);
878 abuf_json_int(abuf, "smartGatewayDownlinkKbps", olsr_cnf->smart_gw_downlink);
879 abuf_json_boolean(abuf, "smartGatewayBandwidthZero", olsr_cnf->smart_gateway_bandwidth_zero);
880 abuf_json_ip_address(abuf, "smartGatewayPrefix", &olsr_cnf->smart_gw_prefix.prefix);
881 abuf_json_int(abuf, "smartGatewayPrefixLength", olsr_cnf->smart_gw_prefix.prefix_len);
884 abuf_json_ip_address(abuf, "mainIp", &olsr_cnf->main_addr);
885 abuf_json_ip_address(abuf, "unicastSourceIpAddress", &olsr_cnf->unicast_src_ip);
886 abuf_json_boolean(abuf, "srcIpRoutes", olsr_cnf->use_src_ip_routes);
889 abuf_json_int(abuf, "maxPrefixLength", olsr_cnf->maxplen);
890 abuf_json_int(abuf, "ipSize", olsr_cnf->ipsize);
891 abuf_json_boolean(abuf, "delgw", olsr_cnf->del_gws);
892 abuf_json_float(abuf, "willingnessUpdateInterval", olsr_cnf->will_int);
893 abuf_json_float(abuf, "maxSendMessageJitter", olsr_cnf->max_jitter);
894 abuf_json_int(abuf, "exitValue", olsr_cnf->exit_value);
895 abuf_json_float(abuf, "maxTcValidTime", olsr_cnf->max_tc_vtime);
897 abuf_json_int(abuf, "niit4to6InterfaceIndex", olsr_cnf->niit4to6_if_index);
898 abuf_json_int(abuf, "niit6to4InterfaceIndex", olsr_cnf->niit6to4_if_index);
901 abuf_json_boolean(abuf, "hasIpv4Gateway", olsr_cnf->has_ipv4_gateway);
902 abuf_json_boolean(abuf, "hasIpv6Gateway", olsr_cnf->has_ipv6_gateway);
904 abuf_json_int(abuf, "ioctlSocket", olsr_cnf->ioctl_s);
906 abuf_json_int(abuf, "routeNetlinkSocket", olsr_cnf->rtnl_s);
907 abuf_json_int(abuf, "routeMonitorSocket", olsr_cnf->rt_monitor_socket);
908 #endif /* __linux__ */
910 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
911 abuf_json_int(abuf, "routeChangeSocket", olsr_cnf->rts);
912 #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ */
913 abuf_json_float(abuf, "linkQualityNatThreshold", olsr_cnf->lq_nat_thresh);
917 abuf_json_int(abuf, "brokenLinkCost", LINK_COST_BROKEN);
918 abuf_json_int(abuf, "brokenRouteCost", ROUTE_COST_BROKEN);
921 // IpcConnect section
922 abuf_json_int(abuf, "ipcConnectMaxConnections", olsr_cnf->ipc_connections);
924 struct ip_prefix_list *ipc_nets;
926 abuf_json_mark_object(true, true, abuf, "ipcConnectAllowed");
927 for (ipc_nets = olsr_cnf->ipc_nets; ipc_nets; ipc_nets = ipc_nets->next) {
928 print_ipc_net_array_entry(abuf, ipc_nets);
930 abuf_json_mark_object(false, true, abuf, NULL);
934 // plugins section: use /plugins
937 // InterfaceDefaults section
938 print_interface_config(abuf, "interfaceDefaults", olsr_cnf->interface_defaults);
941 // Interface(s) section: use /interfaces
945 #if defined _WIN32 || defined _WIN64
946 abuf_json_string(abuf, "os", "Windows");
947 #elif defined __gnu_linux__
948 abuf_json_string(abuf, "os", "GNU/Linux");
949 #elif defined __ANDROID__
950 abuf_json_string(abuf, "os", "Android");
951 #elif defined __APPLE__
952 abuf_json_string(abuf, "os", "Mac OS X");
953 #elif defined __NetBSD__
954 abuf_json_string(abuf, "os", "NetBSD");
955 #elif defined __OpenBSD__
956 abuf_json_string(abuf, "os", "OpenBSD");
957 #elif defined __FreeBSD__ || defined __FreeBSD_kernel__
958 abuf_json_string(abuf, "os", "FreeBSD");
959 #else /* OS detection */
960 abuf_json_string(abuf, "os", "Undefined");
961 #endif /* OS detection */
963 abuf_json_int(abuf, "startTime", start_time.tv_sec);
965 abuf_json_mark_object(false, false, abuf, NULL);
968 void ipc_print_plugins(struct autobuf *abuf) {
969 abuf_json_mark_object(true, true, abuf, "plugins");
970 if (olsr_cnf->plugins) {
971 struct plugin_entry *plugin;
973 for (plugin = olsr_cnf->plugins; plugin; plugin = plugin->next) {
974 struct plugin_param *param;
976 abuf_json_mark_array_entry(true, abuf);
977 abuf_json_string(abuf, "plugin", plugin->name);
978 for (param = plugin->params; param; param = param->next) {
979 abuf_json_string(abuf, param->key, param->value);
981 abuf_json_mark_array_entry(false, abuf);
984 abuf_json_mark_object(false, true, abuf, NULL);