@@ -275,7 +275,8 @@ static int dhcp4_request_route_to_gateway(Link *link, const struct in_addr *gw)
275275static int dhcp4_request_route_auto (
276276 Route * in ,
277277 Link * link ,
278- const struct in_addr * gw ) {
278+ const struct in_addr * gw ,
279+ bool force_use_gw ) {
279280
280281 _cleanup_ (route_freep ) Route * route = in ;
281282 struct in_addr address , netmask , prefix ;
@@ -320,7 +321,8 @@ static int dhcp4_request_route_auto(
320321 route -> gw = IN_ADDR_NULL ;
321322 route -> prefsrc .in = address ;
322323
323- } else if (route -> dst_prefixlen >= prefixlen &&
324+ } else if (!force_use_gw &&
325+ route -> dst_prefixlen >= prefixlen &&
324326 (route -> dst .in .s_addr & netmask .s_addr ) == prefix .s_addr ) {
325327 if (in4_addr_is_set (gw ))
326328 log_link_debug (link , "DHCP: requested route destination " IPV4_ADDRESS_FMT_STR "/%u is in the assigned network "
@@ -470,7 +472,9 @@ static int dhcp4_request_static_routes(Link *link, struct in_addr *ret_default_g
470472 in4_addr_is_null (& default_gw ))
471473 default_gw = gw ;
472474
473- r = dhcp4_request_route_auto (TAKE_PTR (route ), link , & gw );
475+ /* Do not ignore the gateway given by the classless route option even if the destination is
476+ * in the same network. See issue #28280. */
477+ r = dhcp4_request_route_auto (TAKE_PTR (route ), link , & gw , /* force_use_gw = */ n_classless_routes > 0 );
474478 if (r < 0 )
475479 return r ;
476480 }
@@ -606,7 +610,7 @@ static int dhcp4_request_routes_to_servers(
606610 route -> dst .in = servers [i ];
607611 route -> dst_prefixlen = 32 ;
608612
609- r = dhcp4_request_route_auto (TAKE_PTR (route ), link , gw );
613+ r = dhcp4_request_route_auto (TAKE_PTR (route ), link , gw , /* force_use_gw = */ false );
610614 if (r < 0 )
611615 return r ;
612616 }
0 commit comments