]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Nest: Minor fixes in show route
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 8 Mar 2017 15:27:18 +0000 (16:27 +0100)
committerJan Moskyto Matejka <mq@ucw.cz>
Thu, 9 Mar 2017 12:47:00 +0000 (13:47 +0100)
nest/route.h
nest/rt-attr.c
nest/rt-table.c
proto/static/static.c

index 98bef1fdd726d956397b59cb5c49140813f30f7f..657111386930b7dd68e086f12642c1a01adccbff 100644 (file)
@@ -401,6 +401,7 @@ typedef struct rta {
 #define RTD_BLACKHOLE 2                        /* Silently drop packets */
 #define RTD_UNREACHABLE 3              /* Reject as unreachable */
 #define RTD_PROHIBIT 4                 /* Administratively prohibited */
+#define RTD_MAX 5
 
                                        /* Flags for net->n.flags, used by kernel syncer */
 #define KRF_INSTALLED 0x80             /* This route should be installed in the kernel */
@@ -412,6 +413,11 @@ typedef struct rta {
                                           protocol-specific metric is availabe */
 
 
+const char * rta_dest_names[RTD_MAX];
+
+static inline const char *rta_dest_name(uint n)
+{ return (n < RTD_MAX) ? rta_dest_names[n] : "???"; }
+
 /* Route has regular, reachable nexthop (i.e. not RTD_UNREACHABLE and like) */
 static inline int rte_is_reachable(rte *r)
 { return r->attrs->dest == RTD_UNICAST; }
index 2c8ee7dbe8a8d69c660e773890f3609a57e9891a..1b7f5836c2261aa3e1dc33c2938f2f364b4ba9d1 100644 (file)
 
 #include <stddef.h>
 
+const char * rta_dest_names[RTD_MAX] = {
+  [RTD_NONE]           = "",
+  [RTD_UNICAST]                = "unicast",
+  [RTD_BLACKHOLE]      = "blackhole",
+  [RTD_UNREACHABLE]    = "unreachable",
+  [RTD_PROHIBIT]       = "prohibited",
+};
+
 pool *rta_pool;
 
 static slab *rta_slab_[4];
index 8765d293c3905fac4ea398f65a549faf4c31f4cc..92db6cc8bd85453fb6052b2e7a1ab7f411011353 100644 (file)
@@ -50,7 +50,6 @@ static linpool *rte_update_pool;
 
 static list routing_tables;
 
-static byte *rt_format_via(rte *e);
 static void rt_free_hostcache(rtable *tab);
 static void rt_notify_hostcache(rtable *tab, net *net);
 static void rt_update_hostcache(rtable *tab);
@@ -346,7 +345,7 @@ rte_mergable(rte *pri, rte *sec)
 static void
 rte_trace(struct proto *p, rte *e, int dir, char *msg)
 {
-  log(L_TRACE "%s %c %s %N %s", p->name, dir, msg, e->net->n.addr, rt_format_via(e));
+  log(L_TRACE "%s %c %s %N %s", p->name, dir, msg, e->net->n.addr, rta_dest_name(e->attrs->dest));
 }
 
 static inline void
@@ -2395,12 +2394,12 @@ rt_update_hostentry(rtable *tab, struct hostentry *he)
            he->nexthop_linkable = 0;
            break;
          }
-  
+
       he->src = rta_clone(a);
       he->igp_metric = rt_get_igp_metric(e);
     }
 
- done:
+done:
   /* Add a prefix range to the trie */
   trie_add_prefix(tab->hostcache->trie, &he_addr, pxlen, he_addr.pxlen);
 
@@ -2465,25 +2464,6 @@ rta_set_recursive_next_hop(rtable *dep, rta *a, rtable *tab, ip_addr gw, ip_addr
  *  CLI commands
  */
 
-static byte *
-rt_format_via(rte *e)
-{
-  rta *a = e->attrs;
-
-  /* Max text length w/o IP addr and interface name is 16 */
-  static byte via[IPA_MAX_TEXT_LENGTH+sizeof(a->nh.iface->name)+16];
-
-  switch (a->dest)
-    {
-    case RTD_UNICAST:  bsprintf(via, "unicast"); break;
-    case RTD_BLACKHOLE:        bsprintf(via, "blackhole"); break;
-    case RTD_UNREACHABLE:      bsprintf(via, "unreachable"); break;
-    case RTD_PROHIBIT: bsprintf(via, "prohibited"); break;
-    default:           bsprintf(via, "???");
-    }
-  return via;
-}
-
 static void
 rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, ea_list *tmpa)
 {
@@ -2515,26 +2495,31 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, ea_list *tm
     get_route_info(e, info, tmpa);
   else
     bsprintf(info, " (%d)", e->pref);
-  cli_printf(c, -1007, "%-18s %s [%s %s%s]%s%s", ia, rt_format_via(e), a->src->proto->name,
-            tm, from, primary ? (sync_error ? " !" : " *") : "", info);
-  for (nh = &(a->nh); nh; nh = nh->next)
+
+  cli_printf(c, -1007, "%-18s %s [%s %s%s]%s%s", ia, rta_dest_name(a->dest),
+            a->src->proto->name, tm, from, primary ? (sync_error ? " !" : " *") : "", info);
+
+  if (a->dest == RTD_UNICAST)
+    for (nh = &(a->nh); nh; nh = nh->next)
     {
-      char ls[MPLS_MAX_LABEL_STACK*8 + 5]; char *lsp = ls;
+      char mpls[MPLS_MAX_LABEL_STACK*12 + 5], *lsp = mpls;
+
       if (nh->labels)
-       {
+        {
          lsp += bsprintf(lsp, " mpls %d", nh->label[0]);
          for (int i=1;i<nh->labels; i++)
            lsp += bsprintf(lsp, "/%d", nh->label[i]);
-         *lsp++ = '\0';
        }
+      *lsp = '\0';
+
       if (a->nh.next)
-       cli_printf(c, -1007, "\tvia %I%s on %s weight %d", nh->gw, (nh->labels ? ls : ""), nh->iface->name, nh->weight + 1);
+       cli_printf(c, -1007, "\tvia %I%s on %s weight %d", nh->gw, mpls, nh->iface->name, nh->weight + 1);
       else
-       cli_printf(c, -1007, "\tvia %I%s on %s", nh->gw, (nh->labels ? ls : ""), nh->iface->name);
+       cli_printf(c, -1007, "\tvia %I%s on %s", nh->gw, mpls, nh->iface->name);
     }
+
   if (d->verbose)
     rta_show(c, a, tmpa);
-
 }
 
 static void
index dbe490f94093ca316dbe1a72ca3a4bb19127c4cd..55fd957cca7109161996441e724315c79c737f59 100644 (file)
@@ -570,15 +570,6 @@ static_copy_config(struct proto_config *dest, struct proto_config *src)
   }
 }
 
-
-static const char * rta_dest_names[] = {
-  [RTD_NONE]           = "",
-  [RTD_UNICAST]                = "unicast",
-  [RTD_BLACKHOLE]      = "blackhole",
-  [RTD_UNREACHABLE]    = "unreachable",
-  [RTD_PROHIBIT]       = "prohibited",
-};
-
 static void
 static_show_rt(struct static_route *r)
 {