From: Yu Watanabe Date: Wed, 7 Oct 2020 11:34:00 +0000 (+0200) Subject: network: introduce Gateway=_dhcp4 and _dhcp6, and deprecate "_dhcp" X-Git-Tag: v247-rc1~110^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d306d1d0ca2e6559a598a6eb459f65f9377f909e;p=thirdparty%2Fsystemd.git network: introduce Gateway=_dhcp4 and _dhcp6, and deprecate "_dhcp" Fixes #17249. --- diff --git a/man/systemd.network.xml b/man/systemd.network.xml index b8610b3786c..a8582ec6f80 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 31a009b088f..12a344049f0 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)