From: Yu Watanabe Date: Sun, 26 Jan 2025 21:16:24 +0000 (+0900) Subject: network/dhcp4: make dhcp4_request_route_to_gateway() take Route object X-Git-Tag: v258-rc1~1419^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9ee0d2eebab8fc4f692bf37484690af83bf1a20;p=thirdparty%2Fsystemd.git network/dhcp4: make dhcp4_request_route_to_gateway() take Route object No functional change, preparation for later commits. --- diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 0dfb1737e8e..b42d2ffce02 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -438,14 +438,19 @@ static int dhcp4_request_prefix_route(Link *link) { return dhcp4_request_route(route, link); } -static int dhcp4_request_route_to_gateway(Link *link, const struct in_addr *gw) { +static int dhcp4_request_route_to_gateway(Link *link, const Route *rt) { _cleanup_(route_unrefp) Route *route = NULL; struct in_addr address; int r; assert(link); assert(link->dhcp_lease); - assert(gw); + assert(rt); + + if (in_addr_is_set(rt->nexthop.family, &rt->nexthop.gw) <= 0) + return 0; + + assert(rt->nexthop.family == AF_INET); r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); if (r < 0) @@ -455,7 +460,7 @@ static int dhcp4_request_route_to_gateway(Link *link, const struct in_addr *gw) if (r < 0) return r; - route->dst.in = *gw; + route->dst.in = rt->nexthop.gw.in; route->dst_prefixlen = 32; route->prefsrc.in = address; route->scope = RT_SCOPE_LINK; @@ -526,14 +531,14 @@ static int dhcp4_request_route_auto( route->prefsrc.in = address; } else { - r = dhcp4_request_route_to_gateway(link, gw); - if (r < 0) - return r; - route->scope = RT_SCOPE_UNIVERSE; route->nexthop.family = AF_INET; route->nexthop.gw.in = *gw; route->prefsrc.in = address; + + r = dhcp4_request_route_to_gateway(link, route); + if (r < 0) + return r; } return dhcp4_request_route(route, link); @@ -613,12 +618,6 @@ static int dhcp4_request_default_gateway(Link *link) { if (r < 0) return r; - /* The dhcp netmask may mask out the gateway. First, add an explicit route for the gateway host - * so that we can route no matter the netmask or existing kernel route tables. */ - r = dhcp4_request_route_to_gateway(link, &router); - if (r < 0) - return r; - r = route_new(&route); if (r < 0) return r; @@ -628,6 +627,12 @@ static int dhcp4_request_default_gateway(Link *link) { route->nexthop.gw.in = router; route->prefsrc.in = address; + /* The dhcp netmask may mask out the gateway. First, add an explicit route for the gateway host + * so that we can route no matter the netmask or existing kernel route tables. */ + r = dhcp4_request_route_to_gateway(link, route); + if (r < 0) + return r; + return dhcp4_request_route(route, link); } @@ -664,16 +669,16 @@ static int dhcp4_request_semi_static_routes(Link *link) { continue; } - r = dhcp4_request_route_to_gateway(link, &gw); - if (r < 0) - return r; - r = route_dup(rt, NULL, &route); if (r < 0) return r; route->nexthop.gw.in = gw; + r = dhcp4_request_route_to_gateway(link, route); + if (r < 0) + return r; + r = dhcp4_request_route(route, link); if (r < 0) return r;