jsoninfo: sgw: show entries without tc too
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 23 Nov 2015 19:56:03 +0000 (20:56 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 23 Nov 2015 20:25:42 +0000 (21:25 +0100)
The tc is only used for the path cost, so simply show that as
ROUTE_COST_BROKEN when there is no tc.

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/jsoninfo/src/olsrd_jsoninfo.c

index 122155b..04514b2 100644 (file)
@@ -860,42 +860,31 @@ static void sgw_ipvx(struct autobuf *abuf, bool ipv6) {
     struct gateway_entry * current_gw = olsr_get_inet_gateway(ipv6);
     int i;
     for (i = 0; i < olsr_cnf->smart_gw_use_count; i++) {
-      bool selected;
-      struct ipaddr_str originatorStr;
-      const char * originator;
-      struct ipaddr_str prefixStr;
-      const char * prefix;
       struct interfaceName * node = &sgwTunnelInterfaceNames[i];
-      struct ipaddr_str tunnelGwStr;
-      const char * tunnelGw;
-
       struct gateway_entry * gw = node->gw;
-      struct tc_entry* tc;
 
       if (!gw) {
         continue;
       }
 
-      tc = olsr_lookup_tc_entry(&gw->originator);
-      if (!tc) {
-        continue;
-      }
-
-      selected = current_gw && (current_gw == gw);
-      originator = olsr_ip_to_string(&originatorStr, &gw->originator);
-      prefix = olsr_ip_to_string(&prefixStr, &gw->external_prefix.prefix);
-
-      tunnelGw = olsr_ip_to_string(&tunnelGwStr, &gw->originator);
-
       abuf_json_mark_array_entry(true, abuf);
       {
-        abuf_json_boolean(abuf, "selected", selected);
+        struct tc_entry* tc = olsr_lookup_tc_entry(&gw->originator);
+
+        struct ipaddr_str originatorStr;
+        const char * originator = olsr_ip_to_string(&originatorStr, &gw->originator);
+        struct ipaddr_str prefixIpStr;
+        const char * prefix = olsr_ip_to_string(&prefixIpStr, &gw->external_prefix.prefix);
+        struct ipaddr_str tunnelGwStr;
+        const char * tunnelGw = olsr_ip_to_string(&tunnelGwStr, &gw->originator);
+
+        abuf_json_boolean(abuf, "selected", current_gw && (current_gw == gw));
         abuf_json_string(abuf, "originator", originator);
         abuf_json_string(abuf, "prefix", prefix);
         abuf_json_int(abuf, "prefixLen", gw->external_prefix.prefix_len);
         abuf_json_int(abuf, "uplink", gw->uplink);
         abuf_json_int(abuf, "downlink", gw->downlink);
-        abuf_json_int(abuf, "pathcost", tc->path_cost);
+        abuf_json_int(abuf, "pathcost", !tc ? ROUTE_COST_BROKEN : tc->path_cost);
         abuf_json_boolean(abuf, "IPv4", gw->ipv4);
         abuf_json_boolean(abuf, "IPv4-NAT", gw->ipv4nat);
         abuf_json_boolean(abuf, "IPv6", gw->ipv6);