From 44a82da405879b1318f046dc67893934b57cbf37 Mon Sep 17 00:00:00 2001 From: anlan_cs Date: Thu, 31 Oct 2024 22:44:05 +0800 Subject: [PATCH 1/2] zebra: fix missing kernel routes The `rib_update_handle_kernel_route_down_possibility()` didn't consider the kernel routes ( blackhole ) without interface. When some other interfaces are down, these kernel routes will be wrongly removed. Signed-off-by: anlan_cs --- zebra/zebra_rib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index aea39b8ecf18..356c5428afb5 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -4549,7 +4549,7 @@ rib_update_handle_kernel_route_down_possibility(struct route_node *rn, struct interface *ifp = if_lookup_by_index(nexthop->ifindex, nexthop->vrf_id); - if (ifp && if_is_up(ifp)) { + if ((ifp && if_is_up(ifp)) || nexthop->type == NEXTHOP_TYPE_BLACKHOLE) { alive = true; break; } From 0073a870d1b769e96b4f23d0422914200591062e Mon Sep 17 00:00:00 2001 From: anlan_cs Date: Fri, 1 Nov 2024 15:16:09 +0800 Subject: [PATCH 2/2] test: add test case for kernel blackhole routes The test verifies that a kernel blackhole route is not affected by interface's link change. Signed-off-by: anlan_cs --- .../r1/ip_route_kernel_blackhole.json | 24 +++++++++++++++++++ .../test_zebra_multiple_connected.py | 21 ++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_blackhole.json diff --git a/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_blackhole.json b/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_blackhole.json new file mode 100644 index 000000000000..c8ea93037036 --- /dev/null +++ b/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel_blackhole.json @@ -0,0 +1,24 @@ +{ + "0.0.0.0/0":[ + { + "prefix":"0.0.0.0/0", + "prefixLen":0, + "protocol":"kernel", + "vrfName":"default", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "table":254, + "nexthops":[ + { + "fib":true, + "unreachable":true, + "blackhole":true, + "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 7dbeb6f1ccb3..eda8c88706a6 100644 --- a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py +++ b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py @@ -202,6 +202,27 @@ def test_zebra_kernel_route_add(): assert result, "Connected Route should have been added\n{}".format(_) +def test_zebra_kernel_route_blackhole_add(): + "Test that a blackhole route is not affected by interface's link change" + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r1"] + router.run("ip route add blackhole default") + router.run("ip link set dev r1-eth1 down") + + kernel = "{}/{}/ip_route_kernel_blackhole.json".format(CWD, router.name) + expected = json.loads(open(kernel).read()) + + test_func = partial( + topotest.router_json_cmp, router, "show ip route 0.0.0.0/0 json", expected + ) + result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1) + assert result, "Blackhole Route should have not been removed\n{}".format(_) + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args))