use proper rcodes

This commit is contained in:
AJ ONeal 2017-10-06 17:27:17 -06:00
parent f945da161b
commit 0151500ac8
1 changed files with 12 additions and 7 deletions

View File

@ -12,6 +12,10 @@ var common = require('dig.js/common');
var defaultNameservers = require('dns').getServers(); var defaultNameservers = require('dns').getServers();
var hexdump; var hexdump;
var SERVFAIL = 2;
//var NXDOMAIN = 3;
var REFUSED = 5;
cli.parse({ cli.parse({
// 'b': [ false, 'set source IP address (defaults to 0.0.0.0)', 'string' ] // 'b': [ false, 'set source IP address (defaults to 0.0.0.0)', 'string' ]
'class': [ 'c', 'class (defaults to IN)', 'string', 'IN' ] 'class': [ 'c', 'class (defaults to IN)', 'string', 'IN' ]
@ -170,9 +174,10 @@ cli.main(function (args, cli) {
//common.writeResponse(opts, query, nb, packet); //common.writeResponse(opts, query, nb, packet);
} }
function sendEmptyResponse(query, nx) { function sendEmptyResponse(query, rcode) {
// rcode // rcode
// 0 SUCCESS // manages this domain and found a record // 0 SUCCESS // manages this domain and found a record
// 2 SERVFAIL // could not contact authoritatve nameserver (no recursion, etc)
// 3 NXDOMAIN // manages this domain, but doesn't have a record // 3 NXDOMAIN // manages this domain, but doesn't have a record
// 5 REFUSED // doesn't manage this domain // 5 REFUSED // doesn't manage this domain
var newAb; var newAb;
@ -185,7 +190,7 @@ cli.main(function (args, cli) {
, tc: 0 , tc: 0
, rd: query.header.rd , rd: query.header.rd
, ra: cli.norecurse ? 0 : 1 // TODO is this bit dependent on the rd bit? , ra: cli.norecurse ? 0 : 1 // TODO is this bit dependent on the rd bit?
, rcode: nx ? 3 : 0 // no error , rcode: rcode ? rcode : 0 // no error
} }
, question: [] , question: []
, answer: [] , answer: []
@ -233,14 +238,14 @@ cli.main(function (args, cli) {
function recurse() { function recurse() {
if (!query.header.rd) { if (!query.header.rd) {
console.log("[Could not answer. Sent empty response.]"); console.log("[DEV] no recursion desired. Sending empty response.]");
sendEmptyResponse(query, true); sendEmptyResponse(query, SERVFAIL);
return; return;
} }
if (cli.norecurse) { if (cli.norecurse) {
console.log("[Could not answer. Sent empty response.]"); console.log("[DEV] recursion forbidden. Sending empty response.]");
sendEmptyResponse(query, true); sendEmptyResponse(query, REFUSED);
return; return;
} }
@ -358,7 +363,7 @@ cli.main(function (args, cli) {
// TODO get local answer first, if available // TODO get local answer first, if available
require('../lib/dns-store').query(cli.input, query, function (err, resp) { require('../lib/dns-store').query(cli.input, query, function (err, resp) {
if (err) { recurse(); return; } if (err) { console.log('[DEV] answer not found in local db, recursing'); recurse(); return; }
sendResponse(resp); sendResponse(resp);
}); });