convert 'gateways' to JSON
[olsrd.git] / lib / jsoninfo / src / olsrd_jsoninfo.c
index a8b71a8..97e1e2d 100644 (file)
@@ -93,18 +93,20 @@ static int ipc_socket;
 /* IPC initialization function */
 static int plugin_ipc_init(void);
 
+static void abuf_json_open_object(struct autobuf *abuf, const char* header);
+static void abuf_json_close_object(struct autobuf *abuf);
 static void abuf_json_open_array(struct autobuf *abuf, const char* header);
 static void abuf_json_close_array(struct autobuf *abuf);
 static void abuf_json_open_array_entry(struct autobuf *abuf);
 static void abuf_json_close_array_entry(struct autobuf *abuf);
 static void abuf_json_boolean(struct autobuf *abuf, const char* key, int value);
-static void abuf_json_key_string(struct autobuf *abuf, const char* key, const char* value);
-static void abuf_json_key_int(struct autobuf *abuf, const char* key, int value);
-static void abuf_json_key_float(struct autobuf *abuf, const char* key, float value);
+static void abuf_json_string(struct autobuf *abuf, const char* key, const char* value);
+static void abuf_json_int(struct autobuf *abuf, const char* key, long value);
+static void abuf_json_float(struct autobuf *abuf, const char* key, float value);
 
 static void send_info(unsigned int /*send_what*/, int /*socket*/);
 static void ipc_action(int, void *, unsigned int);
-static void ipc_print_neighbors(struct autobuf *, bool);
+static void ipc_print_neighbors(struct autobuf *);
 static void ipc_print_links(struct autobuf *);
 static void ipc_print_routes(struct autobuf *);
 static void ipc_print_topology(struct autobuf *);
@@ -113,6 +115,8 @@ static void ipc_print_mid(struct autobuf *);
 static void ipc_print_gateways(struct autobuf *);
 static void ipc_print_config(struct autobuf *);
 static void ipc_print_interfaces(struct autobuf *);
+static void ipc_print_plugins(struct autobuf *);
+static void ipc_print_olsrd_conf(struct autobuf *abuf);
 
 #define TXT_IPC_BUFSIZE 256
 
@@ -125,10 +129,11 @@ static void ipc_print_interfaces(struct autobuf *);
 #define SIW_GATEWAYS 0x0040
 #define SIW_INTERFACES 0x0080
 #define SIW_CONFIG 0x0100
-#define SIW_TWOHOP 0x0200
+#define SIW_ALL 0x00FF
 
-/* ALL = neigh link route hna mid topo */
-#define SIW_ALL 0x003F
+/* these don't change at runtime, so they are not part of ALL/status */
+#define SIW_PLUGINS 0x0200
+#define SIW_OLSRD_CONF 0x0400
 
 #define MAX_CLIENTS 3
 
@@ -138,6 +143,7 @@ static size_t outbuffer_written[MAX_CLIENTS];
 static int outbuffer_socket[MAX_CLIENTS];
 static int outbuffer_count;
 
+static struct timeval start_time;
 static struct timer_entry *writetimer_entry;
 
 
@@ -150,6 +156,19 @@ static struct timer_entry *writetimer_entry;
 static int entrynumber = 0;
 static int arrayentrynumber = 0;
 
+static void
+abuf_json_open_object(struct autobuf *abuf, const char* header)
+{
+  entrynumber = 0;
+  abuf_appendf(abuf, "{\"%s\": {", header);
+}
+
+static void
+abuf_json_close_object(struct autobuf *abuf)
+{
+  abuf_appendf(abuf, "\t}\n}\n");
+}
+
 static void
 abuf_json_open_array(struct autobuf *abuf, const char* header)
 {
@@ -192,7 +211,7 @@ abuf_json_boolean(struct autobuf *abuf, const char* key, int value)
 }
 
 static void
-abuf_json_key_string(struct autobuf *abuf, const char* key, const char* value)
+abuf_json_string(struct autobuf *abuf, const char* key, const char* value)
 {
   if (entrynumber)
     abuf_appendf(abuf, ",\n");
@@ -203,22 +222,24 @@ abuf_json_key_string(struct autobuf *abuf, const char* key, const char* value)
 }
 
 static void
-abuf_json_key_int(struct autobuf *abuf, const char* key, int value)
+abuf_json_int(struct autobuf *abuf, const char* key, long value)
 {
   if (entrynumber)
     abuf_appendf(abuf, ",\n");
   else
     abuf_appendf(abuf, "\n");
-  abuf_appendf(abuf, "\t\"%s\": %i", key, value);
+  abuf_appendf(abuf, "\t\"%s\": %li", key, value);
   entrynumber++;
 }
 
 static void
-abuf_json_key_float(struct autobuf *abuf, const char* key, float value)
+abuf_json_float(struct autobuf *abuf, const char* key, float value)
 {
   if (entrynumber)
     abuf_appendf(abuf, ",\n");
-  abuf_appendf(abuf, "\t\"%s\": %g,\n", key, value);
+  else
+    abuf_appendf(abuf, "\n");
+  abuf_appendf(abuf, "\t\"%s\": %.03f", key, value);
   entrynumber++;
 }
 
@@ -235,6 +256,9 @@ olsrd_plugin_init(void)
   /* Initial IPC value */
   ipc_socket = -1;
 
+  /* Get start time */
+  gettimeofday(&start_time, NULL);
+
   plugin_ipc_init();
   return 1;
 }
@@ -381,21 +405,22 @@ ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __att
     ssize_t s = recv(ipc_connection, (void *)&requ, sizeof(requ), 0);   /* Win32 needs the cast here */
     if (0 < s) {
       requ[s] = 0;
-      /* print out every combinations of requested tabled
-       * 3++ letter abbreviations are matched */
-      if (0 != strstr(requ, "/all")) send_what = SIW_ALL;
-      else { /*already included in /all*/
+      /* print out the requested tables */
+      if (0 != strstr(requ, "/status")) send_what = SIW_ALL;
+      else { /* included in /status */
         if (0 != strstr(requ, "/neighbors")) send_what |= SIW_NEIGHBORS;
         if (0 != strstr(requ, "/links")) send_what |= SIW_LINKS;
         if (0 != strstr(requ, "/routes")) send_what |= SIW_ROUTES;
         if (0 != strstr(requ, "/hna")) send_what |= SIW_HNA;
         if (0 != strstr(requ, "/mid")) send_what |= SIW_MID;
         if (0 != strstr(requ, "/topology")) send_what |= SIW_TOPOLOGY;
+        if (0 != strstr(requ, "/gateways")) send_what |= SIW_GATEWAYS;
+        if (0 != strstr(requ, "/interfaces")) send_what |= SIW_INTERFACES;
       }
-      if (0 != strstr(requ, "/gateways")) send_what |= SIW_GATEWAYS;
+      /* these don't change during runtime, so leave them out of ALL */
       if (0 != strstr(requ, "/config")) send_what |= SIW_CONFIG;
-      if (0 != strstr(requ, "/interfaces")) send_what |= SIW_INTERFACES;
-      if (0 != strstr(requ, "/twohop")) send_what |= SIW_TWOHOP;
+      if (0 != strstr(requ, "/plugins")) send_what |= SIW_PLUGINS;
+      if (0 != strstr(requ, "/olsrd.conf")) send_what |= SIW_OLSRD_CONF;
     }
     if ( send_what == 0 ) send_what = SIW_ALL;
   }
@@ -404,47 +429,42 @@ ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __att
 }
 
 static void
-ipc_print_neighbors(struct autobuf *abuf, bool list_2hop)
+ipc_print_neighbors(struct autobuf *abuf)
 {
   struct ipaddr_str buf1;
   struct neighbor_entry *neigh;
   struct neighbor_2_list_entry *list_2;
   int thop_cnt;
 
-  //abuf_puts(abuf, "Table: Neighbors\nIP address\tSYM\tMPR\tMPRS\tWill.");
-/*
-  if (list_2hop)
-    abuf_puts(abuf,"\n\t2hop interface adrress\n");
-  else
-    abuf_puts(abuf, "\t2 Hop Neighbors\n");
-*/
-  if (list_2hop)
-    abuf_json_open_array(abuf, "twohop");
-  else
-    abuf_json_open_array(abuf, "neighbors");
+  abuf_json_open_array(abuf, "neighbors");
 
   /* Neighbors */
   OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
-    abuf_appendf(abuf,
-                 "%s\t%s\t%s\t%s\t%d\t",
-                 olsr_ip_to_string(&buf1, &neigh->neighbor_main_addr),
-                 (neigh->status == SYM) ? "YES" : "NO",
-                 neigh->is_mpr ? "YES" : "NO",
-                 olsr_lookup_mprs_set(&neigh->neighbor_main_addr) ? "YES" : "NO",
-                 neigh->willingness);
-    thop_cnt = 0;
+    abuf_json_open_array_entry(abuf);
+    abuf_json_string(abuf, "ipv4Address",
+                     olsr_ip_to_string(&buf1, &neigh->neighbor_main_addr));
+    abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
+    abuf_json_boolean(abuf, "multiPointRelay", neigh->is_mpr);
+    abuf_json_boolean(abuf, "multiPointRelaySelector",
+                      olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
+    abuf_json_int(abuf, "willingness", neigh->willingness);
+    abuf_appendf(abuf, ",\n");
 
-    for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
-      if (list_2hop)
+    thop_cnt = 0;
+    if (neigh->neighbor_2_list.next) {
+      abuf_appendf(abuf, "\t\"twoHopNeighbors\": [");
+      for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
+        if (thop_cnt)
+          abuf_appendf(abuf, ", ");
         abuf_appendf(abuf,
-                     "\t%s\n",
+                     "\"%s\"",
                      olsr_ip_to_string(&buf1, &list_2->neighbor_2->neighbor_2_addr));
-      else
         thop_cnt++;
+      }
     }
-    if (!list_2hop) {
-      abuf_appendf(abuf, "%d\n", thop_cnt);
-    }
+    abuf_appendf(abuf, "]");
+    abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
+    abuf_json_close_array_entry(abuf);
   }
   OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
   abuf_json_close_array(abuf);
@@ -459,22 +479,24 @@ ipc_print_links(struct autobuf *abuf)
   struct link_entry *my_link = NULL;
 
   abuf_json_open_array(abuf, "links");
-  //abuf_puts(abuf, "Table: Links\nLocal IP\tRemote IP\tVTime\tLQ\tNLQ\tCost\n");
-
-  /* Link set */
   OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
+    const char* lqs;
     int diff = (unsigned int)(my_link->link_timer->timer_clock - now_times);
 
-    abuf_appendf(abuf,
-                 "%s\t%s\t%d.%03d\t%s\t%s\t\n",
-                 olsr_ip_to_string(&buf1, &my_link->local_iface_addr),
-                 olsr_ip_to_string(&buf2, &my_link->neighbor_iface_addr),
-                 diff/1000, abs(diff%1000),
-                 get_link_entry_text(my_link, '\t', &lqbuffer1),
-                 get_linkcost_text(my_link->linkcost, false, &lqbuffer2));
+    abuf_json_open_array_entry(abuf);
+    abuf_json_string(abuf, "localIP",
+                     olsr_ip_to_string(&buf1, &my_link->local_iface_addr));
+    abuf_json_string(abuf, "remoteIP",
+                     olsr_ip_to_string(&buf2, &my_link->neighbor_iface_addr));
+    abuf_json_int(abuf, "validityTime", diff);
+    lqs = get_link_entry_text(my_link, '\t', &lqbuffer1);
+    abuf_json_float(abuf, "linkQuality", atof(lqs));
+    abuf_json_float(abuf, "neighborLinkQuality", atof(strrchr(lqs, '\t')));
+    abuf_json_float(abuf, "linkCost",
+                    atof(get_linkcost_text(my_link->linkcost, false, &lqbuffer2)));
+    abuf_json_close_array_entry(abuf);
   }
   OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
-
   abuf_json_close_array(abuf);
 }
 
@@ -490,19 +512,22 @@ ipc_print_routes(struct autobuf *abuf)
 
   /* Walk the route table */
   OLSR_FOR_ALL_RT_ENTRIES(rt) {
-    abuf_appendf(abuf,
-                 "%s/%d\t%s\t%d\t%s\t%s\t\n",
-                 olsr_ip_to_string(&buf1, &rt->rt_dst.prefix),
-                 rt->rt_dst.prefix_len,
-                 olsr_ip_to_string(&buf2, &rt->rt_best->rtp_nexthop.gateway),
-                 rt->rt_best->rtp_metric.hops,
-                 get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &lqbuffer),
-                 if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
+    abuf_json_open_array_entry(abuf);
+    abuf_json_string(abuf, "destination",
+                     olsr_ip_to_string(&buf1, &rt->rt_dst.prefix));
+    abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
+    abuf_json_string(abuf, "gateway",
+                     olsr_ip_to_string(&buf2, &rt->rt_best->rtp_nexthop.gateway));
+    abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
+    abuf_json_float(abuf, "expectedTransmissionCount",
+                    atof(get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &lqbuffer)));
+    abuf_json_string(abuf, "interface",
+                     if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
+    abuf_json_close_array_entry(abuf);
   }
   OLSR_FOR_ALL_RT_ENTRIES_END(rt);
 
   abuf_json_close_array(abuf);
-
 }
 
 static void
@@ -522,11 +547,19 @@ ipc_print_topology(struct autobuf *abuf)
         struct lqtextbuffer lqbuffer1, lqbuffer2;
         uint32_t vt = tc->validity_timer != NULL ? (tc->validity_timer->timer_clock - now_times) : 0;
         int diff = (int)(vt);
-        abuf_appendf(abuf, "%s\t%s\t%s\t%s\t%d.%03d\n", olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr),
-                     olsr_ip_to_string(&addrbuf, &tc->addr),
-                     get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer1),
-                     get_linkcost_text(tc_edge->cost, false, &lqbuffer2),
-                     diff/1000, diff%1000);
+        const char* lqs;
+        abuf_json_open_array_entry(abuf);
+        abuf_json_string(abuf, "destinationIP",
+                         olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr));
+        abuf_json_string(abuf, "lastHopIP",
+                         olsr_ip_to_string(&addrbuf, &tc->addr));
+        lqs = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer1);
+        abuf_json_float(abuf, "linkQuality", atof(lqs));
+        abuf_json_float(abuf, "neighborLinkQuality", atof(strrchr(lqs, '\t')));
+        abuf_json_float(abuf, "cost", 
+                        atof(get_linkcost_text(tc_edge->cost, false, &lqbuffer2)));
+        abuf_json_int(abuf, "validityTime", diff);
+        abuf_json_close_array_entry(abuf);
       }
     }
     OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
@@ -545,24 +578,27 @@ ipc_print_hna(struct autobuf *abuf)
   struct ipaddr_str buf, mainaddrbuf;
 
   abuf_json_open_array(abuf, "hna");
-  //abuf_puts(abuf, "Table: HNA\nDestination\tGateway\tVTime\n");
 
   /* Announced HNA entries */
   if (olsr_cnf->ip_version == AF_INET) {
     for (hna = olsr_cnf->hna_entries; hna != NULL; hna = hna->next) {
-      abuf_appendf(abuf,
-                   "%s/%d\t%s\n",
-                   olsr_ip_to_string(&buf, &hna->net.prefix),
-                   hna->net.prefix_len,
-                   olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
+      abuf_json_open_array_entry(abuf);
+      abuf_json_string(abuf, "destination",
+                       olsr_ip_to_string(&buf, &hna->net.prefix));
+      abuf_json_int(abuf, "genmask", hna->net.prefix_len);
+      abuf_json_string(abuf, "gateway",
+                       olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
+      abuf_json_close_array_entry(abuf);
     }
   } else {
     for (hna = olsr_cnf->hna_entries; hna != NULL; hna = hna->next) {
-      abuf_appendf(abuf,
-                   "%s/%d\t%s\n",
-                   olsr_ip_to_string(&buf, &hna->net.prefix),
-                   hna->net.prefix_len,
-                   olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
+      abuf_json_open_array_entry(abuf);
+      abuf_json_string(abuf, "destination",
+                       olsr_ip_to_string(&buf, &hna->net.prefix));
+      abuf_json_int(abuf, "genmask", hna->net.prefix_len);
+      abuf_json_string(abuf, "gateway",
+                       olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
+      abuf_json_close_array_entry(abuf);
     }
   }
 
@@ -573,12 +609,14 @@ ipc_print_hna(struct autobuf *abuf)
     for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
       uint32_t vt = tmp_net->hna_net_timer != NULL ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0;
       int diff = (int)(vt);
-      abuf_appendf(abuf,
-                   "%s/%d\t%s\t\%d.%03d\n",
-                   olsr_ip_to_string(&buf, &tmp_net->hna_prefix.prefix),
-                   tmp_net->hna_prefix.prefix_len,
-                   olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr),
-                   diff/1000, abs(diff%1000));
+      abuf_json_open_array_entry(abuf);
+      abuf_json_string(abuf, "destination",
+                       olsr_ip_to_string(&buf, &tmp_net->hna_prefix.prefix)),
+      abuf_json_int(abuf, "genmask", tmp_net->hna_prefix.prefix_len);
+      abuf_json_string(abuf, "gateway",
+                       olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr));
+      abuf_json_int(abuf, "validityTime", diff);
+      abuf_json_close_array_entry(abuf);
     }
   }
   OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
@@ -590,12 +628,10 @@ static void
 ipc_print_mid(struct autobuf *abuf)
 {
   int idx;
-  unsigned short is_first;
   struct mid_entry *entry;
   struct mid_address *alias;
 
   abuf_json_open_array(abuf, "mid");
-  //abuf_puts(abuf, "Table: MID\nIP address\tAlias\tVTime\n");
 
   /* MID */
   for (idx = 0; idx < HASHSIZE; idx++) {
@@ -604,18 +640,20 @@ ipc_print_mid(struct autobuf *abuf)
     while (entry != &mid_set[idx]) {
       struct ipaddr_str buf, buf2;
       alias = entry->aliases;
-      is_first = 1;
 
       while (alias) {
         uint32_t vt = alias->vtime - now_times;
         int diff = (int)(vt);
 
-        abuf_appendf(abuf, "%s\t%s\t%d.%03d\n",
-                     olsr_ip_to_string(&buf, &entry->main_addr),
-                     olsr_ip_to_string(&buf2, &alias->alias),
-                     diff/1000, abs(diff%1000));
+        abuf_json_open_array_entry(abuf);
+        abuf_json_string(abuf, "ipv4Address",
+                         olsr_ip_to_string(&buf, &entry->main_addr));
+        abuf_json_string(abuf, "alias",
+                         olsr_ip_to_string(&buf2, &alias->alias));
+        abuf_json_open_array_entry(abuf);
+        abuf_json_int(abuf, "validityTime", diff);
+        abuf_json_close_array_entry(abuf);
         alias = alias->next_alias;
-        is_first = 0;
       }
       entry = entry->next;
     }
@@ -627,24 +665,18 @@ static void
 ipc_print_gateways(struct autobuf *abuf)
 {
 #ifndef linux
-  abuf_json_key_string(abuf, "error", "Gateway mode is only supported in Linux");
+  abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
 #else
-  static const char IPV4[] = "ipv4";
-  static const char IPV4_NAT[] = "ipv4(n)";
-  static const char IPV6[] = "ipv6";
-  static const char NONE[] = "-";
 
   struct ipaddr_str buf;
   struct gateway_entry *gw;
   struct lqtextbuffer lqbuf;
 
-  // Status IP ETX Hopcount Uplink-Speed Downlink-Speed ipv4/ipv4-nat/- ipv6/- ipv6-prefix/-
   abuf_json_open_array(abuf, "gateways");
-  //abuf_puts(abuf, "Table: Gateways\nStatus\tGateway IP\tETX\tHopcnt\tUplink\tDownlnk\tIPv4\tIPv6\tPrefix\n");
   OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
-    char v4 = '-', v6 = '-';
+    const char *v4 = "", *v6 = "";
     bool autoV4 = false, autoV6 = false;
-    const char *v4type = NONE, *v6type = NONE;
+    const char *ipType = "";
     struct tc_entry *tc;
 
     if ((tc = olsr_lookup_tc_entry(&gw->originator)) == NULL) {
@@ -652,40 +684,207 @@ ipc_print_gateways(struct autobuf *abuf)
     }
 
     if (gw == olsr_get_ipv4_inet_gateway(&autoV4)) {
-      v4 = autoV4 ? 'a' : 's';
+      v4 = autoV4 ? "auto" : "s";
     } else if (gw->ipv4 && (olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit)
                && (olsr_cnf->smart_gw_allow_nat || !gw->ipv4nat)) {
-      v4 = 'u';
+      v4 = "u";
     }
 
     if (gw == olsr_get_ipv6_inet_gateway(&autoV6)) {
-      v6 = autoV6 ? 'a' : 's';
+      v6 = autoV6 ? "auto" : "s";
     } else if (gw->ipv6 && olsr_cnf->ip_version == AF_INET6) {
-      v6 = 'u';
+      v6 = "u";
     }
 
+    abuf_json_open_array_entry(abuf);
     if (gw->ipv4) {
-      v4type = gw->ipv4nat ? IPV4_NAT : IPV4;
-    }
-    if (gw->ipv6) {
-      v6type = IPV6;
+      ipType = "ipv4";
+      abuf_json_string(abuf, "ipv4Status", v4);
+    } else if (gw->ipv6) {
+      ipType = "ipv6";
+      abuf_json_string(abuf, "ipv6Status", v6);
     }
-
-    abuf_appendf(abuf, "%c%c\t%s\t%s\t%d\t%u\t%u\t%s\t%s\t%s\n",
-                 v4, v6, olsr_ip_to_string(&buf, &gw->originator),
-                 get_linkcost_text(tc->path_cost, true, &lqbuf), tc->hops,
-                 gw->uplink, gw->downlink, v4type, v6type,
-                 gw->external_prefix.prefix_len == 0 ? NONE : olsr_ip_prefix_to_string(&gw->external_prefix));
+    abuf_json_string(abuf, "ipType", ipType);
+    abuf_json_boolean(abuf, "ipv4", gw->ipv4);
+    abuf_json_boolean(abuf, "ipv4Nat", gw->ipv4nat);
+    abuf_json_boolean(abuf, "ipv6", gw->ipv6);
+    abuf_json_boolean(abuf, "autoIpv4", autoV4);
+    abuf_json_boolean(abuf, "autoIpv6", autoV6);
+    abuf_json_string(abuf, "ipAddress",
+                     olsr_ip_to_string(&buf, &gw->originator));
+    abuf_json_float(abuf, "expectedTransmissionCount",
+                    atof(get_linkcost_text(tc->path_cost, true, &lqbuf)));
+    abuf_json_int(abuf, "hopCount", tc->hops);
+    abuf_json_int(abuf, "uplinkSpeed", gw->uplink);
+    abuf_json_int(abuf, "downlinkSpeed", gw->downlink);
+    if(gw->external_prefix.prefix_len == 0)
+      abuf_json_string(abuf, "externalPrefix",
+                       olsr_ip_prefix_to_string(&gw->external_prefix));
+    abuf_json_close_array_entry(abuf);
   }
   OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
   abuf_json_close_array(abuf);
 #endif
 }
 
+
+static void
+ipc_print_plugins(struct autobuf *abuf)
+{
+  struct plugin_entry *pentry;
+  struct plugin_param *pparam;
+  abuf_json_open_array(abuf, "plugins");
+  if (olsr_cnf->plugins)
+    for (pentry = olsr_cnf->plugins; pentry; pentry = pentry->next) {
+      abuf_json_open_array_entry(abuf);
+      abuf_json_string(abuf, "plugin", pentry->name);
+      for (pparam = pentry->params; pparam; pparam = pparam->next) {
+       abuf_json_string(abuf, pparam->key, pparam->value);
+      }
+      abuf_json_close_array_entry(abuf);
+    }
+  abuf_json_close_array(abuf);
+}
+
+
 static void
 ipc_print_config(struct autobuf *abuf)
 {
-  olsrd_write_cnf_autobuf(abuf, olsr_cnf);
+  struct ipaddr_str mainaddrbuf;
+  struct ip_prefix_list *ipcn;
+
+  abuf_json_open_object(abuf, "config");
+
+  abuf_json_int(abuf, "olsrPort", olsr_cnf->olsrport);
+  abuf_json_int(abuf, "debugLevel", olsr_cnf->debug_level);
+  abuf_json_int(abuf, "noFork", olsr_cnf->no_fork);
+  abuf_json_boolean(abuf, "hostEmulation", olsr_cnf->host_emul);
+  abuf_json_int(abuf, "ipVersion", olsr_cnf->ip_version);
+  abuf_json_boolean(abuf, "allowNoInterfaces", olsr_cnf->allow_no_interfaces);
+  abuf_json_int(abuf, "typeOfService", olsr_cnf->tos);
+  abuf_json_int(abuf, "rtProto", olsr_cnf->rt_proto);
+  abuf_json_int(abuf, "rtTable", olsr_cnf->rt_table);
+  abuf_json_int(abuf, "rtTableDefault", olsr_cnf->rt_table_default);
+  abuf_json_int(abuf, "rtTableTunnel", olsr_cnf->rt_table_tunnel);
+  abuf_json_int(abuf, "rtTablePriority", olsr_cnf->rt_table_pri);
+  abuf_json_int(abuf, "rtTableTunnelPriority", olsr_cnf->rt_table_tunnel_pri);
+  abuf_json_int(abuf, "rtTableDefauiltOlsrPriority", olsr_cnf->rt_table_defaultolsr_pri);
+  abuf_json_int(abuf, "rtTableDefaultPriority", olsr_cnf->rt_table_default_pri);
+  abuf_json_int(abuf, "willingness", olsr_cnf->willingness);
+  abuf_json_boolean(abuf, "willingnessAuto", olsr_cnf->willingness_auto);
+
+  abuf_json_string(abuf, "fibMetrics", FIB_METRIC_TXT[olsr_cnf->fib_metric]);
+  /*
+  struct if_config_options *interface_defaults;
+  */
+  abuf_json_int(abuf, "ipcConnections", olsr_cnf->ipc_connections);
+  if (olsr_cnf->ipc_connections)
+    for (ipcn = olsr_cnf->ipc_nets; ipcn != NULL; ipcn = ipcn->next) {
+      abuf_json_string(abuf, "ipcAllowedAddress",
+                       olsr_ip_to_string(&mainaddrbuf, &ipcn->net.prefix));
+      abuf_json_int(abuf, "ipcAllowedAddressMask", ipcn->net.prefix_len);
+    }
+
+  // keep all time in ms, so convert these two, which are in seconds
+  abuf_json_int(abuf, "pollRate", olsr_cnf->pollrate * 1000);
+  abuf_json_int(abuf, "nicChangePollInterval", olsr_cnf->nic_chgs_pollrate * 1000);
+  abuf_json_boolean(abuf, "clearScreen", olsr_cnf->clear_screen);
+  abuf_json_int(abuf, "tcRedundancy", olsr_cnf->tc_redundancy);
+  abuf_json_int(abuf, "mprCoverage", olsr_cnf->mpr_coverage);
+
+  if (olsr_cnf->lq_level == 0) {
+    abuf_json_boolean(abuf, "useHysteresis", olsr_cnf->use_hysteresis);
+    if (olsr_cnf->use_hysteresis) {
+      abuf_json_float(abuf, "hysteresisScaling", olsr_cnf->hysteresis_param.scaling);
+      abuf_json_float(abuf, "hysteresisLowThreshold", olsr_cnf->hysteresis_param.thr_low);
+      abuf_json_float(abuf, "hysteresisHighThreshold", olsr_cnf->hysteresis_param.thr_high);
+    }
+  }
+  abuf_json_int(abuf, "linkQualityLevel", olsr_cnf->lq_level);
+  abuf_json_int(abuf, "linkQualityFisheye", olsr_cnf->lq_fish);
+  abuf_json_float(abuf, "linkQualityAging", olsr_cnf->lq_aging);
+  abuf_json_string(abuf, "linkQualityAlgorithm", olsr_cnf->lq_algorithm);
+  // keep all time in ms, so convert this from seconds
+  abuf_json_int(abuf, "minTcValidTime", olsr_cnf->min_tc_vtime * 1000);
+  abuf_json_boolean(abuf, "setIpForward", olsr_cnf->set_ip_forward);
+  abuf_json_string(abuf, "lockFile", olsr_cnf->lock_file);
+  abuf_json_boolean(abuf, "useNiit", olsr_cnf->use_niit);
+
+  abuf_json_boolean(abuf, "smartGateway", olsr_cnf->smart_gw_active);
+  if (olsr_cnf->smart_gw_active) {
+    abuf_json_boolean(abuf, "smartGatewayAllowNat", olsr_cnf->smart_gw_allow_nat);
+    abuf_json_boolean(abuf, "smartGatewayUplinkNat", olsr_cnf->smart_gw_uplink_nat);
+    abuf_json_int(abuf, "smartGatewayPeriod", olsr_cnf->smart_gw_period);
+    abuf_json_int(abuf, "smartGatewayStableCount", olsr_cnf->smart_gw_stablecount);
+    abuf_json_int(abuf, "smartGatewayThreshold", olsr_cnf->smart_gw_thresh);
+    abuf_json_int(abuf, "smartGatewayUplink", olsr_cnf->smart_gw_uplink);
+    abuf_json_int(abuf, "smartGatewayDownlink", olsr_cnf->smart_gw_downlink);
+    abuf_json_int(abuf, "smartGatewayType", olsr_cnf->smart_gw_type);
+    abuf_json_string(abuf, "smartGatewayPrefix",
+                     olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->smart_gw_prefix.prefix));
+    abuf_json_int(abuf, "smartGatewayPrefixLength", olsr_cnf->smart_gw_prefix.prefix_len);
+  }
+
+  abuf_json_string(abuf, "mainIpAddress",
+                   olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
+  abuf_json_string(abuf, "unicastSourceIpAddress",
+                   olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->unicast_src_ip));
+
+  abuf_json_boolean(abuf, "useSourceIpRoutes", olsr_cnf->use_src_ip_routes);
+
+  abuf_json_int(abuf, "maxPrefixLength", olsr_cnf->maxplen);
+  abuf_json_int(abuf, "ipSize", olsr_cnf->ipsize);
+  abuf_json_boolean(abuf, "deleteInternetGatewaysAtStartup", olsr_cnf->del_gws);
+  // keep all time in ms, so convert this from seconds
+  abuf_json_int(abuf, "willingnessUpdateInterval", olsr_cnf->will_int * 1000);
+  abuf_json_float(abuf, "maxSendMessageJitter", olsr_cnf->max_jitter);
+  abuf_json_int(abuf, "exitValue", olsr_cnf->exit_value);
+  // keep all time in ms, so convert this from seconds
+  abuf_json_int(abuf, "maxTcValidTime", olsr_cnf->max_tc_vtime * 1000);
+
+  abuf_json_int(abuf, "niit4to6InterfaceIndex", olsr_cnf->niit4to6_if_index);
+  abuf_json_int(abuf, "niit6to4InterfaceIndex", olsr_cnf->niit6to4_if_index);
+
+  abuf_json_boolean(abuf, "hasIpv4Gateway", olsr_cnf->has_ipv4_gateway);
+  abuf_json_boolean(abuf, "hasIpv6Gateway", olsr_cnf->has_ipv6_gateway);
+
+  abuf_json_int(abuf, "ioctlSocket", olsr_cnf->ioctl_s);
+#ifdef __linux__
+  abuf_json_int(abuf, "routeNetlinkSocket", olsr_cnf->rtnl_s);
+  abuf_json_int(abuf, "routeMonitorSocket", olsr_cnf->rt_monitor_socket);
+#endif
+
+#if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
+  abuf_json_int(abuf, "routeChangeSocket", olsr_cnf->rts);
+#endif
+  abuf_json_float(abuf, "linkQualityNatThreshold", olsr_cnf->lq_nat_thresh);
+
+  abuf_json_string(abuf, "olsrdVersion", olsrd_version);
+  abuf_json_string(abuf, "olsrdBuildDate", build_date);
+  abuf_json_string(abuf, "olsrdBuildHost", build_host);
+
+#if defined _WIN32 || defined _WIN64
+  abuf_json_string(abuf, "os", "Windows");
+#elif defined __gnu_linux__
+  abuf_json_string(abuf, "os", "GNU/Linux");
+#elif defined __ANDROID__
+  abuf_json_string(abuf, "os", "Android");
+#elif defined __APPLE__
+  abuf_json_string(abuf, "os", "Mac OS X");
+#elif defined __NetBSD__
+  abuf_json_string(abuf, "os", "NetBSD");
+#elif defined __OpenBSD__
+  abuf_json_string(abuf, "os", "OpenBSD");
+#elif defined __FreeBSD__ || defined __FreeBSD_kernel__
+  abuf_json_string(abuf, "os", "FreeBSD");
+#else
+  abuf_json_string(abuf, "os", "Undefined");
+#endif
+
+  abuf_json_int(abuf, "systemTime", time(NULL));
+  abuf_json_int(abuf, "startTime", start_time.tv_sec);
+
+  abuf_json_close_object(abuf);
 }
 
 static void
@@ -697,27 +896,27 @@ ipc_print_interfaces(struct autobuf *abuf)
   for (ifs = olsr_cnf->interfaces; ifs != NULL; ifs = ifs->next) {
     const struct interface *const rifs = ifs->interf;
     abuf_json_open_array_entry(abuf);
-    abuf_json_key_string(abuf, "name", ifs->name);
+    abuf_json_string(abuf, "name", ifs->name);
     if (!rifs) {
-      abuf_json_key_string(abuf, "state", "down");
+      abuf_json_string(abuf, "state", "down");
     } else {
-      abuf_json_key_string(abuf, "state", "up");
-      abuf_json_key_int(abuf, "mtu", rifs->int_mtu);
+      abuf_json_string(abuf, "state", "up");
+      abuf_json_int(abuf, "mtu", rifs->int_mtu);
       abuf_json_boolean(abuf, "wireless", rifs->is_wireless);
 
       if (olsr_cnf->ip_version == AF_INET) {
         struct ipaddr_str addrbuf, maskbuf, bcastbuf;
-        abuf_json_key_string(abuf, "ipv4Address",
+        abuf_json_string(abuf, "ipv4Address",
                              ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
-        abuf_json_key_string(abuf, "netmask",
+        abuf_json_string(abuf, "netmask",
                              ip4_to_string(&maskbuf, rifs->int_netmask.sin_addr));
-        abuf_json_key_string(abuf, "broadcast",
+        abuf_json_string(abuf, "broadcast",
                              ip4_to_string(&bcastbuf, rifs->int_broadaddr.sin_addr));
       } else {
         struct ipaddr_str addrbuf, maskbuf;
-        abuf_json_key_string(abuf, "ipv6Address",
+        abuf_json_string(abuf, "ipv6Address",
                              ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
-        abuf_json_key_string(abuf, "multicast",
+        abuf_json_string(abuf, "multicast",
                              ip6_to_string(&maskbuf, &rifs->int6_multaddr.sin6_addr));
       }
     }
@@ -727,6 +926,13 @@ ipc_print_interfaces(struct autobuf *abuf)
 }
 
 
+static void
+ipc_print_olsrd_conf(struct autobuf *abuf)
+{
+  olsrd_write_cnf_autobuf(abuf, olsr_cnf);
+}
+
+
 static void
 jsoninfo_write_data(void *foo __attribute__ ((unused)))
 {
@@ -788,34 +994,61 @@ send_info(unsigned int send_what, int the_socket)
 {
   struct autobuf abuf;
 
-  abuf_init(&abuf, 4096);
+  abuf_init(&abuf, 32768);
 
-  /* Print minimal http header */
-  abuf_puts(&abuf, "HTTP/1.0 200 OK\n");
-  abuf_puts(&abuf, "Content-type: text/plain\n\n");
+  /* wrap everything in a JSON array to handle multiple elements*/
+  abuf_puts(&abuf, "\n[\n");
 
   /* Print tables to IPC socket */
 
-  if ((send_what & SIW_LINKS) == SIW_LINKS)
+  if ((send_what & SIW_LINKS) == SIW_LINKS) {
     ipc_print_links(&abuf);
-  if ((send_what & SIW_NEIGHBORS) == SIW_NEIGHBORS)
-    ipc_print_neighbors(&abuf,false);
-  if ((send_what & SIW_TOPOLOGY) == SIW_TOPOLOGY)
+    // if this is being output with others, then include commas
+    if (send_what != SIW_LINKS) abuf_puts(&abuf, ",");
+  }
+  if ((send_what & SIW_NEIGHBORS) == SIW_NEIGHBORS) {
+    ipc_print_neighbors(&abuf);
+    if (send_what != SIW_NEIGHBORS) abuf_puts(&abuf, ",");
+  }
+  if ((send_what & SIW_TOPOLOGY) == SIW_TOPOLOGY) {
     ipc_print_topology(&abuf);
-  if ((send_what & SIW_HNA) == SIW_HNA)
+    if (send_what != SIW_TOPOLOGY) abuf_puts(&abuf, ",");
+  }
+  if ((send_what & SIW_HNA) == SIW_HNA) {
     ipc_print_hna(&abuf);
-  if ((send_what & SIW_MID) == SIW_MID)
+    if (send_what != SIW_HNA) abuf_puts(&abuf, ",");
+  }
+  if ((send_what & SIW_MID) == SIW_MID) {
     ipc_print_mid(&abuf);
-  if ((send_what & SIW_ROUTES) == SIW_ROUTES)
+    if (send_what != SIW_MID) abuf_puts(&abuf, ",");
+  }
+  if ((send_what & SIW_ROUTES) == SIW_ROUTES) {
     ipc_print_routes(&abuf);
-  if ((send_what & SIW_GATEWAYS) == SIW_GATEWAYS)
+    if (send_what != SIW_ROUTES) abuf_puts(&abuf, ",");
+  }
+  if ((send_what & SIW_GATEWAYS) == SIW_GATEWAYS) {
     ipc_print_gateways(&abuf);
-  if ((send_what & SIW_CONFIG) == SIW_CONFIG)
-    ipc_print_config(&abuf);
-  if ((send_what & SIW_INTERFACES) == SIW_INTERFACES)
+    if (send_what != SIW_GATEWAYS) abuf_puts(&abuf, ",");
+  }
+  if ((send_what & SIW_INTERFACES) == SIW_INTERFACES) {
     ipc_print_interfaces(&abuf);
-  if ((send_what & SIW_TWOHOP) == SIW_TWOHOP)
-    ipc_print_neighbors(&abuf,true);
+    if (send_what != SIW_INTERFACES) abuf_puts(&abuf, ",");
+  }
+  if ((send_what & SIW_CONFIG) == SIW_CONFIG) {
+    ipc_print_config(&abuf);
+    if (send_what != SIW_CONFIG) abuf_puts(&abuf, ",");
+  }
+  if ((send_what & SIW_PLUGINS) == SIW_PLUGINS) {
+    ipc_print_plugins(&abuf);
+  }
+
+  /* end of JSON array for status */
+  abuf_puts(&abuf, "]\n");
+
+  /* this outputs the olsrd.conf text directly, not JSON */
+  if ((send_what & SIW_OLSRD_CONF) == SIW_OLSRD_CONF) {
+    ipc_print_olsrd_conf(&abuf);
+  }
 
   outbuffer[outbuffer_count] = olsr_malloc(abuf.len, "txt output buffer");
   outbuffer_size[outbuffer_count] = abuf.len;