Skip to content

Commit ee920c5

Browse files
authored
Merge pull request #18851 from FRRouting/mergify/bp/stable/10.1/pr-18828
bgpd: fix to show exist/non-exist-map in 'show run' properly (backport #18828)
2 parents 26f029c + 209aa81 commit ee920c5

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

bgpd/bgp_vty.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18148,12 +18148,23 @@ static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
1814818148
uint8_t type, int direct)
1814918149
{
1815018150
struct bgp_filter *filter;
18151+
filter = &peer->filter[afi][safi];
1815118152

18152-
if (peer_group_active(peer))
18153+
if (peer_group_active(peer)) {
18154+
/* This is required because the filter_override stores only the filter type.
18155+
* To determine whether exist-map or non-exist-map is configured along with adv-map filter,
18156+
* 'advmap.condition == direct' is evaluated where 'direct' should be passed appropriately by the caller */
18157+
if (type == PEER_FT_ADVERTISE_MAP) {
18158+
if (CHECK_FLAG(peer->filter_override[afi][safi][RMAP_OUT], type)) {
18159+
/* Only return true if the condition matches what we're checking for */
18160+
return (filter->advmap.condition == direct);
18161+
}
18162+
return false;
18163+
}
1815318164
return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
1815418165
type);
18166+
}
1815518167

18156-
filter = &peer->filter[afi][safi];
1815718168
switch (type) {
1815818169
case PEER_FT_DISTRIBUTE_LIST:
1815918170
return !!(filter->dlist[direct].name);

tests/topotests/bgp_peer_group/test_bgp_peer-group.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,89 @@ def _bgp_peer_group_remoteas_add():
143143
assert result is None, "Failed bgp convergence in r1"
144144

145145

146+
def test_bgp_advertise_map_peer_group_config():
147+
"""
148+
Test that advertise-map configurations show correctly in running config
149+
when a peer is part of a peer group. Tests both exist-map and non-exist-map.
150+
"""
151+
tgen = get_topogen()
152+
153+
if tgen.routers_have_failure():
154+
pytest.skip(tgen.errors)
155+
156+
r1 = tgen.gears["r1"]
157+
158+
# Create route-maps
159+
r1.vtysh_cmd(
160+
"""
161+
configure terminal
162+
route-map EXIST-MAP permit 10
163+
route-map ADV-MAP permit 10
164+
"""
165+
)
166+
167+
# First verify the peer is part of a peer group
168+
output = r1.vtysh_cmd("show bgp neighbor 192.168.252.2 json")
169+
json_output = json.loads(output)
170+
assert (
171+
"peerGroup" in json_output["192.168.252.2"]
172+
), "Peer is not part of a peer group"
173+
174+
# Test 1: Configure advertise-map with exist-map
175+
r1.vtysh_cmd(
176+
"""
177+
configure terminal
178+
router bgp 65001
179+
address-family ipv4 unicast
180+
neighbor 192.168.252.2 advertise-map ADV-MAP exist-map EXIST-MAP
181+
"""
182+
)
183+
184+
output = r1.vtysh_cmd("show running-config")
185+
exist_map_config = (
186+
"neighbor 192.168.252.2 advertise-map ADV-MAP exist-map EXIST-MAP"
187+
)
188+
189+
assert exist_map_config in output, (
190+
f"Exist-map configuration not found or incorrect in running config. "
191+
f"Expected: '{exist_map_config}'"
192+
)
193+
194+
# Test 2: Configure advertise-map with non-exist-map
195+
r1.vtysh_cmd(
196+
"""
197+
configure terminal
198+
router bgp 65001
199+
address-family ipv4 unicast
200+
neighbor 192.168.252.2 advertise-map ADV-MAP non-exist-map EXIST-MAP
201+
"""
202+
)
203+
204+
output = r1.vtysh_cmd("show running-config")
205+
non_exist_map_config = (
206+
"neighbor 192.168.252.2 advertise-map ADV-MAP non-exist-map EXIST-MAP"
207+
)
208+
209+
assert non_exist_map_config in output, (
210+
f"Non-exist-map configuration not found or incorrect in running config. "
211+
f"Expected: '{non_exist_map_config}'"
212+
)
213+
214+
logger.info("exist/non-exist-map configuration correctly shown in running config")
215+
216+
# cleanup
217+
r1.vtysh_cmd(
218+
"""
219+
configure terminal
220+
router bgp 65001
221+
address-family ipv4 unicast
222+
no neighbor 192.168.252.2 advertise-map ADV-MAP non-exist-map EXIST-MAP
223+
no route-map EXIST-MAP permit 10
224+
no route-map ADV-MAP permit 10
225+
"""
226+
)
227+
228+
146229
if __name__ == "__main__":
147230
args = ["-s"] + sys.argv[1:]
148231
sys.exit(pytest.main(args))

0 commit comments

Comments
 (0)