From c9e4abf81f32deb752fb55d8b1e3a9a7cdd9af31 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 9 Apr 2022 13:12:28 -0400 Subject: [PATCH 1/2] zebra: Allow system routes to recurse through themselves Currently if a end user has something like this: Routing entry for 192.168.212.1/32 Known via "kernel", distance 0, metric 100, best Last update 00:07:50 ago * directly connected, ens5 Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR, f - OpenFabric, > - selected route, * - FIB route, q - queued, r - rejected, b - backup t - trapped, o - offload failure K>* 0.0.0.0/0 [0/100] via 192.168.212.1, ens5, src 192.168.212.19, 00:00:15 C>* 192.168.212.0/27 is directly connected, ens5, 00:07:50 K>* 192.168.212.1/32 [0/100] is directly connected, ens5, 00:07:50 And FRR does a link flap, it refigures the route and rejects the default route: 2022/04/09 16:38:20 ZEBRA: [NZNZ4-7P54Y] default(0:254):0.0.0.0/0: Processing rn 0x56224dbb5b00 2022/04/09 16:38:20 ZEBRA: [ZJVZ4-XEGPF] default(0:254):0.0.0.0/0: Examine re 0x56224dbddc20 (kernel) status: Changed Installed flags: Selected dist 0 metric 100 2022/04/09 16:38:20 ZEBRA: [GG8QH-195KE] nexthop_active_update: re 0x56224dbddc20 nhe 0x56224dbdd950 (7), curr_nhe 0x56224dedb550 2022/04/09 16:38:20 ZEBRA: [T9JWA-N8HM5] nexthop_active_check: re 0x56224dbddc20, nexthop 192.168.212.1, via ens5 2022/04/09 16:38:20 ZEBRA: [M7EN1-55BTH] nexthop_active: Route Type kernel has not turned on recursion 2022/04/09 16:38:20 ZEBRA: [HJ48M-MB610] nexthop_active_check: Unable to find active nexthop 2022/04/09 16:38:20 ZEBRA: [JPJF4-TGCY5] default(0:254):0.0.0.0/0: After processing: old_selected 0x56224dbddc20 new_selected 0x0 old_fib 0x56224dbddc20 new_fib 0x0 So the 192.168.212.1 route is matched for the nexthop but it is not connected and zebra treats it as a problem. Modify the code such that if a system route matches through another system route, then it should work imo. Signed-off-by: Donald Sharp --- zebra/zebra_nhg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 02894632ea..d1a34d0962 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -2265,7 +2265,8 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, continue; } - if (match->type == ZEBRA_ROUTE_CONNECT) { + if ((match->type == ZEBRA_ROUTE_CONNECT) || + (RIB_SYSTEM_ROUTE(match) && RSYSTEM_ROUTE(type))) { match = zebra_nhg_connected_ifindex(rn, match, nexthop->ifindex); From efcd39d87b778dd944a155444fc86a7f590be0c9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 9 Apr 2022 13:44:17 -0400 Subject: [PATCH 2/2] tests: Add a test case for a kernel route depending on a kernel route Add a test case where a kernel route depends on a kernel route and when you perturb an interface, ensure that FRR does not loose the route. Signed-off-by: Donald Sharp --- .../r1/ip_route2.json | 102 ++++++++++++++++++ .../test_zebra_multiple_connected.py | 24 +++++ 2 files changed, 126 insertions(+) create mode 100644 tests/topotests/zebra_multiple_connected/r1/ip_route2.json diff --git a/tests/topotests/zebra_multiple_connected/r1/ip_route2.json b/tests/topotests/zebra_multiple_connected/r1/ip_route2.json new file mode 100644 index 0000000000..26995654f7 --- /dev/null +++ b/tests/topotests/zebra_multiple_connected/r1/ip_route2.json @@ -0,0 +1,102 @@ +{ + "10.0.1.0/24":[ + { + "prefix":"10.0.1.0/24", + "prefixLen":24, + "protocol":"connected", + "vrfName":"default", + "distance":0, + "metric":0, + "installed":true, + "table":254, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r1-eth1", + "active":true + } + ] + }, + { + "prefix":"10.0.1.0/24", + "prefixLen":24, + "protocol":"connected", + "vrfName":"default", + "distance":0, + "metric":0, + "installed":true, + "table":254, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "10.0.1.30/32":[ + { + "prefix":"10.0.1.30/32", + "prefixLen":32, + "protocol":"kernel", + "vrfName":"default", + "distance":0, + "metric":0, + "installed":true, + "table":254, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r1-eth1", + "active":true + } + ] + } + ], + "10.9.9.0/24":[ + { + "prefix":"10.9.9.0/24", + "prefixLen":24, + "protocol":"kernel", + "vrfName":"default", + "distance":0, + "metric":0, + "installed":true, + "table":254, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.30", + "afi":"ipv4", + "interfaceName":"r1-eth1", + "active":true + } + ] + } + ], + "192.168.1.1/32":[ + { + "prefix":"192.168.1.1/32", + "prefixLen":32, + "protocol":"kernel", + "vrfName":"default", + "distance":0, + "metric":0, + "installed":true, + "table":254, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.99", + "afi":"ipv4", + "interfaceName":"r1-eth1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py index 31ac831b35..8882cf5bda 100644 --- a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py +++ b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py @@ -133,6 +133,30 @@ def test_zebra_connected_multiple(): assert result is None, "Kernel route is missing from zebra" +def test_zebra_system_recursion(): + "Test a system route recursing through another system route" + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r1"] + router.run("ip route add 10.0.1.30/32 dev r1-eth1") + router.run("ip route add 10.9.9.0/24 via 10.0.1.30 dev r1-eth1") + router.run("ip link add dummy2 type dummy") + router.run("ip link set dummy2 up") + router.run("ip link set dummy2 down") + + routes = "{}/{}/ip_route2.json".format(CWD, router.name) + expected = json.loads(open(routes).read()) + test_func = partial( + topotest.router_json_cmp, router, "show ip route json", expected + ) + + _, result = topotest.run_and_expect(test_func, None, count=20, wait=1) + assert result is None, "Kernel route is missing from zebra" + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args))