Skip to content

Commit

Permalink
iked: fix vroute_dbus_dns: System.Error.ENOTCONN
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Markus Friedl authored and tobhe committed Feb 11, 2024
1 parent 727ace8 commit a0fc2e0
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions iked/vroute-netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a0fc2e0

Please sign in to comment.