networkd: Routes should take the gateway into account

Otherwise, changing the default gateway doesn't purge old gateway routes
left on the system during daemon restart. This also fixes removing other
foreign gateway routes that don't match the expected configuration.

Tested:
    Changed gateway addresses prior to the patch and they lingered on
    the system during each reconfiguration. Applied this patch and
    reconfigured gateways and other routes multiple times and it removed
    the foreign routes that had gateways that didn't match.

Signed-off-by: William A. Kennington III <william@wkennington.com>
This commit is contained in:
William A. Kennington III
2019-08-07 20:32:36 +09:00
committed by Yu Watanabe
parent 9f4f7fe3b5
commit 0b1cd3e25a
8 changed files with 62 additions and 17 deletions
@@ -0,0 +1,6 @@
[Match]
Name=dummy98
[Network]
Address=149.10.124.58/28
Gateway=149.10.124.60
@@ -0,0 +1,6 @@
[Match]
Name=dummy98
[Network]
Address=149.10.124.58/28
Gateway=149.10.124.59
@@ -1430,6 +1430,8 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
'25-link-section-unmanaged.network',
'25-route-ipv6-src.network',
'25-route-static.network',
'25-gateway-static.network',
'25-gateway-next-static.network',
'25-sysctl-disable-ipv6.network',
'25-sysctl.network',
'configure-without-carrier.network',
@@ -1632,6 +1634,26 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
print(output)
self.assertRegex(output, 'prohibit 202.54.1.4 proto static')
def test_gateway_reconfigure(self):
copy_unit_to_networkd_unit_path('25-gateway-static.network', '12-dummy.netdev')
start_networkd()
self.wait_online(['dummy98:routable'])
print('### ip -4 route show dev dummy98 default')
output = check_output('ip -4 route show dev dummy98 default')
print(output)
self.assertRegex(output, 'default via 149.10.124.59 proto static')
self.assertNotRegex(output, '149.10.124.60')
remove_unit_from_networkd_path(['25-gateway-static.network'])
copy_unit_to_networkd_unit_path('25-gateway-next-static.network')
restart_networkd(3)
self.wait_online(['dummy98:routable'])
print('### ip -4 route show dev dummy98 default')
output = check_output('ip -4 route show dev dummy98 default')
print(output)
self.assertNotRegex(output, '149.10.124.59')
self.assertRegex(output, 'default via 149.10.124.60 proto static')
def test_ip_route_ipv6_src_route(self):
# a dummy device does not make the addresses go through tentative state, so we
# reuse a bond from an earlier test, which does make the addresses go through