Skip to content

Commit 73803c7

Browse files
yuwatabluca
authored andcommitted
network/dhcp4: do not ignore the gateway even if the destination is in the same network
Fixes #28280. (cherry picked from commit 77451f6) (cherry picked from commit 234b51f) (cherry picked from commit 2ed8067)
1 parent b49a97b commit 73803c7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/network/networkd-dhcp4.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ static int dhcp4_request_route_to_gateway(Link *link, const struct in_addr *gw)
317317
static int dhcp4_request_route_auto(
318318
Route *in,
319319
Link *link,
320-
const struct in_addr *gw) {
320+
const struct in_addr *gw,
321+
bool force_use_gw) {
321322

322323
_cleanup_(route_freep) Route *route = in;
323324
struct in_addr address, netmask, prefix;
@@ -362,7 +363,8 @@ static int dhcp4_request_route_auto(
362363
route->gw = IN_ADDR_NULL;
363364
route->prefsrc.in = address;
364365

365-
} else if (route->dst_prefixlen >= prefixlen &&
366+
} else if (!force_use_gw &&
367+
route->dst_prefixlen >= prefixlen &&
366368
(route->dst.in.s_addr & netmask.s_addr) == prefix.s_addr) {
367369
if (in4_addr_is_set(gw))
368370
log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is in the assigned network "
@@ -512,7 +514,9 @@ static int dhcp4_request_static_routes(Link *link, struct in_addr *ret_default_g
512514
in4_addr_is_null(&default_gw))
513515
default_gw = gw;
514516

515-
r = dhcp4_request_route_auto(TAKE_PTR(route), link, &gw);
517+
/* Do not ignore the gateway given by the classless route option even if the destination is
518+
* in the same network. See issue #28280. */
519+
r = dhcp4_request_route_auto(TAKE_PTR(route), link, &gw, /* force_use_gw = */ n_classless_routes > 0);
516520
if (r < 0)
517521
return r;
518522
}
@@ -648,7 +652,7 @@ static int dhcp4_request_routes_to_servers(
648652
route->dst.in = servers[i];
649653
route->dst_prefixlen = 32;
650654

651-
r = dhcp4_request_route_auto(TAKE_PTR(route), link, gw);
655+
r = dhcp4_request_route_auto(TAKE_PTR(route), link, gw, /* force_use_gw = */ false);
652656
if (r < 0)
653657
return r;
654658
}

0 commit comments

Comments
 (0)