]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce Gateway=_dhcp4 and _dhcp6, and deprecate "_dhcp"
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 Oct 2020 11:34:00 +0000 (13:34 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 Oct 2020 17:51:23 +0000 (02:51 +0900)
Fixes #17249.

man/systemd.network.xml
src/network/networkd-route.c

index b8610b3786c86e8a058438725e3b99d768c1069f..a8582ec6f8057383e94e5ffa7899e06a6d6bd326 100644 (file)
@@ -1282,9 +1282,10 @@ IPv6Token=prefixstable:2002:da8:1::</programlisting></para>
         <varlistentry>
           <term><varname>Gateway=</varname></term>
           <listitem>
-            <para>Takes the gateway address or special value <literal>_dhcp</literal>. If
-            <literal>_dhcp</literal>, then the gateway address provided by DHCP (or in the IPv6 case,
-            provided by IPv6 RA) is used.</para>
+            <para>Takes the gateway address or the special values <literal>_dhcp4</literal> and
+            <literal>_dhcp6</literal>. If <literal>_dhcp4</literal> or <literal>_dhcp6</literal> is
+            set, then the gateway address provided by DHCP (or in the IPv6 case, provided by IPv6 RA)
+            is used.</para>
           </listitem>
         </varlistentry>
          <varlistentry>
index 31a009b088f8ff3f2548ab088caa0adc0c7b8d4d..12a344049f0ecf9f3483ee663dee5153d69da64d 100644 (file)
@@ -1725,6 +1725,20 @@ int config_parse_gateway(
                         TAKE_PTR(n);
                         return 0;
                 }
+
+                if (streq(rvalue, "_dhcp4")) {
+                        n->gw_family = AF_INET;
+                        n->gateway_from_dhcp = true;
+                        TAKE_PTR(n);
+                        return 0;
+                }
+
+                if (streq(rvalue, "_dhcp6")) {
+                        n->gw_family = AF_INET6;
+                        n->gateway_from_dhcp = true;
+                        TAKE_PTR(n);
+                        return 0;
+                }
         }
 
         r = in_addr_from_string_auto(rvalue, &n->gw_family, &n->gw);
@@ -1734,6 +1748,7 @@ int config_parse_gateway(
                 return 0;
         }
 
+        n->gateway_from_dhcp = false;
         TAKE_PTR(n);
         return 0;
 }
@@ -2361,11 +2376,19 @@ static int route_section_verify(Route *route, Network *network) {
         if (route->family == AF_UNSPEC) {
                 assert(route->section);
 
-                return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
-                                         "%s: Route section without Gateway=, Destination=, Source=, "
-                                         "or PreferredSource= field configured. "
-                                         "Ignoring [Route] section from line %u.",
-                                         route->section->filename, route->section->line);
+                if (route->gateway_from_dhcp) {
+                        log_warning("%s: Deprecated value \"_dhcp\" is specified for Gateway= in [Route] section from line %u. "
+                                    "Please use \"_dhcp4\" or \"_dhcp6\" instead. Assuming \"_dhcp4\".",
+                                    route->section->filename, route->section->line);
+
+                        route->family = AF_INET;
+                        route->gw_family = AF_INET;
+                } else
+                        return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                 "%s: Route section without Gateway=, Destination=, Source=, "
+                                                 "or PreferredSource= field configured. "
+                                                 "Ignoring [Route] section from line %u.",
+                                                 route->section->filename, route->section->line);
         }
 
         if (route->family == AF_INET6 && route->gw_family == AF_INET)