]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules: fix issues with dropped answers - resolve()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 4 Nov 2020 09:07:40 +0000 (10:07 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 10 Nov 2020 16:16:47 +0000 (17:16 +0100)
Well... practically it still can't happen that an internal request
gets its answer dropped, but ATM my understanding of the API is that
it is allowed to happen already, and the crashes during tests were
bothering me (simulating drops).

This may become more relevant in future, e.g. if we allow dropping
as a policy action; policy authors may not care about the request being
internal.

modules/detect_time_skew/detect_time_skew.lua
modules/priming/priming.lua
modules/ta_update/ta_update.lua
modules/watchdog/watchdog.lua
tests/config/test_utils.lua

index 2cc792b0b109e176f3592d895245d1a57e3a1117..0c1079605d58e7b3f647e432ababc3ddf165c752 100644 (file)
@@ -9,7 +9,7 @@ local event_id = nil
 -- Check time validity of RRSIGs in priming query
 -- luacheck: no unused args
 local function check_time_callback(pkt, req)
-       if pkt:rcode() ~= kres.rcode.NOERROR then
+       if pkt == nil or pkt:rcode() ~= kres.rcode.NOERROR then
                warn("[detect_time_skew] cannot resolve '.' NS")
                return nil
        end
index c60f2554057c3243614ba5782963f5aa0bc242f2..46c2f4cd10472073197fac8c24bad589161c9ea8 100644 (file)
@@ -42,7 +42,8 @@ end
 -- When all response is processed internal.nsset is published in resolver engine
 -- luacheck: no unused args
 local function address_callback(pkt, req)
-       if pkt:rcode() ~= kres.rcode.NOERROR then
+       if pkt == nil or pkt:rcode() ~= kres.rcode.NOERROR then
+               pkt = req.qsource.packet
                warn("[priming] cannot resolve address '%s', type: %d", kres.dname2str(pkt:qname()), pkt:qtype())
        else
                local section = pkt:rrsets(kres.section.ANSWER)
@@ -80,7 +81,7 @@ end
 -- These new queries should be resolved from cache.
 -- luacheck: no unused args
 local function priming_callback(pkt, req)
-       if pkt:rcode() ~= kres.rcode.NOERROR then
+       if pkt == nil or pkt:rcode() ~= kres.rcode.NOERROR then
                warn("[priming] cannot resolve '.' NS, next priming query in %d seconds", priming.retry_time / sec)
                internal.event = event.after(priming.retry_time, internal.prime)
                return nil
index ce62c13edaf32124e77d5b12c343fca7f28eb64b..3abd2ccad242666a84c9ab2047b2569c542715c9 100644 (file)
@@ -252,7 +252,7 @@ end
 local function active_refresh(keyset, pkt, req, managed)
        local retry = true
 
-       if pkt:rcode() == kres.rcode.NOERROR then
+       if pkt ~= nil and pkt:rcode() == kres.rcode.NOERROR then
                local records = pkt:section(kres.section.ANSWER)
                local new_keys = {}
                for _, rr in ipairs(records) do
@@ -271,6 +271,8 @@ local function active_refresh(keyset, pkt, req, managed)
                local qry = req:initial()
                if qry.flags.DNSSEC_BOGUS == true then
                        warn('[ta_update] active refresh failed, update your trust anchors in "%s"', keyset.filename)
+               elseif pkt == nil then
+                       warn('[ta_update] active refresh failed, answer was dropped')
                else
                        warn('[ta_update] active refresh failed for ' .. kres.dname2str(keyset.owner)
                                .. ' with rcode: ' .. pkt:rcode())
index 1a8065fdd9e3d2ba4715b2d1c0afdcd1fa58334c..b7e162b9db1ea52ef14b58b7daa96d9ebb30dcc0 100644 (file)
@@ -32,13 +32,18 @@ end
 local function check_answer(logbuf)
        return function (pkt, req)
                req.trace_log:free()
-               if pkt:rcode() == kres.rcode.NOERROR or pkt:rcode() == kres.rcode.NXDOMAIN then
+               if pkt ~= nil and (pkt:rcode() == kres.rcode.NOERROR
+                                                       or pkt:rcode() == kres.rcode.NXDOMAIN) then
                        private.ok_callback()
                        return
                end
                log('[watchdog] watchdog query returned unexpected answer! query verbose log:')
                log(table.concat(logbuf, ''))
-               log('[watchdog] problematic answer:\n%s', pkt)
+               if pkt ~= nil then
+                       log('[watchdog] problematic answer:\n%s', pkt)
+               else
+                       log('[watchdog] answer was dropped')
+               end
                -- failure! quit immediatelly to allow process supervisor to restart us
                private.fail_callback()
        end
index afc713b282dddf4623e2f437d73c410c92133279..53b6c09c891760d9c5ec154b2506d4db1371fdc6 100644 (file)
@@ -63,6 +63,7 @@ function M.check_answer(desc, qname, qtype, expected_rcode, expected_rdata)
 
        local done = false
        local callback = function(pkt)
+               ok(pkt, 'answer not dropped')
                same(pkt:rcode(), wire_rcode,
                     desc .. ': expecting answer for query ' .. qname .. ' ' .. qtype_str
                      .. ' with rcode ' .. kres.tostring.rcode[wire_rcode])