From 6a56de44e2e175bff7cab3196880543dbb39c420 Mon Sep 17 00:00:00 2001 From: Markus Friedl Date: Thu, 8 Feb 2024 10:02:13 +0100 Subject: [PATCH] iked: fix vroute_dbus_dns: System.Error.ENOTCONN move sd_bus_open_system() to vroute_do_dns(), otherwise we keep the dbus handle for the lifetime of iked and dbus calls fail with ENOTCONN. --- iked/vroute-netlink.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/iked/vroute-netlink.c b/iked/vroute-netlink.c index 34284479..8a085280 100644 --- a/iked/vroute-netlink.c +++ b/iked/vroute-netlink.c @@ -109,15 +109,6 @@ vroute_init(struct iked *env) NETLINK_ROUTE)) == -1) fatal("%s: failed to create netlink socket", __func__); -#ifdef WITH_SYSTEMD - int r; - r = sd_bus_open_system(&ivr->ivr_bus); - if (r < 0) { - log_warn("%s: sd_bus_open_system", __func__); - ivr->ivr_bus = NULL; - } -#endif - TAILQ_INIT(&ivr->ivr_addrs); TAILQ_INIT(&ivr->ivr_dnss); TAILQ_INIT(&ivr->ivr_routes); @@ -745,12 +736,23 @@ int vroute_dodns(struct iked *env, int add, unsigned int ifindex) { #ifdef WITH_SYSTEMD + struct iked_vroute_sc *ivr = env->sc_vroute; const char *destination = "org.freedesktop.resolve1"; const char *path = "/org/freedesktop/resolve1"; const char *interface = "org.freedesktop.resolve1.Manager"; sd_bus_error error = SD_BUS_ERROR_NULL; int ret; + if (ivr->ivr_bus != NULL) { + log_warnx("%s: vr_bus already set, internal error", __func__); + return (0); + } + if (sd_bus_open_system(&ivr->ivr_bus) < 0) { + log_warn("%s: sd_bus_open_system failed", __func__); + ivr->ivr_bus = NULL; + return (0); + } + ret = vroute_dbus_dns(env, ifindex, &error, add, destination, path, interface); if (ret < 0 && sd_bus_error_has_name(&error, @@ -780,6 +782,9 @@ vroute_dodns(struct iked *env, int add, unsigned int ifindex) error.name, error.message); sd_bus_error_free(&error); } + + sd_bus_flush_close_unref(ivr->ivr_bus); + ivr->ivr_bus = NULL; #endif return (0); }