]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/route: fix adjustment of nexthop weight 34213/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 1 Sep 2024 02:52:12 +0000 (11:52 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 1 Sep 2024 02:54:32 +0000 (11:54 +0900)
Fixes #34167.

src/network/networkd-route.c

index 788b2cb04ff6bddfc40ab002ff943c6ec4649422..271d49850270c187ee9a5a8687714a129c98f4da 100644 (file)
@@ -1104,9 +1104,15 @@ static int process_route_one(
                         route = route_ref(tmp);
                         is_new = true;
 
-                } else
+                } else {
                         /* Update remembered route with the received notification. */
-                        route->nexthop.weight = tmp->nexthop.weight;
+
+                        /* Here, update weight only when a non-zero weight is received. As the kernel does
+                         * not provide the weight of a single-path route. In such case, tmp->nexthop.weight
+                         * is zero, hence we should not overwrite the known weight of the route. */
+                        if (tmp->nexthop.weight != 0)
+                                route->nexthop.weight = tmp->nexthop.weight;
+                }
 
                 /* Also update information that cannot be obtained through netlink notification. */
                 if (req && req->waiting_reply) {
@@ -1116,6 +1122,14 @@ static int process_route_one(
                                 link_enter_failed(link);
                                 return 0;
                         }
+
+                        /* We configure IPv6 multipath route separatedly. When the first path is configured,
+                         * the kernel does not provide the weight of the path. So, we need to adjust it here.
+                         * Hopefully, the weight is assigned correctly. */
+                        if (route->nexthop.weight == 0) {
+                                Route *rt = ASSERT_PTR(req->userdata);
+                                route->nexthop.weight = rt->nexthop.weight;
+                        }
                 }
 
                 route_enter_configured(route);