summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-route-nexthop.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-01-13 05:49:24 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-01-19 02:13:44 +0100
commit406fde1a4d87eb43cbec0b86213bf78b02595c6b (patch)
tree78391961e14ee9a8f79be5eddbb9a5ada77b4a63 /src/network/networkd-route-nexthop.c
parentMeasure empty PK and KEK EFI vars (diff)
downloadsystemd-406fde1a4d87eb43cbec0b86213bf78b02595c6b.tar.xz
systemd-406fde1a4d87eb43cbec0b86213bf78b02595c6b.zip
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.
Diffstat (limited to '')
-rw-r--r--src/network/networkd-route-nexthop.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/network/networkd-route-nexthop.c b/src/network/networkd-route-nexthop.c
index f58cdb3695..9f08938dfc 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)