aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2014-11-09 20:32:33 +0100
committerKim Alvefur <zash@zash.se>2014-11-09 20:32:33 +0100
commit3b5fa59a5496cd0d19e2a0dac067188d61d76c36 (patch)
tree00a4652d294babdf3be6f9add9a811a0e180a5d8 /net
parent763567fa0236b0b80e0271ed1d3325501b979ee1 (diff)
parent486335f3dbc84dacf253120f544f1d2ee026cf94 (diff)
downloadprosody-3b5fa59a5496cd0d19e2a0dac067188d61d76c36.tar.gz
prosody-3b5fa59a5496cd0d19e2a0dac067188d61d76c36.zip
Merge 0.10->trunk
Diffstat (limited to 'net')
-rw-r--r--net/adns.lua5
-rw-r--r--net/dns.lua19
2 files changed, 14 insertions, 10 deletions
diff --git a/net/adns.lua b/net/adns.lua
index 15814fe7..87f2876b 100644
--- a/net/adns.lua
+++ b/net/adns.lua
@@ -76,12 +76,11 @@ function new_async_socket(sock, resolver)
handler.settimeout = function () end
handler.setsockname = function (_, ...) return sock:setsockname(...); end
- handler.setpeername = function (_, ...) peername = (...); local ret = sock:setpeername(...); _:set_send(dummy_send); return ret; end
+ handler.setpeername = function (_, ...) peername = (...); local ret, err = sock:setpeername(...); _:set_send(dummy_send); return ret, err; end
handler.connect = function (_, ...) return sock:connect(...) end
--handler.send = function (_, data) _:write(data); return _.sendbuffer and _.sendbuffer(); end
handler.send = function (_, data)
- local getpeername = sock.getpeername;
- log("debug", "Sending DNS query to %s", (getpeername and getpeername(sock)) or "<unconnected>");
+ log("debug", "Sending DNS query to %s", peername);
return sock:send(data);
end
return handler;
diff --git a/net/dns.lua b/net/dns.lua
index 2b03caf6..2cb677f6 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -624,7 +624,7 @@ function resolver:getsocket(servernum) -- - - - - - - - - - - - - getsocket
local sock = self.socket[servernum];
if sock then return sock; end
- local err;
+ local ok, err;
local peer = self.server[servernum];
if peer:find(":") then
sock, err = socket.udp6();
@@ -637,10 +637,14 @@ function resolver:getsocket(servernum) -- - - - - - - - - - - - - getsocket
end
sock:settimeout(0);
-- todo: attempt to use a random port, fallback to 0
- sock:setsockname('*', 0);
- sock:setpeername(peer, 53);
self.socket[servernum] = sock;
self.socketset[sock] = servernum;
+ -- set{sock,peer}name can fail, eg because of local routing table
+ -- if so, try the next server
+ ok, err = sock:setsockname('*', 0);
+ if not ok then return self:servfail(sock, err); end
+ ok, err = sock:setpeername(peer, 53);
+ if not ok then return self:servfail(sock, err); end
return sock;
end
@@ -788,13 +792,13 @@ function resolver:query(qname, qtype, qclass) -- - - - - - - - - - -- query
return true;
end
-function resolver:servfail(sock)
+function resolver:servfail(sock, err)
-- Resend all queries for this server
local num = self.socketset[sock]
-- Socket is dead now
- self:voidsocket(sock);
+ sock = self:voidsocket(sock);
-- Find all requests to the down server, and retry on the next server
self.time = socket.gettime();
@@ -811,8 +815,8 @@ function resolver:servfail(sock)
--print('timeout');
queries[question] = nil;
else
- local _a = self:getsocket(o.server);
- if _a then _a:send(o.packet); end
+ sock, err = self:getsocket(o.server);
+ if sock then sock:send(o.packet); end
end
end
end
@@ -828,6 +832,7 @@ function resolver:servfail(sock)
self.best_server = 1;
end
end
+ return sock, err;
end
function resolver:settimeout(seconds)