minor fixes
This commit is contained in:
parent
d26b671176
commit
717fb1fe3e
11
bin/digd.js
11
bin/digd.js
|
@ -107,6 +107,7 @@ cli.main(function (args, cli) {
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// TODO log bad queries (?)
|
// TODO log bad queries (?)
|
||||||
console.error("Could not parse DNS query, ignoring.");
|
console.error("Could not parse DNS query, ignoring.");
|
||||||
|
console.error(e);
|
||||||
try {
|
try {
|
||||||
hexdump = require('hexdump.js').hexdump;
|
hexdump = require('hexdump.js').hexdump;
|
||||||
console.error(hexdump(queryAb));
|
console.error(hexdump(queryAb));
|
||||||
|
@ -211,7 +212,8 @@ cli.main(function (args, cli) {
|
||||||
try {
|
try {
|
||||||
newAb = dnsjs.DNSPacket.write(emptyResp);
|
newAb = dnsjs.DNSPacket.write(emptyResp);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error("Could not write DNS response");
|
console.error("Could not write empty DNS response");
|
||||||
|
console.error(e);
|
||||||
console.error(emptyResp);
|
console.error(emptyResp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +229,8 @@ cli.main(function (args, cli) {
|
||||||
try {
|
try {
|
||||||
newAb = dnsjs.DNSPacket.write(newPacket);
|
newAb = dnsjs.DNSPacket.write(newPacket);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error("Could not write DNS response");
|
console.error("Could not write DNS response from local");
|
||||||
|
console.error(e);
|
||||||
console.error(newPacket);
|
console.error(newPacket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -365,10 +368,14 @@ cli.main(function (args, cli) {
|
||||||
// TODO get local answer first, if available
|
// TODO get local answer first, if available
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
require('../lib/dns-store').query(path.resolve(cli.input), query, function (err, resp) {
|
require('../lib/dns-store').query(path.resolve(cli.input), query, function (err, resp) {
|
||||||
|
|
||||||
if (err) { console.log('[DEV] answer not found in local db, recursing'); console.error(err); recurse(); return; }
|
if (err) { console.log('[DEV] answer not found in local db, recursing'); console.error(err); recurse(); return; }
|
||||||
|
|
||||||
if (SERVFAIL === resp.header.rcode) { console.log('[DEV] local cache miss, recursing'); recurse(); return; }
|
if (SERVFAIL === resp.header.rcode) { console.log('[DEV] local cache miss, recursing'); recurse(); return; }
|
||||||
|
|
||||||
|
// TODO double check does it matter whether rd is set when responding with ra?
|
||||||
|
if (!cli.norecurse && query.header.rd) { resp.header.ra = 1; }
|
||||||
|
|
||||||
sendResponse(resp);
|
sendResponse(resp);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ module.exports.ask = function (query, cb) {
|
||||||
var NOERROR = 0;
|
var NOERROR = 0;
|
||||||
var NXDOMAIN = 3;
|
var NXDOMAIN = 3;
|
||||||
var REFUSED = 5;
|
var REFUSED = 5;
|
||||||
|
var primaryNameservers = [ 'localhost' ];
|
||||||
|
|
||||||
function getRecords(db, qname) {
|
function getRecords(db, qname) {
|
||||||
var myRecords = db.records.filter(function (r) {
|
var myRecords = db.records.filter(function (r) {
|
||||||
|
@ -64,6 +65,8 @@ function dbToResourceRecord(r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNs(db, ds, results, cb) {
|
function getNs(db, ds, results, cb) {
|
||||||
|
console.log('[DEV] getNs entered');
|
||||||
|
|
||||||
var d = ds.shift();
|
var d = ds.shift();
|
||||||
|
|
||||||
if (!d) {
|
if (!d) {
|
||||||
|
@ -78,24 +81,39 @@ function getNs(db, ds, results, cb) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
results.authority.push({
|
var ns = {
|
||||||
name: r.domain
|
name: r.domain
|
||||||
, typeName: r.type // NS
|
, typeName: r.type // NS
|
||||||
, className: 'IN'
|
, className: 'IN'
|
||||||
, ttl: r.ttl || 300
|
, ttl: r.ttl || 300
|
||||||
, data: r.value
|
, data: r.address || r.value || r.data
|
||||||
});
|
};
|
||||||
|
|
||||||
|
console.log('got NS record:');
|
||||||
|
console.log(r);
|
||||||
|
console.log(ns);
|
||||||
|
|
||||||
|
// TODO what if this NS is one of the NS?
|
||||||
|
// return SOA record instead
|
||||||
|
results.authority.push(ns);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (results.authority.length) {
|
if (results.authority.length) {
|
||||||
cb(null, results);
|
cb(null, results);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
results.header.rcode = NXDOMAIN;
|
||||||
|
cb(null, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSoa(db, domain, results, cb) {
|
function getSoa(db, domain, results, cb) {
|
||||||
var index = Math.floor(Math.random() * domain.nameservers.length) % domain.nameservers.length;
|
console.log('[DEV] getSoa entered');
|
||||||
var nameserver = domain.nameservers[index];
|
|
||||||
|
var nameservers = domain.nameservers || primaryNameservers;
|
||||||
|
|
||||||
|
var index = Math.floor(Math.random() * nameservers.length) % nameservers.length;
|
||||||
|
var nameserver = nameservers[index];
|
||||||
|
|
||||||
results.authority.push({
|
results.authority.push({
|
||||||
name: domain.id
|
name: domain.id
|
||||||
|
@ -108,12 +126,12 @@ function getSoa(db, domain, results, cb) {
|
||||||
, name_server: nameserver
|
, name_server: nameserver
|
||||||
|
|
||||||
// admin -- email address or domain for admin
|
// admin -- email address or domain for admin
|
||||||
, admin: domain.admin
|
, admin: domain.admin || ('admin.' + domain.id)
|
||||||
, email_addr: domain.admin
|
, email_addr: domain.admin || ('admin.' + domain.id)
|
||||||
|
|
||||||
// serial -- the version, for cache-busting of secondary nameservers. suggested format: YYYYMMDDnn
|
// serial -- the version, for cache-busting of secondary nameservers. suggested format: YYYYMMDDnn
|
||||||
, serial: domain.serial || Math.round((domain.updatedAt || domain.createdAt) / 1000)
|
, serial: domain.serial || Math.round((domain.updatedAt || domain.createdAt || 0) / 1000)
|
||||||
, sn: domain.serial || Math.round((domain.updatedAt || domain.createdAt) / 1000)
|
, sn: domain.serial || Math.round((domain.updatedAt || domain.createdAt || 0) / 1000)
|
||||||
|
|
||||||
// refresh -- only used when nameservers following the DNS NOTIFY spec talk
|
// refresh -- only used when nameservers following the DNS NOTIFY spec talk
|
||||||
, refresh: domain.refresh || 1800
|
, refresh: domain.refresh || 1800
|
||||||
|
@ -184,7 +202,7 @@ module.exports.query = function (input, query, cb) {
|
||||||
, ra: 0 // will be changed by cli.norecurse
|
, ra: 0 // will be changed by cli.norecurse
|
||||||
, rcode: NOERROR // 0 NOERROR, 3 NXDOMAIN, 5 REFUSED
|
, rcode: NOERROR // 0 NOERROR, 3 NXDOMAIN, 5 REFUSED
|
||||||
}
|
}
|
||||||
, question: [], answer: [], authority: [], additional: []
|
, question: [ query.question[0] ], answer: [], authority: [], additional: []
|
||||||
};
|
};
|
||||||
|
|
||||||
var myRecords = getRecords(db, qname);
|
var myRecords = getRecords(db, qname);
|
||||||
|
@ -194,6 +212,7 @@ module.exports.query = function (input, query, cb) {
|
||||||
results.answer.push(dbToResourceRecord(r));
|
results.answer.push(dbToResourceRecord(r));
|
||||||
});
|
});
|
||||||
results.header.rcode = NOERROR;
|
results.header.rcode = NOERROR;
|
||||||
|
console.log('[DEV] results', results);
|
||||||
cb(null, results);
|
cb(null, results);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -246,10 +265,12 @@ module.exports.query = function (input, query, cb) {
|
||||||
console.log('sorted domains', myDomains);
|
console.log('sorted domains', myDomains);
|
||||||
|
|
||||||
return getNs(db, myDomains.slice(0), results, function (err, results) {
|
return getNs(db, myDomains.slice(0), results, function (err, results) {
|
||||||
|
console.log('[DEV] getNs complete');
|
||||||
|
|
||||||
if (err) { cb(err, results); return; }
|
if (err) { cb(err, results); return; }
|
||||||
|
|
||||||
// has NS records
|
// has NS records
|
||||||
if (NXDOMAIN !== results.header.rcode) { cb(null, results); return; }
|
if (NXDOMAIN !== results.header.rcode) { console.log(results); cb(null, results); return; }
|
||||||
|
|
||||||
// myDomains was sorted such that the longest was first
|
// myDomains was sorted such that the longest was first
|
||||||
getSoa(db, myDomains[0], results, cb);
|
getSoa(db, myDomains[0], results, cb);
|
||||||
|
|
Loading…
Reference in New Issue