Comparison

plugins/mod_s2s/s2sout.lib.lua @ 8267:42fad8465537

mod_s2s: Use a separate resolver object for each outgoing session Cleaner approach hopefully fixes problems with some peoples' DNS hanging after a while, failed DNS when a large number of queries are made at once, and source port re-use. Related issues: #487, 761, #991, #992, #1001
author Matthew Wild <mwild1@gmail.com>
date Mon, 25 Sep 2017 23:12:47 +0100
parent 7685:8e43a05e2374
child 8483:6d47b74926dd
child 8899:c72a6226ee31
comparison
equal deleted inserted replaced
8266:9a97dd174ec9 8267:42fad8465537
47 47
48 function s2sout.initiate_connection(host_session) 48 function s2sout.initiate_connection(host_session)
49 initialize_filters(host_session); 49 initialize_filters(host_session);
50 host_session.version = 1; 50 host_session.version = 1;
51 51
52 host_session.resolver = adns.resolver();
53
52 -- Kick the connection attempting machine into life 54 -- Kick the connection attempting machine into life
53 if not s2sout.attempt_connection(host_session) then 55 if not s2sout.attempt_connection(host_session) then
54 -- Intentionally not returning here, the 56 -- Intentionally not returning here, the
55 -- session is needed, connected or not 57 -- session is needed, connected or not
56 s2s_destroy_session(host_session); 58 s2s_destroy_session(host_session);
82 end 84 end
83 85
84 if not err then -- This is our first attempt 86 if not err then -- This is our first attempt
85 log("debug", "First attempt to connect to %s, starting with SRV lookup...", to_host); 87 log("debug", "First attempt to connect to %s, starting with SRV lookup...", to_host);
86 host_session.connecting = true; 88 host_session.connecting = true;
87 local handle; 89 host_session.resolver:lookup(function (answer)
88 handle = adns.lookup(function (answer)
89 handle = nil;
90 local srv_hosts = { answer = answer }; 90 local srv_hosts = { answer = answer };
91 host_session.srv_hosts = srv_hosts; 91 host_session.srv_hosts = srv_hosts;
92 host_session.srv_choice = 0; 92 host_session.srv_choice = 0;
93 host_session.connecting = nil; 93 host_session.connecting = nil;
94 if answer and #answer > 0 then 94 if answer and #answer > 0 then
166 host_session.ip_hosts = IPs; 166 host_session.ip_hosts = IPs;
167 local handle4, handle6; 167 local handle4, handle6;
168 local have_other_result = not(has_ipv4) or not(has_ipv6) or false; 168 local have_other_result = not(has_ipv4) or not(has_ipv6) or false;
169 169
170 if has_ipv4 then 170 if has_ipv4 then
171 handle4 = adns.lookup(function (reply, err) 171 handle4 = host_session.resolver:lookup(function (reply, err)
172 handle4 = nil; 172 handle4 = nil;
173 173
174 if reply and reply[#reply] and reply[#reply].a then 174 if reply and reply[#reply] and reply[#reply].a then
175 for _, ip in ipairs(reply) do 175 for _, ip in ipairs(reply) do
176 log("debug", "DNS reply for %s gives us %s", connect_host, ip.a); 176 log("debug", "DNS reply for %s gives us %s", connect_host, ip.a);
204 else 204 else
205 have_other_result = true; 205 have_other_result = true;
206 end 206 end
207 207
208 if has_ipv6 then 208 if has_ipv6 then
209 handle6 = adns.lookup(function (reply, err) 209 handle6 = host_session.resolver:lookup(function (reply, err)
210 handle6 = nil; 210 handle6 = nil;
211 211
212 if reply and reply[#reply] and reply[#reply].aaaa then 212 if reply and reply[#reply] and reply[#reply].aaaa then
213 for _, ip in ipairs(reply) do 213 for _, ip in ipairs(reply) do
214 log("debug", "DNS reply for %s gives us %s", connect_host, ip.aaaa); 214 log("debug", "DNS reply for %s gives us %s", connect_host, ip.aaaa);