diff --git a/bin/digd.js b/bin/digd.js index c04e7bd..57da2f4 100755 --- a/bin/digd.js +++ b/bin/digd.js @@ -12,6 +12,10 @@ var common = require('dig.js/common'); var defaultNameservers = require('dns').getServers(); var hexdump; +var SERVFAIL = 2; +//var NXDOMAIN = 3; +var REFUSED = 5; + cli.parse({ // 'b': [ false, 'set source IP address (defaults to 0.0.0.0)', 'string' ] 'class': [ 'c', 'class (defaults to IN)', 'string', 'IN' ] @@ -170,9 +174,10 @@ cli.main(function (args, cli) { //common.writeResponse(opts, query, nb, packet); } - function sendEmptyResponse(query, nx) { + function sendEmptyResponse(query, rcode) { // rcode // 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 // 5 REFUSED // doesn't manage this domain var newAb; @@ -185,7 +190,7 @@ cli.main(function (args, cli) { , tc: 0 , rd: query.header.rd , 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: [] , answer: [] @@ -233,14 +238,14 @@ cli.main(function (args, cli) { function recurse() { if (!query.header.rd) { - console.log("[Could not answer. Sent empty response.]"); - sendEmptyResponse(query, true); + console.log("[DEV] no recursion desired. Sending empty response.]"); + sendEmptyResponse(query, SERVFAIL); return; } if (cli.norecurse) { - console.log("[Could not answer. Sent empty response.]"); - sendEmptyResponse(query, true); + console.log("[DEV] recursion forbidden. Sending empty response.]"); + sendEmptyResponse(query, REFUSED); return; } @@ -358,7 +363,7 @@ cli.main(function (args, cli) { // TODO get local answer first, if available 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); });