Skip to content

Commit

Permalink
bgpd: Fixed crashes in bgp received-routes brief and detail json
Browse files Browse the repository at this point in the history
BGP was crashing when show bgp vrf default ipv4 unicast neighbors
<ADDR> received-routes [detail] json was being executed. Crash is
due to the following reasons:

During execution of detail JSON output of the above mentioned show
command, bpi (bgp_path_info) variable in show_adj_route() was passed
to bgp_show_path_info() without setting rest of the fields to 0 in
case the route was filtered, which caused BGP to crash
route_vty_out_detail_header()

Ticket:#3819820
Testing Done: Manual and test-suite run
  • Loading branch information
Pdoijode authored and donaldsharp committed Dec 18, 2024
1 parent 47a3e7b commit 330c4ad
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -14231,18 +14231,7 @@ static void show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table

if (type == bgp_show_adj_route_advertised && subgrp
&& CHECK_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE)) {
if (use_json) {
json_object_int_add(json, "bgpTableVersion",
table->version);
json_object_string_addf(json, "bgpLocalRouterId",
"%pI4", &bgp->router_id);
json_object_int_add(json, "defaultLocPrf",
bgp->default_local_pref);
json_object_int_add(json, "localAS",
peer->change_local_as
? peer->change_local_as
: peer->local_as);
} else {
if (!use_json) {
vty_out(vty,
"BGP table version is %" PRIu64
", local router ID is %pI4, vrf id ",
Expand Down Expand Up @@ -14334,6 +14323,9 @@ static void show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table

if (route_filtered ||
ret == RMAP_DENY) {
memset(&bpi, 0,
sizeof(struct
bgp_path_info));
bpi.attr = &attr;
bpi.peer = peer;
buildit.info = &bpi;
Expand Down Expand Up @@ -14689,8 +14681,6 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi, safi_t
vty_out(vty, ",\"defaultLocPrf\":%u",
bgp->default_local_pref);
vty_out(vty, ",\"localAS\":%u", bgp->as);
vty_out(vty, ",\"bgpStatusCodes\": ");
vty_out(vty, ",\"bgpOriginCodes\": ");
if (type == bgp_show_adj_route_advertised &&
subgrp &&
CHECK_FLAG(subgrp->sflags,
Expand Down Expand Up @@ -14798,15 +14788,8 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi, safi_t
output_count);
json_object_int_add(json, "filteredPrefixCounter",
filtered_count);
}

/*
* This is an extremely expensive operation at scale
* and non-pretty reduces memory footprint significantly.
*/
if ((type != bgp_show_adj_route_advertised) &&
(type != bgp_show_adj_route_received))
vty_json_no_pretty(vty, json);
}
} else if (output_count > 0) {
if (!match && filtered_count > 0)
vty_out(vty,
Expand Down

0 comments on commit 330c4ad

Please sign in to comment.