Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: Show internal data for BGP routes #17870

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions bgpd/bgp_evpn_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
112 changes: 66 additions & 46 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -10743,7 +10743,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] = {};
Expand Down Expand Up @@ -11764,6 +11764,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))
Expand Down Expand Up @@ -12195,7 +12205,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);
Expand Down Expand Up @@ -12713,7 +12724,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;
Expand Down Expand Up @@ -12757,7 +12769,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) {
Expand Down Expand Up @@ -12794,12 +12807,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;
Expand Down Expand Up @@ -12844,8 +12856,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);
}
Expand Down Expand Up @@ -12904,8 +12916,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);
}
Expand All @@ -12932,7 +12944,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);
Expand All @@ -12952,10 +12964,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();
Expand All @@ -12972,9 +12984,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,
Expand Down Expand Up @@ -13336,7 +13348,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
Expand Down Expand Up @@ -13387,6 +13399,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")
Expand Down Expand Up @@ -13415,6 +13428,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);
Expand Down Expand Up @@ -13703,7 +13719,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
Expand All @@ -13714,6 +13730,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"
Expand All @@ -13730,6 +13747,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;

Expand Down Expand Up @@ -13767,6 +13785,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;
Expand All @@ -13775,8 +13797,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,
Expand Down Expand Up @@ -14634,9 +14656,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 */

Expand Down Expand Up @@ -14668,9 +14689,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,
Expand Down Expand Up @@ -14826,8 +14846,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);
Expand Down Expand Up @@ -14963,7 +14984,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,
Expand Down Expand Up @@ -15015,7 +15036,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);
Expand Down Expand Up @@ -15061,9 +15082,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,
Expand Down Expand Up @@ -15705,20 +15727,18 @@ 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) {
vty_out(vty, "%% Malformed Route Distinguisher\n");
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)
Expand Down
3 changes: 2 additions & 1 deletion bgpd/bgp_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -968,7 +969,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,
Expand Down
Loading
Loading