Skip to content

Commit 44c4743

Browse files
authored
Merge pull request FRRouting#18378 from Tuetuopay/fix-route-map-gateway-ip
bgpd: fix `set evpn gateway-ip ipv[46]` route-map
2 parents efa761d + 7320659 commit 44c4743

File tree

7 files changed

+169
-2
lines changed

7 files changed

+169
-2
lines changed

bgpd/bgp_route.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5186,7 +5186,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
51865186
* attr->evpn_overlay with evpn directly. Instead memcpy
51875187
* evpn to new_atr.evpn_overlay before it is interned.
51885188
*/
5189-
if (soft_reconfig && evpn && afi == AFI_L2VPN) {
5189+
if (evpn && afi == AFI_L2VPN &&
5190+
(soft_reconfig || !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))) {
51905191
bgp_attr_set_evpn_overlay(&new_attr, evpn);
51915192
p_evpn = NULL;
51925193
}

bgpd/bgp_routemap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ route_set_evpn_gateway_ip(void *rule, const struct prefix *prefix, void *object)
14411441

14421442
/* Set gateway-ip value. */
14431443
bre->type = OVERLAY_INDEX_GATEWAY_IP;
1444-
memcpy(&bre->gw_ip, &gw_ip->ip.addr, IPADDRSZ(gw_ip));
1444+
bre->gw_ip = *gw_ip;
14451445
bgp_attr_set_evpn_overlay(path->attr, bre);
14461446

14471447
return RMAP_OKAY;

tests/topotests/bgp_evpn_route_map_set/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
int lo
2+
ip address 10.10.10.10/32
3+
!
4+
int c1-eth0
5+
ip address 10.0.0.1/31
6+
!
7+
router bgp 65000
8+
no bgp ebgp-requires-policy
9+
no bgp network import-check
10+
!
11+
neighbor 10.0.0.0 remote-as external
12+
neighbor 10.0.0.0 timers 1 3
13+
neighbor 10.0.0.0 timers connect 1
14+
!
15+
address-family ipv4 unicast
16+
neighbor 10.0.0.0 activate
17+
redistribute connected route-map allow-lo
18+
exit-address-family
19+
!
20+
route-map allow-lo permit 10
21+
match interface lo
22+
!
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
! This router advertises as EVPN type-5 routes those received in a plain
2+
! ipv4 unicast session
3+
!
4+
vni 10
5+
!
6+
int r1-eth0
7+
ip address 10.0.0.0/31
8+
!
9+
int r1-eth1
10+
ip address 10.0.0.2/31
11+
!
12+
router bgp 64000
13+
no bgp ebgp-requires-policy
14+
no bgp network import-check
15+
!
16+
neighbor 10.0.0.1 remote-as external
17+
neighbor 10.0.0.1 timers 1 3
18+
neighbor 10.0.0.1 timers connect 1
19+
!
20+
address-family ipv4 unicast
21+
neighbor 10.0.0.1 activate
22+
!
23+
neighbor 10.0.0.3 remote-as internal
24+
neighbor 10.0.0.3 timers 1 3
25+
neighbor 10.0.0.3 timers connect 1
26+
!
27+
address-family l2vpn evpn
28+
neighbor 10.0.0.3 activate
29+
neighbor 10.0.0.3 route-map set-gw-ip out
30+
!
31+
advertise-all-vni
32+
!
33+
advertise ipv4 unicast
34+
exit-address-family
35+
!
36+
route-map set-gw-ip permit 10
37+
set evpn gateway-ip ipv4 10.10.10.10
38+
!
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
vni 10
2+
!
3+
int r2-eth0
4+
ip address 10.0.0.3/31
5+
!
6+
router bgp 64000
7+
no bgp default ipv4-unicast
8+
!
9+
neighbor 10.0.0.2 remote-as internal
10+
neighbor 10.0.0.2 timers 1 3
11+
neighbor 10.0.0.2 timers connect 1
12+
!
13+
address-family l2vpn evpn
14+
neighbor 10.0.0.2 activate
15+
!
16+
advertise-all-vni
17+
exit-address-family
18+
!
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python
2+
# SPDX-License-Identifier: GPL-2.0-or-later
3+
4+
# Copyright (c) 2025 Tuetuopay <[email protected]>
5+
6+
"""
7+
Test if route-map set for EVPN fields works.
8+
"""
9+
10+
import os
11+
import sys
12+
import json
13+
import pytest
14+
import functools
15+
16+
pytestmark = [pytest.mark.bgpd]
17+
18+
CWD = os.path.dirname(os.path.realpath(__file__))
19+
sys.path.append(os.path.join(CWD, "../"))
20+
21+
# pylint: disable=C0413
22+
from lib import topotest
23+
from lib.topogen import TopoRouter, Topogen, get_topogen
24+
from lib.topolog import logger
25+
26+
def setup_module(mod):
27+
topodef = {"s1": ("c1", "r1"), "s2": ("r1", "r2")}
28+
tgen = Topogen(topodef, mod.__name__)
29+
tgen.start_topology()
30+
31+
tgen.net["r1"].cmd(
32+
"""
33+
ip link add br10 up type bridge
34+
ip link add vxlan10 up master br10 type vxlan id 10 dstport 4789 local 10.0.0.2 nolearning
35+
"""
36+
)
37+
tgen.net["r2"].cmd(
38+
"""
39+
ip link add br10 up type bridge
40+
ip link add vxlan10 up master br10 type vxlan id 10 dstport 4789 local 10.0.0.3 nolearning
41+
"""
42+
)
43+
44+
for name, router in tgen.routers().items():
45+
router.load_frr_config(os.path.join(CWD, f"{name}/frr.conf"))
46+
47+
tgen.start_router()
48+
49+
50+
def teardown_module(mod):
51+
get_topogen().stop_topology()
52+
53+
54+
def test_bgp_evpn_route_map_set_gateway_ip():
55+
tgen: Topogen = get_topogen()
56+
57+
if tgen.routers_have_failure():
58+
pytest.skip(tgen.errors)
59+
60+
r2: TopoRouter = tgen.gears["r2"]
61+
def _bgp_converge():
62+
output = json.loads(r2.vtysh_cmd("show bgp l2vpn evpn all overlay json"))
63+
expected = {
64+
"10.0.0.2:1": {
65+
"[5]:[0]:[32]:[10.10.10.10]": {
66+
"paths": [
67+
{
68+
"valid": True,
69+
"overlay": {
70+
"gw": "10.10.10.10",
71+
},
72+
},
73+
],
74+
},
75+
},
76+
"numPrefix": 1,
77+
}
78+
return topotest.json_cmp(output, expected)
79+
80+
logger.info("Check route type-5 gateway-ip")
81+
test_func = functools.partial(_bgp_converge)
82+
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
83+
assert result is None, "EVPN Route with gateway-ip should be advertised"
84+
85+
86+
if __name__ == "__main__":
87+
args = ["-s"] + sys.argv[1:]
88+
sys.exit(pytest.main(args))

0 commit comments

Comments
 (0)