diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 988be7f4de4c..17d25f8248b9 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -14675,6 +14675,8 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table, } for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) { + struct bgp_path_info *bpi = NULL; + if (type == bgp_show_adj_route_received || type == bgp_show_adj_route_filtered) { for (ain = dest->adj_in; ain; ain = ain->next) { @@ -14779,57 +14781,51 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table, peer, rn_p, &attr, afi, safi, rmap_name); - if (ret != RMAP_DENY) { - if ((safi == SAFI_MPLS_VPN) - || (safi == SAFI_ENCAP) - || (safi == SAFI_EVPN)) { - if (use_json) - json_object_string_add( - json_ar, - "rd", - rd_str); - else if (show_rd - && rd_str) { - vty_out(vty, - "Route Distinguisher: %s\n", - rd_str); - show_rd = false; - } + if (ret == RMAP_DENY) { + (*filtered_count)++; + bgp_attr_flush(&attr); + continue; + } + + if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || + (safi == SAFI_EVPN)) { + if (use_json) + json_object_string_add(json_ar, "rd", + rd_str); + else if (show_rd && rd_str) { + vty_out(vty, "Route Distinguisher: %s\n", + rd_str); + show_rd = false; } - if (detail) { - if (use_json) - json_net = - json_object_new_object(); - bgp_show_path_info( - NULL /* prefix_rd - */ - , - dest, vty, bgp, - afi, safi, - json_net, - BGP_PATH_SHOW_ALL, - &display, - RPKI_NOT_BEING_USED); - if (use_json) - json_object_object_addf( - json_ar, - json_net, - "%pFX", - rn_p); - } else - route_vty_out_tmp(vty, - bgp, - dest, - rn_p, - &attr, - safi, - use_json, - json_ar, - wide); - (*output_count)++; + } + if (detail) { + if (use_json) + json_net = json_object_new_object(); + bgp_show_path_info(NULL, dest, vty, bgp, afi, safi, + json_net, BGP_PATH_SHOW_ALL, + &display, RPKI_NOT_BEING_USED); + if (use_json) + json_object_object_addf(json_ar, json_net, + "%pFX", rn_p); } else { - (*filtered_count)++; + /* For JSON output use route_vty_out_tmp() instead + * of route_vty_out(). + * route_vty_out() is path-aware, while + * route_vty_out_tmp() prints only the best path. + * This is for backward compatibility. + */ + if (use_json) { + route_vty_out_tmp(vty, bgp, dest, rn_p, + &attr, safi, use_json, + json_ar, wide); + } else { + for (bpi = bgp_dest_get_bgp_path_info(dest); + bpi; bpi = bpi->next) + route_vty_out(vty, rn_p, bpi, 0, + safi, NULL, wide); + } } + (*output_count)++; bgp_attr_flush(&attr); }