]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Moved nexthop + hostentry display to other eattrs
authorMaria Matejka <mq@ucw.cz>
Mon, 27 Jun 2022 11:39:28 +0000 (13:39 +0200)
committerMaria Matejka <mq@ucw.cz>
Mon, 27 Jun 2022 11:39:28 +0000 (13:39 +0200)
nest/rt-attr.c
nest/rt-show.c
nest/rt.h
proto/static/static.c

index 049dc72a6d9f56d7aeba1633e900a7eaeb6c0147..ba036cd232848f95043b80ddd98be9fc511083c3 100644 (file)
@@ -1057,6 +1057,49 @@ ea_show_lc_set(struct cli *c, const char *name, const struct adata *ad, byte *bu
     }
 }
 
+void
+ea_show_nexthop_list(struct cli *c, struct nexthop_adata *nhad)
+{
+  if (!NEXTHOP_IS_REACHABLE(nhad))
+    return;
+
+  NEXTHOP_WALK(nh, nhad)
+  {
+    char mpls[MPLS_MAX_LABEL_STACK*12 + 5], *lsp = mpls;
+    char *onlink = (nh->flags & RNF_ONLINK) ? " onlink" : "";
+    char weight[16] = "";
+
+    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';
+
+    if (!NEXTHOP_ONE(nhad))
+      bsprintf(weight, " weight %d", nh->weight + 1);
+
+    if (ipa_nonzero(nh->gw))
+      cli_printf(c, -1007, "\tvia %I on %s%s%s%s",
+         nh->gw, nh->iface->name, mpls, onlink, weight);
+    else
+      cli_printf(c, -1007, "\tdev %s%s%s",
+         nh->iface->name, mpls,  onlink, weight);
+  }
+}
+
+void
+ea_show_hostentry(const struct adata *ad, byte *buf, uint size)
+{
+  const struct hostentry_adata *had = (const struct hostentry_adata *) ad;
+
+  if (ipa_nonzero(had->he->link) && !ipa_equal(had->he->link, had->he->addr))
+    bsnprintf(buf, size, "via %I %I table %s", had->he->addr, had->he->link, had->he->tab->name);
+  else
+    bsnprintf(buf, size, "via %I table %s", had->he->addr, had->he->tab->name);
+}
+
 /**
  * ea_show - print an &eattr to CLI
  * @c: destination CLI
@@ -1088,6 +1131,9 @@ ea_show(struct cli *c, const eattr *e)
     switch (e->type)
       {
        case T_INT:
+         if ((cls == &ea_gen_igp_metric) && e->u.data >= IGP_METRIC_UNKNOWN)
+           return;
+
          bsprintf(pos, "%u", e->u.data);
          break;
        case T_OPAQUE:
@@ -1111,6 +1157,12 @@ ea_show(struct cli *c, const eattr *e)
        case T_LCLIST:
          ea_show_lc_set(c, cls->name, ad, buf);
          return;
+       case T_NEXTHOP_LIST:
+         ea_show_nexthop_list(c, (struct nexthop_adata *) e->u.ptr);
+         return;
+       case T_HOSTENTRY:
+         ea_show_hostentry(ad, pos, end - pos);
+         break;
        default:
          bsprintf(pos, "<type %02x>", e->type);
       }
@@ -1396,12 +1448,15 @@ rta_init(void)
   rte_src_init();
   ea_class_init();
 
+  /* These attributes are required to be first for nice "show route" output */
+  ea_register_init(&ea_gen_nexthop);
+  ea_register_init(&ea_gen_hostentry);
+
+  /* Other generic route attributes */
   ea_register_init(&ea_gen_preference);
   ea_register_init(&ea_gen_igp_metric);
   ea_register_init(&ea_gen_from);
   ea_register_init(&ea_gen_source);
-  ea_register_init(&ea_gen_nexthop);
-  ea_register_init(&ea_gen_hostentry);
   ea_register_init(&ea_gen_flowspec_valid);
 }
 
index 1404f7e6129a87e7d085f1e6ab6d93e503c8ff10..ac6653ecfe5339984f6ab0271bdb6f09dfd9b75e 100644 (file)
@@ -83,41 +83,16 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary
       net_is_flow(e->net) ? flowspec_valid_name(flowspec_valid) : had ? "recursive" : rta_dest_name(dest),
       e->src->proto->name, tm, from, primary ? (sync_error ? " !" : " *") : "", info);
 
-  if (dest == RTD_UNICAST)
-    NEXTHOP_WALK(nh, nhad)
-    {
-      char mpls[MPLS_MAX_LABEL_STACK*12 + 5], *lsp = mpls;
-      char *onlink = (nh->flags & RNF_ONLINK) ? " onlink" : "";
-      char weight[16] = "";
-
-      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';
-
-      if (!NEXTHOP_ONE(nhad))
-       bsprintf(weight, " weight %d", nh->weight + 1);
-
-      if (ipa_nonzero(nh->gw))
-       cli_printf(c, -1007, "\tvia %I on %s%s%s%s",
-                  nh->gw, nh->iface->name, mpls, onlink, weight);
-      else
-       cli_printf(c, -1007, "\tdev %s%s%s",
-                  nh->iface->name, mpls,  onlink, weight);
-    }
-  else if (had)
-    {
-      if (ipa_nonzero(had->he->link) && !ipa_equal(had->he->link, had->he->addr))
-       cli_printf(c, -1007, "\tvia %I %I table %s", had->he->addr, had->he->link, had->he->tab->name);
-      else
-       cli_printf(c, -1007, "\tvia %I table %s", had->he->addr, had->he->tab->name);
-    }
-
   if (d->verbose)
     ea_show_list(c, a);
+  else if (dest == RTD_UNICAST)
+    ea_show_nexthop_list(c, nhad);
+  else if (had)
+  {
+    char hetext[256];
+    ea_show_hostentry(&had->ad, hetext, sizeof hetext);
+    cli_printf(c, -1007, "\t%s", hetext);
+  }
 }
 
 static void
index 70e0283fff9dbf84c747592ce5172eabc8490bc5..745f96ef812a31a7b9e44aa00368199f8bd599b9 100644 (file)
--- a/nest/rt.h
+++ b/nest/rt.h
@@ -459,6 +459,8 @@ struct hostentry_adata {
 void
 ea_set_hostentry(ea_list **to, struct rtable *dep, struct rtable *tab, ip_addr gw, ip_addr ll, u32 lnum, u32 labels[lnum]);
 
+void ea_show_hostentry(const struct adata *ad, byte *buf, uint size);
+void ea_show_nexthop_list(struct cli *c, struct nexthop_adata *nhad);
 
 /*
  *     Default protocol preferences
index d1d5b92babca8d1b2a518853fea51ee378e310c3..f0a514f7c5cc12138807103c6362ea6cdbcbe0f3 100644 (file)
@@ -695,7 +695,7 @@ static_get_route_info(rte *rte, byte *buf)
 {
   eattr *a = ea_find(rte->attrs, &ea_gen_igp_metric);
   u32 pref = rt_get_preference(rte);
-  if (a)
+  if (a && (a->u.data < IGP_METRIC_UNKNOWN))
     buf += bsprintf(buf, " (%d/%u)", pref, a->u.data);
   else
     buf += bsprintf(buf, " (%d)", pref);