until.tv_sec += actualSeconds;
for (const auto& capair : m) {
unsigned int count = 0;
+ /* this legacy interface does not support ranges or ports, use DynBlockRulesGroup instead */
AddressAndPortRange requestor(capair.first, capair.first.isIPv4() ? 32 : 128, 0);
auto got = slow.lookup(requestor);
bool expired = false;
void DynBlockRulesGroup::addOrRefreshBlock(boost::optional<NetmaskTree<DynBlock, AddressAndPortRange> >& blocks, const struct timespec& now, const AddressAndPortRange& requestor, const DynBlockRule& rule, bool& updated, bool warning)
{
+ /* network exclusions are address-based only (no port) */
if (d_excludedSubnets.match(requestor.getNetwork())) {
/* do not add a block for excluded subnets */
return;
struct timespec until = now;
until.tv_sec += rule.d_blockDuration;
unsigned int count = 0;
- const auto& got = blocks->lookup(requestor.getNetwork());
+ const auto& got = blocks->lookup(requestor);
bool expired = false;
bool wasWarning = false;
bool bpf = false;
if (db.action == DNSAction::Action::Drop && g_defaultBPFFilter &&
((requestor.isIPv4() && requestor.getBits() == 32) || (requestor.isIPv6() && requestor.getBits() == 128))) {
try {
+ /* the current BPF filter implementation only supports full addresses (/32 or /128) and no port */
g_defaultBPFFilter->block(requestor.getNetwork());
bpf = true;
}
/* outside of the range should not */
BOOST_CHECK(g_dynblockNMG.getLocal()->lookup(AddressAndPortRange(ComboAddress("192.0.2.1:16384"), 32, 16)) == nullptr);
}
+
+ /* we (again) insert just above 50 qps from several clients the same IPv4 port range, this should update the block which will
+ check by looking at the blocked counter */
+ {
+ auto block = g_dynblockNMG.getLocal()->lookup(AddressAndPortRange(ComboAddress("192.0.2.1:0"), 32, 16));
+ BOOST_REQUIRE(block != nullptr);
+ BOOST_CHECK_EQUAL(block->second.blocks, 0U);
+ block->second.blocks = 42U;
+ }
+
+ g_rings.clear();
+ BOOST_CHECK_EQUAL(g_rings.getNumberOfQueryEntries(), 0U);
+
+ for (size_t idx = 0; idx < numberOfQueries; idx++) {
+ ComboAddress requestor("192.0.2.1:" + std::to_string(idx));
+ g_rings.insertQuery(now, requestor, qname, qtype, size, dh, protocol);
+ g_rings.insertResponse(now, requestor, qname, qtype, responseTime, size, dh, backend, outgoingProtocol);
+ }
+ BOOST_CHECK_EQUAL(g_rings.getNumberOfQueryEntries(), numberOfQueries);
+
+ dbrg.apply(now);
+
+ BOOST_CHECK_EQUAL(g_dynblockNMG.getLocal()->size(), 1U);
+ {
+ /* previous address/port should still be blocked */
+ auto block = g_dynblockNMG.getLocal()->lookup(AddressAndPortRange(ComboAddress("192.0.2.1:0"), 32, 16));
+ BOOST_REQUIRE(block != nullptr);
+ BOOST_CHECK_EQUAL(block->second.blocks, 42U);
+ }
+
+ /* but not a different one */
+ BOOST_CHECK(g_dynblockNMG.getLocal()->lookup(AddressAndPortRange(ComboAddress("192.0.2.1:16384"), 32, 16)) == nullptr);
+
}
}