[PATCH] afsocket: Do not die if a destination is not resolvable at startup.
If a destination cannot be resolved at init time, do not panic, just bail out, but otherwise pretend we succeeded: after time_reopen, we'll retry anyway! And on that note, teach afsocket_dd_start_connect() to call afsocket_dd_apply_transport() if our fd is -1 (ie, not connected). Reported-by: Peter Palfrader <weasel@debian.org> Signed-off-by: Gergely Nagy <algernon@balabit.hu> --- modules/afsocket/afinet.c | 2 +- modules/afsocket/afsocket.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/afsocket/afinet.c b/modules/afsocket/afinet.c index f83ff38..a7d3635 100644 --- a/modules/afsocket/afinet.c +++ b/modules/afsocket/afinet.c @@ -498,7 +498,7 @@ afinet_dd_apply_transport(AFSocketDestDriver *s) if ((self->bind_ip && !resolve_hostname(&self->super.bind_addr, self->bind_ip)) || !resolve_hostname(&self->super.dest_addr, self->super.hostname)) - return FALSE; + return TRUE; afinet_set_port(self->super.dest_addr, self->dest_port ? : default_dest_port, self->super.flags & AFSOCKET_DGRAM ? "udp" : "tcp"); diff --git a/modules/afsocket/afsocket.c b/modules/afsocket/afsocket.c index ae9c5c2..095f5a5 100644 --- a/modules/afsocket/afsocket.c +++ b/modules/afsocket/afsocket.c @@ -1103,6 +1103,11 @@ afsocket_dd_start_connect(AFSocketDestDriver *self) gchar buf1[MAX_SOCKADDR_STRING], buf2[MAX_SOCKADDR_STRING]; main_loop_assert_main_thread(); + + if (self->fd == -1) + if (!afsocket_dd_apply_transport(self)) + return FALSE; + if (!afsocket_open_socket(self->bind_addr, !!(self->flags & AFSOCKET_STREAM), &sock)) { return FALSE; @@ -1169,10 +1174,7 @@ afsocket_dd_init(LogPipe *s) /* these fields must be set up by apply_transport, so let's check if it indeed did */ g_assert(self->transport); - g_assert(self->bind_addr); - g_assert(self->dest_addr); g_assert(self->hostname); - g_assert(self->dest_name); if (cfg) { -- 1.7.9
I think this is already implemented in 3.4 in a different way, this was the patch that introduced the change: commit 775af1b8ead493198c1e3cea1edf64909d8a72b2 Author: Balazs Scheidler <bazsi@balabit.hu> Date: Sat Oct 29 20:15:35 2011 +0200 afsocket: handle DNS failures as if it was a connection failure Instead of preventing the startup completely. Reported-By: Heiko Gerstung <heiko@am-anger-1.de> Signed-off-by: Balazs Scheidler <bazsi@balabit.hu> On Fri, 2012-03-30 at 13:44 +0200, Gergely Nagy wrote:
If a destination cannot be resolved at init time, do not panic, just bail out, but otherwise pretend we succeeded: after time_reopen, we'll retry anyway!
And on that note, teach afsocket_dd_start_connect() to call afsocket_dd_apply_transport() if our fd is -1 (ie, not connected).
Reported-by: Peter Palfrader <weasel@debian.org> Signed-off-by: Gergely Nagy <algernon@balabit.hu> --- modules/afsocket/afinet.c | 2 +- modules/afsocket/afsocket.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/modules/afsocket/afinet.c b/modules/afsocket/afinet.c index f83ff38..a7d3635 100644 --- a/modules/afsocket/afinet.c +++ b/modules/afsocket/afinet.c @@ -498,7 +498,7 @@ afinet_dd_apply_transport(AFSocketDestDriver *s)
if ((self->bind_ip && !resolve_hostname(&self->super.bind_addr, self->bind_ip)) || !resolve_hostname(&self->super.dest_addr, self->super.hostname)) - return FALSE; + return TRUE;
afinet_set_port(self->super.dest_addr, self->dest_port ? : default_dest_port, self->super.flags & AFSOCKET_DGRAM ? "udp" : "tcp");
diff --git a/modules/afsocket/afsocket.c b/modules/afsocket/afsocket.c index ae9c5c2..095f5a5 100644 --- a/modules/afsocket/afsocket.c +++ b/modules/afsocket/afsocket.c @@ -1103,6 +1103,11 @@ afsocket_dd_start_connect(AFSocketDestDriver *self) gchar buf1[MAX_SOCKADDR_STRING], buf2[MAX_SOCKADDR_STRING];
main_loop_assert_main_thread(); + + if (self->fd == -1) + if (!afsocket_dd_apply_transport(self)) + return FALSE; + if (!afsocket_open_socket(self->bind_addr, !!(self->flags & AFSOCKET_STREAM), &sock)) { return FALSE; @@ -1169,10 +1174,7 @@ afsocket_dd_init(LogPipe *s)
/* these fields must be set up by apply_transport, so let's check if it indeed did */ g_assert(self->transport); - g_assert(self->bind_addr); - g_assert(self->dest_addr); g_assert(self->hostname); - g_assert(self->dest_name);
if (cfg) {
-- Bazsi
Balazs Scheidler <bazsi@balabit.hu> writes:
I think this is already implemented in 3.4 in a different way, this was the patch that introduced the change:
Mmhm. I saw my patch causing a conflict when I tried to apply it to 3.4. I'll see if I can backport the 3.4 patch to 3.3. Thanks for the hint! -- |8]
Gergely Nagy <algernon@balabit.hu> writes:
Balazs Scheidler <bazsi@balabit.hu> writes:
I think this is already implemented in 3.4 in a different way, this was the patch that introduced the change:
Mmhm. I saw my patch causing a conflict when I tried to apply it to 3.4. I'll see if I can backport the 3.4 patch to 3.3.
I checked the patch in 3.4, and that does, indeed, fix the issue. It can also be cherry-picked to 3.3 without conflict, and solves the issue there too. My hotfix/3.3/dest-unreachable branch has it cherry-picked, if that may be more convenient (although I doubt that). -- |8]
participants (2)
-
Balazs Scheidler
-
Gergely Nagy