1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-06 01:57:47 +03:00

network: route: make stored multipath route weight equivalent to hop of nexthop

This commit is contained in:
Yu Watanabe 2021-05-13 15:07:35 +09:00
parent 0557680919
commit 234106dbf9
2 changed files with 7 additions and 2 deletions

View 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)) {

View 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 0254. 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);