Skip to content

Commit 07daa3e

Browse files
committed
bgpd, topotests: fix validate imported routes only in 'import vrf' cases
The bgp_vpnv4_gre test validates imported routes as ok when route-map is detached. Whereas, The nexthop of MPLS paths must either be a labelled nexthop or point to a GRE interface (by using route-map). The case where this check does not matter is when local importation is performed by using the 'import vrf' command. Fix this by applying the automatic validation only when this command is used to import VPN paths. Enforce the current topotest by really checking the invalidity of the path. Apply black style to modified topotest. Fixes: bgpd: ("Validate imported routes next-hop that is in a default VRF") Signed-off-by: Philippe Guibert <[email protected]>
1 parent 872ed46 commit 07daa3e

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

bgpd/bgp_nht.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,19 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, afi_
480480
path_nh_map(pi, bnc, true);
481481

482482
bpi_ultimate = bgp_get_imported_bpi_ultimate(pi);
483+
if (bpi_ultimate != pi && safi == SAFI_UNICAST &&
484+
(CHECK_FLAG(bgp_route->af_flags[afi][SAFI_UNICAST],
485+
BGP_CONFIG_VRF_TO_VRF_IMPORT) ||
486+
CHECK_FLAG(bgp_route->af_flags[afi][SAFI_UNICAST],
487+
BGP_CONFIG_VRF_TO_VRF_EXPORT)))
488+
/* import does not require any valid MPLS label */
489+
SET_FLAG(bnc->flags, BGP_NEXTHOP_ULTIMATE);
490+
483491
if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID) && bnc->metric)
484492
(bgp_path_info_extra_get(bpi_ultimate))->igpmetric =
485493
bnc->metric;
486494
else if (bpi_ultimate->extra)
487495
bpi_ultimate->extra->igpmetric = 0;
488-
489-
SET_FLAG(bnc->flags, BGP_NEXTHOP_ULTIMATE);
490496
} else if (peer) {
491497
/*
492498
* Let's not accidentally save the peer data for a peer

tests/topotests/bgp_vpnv4_gre/test_bgp_vpnv4_gre.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#
1010

1111
"""
12-
test_bgp_vpnv4_gre.py: Test the FRR BGP daemon with BGP IPv6 interface
13-
with route advertisements on a separate netns.
12+
test_bgp_vpnv4_gre.py: Test the FRR BGP daemon with BGP IPv6 interface
13+
with route advertisements on a separate netns.
1414
"""
1515

1616
import os
@@ -27,6 +27,7 @@
2727
# Import topogen and topotest helpers
2828
from lib import topotest
2929
from lib.topogen import Topogen, TopoRouter, get_topogen
30+
from lib.common_config import retry
3031
from lib.topolog import logger
3132

3233
# Required to instantiate the topology builder class.
@@ -106,6 +107,19 @@ def teardown_module(_mod):
106107
tgen.stop_topology()
107108

108109

110+
@retry(retry_timeout=10)
111+
def _check_show_bgp_mpls_not_selected(router, vrf, ipv4prefix):
112+
valid = True
113+
output = json.loads(router.vtysh_cmd(f"show bgp vrf {vrf} ipv4 {ipv4prefix} json"))
114+
paths = output["paths"]
115+
for path in paths:
116+
if "remoteLabel" in path.keys():
117+
valid = path.get("valid", False)
118+
if not valid:
119+
return True
120+
return f"MPLS path to {prefix} in vrf {vrf} not found or considered as valid"
121+
122+
109123
def test_protocols_convergence():
110124
"""
111125
Assert that all protocols have converged
@@ -148,7 +162,7 @@ def test_protocols_convergence():
148162
assertmsg = '"{}" JSON output mismatches'.format(router.name)
149163
assert result is None, assertmsg
150164

151-
# Check BGP IPv4 routing tables on r2 not installed
165+
# Check BGP IPv4 convergence on r2
152166
logger.info("Checking BGP IPv4 routes for convergence on r2")
153167
router = tgen.gears["r2"]
154168
json_file = "{}/{}/bgp_ipv4_routes.json".format(CWD, router.name)
@@ -166,6 +180,13 @@ def test_protocols_convergence():
166180
assertmsg = '"{}" JSON output mismatches'.format(router.name)
167181
assert result is None, assertmsg
168182

183+
# Check BGP IPv4 route 10.201.0.0/24 on r2 not installed
184+
logger.info("Checking BGP IPv4 route 10.201.0.0/24 for invalidity on r2")
185+
success = _check_show_bgp_mpls_not_selected(
186+
tgen.gears["r2"], "vrf1", "10.201.0.0/24"
187+
)
188+
assert success is True, "network 10.201.0.0/24 invalid for MPLS: not found on r2"
189+
169190

170191
def test_memory_leak():
171192
"Run the memory leak test and report results."

0 commit comments

Comments
 (0)