]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/nexthop: also remove nexthop on cancelling request
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 2 Jan 2024 19:40:44 +0000 (04:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 5 Jan 2024 10:17:59 +0000 (19:17 +0900)
Otherwise, the nexthop may arrive after we call
link_drop_foreign_address() or so on reconfiguring interface.

src/network/networkd-link.c
src/network/networkd-nexthop.c
src/network/networkd-nexthop.h

index 69f6a0ce726e6e4b027229c17500dd1ed3189c76..5f84b5af9aba089549759cc3949a26d4798673d0 100644 (file)
@@ -961,6 +961,13 @@ static int link_drop_requests(Link *link) {
                                         RET_GATHER(ret, neighbor_remove(neighbor, link));
                                 break;
                         }
+                        case REQUEST_TYPE_NEXTHOP: {
+                                NextHop *nexthop = ASSERT_PTR(req->userdata);
+
+                                if (nexthop_get_by_id(link->manager, nexthop->id, NULL) < 0)
+                                        RET_GATHER(ret, nexthop_remove(nexthop, link->manager));
+                                break;
+                        }
                         default:
                                 ;
                         }
index 1ab56a8ffdb79e8f43db748a52f99eefb1428818..148417d2c67e004ebfda49b64b1c12e59766d34b 100644 (file)
@@ -424,17 +424,14 @@ static int nexthop_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link
         return 1;
 }
 
-static int nexthop_remove(NextHop *nexthop) {
+int nexthop_remove(NextHop *nexthop, Manager *manager) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
-        Manager *manager;
         Link *link = NULL;
-        Request *req;
         int r;
 
         assert(nexthop);
         assert(nexthop->id > 0);
-
-        manager = ASSERT_PTR(nexthop->manager);
+        assert(manager);
 
         /* link may be NULL. */
         (void) link_get_by_index(manager, nexthop->ifindex, &link);
@@ -457,9 +454,6 @@ static int nexthop_remove(NextHop *nexthop) {
         link_ref(link); /* link may be NULL, link_ref() is OK with that */
 
         nexthop_enter_removing(nexthop);
-        if (nexthop_get_request_by_id(manager, nexthop->id, &req) >= 0)
-                nexthop_enter_removing(req->userdata);
-
         return 0;
 }
 
@@ -780,7 +774,7 @@ int link_drop_nexthops(Link *link, bool foreign) {
                 if (!nexthop_is_marked(nexthop))
                         continue;
 
-                RET_GATHER(r, nexthop_remove(nexthop));
+                RET_GATHER(r, nexthop_remove(nexthop, link->manager));
         }
 
         return r;
index 564b52532fa72fb7aff3a75b14f420f256bc5e20..142538ff579f2a25d4eed2d4db91595d4635f3ba 100644 (file)
@@ -37,6 +37,8 @@ typedef struct NextHop {
 
 NextHop *nexthop_free(NextHop *nexthop);
 
+int nexthop_remove(NextHop *nexthop, Manager *manager);
+
 int network_drop_invalid_nexthops(Network *network);
 
 int link_drop_nexthops(Link *link, bool foreign);