diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-03 17:59:46 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-05 05:19:02 +0100 |
commit | 56ba90c2df61d3ef04a599af43007434f77bef62 (patch) | |
tree | 8ba083aba39bb980d724cfd92a7dbd47a6842cae /src | |
parent | network: use destroy callback to clear resolved wireguard endpoints (diff) | |
download | systemd-56ba90c2df61d3ef04a599af43007434f77bef62.tar.xz systemd-56ba90c2df61d3ef04a599af43007434f77bef62.zip |
network: use destroy callback to unref netdev attached to event source
Diffstat (limited to 'src')
-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 | 4 | ||||
-rw-r--r-- | src/network/netdev/netdev.h | 2 | ||||
-rw-r--r-- | src/network/netdev/wireguard.c | 23 | ||||
-rw-r--r-- | src/network/netdev/wireguard.h | 1 |
6 files changed, 24 insertions, 10 deletions
diff --git a/src/network/netdev/bridge.c b/src/network/netdev/bridge.c index 5a462f8376..cb00780b8a 100644 --- a/src/network/netdev/bridge.c +++ b/src/network/netdev/bridge.c @@ -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"); diff --git a/src/network/netdev/geneve.c b/src/network/netdev/geneve.c index e407a8fc5c..1742e399b8 100644 --- a/src/network/netdev/geneve.c +++ b/src/network/netdev/geneve.c @@ -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"); diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 06709679a0..52b40dd68e 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -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"); diff --git a/src/network/netdev/netdev.h b/src/network/netdev/netdev.h index 2c1a59f2c4..8c884bb124 100644 --- a/src/network/netdev/netdev.h +++ b/src/network/netdev/netdev.h @@ -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); diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c index de685157ef..2f4e7bdd91 100644 --- a/src/network/netdev/wireguard.c +++ b/src/network/netdev/wireguard.c @@ -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); diff --git a/src/network/netdev/wireguard.h b/src/network/netdev/wireguard.h index 7e6feb298b..361b381a0e 100644 --- a/src/network/netdev/wireguard.h +++ b/src/network/netdev/wireguard.h @@ -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); |