diff --git a/tests/sys/net/routing/test_routing_l3.py b/tests/sys/net/routing/test_routing_l3.py --- a/tests/sys/net/routing/test_routing_l3.py +++ b/tests/sys/net/routing/test_routing_l3.py @@ -86,6 +86,47 @@ nh = [nh for nh in nhops if nh["index"] == nhop_kidx][0] assert nh["ifa"] == str(second_addr.ip) + @pytest.mark.parametrize("family", ["inet", "inet6"]) + @pytest.mark.require_user("root") + def test_add_address_same_prefix_present(self, family): + """ + Tests adding an interface prefix route when a route with the same + prefix is already present in the routing table + """ + vnet = self.vnet_map["vnet1"] + first_iface = vnet.iface_alias_map["if1"] + + if family == "inet": + first_addr = ipaddress.ip_interface("192.0.2.1/24") + else: + first_addr = ipaddress.ip_interface("2001:db8::1/64") + + # Add a route pointing to the loopback interface + ToolsHelper.print_output( + f"route add -net -{family} {first_addr.network} -interface lo0" + ) + + # Verify the route points to the loopback interface + routes = ToolsHelper.get_routes(family) + px = [ + r for r in routes if r["destination"] == str(first_addr.network) + ][0] + assert px["interface-name"] == "lo0" + + # Add an address to the first interface with the same prefix as the + # route, and verify switchover + first_iface.setup_addr(str(first_addr)) + + routes = ToolsHelper.get_routes(family) + px = [ + r for r in routes if r["destination"] == str(first_addr.network) + ][0] + nhop_kidx = px["nhop"] + assert px["interface-name"] == first_iface.name + nhops = ToolsHelper.get_nhops(family) + nh = [nh for nh in nhops if nh["index"] == nhop_kidx][0] + assert nh["ifa"] == str(first_addr.ip) + class TestRouteCornerCase1(SingleVnetTestTemplate): @pytest.mark.parametrize("family", ["inet", "inet6"])