]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/route-nexthop: use RTA_MULTIPATH when weight is not zero
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 13 Jan 2024 04:49:24 +0000 (13:49 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 19 Jan 2024 01:13:44 +0000 (10:13 +0900)
As we have no way to specify the weight of gateway without using
RTA_MULTIPATH.

src/network/networkd-route-nexthop.c

index f58cdb36955566432ea74cf7aa3a49e6f361982c..9f08938dfc377cbe908a34f8cb0b735ebb35b2b3 100644 (file)
@@ -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)