From ad268c9db3f4eec85a378f39d3186057568f0eeb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 Jun 2018 00:02:06 +0200 Subject: net.dns: Cache all records from the 'answer' section (fixes #487) This should preserve CNAME records included here --- net/dns.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net/dns.lua') diff --git a/net/dns.lua b/net/dns.lua index eba2b5a0..93c1805b 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -889,7 +889,7 @@ function resolver:feed(sock, packet, force) --self.print(response); for _, rr in pairs(response.answer) do - self:remember(rr, response.question[1].type); + self:remember(rr, rr.type); end -- retire the query -- cgit v1.2.3 From 73a7fa134dbd699120920d1f65b3224fc6aa5e5e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 3 Jun 2018 00:40:42 +0200 Subject: net.dns: Also cache records from the 'additional' section Could be getting A/AAAA records here when asking for SRV --- net/dns.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'net/dns.lua') diff --git a/net/dns.lua b/net/dns.lua index 93c1805b..b69ba953 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -892,6 +892,10 @@ function resolver:feed(sock, packet, force) self:remember(rr, rr.type); end + for _, rr in pairs(response.additional) do + self:remember(rr, rr.type); + end + -- retire the query local queries = self.active[response.header.id]; queries[response.question.raw] = nil; -- cgit v1.2.3 From fb63de9331f4fb1c50e11b2f1bcbaab53209f45f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 Jun 2018 15:35:03 +0200 Subject: net.dns: Don't attempt to cache unparsed data (fixes #1056) rr[qtype:lower()] can be nil. I think this happens if the type does not have a parser. Also see #819 #976 --- net/dns.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net/dns.lua') diff --git a/net/dns.lua b/net/dns.lua index b69ba953..8a7d4e7a 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -672,7 +672,7 @@ function resolver:remember(rr, type) -- - - - - - - - - - - - - - remember self.cache = self.cache or setmetatable({}, cache_metatable); local rrs = get(self.cache, qclass, type, qname) or set(self.cache, qclass, type, qname, setmetatable({}, rrs_metatable)); - if not rrs[rr[qtype:lower()]] then + if rr[qtype:lower()] and not rrs[rr[qtype:lower()]] then rrs[rr[qtype:lower()]] = true; append(rrs, rr); end -- cgit v1.2.3 From 5ae35f54cc69163c9d0c0f3e9bb40b07542af9c0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 Jun 2018 15:34:00 +0200 Subject: net.dns: Syntesize type names for the full range Otherwise unknown records are identified as A records. This also fixes various tracebacks unearthed by previous commits and mis-identified records. Related to #1056 #976 #819 --- net/dns.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'net/dns.lua') diff --git a/net/dns.lua b/net/dns.lua index 8a7d4e7a..0d2cce01 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -86,9 +86,10 @@ local function highbyte(i) -- - - - - - - - - - - - - - - - - - - highbyte end -local function augment (t) -- - - - - - - - - - - - - - - - - - - - augment +local function augment (t, prefix) -- - - - - - - - - - - - - - - - - augment local a = {}; - for i,s in pairs(t) do + for i = 1, 0xffff do + local s = t[i] or ("%s%d"):format(prefix, i); a[i] = s; a[s] = s; a[string.lower(s)] = s; @@ -119,8 +120,8 @@ dns.types = { dns.classes = { 'IN', 'CS', 'CH', 'HS', [255] = '*' }; -dns.type = augment (dns.types); -dns.class = augment (dns.classes); +dns.type = augment (dns.types, "TYPE"); +dns.class = augment (dns.classes, "CLASS"); dns.typecode = encode (dns.types); dns.classcode = encode (dns.classes); -- cgit v1.2.3