fix: systemd-networkd reverse route ordering

We missing a default route. Add gateway first.

This fixes https://github.com/systemd/systemd/issues/5430
This commit is contained in:
Susant Sahani 2018-11-26 22:43:17 +05:30 committed by Yu Watanabe
parent e6eed94459
commit 0d34228fc0
3 changed files with 49 additions and 9 deletions

View File

@ -860,16 +860,30 @@ static int link_enter_set_routes(Link *link) {
link_set_state(link, LINK_STATE_SETTING_ROUTES);
LIST_FOREACH(routes, rt, link->network->static_routes) {
r = route_configure(rt, link, route_handler);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set routes: %m");
link_enter_failed(link);
return r;
/* First add the default route i.e. Gateway.*/
LIST_FOREACH(routes, rt, link->network->static_routes)
if (in_addr_is_null(rt->family, &rt->gw)) {
r = route_configure(rt, link, route_handler);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set routes: %m");
link_enter_failed(link);
return r;
}
link->route_messages++;
}
link->route_messages++;
}
LIST_FOREACH(routes, rt, link->network->static_routes)
if (!in_addr_is_null(rt->family, &rt->gw)) {
r = route_configure(rt, link, route_handler);
if (r < 0) {
log_link_warning_errno(link, r, "Could not set routes: %m");
link_enter_failed(link);
return r;
}
link->route_messages++;
}
if (link->route_messages == 0) {
link->static_routes_configured = true;

View File

@ -0,0 +1,15 @@
[Match]
Name=dummy98
[Network]
LinkLocalAddressing=ipv6
Address=2001:1234:5:8f63::1/128
IPv6AcceptRA=no
[Route]
Destination=2001:1234:5:8fff:ff:ff:ff:ff/128
Scope=link
[Route]
Destination=::/0
Gateway=2001:1234:5:8fff:ff:ff:ff:ff

View File

@ -431,7 +431,7 @@ class NetworkdNetWorkTests(unittest.TestCase, Utilities):
'25-route-section.network', '25-route-type.network', '25-route-tcp-window-settings.network',
'25-route-gateway.network', '25-route-gateway-on-link.network',
'25-address-link-section.network', '25-ipv6-address-label-section.network', '25-link-section-unmanaged.network',
'25-sysctl.network']
'25-sysctl.network', '25-route-reverse-order.network']
def setUp(self):
self.link_remove(self.links)
@ -519,6 +519,17 @@ class NetworkdNetWorkTests(unittest.TestCase, Utilities):
self.assertRegex(output, 'static')
self.assertRegex(output, '192.168.0.0/24')
def test_ip_route_reverse(self):
self.copy_unit_to_networkd_unit_path('25-route-reverse-order.network', '12-dummy.netdev')
self.start_networkd()
self.assertTrue(self.link_exits('dummy98'))
output = subprocess.check_output(['ip', '-6', 'route', 'show', 'dev', 'dummy98']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, '2001:1234:5:8fff:ff:ff:ff:ff')
self.assertRegex(output, '2001:1234:5:8f63::1')
def test_ip_route_blackhole_unreachable_prohibit(self):
self.copy_unit_to_networkd_unit_path('25-route-type.network', '12-dummy.netdev')
self.start_networkd()