]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: route: make stored multipath route weight equivalent to hop of nexthop
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 13 May 2021 06:07:35 +0000 (15:07 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 21 May 2021 19:54:09 +0000 (04:54 +0900)
src/libsystemd/sd-netlink/netlink-util.c
src/network/networkd-route.c

index 90a184319a9b4d2642bb044d9290b0b863661778..78a51cf78d80c20f9920c5e6fa3bcc605a42edb3 100644 (file)
@@ -472,7 +472,7 @@ int rtattr_read_nexthop(const struct rtnexthop *rtnh, size_t size, int family, O
 
                 *m = (MultipathRoute) {
                         .ifindex = rtnh->rtnh_ifindex,
-                        .weight = rtnh->rtnh_hops == 0 ? 0 : rtnh->rtnh_hops + 1,
+                        .weight = rtnh->rtnh_hops,
                 };
 
                 if (rtnh->rtnh_len > sizeof(struct rtnexthop)) {
index a5382e42ab4d8600cf787b529e4c09fd847d0a7f..d0d0c192c00ff37e87652f743c5f18897b981deb 100644 (file)
@@ -1220,7 +1220,7 @@ static int append_nexthop_one(const Route *route, const MultipathRoute *m, struc
         *rtnh = (struct rtnexthop) {
                 .rtnh_len = sizeof(*rtnh),
                 .rtnh_ifindex = m->ifindex,
-                .rtnh_hops = m->weight > 0 ? m->weight - 1 : 0,
+                .rtnh_hops = m->weight,
         };
 
         (*rta)->rta_len += sizeof(struct rtnexthop);
@@ -2779,11 +2779,16 @@ int config_parse_multipath_route(
                                    "Invalid multipath route weight, ignoring assignment: %s", p);
                         return 0;
                 }
+                /* ip command takes weight in the range 1…255, while kernel takes the value in the
+                 * range 0…254. MultiPathRoute= setting also takes weight in the same range which ip
+                 * command uses, then networkd decreases by one and stores it to match the range which
+                 * kernel uses. */
                 if (m->weight == 0 || m->weight > 256) {
                         log_syntax(unit, LOG_WARNING, filename, line, 0,
                                    "Invalid multipath route weight, ignoring assignment: %s", p);
                         return 0;
                 }
+                m->weight--;
         }
 
         r = ordered_set_ensure_put(&n->multipath_routes, NULL, m);