#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 */
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; }
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);
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
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);
* 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)
{
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