aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2012-05-29 18:02:48 +0200
committerKim Alvefur <zash@zash.se>2012-05-29 18:02:48 +0200
commitbb98bf4a58c1a26e127f4e0e6b548eb74df32ad4 (patch)
tree06b8e7e06f457f6150cd7a77ad0398b276df7359
parent375db8a3fb81215819e482cb912a1bebe8a403d5 (diff)
downloadprosody-bb98bf4a58c1a26e127f4e0e6b548eb74df32ad4.tar.gz
prosody-bb98bf4a58c1a26e127f4e0e6b548eb74df32ad4.zip
mod_s2s: Only do AAAA lookup if IPv6 is available, and A if IPv4 is available.
-rw-r--r--plugins/mod_s2s/s2sout.lib.lua18
1 files changed, 17 insertions, 1 deletions
diff --git a/plugins/mod_s2s/s2sout.lib.lua b/plugins/mod_s2s/s2sout.lib.lua
index 94445ea2..3b05b4b9 100644
--- a/plugins/mod_s2s/s2sout.lib.lua
+++ b/plugins/mod_s2s/s2sout.lib.lua
@@ -25,6 +25,7 @@ local s2s_destroy_session = require "core.s2smanager".destroy_session;
local log = module._log;
local sources = {};
+local has_ipv4, has_ipv6;
local dns_timeout = module:get_option_number("dns_timeout", 15);
dns.settimeout(dns_timeout);
@@ -114,7 +115,7 @@ function s2sout.attempt_connection(host_session, err)
log("debug", "Best record found, will connect to %s:%d", connect_host, connect_port);
end
else
- log("debug", to_host.." has no SRV records, falling back to A");
+ log("debug", to_host.." has no SRV records, falling back to A/AAAA");
end
-- Try with SRV, or just the plain hostname if no SRV
local ok, err = s2sout.try_connect(host_session, connect_host, connect_port);
@@ -171,6 +172,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err)
local handle4, handle6;
local has_other = false;
+ if has_ipv4 then
handle4 = adns.lookup(function (reply, err)
handle4 = nil;
@@ -214,7 +216,11 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err)
has_other = true;
end
end, connect_host, "A", "IN");
+ else
+ has_other = true;
+ end
+ if has_ipv6 then
handle6 = adns.lookup(function (reply, err)
handle6 = nil;
@@ -246,6 +252,9 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err)
has_other = true;
end
end, connect_host, "AAAA", "IN");
+ else
+ has_other = true;
+ end
return true;
elseif host_session.ip_hosts and #host_session.ip_hosts > host_session.ip_choice then -- Not our first attempt, and we also have IPs left to try
@@ -347,6 +356,13 @@ module:hook_global("service-added", function (event)
sources[#sources + 1] = new_ip(source, (source:find(":") and "IPv6") or "IPv4");
end
end
+ for i = 1,#sources do
+ if sources[i].proto == "IPv6" then
+ has_ipv6 = true;
+ elseif sources[i].proto == "IPv4" then
+ has_ipv4 = true;
+ end
+ end
end);
return s2sout;