From: Otto Date: Wed, 24 Nov 2021 16:29:38 +0000 (+0100) Subject: Compute step sizes for QM a la RFC 9156 X-Git-Tag: rec-4.7.0-alpha0~9^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d948586b66908d174b70f35e10db304a94d5ed67;p=thirdparty%2Fpdns.git Compute step sizes for QM a la RFC 9156 --- diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 92344dd931..426e8bb709 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -677,6 +677,25 @@ LWResult::Result SyncRes::asyncresolveWrapper(const ComboAddress& ip, bool ednsM #define QLOG(x) LOG(prefix << " child=" << child << ": " << x << endl) +/* The parameters from rfc9156. */ +static const unsigned int s_max_minimise_count = 10; +static const unsigned int s_minimise_one_lab = 4; + +static unsigned int qmStepLen(unsigned int labels, unsigned int qnamelen, unsigned int i) +{ + unsigned int step; + + if (i < s_minimise_one_lab) { + step = 1; + } else if (i < s_max_minimise_count) { + step = std::max(1U, (qnamelen - labels) / (10 - i)); + } else { + step = qnamelen - labels; + } + unsigned int targetlen = std::min(labels + step, qnamelen); + return targetlen; +} + int SyncRes::doResolve(const DNSName &qname, const QType qtype, vector&ret, unsigned int depth, set& beenthere, vState& state) { string prefix = d_prefix; @@ -786,16 +805,15 @@ int SyncRes::doResolve(const DNSName &qname, const QType qtype, vector 3 ? 3 : 1), qnamelen); - for (; i <= qnamelen; i++) { // Step 2 - while (child.countLabels() < targetlen) { - child.prependRawLabel(qname.getRawLabel(qnamelen - child.countLabels() - 1)); + unsigned int labels = child.countLabels(); + unsigned int targetlen = qmStepLen(labels, qnamelen, i); + + while (labels < targetlen) { + child.prependRawLabel(qname.getRawLabel(qnamelen - labels - 1)); + labels++; } - targetlen += i > 3 ? 3 : 1; - targetlen = std::min(targetlen, qnamelen); QLOG("Step2 New child");