Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
teach bgplgd to display Adj-RIB-In and Adj-RIB-Out
To:
tech@openbsd.org
Date:
Mon, 2 Dec 2024 17:27:22 +0100

Download raw body.

Thread
This extends the /rib endpoint to /rib/in and /rib/out which are shortcuts
for /rib?rib=Adj-RIB-In and /rib?rib=Adj-RIB-Out.
While doing this I realized that the rib param was wrongly translated and
caused bgpctl to fail.

Works for me :)
-- 
:wq Claudio

Index: bgplgd.8
===================================================================
RCS file: /cvs/src/usr.sbin/bgplgd/bgplgd.8,v
diff -u -p -r1.11 bgplgd.8
--- bgplgd.8	19 Sep 2024 08:55:22 -0000	1.11
+++ bgplgd.8	2 Dec 2024 16:25:24 -0000
@@ -88,7 +88,8 @@ Show the version and exit.
 .Nm
 provides the following API endpoints.
 Unless further specified the endpoints do not take any parameters:
-.Bl -tag -width Ds
+.Pp
+.Bl -tag -width "/interfaces" -compact
 .It Pa /interfaces
 Show the interface states.
 .It Pa /memory
@@ -110,7 +111,17 @@ Show only entries from the specified pee
 .It Pa /nexthops
 Show the list of BGP nexthops and the result of their validity check.
 .It Pa /rib
+.It Pa /rib/in
+.It Pa /rib/out
 Show routes from the bgpd(8) Routing Information Base.
+For
+.Pa /rib/in
+the
+.Ar Adj-RIB-In
+will be queried and for
+.Pa /rib/out
+the
+.Ar Adj-RIB-out .
 The following parameters can be used to filter the output:
 .Pp
 .Bl -tag -width "neighbor=peer" -compact
@@ -134,6 +145,9 @@ Show only entries that match the specifi
 .It Cm rib Ns = Ns Ar name
 Show only entries from the RIB with name
 .Ar name .
+Can only be used with the
+.Pa /rib 
+endpoint.
 .It Xo
 .Ic ovs Ns = Ns
 .Pq Ic valid | not-found | invalid
Index: bgplgd.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgplgd/bgplgd.c,v
diff -u -p -r1.3 bgplgd.c
--- bgplgd.c	17 Oct 2022 15:42:19 -0000	1.3
+++ bgplgd.c	2 Dec 2024 15:55:40 -0000
@@ -25,7 +25,7 @@
 
 #include "bgplgd.h"
 
-#define NCMDARGS	4
+#define NCMDARGS	5
 #define OMETRIC_TYPE	\
 	    "application/openmetrics-text; version=1.0.0; charset=utf-8"
 
@@ -41,6 +41,8 @@ const struct cmd {
 	{ "/neighbors", { "show", "neighbor", NULL }, QS_MASK_NEIGHBOR, 1 },
 	{ "/nexthops", { "show", "nexthop", NULL }, 0 },
 	{ "/rib", { "show", "rib", "detail", NULL }, QS_MASK_RIB },
+	{ "/rib/in", { "show", "rib", "in", "detail", NULL }, QS_MASK_ADJRIB },
+	{ "/rib/out", { "show", "rib", "out", "detail", NULL }, QS_MASK_ADJRIB },
 	{ "/rtr", { "show", "rtr", NULL }, 0 },
 	{ "/sets", { "show", "sets", NULL }, 0 },
 	{ "/summary", { "show", NULL }, 0 },
Index: bgplgd.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgplgd/bgplgd.h,v
diff -u -p -r1.4 bgplgd.h
--- bgplgd.h	15 Aug 2024 09:13:13 -0000	1.4
+++ bgplgd.h	2 Dec 2024 15:55:40 -0000
@@ -35,17 +35,19 @@
 #define QS_FILTERED		18
 #define QS_MAX			19
 
-/* too add: empty-as, in, out, peer-as, source-as, transit-as */
+/* too add: empty-as, peer-as, source-as, transit-as */
 
 #define QS_MASK_NEIGHBOR	((1 << QS_NEIGHBOR) | (1 << QS_GROUP))
-#define QS_MASK_RIB						\
+#define QS_MASK_ADJRIB						\
 	((1 << QS_NEIGHBOR) | (1 << QS_GROUP) |	(1 << QS_AS) |	\
 	(1 << QS_PREFIX) | (1 << QS_COMMUNITY) |		\
 	(1 << QS_EXTCOMMUNITY) | (1 << QS_LARGECOMMUNITY) |	\
-	(1 << QS_AF) |	(1 << QS_RIB) | (1 << QS_OVS) |		\
-	(1 << QS_BEST) | (1 << QS_ALL) | (1 << QS_SHORTER) |	\
-	(1 << QS_ERROR) | (1 << QS_AVS) | (1 << QS_INVALID) |	\
-	(1 << QS_LEAKED) | (1 << QS_FILTERED))
+	(1 << QS_AF) | (1 << QS_OVS) | (1 << QS_BEST) |		\
+	(1 << QS_ALL) | (1 << QS_SHORTER) | (1 << QS_ERROR) |	\
+	(1 << QS_AVS) | (1 << QS_INVALID) | (1 << QS_LEAKED) |	\
+	(1 << QS_FILTERED))
+
+#define QS_MASK_RIB	(QS_MASK_ADJRIB | (1 << QS_RIB))
 
 struct cmd;
 struct lg_ctx {
Index: qs.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgplgd/qs.c,v
diff -u -p -r1.6 qs.c
--- qs.c	15 Aug 2024 09:13:13 -0000	1.6
+++ qs.c	2 Dec 2024 16:08:40 -0000
@@ -367,7 +367,7 @@ qs_argv(char **argv, size_t argc, size_t
 	}
 	if (ctx->qs_set & (1 << QS_RIB)) {
 		if (argc < len)
-			argv[argc++] = "rib";
+			argv[argc++] = "table";
 		if (argc < len)
 			argv[argc++] = ctx->qs_args[QS_RIB].string;
 	}