diff --git a/man/systemd.network.xml b/man/systemd.network.xml index e35da7bd4c..ffed2ee066 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -2008,9 +2008,11 @@ allow my_server_t localnet_peer_t:peer recv; RouteTable=num - The table identifier for DHCP routes (a number between 1 and 4294967295, or 0 to - unset). The table can be retrieved using - ip route show table num. + The table identifier for DHCP routes. Takes one of predefined names + default, main, and local, and names + defined in RouteTable= in + networkd.conf5, + or a number between 1…4294967295. When used in combination with VRF=, the VRF's routing table is used when this parameter is not specified. @@ -2502,10 +2504,14 @@ Token=prefixstable:2002:da8:1:: RouteTable=num - The table identifier for the routes received in the Router Advertisement - (a number between 1 and 4294967295, or 0 to unset). - The table can be retrieved using ip route show table num. - + The table identifier for the routes received in the Router Advertisement. Takes one of + predefined names default, main, and local, + and names defined in RouteTable= in + networkd.conf5, + or a number between 1…4294967295. + + When used in combination with VRF=, the VRF's routing table is + used when this parameter is not specified. diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c index 6526d3378f..7b0b2dea85 100644 --- a/src/network/networkd-dhcp-common.c +++ b/src/network/networkd-dhcp-common.c @@ -15,6 +15,7 @@ #include "networkd-link.h" #include "networkd-manager.h" #include "networkd-network.h" +#include "networkd-route-util.h" #include "parse-util.h" #include "socket-util.h" #include "string-table.h" @@ -529,7 +530,7 @@ int config_parse_dhcp_or_ra_route_table( assert(IN_SET(ltype, AF_INET, AF_INET6)); assert(rvalue); - r = safe_atou32(rvalue, &rt); + r = manager_get_route_table_from_string(network->manager, rvalue, &rt); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse RouteTable=%s, ignoring assignment: %m", rvalue); diff --git a/src/network/networkd-route-util.c b/src/network/networkd-route-util.c index 312f5f298a..0366382093 100644 --- a/src/network/networkd-route-util.c +++ b/src/network/networkd-route-util.c @@ -417,8 +417,8 @@ int manager_get_route_table_to_string(const Manager *m, uint32_t table, char **r assert(m); assert(ret); - if (table == 0) - return -EINVAL; + /* Unlike manager_get_route_table_from_string(), this accepts 0, as the kernel may create routes with + * table 0. See issue #25089. */ s = route_table_to_string(table); if (!s) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 514845f7c5..d1f3bab092 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -2351,7 +2351,7 @@ int config_parse_route_table( r = manager_get_route_table_from_string(network->manager, rvalue, &n->table); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, - "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue); + "Could not parse route table \"%s\", ignoring assignment: %m", rvalue); return 0; } diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 71c4360fa3..130ed5e0a7 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -1250,7 +1250,7 @@ int config_parse_routing_policy_rule_table( r = manager_get_route_table_from_string(network->manager, rvalue, &n->table); if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, - "Could not parse RPDB rule route table number \"%s\", ignoring assignment: %m", rvalue); + "Could not parse RPDB rule route table \"%s\", ignoring assignment: %m", rvalue); return 0; } diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 2f7614428c..3b559c8dec 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -2618,18 +2618,18 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): self.assertIn('anycast 149.10.123.2 proto static scope link', output) self.assertIn('broadcast 149.10.123.3 proto static scope link', output) - print('### ip route show type blackhole') - output = check_output('ip route show type blackhole') + print('### ip -4 route show type blackhole') + output = check_output('ip -4 route show type blackhole') print(output) self.assertIn('blackhole 202.54.1.2 proto static', output) - print('### ip route show type unreachable') - output = check_output('ip route show type unreachable') + print('### ip -4 route show type unreachable') + output = check_output('ip -4 route show type unreachable') print(output) self.assertIn('unreachable 202.54.1.3 proto static', output) - print('### ip route show type prohibit') - output = check_output('ip route show type prohibit') + print('### ip -4 route show type prohibit') + output = check_output('ip -4 route show type prohibit') print(output) self.assertIn('prohibit 202.54.1.4 proto static', output) @@ -2680,18 +2680,18 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): self.wait_online(['dummy98:routable']) # check all routes managed by Manager are removed - print('### ip route show type blackhole') - output = check_output('ip route show type blackhole') + print('### ip -4 route show type blackhole') + output = check_output('ip -4 route show type blackhole') print(output) self.assertEqual(output, '') - print('### ip route show type unreachable') - output = check_output('ip route show type unreachable') + print('### ip -4 route show type unreachable') + output = check_output('ip -4 route show type unreachable') print(output) self.assertEqual(output, '') - print('### ip route show type prohibit') - output = check_output('ip route show type prohibit') + print('### ip -4 route show type prohibit') + output = check_output('ip -4 route show type prohibit') print(output) self.assertEqual(output, '') @@ -2715,18 +2715,18 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): self.wait_online(['dummy98:routable']) # check all routes managed by Manager are reconfigured - print('### ip route show type blackhole') - output = check_output('ip route show type blackhole') + print('### ip -4 route show type blackhole') + output = check_output('ip -4 route show type blackhole') print(output) self.assertIn('blackhole 202.54.1.2 proto static', output) - print('### ip route show type unreachable') - output = check_output('ip route show type unreachable') + print('### ip -4 route show type unreachable') + output = check_output('ip -4 route show type unreachable') print(output) self.assertIn('unreachable 202.54.1.3 proto static', output) - print('### ip route show type prohibit') - output = check_output('ip route show type prohibit') + print('### ip -4 route show type prohibit') + output = check_output('ip -4 route show type prohibit') print(output) self.assertIn('prohibit 202.54.1.4 proto static', output) @@ -2749,18 +2749,18 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): time.sleep(2) # check all routes managed by Manager are removed - print('### ip route show type blackhole') - output = check_output('ip route show type blackhole') + print('### ip -4 route show type blackhole') + output = check_output('ip -4 route show type blackhole') print(output) self.assertEqual(output, '') - print('### ip route show type unreachable') - output = check_output('ip route show type unreachable') + print('### ip -4 route show type unreachable') + output = check_output('ip -4 route show type unreachable') print(output) self.assertEqual(output, '') - print('### ip route show type prohibit') - output = check_output('ip route show type prohibit') + print('### ip -4 route show type prohibit') + output = check_output('ip -4 route show type prohibit') print(output) self.assertEqual(output, '')