Skip to content

Commit

Permalink
state_diff: filter out loopback host scoped route
Browse files Browse the repository at this point in the history
When the loopback interface is managed with Netplan, filter out the
following route from the list:

local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1
  • Loading branch information
daniloegea committed Feb 6, 2024
1 parent f4cd601 commit 0a3daeb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion netplan_cli/cli/state_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
8 changes: 5 additions & 3 deletions tests/cli/test_state_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0a3daeb

Please sign in to comment.