diff options
-rw-r--r-- | src/core/loopback-setup.c | 6 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-internal.h | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/sd-netlink.c | 57 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/test-netlink.c | 8 | ||||
-rw-r--r-- | src/network/netdev/bridge.c | 2 | ||||
-rw-r--r-- | src/network/netdev/geneve.c | 2 | ||||
-rw-r--r-- | src/network/netdev/netdev.c | 6 | ||||
-rw-r--r-- | src/network/networkd-address-label.c | 2 | ||||
-rw-r--r-- | src/network/networkd-address.c | 4 | ||||
-rw-r--r-- | src/network/networkd-brvlan.c | 2 | ||||
-rw-r--r-- | src/network/networkd-fdb.c | 2 | ||||
-rw-r--r-- | src/network/networkd-ipv6-proxy-ndp.c | 2 | ||||
-rw-r--r-- | src/network/networkd-link.c | 19 | ||||
-rw-r--r-- | src/network/networkd-route.c | 4 | ||||
-rw-r--r-- | src/network/networkd-routing-policy-rule.c | 4 | ||||
-rw-r--r-- | src/systemd/sd-netlink.h | 8 |
16 files changed, 75 insertions, 54 deletions
diff --git a/src/core/loopback-setup.c b/src/core/loopback-setup.c index 835553ec8f..9380d1b09d 100644 --- a/src/core/loopback-setup.c +++ b/src/core/loopback-setup.c @@ -53,7 +53,7 @@ static int start_loopback(sd_netlink *rtnl, struct state *s) { if (r < 0) return r; - r = sd_netlink_call_async(rtnl, req, generic_handler, s, LOOPBACK_SETUP_TIMEOUT_USEC, NULL); + r = sd_netlink_call_async(rtnl, req, generic_handler, NULL, s, LOOPBACK_SETUP_TIMEOUT_USEC, NULL); if (r < 0) return r; @@ -88,7 +88,7 @@ static int add_ipv4_address(sd_netlink *rtnl, struct state *s) { if (r < 0) return r; - r = sd_netlink_call_async(rtnl, req, generic_handler, s, USEC_INFINITY, NULL); + r = sd_netlink_call_async(rtnl, req, generic_handler, NULL, s, USEC_INFINITY, NULL); if (r < 0) return r; @@ -123,7 +123,7 @@ static int add_ipv6_address(sd_netlink *rtnl, struct state *s) { if (r < 0) return r; - r = sd_netlink_call_async(rtnl, req, generic_handler, s, USEC_INFINITY, NULL); + r = sd_netlink_call_async(rtnl, req, generic_handler, NULL, s, USEC_INFINITY, NULL); if (r < 0) return r; diff --git a/src/libsystemd/sd-netlink/netlink-internal.h b/src/libsystemd/sd-netlink/netlink-internal.h index 661323e05f..8b56d34220 100644 --- a/src/libsystemd/sd-netlink/netlink-internal.h +++ b/src/libsystemd/sd-netlink/netlink-internal.h @@ -23,6 +23,7 @@ struct reply_callback { usec_t timeout; uint64_t serial; unsigned prioq_idx; + sd_netlink_destroy_t destroy_callback; }; struct match_callback { diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c index da5c0b0c3d..6c8740097d 100644 --- a/src/libsystemd/sd-netlink/sd-netlink.c +++ b/src/libsystemd/sd-netlink/sd-netlink.c @@ -148,6 +148,7 @@ int sd_netlink_inc_rcvbuf(sd_netlink *rtnl, size_t size) { } static sd_netlink *netlink_free(sd_netlink *rtnl) { + struct reply_callback *c; struct match_callback *f; unsigned i; @@ -163,7 +164,12 @@ static sd_netlink *netlink_free(sd_netlink *rtnl) { free(rtnl->rbuffer); - hashmap_free_free(rtnl->reply_callbacks); + while ((c = hashmap_steal_first(rtnl->reply_callbacks))) { + if (c->destroy_callback) + c->destroy_callback(c->userdata); + free(c); + } + hashmap_free(rtnl->reply_callbacks); prioq_free(rtnl->reply_callbacks_prioq); sd_event_source_unref(rtnl->io_event_source); @@ -299,6 +305,9 @@ static int process_timeout(sd_netlink *rtnl) { if (r < 0) log_debug_errno(r, "sd-netlink: timedout callback failed: %m"); + if (c->destroy_callback) + c->destroy_callback(c->userdata); + free(c); return 1; @@ -332,6 +341,9 @@ static int process_reply(sd_netlink *rtnl, sd_netlink_message *m) { if (r < 0) log_debug_errno(r, "sd-netlink: callback failed: %m"); + if (c->destroy_callback) + c->destroy_callback(c->userdata); + return 1; } @@ -494,13 +506,15 @@ static int timeout_compare(const void *a, const void *b) { return CMP(x->timeout, y->timeout); } -int sd_netlink_call_async(sd_netlink *nl, - sd_netlink_message *m, - sd_netlink_message_handler_t callback, - void *userdata, - uint64_t usec, - uint32_t *serial) { - struct reply_callback *c; +int sd_netlink_call_async( + sd_netlink *nl, + sd_netlink_message *m, + sd_netlink_message_handler_t callback, + sd_netlink_destroy_t destroy_callback, + void *userdata, + uint64_t usec, + uint32_t *serial) { + _cleanup_free_ struct reply_callback *c = NULL; uint32_t s; int r, k; @@ -519,33 +533,31 @@ int sd_netlink_call_async(sd_netlink *nl, return r; } - c = new0(struct reply_callback, 1); + c = new(struct reply_callback, 1); if (!c) return -ENOMEM; - c->callback = callback; - c->userdata = userdata; - c->timeout = calc_elapse(usec); + *c = (struct reply_callback) { + .callback = callback, + .userdata = userdata, + .timeout = calc_elapse(usec), + .destroy_callback = destroy_callback, + }; k = sd_netlink_send(nl, m, &s); - if (k < 0) { - free(c); + if (k < 0) return k; - } c->serial = s; r = hashmap_put(nl->reply_callbacks, &c->serial, c); - if (r < 0) { - free(c); + if (r < 0) return r; - } if (c->timeout != 0) { r = prioq_put(nl->reply_callbacks_prioq, c, &c->prioq_idx); if (r < 0) { - c->timeout = 0; - sd_netlink_call_async_cancel(nl, c->serial); + (void) hashmap_remove(nl->reply_callbacks, &c->serial); return r; } } @@ -553,6 +565,8 @@ int sd_netlink_call_async(sd_netlink *nl, if (serial) *serial = s; + TAKE_PTR(c); + return k; } @@ -571,6 +585,9 @@ int sd_netlink_call_async_cancel(sd_netlink *nl, uint32_t serial) { if (c->timeout != 0) prioq_remove(nl->reply_callbacks_prioq, c, &c->prioq_idx); + if (c->destroy_callback) + c->destroy_callback(c->userdata); + free(c); return 1; } diff --git a/src/libsystemd/sd-netlink/test-netlink.c b/src/libsystemd/sd-netlink/test-netlink.c index 03773fb936..b0686873c1 100644 --- a/src/libsystemd/sd-netlink/test-netlink.c +++ b/src/libsystemd/sd-netlink/test-netlink.c @@ -199,7 +199,7 @@ static void test_event_loop(int ifindex) { assert_se(sd_netlink_open(&rtnl) >= 0); assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0); - assert_se(sd_netlink_call_async(rtnl, m, link_handler, ifname, 0, NULL) >= 0); + assert_se(sd_netlink_call_async(rtnl, m, link_handler, NULL, ifname, 0, NULL) >= 0); assert_se(sd_event_default(&event) >= 0); @@ -240,7 +240,7 @@ static void test_async(int ifindex) { assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0); - assert_se(sd_netlink_call_async(rtnl, m, link_handler, ifname, 0, &serial) >= 0); + assert_se(sd_netlink_call_async(rtnl, m, link_handler, NULL, ifname, 0, &serial) >= 0); assert_se(sd_netlink_wait(rtnl, 0) >= 0); assert_se(sd_netlink_process(rtnl, &r) >= 0); @@ -259,10 +259,10 @@ static void test_pipe(int ifindex) { assert_se(sd_rtnl_message_new_link(rtnl, &m2, RTM_GETLINK, ifindex) >= 0); counter++; - assert_se(sd_netlink_call_async(rtnl, m1, pipe_handler, &counter, 0, NULL) >= 0); + assert_se(sd_netlink_call_async(rtnl, m1, pipe_handler, NULL, &counter, 0, NULL) >= 0); counter++; - assert_se(sd_netlink_call_async(rtnl, m2, pipe_handler, &counter, 0, NULL) >= 0); + assert_se(sd_netlink_call_async(rtnl, m2, pipe_handler, NULL, &counter, 0, NULL) >= 0); while (counter > 0) { assert_se(sd_netlink_wait(rtnl, 0) >= 0); diff --git a/src/network/netdev/bridge.c b/src/network/netdev/bridge.c index be5914a2fa..3ff7189ca7 100644 --- a/src/network/netdev/bridge.c +++ b/src/network/netdev/bridge.c @@ -129,7 +129,7 @@ static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_mess if (r < 0) return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); - r = sd_netlink_call_async(netdev->manager->rtnl, req, netdev_bridge_set_handler, netdev, 0, NULL); + r = sd_netlink_call_async(netdev->manager->rtnl, req, netdev_bridge_set_handler, NULL, netdev, 0, NULL); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); diff --git a/src/network/netdev/geneve.c b/src/network/netdev/geneve.c index 18b6b359f3..ff43f94bd2 100644 --- a/src/network/netdev/geneve.c +++ b/src/network/netdev/geneve.c @@ -135,7 +135,7 @@ static int netdev_geneve_create(NetDev *netdev) { if (r < 0) return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m"); - r = sd_netlink_call_async(netdev->manager->rtnl, m, geneve_netdev_create_handler, netdev, 0, NULL); + r = sd_netlink_call_async(netdev->manager->rtnl, m, geneve_netdev_create_handler, NULL, netdev, 0, NULL); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 72c9db7d07..77cbdd0e86 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -229,7 +229,7 @@ static int netdev_enslave_ready(NetDev *netdev, Link* link, sd_netlink_message_h if (r < 0) return log_netdev_error_errno(netdev, r, "Could not append IFLA_MASTER attribute: %m"); - r = sd_netlink_call_async(netdev->manager->rtnl, req, callback, link, 0, NULL); + r = sd_netlink_call_async(netdev->manager->rtnl, req, callback, NULL, link, 0, NULL); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); @@ -537,13 +537,13 @@ static int netdev_create(NetDev *netdev, Link *link, return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m"); if (link) { - r = sd_netlink_call_async(netdev->manager->rtnl, m, callback, link, 0, NULL); + r = sd_netlink_call_async(netdev->manager->rtnl, m, callback, NULL, link, 0, NULL); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); link_ref(link); } else { - r = sd_netlink_call_async(netdev->manager->rtnl, m, netdev_create_handler, netdev, 0, NULL); + r = sd_netlink_call_async(netdev->manager->rtnl, m, netdev_create_handler, NULL, netdev, 0, NULL); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m"); diff --git a/src/network/networkd-address-label.c b/src/network/networkd-address-label.c index 4c55442739..92b2c58f6b 100644 --- a/src/network/networkd-address-label.c +++ b/src/network/networkd-address-label.c @@ -112,7 +112,7 @@ int address_label_configure( if (r < 0) return log_error_errno(r, "Could not append IFA_ADDRESS attribute: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, callback, NULL, link, 0, NULL); if (r < 0) return log_error_errno(r, "Could not send rtnetlink message: %m"); diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index b07196b6b9..45e02c76da 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -453,7 +453,7 @@ int address_remove( if (r < 0) return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, callback, NULL, link, 0, NULL); if (r < 0) return log_error_errno(r, "Could not send rtnetlink message: %m"); @@ -631,7 +631,7 @@ int address_configure( if (r < 0) return r; - r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, callback, NULL, link, 0, NULL); if (r < 0) { address_release(address); return log_error_errno(r, "Could not send rtnetlink message: %m"); diff --git a/src/network/networkd-brvlan.c b/src/network/networkd-brvlan.c index 8e8a618e21..fe418b4768 100644 --- a/src/network/networkd-brvlan.c +++ b/src/network/networkd-brvlan.c @@ -195,7 +195,7 @@ int br_vlan_configure(Link *link, uint16_t pvid, uint32_t *br_vid_bitmap, uint32 return log_link_error_errno(link, r, "Could not close IFLA_AF_SPEC container: %m"); /* send message to the kernel */ - r = sd_netlink_call_async(rtnl, req, set_brvlan_handler, link, 0, NULL); + r = sd_netlink_call_async(rtnl, req, set_brvlan_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); diff --git a/src/network/networkd-fdb.c b/src/network/networkd-fdb.c index 11f70723a9..32fcf82bbd 100644 --- a/src/network/networkd-fdb.c +++ b/src/network/networkd-fdb.c @@ -134,7 +134,7 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) { } /* send message to the kernel to update its internal static MAC table. */ - r = sd_netlink_call_async(rtnl, req, set_fdb_handler, link, 0, NULL); + r = sd_netlink_call_async(rtnl, req, set_fdb_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); diff --git a/src/network/networkd-ipv6-proxy-ndp.c b/src/network/networkd-ipv6-proxy-ndp.c index d5d8b62f5a..7e1c7d6d2e 100644 --- a/src/network/networkd-ipv6-proxy-ndp.c +++ b/src/network/networkd-ipv6-proxy-ndp.c @@ -173,7 +173,7 @@ int ipv6_proxy_ndp_address_configure(Link *link, IPv6ProxyNDPAddress *ipv6_proxy if (r < 0) return rtnl_log_create_error(r); - r = sd_netlink_call_async(rtnl, req, set_ipv6_proxy_ndp_address_handler, link, 0, NULL); + r = sd_netlink_call_async(rtnl, req, set_ipv6_proxy_ndp_address_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index d7f8ad3040..f74308b5ec 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1327,7 +1327,7 @@ int link_set_mtu(Link *link, uint32_t mtu) { if (r < 0) return log_link_error_errno(link, r, "Could not append MTU: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, set_mtu_handler, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, set_mtu_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); @@ -1398,7 +1398,7 @@ static int link_set_flags(Link *link) { if (r < 0) return log_link_error_errno(link, r, "Could not set link flags: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, set_flags_handler, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, set_flags_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); @@ -1473,7 +1473,7 @@ static int link_set_bridge(Link *link) { if (r < 0) return log_link_error_errno(link, r, "Could not append IFLA_LINKINFO attribute: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, link_set_handler, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, link_set_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); @@ -1525,7 +1525,7 @@ static int link_bond_set(Link *link) { if (r < 0) return log_link_error_errno(link, r, "Could not append IFLA_INFO_DATA attribute: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, set_flags_handler, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, set_flags_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); @@ -1818,7 +1818,7 @@ int link_up(Link *link) { if (r < 0) return log_link_error_errno(link, r, "Could not close IFLA_AF_SPEC container: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, link_up_handler, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, link_up_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); @@ -1843,7 +1843,7 @@ static int link_up_can(Link *link) { if (r < 0) return log_link_error_errno(link, r, "Could not set link flags: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, link_up_handler, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, link_up_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); @@ -1932,7 +1932,7 @@ static int link_set_can(Link *link) { if (r < 0) return log_link_error_errno(link, r, "Failed to close netlink container: %m"); - r = sd_netlink_call_async(link->manager->rtnl, m, link_set_handler, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, m, link_set_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); @@ -1991,7 +1991,7 @@ int link_down(Link *link) { if (r < 0) return log_link_error_errno(link, r, "Could not set link flags: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, link_down_handler, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, link_down_handler, NULL, link, 0, NULL); if (r < 0) return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); @@ -3103,7 +3103,8 @@ int link_initialized(Link *link, sd_device *device) { return r; r = sd_netlink_call_async(link->manager->rtnl, req, - link_initialized_and_synced, link, 0, NULL); + link_initialized_and_synced, + NULL, link, 0, NULL); if (r < 0) return r; diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index aa86ce792d..9ebbc4355e 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -439,7 +439,7 @@ int route_remove(Route *route, Link *link, return log_error_errno(r, "Could not append RTA_OIF attribute: %m"); } - r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, callback, NULL, link, 0, NULL); if (r < 0) return log_error_errno(r, "Could not send rtnetlink message: %m"); @@ -638,7 +638,7 @@ int route_configure( if (r < 0) return log_error_errno(r, "Could not append RTA_METRICS attribute: %m"); - r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, req, callback, NULL, link, 0, NULL); if (r < 0) return log_error_errno(r, "Could not send rtnetlink message: %m"); diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index bbab393546..cd9e913ebb 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -370,7 +370,7 @@ int routing_policy_rule_remove(RoutingPolicyRule *routing_policy_rule, Link *lin return log_error_errno(r, "Could not set destination prefix length: %m"); } - r = sd_netlink_call_async(link->manager->rtnl, m, callback, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, m, callback, NULL, link, 0, NULL); if (r < 0) return log_error_errno(r, "Could not send rtnetlink message: %m"); @@ -538,7 +538,7 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, sd_netlin rule->link = link; - r = sd_netlink_call_async(link->manager->rtnl, m, callback, link, 0, NULL); + r = sd_netlink_call_async(link->manager->rtnl, m, callback, NULL, link, 0, NULL); if (r < 0) return log_error_errno(r, "Could not send rtnetlink message: %m"); diff --git a/src/systemd/sd-netlink.h b/src/systemd/sd-netlink.h index 604edb9cfb..01b33c8fc0 100644 --- a/src/systemd/sd-netlink.h +++ b/src/systemd/sd-netlink.h @@ -38,6 +38,7 @@ typedef enum {SD_GENL_ID_CTRL, SD_GENL_WIREGUARD, SD_GENL_FOU} sd_genl_family; /* callback */ typedef int (*sd_netlink_message_handler_t)(sd_netlink *nl, sd_netlink_message *m, void *userdata); +typedef void (*sd_netlink_destroy_t)(void *userdata); /* bus */ int sd_netlink_new_from_netlink(sd_netlink **nl, int fd); @@ -50,11 +51,12 @@ sd_netlink *sd_netlink_unref(sd_netlink *nl); int sd_netlink_send(sd_netlink *nl, sd_netlink_message *message, uint32_t *serial); int sd_netlink_call_async(sd_netlink *nl, sd_netlink_message *message, - sd_netlink_message_handler_t callback, - void *userdata, uint64_t usec, uint32_t *serial); + sd_netlink_message_handler_t callback, + sd_netlink_destroy_t destoy_callback, + void *userdata, uint64_t usec, uint32_t *serial); int sd_netlink_call_async_cancel(sd_netlink *nl, uint32_t serial); int sd_netlink_call(sd_netlink *nl, sd_netlink_message *message, uint64_t timeout, - sd_netlink_message **reply); + sd_netlink_message **reply); int sd_netlink_get_events(sd_netlink *nl); int sd_netlink_get_timeout(sd_netlink *nl, uint64_t *timeout); |