diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 7a8773947923..a78ae2de2d9f 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -9056,6 +9056,7 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, memset(&rmap_path, 0, sizeof(rmap_path)); rmap_path.peer = bgp->peer_self; rmap_path.attr = &attr_new; + rmap_path.type = type; SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE); diff --git a/tests/topotests/bgp_route_map_match_source_protocol/test_bgp_route_map_match_source_protocol.py b/tests/topotests/bgp_route_map_match_source_protocol/test_bgp_route_map_match_source_protocol.py index 7116deaea46a..c123e842ae42 100644 --- a/tests/topotests/bgp_route_map_match_source_protocol/test_bgp_route_map_match_source_protocol.py +++ b/tests/topotests/bgp_route_map_match_source_protocol/test_bgp_route_map_match_source_protocol.py @@ -22,7 +22,7 @@ # pylint: disable=C0413 from lib import topotest -from lib.topogen import Topogen, get_topogen +from lib.topogen import Topogen, TopoRouter, get_topogen pytestmark = [pytest.mark.bgpd] @@ -48,6 +48,7 @@ def setup_module(mod): for _, (rname, router) in enumerate(router_list.items(), 1): router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + router.load_config(TopoRouter.RD_SHARP, "") tgen.start_router() @@ -109,6 +110,65 @@ def _bgp_check_advertised_routes_r3(): _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assert result is None, "Failed to filter routes by source-protocol for r3" + def _bgp_check_advertised_routes_r4(): + #Remove match source-protocol towards Nbr out policy for Nbr 192.168.1.2 so it receives all routes + tgen.gears["r1"].vtysh_cmd( + """ + configure terminal + route-map r2 permit 10 + no match source-protocol + """ + ) + + tgen.gears["r1"].vtysh_cmd("sharp install route 1.1.1.0 nexthop 172.16.255.1 5") + + #Configure a r4 with source protocol sharp and apply it to all redistribute cmds + tgen.gears["r1"].vtysh_cmd( + """ + configure terminal + route-map r4 permit 10 + match source-protocol sharp + router bgp 65001 + address-family ipv4 unicast + redistribute connected route-map r4 + redistribute static route-map r4 + redistribute sharp route-map r4 + """ + ) + + #Since match protocol is sharp, only sharp protocol routes are to be advertised + output = json.loads( + tgen.gears["r1"].vtysh_cmd( + "show bgp ipv4 unicast neighbors 192.168.1.2 advertised-routes json" + ) + ) + expected = { + "advertisedRoutes": { + "1.1.1.0/32": { + "valid": True, + }, + "1.1.1.1/32": { + "valid": True, + }, + "1.1.1.2/32": { + "valid": True, + }, + "1.1.1.3/32": { + "valid": True, + }, + "1.1.1.4/32": { + "valid": True, + }, + }, + "totalPrefixCounter": 5, + } + + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_check_advertised_routes_r4) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Failed to match the source-protocol for redistribute cmds" + if __name__ == "__main__": args = ["-s"] + sys.argv[1:]