Comparison

net/resolvers/basic.lua @ 11901:26406ce35e20

net.connect: Propagate last error message from resolvers Previously it would only say "unable to resolve server" for all DNS problems. While "NoError in A lookup" might not make much sense to users, it should help in debugging more than the previous generic error. Friendlier errors will be future work.
author Kim Alvefur <zash@zash.se>
date Fri, 12 Nov 2021 16:52:55 +0100
parent 11708:5ef729c355f3
child 12025:6ed7fd28f5e3
comparison
equal deleted inserted replaced
11900:60676b607b6d 11901:26406ce35e20
50 50
51 -- Resolve DNS to target list 51 -- Resolve DNS to target list
52 local dns_resolver = adns.resolver(); 52 local dns_resolver = adns.resolver();
53 53
54 if not self.extra or self.extra.use_ipv4 ~= false then 54 if not self.extra or self.extra.use_ipv4 ~= false then
55 dns_resolver:lookup(function (answer) 55 dns_resolver:lookup(function (answer, err)
56 if answer then 56 if answer then
57 secure = secure and answer.secure; 57 secure = secure and answer.secure;
58 for _, record in ipairs(answer) do 58 for _, record in ipairs(answer) do
59 table.insert(targets, { self.conn_type.."4", record.a, self.port, self.extra }); 59 table.insert(targets, { self.conn_type.."4", record.a, self.port, self.extra });
60 end 60 end
61 if answer.status then
62 self.last_error = answer.status .. " in A lookup";
63 end
64 else
65 self.last_error = err;
61 end 66 end
62 ready(); 67 ready();
63 end, self.hostname, "A", "IN"); 68 end, self.hostname, "A", "IN");
64 else 69 else
65 ready(); 70 ready();
66 end 71 end
67 72
68 if not self.extra or self.extra.use_ipv6 ~= false then 73 if not self.extra or self.extra.use_ipv6 ~= false then
69 dns_resolver:lookup(function (answer) 74 dns_resolver:lookup(function (answer, err)
70 if answer then 75 if answer then
71 secure = secure and answer.secure; 76 secure = secure and answer.secure;
72 for _, record in ipairs(answer) do 77 for _, record in ipairs(answer) do
73 table.insert(targets, { self.conn_type.."6", record.aaaa, self.port, self.extra }); 78 table.insert(targets, { self.conn_type.."6", record.aaaa, self.port, self.extra });
74 end 79 end
80 if answer.status then
81 self.last_error = answer.status .. " in AAAA lookup";
82 end
83 else
84 self.last_error = err;
75 end 85 end
76 ready(); 86 ready();
77 end, self.hostname, "AAAA", "IN"); 87 end, self.hostname, "AAAA", "IN");
78 else 88 else
79 ready(); 89 ready();
80 end 90 end
81 91
82 if self.extra and self.extra.use_dane == true then 92 if self.extra and self.extra.use_dane == true then
83 dns_resolver:lookup(function (answer) 93 dns_resolver:lookup(function (answer, err)
84 if answer then 94 if answer then
85 secure = secure and answer.secure; 95 secure = secure and answer.secure;
86 for _, record in ipairs(answer) do 96 for _, record in ipairs(answer) do
87 table.insert(tlsa, record.tlsa); 97 table.insert(tlsa, record.tlsa);
88 end 98 end
99 if answer.status then
100 self.last_error = answer.status .. " in TLSA lookup";
101 end
102 else
103 self.last_error = err;
89 end 104 end
90 ready(); 105 ready();
91 end, ("_%d._tcp.%s"):format(self.port, self.hostname), "TLSA", "IN"); 106 end, ("_%d._tcp.%s"):format(self.port, self.hostname), "TLSA", "IN");
92 else 107 else
93 ready(); 108 ready();