aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-11-24 04:23:51 +0100
committerKim Alvefur <zash@zash.se>2019-11-24 04:23:51 +0100
commit7c056be161ad591b97ca42af3e3087ef45872c61 (patch)
treede7b9df415d525e6844ffb5b708c506d540718ff
parent7ac5e467baa7ebc557ed3a07bdca7dc9ade0c1db (diff)
downloadprosody-7c056be161ad591b97ca42af3e3087ef45872c61.tar.gz
prosody-7c056be161ad591b97ca42af3e3087ef45872c61.zip
net.resolvers.basic: Move IP literal check to constructor
This is to prepare for fixing #1459. An IPv6 literal in [ ] brackets does not pass IDNA and resolving it fails there.
-rw-r--r--net/resolvers/basic.lua25
1 files changed, 14 insertions, 11 deletions
diff --git a/net/resolvers/basic.lua b/net/resolvers/basic.lua
index f37e74a2..e3a94382 100644
--- a/net/resolvers/basic.lua
+++ b/net/resolvers/basic.lua
@@ -33,16 +33,6 @@ function methods:next(cb)
self:next(cb);
end
- local is_ip = inet_pton(self.hostname);
- if is_ip then
- if #is_ip == 16 then
- cb(self.conn_type.."6", self.hostname, self.port, self.extra);
- elseif #is_ip == 4 then
- cb(self.conn_type.."4", self.hostname, self.port, self.extra);
- end
- return;
- end
-
-- Resolve DNS to target list
local dns_resolver = adns.resolver();
dns_resolver:lookup(function (answer)
@@ -65,11 +55,24 @@ function methods:next(cb)
end
local function new(hostname, port, conn_type, extra)
+ local ascii_host = idna_to_ascii(hostname);
+ local targets = nil;
+
+ local is_ip = inet_pton(hostname);
+ if is_ip then
+ if #is_ip == 16 then
+ targets = { { conn_type.."6", hostname, port, extra } };
+ elseif #is_ip == 4 then
+ targets = { { conn_type.."4", hostname, port, extra } };
+ end
+ end
+
return setmetatable({
- hostname = idna_to_ascii(hostname);
+ hostname = ascii_host;
port = port;
conn_type = conn_type or "tcp";
extra = extra;
+ targets = targets;
}, resolver_mt);
end