]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: use scope link for direct unicast routes by default
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 13 Jan 2022 12:42:28 +0000 (21:42 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 13 Jan 2022 22:46:52 +0000 (22:46 +0000)
Strictly speaking, this breaks the backward compatibility, but I guess
in most cases people already sets Scope=link for such routes.

This behavior matches with how 'ip route' command adds such route by
default.

Prompted by https://twitter.com/jplitza/status/1480500562391179270.

man/systemd.network.xml
src/network/networkd-route.c
test/test-network/conf/25-route-static.network
test/test-network/systemd-networkd-tests.py

index 197e0dad1da3d7f93cd274f3152dd5757b870a9c..93c10b775587105af32c3fe7a68732c88ac41cc5 100644 (file)
@@ -1547,9 +1547,9 @@ Table=1234</programlisting></para>
 
           <para>For IPv4 route, defaults to <literal>host</literal> if <varname>Type=</varname> is
           <literal>local</literal> or <literal>nat</literal>, and <literal>link</literal> if
-          <varname>Type=</varname> is <literal>broadcast</literal>, <literal>multicast</literal>, or
-          <literal>anycast</literal>. In other cases, defaults to <literal>global</literal>. The value
-          is not used for IPv6.</para>
+          <varname>Type=</varname> is <literal>broadcast</literal>, <literal>multicast</literal>,
+          <literal>anycast</literal>, or direct <literal>unicast</literal> routes. In other cases,
+          defaults to <literal>global</literal>. The value is not used for IPv6.</para>
         </listitem>
       </varlistentry>
 
index f0697a66af8081b26bf7745c798f7da222ded964..00e64978d45ba7ba36b21b0ec5ce91c023a4e776 100644 (file)
@@ -2846,6 +2846,12 @@ static int route_section_verify(Route *route, Network *network) {
                         route->scope = RT_SCOPE_HOST;
                 else if (IN_SET(route->type, RTN_BROADCAST, RTN_ANYCAST, RTN_MULTICAST))
                         route->scope = RT_SCOPE_LINK;
+                else if (IN_SET(route->type, RTN_UNICAST, RTN_UNSPEC) &&
+                         !route->gateway_from_dhcp_or_ra &&
+                         !in_addr_is_set(route->gw_family, &route->gw) &&
+                         ordered_set_isempty(route->multipath_routes) &&
+                         route->nexthop_id == 0)
+                        route->scope = RT_SCOPE_LINK;
         }
 
         if (route->scope != RT_SCOPE_UNIVERSE && route->family == AF_INET6) {
index 8f242bd1fe511ad9ae803e6966c34eadcb08e044..6aa3ec66dcfb56e34041d143093083bbeddf730e 100644 (file)
@@ -24,7 +24,6 @@ Gateway=fe80::222:4dff:ff:ff:ff:ff
 
 [Route]
 Destination=149.10.124.64
-Scope=link
 
 [Route]
 Gateway=149.10.124.64
index 5613398757fa31e1fd104d199083b0c8625c1f79..2207f36245a2e962246789a6654cf9fa28e8950e 100755 (executable)
@@ -2542,9 +2542,9 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         self.assertIn('149.10.124.48/28 proto kernel scope link src 149.10.124.58', output)
         self.assertIn('149.10.124.64 proto static scope link', output)
         self.assertIn('169.254.0.0/16 proto static scope link metric 2048', output)
-        self.assertIn('192.168.1.1 proto static initcwnd 20', output)
-        self.assertIn('192.168.1.2 proto static initrwnd 30', output)
-        self.assertIn('192.168.1.3 proto static advmss 30', output)
+        self.assertIn('192.168.1.1 proto static scope link initcwnd 20', output)
+        self.assertIn('192.168.1.2 proto static scope link initrwnd 30', output)
+        self.assertIn('192.168.1.3 proto static scope link advmss 30', output)
         self.assertIn('multicast 149.10.123.4 proto static', output)
 
         print('### ip -4 route show dev dummy98 default')