static int dhcp4_request_route_auto(
Route *in,
Link *link,
- const struct in_addr *gw,
- bool force_use_gw) {
+ const struct in_addr *gw) {
_cleanup_(route_freep) Route *route = in;
- struct in_addr address, prefix;
- uint8_t prefixlen;
+ struct in_addr address;
int r;
assert(route);
if (r < 0)
return r;
- r = sd_dhcp_lease_get_prefix(link->dhcp_lease, &prefix, &prefixlen);
- if (r < 0)
- return r;
-
if (in4_addr_is_localhost(&route->dst.in)) {
if (in4_addr_is_set(gw))
log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is localhost, "
route->gw = IN_ADDR_NULL;
route->prefsrc.in = address;
- } else if (!force_use_gw &&
- dhcp4_prefix_covers(link, &route->dst.in, route->dst_prefixlen) > 0) {
- if (in4_addr_is_set(gw))
- log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is in the assigned network "
- IPV4_ADDRESS_FMT_STR"/%u, ignoring gateway address "IPV4_ADDRESS_FMT_STR,
- IPV4_ADDRESS_FMT_VAL(route->dst.in), route->dst_prefixlen,
- IPV4_ADDRESS_FMT_VAL(prefix), prefixlen,
- IPV4_ADDRESS_FMT_VAL(*gw));
+ } else if (in4_addr_is_null(gw)) {
+ r = dhcp4_prefix_covers(link, &route->dst.in, route->dst_prefixlen);
+ if (r < 0)
+ return r;
+ if (r == 0 && DEBUG_LOGGING) {
+ struct in_addr prefix;
+ uint8_t prefixlen;
- route->scope = RT_SCOPE_LINK;
- route->gw_family = AF_UNSPEC;
- route->gw = IN_ADDR_NULL;
- route->prefsrc.in = address;
+ r = sd_dhcp_lease_get_prefix(link->dhcp_lease, &prefix, &prefixlen);
+ if (r < 0)
+ return r;
- } else if (in4_addr_is_null(gw)) {
- log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is not in the assigned network "
- IPV4_ADDRESS_FMT_STR"/%u, but no gateway is specified, using 'link' scope.",
- IPV4_ADDRESS_FMT_VAL(route->dst.in), route->dst_prefixlen,
- IPV4_ADDRESS_FMT_VAL(prefix), prefixlen);
+ log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is not in the assigned network "
+ IPV4_ADDRESS_FMT_STR"/%u, but no gateway is specified, using 'link' scope.",
+ IPV4_ADDRESS_FMT_VAL(route->dst.in), route->dst_prefixlen,
+ IPV4_ADDRESS_FMT_VAL(prefix), prefixlen);
+ }
route->scope = RT_SCOPE_LINK;
route->gw_family = AF_UNSPEC;
in4_addr_is_null(&default_gw))
default_gw = 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 = */ is_classless);
+ r = dhcp4_request_route_auto(TAKE_PTR(route), link, &gw);
if (r < 0)
return r;
}
route->dst.in = *dst;
route->dst_prefixlen = 32;
- r = dhcp4_request_route_auto(TAKE_PTR(route), link, &gw, /* force_use_gw = */ false);
+ r = dhcp4_request_route_auto(TAKE_PTR(route), link, &gw);
if (r < 0)
return r;
}
additional_options = [
'--dhcp-option=option:dns-server,192.168.5.10,8.8.8.8',
'--dhcp-option=option:ntp-server,192.168.5.11,9.9.9.9',
- '--dhcp-option=option:static-route,192.168.5.100,192.168.5.2,8.8.8.8,192.168.5.3'
+ '--dhcp-option=option:static-route,192.168.6.100,192.168.5.2,8.8.8.8,192.168.5.3'
]
if classless:
additional_options += [
self.assertRegex(output, r'192.168.5.4 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
self.assertRegex(output, r'192.168.5.5 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
else:
- self.assertRegex(output, r'192.168.5.0/24 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
+ self.assertRegex(output, r'192.168.6.0/24 via 192.168.5.2 proto dhcp src 192.168.5.[0-9]* metric 1024')
self.assertRegex(output, r'8.0.0.0/8 via 192.168.5.3 proto dhcp src 192.168.5.[0-9]* metric 1024')
+ self.assertRegex(output, r'192.168.5.2 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
self.assertRegex(output, r'192.168.5.3 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
else:
self.assertNotRegex(output, r'default via 192.168.5.4 proto dhcp src 192.168.5.[0-9]* metric 1024')
self.assertNotRegex(output, r'8.0.0.0/8 via 192.168.5.5 proto dhcp src 192.168.5.[0-9]* metric 1024')
self.assertNotRegex(output, r'192.168.5.4 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
self.assertNotRegex(output, r'192.168.5.5 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
- self.assertNotRegex(output, r'192.168.5.0/24 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
+ self.assertNotRegex(output, r'192.168.6.0/24 via 192.168.5.2 proto dhcp src 192.168.5.[0-9]* metric 1024')
self.assertNotRegex(output, r'8.0.0.0/8 via 192.168.5.3 proto dhcp src 192.168.5.[0-9]* metric 1024')
+ self.assertNotRegex(output, r'192.168.5.2 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
self.assertNotRegex(output, r'192.168.5.3 proto dhcp scope link src 192.168.5.[0-9]* metric 1024')
# Check UseGateway=