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 ipc_print_neighbors_internal(struct autobuf *abuf, bool list_2hop) {
209 struct ipaddr_str neighAddrBuf;
210 struct neighbor_entry *neigh;
211 struct neighbor_2_list_entry *list_2;
215 abuf_json_mark_object(true, true, abuf, "neighbors");
217 abuf_json_mark_object(true, true, abuf, "2hop");
221 OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
222 abuf_json_mark_array_entry(true, abuf);
224 abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&neighAddrBuf, &neigh->neighbor_main_addr));
225 abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
226 abuf_json_int(abuf, "willingness", neigh->willingness);
227 abuf_json_boolean(abuf, "isMultiPointRelay", neigh->is_mpr);
228 abuf_json_boolean(abuf, "wasMultiPointRelay", neigh->was_mpr);
229 abuf_json_boolean(abuf, "multiPointRelaySelector", olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
230 abuf_json_boolean(abuf, "skip", neigh->skip);
231 abuf_json_int(abuf, "neighbor2nocov", neigh->neighbor_2_nocov);
232 abuf_json_int(abuf, "linkcount", neigh->linkcount);
235 abuf_json_mark_object(true, true, abuf, "twoHopNeighbors");
239 for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
240 if (list_2hop && list_2->neighbor_2) {
241 abuf_json_mark_array_entry(true, abuf);
242 abuf_json_string(abuf, "ipAddress", list_2->neighbor_2 ? olsr_ip_to_string(&neighAddrBuf, &list_2->neighbor_2->neighbor_2_addr) : "");
243 abuf_json_mark_array_entry(false, abuf);
249 abuf_json_mark_object(false, true, abuf, NULL);
251 abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
253 abuf_json_mark_array_entry(false, abuf);
254 } OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
255 abuf_json_mark_object(false, true, abuf, NULL);
258 void ipc_print_neighbors(struct autobuf *abuf) {
259 ipc_print_neighbors_internal(abuf, false);
262 void ipc_print_links(struct autobuf *abuf) {
263 struct link_entry *my_link;
265 abuf_json_mark_object(true, true, abuf, "links");
267 OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
268 struct ipaddr_str localAddr;
269 struct ipaddr_str remoteAddr;
270 struct lqtextbuffer lqBuffer;
271 const char* lqString = get_link_entry_text(my_link, '\t', &lqBuffer);
272 char * nlqString = strrchr(lqString, '\t');
279 abuf_json_mark_array_entry(true, abuf);
281 abuf_json_string(abuf, "localIP", olsr_ip_to_string(&localAddr, &my_link->local_iface_addr));
282 abuf_json_string(abuf, "remoteIP", olsr_ip_to_string(&remoteAddr, &my_link->neighbor_iface_addr));
283 abuf_json_string(abuf, "olsrInterface", (my_link->inter && my_link->inter->int_name) ? my_link->inter->int_name : "");
284 abuf_json_string(abuf, "ifName", my_link->if_name ? my_link->if_name : "");
285 abuf_json_int(abuf, "validityTime", my_link->link_timer ? (long) (my_link->link_timer->timer_clock - now_times) : 0);
286 abuf_json_int(abuf, "symmetryTime", my_link->link_sym_timer ? (long) (my_link->link_sym_timer->timer_clock - now_times) : 0);
287 abuf_json_int(abuf, "asymmetryTime", my_link->ASYM_time);
288 abuf_json_int(abuf, "vtime", (long) my_link->vtime);
289 // neighbor (no need to print, can be looked up via neighbours)
290 abuf_json_string(abuf, "currentLinkStatus", linkTypeToString(lookup_link_status(my_link)));
291 abuf_json_string(abuf, "previousLinkStatus", linkTypeToString(my_link->prev_status));
293 abuf_json_float(abuf, "hysteresis", my_link->L_link_quality);
294 abuf_json_boolean(abuf, "pending", my_link->L_link_pending != 0);
295 abuf_json_int(abuf, "lostLinkTime", (long) my_link->L_LOST_LINK_time);
296 abuf_json_int(abuf, "helloTime", my_link->link_hello_timer ? (long) (my_link->link_hello_timer->timer_clock - now_times) : 0);
297 abuf_json_int(abuf, "lastHelloTime", (long) my_link->last_htime);
298 abuf_json_boolean(abuf, "seqnoValid", my_link->olsr_seqno_valid);
299 abuf_json_int(abuf, "seqno", my_link->olsr_seqno);
301 abuf_json_int(abuf, "lossHelloInterval", (long) my_link->loss_helloint);
302 abuf_json_int(abuf, "lossTime", my_link->link_loss_timer ? (long) (my_link->link_loss_timer->timer_clock - now_times) : 0);
304 abuf_json_int(abuf, "lossMultiplier", (long) my_link->loss_link_multiplier);
306 abuf_json_int(abuf, "linkCost", MIN(my_link->linkcost, LINK_COST_BROKEN));
308 abuf_json_float(abuf, "linkQuality", atof(lqString));
309 abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
311 abuf_json_mark_array_entry(false, abuf);
312 } OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
313 abuf_json_mark_object(false, true, abuf, NULL);
316 void ipc_print_routes(struct autobuf *abuf) {
319 abuf_json_mark_object(true, true, abuf, "routes");
321 /* Walk the route table */
322 OLSR_FOR_ALL_RT_ENTRIES(rt) {
323 struct ipaddr_str dstAddr;
324 struct ipaddr_str nexthopAddr;
325 struct lqtextbuffer costbuffer;
328 abuf_json_mark_array_entry(true, abuf);
329 abuf_json_string(abuf, "destination", olsr_ip_to_string(&dstAddr, &rt->rt_dst.prefix));
330 abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
331 abuf_json_string(abuf, "gateway", olsr_ip_to_string(&nexthopAddr, &rt->rt_best->rtp_nexthop.gateway));
332 abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
333 abuf_json_float(abuf, "etx", atof(get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &costbuffer)));
334 abuf_json_int(abuf, "rtpMetricCost", MIN(ROUTE_COST_BROKEN, rt->rt_best->rtp_metric.cost));
335 abuf_json_string(abuf, "networkInterface", if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
336 abuf_json_mark_array_entry(false, abuf);
338 } OLSR_FOR_ALL_RT_ENTRIES_END(rt);
340 abuf_json_mark_object(false, true, abuf, NULL);
343 void ipc_print_topology(struct autobuf *abuf) {
346 abuf_json_mark_object(true, true, abuf, "topology");
349 OLSR_FOR_ALL_TC_ENTRIES(tc) {
350 struct tc_edge_entry *tc_edge;
351 OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
352 if (tc_edge->edge_inv) {
353 struct ipaddr_str dstAddr;
354 struct ipaddr_str lastHopAddr;
355 struct lqtextbuffer lqbuffer;
357 const char* lqString = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer);
358 char * nlqString = strrchr(lqString, '\t');
365 abuf_json_mark_array_entry(true, abuf);
368 abuf_json_string(abuf, "lastHopIP", olsr_ip_to_string(&lastHopAddr, &tc->addr));
370 abuf_json_int(abuf, "pathCost", MIN(tc->path_cost, ROUTE_COST_BROKEN));
376 abuf_json_int(abuf, "validityTime", tc->validity_timer ? (tc->validity_timer->timer_clock - now_times) : 0);
377 abuf_json_int(abuf, "refCount", tc->refcount);
378 abuf_json_int(abuf, "msgSeq", tc->msg_seq);
379 abuf_json_int(abuf, "msgHops", tc->msg_hops);
380 abuf_json_int(abuf, "hops", tc->hops);
381 abuf_json_int(abuf, "ansn", tc->ansn);
382 abuf_json_int(abuf, "tcIgnored", tc->ignored);
384 abuf_json_int(abuf, "errSeq", tc->err_seq);
385 abuf_json_boolean(abuf, "errSeqValid", tc->err_seq_valid);
388 abuf_json_string(abuf, "destinationIP", olsr_ip_to_string(&dstAddr, &tc_edge->T_dest_addr));
390 abuf_json_int(abuf, "tcEdgeCost", MIN(LINK_COST_BROKEN, tc_edge->cost));
391 abuf_json_int(abuf, "ansnEdge", tc_edge->ansn);
392 abuf_json_float(abuf, "linkQuality", atof(lqString));
393 abuf_json_float(abuf, "neighborLinkQuality", nlqString ? atof(nlqString) : 0.0);
395 abuf_json_mark_array_entry(false, abuf);
397 } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
398 } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
400 abuf_json_mark_object(false, true, abuf, NULL);
403 void ipc_print_hna(struct autobuf *abuf) {
404 struct ip_prefix_list *hna;
405 struct hna_entry *tmp_hna;
406 struct ipaddr_str prefixbuf;
407 struct ipaddr_str gwaddrbuf;
409 olsr_ip_to_string(&gwaddrbuf, &olsr_cnf->main_addr);
411 abuf_json_mark_object(true, true, abuf, "hna");
413 /* Announced HNA entries */
414 for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
415 abuf_json_mark_array_entry(true, abuf);
416 abuf_json_string(abuf, "gateway", gwaddrbuf.buf);
417 abuf_json_string(abuf, "destination", olsr_ip_to_string(&prefixbuf, &hna->net.prefix));
418 abuf_json_int(abuf, "genmask", hna->net.prefix_len);
419 abuf_json_int(abuf, "validityTime", 0);
420 abuf_json_mark_array_entry(false, abuf);
423 OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
424 struct hna_net *tmp_net;
426 olsr_ip_to_string(&gwaddrbuf, &tmp_hna->A_gateway_addr);
428 /* Check all networks */
429 for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
430 abuf_json_mark_array_entry(true, abuf);
431 abuf_json_string(abuf, "gateway", gwaddrbuf.buf);
432 abuf_json_string(abuf, "destination", olsr_ip_to_string(&prefixbuf, &tmp_net->hna_prefix.prefix));
433 abuf_json_int(abuf, "genmask", tmp_net->hna_prefix.prefix_len);
434 abuf_json_int(abuf, "validityTime", tmp_net->hna_net_timer ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0);
435 abuf_json_mark_array_entry(false, abuf);
437 } OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
439 abuf_json_mark_object(false, true, abuf, NULL);
442 void ipc_print_mid(struct autobuf *abuf) {
445 abuf_json_mark_object(true, true, abuf, "mid");
448 for (idx = 0; idx < HASHSIZE; idx++) {
449 struct mid_entry * entry = mid_set[idx].next;
451 while (entry != &mid_set[idx]) {
452 struct ipaddr_str midAddr;
454 abuf_json_mark_array_entry(true, abuf);
455 abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&midAddr, &entry->main_addr));
456 abuf_json_int(abuf, "validityTime", entry->mid_timer ? (entry->mid_timer->timer_clock - now_times) : 0);
458 struct mid_address * alias = entry->aliases;
460 abuf_json_mark_object(true, true, abuf, "aliases");
462 struct ipaddr_str aliasAddr;
464 abuf_json_mark_array_entry(true, abuf);
465 abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&aliasAddr, &alias->alias));
466 abuf_json_int(abuf, "validityTime", alias->vtime - now_times);
467 abuf_json_mark_array_entry(false, abuf);
469 alias = alias->next_alias;
471 abuf_json_mark_object(false, true, abuf, NULL); // aliases
473 abuf_json_mark_array_entry(false, abuf); // entry
478 abuf_json_mark_object(false, true, abuf, NULL); // mid
483 static void ipc_print_gateway_entry(struct autobuf *abuf, bool ipv6, struct gateway_entry * current_gw, struct gateway_entry * gw) {
484 struct tc_entry* tc = olsr_lookup_tc_entry(&gw->originator);
486 abuf_json_boolean(abuf, "selected", current_gw && (current_gw == gw));
487 abuf_json_boolean(abuf, "selectable", isGwSelectable(gw, ipv6));
488 abuf_json_ip_address(abuf, "originator", &gw->originator);
489 abuf_json_ip_address(abuf, "prefix", &gw->external_prefix.prefix);
490 abuf_json_int(abuf, "prefixLen", gw->external_prefix.prefix_len);
491 abuf_json_int(abuf, "uplink", gw->uplink);
492 abuf_json_int(abuf, "downlink", gw->downlink);
493 abuf_json_int(abuf, "cost", gw->path_cost);
494 abuf_json_boolean(abuf, "IPv4", gw->ipv4);
495 abuf_json_boolean(abuf, "IPv4-NAT", gw->ipv4nat);
496 abuf_json_boolean(abuf, "IPv6", gw->ipv6);
497 abuf_json_int(abuf, "expireTime", gw->expire_timer ? (gw->expire_timer->timer_clock - now_times) : 0);
498 abuf_json_int(abuf, "cleanupTime", gw->cleanup_timer ? (gw->cleanup_timer->timer_clock - now_times) : 0);
500 abuf_json_int(abuf, "pathcost", !tc ? ROUTE_COST_BROKEN : tc->path_cost);
501 abuf_json_int(abuf, "hops", !tc ? 0 : tc->hops);
504 static void ipc_print_gateways_ipvx(struct autobuf *abuf, bool ipv6) {
505 abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
507 if (olsr_cnf->smart_gw_active) {
508 struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
509 struct gateway_entry * gw;
510 OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
511 if ((!ipv6 && !gw->ipv4) || (ipv6 && !gw->ipv6)) {
512 /* gw does not advertise the requested IP version */
516 abuf_json_mark_array_entry(true, abuf);
517 ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
518 abuf_json_mark_array_entry(false, abuf);
519 } OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
522 abuf_json_mark_object(false, true, abuf, NULL);
524 #endif /* __linux__ */
526 void ipc_print_gateways(struct autobuf *abuf) {
528 abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
529 #else /* __linux__ */
530 abuf_json_mark_object(true, false, abuf, "gateways");
532 ipc_print_gateways_ipvx(abuf, false);
533 ipc_print_gateways_ipvx(abuf, true);
535 abuf_json_mark_object(false, false, abuf, NULL);
536 #endif /* __linux__ */
541 /** interface names for smart gateway tunnel interfaces, IPv4 */
542 extern struct interfaceName * sgwTunnel4InterfaceNames;
544 /** interface names for smart gateway tunnel interfaces, IPv6 */
545 extern struct interfaceName * sgwTunnel6InterfaceNames;
548 * Construct the sgw table for a given ip version
550 * @param abuf the string buffer
551 * @param ipv6 true for IPv6, false for IPv4
552 * @param fmtv the format for printing
554 static void sgw_ipvx(struct autobuf *abuf, bool ipv6) {
555 struct interfaceName * sgwTunnelInterfaceNames = !ipv6 ? sgwTunnel4InterfaceNames : sgwTunnel6InterfaceNames;
557 abuf_json_mark_object(true, true, abuf, ipv6 ? "ipv6" : "ipv4");
559 if (olsr_cnf->smart_gw_active && sgwTunnelInterfaceNames) {
560 struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
562 for (i = 0; i < olsr_cnf->smart_gw_use_count; i++) {
563 struct interfaceName * node = &sgwTunnelInterfaceNames[i];
564 struct gateway_entry * gw = node->gw;
570 abuf_json_mark_array_entry(true, abuf);
571 ipc_print_gateway_entry(abuf, ipv6, current_gw, gw);
572 abuf_json_ip_address(abuf, "destination", &gw->originator);
573 abuf_json_string(abuf, "tunnel", node->name);
574 abuf_json_int(abuf, "tableNr", node->tableNr);
575 abuf_json_int(abuf, "ruleNr", node->ruleNr);
576 abuf_json_int(abuf, "bypassRuleNr", node->bypassRuleNr);
577 abuf_json_mark_array_entry(false, abuf);
581 abuf_json_mark_object(false, true, abuf, NULL);
583 #endif /* __linux__ */
585 void ipc_print_sgw(struct autobuf *abuf) {
587 abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
589 abuf_json_mark_object(true, false, abuf, "sgw");
591 sgw_ipvx(abuf, false);
592 sgw_ipvx(abuf, true);
594 abuf_json_mark_object(false, false, abuf, NULL);
595 #endif /* __linux__ */
598 void ipc_print_version(struct autobuf *abuf) {
599 abuf_json_mark_object(true, false, abuf, "version");
601 abuf_json_string(abuf, "version", olsrd_version);
603 abuf_json_string(abuf, "date", build_date);
604 abuf_json_string(abuf, "host", build_host);
605 abuf_json_string(abuf, "gitDescriptor", git_descriptor);
606 abuf_json_string(abuf, "gitSha", git_sha);
607 abuf_json_string(abuf, "releaseVersion", release_version);
608 abuf_json_string(abuf, "sourceHash", source_hash);
610 abuf_json_mark_object(false, false, abuf, NULL);
613 void ipc_print_olsrd_conf(struct autobuf *abuf) {
614 olsrd_write_cnf_autobuf(abuf, olsr_cnf);
617 void ipc_print_interfaces(struct autobuf *abuf) {
620 char path[PATH_MAX], linkpath[PATH_MAX];
621 #endif /* __linux__ */
622 char ipv6_buf[INET6_ADDRSTRLEN]; /* buffer for IPv6 inet_htop */
623 struct olsr_lq_mult *mult;
624 const struct olsr_if *ifs;
625 abuf_json_mark_object(true, true, abuf, "interfaces");
626 for (ifs = olsr_cnf->interfaces; ifs != NULL ; ifs = ifs->next) {
627 const struct interface_olsr * const rifs = ifs->interf;
628 abuf_json_mark_array_entry(true, abuf);
629 abuf_json_string(abuf, "name", ifs->name);
631 abuf_json_mark_object(true, true, abuf, "linkQualityMultipliers");
632 for (mult = ifs->cnf->lq_mult; mult != NULL ; mult = mult->next) {
633 abuf_json_mark_array_entry(true, abuf);
634 abuf_json_string(abuf, "route", inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
635 abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
636 abuf_json_mark_array_entry(false, abuf);
638 abuf_json_mark_object(false, true, abuf, NULL); // linkQualityMultipliers
641 abuf_json_string(abuf, "state", "down");
643 abuf_json_string(abuf, "state", "up");
644 abuf_json_string(abuf, "nameFromKernel", rifs->int_name);
645 abuf_json_int(abuf, "interfaceMode", rifs->mode);
646 abuf_json_boolean(abuf, "emulatedHostClientInterface", rifs->is_hcif);
647 abuf_json_boolean(abuf, "sendTcImmediately", rifs->immediate_send_tc);
648 abuf_json_int(abuf, "fishEyeTtlIndex", rifs->ttl_index);
649 abuf_json_int(abuf, "olsrForwardingTimeout", rifs->fwdtimer);
650 abuf_json_int(abuf, "olsrMessageSequenceNumber", rifs->olsr_seqnum);
651 abuf_json_int(abuf, "olsrInterfaceMetric", rifs->int_metric);
652 abuf_json_int(abuf, "olsrMTU", rifs->int_mtu);
653 abuf_json_int(abuf, "helloEmissionInterval", rifs->hello_etime);
654 abuf_json_int(abuf, "helloValidityTime", me_to_reltime(rifs->valtimes.hello));
655 abuf_json_int(abuf, "tcValidityTime", me_to_reltime(rifs->valtimes.tc));
656 abuf_json_int(abuf, "midValidityTime", me_to_reltime(rifs->valtimes.mid));
657 abuf_json_int(abuf, "hnaValidityTime", me_to_reltime(rifs->valtimes.hna));
658 abuf_json_boolean(abuf, "wireless", rifs->is_wireless);
661 abuf_json_boolean(abuf, "icmpRedirect", rifs->nic_state.redirect);
662 abuf_json_boolean(abuf, "spoofFilter", rifs->nic_state.spoof);
663 #endif /* __linux__ */
665 if (olsr_cnf->ip_version == AF_INET) {
666 struct ipaddr_str addrbuf, maskbuf, bcastbuf;
667 abuf_json_string(abuf, "ipv4Address", ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
668 abuf_json_string(abuf, "netmask", ip4_to_string(&maskbuf, rifs->int_netmask.sin_addr));
669 abuf_json_string(abuf, "broadcast", ip4_to_string(&bcastbuf, rifs->int_broadaddr.sin_addr));
671 struct ipaddr_str addrbuf, maskbuf;
672 abuf_json_string(abuf, "ipv6Address", ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
673 abuf_json_string(abuf, "multicast", ip6_to_string(&maskbuf, &rifs->int6_multaddr.sin6_addr));
677 snprintf(path, PATH_MAX, "/sys/class/net/%s/device/driver/module", ifs->name);
678 linklen = readlink(path, linkpath, PATH_MAX - 1);
680 linkpath[linklen] = '\0';
681 abuf_json_string(abuf, "kernelModule", basename(linkpath));
684 abuf_json_sys_class_net(abuf, "addressLength", ifs->name, "addr_len");
685 abuf_json_sys_class_net(abuf, "carrier", ifs->name, "carrier");
686 abuf_json_sys_class_net(abuf, "dormant", ifs->name, "dormant");
687 abuf_json_sys_class_net(abuf, "features", ifs->name, "features");
688 abuf_json_sys_class_net(abuf, "flags", ifs->name, "flags");
689 abuf_json_sys_class_net(abuf, "linkMode", ifs->name, "link_mode");
690 abuf_json_sys_class_net(abuf, "macAddress", ifs->name, "address");
691 abuf_json_sys_class_net(abuf, "ethernetMTU", ifs->name, "mtu");
692 abuf_json_sys_class_net(abuf, "operationalState", ifs->name, "operstate");
693 abuf_json_sys_class_net(abuf, "txQueueLength", ifs->name, "tx_queue_len");
694 abuf_json_sys_class_net(abuf, "collisions", ifs->name, "statistics/collisions");
695 abuf_json_sys_class_net(abuf, "multicastPackets", ifs->name, "statistics/multicast");
696 abuf_json_sys_class_net(abuf, "rxBytes", ifs->name, "statistics/rx_bytes");
697 abuf_json_sys_class_net(abuf, "rxCompressed", ifs->name, "statistics/rx_compressed");
698 abuf_json_sys_class_net(abuf, "rxCrcErrors", ifs->name, "statistics/rx_crc_errors");
699 abuf_json_sys_class_net(abuf, "rxDropped", ifs->name, "statistics/rx_dropped");
700 abuf_json_sys_class_net(abuf, "rxErrors", ifs->name, "statistics/rx_errors");
701 abuf_json_sys_class_net(abuf, "rxFifoErrors", ifs->name, "statistics/rx_fifo_errors");
702 abuf_json_sys_class_net(abuf, "rxFrameErrors", ifs->name, "statistics/rx_frame_errors");
703 abuf_json_sys_class_net(abuf, "rxLengthErrors", ifs->name, "statistics/rx_length_errors");
704 abuf_json_sys_class_net(abuf, "rxMissedErrors", ifs->name, "statistics/rx_missed_errors");
705 abuf_json_sys_class_net(abuf, "rxOverErrors", ifs->name, "statistics/rx_over_errors");
706 abuf_json_sys_class_net(abuf, "rxPackets", ifs->name, "statistics/rx_packets");
707 abuf_json_sys_class_net(abuf, "txAbortedErrors", ifs->name, "statistics/tx_aborted_errors");
708 abuf_json_sys_class_net(abuf, "txBytes", ifs->name, "statistics/tx_bytes");
709 abuf_json_sys_class_net(abuf, "txCarrierErrors", ifs->name, "statistics/tx_carrier_errors");
710 abuf_json_sys_class_net(abuf, "txCompressed", ifs->name, "statistics/tx_compressed");
711 abuf_json_sys_class_net(abuf, "txDropped", ifs->name, "statistics/tx_dropped");
712 abuf_json_sys_class_net(abuf, "txErrors", ifs->name, "statistics/tx_errors");
713 abuf_json_sys_class_net(abuf, "txFifoErrors", ifs->name, "statistics/tx_fifo_errors");
714 abuf_json_sys_class_net(abuf, "txHeartbeatErrors", ifs->name, "statistics/tx_heartbeat_errors");
715 abuf_json_sys_class_net(abuf, "txPackets", ifs->name, "statistics/tx_packets");
716 abuf_json_sys_class_net(abuf, "txWindowErrors", ifs->name, "statistics/tx_window_errors");
717 abuf_json_sys_class_net(abuf, "beaconing", ifs->name, "wireless/beacon");
718 abuf_json_sys_class_net(abuf, "encryptionKey", ifs->name, "wireless/crypt");
719 abuf_json_sys_class_net(abuf, "fragmentationThreshold", ifs->name, "wireless/fragment");
720 abuf_json_sys_class_net(abuf, "signalLevel", ifs->name, "wireless/level");
721 abuf_json_sys_class_net(abuf, "linkQuality", ifs->name, "wireless/link");
722 abuf_json_sys_class_net(abuf, "misc", ifs->name, "wireless/misc");
723 abuf_json_sys_class_net(abuf, "noiseLevel", ifs->name, "wireless/noise");
724 abuf_json_sys_class_net(abuf, "nwid", ifs->name, "wireless/nwid");
725 abuf_json_sys_class_net(abuf, "wirelessRetries", ifs->name, "wireless/retries");
726 abuf_json_sys_class_net(abuf, "wirelessStatus", ifs->name, "wireless/status");
727 #endif /* __linux__ */
728 abuf_json_mark_array_entry(false, abuf);
730 abuf_json_mark_object(false, true, abuf, NULL); // interfaces
733 void ipc_print_twohop(struct autobuf *abuf) {
734 ipc_print_neighbors_internal(abuf, true);
737 void ipc_print_config(struct autobuf *abuf) {
738 struct ip_prefix_list *hna;
739 struct ipaddr_str buf, mainaddrbuf;
740 struct ip_prefix_list *ipcn;
741 struct olsr_lq_mult *mult;
742 char ipv6_buf[INET6_ADDRSTRLEN]; /* buffer for IPv6 inet_htop */
744 abuf_json_mark_object(true, false, abuf, "config");
746 abuf_json_int(abuf, "olsrPort", olsr_cnf->olsrport);
747 abuf_json_int(abuf, "debugLevel", olsr_cnf->debug_level);
748 abuf_json_boolean(abuf, "noFork", olsr_cnf->no_fork);
749 abuf_json_boolean(abuf, "hostEmulation", olsr_cnf->host_emul);
750 abuf_json_int(abuf, "ipVersion", olsr_cnf->ip_version);
751 abuf_json_boolean(abuf, "allowNoInterfaces", olsr_cnf->allow_no_interfaces);
752 abuf_json_int(abuf, "typeOfService", olsr_cnf->tos);
753 abuf_json_int(abuf, "rtProto", olsr_cnf->rt_proto);
754 abuf_json_int(abuf, "rtTable", olsr_cnf->rt_table);
755 abuf_json_int(abuf, "rtTableDefault", olsr_cnf->rt_table_default);
756 abuf_json_int(abuf, "rtTableTunnel", olsr_cnf->rt_table_tunnel);
757 abuf_json_int(abuf, "rtTablePriority", olsr_cnf->rt_table_pri);
758 abuf_json_int(abuf, "rtTableTunnelPriority", olsr_cnf->rt_table_tunnel_pri);
759 abuf_json_int(abuf, "rtTableDefauiltOlsrPriority", olsr_cnf->rt_table_defaultolsr_pri);
760 abuf_json_int(abuf, "rtTableDefaultPriority", olsr_cnf->rt_table_default_pri);
761 abuf_json_int(abuf, "willingness", olsr_cnf->willingness);
762 abuf_json_boolean(abuf, "willingnessAuto", olsr_cnf->willingness_auto);
764 abuf_json_int(abuf, "brokenLinkCost", LINK_COST_BROKEN);
765 abuf_json_int(abuf, "brokenRouteCost", ROUTE_COST_BROKEN);
767 abuf_json_string(abuf, "fibMetrics", FIB_METRIC_TXT[olsr_cnf->fib_metric]);
769 abuf_json_string(abuf, "defaultIpv6Multicast", inet_ntop(AF_INET6, &olsr_cnf->interface_defaults->ipv6_multicast.v6, ipv6_buf, sizeof(ipv6_buf)));
770 if (olsr_cnf->interface_defaults->ipv4_multicast.v4.s_addr)
771 abuf_json_string(abuf, "defaultIpv4Broadcast", inet_ntoa(olsr_cnf->interface_defaults->ipv4_multicast.v4));
773 abuf_json_string(abuf, "defaultIpv4Broadcast", "auto");
775 if (olsr_cnf->interface_defaults->mode == IF_MODE_ETHER)
776 abuf_json_string(abuf, "defaultInterfaceMode", "ether");
778 abuf_json_string(abuf, "defaultInterfaceMode", "mesh");
780 abuf_json_float(abuf, "defaultHelloEmissionInterval", olsr_cnf->interface_defaults->hello_params.emission_interval);
781 abuf_json_float(abuf, "defaultHelloValidityTime", olsr_cnf->interface_defaults->hello_params.validity_time);
782 abuf_json_float(abuf, "defaultTcEmissionInterval", olsr_cnf->interface_defaults->tc_params.emission_interval);
783 abuf_json_float(abuf, "defaultTcValidityTime", olsr_cnf->interface_defaults->tc_params.validity_time);
784 abuf_json_float(abuf, "defaultMidEmissionInterval", olsr_cnf->interface_defaults->mid_params.emission_interval);
785 abuf_json_float(abuf, "defaultMidValidityTime", olsr_cnf->interface_defaults->mid_params.validity_time);
786 abuf_json_float(abuf, "defaultHnaEmissionInterval", olsr_cnf->interface_defaults->hna_params.emission_interval);
787 abuf_json_float(abuf, "defaultHnaValidityTime", olsr_cnf->interface_defaults->hna_params.validity_time);
788 abuf_json_boolean(abuf, "defaultAutoDetectChanges", olsr_cnf->interface_defaults->autodetect_chg);
790 abuf_json_mark_object(true, true, abuf, "defaultLinkQualityMultipliers");
791 for (mult = olsr_cnf->interface_defaults->lq_mult; mult != NULL ; mult = mult->next) {
792 abuf_json_mark_array_entry(true, abuf);
793 abuf_json_string(abuf, "route", inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
794 abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
795 abuf_json_mark_array_entry(false, abuf);
797 abuf_json_mark_object(false, true, abuf, NULL);
799 abuf_json_mark_object(true, true, abuf, "hna");
800 for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
801 abuf_json_mark_array_entry(true, abuf);
802 abuf_json_string(abuf, "destination", olsr_ip_to_string(&buf, &hna->net.prefix));
803 abuf_json_int(abuf, "genmask", hna->net.prefix_len);
804 abuf_json_string(abuf, "gateway", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
805 abuf_json_mark_array_entry(false, abuf);
807 abuf_json_mark_object(false, true, abuf, NULL);
809 abuf_json_int(abuf, "totalIpcConnectionsAllowed", olsr_cnf->ipc_connections);
810 abuf_json_mark_object(true, true, abuf, "ipcAllowedAddresses");
811 if (olsr_cnf->ipc_connections) {
812 for (ipcn = olsr_cnf->ipc_nets; ipcn != NULL ; ipcn = ipcn->next) {
813 abuf_json_mark_array_entry(true, abuf);
814 abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&mainaddrbuf, &ipcn->net.prefix));
815 abuf_json_int(abuf, "netmask", ipcn->net.prefix_len);
816 abuf_json_mark_array_entry(false, abuf);
819 abuf_json_mark_object(false, true, abuf, NULL);
821 // keep all time in ms, so convert these two, which are in seconds
822 abuf_json_int(abuf, "pollRate", olsr_cnf->pollrate * 1000);
823 abuf_json_int(abuf, "nicChangePollInterval", olsr_cnf->nic_chgs_pollrate * 1000);
824 abuf_json_boolean(abuf, "clearScreen", olsr_cnf->clear_screen);
825 abuf_json_int(abuf, "tcRedundancy", olsr_cnf->tc_redundancy);
826 abuf_json_int(abuf, "mprCoverage", olsr_cnf->mpr_coverage);
828 if (!olsr_cnf->lq_level) {
829 abuf_json_boolean(abuf, "useHysteresis", olsr_cnf->use_hysteresis);
830 if (olsr_cnf->use_hysteresis) {
831 abuf_json_float(abuf, "hysteresisScaling", olsr_cnf->hysteresis_param.scaling);
832 abuf_json_float(abuf, "hysteresisLowThreshold", olsr_cnf->hysteresis_param.thr_low);
833 abuf_json_float(abuf, "hysteresisHighThreshold", olsr_cnf->hysteresis_param.thr_high);
836 abuf_json_int(abuf, "linkQualityLevel", olsr_cnf->lq_level);
837 abuf_json_float(abuf, "linkQualityAging", olsr_cnf->lq_aging);
838 abuf_json_boolean(abuf, "linkQualityFisheye", olsr_cnf->lq_fish);
839 abuf_json_string(abuf, "linkQualityAlgorithm", olsr_cnf->lq_algorithm);
840 // keep all time in ms, so convert this from seconds
841 abuf_json_int(abuf, "minTcValidTime", olsr_cnf->min_tc_vtime * 1000);
842 abuf_json_boolean(abuf, "setIpForward", olsr_cnf->set_ip_forward);
843 abuf_json_string(abuf, "lockFile", olsr_cnf->lock_file);
844 abuf_json_boolean(abuf, "useNiit", olsr_cnf->use_niit);
847 abuf_json_boolean(abuf, "smartGateway", olsr_cnf->smart_gw_active);
848 if (olsr_cnf->smart_gw_active) {
849 abuf_json_boolean(abuf, "smartGatewayAlwaysRemoveServerTunnel", olsr_cnf->smart_gw_always_remove_server_tunnel);
850 abuf_json_int(abuf, "smartGatewayUseCount", olsr_cnf->smart_gw_use_count);
851 abuf_json_string(abuf, "smartGatewayInstanceId", olsr_cnf->smart_gw_instance_id);
852 abuf_json_string(abuf, "smartGatewayPolicyRoutingScript", olsr_cnf->smart_gw_policyrouting_script);
854 struct autobuf egressbuf;
855 struct sgw_egress_if * egressif = olsr_cnf->smart_gw_egress_interfaces;
857 abuf_init(&egressbuf, (olsr_cnf->smart_gw_egress_interfaces_count * IFNAMSIZ) /* interface names */
858 + (olsr_cnf->smart_gw_egress_interfaces_count - 1) /* commas */);
861 abuf_puts(&egressbuf, ",");
863 abuf_appendf(&egressbuf, "%s", egressif->name);
864 egressif = egressif->next;
866 abuf_json_string(abuf, "smartGatewayEgressInterfaces", egressbuf.buf);
867 abuf_free(&egressbuf);
869 abuf_json_int(abuf, "smartGatewayTablesOffset", olsr_cnf->smart_gw_offset_tables);
870 abuf_json_int(abuf, "smartGatewayRulesOffset", olsr_cnf->smart_gw_offset_rules);
871 abuf_json_boolean(abuf, "smartGatewayAllowNat", olsr_cnf->smart_gw_allow_nat);
872 abuf_json_boolean(abuf, "smartGatewayUplinkNat", olsr_cnf->smart_gw_uplink_nat);
873 abuf_json_int(abuf, "smartGatewayPeriod", olsr_cnf->smart_gw_period);
874 abuf_json_int(abuf, "smartGatewayStableCount", olsr_cnf->smart_gw_stablecount);
875 abuf_json_int(abuf, "smartGatewayThreshold", olsr_cnf->smart_gw_thresh);
876 abuf_json_int(abuf, "smartGatewayUplink", olsr_cnf->smart_gw_uplink);
877 abuf_json_int(abuf, "smartGatewayDownlink", olsr_cnf->smart_gw_downlink);
878 abuf_json_int(abuf, "smartGatewayType", olsr_cnf->smart_gw_type);
879 abuf_json_string(abuf, "smartGatewayPrefix", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->smart_gw_prefix.prefix));
880 abuf_json_int(abuf, "smartGatewayPrefixLength", olsr_cnf->smart_gw_prefix.prefix_len);
882 #endif /* __linux__ */
884 abuf_json_string(abuf, "mainIpAddress", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
885 abuf_json_string(abuf, "unicastSourceIpAddress", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->unicast_src_ip));
887 abuf_json_boolean(abuf, "useSourceIpRoutes", 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, "deleteInternetGatewaysAtStartup", olsr_cnf->del_gws);
892 // keep all time in ms, so convert this from seconds
893 abuf_json_int(abuf, "willingnessUpdateInterval", olsr_cnf->will_int * 1000);
894 abuf_json_float(abuf, "maxSendMessageJitter", olsr_cnf->max_jitter);
895 abuf_json_int(abuf, "exitValue", olsr_cnf->exit_value);
896 // keep all time in ms, so convert this from seconds
897 abuf_json_int(abuf, "maxTcValidTime", olsr_cnf->max_tc_vtime * 1000);
899 abuf_json_int(abuf, "niit4to6InterfaceIndex", olsr_cnf->niit4to6_if_index);
900 abuf_json_int(abuf, "niit6to4InterfaceIndex", olsr_cnf->niit6to4_if_index);
902 abuf_json_boolean(abuf, "hasIpv4Gateway", olsr_cnf->has_ipv4_gateway);
903 abuf_json_boolean(abuf, "hasIpv6Gateway", olsr_cnf->has_ipv6_gateway);
905 abuf_json_int(abuf, "ioctlSocket", olsr_cnf->ioctl_s);
907 abuf_json_int(abuf, "routeNetlinkSocket", olsr_cnf->rtnl_s);
908 abuf_json_int(abuf, "routeMonitorSocket", olsr_cnf->rt_monitor_socket);
909 #endif /* __linux__ */
911 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
912 abuf_json_int(abuf, "routeChangeSocket", olsr_cnf->rts);
913 #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ */
914 abuf_json_float(abuf, "linkQualityNatThreshold", olsr_cnf->lq_nat_thresh);
916 abuf_json_string(abuf, "olsrdVersion", olsrd_version);
917 abuf_json_string(abuf, "olsrdBuildDate", build_date);
918 abuf_json_string(abuf, "olsrdBuildHost", build_host);
920 #if defined _WIN32 || defined _WIN64
921 abuf_json_string(abuf, "os", "Windows");
922 #elif defined __gnu_linux__
923 abuf_json_string(abuf, "os", "GNU/Linux");
924 #elif defined __ANDROID__
925 abuf_json_string(abuf, "os", "Android");
926 #elif defined __APPLE__
927 abuf_json_string(abuf, "os", "Mac OS X");
928 #elif defined __NetBSD__
929 abuf_json_string(abuf, "os", "NetBSD");
930 #elif defined __OpenBSD__
931 abuf_json_string(abuf, "os", "OpenBSD");
932 #elif defined __FreeBSD__ || defined __FreeBSD_kernel__
933 abuf_json_string(abuf, "os", "FreeBSD");
934 #else /* OS detection */
935 abuf_json_string(abuf, "os", "Undefined");
936 #endif /* OS detection */
938 abuf_json_int(abuf, "startTime", start_time.tv_sec);
940 abuf_json_mark_object(false, false, abuf, NULL);
943 void ipc_print_plugins(struct autobuf *abuf) {
944 abuf_json_mark_object(true, true, abuf, "plugins");
945 if (olsr_cnf->plugins) {
946 struct plugin_entry *plugin;
948 for (plugin = olsr_cnf->plugins; plugin; plugin = plugin->next) {
949 struct plugin_param *param;
951 abuf_json_mark_array_entry(true, abuf);
952 abuf_json_string(abuf, "plugin", plugin->name);
953 for (param = plugin->params; param; param = param->next) {
954 abuf_json_string(abuf, param->key, param->value);
956 abuf_json_mark_array_entry(false, abuf);
959 abuf_json_mark_object(false, true, abuf, NULL);