Skip to content

Commit

Permalink
fix: systemd-networkd reverse route ordering
Browse files Browse the repository at this point in the history
we missing a default route. Add gateway first.
This fixes systemd#5430
  • Loading branch information
ssahani committed Nov 28, 2018
1 parent 66e3834 commit 6d8937e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
29 changes: 21 additions & 8 deletions src/network/networkd-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,16 +860,29 @@ 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;
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;
Expand Down
15 changes: 15 additions & 0 deletions test/test-network/conf/25-route-reverse-order.network
Original file line number Diff line number Diff line change
@@ -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
13 changes: 12 additions & 1 deletion test/test-network/systemd-networkd-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -519,6 +519,17 @@ def test_ip_route(self):
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()
Expand Down

0 comments on commit 6d8937e

Please sign in to comment.