From 5f507ad42d4f53bc532702b7d2b7cd9862b36eff Mon Sep 17 00:00:00 2001 From: Jan Moskyto Matejka Date: Mon, 19 Jun 2017 16:37:43 +0200 Subject: [PATCH] show route flowspec: wrap lines --- lib/flowspec.c | 18 +++++++++--------- lib/flowspec.h | 4 ++-- lib/net.c | 4 ++-- nest/rt-show.c | 22 +++++++++++++++++----- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/lib/flowspec.c b/lib/flowspec.c index 87ce0206..dd6a2cba 100644 --- a/lib/flowspec.c +++ b/lib/flowspec.c @@ -1086,7 +1086,7 @@ net_format_flow_bitmask(buffer *b, const byte *part) } static uint -net_format_flow(char *buf, uint blen, const byte *data, uint dlen, int ipv6) +net_format_flow(char *buf, uint blen, const byte *data, uint dlen, int ipv6, const char *sep) { buffer b = { .start = buf, @@ -1098,13 +1098,13 @@ net_format_flow(char *buf, uint blen, const byte *data, uint dlen, int ipv6) *buf = 0; if (ipv6) - buffer_puts(&b, "flow6 { "); + buffer_puts(&b, "flow6 {"); else - buffer_puts(&b, "flow4 { "); + buffer_puts(&b, "flow4 {"); while (part) { - buffer_print(&b, "%s ", flow_type_str(*part, ipv6)); + buffer_print(&b, "%s%s ", sep, flow_type_str(*part, ipv6)); switch (*part) { @@ -1132,7 +1132,7 @@ net_format_flow(char *buf, uint blen, const byte *data, uint dlen, int ipv6) part = flow_next_part(part, data+dlen, ipv6); } - buffer_puts(&b, "}"); + buffer_print(&b, "%s}", sep); if (b.pos == b.end) { @@ -1154,9 +1154,9 @@ net_format_flow(char *buf, uint blen, const byte *data, uint dlen, int ipv6) * ' ...}' sequence and zero-terminator. */ uint -flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f) +flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f, const char *sep) { - return net_format_flow(buf, blen, f->data, f->length - sizeof(net_addr_flow4), 0); + return net_format_flow(buf, blen, f->data, f->length - sizeof(net_addr_flow4), 0, sep); } /** @@ -1170,7 +1170,7 @@ flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f) * ' ...}' sequence and zero-terminator. */ uint -flow6_net_format(char *buf, uint blen, const net_addr_flow6 *f) +flow6_net_format(char *buf, uint blen, const net_addr_flow6 *f, const char *sep) { - return net_format_flow(buf, blen, f->data, f->length - sizeof(net_addr_flow6), 1); + return net_format_flow(buf, blen, f->data, f->length - sizeof(net_addr_flow6), 1, sep); } diff --git a/lib/flowspec.h b/lib/flowspec.h index 4fe23da1..90438b5b 100644 --- a/lib/flowspec.h +++ b/lib/flowspec.h @@ -146,7 +146,7 @@ void flow6_validate_cf(net_addr_flow6 *f); * Net Formatting */ -uint flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f); -uint flow6_net_format(char *buf, uint blen, const net_addr_flow6 *f); +uint flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f, const char *sep); +uint flow6_net_format(char *buf, uint blen, const net_addr_flow6 *f, const char *sep); #endif /* _BIRD_FLOWSPEC_H_ */ diff --git a/lib/net.c b/lib/net.c index a00ff272..09e5354a 100644 --- a/lib/net.c +++ b/lib/net.c @@ -99,9 +99,9 @@ net_format(const net_addr *N, char *buf, int buflen) case NET_ROA6: return bsnprintf(buf, buflen, "%I6/%u-%u AS%u", n->roa6.prefix, n->roa6.pxlen, n->roa6.max_pxlen, n->roa6.asn); case NET_FLOW4: - return flow4_net_format(buf, buflen, &n->flow4); + return flow4_net_format(buf, buflen, &n->flow4, " "); case NET_FLOW6: - return flow6_net_format(buf, buflen, &n->flow6); + return flow6_net_format(buf, buflen, &n->flow6, " "); case NET_MPLS: return bsnprintf(buf, buflen, "%u", n->mpls.label); } diff --git a/nest/rt-show.c b/nest/rt-show.c index 3f5ef04d..981f74e2 100644 --- a/nest/rt-show.c +++ b/nest/rt-show.c @@ -15,6 +15,7 @@ #include "nest/cli.h" #include "nest/iface.h" #include "filter/filter.h" +#include "lib/flowspec.h" static void rt_show_table(struct cli *c, struct rt_show_data *d) @@ -90,16 +91,26 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, ea_list *tm } static void -rt_show_net(struct cli *c, net *n, struct rt_show_data *d) +rt_show_net(struct cli *c, net *n, struct rt_show_data *d, const uint addr_type) { rte *e, *ee; - byte ia[NET_MAX_TEXT_LENGTH+1]; + byte ia[(net_max_text_length[addr_type] ?: 65536)]; struct ea_list *tmpa; struct channel *ec = d->tab->export_channel; int first = 1; int pass = 0; - bsnprintf(ia, sizeof(ia), "%N", n->n.addr); + switch (addr_type) + { + case NET_FLOW4: + flow4_net_format(ia, sizeof(ia), (net_addr_flow4 *) n->n.addr, "\n\t"); + break; + case NET_FLOW6: + flow6_net_format(ia, sizeof(ia), (net_addr_flow6 *) n->n.addr, "\n\t"); + break; + default: + bsnprintf(ia, sizeof(ia), "%N", n->n.addr); + } for (e = n->routes; e; e = e->next) { @@ -210,6 +221,7 @@ rt_show_cont(struct cli *c) #endif struct fib *fib = &d->tab->table->fib; struct fib_iterator *it = &d->fit; + uint addr_type = d->tab->table->addr_type; if (d->running_on_config && (d->running_on_config != config)) { @@ -238,7 +250,7 @@ rt_show_cont(struct cli *c) FIB_ITERATE_PUT(it); return; } - rt_show_net(c, n, d); + rt_show_net(c, n, d, addr_type); } FIB_ITERATE_END; @@ -402,7 +414,7 @@ rt_show(struct rt_show_data *d) n = net_find(tab->table, d->addr); if (n) - rt_show_net(this_cli, n, d); + rt_show_net(this_cli, n, d, tab->table->addr_type); } if (d->rt_counter)