Skip to content

Commit

Permalink
bgpd: Fix for match source-protocol in route-map for redistribute cmd
Browse files Browse the repository at this point in the history
A redistribute cmd can have a route-map attached to it and adding the
match source-protocol to that route-map means BGP to filter which
protocol routes to accept among the bunch of routes zebra is sending.

Fixing this since this wasnt implemented earlier.

Ticket :#4119692

Signed-off-by: Donald Sharp <[email protected]>

Signed-off-by: Rajasekar Raja <[email protected]>
(cherry picked from commit 68358c0)

# Conflicts:
#	tests/topotests/bgp_route_map_match_source_protocol/test_bgp_route_map_match_source_protocol.py
  • Loading branch information
raja-rajasekar authored and mergify[bot] committed Nov 9, 2024
1 parent 77fa604 commit c0d4613
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -8760,6 +8760,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,20 @@ def setup_module(mod):

router_list = tgen.routers()

<<<<<<< HEAD
for i, (rname, router) in enumerate(router_list.items(), 1):
router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname)))
=======
for _, (rname, router) in enumerate(router_list.items(), 1):
router.load_frr_config(
os.path.join(CWD, "{}/frr.conf".format(rname)),
[
(TopoRouter.RD_ZEBRA, None),
(TopoRouter.RD_SHARP, None),
(TopoRouter.RD_BGP, None),
],
)
>>>>>>> 68358c0f92 (bgpd: Fix for match source-protocol in route-map for redistribute cmd)

tgen.start_router()

Expand Down Expand Up @@ -109,6 +121,68 @@ 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 192.168.11.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": {
"192.168.11.0/32": {
"valid": True,
},
"192.168.11.1/32": {
"valid": True,
},
"192.168.11.2/32": {
"valid": True,
},
"192.168.11.3/32": {
"valid": True,
},
"192.168.11.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:]
Expand Down

0 comments on commit c0d4613

Please sign in to comment.