Skip to content

Commit 6de8a26

Browse files
authored
Merge pull request FRRouting#18811 from FRRouting/mergify/bp/stable/10.1/pr-18802
bgpd: fix show bgp vpn rd json (backport FRRouting#18802)
2 parents dd4a598 + 516e5e2 commit 6de8a26

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

bgpd/bgp_route.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11949,6 +11949,17 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t sa
1194911949
return CMD_SUCCESS;
1195011950
}
1195111951

11952+
static struct bgp_dest *bgp_route_find_prd_match(struct bgp_dest *curr, struct prefix_rd *match)
11953+
{
11954+
const struct prefix *curr_p = bgp_dest_get_prefix(curr);
11955+
11956+
while (curr && match && memcmp(curr_p->u.val, match->val, 8) != 0) {
11957+
curr = bgp_route_next(curr);
11958+
curr_p = bgp_dest_get_prefix(curr);
11959+
}
11960+
return curr;
11961+
}
11962+
1195211963
int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1195311964
struct bgp_table *table, struct prefix_rd *prd_match,
1195411965
enum bgp_show_type type, void *output_arg,
@@ -11964,12 +11975,10 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
1196411975

1196511976
show_msg = (!use_json && type == bgp_show_type_normal);
1196611977

11967-
for (dest = bgp_table_top(table); dest; dest = next) {
11978+
for (dest = bgp_route_find_prd_match(bgp_table_top(table), prd_match); dest; dest = next) {
1196811979
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
1196911980

11970-
next = bgp_route_next(dest);
11971-
if (prd_match && memcmp(dest_p->u.val, prd_match->val, 8) != 0)
11972-
continue;
11981+
next = bgp_route_find_prd_match(bgp_route_next(dest), prd_match);
1197311982

1197411983
itable = bgp_dest_get_bgp_table_info(dest);
1197511984
if (itable != NULL) {

tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import sys
1717
from functools import partial
1818
import pytest
19+
import json
1920

2021
CWD = os.path.dirname(os.path.realpath(__file__))
2122
sys.path.append(os.path.join(CWD, "../"))
@@ -507,6 +508,26 @@ def test_vrf_route_leak_donna_delete_vrf_zita():
507508
assert result, "BGP VRF DONNA check failed:\n{}".format(diff)
508509

509510

511+
def test_show_bgp_rd_json_output():
512+
"""
513+
Test show bgp ipv4 vpn rd XX json output format is correct
514+
"""
515+
516+
tgen = get_topogen()
517+
# Don't run this test if we have any failure.
518+
if tgen.routers_have_failure():
519+
pytest.skip(tgen.errors)
520+
521+
r1 = tgen.gears["r1"]
522+
ouput = r1.vtysh_cmd("show bgp ipv4 vpn json", isjson=True)
523+
524+
rds = ouput.get("routes", {}).get("routeDistinguishers", {}).keys()
525+
assert len(rds) > 1, "Missing routeDistinguishers"
526+
527+
# will fail with json.decoder.JSONDecodeError if JSON is malformed
528+
json.loads(r1.vtysh_cmd(f"show bgp ipv4 vpn rd {list(rds)[0]} json"))
529+
530+
510531
def test_memory_leak():
511532
"Run the memory leak test and report results."
512533
tgen = get_topogen()

0 commit comments

Comments
 (0)