From c88611d664e000e5ccdf143c64c2751591c41ca6 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 25 Sep 2023 13:59:44 +0200 Subject: [PATCH] Make QName Minimization parameters from RFC 9156 settable Also fix a counting ommission --- pdns/recursordist/rec-main.cc | 2 ++ pdns/recursordist/settings/table.py | 26 +++++++++++++++++++++++++- pdns/recursordist/syncres.cc | 15 ++++++++------- pdns/recursordist/syncres.hh | 2 ++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 25e6d7d74c..fd713a11fd 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -1687,6 +1687,8 @@ static int initSyncRes(Logr::log_t log) SyncRes::s_ecscachelimitttl = ::arg().asNum("ecs-cache-limit-ttl"); SyncRes::s_qnameminimization = ::arg().mustDo("qname-minimization"); + SyncRes::s_minimize_one_lab = ::arg().asNum("qname-minimize-one-label"); + SyncRes::s_max_minimize_count = ::arg().asNum("qname-max-minimize-count"); SyncRes::s_hardenNXD = SyncRes::HardenNXD::DNSSEC; string value = ::arg()["nothing-below-nxdomain"]; diff --git a/pdns/recursordist/settings/table.py b/pdns/recursordist/settings/table.py index e833fb6564..2a54dc1478 100644 --- a/pdns/recursordist/settings/table.py +++ b/pdns/recursordist/settings/table.py @@ -1955,10 +1955,34 @@ Path to the Public Suffix List file, if any. If set, PowerDNS will try to load t 'help' : 'Use Query Name Minimization', 'doc' : ''' Enable Query Name Minimization. This implements a relaxed form of Query Name Mimimization as -described in :rfc:`7816`. +described in :rfc:`9156`. ''', 'versionadded': '4.3.0' }, + { + 'name' : 'qname_max_minimize_count', + 'section' : 'recursor', + 'type' : LType.Uint64, + 'default' : '10', + 'help' : 'RFC9156 max minimize count', + 'doc' : ''' +``Max minimize count`` parameter, described in :rfc:`9156`. This is the maximum number of iterations +of the Quqey Name Minimization Algorithm. + ''', + 'versionadded': '5.0.0' + }, + { + 'name' : 'qname_minimize_one_label', + 'section' : 'recursor', + 'type' : LType.Uint64, + 'default' : '4', + 'help' : 'RFC9156 minimize one label parameter', + 'doc' : ''' +``Minimize one label`` parameter, described in :rfc:`9156`. +The value for the number of iterations of the Query Name Minimization Algorithm that should only have one label appended. + ''', + 'versionadded': '5.0.0' + }, { 'name' : 'source_address', 'section' : 'outgoing', diff --git a/pdns/recursordist/syncres.cc b/pdns/recursordist/syncres.cc index 129091b5db..2c779dddcf 100644 --- a/pdns/recursordist/syncres.cc +++ b/pdns/recursordist/syncres.cc @@ -1596,20 +1596,20 @@ LWResult::Result SyncRes::asyncresolveWrapper(const ComboAddress& address, bool } /* The parameters from rfc9156. */ -/* maximum number of QNAME minimisation iterations */ -static const unsigned int s_max_minimise_count = 10; -/* number of queries that should only have one label appended */ -static const unsigned int s_minimise_one_lab = 4; +/* maximum number of QNAME minimization iterations */ +unsigned int SyncRes::s_max_minimize_count; // default is 10 +/* number of iterations that should only have one label appended */ +unsigned int SyncRes::s_minimize_one_lab; // default is 4 static unsigned int qmStepLen(unsigned int labels, unsigned int qnamelen, unsigned int i) { unsigned int step; - if (i < s_minimise_one_lab) { + if (i < SyncRes::s_minimize_one_lab) { step = 1; } - else if (i < s_max_minimise_count) { - step = std::max(1U, (qnamelen - labels) / (10 - i)); + else if (i < SyncRes::s_max_minimize_count) { + step = std::max(1U, (qnamelen - labels) / (SyncRes::s_max_minimize_count - i)); } else { step = qnamelen - labels; @@ -1788,6 +1788,7 @@ int SyncRes::doResolve(const DNSName& qname, const QType qtype, vector