From 98ca49e0ee581259903e8ab2d6306e61dfc87606 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Wed, 13 Nov 2024 11:47:33 +0200 Subject: [PATCH] bgpd: Show neighbor advertised paths including addpath Without the patch only the best path is displayed. With the patch, display all paths including addpaths, but only for non-JSON output to avoid breaking existing output. E.g.: ``` munet> r2 shi vtysh -c 'sh ip bgp nei 192.168.2.3 advertised-routes' Network Next Hop Metric LocPrf Weight Path *> 172.16.16.254/32 192.168.2.3 0 0 65003 ? * 172.16.16.254/32 192.168.2.4 0 0 65004 ? *> 192.168.2.0/24 192.168.2.3 0 0 65003 ? * 192.168.2.0/24 192.168.2.4 0 0 65004 ? ``` Before it was: ``` munet> r2 shi vtysh -c 'sh ip bgp nei 192.168.2.3 advertised-routes' Network Next Hop Metric LocPrf Weight Path *> 172.16.16.254/32 192.168.2.3 0 0 65003 ? *> 192.168.2.0/24 192.168.2.3 0 0 65003 ? ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_route.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 988be7f4de4c..5290cb74bf21 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) { @@ -14816,16 +14818,27 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table, json_net, "%pFX", rn_p); - } else - route_vty_out_tmp(vty, - bgp, - dest, - rn_p, - &attr, - safi, - use_json, - json_ar, - wide); + } else { + /* 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)++; } else { (*filtered_count)++;