From 27bb782a980783de851a0613f4baa226032660c3 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 20 Dec 2022 13:01:52 +0200 Subject: [PATCH] bgpd: Adopt `show bgp detail-routes` command for L3VPN outputs as well ``` unet> sh pe2 vtysh -c 'sh ip bgp ipv4 vpn detail-routes' BGP table version is 4, local router ID is 10.10.10.20, vrf id 0 Default local pref 100, local AS 65001 Route Distinguisher: 192.168.2.2:2 BGP routing table entry for 192.168.2.2:2:10.0.0.0/24, version 1 not allocated Paths: (1 available, best #1) Not advertised to any peer 65000 192.168.2.1 from 0.0.0.0 (10.10.10.20) vrf RED(4) announce-nh-self Origin incomplete, metric 0, localpref 50, valid, sourced, local, best (First path received) Extended Community: RT:192.168.2.2:2 Originator: 10.10.10.20 Remote label: 2222 Last update: Tue Dec 20 13:01:20 2022 BGP routing table entry for 192.168.2.2:2:172.16.255.1/32, version 2 not allocated Paths: (1 available, best #1) Not advertised to any peer 65000 192.168.2.1 from 0.0.0.0 (10.10.10.20) vrf RED(4) announce-nh-self Origin incomplete, localpref 50, valid, sourced, local, best (First path received) Extended Community: RT:192.168.2.2:2 Originator: 10.10.10.20 Remote label: 2222 Last update: Tue Dec 20 13:01:20 2022 BGP routing table entry for 192.168.2.2:2:192.168.1.0/24, version 3 not allocated Paths: (1 available, best #1) Not advertised to any peer 65000 192.168.2.1 from 0.0.0.0 (10.10.10.20) vrf RED(4) announce-nh-self Origin incomplete, localpref 50, valid, sourced, local, best (First path received) Extended Community: RT:192.168.2.2:2 Originator: 10.10.10.20 Remote label: 2222 Last update: Tue Dec 20 13:01:20 2022 BGP routing table entry for 192.168.2.2:2:192.168.2.0/24, version 4 not allocated Paths: (1 available, best #1) Not advertised to any peer 65000 192.168.2.1 from 0.0.0.0 (10.10.10.20) vrf RED(4) announce-nh-self Origin incomplete, metric 0, localpref 50, valid, sourced, local, best (First path received) Extended Community: RT:192.168.2.2:2 Originator: 10.10.10.20 Remote label: 2222 Last update: Tue Dec 20 13:01:20 2022 Displayed 4 routes and 4 total paths ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_mplsvpn.c | 6 +++++- bgpd/bgp_route.c | 21 ++++++++++----------- bgpd/bgp_route.h | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 0270695c2f..c92d678eff 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -2821,6 +2821,10 @@ int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd, { struct bgp *bgp; struct bgp_table *table; + uint16_t show_flags = 0; + + if (use_json) + SET_FLAG(show_flags, BGP_SHOW_OPT_JSON); bgp = bgp_get_default(); if (bgp == NULL) { @@ -2832,7 +2836,7 @@ int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd, } table = bgp->rib[afi][SAFI_MPLS_VPN]; return bgp_show_table_rd(vty, bgp, SAFI_MPLS_VPN, table, prd, type, - output_arg, use_json); + output_arg, show_flags); } DEFUN (show_bgp_ip_vpn_all_rd, diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 8f6a1ff223..e4f1a31fa6 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11601,10 +11601,12 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, AFI_IP, safi, use_json, json_paths); else { - if (detail_routes) { - const struct prefix_rd *prd; + if (detail_routes || detail_json) { + const struct prefix_rd *prd = NULL; - prd = bgp_rd_from_dest(dest, safi); + if (dest->pdest) + prd = bgp_rd_from_dest( + dest->pdest, safi); if (!use_json) route_vty_out_detail_header( @@ -11615,8 +11617,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, NULL); route_vty_out_detail( - vty, bgp, dest, - bgp_dest_get_prefix(dest), pi, + vty, bgp, dest, dest_p, pi, family2afi(dest_p->family), safi, RPKI_NOT_BEING_USED, json_paths); @@ -11705,7 +11706,8 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, struct bgp_table *table, struct prefix_rd *prd_match, - enum bgp_show_type type, void *output_arg, bool use_json) + enum bgp_show_type type, void *output_arg, + uint16_t show_flags) { struct bgp_dest *dest, *next; unsigned long output_cum = 0; @@ -11713,13 +11715,10 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, unsigned long json_header_depth = 0; struct bgp_table *itable; bool show_msg; - uint16_t show_flags = 0; + bool use_json = !!CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON); show_msg = (!use_json && type == bgp_show_type_normal); - if (use_json) - SET_FLAG(show_flags, BGP_SHOW_OPT_JSON); - for (dest = bgp_table_top(table); dest; dest = next) { const struct prefix *dest_p = bgp_dest_get_prefix(dest); @@ -11785,7 +11784,7 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, /* use MPLS and ENCAP specific shows until they are merged */ if (safi == SAFI_MPLS_VPN) { return bgp_show_table_rd(vty, bgp, safi, table, NULL, type, - output_arg, use_json); + output_arg, show_flags); } if (safi == SAFI_FLOWSPEC && type == bgp_show_type_detail) { diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 63dd69f805..152a8a0a72 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -866,7 +866,7 @@ extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp, extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, struct bgp_table *table, struct prefix_rd *prd, enum bgp_show_type type, void *output_arg, - bool use_json); + uint16_t show_flags); extern void bgp_best_path_select_defer(struct bgp *bgp, afi_t afi, safi_t safi); extern bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi, uint8_t type, uint8_t stype, -- 2.39.5