On Sun, Jul 27, 2014 at 03:36:06PM +0100, Stuart Henderson wrote:
> On 2014/07/27 11:15, Claudio Jeker wrote:
> > Not a big fan since this makes the bgpctl show output no longer fit 80
> > chars and so will wrap lines on default terminals. While it is OK to
> > increase the size it should be taken away from other fields in some whay.
> > An option would be to drop the OutQ since that field has only limited
> > value IMO.
> 
> oh, I would miss not having OutQ, it's totally useless when things are
> working correctly, but I have had a couple of situations (one with openbgp,
> one with *cough* bay BCN "some time ago"...) where this has been helpful.
> It gives quite a clear pointer to problems transmitting to that particular
> peer without having to look in netstat output and work out which peer is
> which (some physical layer problems, MTU problems etc).
> 
> I think the most usable display would be to have neighbor and AS "share"
> a column, with priority to AS... i.e.
> 
> somepeer                12345      16419      89603     0 09:42:06    100/8000
> somepeer-with-long-name  5678    1604940    1367282     0 13:39:28    100/8000
> otherpeer            16584484      16420      89606     0 1d00h58m Active
> otherpeer-with-long- 16584485    1604940    1367282     0 13:40:17    100/8000
> 

The attached patch does just that. Maximum line length is now 80
characters (excluding the trailing newline), and the "Neighbor" and "AS"
columns now take a combined maximum of 29 characters, including the
blank separating peer name and AS. The result looks like this:

$ bgpctl show
Neighbor                   AS    MsgRcvd    MsgSent  OutQ Up/Down  State/PrfRcvd
other-peer-with-l 16581.44851          0          0     0 Never    Connect
other-peer         1658.44841          0          0     0 Never    Active
some-peer-with-long-name 5678          0          0     0 Never    Active
some-peer               12345          0          0     0 Never    Active

Where before it was

$ bgpctl show
Neighbor                   AS    MsgRcvd    MsgSent  OutQ Up/Down  State/PrfRcvd
other-peer-with-long 16581.44851          0          0     0 Never    Connect
other-peer           1658.44841          0          0     0 Never    Active
some-peer-with-long-     5678          0          0     0 Never    Active
some-peer               12345          0          0     0 Never    Connect


-- 
        Gregor Best
Index: bgpctl.c
===================================================================
RCS file: /mnt/media/cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.174
diff -u -p -u -r1.174 bgpctl.c
--- bgpctl.c    18 Mar 2014 13:47:14 -0000      1.174
+++ bgpctl.c    27 Jul 2014 15:20:59 -0000
@@ -517,16 +517,26 @@ show_summary_msg(struct imsg *imsg, int 
 {
        struct peer             *p;
        char                    *s;
+       const char              *a;
+       char                    *pa;
+       size_t                  alen;
 
        switch (imsg->hdr.type) {
        case IMSG_CTL_SHOW_NEIGHBOR:
                p = imsg->data;
                s = fmt_peer(p->conf.descr, &p->conf.remote_addr,
                    p->conf.remote_masklen, nodescr);
-               if (strlen(s) >= 20)
-                       s[20] = 0;
-               printf("%-20s %8s %10llu %10llu %5u %-8s ",
-                   s, log_as(p->conf.remote_as),
+
+               a = log_as(p->conf.remote_as);
+               alen = strlen(a);
+
+               if (asprintf(&pa, "%-28s", s) == -1)
+                       err(1, NULL);
+               if (strlen(pa) > 28 - alen)
+                       pa[28 - alen] = 0;
+
+               printf("%s %s %10llu %10llu %5u %-8s ",
+                   pa, a,
                    p->stats.msg_rcvd_open + p->stats.msg_rcvd_notification +
                    p->stats.msg_rcvd_update + p->stats.msg_rcvd_keepalive +
                    p->stats.msg_rcvd_rrefresh,
@@ -544,6 +554,7 @@ show_summary_msg(struct imsg *imsg, int 
                else
                        printf("%s", statenames[p->state]);
                printf("\n");
+               free(pa);
                free(s);
                break;
        case IMSG_CTL_END:

Reply via email to