]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: do not remove static routes on other interfaces that are currently in the...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 15 Mar 2025 00:38:09 +0000 (09:38 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 8 Apr 2025 19:52:11 +0000 (20:52 +0100)
Otherwise, even if .network file has KeepConfiguration=yes, routes on
an interfaces may be removed on restart.

Fixes a bug introduced by 8d01e44c1f0e00b414d36bd1b46ecff548242208.

(cherry picked from commit cf28def391d1cc06c9757d2413cd7a31b38f59e1)
(cherry picked from commit 48b2ca96cee9e0c5ae9e61f634a6281c6fdfa550)

src/network/networkd-route.c

index 5c364a24b83f2d7603ddf8d53c6c775a5538733f..6998d215c31ce6b34c06c6068bb576b7d3ca89e2 100644 (file)
@@ -1392,15 +1392,22 @@ static int link_mark_routes(Link *link, bool foreign) {
                                 continue;
                 }
 
-                /* When we mark foreign routes, do not mark routes assigned to other interfaces.
-                 * Otherwise, routes assigned to unmanaged interfaces will be dropped.
-                 * Note, route_get_link() does not provide assigned link for routes with an unreachable type
-                 * or IPv4 multipath routes. So, the current implementation does not support managing such
-                 * routes by other daemon or so, unless ManageForeignRoutes=no. */
-                if (foreign) {
-                        Link *route_link;
+                Link *route_link = NULL;
+                if (route_get_link(link->manager, route, &route_link) >= 0 && route_link != link) {
+                        /* When we also mark foreign routes, do not mark routes assigned to other interfaces.
+                         * Otherwise, routes assigned to unmanaged interfaces will be dropped.
+                         * Note, route_get_link() does not provide assigned link for routes with an
+                         * unreachable type or IPv4 multipath routes. So, the current implementation does not
+                         * support managing such routes by other daemon or so, unless ManageForeignRoutes=no. */
+                        if (foreign)
+                                continue;
 
-                        if (route_get_link(link->manager, route, &route_link) >= 0 && route_link != link)
+                        /* When we mark only static routes, do not mark routes assigned to links that we do
+                         * not know the assignment of .network files to the interfaces. Otherwise, if an
+                         * interface is in the pending state, even if the .network file to be assigned to the
+                         * interface has KeepConfiguration=yes, routes on the interface will be removed.
+                         * This is especially important when systemd-networkd is restarted. */
+                        if (!IN_SET(route_link->state, LINK_STATE_UNMANAGED, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
                                 continue;
                 }