diff --git a/netplan_cli/cli/state_diff.py b/netplan_cli/cli/state_diff.py index 092ee05e9..28644a1f1 100644 --- a/netplan_cli/cli/state_diff.py +++ b/netplan_cli/cli/state_diff.py @@ -441,7 +441,8 @@ def _filter_system_routes(self, system_routes: AbstractSet[NetplanRoute], system if route.to != 'default' and ipaddress.ip_interface(route.to).is_link_local: continue # Filter out host scoped routes - if route.scope == 'host' and route.type == 'local' and route.to in addresses: + if (route.scope == 'host' and route.type == 'local' and + (route.to in addresses or ipaddress.ip_interface(route.to).is_loopback)): continue # Filter out the default IPv6 multicast route if route.family == 10 and route.type == 'multicast' and route.to == 'ff00::/8': diff --git a/tests/cli/test_state_diff.py b/tests/cli/test_state_diff.py index 8205564fa..b2e9522d0 100644 --- a/tests/cli/test_state_diff.py +++ b/tests/cli/test_state_diff.py @@ -987,9 +987,11 @@ def test__filter_system_routes_dhcp_ra_routes(self): self.assertSetEqual(filtered, set()) def test__filter_system_routes_link_local_routes(self): - route = NetplanRoute(scope='host', type='local', to='1.2.3.4', from_addr='1.2.3.4') - system_addresses = ['1.2.3.4/24'] - filtered = self.diff_state._filter_system_routes({route}, system_addresses) + route1 = NetplanRoute(scope='host', type='local', to='1.2.3.4', from_addr='1.2.3.4') + # local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1 + route2 = NetplanRoute(scope='host', type='local', to='127.0.0.0/8', from_addr='127.0.0.1') + system_addresses = ['1.2.3.4/24', '127.0.0.1/8'] + filtered = self.diff_state._filter_system_routes({route1, route2}, system_addresses) self.assertSetEqual(filtered, set()) def test__filter_system_routes_link_local_routes_with_multiple_ips_same_subnet(self):