From: Yu Watanabe Date: Sat, 13 Jan 2024 04:49:24 +0000 (+0900) Subject: network/route-nexthop: use RTA_MULTIPATH when weight is not zero X-Git-Tag: v256-rc1~1108^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=406fde1a4d87eb43cbec0b86213bf78b02595c6b;p=thirdparty%2Fsystemd.git network/route-nexthop: use RTA_MULTIPATH when weight is not zero As we have no way to specify the weight of gateway without using RTA_MULTIPATH. --- diff --git a/src/network/networkd-route-nexthop.c b/src/network/networkd-route-nexthop.c index f58cdb36955..9f08938dfc3 100644 --- a/src/network/networkd-route-nexthop.c +++ b/src/network/networkd-route-nexthop.c @@ -384,9 +384,6 @@ static int netlink_message_append_multipath_route(Link *link, const Route *route assert(route); assert(message); - if (ordered_set_isempty(route->nexthops)) - return 0; - rta = new(struct rtattr, 1); if (!rta) return -ENOMEM; @@ -397,16 +394,23 @@ static int netlink_message_append_multipath_route(Link *link, const Route *route }; offset = (uint8_t *) RTA_DATA(rta) - (uint8_t *) rta; - RouteNextHop *nh; - ORDERED_SET_FOREACH(nh, route->nexthops) { - struct rtnexthop *rtnh; - - r = append_nexthop_one(link, route, nh, &rta, offset); + if (ordered_set_isempty(route->nexthops)) { + r = append_nexthop_one(link, route, &route->nexthop, &rta, offset); if (r < 0) return r; - rtnh = (struct rtnexthop *)((uint8_t *) rta + offset); - offset = (uint8_t *) RTNH_NEXT(rtnh) - (uint8_t *) rta; + } else { + RouteNextHop *nh; + ORDERED_SET_FOREACH(nh, route->nexthops) { + struct rtnexthop *rtnh; + + r = append_nexthop_one(link, route, nh, &rta, offset); + if (r < 0) + return r; + + rtnh = (struct rtnexthop *)((uint8_t *) rta + offset); + offset = (uint8_t *) RTNH_NEXT(rtnh) - (uint8_t *) rta; + } } return sd_netlink_message_append_data(message, RTA_MULTIPATH, RTA_DATA(rta), RTA_PAYLOAD(rta)); @@ -425,7 +429,9 @@ int route_nexthops_set_netlink_message(Link *link, const Route *route, sd_netlin if (route_type_is_reject(route)) return 0; - if (ordered_set_isempty(route->nexthops)) { + /* We request IPv6 multipath routes separatedly. Even though, if weight is non-zero, we need to use + * RTA_MULTIPATH, as we have no way to specify the weight of the nexthop. */ + if (ordered_set_isempty(route->nexthops) && route->nexthop.weight == 0) { if (in_addr_is_set(route->nexthop.family, &route->nexthop.gw)) { if (route->nexthop.family == route->family)