Mercurial > prosody-hg
comparison plugins/mod_s2s/s2sout.lib.lua @ 4922:d1fdc545f8b2
mod_s2s: Only do AAAA lookup if IPv6 is available, and A if IPv4 is available.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 29 May 2012 18:02:48 +0200 |
| parents | 89df1f03546a |
| children | 760a1f367f02 |
comparison
equal
deleted
inserted
replaced
| 4921:9a01c6bc435e | 4922:d1fdc545f8b2 |
|---|---|
| 23 local s2s_destroy_session = require "core.s2smanager".destroy_session; | 23 local s2s_destroy_session = require "core.s2smanager".destroy_session; |
| 24 | 24 |
| 25 local log = module._log; | 25 local log = module._log; |
| 26 | 26 |
| 27 local sources = {}; | 27 local sources = {}; |
| 28 local has_ipv4, has_ipv6; | |
| 28 | 29 |
| 29 local dns_timeout = module:get_option_number("dns_timeout", 15); | 30 local dns_timeout = module:get_option_number("dns_timeout", 15); |
| 30 dns.settimeout(dns_timeout); | 31 dns.settimeout(dns_timeout); |
| 31 local max_dns_depth = module:get_option_number("dns_max_depth", 3); | 32 local max_dns_depth = module:get_option_number("dns_max_depth", 3); |
| 32 | 33 |
| 112 if srv_choice then | 113 if srv_choice then |
| 113 connect_host, connect_port = srv_choice.target or to_host, srv_choice.port or connect_port; | 114 connect_host, connect_port = srv_choice.target or to_host, srv_choice.port or connect_port; |
| 114 log("debug", "Best record found, will connect to %s:%d", connect_host, connect_port); | 115 log("debug", "Best record found, will connect to %s:%d", connect_host, connect_port); |
| 115 end | 116 end |
| 116 else | 117 else |
| 117 log("debug", to_host.." has no SRV records, falling back to A"); | 118 log("debug", to_host.." has no SRV records, falling back to A/AAAA"); |
| 118 end | 119 end |
| 119 -- Try with SRV, or just the plain hostname if no SRV | 120 -- Try with SRV, or just the plain hostname if no SRV |
| 120 local ok, err = s2sout.try_connect(host_session, connect_host, connect_port); | 121 local ok, err = s2sout.try_connect(host_session, connect_host, connect_port); |
| 121 if not ok then | 122 if not ok then |
| 122 if not s2sout.attempt_connection(host_session, err) then | 123 if not s2sout.attempt_connection(host_session, err) then |
| 169 local IPs = {}; | 170 local IPs = {}; |
| 170 host_session.ip_hosts = IPs; | 171 host_session.ip_hosts = IPs; |
| 171 local handle4, handle6; | 172 local handle4, handle6; |
| 172 local has_other = false; | 173 local has_other = false; |
| 173 | 174 |
| 175 if has_ipv4 then | |
| 174 handle4 = adns.lookup(function (reply, err) | 176 handle4 = adns.lookup(function (reply, err) |
| 175 handle4 = nil; | 177 handle4 = nil; |
| 176 | 178 |
| 177 -- COMPAT: This is a compromise for all you CNAME-(ab)users :) | 179 -- COMPAT: This is a compromise for all you CNAME-(ab)users :) |
| 178 if not (reply and reply[#reply] and reply[#reply].a) then | 180 if not (reply and reply[#reply] and reply[#reply].a) then |
| 212 end | 214 end |
| 213 else | 215 else |
| 214 has_other = true; | 216 has_other = true; |
| 215 end | 217 end |
| 216 end, connect_host, "A", "IN"); | 218 end, connect_host, "A", "IN"); |
| 217 | 219 else |
| 220 has_other = true; | |
| 221 end | |
| 222 | |
| 223 if has_ipv6 then | |
| 218 handle6 = adns.lookup(function (reply, err) | 224 handle6 = adns.lookup(function (reply, err) |
| 219 handle6 = nil; | 225 handle6 = nil; |
| 220 | 226 |
| 221 if reply and reply[#reply] and reply[#reply].aaaa then | 227 if reply and reply[#reply] and reply[#reply].aaaa then |
| 222 for _, ip in ipairs(reply) do | 228 for _, ip in ipairs(reply) do |
| 244 end | 250 end |
| 245 else | 251 else |
| 246 has_other = true; | 252 has_other = true; |
| 247 end | 253 end |
| 248 end, connect_host, "AAAA", "IN"); | 254 end, connect_host, "AAAA", "IN"); |
| 255 else | |
| 256 has_other = true; | |
| 257 end | |
| 249 | 258 |
| 250 return true; | 259 return true; |
| 251 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 | 260 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 |
| 252 s2sout.try_next_ip(host_session); | 261 s2sout.try_next_ip(host_session); |
| 253 else | 262 else |
| 345 end | 354 end |
| 346 else | 355 else |
| 347 sources[#sources + 1] = new_ip(source, (source:find(":") and "IPv6") or "IPv4"); | 356 sources[#sources + 1] = new_ip(source, (source:find(":") and "IPv6") or "IPv4"); |
| 348 end | 357 end |
| 349 end | 358 end |
| 359 for i = 1,#sources do | |
| 360 if sources[i].proto == "IPv6" then | |
| 361 has_ipv6 = true; | |
| 362 elseif sources[i].proto == "IPv4" then | |
| 363 has_ipv4 = true; | |
| 364 end | |
| 365 end | |
| 350 end); | 366 end); |
| 351 | 367 |
| 352 return s2sout; | 368 return s2sout; |
