From: claudio Date: Mon, 9 Aug 2021 08:24:36 +0000 (+0000) Subject: Make it possible to match on path-id in bgpctl show rib outputs. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=46daf8ccaf7ebe86b50b9b71eb03242ad5810152;p=openbsd Make it possible to match on path-id in bgpctl show rib outputs. To work properly also a neighbor needs to be selected. The assumption here is that the peer will use the same path-id for the same peer accross all its routes. The RFC does not require this and it is valid to assign path-ids randomly. The path-id only matters for one specific path but most BGP implementations seem to assign the same path-id to multiple routes when originated from the same source. OK benno@ --- diff --git a/usr.sbin/bgpctl/bgpctl.8 b/usr.sbin/bgpctl/bgpctl.8 index 32e3462bcdb..a9e6accdf1e 100644 --- a/usr.sbin/bgpctl/bgpctl.8 +++ b/usr.sbin/bgpctl/bgpctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: bgpctl.8,v 1.99 2021/06/16 16:24:12 job Exp $ +.\" $OpenBSD: bgpctl.8,v 1.100 2021/08/09 08:24:36 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: June 16 2021 $ +.Dd $Mdocdate: August 9 2021 $ .Dt BGPCTL 8 .Os .Sh NAME @@ -348,6 +348,13 @@ Show RIB memory statistics. Show only entries from the specified peer. .It Cm neighbor group Ar description Show only entries from the specified peer group. +.It Cm path-id Ar pathid +Show only entries which match the specified +.Ar pathid . +Must be used together with either +.Cm neighbor +or +.Cm out . .It Cm peer-as Ar as Show all entries with .Ar as diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index 1e0b733c281..724c185f44c 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.272 2021/08/02 16:51:39 claudio Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.273 2021/08/09 08:24:36 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -249,6 +249,7 @@ main(int argc, char *argv[]) ribreq.neighbor = neighbor; strlcpy(ribreq.rib, res->rib, sizeof(ribreq.rib)); ribreq.aid = res->aid; + ribreq.path_id = res->pathid; ribreq.flags = res->flags; imsg_compose(ibuf, type, 0, 0, -1, &ribreq, sizeof(ribreq)); break; diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c index 5b5e94b5695..f1a85519958 100644 --- a/usr.sbin/bgpctl/parser.c +++ b/usr.sbin/bgpctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.106 2021/02/16 08:30:21 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.107 2021/08/09 08:24:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -61,7 +61,8 @@ enum token_type { RD, FAMILY, RTABLE, - FILENAME + FILENAME, + PATHID, }; struct token { @@ -114,6 +115,7 @@ static const struct token t_log[]; static const struct token t_fib_table[]; static const struct token t_show_fib_table[]; static const struct token t_communication[]; +static const struct token t_show_rib_path[]; static const struct token t_main[] = { { KEYWORD, "reload", RELOAD, t_communication}, @@ -178,10 +180,11 @@ static const struct token t_show_rib[] = { { FLAG, "in", F_CTL_ADJ_IN, t_show_rib}, { FLAG, "out", F_CTL_ADJ_OUT, t_show_rib}, { KEYWORD, "neighbor", NONE, t_show_rib_neigh}, + { KEYWORD, "ovs", NONE, t_show_ovs}, + { KEYWORD, "path-id", NONE, t_show_rib_path}, { KEYWORD, "table", NONE, t_show_rib_rib}, { KEYWORD, "summary", SHOW_SUMMARY, t_show_summary}, { KEYWORD, "memory", SHOW_RIB_MEM, NULL}, - { KEYWORD, "ovs", NONE, t_show_ovs}, { FAMILY, "", NONE, t_show_rib}, { PREFIX, "", NONE, t_show_prefix}, { ENDTOKEN, "", NONE, NULL} @@ -479,6 +482,11 @@ static const struct token t_show_fib_table[] = { { ENDTOKEN, "", NONE, NULL} }; +static const struct token t_show_rib_path[] = { + { PATHID, "", NONE, t_show_rib}, + { ENDTOKEN, "", NONE, NULL} +}; + static struct parse_result res; const struct token *match_token(int *argc, char **argv[], @@ -748,6 +756,7 @@ match_token(int *argc, char **argv[], const struct token table[]) case PREPSELF: case WEIGHT: case RTABLE: + case PATHID: if (word != NULL && wordlen > 0 && parse_number(word, &res, table[i].type)) { match++; @@ -863,6 +872,7 @@ show_valid_args(const struct token table[]) case PREPNBR: case PREPSELF: case WEIGHT: + case PATHID: fprintf(stderr, " \n"); break; case RTABLE: @@ -1019,9 +1029,16 @@ parse_number(const char *word, struct parse_result *r, enum token_type type) errx(1, "number is %s: %s", errstr, word); /* number was parseable */ - if (type == RTABLE) { + switch (type) { + case RTABLE: r->rtableid = uval; return (1); + case PATHID: + r->pathid = uval; + r->flags |= F_CTL_HAS_PATHID; + return (1); + default: + break; } if ((fs = calloc(1, sizeof(struct filter_set))) == NULL) diff --git a/usr.sbin/bgpctl/parser.h b/usr.sbin/bgpctl/parser.h index 31080505287..397bd9bc896 100644 --- a/usr.sbin/bgpctl/parser.h +++ b/usr.sbin/bgpctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.40 2021/02/16 08:30:21 claudio Exp $ */ +/* $OpenBSD: parser.h,v 1.41 2021/08/09 08:24:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -71,9 +71,10 @@ struct parse_result { u_int64_t rd; int flags; int is_group; - u_int8_t validation_state; u_int rtableid; + u_int32_t pathid; enum actions action; + u_int8_t validation_state; u_int8_t prefixlen; u_int8_t aid; int mrtfd;