const auto& tagValue = got->second.tagSettings->d_value;
dnsQuestion.setTag(tagName, tagValue);
vinfolog("Query from %s setting tag %s to %s because of dynamic block", dnsQuestion.ids.origRemote.toStringWithPort(), tagName, tagValue);
- return true;
+ // do not return, the whole point it to set a Tag to be able to do further processing in rules
+ break;
}
default:
updateBlockStats();
const auto& tagValue = got->tagSettings->d_value;
dnsQuestion.setTag(tagName, tagValue);
vinfolog("Query from %s setting tag %s to %s because of dynamic block", dnsQuestion.ids.origRemote.toStringWithPort(), tagName, tagValue);
- return true;
+ // do not return, the whole point it to set a Tag to be able to do further processing in rules
+ break;
}
default:
updateBlockStats();
local dbr = dynBlockRulesGroup()
dbr:setCacheMissRatio(0.8, %d, "Exceeded cache miss ratio", %d, 20, 0.0, DNSAction.SetTag, 0.0, { tagName='dyn-miss-ratio', tagValue='hit' })
+ -- check that the tag is set and query rules executed
+ addAction(AndRule{QNameRule("test-query-rules.cachemissratio-settag.group.dynblocks.tests.powerdns.com."), TagRule('dyn-miss-ratio', 'hit')}, SpoofAction("192.0.2.2"))
+
-- on a cache miss, and if the cache miss ratio threshold was exceeded, send a REFUSED response
addCacheMissAction(TagRule('dyn-miss-ratio', 'hit'), RCodeAction(DNSRCode.REFUSED))
(_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=0.5)
self.assertEqual(receivedResponse, expectedResponse)
+ # this specific query will match the query rules before triggering a cache miss
+ # so we can check that the tag is correctly set for query rules as well
+ query = dns.message.make_query('test-query-rules.' + name, 'A', 'IN')
+ # dnsdist sets RA = RD for TC responses
+ query.flags &= ~dns.flags.RD
+ expectedResponse = dns.message.make_response(query)
+ queryRulesRRset = dns.rrset.from_text('test-query-rules.' + name,
+ 60,
+ dns.rdataclass.IN,
+ dns.rdatatype.A,
+ '192.0.2.2')
+ expectedResponse.answer.append(queryRulesRRset)
+ (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=0.5)
+ self.assertEqual(receivedResponse, expectedResponse)
+
# wait until we are not blocked anymore
time.sleep(self._dynBlockDuration + self._dynBlockPeriod)