From 81cd72f30006e2e1757a6dc4802b5ca4bb7c8df2 Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Fri, 27 Sep 2019 10:34:55 +0000 Subject: Implement 'bgpctl show rib 8.8.8.8 or-shorter' to show all routes covering 8.8.8.8. Additionally add 'or-longer' as an alias for 'all'. OK job@ sthen@ --- usr.sbin/bgpctl/bgpctl.8 | 18 ++++++++++++++---- usr.sbin/bgpctl/bgpctl.c | 28 +++++++++++++++++++--------- usr.sbin/bgpctl/parser.c | 4 +++- 3 files changed, 36 insertions(+), 14 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/bgpctl/bgpctl.8 b/usr.sbin/bgpctl/bgpctl.8 index 8048f16d09b..cd1f465295f 100644 --- a/usr.sbin/bgpctl/bgpctl.8 +++ b/usr.sbin/bgpctl/bgpctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: bgpctl.8,v 1.91 2019/09/25 15:35:50 sthen Exp $ +.\" $OpenBSD: bgpctl.8,v 1.92 2019/09/27 10:34:54 claudio Exp $ .\" .\" Copyright (c) 2003 Henning Brauer .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 25 2019 $ +.Dd $Mdocdate: September 27 2019 $ .Dt BGPCTL 8 .Os .Sh NAME @@ -223,7 +223,7 @@ Show routes from an MRT table dump file. .Ar filter can be an IP address, a CIDR prefix, an AS filter, a combination or nothing: .Pp -.Bl -tag -width "address/len all" -compact +.Bl -tag -width "address/len or-shorter" -compact .It Ar address Show best matching route for address. .It Ar address Ns Li / Ns Ar len @@ -234,6 +234,11 @@ Show RIB entry for this CIDR prefix. .Xc Show all entries in the specified range. .\".It Ar address/len Cm longer-prefixes +.It Xo +.Ar address Ns Li / Ns Ar len +.Cm or-shorter +.Xc +Show all entries covering and including the specified prefix. .It Cm as Ar as Show all entries with .Ar as @@ -312,7 +317,7 @@ Routing Information Base. .Ar filter can be an IP address, a CIDR prefix, an AS filter or nothing: .Pp -.Bl -tag -width "address/len all" -compact +.Bl -tag -width "address/len or-shorter" -compact .It Ar address Show best matching route for address. .It Ar address Ns Li / Ns Ar len @@ -323,6 +328,11 @@ Show RIB entry for this CIDR prefix. .Xc Show all entries in the specified range. .\".It Ar address/len Cm longer-prefixes +.It Xo +.Ar address Ns Li / Ns Ar len +.Cm or-shorter +.Xc +Show all entries covering and including the specified prefix. .It Cm as Ar as Show all entries with .Ar as diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index 10f2b5c3cf4..6fa5b76e992 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.245 2019/09/25 15:35:50 sthen Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.246 2019/09/27 10:34:54 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -2132,15 +2132,25 @@ show_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg) return; /* filter by prefix */ if (req->prefix.aid != AID_UNSPEC) { - if (!prefix_compare(&req->prefix, &ctl.prefix, - req->prefixlen)) { - if (req->flags & F_LONGER) { - if (req->prefixlen > ctl.prefixlen) - return; - } else if (req->prefixlen != ctl.prefixlen) + if (req->flags & F_LONGER) { + if (req->prefixlen > ctl.prefixlen) return; - } else - return; + if (prefix_compare(&req->prefix, &ctl.prefix, + req->prefixlen)) + return; + } else if (req->flags & F_SHORTER) { + if (req->prefixlen < ctl.prefixlen) + return; + if (prefix_compare(&req->prefix, &ctl.prefix, + ctl.prefixlen)) + return; + } else { + if (req->prefixlen != ctl.prefixlen) + return; + if (prefix_compare(&req->prefix, &ctl.prefix, + req->prefixlen)) + return; + } } /* filter by AS */ if (req->as.type != AS_UNDEF && diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c index e984596d4d9..6ce663d938c 100644 --- a/usr.sbin/bgpctl/parser.c +++ b/usr.sbin/bgpctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.98 2019/06/28 12:12:06 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.99 2019/09/27 10:34:54 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -305,6 +305,8 @@ static const struct token t_show_prefix[] = { { NOTOKEN, "", NONE, NULL}, { FLAG, "all", F_LONGER, NULL}, { FLAG, "longer-prefixes", F_LONGER, NULL}, + { FLAG, "or-longer", F_LONGER, NULL}, + { FLAG, "or-shorter", F_SHORTER, NULL}, { ENDTOKEN, "", NONE, NULL} }; -- cgit v1.2.3