This diff extends the show rib command to only show invalid (ineligible)
or leaked (via OTC leak detection) routes.

While there rename the OTC_LOOP defines to OTC_LEAK since this is not a
route loop but a route leak.
-- 
:wq Claudio

Index: usr.sbin/bgpctl/bgpctl.8
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.8,v
retrieving revision 1.105
diff -u -p -r1.105 bgpctl.8
--- usr.sbin/bgpctl/bgpctl.8    2 Mar 2023 17:09:52 -0000       1.105
+++ usr.sbin/bgpctl/bgpctl.8    13 Mar 2023 16:03:01 -0000
@@ -387,8 +387,20 @@ are defined:
 .It Cm best
 Alias for
 .Ic selected .
+.It Cm detail
+Show more detailed output for matching routes.
 .It Cm error
 Show only prefixes which are marked invalid and were treated as withdrawn.
+.It Ar family
+Limit the output to the given address family.
+.It Cm in
+Show routes from the unfiltered Adj-RIB-In.
+.It Cm invalid
+Show only routes which are not eligible.
+.It Cm leaked
+Show only routes where a route leak was detected.
+.It Cm out
+Show the filtered routes sent to a neighbor.
 .It Cm selected
 Show only selected routes.
 .It Cm ssv
@@ -396,17 +408,9 @@ Show each RIB entry as a single line, wi
 Only works if
 .Cm detail
 is specified.
-.It Cm detail
-Show more detailed output for matching routes.
-.It Ar family
-Limit the output to the given address family.
-.It Cm in
-Show routes from the unfiltered Adj-RIB-In.
 The
 .Cm neighbor
 needs to be specified.
-.It Cm out
-Show the filtered routes sent to a neighbor.
 The
 .Cm neighbor
 needs to be specified.
Index: usr.sbin/bgpctl/bgpctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.289
diff -u -p -r1.289 bgpctl.c
--- usr.sbin/bgpctl/bgpctl.c    24 Jan 2023 11:29:34 -0000      1.289
+++ usr.sbin/bgpctl/bgpctl.c    13 Mar 2023 16:09:02 -0000
@@ -711,7 +711,7 @@ fmt_flags(uint32_t flags, int sum)
        if (sum) {
                if (flags & F_PREF_INVALID)
                        *p++ = 'E';
-               if (flags & F_PREF_OTC_LOOP)
+               if (flags & F_PREF_OTC_LEAK)
                        *p++ = 'L';
                if (flags & F_PREF_ANNOUNCE)
                        *p++ = 'A';
@@ -737,8 +737,8 @@ fmt_flags(uint32_t flags, int sum)
 
                if (flags & F_PREF_INVALID)
                        strlcat(buf, ", invalid", sizeof(buf));
-               if (flags & F_PREF_OTC_LOOP)
-                       strlcat(buf, ", otc loop", sizeof(buf));
+               if (flags & F_PREF_OTC_LEAK)
+                       strlcat(buf, ", otc leak", sizeof(buf));
                if (flags & F_PREF_STALE)
                        strlcat(buf, ", stale", sizeof(buf));
                if (flags & F_PREF_ELIGIBLE)
Index: usr.sbin/bgpctl/parser.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/parser.c,v
retrieving revision 1.121
diff -u -p -r1.121 parser.c
--- usr.sbin/bgpctl/parser.c    2 Feb 2023 19:23:01 -0000       1.121
+++ usr.sbin/bgpctl/parser.c    13 Mar 2023 16:09:22 -0000
@@ -178,9 +178,11 @@ static const struct token t_show_rib[] =
        { FLAG,         "selected",     F_CTL_BEST,     t_show_rib},
        { FLAG,         "detail",       F_CTL_DETAIL,   t_show_rib},
        { FLAG,         "error",        F_CTL_INVALID,  t_show_rib},
-       { FLAG,         "ssv"   ,       F_CTL_SSV,      t_show_rib},
+       { FLAG,         "invalid",      F_CTL_INELIGIBLE, t_show_rib},
+       { FLAG,         "leaked",       F_CTL_LEAKED,   t_show_rib},
        { FLAG,         "in",           F_CTL_ADJ_IN,   t_show_rib},
        { FLAG,         "out",          F_CTL_ADJ_OUT,  t_show_rib},
+       { FLAG,         "ssv"   ,       F_CTL_SSV,      t_show_rib},
        { KEYWORD,      "neighbor",     NONE,           t_show_rib_neigh},
        { KEYWORD,      "avs",          NONE,           t_show_avs},
        { KEYWORD,      "ovs",          NONE,           t_show_ovs},
Index: usr.sbin/bgpd/bgpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.464
diff -u -p -r1.464 bgpd.h
--- usr.sbin/bgpd/bgpd.h        10 Mar 2023 07:57:15 -0000      1.464
+++ usr.sbin/bgpd/bgpd.h        13 Mar 2023 16:06:51 -0000
@@ -83,20 +83,22 @@
 #define        F_MPLS                  0x0080
 #define        F_LONGER                0x0200
 #define        F_SHORTER               0x0400
-#define        F_CTL_DETAIL            0x1000  /* only set on requests */
-#define        F_CTL_ADJ_IN            0x2000  /* only set on requests */
-#define        F_CTL_ADJ_OUT           0x4000  /* only set on requests */
+#define        F_CTL_DETAIL            0x1000          /* only set on requests 
*/
+#define        F_CTL_ADJ_IN            0x2000          /* only set on requests 
*/
+#define        F_CTL_ADJ_OUT           0x4000          /* only set on requests 
*/
 #define        F_CTL_BEST              0x8000
-#define        F_CTL_SSV               0x20000 /* only used by bgpctl */
-#define        F_CTL_INVALID           0x40000 /* only set on requests */
+#define        F_CTL_INELIGIBLE        0x10000         /* only set on requests 
*/
+#define        F_CTL_LEAKED            0x20000         /* only set on requests 
*/
+#define        F_CTL_INVALID           0x40000         /* only set on requests 
*/
 #define        F_CTL_OVS_VALID         0x80000
 #define        F_CTL_OVS_INVALID       0x100000
 #define        F_CTL_OVS_NOTFOUND      0x200000
-#define        F_CTL_NEIGHBORS         0x400000 /* only used by bgpctl */
-#define        F_CTL_HAS_PATHID        0x800000 /* only set on requests */
+#define        F_CTL_NEIGHBORS         0x400000         /* only used by bgpctl 
*/
+#define        F_CTL_HAS_PATHID        0x800000         /* only set on 
requests */
 #define        F_CTL_AVS_VALID         0x1000000
 #define        F_CTL_AVS_INVALID       0x2000000
 #define        F_CTL_AVS_UNKNOWN       0x4000000
+#define        F_CTL_SSV               0x80000000      /* only used by bgpctl 
*/
 
 #define CTASSERT(x)    extern char  _ctassert[(x) ? 1 : -1 ] \
                            __attribute__((__unused__))
@@ -837,7 +839,7 @@ struct ctl_neighbor {
 #define        F_PREF_STALE    0x010
 #define        F_PREF_INVALID  0x020
 #define        F_PREF_PATH_ID  0x040
-#define        F_PREF_OTC_LOOP 0x080
+#define        F_PREF_OTC_LEAK 0x080
 #define        F_PREF_ECMP     0x100
 #define        F_PREF_AS_WIDE  0x200
 
Index: usr.sbin/bgpd/rde.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
retrieving revision 1.595
diff -u -p -r1.595 rde.c
--- usr.sbin/bgpd/rde.c 10 Mar 2023 07:57:15 -0000      1.595
+++ usr.sbin/bgpd/rde.c 13 Mar 2023 16:03:59 -0000
@@ -1608,7 +1608,7 @@ rde_update_dispatch(struct rde_peer *pee
                        }
                } else {
                        /* Only IPv4 and IPv6 unicast do OTC handling */
-                       state.aspath.flags &= ~F_ATTR_OTC_LOOP;
+                       state.aspath.flags &= ~F_ATTR_OTC_LEAK;
                }
 
                /* unlock the previously locked nexthop, it is no longer used */
@@ -2194,13 +2194,13 @@ bad_flags:
                switch (peer->role) {
                case ROLE_PROVIDER:
                case ROLE_RS:
-                       a->flags |= F_ATTR_OTC_LOOP;
+                       a->flags |= F_ATTR_OTC_LEAK;
                        break;
                case ROLE_PEER:
                        memcpy(&tmp32, p, sizeof(tmp32));
                        tmp32 = ntohl(tmp32);
                        if (tmp32 != peer->conf.remote_as)
-                               a->flags |= F_ATTR_OTC_LOOP;
+                               a->flags |= F_ATTR_OTC_LEAK;
                        break;
                default:
                        break;
@@ -2678,8 +2678,8 @@ rde_dump_rib_as(struct prefix *p, struct
        if (prefix_eligible(p))
                rib.flags |= F_PREF_ELIGIBLE;
        /* otc loop includes parse err so skip the latter if the first is set */
-       if (asp->flags & F_ATTR_OTC_LOOP)
-               rib.flags |= F_PREF_OTC_LOOP;
+       if (asp->flags & F_ATTR_OTC_LEAK)
+               rib.flags |= F_PREF_OTC_LEAK;
        else if (asp->flags & F_ATTR_PARSE_ERR)
                rib.flags |= F_PREF_INVALID;
        staletime = peer->staletime[p->pt->aid];
@@ -2772,6 +2772,11 @@ rde_dump_filter(struct prefix *p, struct
                return;
        if ((req->flags & F_CTL_INVALID) &&
            (asp->flags & F_ATTR_PARSE_ERR) == 0)
+               return;
+       if ((req->flags & F_CTL_INELIGIBLE) && prefix_eligible(p))
+               return;
+       if ((req->flags & F_CTL_LEAKED) &&
+           (asp->flags & F_ATTR_OTC_LEAK) == 0)
                return;
        if ((req->flags & F_CTL_HAS_PATHID)) {
                /* Match against the transmit path id if adjout is used.  */
Index: usr.sbin/bgpd/rde.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v
retrieving revision 1.285
diff -u -p -r1.285 rde.h
--- usr.sbin/bgpd/rde.h 10 Mar 2023 07:57:15 -0000      1.285
+++ usr.sbin/bgpd/rde.h 13 Mar 2023 16:03:20 -0000
@@ -203,7 +203,7 @@ struct rde_community {
 #define        F_PREFIX_ANNOUNCED      0x00400
 #define        F_ANN_DYNAMIC           0x00800
 #define        F_ATTR_OTC              0x01000 /* OTC present */
-#define        F_ATTR_OTC_LOOP         0x02000 /* otc loop, not eligible */
+#define        F_ATTR_OTC_LEAK         0x02000 /* otc leak, not eligible */
 #define        F_ATTR_PARSE_ERR        0x10000 /* parse error, not eligible */
 #define        F_ATTR_LINKED           0x20000 /* if set path is on various 
lists */
 
Index: usr.sbin/bgpd/rde_decide.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_decide.c,v
retrieving revision 1.100
diff -u -p -r1.100 rde_decide.c
--- usr.sbin/bgpd/rde_decide.c  9 Mar 2023 13:12:19 -0000       1.100
+++ usr.sbin/bgpd/rde_decide.c  13 Mar 2023 16:07:31 -0000
@@ -488,7 +488,7 @@ prefix_eligible(struct prefix *p)
 
        /* The aspath needs to be loop and error free */
        if (asp == NULL ||
-           asp->flags & (F_ATTR_LOOP|F_ATTR_OTC_LOOP|F_ATTR_PARSE_ERR))
+           asp->flags & (F_ATTR_LOOP|F_ATTR_OTC_LEAK|F_ATTR_PARSE_ERR))
                return 0;
 
        /* The nexthop must be valid. */
Index: usr.sbin/bgpd/rde_update.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_update.c,v
retrieving revision 1.158
diff -u -p -r1.158 rde_update.c
--- usr.sbin/bgpd/rde_update.c  10 Mar 2023 07:57:16 -0000      1.158
+++ usr.sbin/bgpd/rde_update.c  13 Mar 2023 16:07:49 -0000
@@ -66,7 +66,7 @@ up_test_update(struct rde_peer *peer, st
 
        if (asp == NULL || asp->flags & F_ATTR_PARSE_ERR)
                fatalx("try to send out a botched path");
-       if (asp->flags & (F_ATTR_LOOP | F_ATTR_OTC_LOOP))
+       if (asp->flags & (F_ATTR_LOOP | F_ATTR_OTC_LEAK))
                fatalx("try to send out a looped path");
 
        if (peer == frompeer)

Reply via email to