From 6deaf5794d7940ca8a4a5f0c693abbedc5ab12c8 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 27 Jul 2021 22:29:43 -0300 Subject: [PATCH] bgpd: add "json" option to "show ip bgp ... prefix-list" Move the "prefix-list" option from show_ip_bgp_cmd to show_ip_bgp_json_cmd so that is has access to JSON output. Signed-off-by: Renato Westphal --- bgpd/bgp_route.c | 46 ++++++++++++++++++---------------------------- doc/user/bgp.rst | 9 +++++++++ 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 637408a8da..02a2273952 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -10635,9 +10635,6 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path\n" #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path\n" -static int bgp_show_prefix_list(struct vty *vty, struct bgp *bgp, - const char *prefix_list_str, afi_t afi, - safi_t safi, enum bgp_show_type type); static int bgp_show_filter_list(struct vty *vty, struct bgp *bgp, const char *filter, afi_t afi, safi_t safi, enum bgp_show_type type); @@ -12016,7 +12013,6 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, "]]\ <[all$all] dampening \ |route-map WORD\ - |prefix-list WORD\ |filter-list AS_PATH_FILTER_NAME\ |A.B.C.D/M longer-prefixes\ |X:X::X:X/M longer-prefixes\ @@ -12028,8 +12024,6 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, "Display detail of configured dampening parameters\n" "Display routes matching the route-map\n" "A route-map to match on\n" - "Display routes conforming to the prefix-list\n" - "Prefix-list name\n" "Display routes conforming to the filter-list\n" "Regular expression access list name\n" "IPv4 prefix\n" @@ -12064,10 +12058,6 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, show_flags); } - if (argv_find(argv, argc, "prefix-list", &idx)) - return bgp_show_prefix_list(vty, bgp, argv[idx + 1]->arg, afi, - safi, bgp_show_type_prefix_list); - if (argv_find(argv, argc, "filter-list", &idx)) return bgp_show_filter_list(vty, bgp, argv[idx + 1]->arg, afi, safi, bgp_show_type_filter_list); @@ -12100,6 +12090,7 @@ DEFPY(show_ip_bgp_json, show_ip_bgp_json_cmd, |route-filter-v4|route-filter-translated-v6\ |route-filter-translated-v4] [exact-match]\ |community-list <(1-500)|COMMUNITY_LIST_NAME> [exact-match]\ + |prefix-list WORD\ |rpki \ |version (1-4294967295)\ |alias ALIAS_NAME\ @@ -12131,6 +12122,8 @@ DEFPY(show_ip_bgp_json, show_ip_bgp_json_cmd, "Community-list name\n" "Display routes matching the community-list\n" "Exact match of the communities\n" + "Display routes conforming to the prefix-list\n" + "Prefix-list name\n" "RPKI route types\n" "A valid path as determined by rpki\n" "A invalid path as determined by rpki\n" @@ -12235,6 +12228,21 @@ DEFPY(show_ip_bgp_json, show_ip_bgp_json_cmd, output_arg = list; } + if (argv_find(argv, argc, "prefix-list", &idx)) { + const char *prefix_list_str = argv[++idx]->arg; + struct prefix_list *plist; + + plist = prefix_list_lookup(afi, prefix_list_str); + if (plist == NULL) { + vty_out(vty, "%% %s is not a valid prefix-list name\n", + prefix_list_str); + return CMD_WARNING; + } + + sh_type = bgp_show_type_prefix_list; + output_arg = plist; + } + if (argv_find(argv, argc, "rpki", &idx)) { sh_type = bgp_show_type_rpki; if (argv_find(argv, argc, "valid", &idx)) @@ -12521,24 +12529,6 @@ static int bgp_show_regexp(struct vty *vty, struct bgp *bgp, const char *regstr, return rc; } -static int bgp_show_prefix_list(struct vty *vty, struct bgp *bgp, - const char *prefix_list_str, afi_t afi, - safi_t safi, enum bgp_show_type type) -{ - struct prefix_list *plist; - uint16_t show_flags = 0; - - plist = prefix_list_lookup(afi, prefix_list_str); - if (plist == NULL) { - vty_out(vty, "%% %s is not a valid prefix-list name\n", - prefix_list_str); - return CMD_WARNING; - } - - return bgp_show(vty, bgp, afi, safi, type, plist, show_flags, - RPKI_NOT_BEING_USED); -} - static int bgp_show_filter_list(struct vty *vty, struct bgp *bgp, const char *filter, afi_t afi, safi_t safi, enum bgp_show_type type) diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst index f17fd4f02f..d5267357a5 100644 --- a/doc/user/bgp.rst +++ b/doc/user/bgp.rst @@ -3585,6 +3585,15 @@ structure is extended with :clicmd:`show bgp [afi] [safi]`. Display routes with non-natural netmasks. +.. clicmd:: show [ip] bgp [afi] [safi] [all] prefix-list WORD [wide|json] + + Display routes that match the specified prefix-list. + + If ``wide`` option is specified, then the prefix table's width is increased + to fully display the prefix and the nexthop. + + If the ``json`` option is specified, output is displayed in JSON format. + .. clicmd:: show [ip] bgp [afi] [safi] [all] neighbors A.B.C.D [advertised-routes|received-routes|filtered-routes] [json|wide] Display the routes advertised to a BGP neighbor or received routes -- 2.39.5