aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_s2s/s2sout.lib.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-01-22 15:03:02 +0100
committerKim Alvefur <zash@zash.se>2016-01-22 15:03:02 +0100
commit931549f781d8a0cb98af05b98cf00880dca5fb9f (patch)
tree6826436cb243da87ede7abff06607216fa25fa4b /plugins/mod_s2s/s2sout.lib.lua
parentb0864f247d26d45d1a2e6f0dc4958254ca8bcb47 (diff)
parent6116ba8cfbeff29bd3c4cedd1b05babec47e1507 (diff)
downloadprosody-931549f781d8a0cb98af05b98cf00880dca5fb9f.tar.gz
prosody-931549f781d8a0cb98af05b98cf00880dca5fb9f.zip
Merge 0.10->trunk
Diffstat (limited to 'plugins/mod_s2s/s2sout.lib.lua')
-rw-r--r--plugins/mod_s2s/s2sout.lib.lua46
1 files changed, 22 insertions, 24 deletions
diff --git a/plugins/mod_s2s/s2sout.lib.lua b/plugins/mod_s2s/s2sout.lib.lua
index 395406cd..42413164 100644
--- a/plugins/mod_s2s/s2sout.lib.lua
+++ b/plugins/mod_s2s/s2sout.lib.lua
@@ -18,31 +18,13 @@ local socket = require "socket";
local adns = require "net.adns";
local dns = require "net.dns";
local t_insert, t_sort, ipairs = table.insert, table.sort, ipairs;
+local local_addresses = require "util.net".local_addresses;
local s2s_destroy_session = require "core.s2smanager".destroy_session;
local log = module._log;
-local anysource = { IPv4 = "0.0.0.0", IPv6 = "::" };
-local function get_sources(addrs)
- local sources = {};
- for _, IP in ipairs(addrs) do
- local sock;
- if IP.proto == "IPv4" then
- sock = socket.udp();
- elseif IP.proto == "IPv6" then
- sock = socket.udp6();
- end
- sock:setpeername(IP.addr, 9);
- local localaddr = sock:getsockname() or anysource[IP.proto];
- sock:close();
- if not sources[localaddr] then
- sources[localaddr] = true;
- t_insert(sources, new_ip(localaddr, IP.proto));
- end
- end
- return sources;
-end
+local sources = {};
local has_ipv4, has_ipv6;
local dns_timeout = module:get_option_number("dns_timeout", 15);
@@ -196,7 +178,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err)
if have_other_result then
if #IPs > 0 then
- rfc6724_dest(host_session.ip_hosts, get_sources(host_session.ip_hosts));
+ rfc6724_dest(host_session.ip_hosts, sources);
for i = 1, #IPs do
IPs[i] = {ip = IPs[i], port = connect_port};
end
@@ -232,7 +214,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err)
if have_other_result then
if #IPs > 0 then
- rfc6724_dest(host_session.ip_hosts, get_sources(host_session.ip_hosts));
+ rfc6724_dest(host_session.ip_hosts, sources);
for i = 1, #IPs do
IPs[i] = {ip = IPs[i], port = connect_port};
end
@@ -320,12 +302,28 @@ module:hook_global("service-added", function (event)
return;
end
for source, _ in pairs(s2s_sources) do
- if source:find(":") then
- has_ipv6 = true;
+ if source == "*" or source == "0.0.0.0" then
+ for _, addr in ipairs(local_addresses("ipv4", true)) do
+ sources[#sources + 1] = new_ip(addr, "IPv4");
+ end
+ elseif source == "::" then
+ for _, addr in ipairs(local_addresses("ipv6", true)) do
+ sources[#sources + 1] = new_ip(addr, "IPv6");
+ end
else
+ 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
+ if not (has_ipv4 or has_ipv6) then
+ module:log("warn", "No local IPv4 or IPv6 addresses detected, outgoing connections may fail");
+ end
end);
return s2sout;