@@ -278,7 +278,8 @@ static int dhcp4_request_route_to_gateway(Link *link, const struct in_addr *gw)
278278static int dhcp4_request_route_auto (
279279 Route * in ,
280280 Link * link ,
281- const struct in_addr * gw ) {
281+ const struct in_addr * gw ,
282+ bool force_use_gw ) {
282283
283284 _cleanup_ (route_freep ) Route * route = in ;
284285 struct in_addr address , netmask , prefix ;
@@ -323,7 +324,8 @@ static int dhcp4_request_route_auto(
323324 route -> gw = IN_ADDR_NULL ;
324325 route -> prefsrc .in = address ;
325326
326- } else if (route -> dst_prefixlen >= prefixlen &&
327+ } else if (!force_use_gw &&
328+ route -> dst_prefixlen >= prefixlen &&
327329 (route -> dst .in .s_addr & netmask .s_addr ) == prefix .s_addr ) {
328330 if (in4_addr_is_set (gw ))
329331 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
473475 in4_addr_is_null (& default_gw ))
474476 default_gw = gw ;
475477
476- r = dhcp4_request_route_auto (TAKE_PTR (route ), link , & gw );
478+ /* Do not ignore the gateway given by the classless route option even if the destination is
479+ * in the same network. See issue #28280. */
480+ r = dhcp4_request_route_auto (TAKE_PTR (route ), link , & gw , /* force_use_gw = */ n_classless_routes > 0 );
477481 if (r < 0 )
478482 return r ;
479483 }
@@ -609,7 +613,7 @@ static int dhcp4_request_routes_to_servers(
609613 route -> dst .in = servers [i ];
610614 route -> dst_prefixlen = 32 ;
611615
612- r = dhcp4_request_route_auto (TAKE_PTR (route ), link , gw );
616+ r = dhcp4_request_route_auto (TAKE_PTR (route ), link , gw , /* force_use_gw = */ false );
613617 if (r < 0 )
614618 return r ;
615619 }
0 commit comments