Skip to content

Commit

Permalink
Make QNAme Minimization parameters from RFC 9156 settable
Browse files Browse the repository at this point in the history
Also fix a counting ommission
  • Loading branch information
omoerbeek committed Sep 25, 2023
1 parent 0ef891c commit 866140a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pdns/recursordist/rec-main.cc
Expand Up @@ -1685,6 +1685,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");

if (SyncRes::s_qnameminimization) {
// With an empty cache, a rev ipv6 query with dnssec enabled takes
Expand Down
26 changes: 25 additions & 1 deletion pdns/recursordist/settings/table.py
Expand Up @@ -1955,10 +1955,34 @@
'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',
Expand Down
15 changes: 8 additions & 7 deletions pdns/recursordist/syncres.cc
Expand Up @@ -1577,20 +1577,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;
Expand Down Expand Up @@ -1769,6 +1769,7 @@ int SyncRes::doResolve(const DNSName& qname, const QType qtype, vector<DNSRecord
LOG(prefix << qname << ": Step4 Resolve " << child << "|A result is " << RCode::to_s(res) << "/" << retq.size() << "/" << stopAtDelegation << endl);
if (stopAtDelegation == Stopped) {
LOG(prefix << qname << ": Delegation seen, continue at step 1" << endl);
i++;
break;
}

Expand Down
2 changes: 2 additions & 0 deletions pdns/recursordist/syncres.hh
Expand Up @@ -548,6 +548,8 @@ public:
static bool s_dot_to_port_853;
static unsigned int s_max_busy_dot_probes;
static unsigned int s_max_CNAMES_followed;
static unsigned int s_max_minimize_count;
static unsigned int s_minimize_one_lab;

static const int event_trace_to_pb = 1;
static const int event_trace_to_log = 2;
Expand Down

0 comments on commit 866140a

Please sign in to comment.