]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/nexthop: drop dependent nexthops on removal
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 15 Jan 2024 04:14:46 +0000 (13:14 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 16 Jan 2024 03:48:50 +0000 (12:48 +0900)
If a nexthop is removed, dependent nexthops are silently removed by the
kernel. Hence, networkd may be confused that nexthops that depends on the
nexthop still exist, and may fail to configure other routes or so.

src/network/networkd-nexthop.c

index 49856c483a707ec04c3ddeb6f599353cfabff17f..cf62e0e82dc666450a42faf5bf2d87ec4c1bc980 100644 (file)
@@ -482,6 +482,29 @@ static void log_nexthop_debug(const NextHop *nexthop, const char *str, Manager *
                        yes_no(nexthop->blackhole), strna(group), strna(flags));
 }
 
+static int nexthop_remove_dependents(NextHop *nexthop, Manager *manager) {
+        int r = 0;
+
+        assert(nexthop);
+        assert(manager);
+
+        /* If a nexthop is removed, the kernel silently removes nexthops 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));
+        }
+
+        return r;
+}
+
 static int nexthop_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, RemoveRequest *rreq) {
         int r;
 
@@ -497,6 +520,8 @@ static int nexthop_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Remov
                                        (r == -ENOENT || !nexthop->manager) ? LOG_DEBUG : LOG_WARNING,
                                        r, "Could not drop nexthop, ignoring");
 
+                (void) nexthop_remove_dependents(nexthop, manager);
+
                 if (nexthop->manager) {
                         /* If the nexthop cannot be removed, then assume the nexthop is already removed. */
                         log_nexthop_debug(nexthop, "Forgetting", manager);
@@ -1014,6 +1039,7 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
                 if (nexthop) {
                         nexthop_enter_removed(nexthop);
                         log_nexthop_debug(nexthop, "Forgetting removed", m);
+                        (void) nexthop_remove_dependents(nexthop, m);
                         nexthop_detach(nexthop);
                 } else
                         log_nexthop_debug(&(const NextHop) { .id = id }, "Kernel removed unknown", m);