[Olsr-dev] [PATCH v1 040/115] txtinfo: convert ACTIVATE_VTIME_TXTINFO into a plugin parameter

Ferry Huberts (spam-protected)
Wed Dec 2 21:28:13 CET 2015


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 lib/txtinfo/README_TXTINFO         |   3 +
 lib/txtinfo/src/olsrd_plugin.c     |   5 +-
 lib/txtinfo/src/olsrd_txtinfo.h    |   3 -
 lib/txtinfo/src/txtinfo_printers.c | 143 ++++++++++++++++++-------------------
 4 files changed, 76 insertions(+), 78 deletions(-)

diff --git a/lib/txtinfo/README_TXTINFO b/lib/txtinfo/README_TXTINFO
index 57b1ea9..21aa743 100644
--- a/lib/txtinfo/README_TXTINFO
+++ b/lib/txtinfo/README_TXTINFO
@@ -79,4 +79,7 @@ LoadPlugin "olsrd_txtinfo.so.0.1"
 
     # Set to true to only listen on IPv6 addresses when running in IPv6 mode.
     # PlParam     "ipv6only"           "false"
+
+    # Set to true to include VTime values into Link/Topology commands
+    # PlParam     "vtime"             "false"
 }
\ No newline at end of file
diff --git a/lib/txtinfo/src/olsrd_plugin.c b/lib/txtinfo/src/olsrd_plugin.c
index cc50e6f..def3368 100644
--- a/lib/txtinfo/src/olsrd_plugin.c
+++ b/lib/txtinfo/src/olsrd_plugin.c
@@ -66,6 +66,7 @@ int nompr;
 bool http_headers;
 bool allow_localhost;
 int txtinfo_ipv6_only;
+bool vtime;
 
 static void my_init(void) __attribute__ ((constructor));
 static void my_fini(void) __attribute__ ((destructor));
@@ -82,6 +83,7 @@ static void my_init(void) {
   http_headers = true;
   allow_localhost = false;
   txtinfo_ipv6_only = false;
+  vtime = false;
 
   if (olsr_cnf->ip_version == AF_INET) {
     txtinfo_accept_ip.v4.s_addr = htonl(INADDR_LOOPBACK);
@@ -119,7 +121,8 @@ static const struct olsrd_plugin_parameters plugin_parameters[] = { //
         { .name = "listen", .set_plugin_parameter = &set_plugin_ipaddress, .data = &txtinfo_listen_ip }, //
         { .name = "httpheaders", .set_plugin_parameter = &set_plugin_boolean, .data = &http_headers }, //
         { .name = "allowlocalhost", .set_plugin_parameter = &set_plugin_boolean, .data = &allow_localhost }, //
-        { .name = "ipv6only", .set_plugin_parameter = &set_plugin_boolean, .data = &txtinfo_ipv6_only } //
+        { .name = "ipv6only", .set_plugin_parameter = &set_plugin_boolean, .data = &txtinfo_ipv6_only }, //
+        { .name = "vtime", .set_plugin_parameter = &set_plugin_boolean, .data = &vtime } //
     };
 
 void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size) {
diff --git a/lib/txtinfo/src/olsrd_txtinfo.h b/lib/txtinfo/src/olsrd_txtinfo.h
index eac3aca..eac7126 100644
--- a/lib/txtinfo/src/olsrd_txtinfo.h
+++ b/lib/txtinfo/src/olsrd_txtinfo.h
@@ -50,9 +50,6 @@
 #include "olsrd_plugin.h"
 #include "plugin_util.h"
 
-/* uncomment this to include VTime values into Link/Topology command */
-/* #define ACTIVATE_VTIME_TXTINFO */
-
 extern union olsr_ip_addr txtinfo_accept_ip;
 extern union olsr_ip_addr txtinfo_listen_ip;
 extern int ipc_port;
diff --git a/lib/txtinfo/src/txtinfo_printers.c b/lib/txtinfo/src/txtinfo_printers.c
index 11da922..34f5f79 100644
--- a/lib/txtinfo/src/txtinfo_printers.c
+++ b/lib/txtinfo/src/txtinfo_printers.c
@@ -53,6 +53,8 @@
 #include "gateway.h"
 #include "../../info/info_types.h"
 
+extern bool vtime;
+
 bool isCommand(const char *str, unsigned int siw) {
   switch (siw) {
     case SIW_OLSRD_CONF:
@@ -152,28 +154,27 @@ void ipc_print_links(struct autobuf *abuf) {
 
   struct link_entry *my_link = NULL;
 
-#ifdef ACTIVATE_VTIME_TXTINFO
-  abuf_puts(abuf, "Table: Links\nLocal IP\tRemote IP\tVTime\tLQ\tNLQ\tCost\n");
-#else /* ACTIVATE_VTIME_TXTINFO */
-  abuf_puts(abuf, "Table: Links\nLocal IP\tRemote IP\tHyst.\tLQ\tNLQ\tCost\n");
-#endif /* ACTIVATE_VTIME_TXTINFO */
+  if (vtime)
+    abuf_puts(abuf, "Table: Links\nLocal IP\tRemote IP\tVTime\tLQ\tNLQ\tCost\n");
+  else
+    abuf_puts(abuf, "Table: Links\nLocal IP\tRemote IP\tHyst.\tLQ\tNLQ\tCost\n");
 
   /* Link set */
   OLSR_FOR_ALL_LINK_ENTRIES(my_link)
       {
-#ifdef ACTIVATE_VTIME_TXTINFO
-        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));
-#else /* ACTIVATE_VTIME_TXTINFO */
-        abuf_appendf(abuf, "%s\t%s\t0.00\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), get_link_entry_text(my_link, '\t', &lqbuffer1),
-            get_linkcost_text(my_link->linkcost, false, &lqbuffer2));
-#endif /* ACTIVATE_VTIME_TXTINFO */
+        if (vtime) {
+          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));
+        } else {
+          abuf_appendf(abuf, "%s\t%s\t0.00\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), get_link_entry_text(my_link, '\t', &lqbuffer1),
+              get_linkcost_text(my_link->linkcost, false, &lqbuffer2));
+        }
       }OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
 
   abuf_puts(abuf, "\n");
@@ -201,11 +202,10 @@ void ipc_print_routes(struct autobuf *abuf) {
 void ipc_print_topology(struct autobuf *abuf) {
   struct tc_entry *tc;
 
-#ifdef ACTIVATE_VTIME_TXTINFO
-  abuf_puts(abuf, "Table: Topology\nDest. IP\tLast hop IP\tLQ\tNLQ\tCost\tVTime\n");
-#else /* ACTIVATE_VTIME_TXTINFO */
-  abuf_puts(abuf, "Table: Topology\nDest. IP\tLast hop IP\tLQ\tNLQ\tCost\n");
-#endif /* ACTIVATE_VTIME_TXTINFO */
+  if (vtime)
+    abuf_puts(abuf, "Table: Topology\nDest. IP\tLast hop IP\tLQ\tNLQ\tCost\tVTime\n");
+  else
+    abuf_puts(abuf, "Table: Topology\nDest. IP\tLast hop IP\tLQ\tNLQ\tCost\n");
 
   /* Topology */
   OLSR_FOR_ALL_TC_ENTRIES(tc)
@@ -216,18 +216,18 @@ void ipc_print_topology(struct autobuf *abuf) {
               if (tc_edge->edge_inv) {
                 struct ipaddr_str dstbuf, addrbuf;
                 struct lqtextbuffer lqbuffer1, lqbuffer2;
-#ifdef ACTIVATE_VTIME_TXTINFO
-                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);
-#else /* ACTIVATE_VTIME_TXTINFO */
-                abuf_appendf(abuf, "%s\t%s\t%s\t%s\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));
-#endif /* ACTIVATE_VTIME_TXTINFO */
+                if (vtime) {
+                  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);
+                } else {
+                  abuf_appendf(abuf, "%s\t%s\t%s\t%s\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));
+                }
               }
             }OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
       }OLSR_FOR_ALL_TC_ENTRIES_END(tc);
@@ -241,11 +241,10 @@ void ipc_print_hna(struct autobuf *abuf) {
   struct hna_net *tmp_net;
   struct ipaddr_str buf, mainaddrbuf;
 
-#ifdef ACTIVATE_VTIME_TXTINFO
-  abuf_puts(abuf, "Table: HNA\nDestination\tGateway\tVTime\n");
-#else /* ACTIVATE_VTIME_TXTINFO */
-  abuf_puts(abuf, "Table: HNA\nDestination\tGateway\n");
-#endif /* ACTIVATE_VTIME_TXTINFO */
+  if (vtime)
+    abuf_puts(abuf, "Table: HNA\nDestination\tGateway\tVTime\n");
+  else
+    abuf_puts(abuf, "Table: HNA\nDestination\tGateway\n");
 
   /* Announced HNA entries */
   for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
@@ -258,16 +257,16 @@ void ipc_print_hna(struct autobuf *abuf) {
 
           /* Check all networks */
           for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
-#ifdef ACTIVATE_VTIME_TXTINFO
-            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));
-#else /* ACTIVATE_VTIME_TXTINFO */
-            abuf_appendf(abuf, "%s/%d\t%s\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));
-#endif /* ACTIVATE_VTIME_TXTINFO */
+            if (vtime) {
+              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));
+            } else {
+              abuf_appendf(abuf, "%s/%d\t%s\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));
+            }
           }
         }OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
 
@@ -279,45 +278,41 @@ void ipc_print_mid(struct autobuf *abuf) {
   unsigned short is_first;
   struct mid_entry *entry;
   struct mid_address *alias;
-#ifdef ACTIVATE_VTIME_TXTINFO
-  abuf_puts(abuf, "Table: MID\nIP address\tAlias\tVTime\n");
-#else /* ACTIVATE_VTIME_TXTINFO */
-  abuf_puts(abuf, "Table: MID\nIP address\tAliases\n");
-#endif /* ACTIVATE_VTIME_TXTINFO */
+  if (vtime)
+    abuf_puts(abuf, "Table: MID\nIP address\tAlias\tVTime\n");
+  else
+    abuf_puts(abuf, "Table: MID\nIP address\tAliases\n");
 
   /* MID */
   for (idx = 0; idx < HASHSIZE; idx++) {
     entry = mid_set[idx].next;
 
     while (entry != &mid_set[idx]) {
-#ifdef ACTIVATE_VTIME_TXTINFO
       struct ipaddr_str buf, buf2;
-#else /* ACTIVATE_VTIME_TXTINFO */
-      struct ipaddr_str buf;
-      abuf_puts(abuf, olsr_ip_to_string(&buf, &entry->main_addr));
-#endif /* ACTIVATE_VTIME_TXTINFO */
+      if (!vtime)
+        abuf_puts(abuf, olsr_ip_to_string(&buf, &entry->main_addr));
+
       alias = entry->aliases;
       is_first = 1;
 
       while (alias) {
-#ifdef ACTIVATE_VTIME_TXTINFO
-        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));
-#else /* ACTIVATE_VTIME_TXTINFO */
-        abuf_appendf(abuf, "%s%s", (is_first ? "\t" : ";"), olsr_ip_to_string(&buf, &alias->alias));
-#endif /* ACTIVATE_VTIME_TXTINFO */
+        if (vtime) {
+          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));
+        } else {
+          abuf_appendf(abuf, "%s%s", (is_first ? "\t" : ";"), olsr_ip_to_string(&buf, &alias->alias));
+        }
         alias = alias->next_alias;
         is_first = 0;
       }
       entry = entry->next;
-#ifndef ACTIVATE_VTIME_TXTINFO
-      abuf_puts(abuf, "\n");
-#endif /* ACTIVATE_VTIME_TXTINFO */
+      if (!vtime)
+        abuf_puts(abuf, "\n");
     }
   }
   abuf_puts(abuf, "\n");
-- 
2.5.0




More information about the Olsr-dev mailing list