Merge pull request #17870 from opensourcerouting/fix/bgp_show_ip_bgp_cmd_internal

bgpd: Show internal data for BGP routes
This commit is contained in:
Russ White 2025-02-11 08:44:43 -05:00 committed by GitHub
commit b040b83c35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 81 additions and 56 deletions

View File

@ -766,7 +766,7 @@ static void bgp_evpn_show_routes_mac_ip_es(struct vty *vty, esi_t *esi,
if (detail)
route_vty_out_detail(vty, bgp, bd, bgp_dest_get_prefix(bd), pi,
AFI_L2VPN, SAFI_EVPN, RPKI_NOT_BEING_USED,
json_path, NULL);
json_path, NULL, 0);
else
route_vty_out(vty, &bd->rn->p, pi, 0, SAFI_EVPN,
json_path, false);
@ -893,7 +893,7 @@ static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn,
if (detail)
route_vty_out_detail(vty, bgp, dest, &tmp_p, pi, AFI_L2VPN,
SAFI_EVPN, RPKI_NOT_BEING_USED, json_path,
NULL);
NULL, 0);
else
route_vty_out(vty, &tmp_p, pi, 0, SAFI_EVPN,
@ -2569,7 +2569,7 @@ static void evpn_show_route_vni_multicast(struct vty *vty, struct bgp *bgp,
json_path = json_object_new_array();
route_vty_out_detail(vty, bgp, dest, bgp_dest_get_prefix(dest), pi, afi, safi,
RPKI_NOT_BEING_USED, json_path, NULL);
RPKI_NOT_BEING_USED, json_path, NULL, 0);
if (json)
json_object_array_add(json_paths, json_path);
@ -2697,7 +2697,7 @@ static void evpn_show_route_vni_macip(struct vty *vty, struct bgp *bgp,
}
route_vty_out_detail(vty, bgp, dest, (struct prefix *)&tmp_p, pi, afi, safi,
RPKI_NOT_BEING_USED, json_path, NULL);
RPKI_NOT_BEING_USED, json_path, NULL, 0);
if (json)
json_object_array_add(json_paths, json_path);
@ -2807,7 +2807,7 @@ static void evpn_show_route_rd_macip(struct vty *vty, struct bgp *bgp,
json_path = json_object_new_array();
route_vty_out_detail(vty, bgp, dest, bgp_dest_get_prefix(dest), pi, afi, safi,
RPKI_NOT_BEING_USED, json_path, NULL);
RPKI_NOT_BEING_USED, json_path, NULL, 0);
if (json)
json_object_array_add(json_paths, json_path);
@ -2919,7 +2919,7 @@ static void evpn_show_route_rd(struct vty *vty, struct bgp *bgp,
json_path = json_object_new_array();
route_vty_out_detail(vty, bgp, dest, bgp_dest_get_prefix(dest), pi, afi,
safi, RPKI_NOT_BEING_USED, json_path, NULL);
safi, RPKI_NOT_BEING_USED, json_path, NULL, 0);
if (json)
json_object_array_add(json_paths, json_path);
@ -3055,7 +3055,7 @@ static void evpn_show_route_rd_all_macip(struct vty *vty, struct bgp *bgp,
json_path = json_object_new_array();
route_vty_out_detail(vty, bgp, dest, p, pi, AFI_L2VPN, SAFI_EVPN,
RPKI_NOT_BEING_USED, json_path, NULL);
RPKI_NOT_BEING_USED, json_path, NULL, 0);
if (json)
json_object_array_add(json_paths, json_path);
@ -3227,7 +3227,8 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
route_vty_out_detail(vty, bgp, dest,
bgp_dest_get_prefix(dest), pi,
AFI_L2VPN, SAFI_EVPN,
RPKI_NOT_BEING_USED, json_path, NULL);
RPKI_NOT_BEING_USED, json_path, NULL,
0);
} else
route_vty_out(vty, p, pi, 0, SAFI_EVPN,
json_path, false);

View File

@ -10795,7 +10795,7 @@ static void route_vty_out_detail_es_info(struct vty *vty,
void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
const struct prefix *p, struct bgp_path_info *path, afi_t afi,
safi_t safi, enum rpki_states rpki_curr_state, json_object *json_paths,
struct attr *pattr)
struct attr *pattr, uint16_t show_opts)
{
char buf[INET6_ADDRSTRLEN];
char vni_buf[30] = {};
@ -11824,6 +11824,16 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
llgr_remaining);
}
/* Display internal data if asked */
if (CHECK_FLAG(show_opts, BGP_SHOW_OPT_INTERNAL_DATA)) {
if (!json_paths) {
vty_out(vty, " net: %p, path: %p, pathext: %p, attr: %p\n", path->net,
path, path->extra, attr);
vty_out(vty, " flags net: 0x%u, path: 0x%u, attr: 0x%" PRIu64 "\n",
path->net->flags, path->flags, attr->flag);
}
}
/* Output some debug about internal state of the dest flags */
if (json_paths) {
if (CHECK_FLAG(bn->flags, BGP_NODE_PROCESS_SCHEDULED))
@ -12255,7 +12265,8 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t sa
route_vty_out_detail(vty, bgp, dest, dest_p, pi,
family2afi(dest_p->family), safi,
rpki_curr_state, json_paths, NULL);
rpki_curr_state, json_paths, NULL,
show_flags);
} else {
route_vty_out(vty, dest_p, pi, display,
safi, json_paths, wide);
@ -12773,7 +12784,8 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
static void bgp_show_path_info(const struct prefix_rd *pfx_rd, struct bgp_dest *bgp_node,
struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
json_object *json, enum bgp_path_type pathtype, int *display,
enum rpki_states rpki_target_state, struct attr *attr)
enum rpki_states rpki_target_state, struct attr *attr,
uint16_t show_opts)
{
struct bgp_path_info *pi;
int header = 1;
@ -12817,7 +12829,8 @@ static void bgp_show_path_info(const struct prefix_rd *pfx_rd, struct bgp_dest *
&& (CHECK_FLAG(pi->flags, BGP_PATH_MULTIPATH)
|| CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))))
route_vty_out_detail(vty, bgp, bgp_node, bgp_dest_get_prefix(bgp_node), pi,
afi, safi, rpki_curr_state, json_paths, attr);
afi, safi, rpki_curr_state, json_paths, attr,
show_opts);
}
if (json && json_paths) {
@ -12854,12 +12867,11 @@ const struct prefix_rd *bgp_rd_from_dest(const struct bgp_dest *dest,
}
/* Display specified route of BGP table. */
static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,
struct bgp_table *rib, const char *ip_str,
afi_t afi, safi_t safi,
enum rpki_states rpki_target_state,
struct prefix_rd *prd, int prefix_check,
enum bgp_path_type pathtype, bool use_json)
static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, struct bgp_table *rib,
const char *ip_str, afi_t afi, safi_t safi,
enum rpki_states rpki_target_state, struct prefix_rd *prd,
int prefix_check, enum bgp_path_type pathtype, bool use_json,
uint16_t show_opts)
{
int ret;
int display = 0;
@ -12904,8 +12916,8 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,
continue;
}
bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty, bgp, afi, safi,
json, pathtype, &display, rpki_target_state, NULL);
bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty, bgp, afi, safi, json,
pathtype, &display, rpki_target_state, NULL, show_opts);
bgp_dest_unlock_node(rm);
}
@ -12964,8 +12976,8 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,
rm = longest_pfx;
bgp_dest_lock_node(rm);
bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty, bgp, afi, safi,
json, pathtype, &display, rpki_target_state, NULL);
bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty, bgp, afi, safi, json,
pathtype, &display, rpki_target_state, NULL, show_opts);
bgp_dest_unlock_node(rm);
}
@ -12992,7 +13004,7 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,
if (!prefix_check
|| dest_p->prefixlen == match.prefixlen) {
bgp_show_path_info(NULL, dest, vty, bgp, afi, safi, json, pathtype,
&display, rpki_target_state, NULL);
&display, rpki_target_state, NULL, show_opts);
}
bgp_dest_unlock_node(dest);
@ -13012,10 +13024,10 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,
}
/* Display specified route of Main RIB */
static int bgp_show_route(struct vty *vty, struct bgp *bgp, const char *ip_str,
afi_t afi, safi_t safi, struct prefix_rd *prd,
int prefix_check, enum bgp_path_type pathtype,
enum rpki_states rpki_target_state, bool use_json)
static int bgp_show_route(struct vty *vty, struct bgp *bgp, const char *ip_str, afi_t afi,
safi_t safi, struct prefix_rd *prd, int prefix_check,
enum bgp_path_type pathtype, enum rpki_states rpki_target_state,
bool use_json, uint16_t show_opts)
{
if (!bgp) {
bgp = bgp_get_default();
@ -13032,9 +13044,9 @@ static int bgp_show_route(struct vty *vty, struct bgp *bgp, const char *ip_str,
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
return bgp_show_route_in_table(vty, bgp, bgp->rib[afi][safi], ip_str,
afi, safi, rpki_target_state, prd,
prefix_check, pathtype, use_json);
return bgp_show_route_in_table(vty, bgp, bgp->rib[afi][safi], ip_str, afi, safi,
rpki_target_state, prd, prefix_check, pathtype, use_json,
show_opts);
}
static int bgp_show_lcommunity(struct vty *vty, struct bgp *bgp, int argc,
@ -13396,7 +13408,7 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd,
|A.B.C.D/M longer-prefixes\
|X:X::X:X/M longer-prefixes\
|"BGP_SELF_ORIG_CMD_STR"\
|detail-routes$detail_routes\
|detail-routes$detail_routes [internal$internal]\
] [json$uj [detail$detail_json] | wide$wide]",
SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
@ -13447,6 +13459,7 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd,
"Display route and more specific routes\n"
BGP_SELF_ORIG_HELP_STR
"Display detailed version of all routes\n"
"Display detailed version of all routes including internal data\n"
JSON_STR
"Display detailed version of JSON output\n"
"Increase table width for longer prefixes\n")
@ -13475,6 +13488,9 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd,
if (detail_routes)
SET_FLAG(show_flags, BGP_SHOW_OPT_ROUTES_DETAIL);
if (internal)
SET_FLAG(show_flags, BGP_SHOW_OPT_INTERNAL_DATA);
/* [<ipv4|ipv6> [all]] */
if (all) {
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_ALL);
@ -13763,7 +13779,7 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd,
DEFUN (show_ip_bgp_route,
show_ip_bgp_route_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]<A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> [<bestpath|multipath>] [rpki <valid|invalid|notfound>] [json]",
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]<A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> [internal] [<bestpath|multipath>] [rpki <valid|invalid|notfound>] [json]",
SHOW_STR
IP_STR
BGP_STR
@ -13774,6 +13790,7 @@ DEFUN (show_ip_bgp_route,
"IPv4 prefix\n"
"Network in the BGP routing table to display\n"
"IPv6 prefix\n"
"Display internal data additionally\n"
"Display only the bestpath\n"
"Display only multipaths\n"
"Display only paths that match the specified rpki state\n"
@ -13790,6 +13807,7 @@ DEFUN (show_ip_bgp_route,
struct bgp *bgp = NULL;
enum bgp_path_type path_type;
bool uj = use_json(argc, argv);
uint16_t show_opts = 0;
int idx = 0;
@ -13827,6 +13845,10 @@ DEFUN (show_ip_bgp_route,
prefix = argv[idx]->arg;
/* Display internal data also */
if (argv_find(argv, argc, "internal", &idx))
SET_FLAG(show_opts, BGP_SHOW_OPT_INTERNAL_DATA);
/* [<bestpath|multipath>] */
if (argv_find(argv, argc, "bestpath", &idx))
path_type = BGP_PATH_SHOW_BESTPATH;
@ -13835,8 +13857,8 @@ DEFUN (show_ip_bgp_route,
else
path_type = BGP_PATH_SHOW_ALL;
return bgp_show_route(vty, bgp, prefix, afi, safi, NULL, prefix_check,
path_type, RPKI_NOT_BEING_USED, uj);
return bgp_show_route(vty, bgp, prefix, afi, safi, NULL, prefix_check, path_type,
RPKI_NOT_BEING_USED, uj, show_opts);
}
DEFUN (show_ip_bgp_regexp,
@ -14694,9 +14716,8 @@ DEFUN (show_ip_bgp_vpn_all_route_prefix,
return CMD_WARNING;
}
return bgp_show_route(vty, bgp, network, AFI_IP, SAFI_MPLS_VPN, NULL, 0,
BGP_PATH_SHOW_ALL, RPKI_NOT_BEING_USED,
use_json(argc, argv));
return bgp_show_route(vty, bgp, network, AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_SHOW_ALL,
RPKI_NOT_BEING_USED, use_json(argc, argv), 0);
}
#endif /* KEEP_OLD_VPN_COMMANDS */
@ -14728,9 +14749,8 @@ DEFUN (show_bgp_l2vpn_evpn_route_prefix,
vty_out(vty, "Unable to figure out Network\n");
return CMD_WARNING;
}
return bgp_show_route(vty, NULL, network, AFI_L2VPN, SAFI_EVPN, NULL,
prefix_check, BGP_PATH_SHOW_ALL,
RPKI_NOT_BEING_USED, use_json(argc, argv));
return bgp_show_route(vty, NULL, network, AFI_L2VPN, SAFI_EVPN, NULL, prefix_check,
BGP_PATH_SHOW_ALL, RPKI_NOT_BEING_USED, use_json(argc, argv), 0);
}
static void show_adj_route_header(struct vty *vty, struct peer *peer,
@ -14886,8 +14906,9 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
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, NULL);
bgp_show_path_info(NULL /* prefix_rd */, dest, vty, bgp, afi, safi,
json_net, BGP_PATH_SHOW_ALL, &display,
RPKI_NOT_BEING_USED, NULL, show_flags);
if (use_json)
json_object_object_addf(json_ar, json_net,
"%pFX", rn_p);
@ -15023,7 +15044,7 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
pass_in = dest;
bgp_show_path_info(NULL, pass_in, vty, bgp, afi, safi,
json_net, BGP_PATH_SHOW_ALL, &display,
RPKI_NOT_BEING_USED, NULL);
RPKI_NOT_BEING_USED, NULL, show_flags);
if (use_json)
json_object_object_addf(
json_ar, json_net,
@ -15075,7 +15096,7 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
bgp_show_path_info(NULL, dest, vty, bgp, afi, safi,
json_net, BGP_PATH_SHOW_ALL,
&display, RPKI_NOT_BEING_USED,
adj->attr);
adj->attr, show_flags);
if (use_json)
json_object_object_addf(json_ar, json_net,
"%pFX", rn_p);
@ -15121,9 +15142,10 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
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_BESTPATH,
&display, RPKI_NOT_BEING_USED, NULL);
bgp_show_path_info(NULL /* prefix_rd */, dest, vty, bgp,
afi, safi, json_net,
BGP_PATH_SHOW_BESTPATH, &display,
RPKI_NOT_BEING_USED, NULL, show_flags);
if (use_json)
json_object_object_addf(
json_ar, json_net,
@ -15767,10 +15789,9 @@ DEFUN (show_bgp_afi_vpn_rd_route,
}
if (!strcmp(argv[5]->arg, "all"))
return bgp_show_route(vty, NULL, argv[6]->arg, afi,
SAFI_MPLS_VPN, NULL, 0, BGP_PATH_SHOW_ALL,
RPKI_NOT_BEING_USED,
use_json(argc, argv));
return bgp_show_route(vty, NULL, argv[6]->arg, afi, SAFI_MPLS_VPN, NULL, 0,
BGP_PATH_SHOW_ALL, RPKI_NOT_BEING_USED, use_json(argc, argv),
0);
ret = str2prefix_rd(argv[5]->arg, &prd);
if (!ret) {
@ -15778,9 +15799,8 @@ DEFUN (show_bgp_afi_vpn_rd_route,
return CMD_WARNING;
}
return bgp_show_route(vty, NULL, argv[6]->arg, afi, SAFI_MPLS_VPN, &prd,
0, BGP_PATH_SHOW_ALL, RPKI_NOT_BEING_USED,
use_json(argc, argv));
return bgp_show_route(vty, NULL, argv[6]->arg, afi, SAFI_MPLS_VPN, &prd, 0,
BGP_PATH_SHOW_ALL, RPKI_NOT_BEING_USED, use_json(argc, argv), 0);
}
static struct bgp_distance *bgp_distance_new(void)

View File

@ -752,6 +752,7 @@ DECLARE_HOOK(bgp_route_update,
#define BGP_SHOW_OPT_JSON_DETAIL (1 << 7)
#define BGP_SHOW_OPT_TERSE (1 << 8)
#define BGP_SHOW_OPT_ROUTES_DETAIL (1 << 9)
#define BGP_SHOW_OPT_INTERNAL_DATA (1 << 10)
/* Prototypes. */
extern void bgp_rib_remove(struct bgp_dest *dest, struct bgp_path_info *pi,
@ -969,7 +970,7 @@ extern void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
const struct prefix *p, struct bgp_path_info *path, afi_t afi,
safi_t safi, enum rpki_states, json_object *json_paths,
struct attr *attr);
struct attr *attr, uint16_t show_opts);
extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
struct bgp_table *table, struct prefix_rd *prd,
enum bgp_show_type type, void *output_arg,

View File

@ -4647,7 +4647,7 @@ incoming/outgoing directions.
If ``json`` option is specified, output is displayed in JSON format.
.. clicmd:: show [ip] bgp [afi] [safi] [all] detail-routes
.. clicmd:: show [ip] bgp [afi] [safi] [all] detail-routes [internal]
Display the detailed version of all routes. The same format as using
``show [ip] bgp [afi] [safi] PREFIX``, but for the whole BGP table.
@ -4655,6 +4655,9 @@ incoming/outgoing directions.
If ``all`` option is specified, ``ip`` keyword is ignored and,
routes displayed for all AFIs and SAFIs.
``internal`` option is used to display internal data additionally. JSON
output is not supported with this option.
If ``afi`` is specified, with ``all`` option, routes will be displayed for
each SAFI in the selected AFI.