Mercurial > prosody-hg
comparison plugins/mod_s2s/s2sout.lib.lua @ 4970:eeff01224865
Merge 0.9->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 22 Jul 2012 17:08:09 +0100 |
| parents | ab696f5394cf |
| children | d37f2abac72c |
comparison
equal
deleted
inserted
replaced
| 4958:1f1c74ac9666 | 4970:eeff01224865 |
|---|---|
| 171 host_session.ip_hosts = IPs; | 171 host_session.ip_hosts = IPs; |
| 172 local handle4, handle6; | 172 local handle4, handle6; |
| 173 local have_other_result = not(has_ipv4) or not(has_ipv6) or false; | 173 local have_other_result = not(has_ipv4) or not(has_ipv6) or false; |
| 174 | 174 |
| 175 if has_ipv4 then | 175 if has_ipv4 then |
| 176 handle4 = adns.lookup(function (reply, err) | 176 handle4 = adns.lookup(function (reply, err) |
| 177 handle4 = nil; | 177 handle4 = nil; |
| 178 | 178 |
| 179 -- COMPAT: This is a compromise for all you CNAME-(ab)users :) | 179 -- COMPAT: This is a compromise for all you CNAME-(ab)users :) |
| 180 if not (reply and reply[#reply] and reply[#reply].a) then | 180 if not (reply and reply[#reply] and reply[#reply].a) then |
| 181 local count = max_dns_depth; | 181 local count = max_dns_depth; |
| 182 reply = dns.peek(connect_host, "CNAME", "IN"); | 182 reply = dns.peek(connect_host, "CNAME", "IN"); |
| 183 while count > 0 and reply and reply[#reply] and not reply[#reply].a and reply[#reply].cname do | 183 while count > 0 and reply and reply[#reply] and not reply[#reply].a and reply[#reply].cname do |
| 184 log("debug", "Looking up %s (DNS depth is %d)", tostring(reply[#reply].cname), count); | 184 log("debug", "Looking up %s (DNS depth is %d)", tostring(reply[#reply].cname), count); |
| 185 reply = dns.peek(reply[#reply].cname, "A", "IN") or dns.peek(reply[#reply].cname, "CNAME", "IN"); | 185 reply = dns.peek(reply[#reply].cname, "A", "IN") or dns.peek(reply[#reply].cname, "CNAME", "IN"); |
| 186 count = count - 1; | 186 count = count - 1; |
| 187 end | 187 end |
| 188 end | 188 end |
| 189 -- end of CNAME resolving | 189 -- end of CNAME resolving |
| 190 | 190 |
| 191 if reply and reply[#reply] and reply[#reply].a then | 191 if reply and reply[#reply] and reply[#reply].a then |
| 192 for _, ip in ipairs(reply) do | 192 for _, ip in ipairs(reply) do |
| 193 log("debug", "DNS reply for %s gives us %s", connect_host, ip.a); | 193 log("debug", "DNS reply for %s gives us %s", connect_host, ip.a); |
| 194 IPs[#IPs+1] = new_ip(ip.a, "IPv4"); | 194 IPs[#IPs+1] = new_ip(ip.a, "IPv4"); |
| 195 end | 195 end |
| 196 end | 196 end |
| 197 | 197 |
| 198 if have_other_result then | 198 if have_other_result then |
| 199 if #IPs > 0 then | 199 if #IPs > 0 then |
| 200 rfc3484_dest(host_session.ip_hosts, sources); | 200 rfc3484_dest(host_session.ip_hosts, sources); |
| 201 for i = 1, #IPs do | 201 for i = 1, #IPs do |
| 202 IPs[i] = {ip = IPs[i], port = connect_port}; | 202 IPs[i] = {ip = IPs[i], port = connect_port}; |
| 203 end | 203 end |
| 204 host_session.ip_choice = 0; | 204 host_session.ip_choice = 0; |
| 205 s2sout.try_next_ip(host_session); | 205 s2sout.try_next_ip(host_session); |
| 206 else | |
| 207 log("debug", "DNS lookup failed to get a response for %s", connect_host); | |
| 208 host_session.ip_hosts = nil; | |
| 209 if not s2sout.attempt_connection(host_session, "name resolution failed") then -- Retry if we can | |
| 210 log("debug", "No other records to try for %s - destroying", host_session.to_host); | |
| 211 err = err and (": "..err) or ""; | |
| 212 s2s_destroy_session(host_session, "DNS resolution failed"..err); -- End of the line, we can't | |
| 213 end | |
| 214 end | |
| 206 else | 215 else |
| 207 log("debug", "DNS lookup failed to get a response for %s", connect_host); | 216 have_other_result = true; |
| 208 host_session.ip_hosts = nil; | 217 end |
| 209 if not s2sout.attempt_connection(host_session, "name resolution failed") then -- Retry if we can | 218 end, connect_host, "A", "IN"); |
| 210 log("debug", "No other records to try for %s - destroying", host_session.to_host); | |
| 211 err = err and (": "..err) or ""; | |
| 212 s2s_destroy_session(host_session, "DNS resolution failed"..err); -- End of the line, we can't | |
| 213 end | |
| 214 end | |
| 215 else | |
| 216 have_other_result = true; | |
| 217 end | |
| 218 end, connect_host, "A", "IN"); | |
| 219 else | 219 else |
| 220 have_other_result = true; | 220 have_other_result = true; |
| 221 end | 221 end |
| 222 | 222 |
| 223 if has_ipv6 then | 223 if has_ipv6 then |
| 224 handle6 = adns.lookup(function (reply, err) | 224 handle6 = adns.lookup(function (reply, err) |
| 225 handle6 = nil; | 225 handle6 = nil; |
| 226 | 226 |
| 227 if reply and reply[#reply] and reply[#reply].aaaa then | 227 if reply and reply[#reply] and reply[#reply].aaaa then |
| 228 for _, ip in ipairs(reply) do | 228 for _, ip in ipairs(reply) do |
| 229 log("debug", "DNS reply for %s gives us %s", connect_host, ip.aaaa); | 229 log("debug", "DNS reply for %s gives us %s", connect_host, ip.aaaa); |
| 230 IPs[#IPs+1] = new_ip(ip.aaaa, "IPv6"); | 230 IPs[#IPs+1] = new_ip(ip.aaaa, "IPv6"); |
| 231 end | 231 end |
| 232 end | 232 end |
| 233 | 233 |
| 234 if have_other_result then | 234 if have_other_result then |
| 235 if #IPs > 0 then | 235 if #IPs > 0 then |
| 236 rfc3484_dest(host_session.ip_hosts, sources); | 236 rfc3484_dest(host_session.ip_hosts, sources); |
| 237 for i = 1, #IPs do | 237 for i = 1, #IPs do |
| 238 IPs[i] = {ip = IPs[i], port = connect_port}; | 238 IPs[i] = {ip = IPs[i], port = connect_port}; |
| 239 end | 239 end |
| 240 host_session.ip_choice = 0; | 240 host_session.ip_choice = 0; |
| 241 s2sout.try_next_ip(host_session); | 241 s2sout.try_next_ip(host_session); |
| 242 else | |
| 243 log("debug", "DNS lookup failed to get a response for %s", connect_host); | |
| 244 host_session.ip_hosts = nil; | |
| 245 if not s2sout.attempt_connection(host_session, "name resolution failed") then -- Retry if we can | |
| 246 log("debug", "No other records to try for %s - destroying", host_session.to_host); | |
| 247 err = err and (": "..err) or ""; | |
| 248 s2s_destroy_session(host_session, "DNS resolution failed"..err); -- End of the line, we can't | |
| 249 end | |
| 250 end | |
| 242 else | 251 else |
| 243 log("debug", "DNS lookup failed to get a response for %s", connect_host); | 252 have_other_result = true; |
| 244 host_session.ip_hosts = nil; | 253 end |
| 245 if not s2sout.attempt_connection(host_session, "name resolution failed") then -- Retry if we can | 254 end, connect_host, "AAAA", "IN"); |
| 246 log("debug", "No other records to try for %s - destroying", host_session.to_host); | |
| 247 err = err and (": "..err) or ""; | |
| 248 s2s_destroy_session(host_session, "DNS resolution failed"..err); -- End of the line, we can't | |
| 249 end | |
| 250 end | |
| 251 else | |
| 252 have_other_result = true; | |
| 253 end | |
| 254 end, connect_host, "AAAA", "IN"); | |
| 255 else | 255 else |
| 256 have_other_result = true; | 256 have_other_result = true; |
| 257 end | 257 end |
| 258 return true; | 258 return true; |
| 259 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 | 259 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 |
