From: bert hubert Date: Fri, 25 Aug 2017 11:59:00 +0000 (+0200) Subject: make sure stats get updated in all the right places, plus factor out the updating... X-Git-Tag: auth-4.1.0-rc1~2^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=701f690b7661dbf0899bf71e103db1b10fa08355;p=pdns make sure stats get updated in all the right places, plus factor out the updating to a function --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 7466b7d54..725d07b2e 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -877,6 +877,11 @@ bool processQuery(LocalStateHolder >& localDynNMGBlock, } if(auto got=localDynNMGBlock->lookup(*dq.remote)) { + auto updateBlockStats = [&got]() { + g_stats.dynBlocked++; + got->second.blocks++; + }; + if(now < got->second.until) { DNSAction::Action action = got->second.action; if (action == DNSAction::Action::None) { @@ -884,8 +889,7 @@ bool processQuery(LocalStateHolder >& localDynNMGBlock, } if (action == DNSAction::Action::Refused) { vinfolog("Query from %s refused because of dynamic block", dq.remote->toStringWithPort()); - g_stats.dynBlocked++; - got->second.blocks++; + updateBlockStats(); dq.dh->rcode = RCode::Refused; dq.dh->qr=true; @@ -893,9 +897,7 @@ bool processQuery(LocalStateHolder >& localDynNMGBlock, } else if (action == DNSAction::Action::Truncate) { if(!dq.tcp) { - g_stats.dynBlocked++; - got->second.blocks++; - + updateBlockStats(); vinfolog("Query from %s truncated because of dynamic block", dq.remote->toStringWithPort()); dq.dh->tc = true; dq.dh->qr = true; @@ -907,6 +909,7 @@ bool processQuery(LocalStateHolder >& localDynNMGBlock, } else { + updateBlockStats(); vinfolog("Query from %s dropped because of dynamic block", dq.remote->toStringWithPort()); return false; } @@ -914,6 +917,11 @@ bool processQuery(LocalStateHolder >& localDynNMGBlock, } if(auto got=localDynSMTBlock->lookup(*dq.qname)) { + auto updateBlockStats = [&got]() { + g_stats.dynBlocked++; + got->blocks++; + }; + if(now < got->until) { DNSAction::Action action = got->action; if (action == DNSAction::Action::None) { @@ -921,8 +929,7 @@ bool processQuery(LocalStateHolder >& localDynNMGBlock, } if (action == DNSAction::Action::Refused) { vinfolog("Query from %s for %s refused because of dynamic block", dq.remote->toStringWithPort(), dq.qname->toString()); - g_stats.dynBlocked++; - got->blocks++; + updateBlockStats(); dq.dh->rcode = RCode::Refused; dq.dh->qr=true; @@ -930,8 +937,7 @@ bool processQuery(LocalStateHolder >& localDynNMGBlock, } else if (action == DNSAction::Action::Truncate) { if(!dq.tcp) { - g_stats.dynBlocked++; - got->blocks++; + updateBlockStats(); vinfolog("Query from %s for %s truncated because of dynamic block", dq.remote->toStringWithPort(), dq.qname->toString()); dq.dh->tc = true; @@ -943,6 +949,7 @@ bool processQuery(LocalStateHolder >& localDynNMGBlock, } } else { + updateBlockStats(); vinfolog("Query from %s for %s dropped because of dynamic block", dq.remote->toStringWithPort(), dq.qname->toString()); return false; }