This is just some minor cleanup needed before starting to split out
functions into a new file. First it shuffles and changes the fmt_timecore
functions. It adds an additional check to not print negative timeframes
(the result would most probably be wrong anyway).
Second switch show_mrt_dump to use show_rib instead of calling
show_rib_detail or show_rib_brief directly.

This should not cause any visible change to bgpctl.
OK?
-- 
:wq Claudio

Index: bgpctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.251
diff -u -p -r1.251 bgpctl.c
--- bgpctl.c    19 Dec 2019 06:43:51 -0000      1.251
+++ bgpctl.c    19 Dec 2019 15:57:02 -0000
@@ -58,8 +58,7 @@ void           print_neighbor_capa_mp(struct pee
 void            print_neighbor_capa_restart(struct peer *);
 void            print_neighbor_msgstats(struct peer *);
 void            print_timer(const char *, time_t);
-static char    *fmt_timeframe(time_t t);
-static char    *fmt_timeframe_core(time_t t);
+const char     *fmt_timeframe(time_t t);
 void            show_fib_flags(u_int16_t);
 void            show_fib(struct kroute_full *);
 void            show_fib_table(struct ktable *);
@@ -821,30 +820,10 @@ print_neighbor_msgstats(struct peer *p)
            p->stats.prefix_sent_eor, p->stats.prefix_rcvd_eor);
 }
 
-void
-print_timer(const char *name, time_t d)
-{
-       printf("  %-20s ", name);
-
-       if (d <= 0)
-               printf("%-20s\n", "due");
-       else
-               printf("due in %-13s\n", fmt_timeframe_core(d));
-}
-
 #define TF_BUFS        8
 #define TF_LEN 9
 
-static char *
-fmt_timeframe(time_t t)
-{
-       if (t == 0)
-               return ("Never");
-       else
-               return (fmt_timeframe_core(time(NULL) - t));
-}
-
-static char *
+static const char *
 fmt_timeframe_core(time_t t)
 {
        char            *buf;
@@ -878,6 +857,31 @@ fmt_timeframe_core(time_t t)
        return (buf);
 }
 
+const char *
+fmt_timeframe(time_t t)
+{
+       time_t now;
+
+       if (t == 0)
+               return ("Never");
+
+       now = time(NULL);
+       if (t > now)    /* time in the future is not possible */
+               t = now;
+       return (fmt_timeframe_core(now - t));
+}
+
+void
+print_timer(const char *name, time_t d)
+{
+       printf("  %-20s ", name);
+
+       if (d <= 0)
+               printf("%-20s\n", "due");
+       else
+               printf("due in %-13s\n", fmt_timeframe_core(d));
+}
+
 void
 show_fib_flags(u_int16_t flags)
 {
@@ -1880,10 +1884,14 @@ void
 show_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg)
 {
        struct ctl_show_rib              ctl;
+       struct parse_result              res;
        struct ctl_show_rib_request     *req = arg;
        struct mrt_rib_entry            *mre;
        u_int16_t                        i, j;
 
+       memset(&res, 0, sizeof(res));
+       res.flags = req->flags;
+
        for (i = 0; i < mr->nentries; i++) {
                mre = &mr->entries[i];
                bzero(&ctl, sizeof(ctl));
@@ -1937,14 +1945,13 @@ show_mrt_dump(struct mrt_rib *mr, struct
                    !match_aspath(mre->aspath, mre->aspath_len, &req->as))
                        continue;
 
+               show_rib(&ctl, mre->aspath, mre->aspath_len, &res);
                if (req->flags & F_CTL_DETAIL) {
-                       show_rib_detail(&ctl, mre->aspath, mre->aspath_len, 0);
                        for (j = 0; j < mre->nattrs; j++)
                                show_attr(mre->attrs[j].attr,
                                    mre->attrs[j].attr_len,
                                    req->flags);
-               } else
-                       show_rib_brief(&ctl, mre->aspath, mre->aspath_len);
+               }
        }
 }
 

Reply via email to