Skip to content

Commit

Permalink
dns: add middleware property to root server to hijack queries
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Mar 4, 2021
1 parent df16daf commit 1cc2086
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/dns/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class RootServer extends DNSServer {
this.host = '127.0.0.1';
this.port = 5300;
this.lookup = null;
this.middle = null;
this.publicHost = '127.0.0.1';

// Plugins can add or remove items from
Expand Down Expand Up @@ -397,6 +398,27 @@ class RootServer extends DNSServer {
const {name, type} = qs;
const tld = util.from(name, -1);

// Plugins can insert middleware here and hijack the
// lookup for special TLDs before checking Urkel tree.
// We also pass the entire question in case a plugin
// is able to return an authoritative (non-referral) answer.
if (typeof this.middle === 'function') {
let res;
try {
res = await this.middle(tld, req);
} catch (e) {
this.logger.warning(
'Root server middleware resolution failed for name: %s',
name
);
this.logger.debug(e.stack);
}

if (res) {
return res;
}
}

// Hit the cache first.
const cache = this.cache.get(name, type);

Expand All @@ -421,6 +443,11 @@ class RootServer extends DNSServer {
return reserved.getByName(tld);
}

// Intended to be called by plugin.
signRRSet(rrset, type) {
key.signZSK(rrset, type);
}

resetCache() {
this.cache.reset();
}
Expand Down

0 comments on commit 1cc2086

Please sign in to comment.