]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/nexthop: do not remove depending nexthops when a nexthop is removed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 11 Nov 2024 04:51:49 +0000 (13:51 +0900)
committerLuca Boccassi <bluca@debian.org>
Mon, 11 Nov 2024 13:59:41 +0000 (13:59 +0000)
Previously, when a nexthop is removed, depending nexthops were removed, but
that's not necessary, as the kernel keeps them, at least with v6.11.

src/network/networkd-nexthop.c
test/test-network/systemd-networkd-tests.py

index e0fa4745ea7f00bfcfcd45793714562fe40411ef..76f2371bd8e6f6fea55c0944738fa85c0dd8f339 100644 (file)
@@ -491,19 +491,9 @@ static int nexthop_remove_dependents(NextHop *nexthop, Manager *manager) {
         assert(nexthop);
         assert(manager);
 
-        /* If a nexthop is removed, the kernel silently removes nexthops and routes that depend on the
-         * removed nexthop. Let's remove them for safety (though, they are already removed in the kernel,
-         * hence that should fail), and forget them. */
-
-        void *id;
-        SET_FOREACH(id, nexthop->nexthops) {
-                NextHop *nh;
-
-                if (nexthop_get_by_id(manager, PTR_TO_UINT32(id), &nh) < 0)
-                        continue;
-
-                RET_GATHER(r, nexthop_remove(nh, manager));
-        }
+        /* If a nexthop is removed, the kernel silently removes routes that depend on the removed nexthop.
+         * Let's remove them for safety (though, they are already removed in the kernel, hence that should
+         * fail), and forget them. */
 
         Route *route;
         SET_FOREACH(route, nexthop->routes)
index 111da949abe443118f197d0d09691d3530023099..6b19a8a9388455826dc13633f8c94aeff9fbf8f8 100755 (executable)
@@ -4798,11 +4798,18 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
 
         # Remove nexthop with ID 20
         check_output('ip nexthop del id 20')
+
+        # Check the nexthop ID 20 is dropped from the group nexthop.
+        output = check_output('ip -0 nexthop list id 21')
+        print(output)
+        self.assertRegex(output, r'id 21 group 1,3')
+
+        # Remove nexthop with ID 21
+        check_output('ip nexthop del id 21')
         copy_network_unit('11-dummy.netdev', '25-nexthop-test1.network')
         networkctl_reload()
 
-        # 25-nexthop-test1.network requests a route with nexthop ID 21,
-        # which is silently removed by the kernel when nexthop with ID 20 is removed in the above,
+        # 25-nexthop-test1.network requests a route with nexthop ID 21, which is removed in the above,
         # hence test1 should be stuck in the configuring state.
         self.wait_operstate('test1', operstate='routable', setup_state='configuring')
 
@@ -4811,7 +4818,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         output = networkctl_status('test1')
         self.assertIn('State: routable (configuring)', output)
 
-        # Check if the route which needs nexthop 20 and 21 are forgotten.
+        # Check if the route which needs nexthop 21 are forgotten.
         output = networkctl_json()
         check_json(output)
         self.assertNotIn('"Destination":[10.10.10.14]', output)