mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
network: use destroy callback to unref netdev attached to event source
This commit is contained in:
parent
8173d1d0ec
commit
56ba90c2df
@ -130,7 +130,7 @@ static int netdev_bridge_post_create(NetDev *netdev, Link *link, sd_netlink_mess
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m");
|
||||
|
||||
r = sd_netlink_call_async(netdev->manager->rtnl, NULL, req, netdev_bridge_set_handler,
|
||||
netdev_netlink_destroy_callback, netdev, 0, __func__);
|
||||
netdev_destroy_callback, netdev, 0, __func__);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m");
|
||||
|
||||
|
@ -137,7 +137,7 @@ static int netdev_geneve_create(NetDev *netdev) {
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m");
|
||||
|
||||
r = sd_netlink_call_async(netdev->manager->rtnl, NULL, m, geneve_netdev_create_handler,
|
||||
netdev_netlink_destroy_callback, netdev, 0, __func__);
|
||||
netdev_destroy_callback, netdev, 0, __func__);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m");
|
||||
|
||||
|
@ -155,7 +155,7 @@ static NetDev *netdev_free(NetDev *netdev) {
|
||||
|
||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(NetDev, netdev, netdev_free);
|
||||
|
||||
void netdev_netlink_destroy_callback(void *userdata) {
|
||||
void netdev_destroy_callback(void *userdata) {
|
||||
NetDev *netdev = userdata;
|
||||
|
||||
assert(userdata);
|
||||
@ -550,7 +550,7 @@ static int netdev_create(NetDev *netdev, Link *link,
|
||||
link_ref(link);
|
||||
} else {
|
||||
r = sd_netlink_call_async(netdev->manager->rtnl, NULL, m, netdev_create_handler,
|
||||
netdev_netlink_destroy_callback, netdev, 0, __func__);
|
||||
netdev_destroy_callback, netdev, 0, __func__);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m");
|
||||
|
||||
|
@ -150,7 +150,7 @@ void netdev_drop(NetDev *netdev);
|
||||
|
||||
NetDev *netdev_unref(NetDev *netdev);
|
||||
NetDev *netdev_ref(NetDev *netdev);
|
||||
void netdev_netlink_destroy_callback(void *userdata);
|
||||
void netdev_destroy_callback(void *userdata);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref);
|
||||
|
||||
int netdev_get(Manager *manager, const char *name, NetDev **ret);
|
||||
|
@ -222,8 +222,11 @@ static int on_resolve_retry(sd_event_source *s, usec_t usec, void *userdata) {
|
||||
w = WIREGUARD(netdev);
|
||||
assert(w);
|
||||
|
||||
w->resolve_retry_event_source = sd_event_source_unref(w->resolve_retry_event_source);
|
||||
if (!netdev->manager)
|
||||
/* The netdev is detached. */
|
||||
return 0;
|
||||
|
||||
assert(!w->unresolved_endpoints);
|
||||
w->unresolved_endpoints = TAKE_PTR(w->failed_endpoints);
|
||||
|
||||
resolve_endpoints(netdev);
|
||||
@ -279,16 +282,29 @@ static int wireguard_resolve_handler(sd_resolve_query *q,
|
||||
|
||||
set_wireguard_interface(netdev);
|
||||
if (w->failed_endpoints) {
|
||||
_cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
|
||||
|
||||
w->n_retries++;
|
||||
r = sd_event_add_time(netdev->manager->event,
|
||||
&w->resolve_retry_event_source,
|
||||
&s,
|
||||
CLOCK_MONOTONIC,
|
||||
now(CLOCK_MONOTONIC) + exponential_backoff_milliseconds(w->n_retries),
|
||||
0,
|
||||
on_resolve_retry,
|
||||
netdev);
|
||||
if (r < 0)
|
||||
if (r < 0) {
|
||||
log_netdev_warning_errno(netdev, r, "Could not arm resolve retry handler: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = sd_event_source_set_destroy_callback(s, netdev_destroy_callback);
|
||||
if (r < 0) {
|
||||
log_netdev_warning_errno(netdev, r, "Failed to set destroy callback to event source: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void) sd_event_source_set_floating(s, true);
|
||||
netdev_ref(netdev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -705,7 +721,6 @@ static void wireguard_done(NetDev *netdev) {
|
||||
assert(netdev);
|
||||
w = WIREGUARD(netdev);
|
||||
assert(!w->unresolved_endpoints);
|
||||
w->resolve_retry_event_source = sd_event_source_unref(w->resolve_retry_event_source);
|
||||
|
||||
while ((peer = w->peers)) {
|
||||
LIST_REMOVE(peers, w->peers, peer);
|
||||
|
@ -58,7 +58,6 @@ struct Wireguard {
|
||||
|
||||
LIST_HEAD(WireguardPeer, peers);
|
||||
size_t allocation_size;
|
||||
sd_event_source *resolve_retry_event_source;
|
||||
|
||||
LIST_HEAD(WireguardEndpoint, unresolved_endpoints);
|
||||
LIST_HEAD(WireguardEndpoint, failed_endpoints);
|
||||
|
Loading…
Reference in New Issue
Block a user