diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index b8610b3786..a8582ec6f8 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -1282,9 +1282,10 @@ IPv6Token=prefixstable:2002:da8:1::
Gateway=
- Takes the gateway address or special value _dhcp. If
- _dhcp, then the gateway address provided by DHCP (or in the IPv6 case,
- provided by IPv6 RA) is used.
+ Takes the gateway address or the special values _dhcp4 and
+ _dhcp6. If _dhcp4 or _dhcp6 is
+ set, then the gateway address provided by DHCP (or in the IPv6 case, provided by IPv6 RA)
+ is used.
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index 31a009b088..12a344049f 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -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)