From: Yu Watanabe Date: Thu, 13 May 2021 06:07:35 +0000 (+0900) Subject: network: route: make stored multipath route weight equivalent to hop of nexthop X-Git-Tag: v249-rc1~176^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=234106dbf989fa766612116f325283c087bf25f0;p=thirdparty%2Fsystemd.git network: route: make stored multipath route weight equivalent to hop of nexthop --- diff --git a/src/libsystemd/sd-netlink/netlink-util.c b/src/libsystemd/sd-netlink/netlink-util.c index 90a184319a9..78a51cf78d8 100644 --- a/src/libsystemd/sd-netlink/netlink-util.c +++ b/src/libsystemd/sd-netlink/netlink-util.c @@ -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)) { diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index a5382e42ab4..d0d0c192c00 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -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);