1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-08 05:57:26 +03:00

network/dhcp4: do not ignore the gateway even if the destination is in the same network

Fixes #28280.

(cherry picked from commit 77451f654a89d822cd288883edfac315949d1cb6)
This commit is contained in:
Yu Watanabe 2023-07-07 06:31:04 +09:00 committed by Luca Boccassi
parent f9a8c8299c
commit 234b51fb73

View File

@ -278,7 +278,8 @@ static int dhcp4_request_route_to_gateway(Link *link, const struct in_addr *gw)
static int dhcp4_request_route_auto(
Route *in,
Link *link,
const struct in_addr *gw) {
const struct in_addr *gw,
bool force_use_gw) {
_cleanup_(route_freep) Route *route = in;
struct in_addr address, netmask, prefix;
@ -323,7 +324,8 @@ static int dhcp4_request_route_auto(
route->gw = IN_ADDR_NULL;
route->prefsrc.in = address;
} else if (route->dst_prefixlen >= prefixlen &&
} else if (!force_use_gw &&
route->dst_prefixlen >= prefixlen &&
(route->dst.in.s_addr & netmask.s_addr) == prefix.s_addr) {
if (in4_addr_is_set(gw))
log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is in the assigned network "
@ -473,7 +475,9 @@ static int dhcp4_request_static_routes(Link *link, struct in_addr *ret_default_g
in4_addr_is_null(&default_gw))
default_gw = gw;
r = dhcp4_request_route_auto(TAKE_PTR(route), link, &gw);
/* Do not ignore the gateway given by the classless route option even if the destination is
* in the same network. See issue #28280. */
r = dhcp4_request_route_auto(TAKE_PTR(route), link, &gw, /* force_use_gw = */ n_classless_routes > 0);
if (r < 0)
return r;
}
@ -609,7 +613,7 @@ static int dhcp4_request_routes_to_servers(
route->dst.in = servers[i];
route->dst_prefixlen = 32;
r = dhcp4_request_route_auto(TAKE_PTR(route), link, gw);
r = dhcp4_request_route_auto(TAKE_PTR(route), link, gw, /* force_use_gw = */ false);
if (r < 0)
return r;
}