maker rr more similar to node-dns
This commit is contained in:
		
							parent
							
								
									3692e4c828
								
							
						
					
					
						commit
						eca24330e1
					
				| @ -2,6 +2,7 @@ | ||||
| 'use strict'; | ||||
| 
 | ||||
| // http://www.zytrax.com/books/dns/ch8/soa.html
 | ||||
| // https://github.com/tjfontaine/node-dns#resourcerecord
 | ||||
| 
 | ||||
| // Value              Meaning/Use
 | ||||
| // Primary NS         Variable length. The name of the Primary Master for the domain. May be a label, pointer, or any combination
 | ||||
| @ -13,25 +14,25 @@ | ||||
| // Minimum TTL        Unsigned 32-bit integer
 | ||||
| 
 | ||||
| exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) { | ||||
|   if(!record.name_server){ | ||||
|   if(!record.primary && !record.name_server){ | ||||
|     throw new Error("no name server for SOA record"); | ||||
|   } | ||||
|   if(!record.email_addr){ | ||||
|   if(!record.admin && !record.email_addr){ | ||||
|     throw new Error("ne email address for SOA record"); | ||||
|   } | ||||
|   if(!record.sn){ | ||||
|   if(!record.serial && !record.sn){ | ||||
|     throw new Error("no serial number for SOA record"); | ||||
|   } | ||||
|   if(!record.ref){ | ||||
|   if(!record.refresh && !record.ref){ | ||||
|     throw new Error("no refresh for SOA record"); | ||||
|   } | ||||
|   if(!record.ret){ | ||||
|   if(!record.retry && !record.ret){ | ||||
|     throw new Error("no update retry for SOA record"); | ||||
|   } | ||||
|   if(!record.ex){ | ||||
|   if(!record.expiration && !record.ex){ | ||||
|     throw new Error("no expiry for SOA record"); | ||||
|   } | ||||
|   if(!record.nx){ | ||||
|   if(!record.minimum && !record.nx){ | ||||
|     throw new Error("no nxdomain for SOA record"); | ||||
|   } | ||||
| 
 | ||||
| @ -40,9 +41,9 @@ exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) { | ||||
|   var rdLenIndex = total; | ||||
|   total += 2; // Save space for RDLENGTH
 | ||||
| 
 | ||||
|   console.log('record.name_server', 1 + record.name_server.length, record.name_server); | ||||
|   //console.log('record.name_server', 1 + record.name_server.length, record.name_server);
 | ||||
|   // pack name_server which is a sequence of labels
 | ||||
|   record.name_server.split('.').forEach(function (label) { | ||||
|   (record.primary || record.name_server).split('.').forEach(function (label) { | ||||
|     soaLen += (1 + label.length); | ||||
| 
 | ||||
|     dv.setUint8(total, label.length, false); | ||||
| @ -58,9 +59,9 @@ exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) { | ||||
|   total += 1; | ||||
|   soaLen += 1; | ||||
| 
 | ||||
|   console.log('record.email_addr', 1 + record.email_addr.length, record.email_addr); | ||||
|   //console.log('record.email_addr', 1 + record.email_addr.length, record.email_addr);
 | ||||
|   // pack email address which is a sequence of labels
 | ||||
|   record.email_addr.split('.').forEach(function (label) { | ||||
|   (record.admin || record.email_addr).split('.').forEach(function (label) { | ||||
|     soaLen += 1 + label.length; | ||||
| 
 | ||||
|     dv.setUint8(total, label.length, false); | ||||
| @ -77,20 +78,20 @@ exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) { | ||||
|   soaLen += 1; | ||||
| 
 | ||||
|   // pack all 32-bit values
 | ||||
|   dv.setUint32(total, parseInt(record.sn, 10), false); | ||||
|   dv.setUint32(total, parseInt(record.serial || record.sn, 10), false); | ||||
|   total+=4; | ||||
|   dv.setUint32(total, parseInt(record.ref, 10), false); | ||||
|   dv.setUint32(total, parseInt(record.refresh || record.ref, 10), false); | ||||
|   total+=4; | ||||
|   dv.setUint32(total, parseInt(record.ret, 10), false); | ||||
|   dv.setUint32(total, parseInt(record.retry || record.ret, 10), false); | ||||
|   total+=4; | ||||
|   dv.setUint32(total, parseInt(record.ex, 10), false); | ||||
|   dv.setUint32(total, parseInt(record.expiration || record.ex, 10), false); | ||||
|   total+=4; | ||||
|   dv.setUint32(total, parseInt(record.nx, 10), false); | ||||
|   dv.setUint32(total, parseInt(record.minimum || record.nx, 10), false); | ||||
|   total+=4; | ||||
| 
 | ||||
|   // RDLENGTH
 | ||||
|   console.log('rdAt', rdLenIndex); | ||||
|   console.log('soaLen (lables + 2 + 20)', soaLen); | ||||
|   //console.log('rdAt', rdLenIndex);
 | ||||
|   //console.log('soaLen (lables + 2 + 20)', soaLen);
 | ||||
|   dv.setUint16(rdLenIndex, soaLen, false); | ||||
| 
 | ||||
|   return total; | ||||
|  | ||||
| @ -13,18 +13,22 @@ | ||||
| var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS; | ||||
| 
 | ||||
| exports.DNS_PARSER_TYPE_SOA = function (ab, packet, record) { | ||||
|   //
 | ||||
|   // Look!
 | ||||
|   // http://www.peerwisdom.org/2013/05/15/dns-understanding-the-soa-record/
 | ||||
| 
 | ||||
|   var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength); | ||||
|   var dv = new DataView(rdataAb); | ||||
| 
 | ||||
|   // we need this information for this parser
 | ||||
|   var labelInfo = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }); | ||||
|   var cpcount = labelInfo.cpcount; | ||||
|   //var cpcount = labelInfo.cpcount;
 | ||||
|   var offset = labelInfo.byteLength; | ||||
|   var labels = labelInfo.labels; | ||||
|   //var labels = labelInfo.labels;
 | ||||
| 
 | ||||
|   // Primary NS
 | ||||
|   record.name_server = labelInfo.name; | ||||
|   record.primary = labelInfo.name; | ||||
|   record.name_server = record.primary; | ||||
| 
 | ||||
|   // TODO delete this commented out code after some testing
 | ||||
|   // (pretty sure it was unnecessary and it seemed to work on code with compression pointers just fine)
 | ||||
| @ -52,18 +56,19 @@ exports.DNS_PARSER_TYPE_SOA = function (ab, packet, record) { | ||||
|     record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart + offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; | ||||
|   } | ||||
|   */ | ||||
|   record.email_addr = unpackLabels(new Uint8Array(ab), record.rdstart + offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; | ||||
|   record.admin = unpackLabels(new Uint8Array(ab), record.rdstart + offset, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; | ||||
|   record.email_addr = record.admin; | ||||
| 
 | ||||
|   // Serial Number
 | ||||
|   record.sn = dv.getUint32(dv.byteLength - 20, false); | ||||
|   record.serial = record.sn = dv.getUint32(dv.byteLength - 20, false); | ||||
|   // Refresh Interval
 | ||||
|   record.ref = dv.getUint32(dv.byteLength - 16, false); | ||||
|   record.refresh = record.ref = dv.getUint32(dv.byteLength - 16, false); | ||||
|   // Retry Interval
 | ||||
|   record.ret = dv.getUint32(dv.byteLength - 12, false); | ||||
|   record.retry = record.ret = dv.getUint32(dv.byteLength - 12, false); | ||||
|   // Expiration Limit
 | ||||
|   record.ex = dv.getUint32(dv.byteLength - 8, false); | ||||
|   record.expiration = record.ex = dv.getUint32(dv.byteLength - 8, false); | ||||
|   // Minimum TTL
 | ||||
|   record.nx = dv.getUint32(dv.byteLength - 4, false); | ||||
|   record.minimum = record.nx = dv.getUint32(dv.byteLength - 4, false); | ||||
| 
 | ||||
|   return record; | ||||
| }; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user