Re: adjust bgpctl show fib formatting

2022-07-28 Thread Theo Buehler
On Thu, Jul 28, 2022 at 12:22:24PM +0200, Claudio Jeker wrote:
> This adjusts the output of bgpctl show fib. It removes the F_DOWN check
> since kroutes no longer track this. And it changes the flag printing code
> to reserve the space needed so that adjusting the flags does not break the
> output. Last but not least increase the size of destination and gateway to
> 32bytes so that more IPv6 addrs fit.

I like it.

ok tb

F_DOWN could now be removed from bgpd.h



adjust bgpctl show fib formatting

2022-07-28 Thread Claudio Jeker
This adjusts the output of bgpctl show fib. It removes the F_DOWN check
since kroutes no longer track this. And it changes the flag printing code
to reserve the space needed so that adjusting the flags does not break the
output. Last but not least increase the size of destination and gateway to
32bytes so that more IPv6 addrs fit.

Before:
> bgpctl show fib con
flags: * = valid, B = BGP, C = Connected, S = Static
   N = BGP Nexthop reachable via this route
   r = reject route, b = blackhole route

flags prio destination  gateway
*CN 4 10.83.0.0/24 link#1
*C  1 10.83.66.5/32link#4

After:
> bgpctl show fib con
flags: B = BGP, C = Connected, S = Static
   N = BGP Nexthop reachable via this route
   r = reject route, b = blackhole route

flags prio destination  gateway 
CN   4 10.83.0.0/24 link#1
C1 10.83.66.5/32link#4

 
-- 
:wq Claudio

Index: bgpctl.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.280
diff -u -p -r1.280 bgpctl.c
--- bgpctl.c7 Jul 2022 12:17:57 -   1.280
+++ bgpctl.c28 Jul 2022 10:03:31 -
@@ -625,19 +625,14 @@ fmt_fib_flags(uint16_t flags)
 {
static char buf[8];
 
-   if (flags & F_DOWN)
-   strlcpy(buf, " ", sizeof(buf));
-   else
-   strlcpy(buf, "*", sizeof(buf));
-
if (flags & F_BGPD)
-   strlcat(buf, "B", sizeof(buf));
+   strlcpy(buf, "B", sizeof(buf));
else if (flags & F_CONNECTED)
-   strlcat(buf, "C", sizeof(buf));
+   strlcpy(buf, "C", sizeof(buf));
else if (flags & F_STATIC)
-   strlcat(buf, "S", sizeof(buf));
+   strlcpy(buf, "S", sizeof(buf));
else
-   strlcat(buf, " ", sizeof(buf));
+   strlcpy(buf, " ", sizeof(buf));
 
if (flags & F_NEXTHOP)
strlcat(buf, "N", sizeof(buf));
@@ -652,9 +647,6 @@ fmt_fib_flags(uint16_t flags)
strlcat(buf, "b", sizeof(buf));
else
strlcat(buf, " ", sizeof(buf));
-
-   if (strlcat(buf, " ", sizeof(buf)) >= sizeof(buf))
-   errx(1, "%s buffer too small", __func__);
 
return buf;
 }
Index: output.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/output.c,v
retrieving revision 1.24
diff -u -p -r1.24 output.c
--- output.c8 Jul 2022 16:12:11 -   1.24
+++ output.c28 Jul 2022 09:59:13 -
@@ -45,12 +45,12 @@ show_head(struct parse_result *res)
"MsgRcvd", "MsgSent", "OutQ", "Up/Down", "State/PrfRcvd");
break;
case SHOW_FIB:
-   printf("flags: * = valid, B = BGP, C = Connected, "
-   "S = Static\n");
+   printf("flags: B = BGP, C = Connected, S = Static\n");
printf("   "
"N = BGP Nexthop reachable via this route\n");
printf("   r = reject route, b = blackhole route\n\n");
-   printf("flags prio destination  gateway\n");
+   printf("%-5s %-4s %-32s %-32s\n", "flags", "prio",
+   "destination", "gateway");
break;
case SHOW_FIB_TABLES:
printf("%-5s %-20s %-8s\n", "Table", "Description", "State");
@@ -467,7 +467,7 @@ show_fib(struct kroute_full *kf)
 
if (asprintf(&p, "%s/%u", log_addr(&kf->prefix), kf->prefixlen) == -1)
err(1, NULL);
-   printf("%s%4i %-20s ", fmt_fib_flags(kf->flags), kf->priority, p);
+   printf("%-5s %4i %-32s ", fmt_fib_flags(kf->flags), kf->priority, p);
free(p);
 
if (kf->flags & F_CONNECTED)
Index: output_json.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/output_json.c,v
retrieving revision 1.19
diff -u -p -r1.19 output_json.c
--- output_json.c   8 Jul 2022 16:12:11 -   1.19
+++ output_json.c   28 Jul 2022 10:04:44 -
@@ -362,7 +362,6 @@ json_fib(struct kroute_full *kf)
 
json_do_printf("prefix", "%s/%u", log_addr(&kf->prefix), kf->prefixlen);
json_do_uint("priority", kf->priority);
-   json_do_bool("up", !(kf->flags & F_DOWN));
if (kf->flags & F_BGPD)
origin = "bgp";
else if (kf->flags & F_CONNECTED)