completed SOA rdata packer. Need to make automated test to see if bin and JSON conversions match

This commit is contained in:
Daplie 2017-03-16 18:48:08 -06:00
commit e98b3dd1a6
43 changed files with 83 additions and 661 deletions

View File

@ -48,19 +48,31 @@ Similar API to `dns.js` and `native-dns-packet`.
} }
``` ```
Install Install with git
------- -------
You can use git to install v1.x (and get updates) or just v1.0.x (and only get patches). You can use git to install v1.x like so:
The API will not break until v2.
```bash ```bash
# latest of v1.x # latest of v1.x
npm install 'git+https://git@git.daplie.com:Daplie/dns-suite#v1' npm install 'git+https://git@git.daplie.com:Daplie/dns-suite#v1'
``` ```
Don't have git? You can bow down to the gods of the centralized, monopolized, concentrated, dictatornet If you want to be more specific to v1.0.x or exactly v1.0.2 you can do so like this:
(as we like to call it here at Daplie Labs):
```
# latest of v1.0.x
npm install 'git+https://git@git.daplie.com:Daplie/dns-suite#v1.0'
# exactly v1.0.2
npm install 'git+https://git@git.daplie.com:Daplie/dns-suite#v1.0.2'
```
Install without git
-------
Don't have git? Well you can also bow down to the gods of the centralized, monopolized, concentrated, dictatornet
(as we like to call it here at Daplie Labs), if that's how you roll:
``` ```
npm install --save dns-suite npm install --save dns-suite

View File

@ -1,10 +1,24 @@
(function (exports) { (function (exports) {
'use strict'; 'use strict';
// Value Meaning/Use
// Primary NS Variable length. The name of the Primary Master for the domain. May be a label, pointer, or any combination
// Admin MB Variable length. The administrator's mailbox. May be a label, pointer, or any combination
// Serial Number Unsigned 32-bit integer
// Refresh Interval Unsigned 32-bit integer
// Retry Interval Unsigned 32-bit integer
// Expiration Limit Unsigned 32-bit integer
// Minimum TTL Unsigned 32-bit integer
exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) { exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) {
if(!record.name_server){
throw new Error("no name server for SOA record");
}
if(!record.email_addr){
throw new Error("ne email address for SOA record");
}
if(!record.sn){ if(!record.sn){
throw new Error("no serial number for SOA record"); throw new Error("no serial number for SOA record");
} }
@ -21,8 +35,51 @@ exports.DNS_PACKER_TYPE_SOA = function (ab, dv, total, record) {
throw new Error("no serial number for SOA record"); throw new Error("no serial number for SOA record");
} }
var soaLen = 20; // take into account sn, ref, ret, ex, and nx
// (32-bits each. 4Bytes * 5 = 20)
var rdLenIndex = total;
total += 2; // Save space for RDLENGTH
// pack name_server which is a sequence of labels
record.name_server.split('.').forEach(function(label){
soaLen += 1 + label.length;
dv.setUint8(total, label.length, false);
total += 1;
label.split('').forEach(function(ch) {
dv.setUint8(total, ch.charCodeAt(0), false);
total += 1;
});
});
// pack email address which is a sequence of labels
record.email_addr.split('.').forEach(function (label){
soaLen += 1 + label.length;
dv.setUint8(total, label.length, false);
total += 1;
label.split('').forEach(function (ch){
dv.setUint8(total, ch.charCodeAt(0), false);
total += 1;
});
});
// pack all 32-bit values
dv.setUint32(total, parseInt(record.sn, 10), false);
total+=4;
dv.setUint32(total, parseInt(record.ref, 10), false);
total+=4;
dv.setUint32(total, parseInt(record.ret, 10), false);
total+=4;
dv.setUint32(total, parseInt(record.ex, 10), false);
total+=4;
dv.setUint32(total, parseInt(record.nx, 10), false);
total+=4;
// RDLENGTH
dv.setUint16(rdLenIndex, soaLen, false);
return total; return total;
}; };

View File

@ -36,7 +36,7 @@ exports.DNS_PACKER_TYPE_SRV = function (ab, dv, total, record) {
var srvLen = 6; // 16-bit priority, weight and port = 6 Bytes var srvLen = 6; // 16-bit priority, weight and port = 6 Bytes
var rdLenIndex = total; var rdLenIndex = total;
total+=2; total+=2; // space for RDLENGTH
dv.setUint16(total, parseInt(record.priority, 10), false); dv.setUint16(total, parseInt(record.priority, 10), false);
total+=2; total+=2;
@ -59,14 +59,10 @@ exports.DNS_PACKER_TYPE_SRV = function (ab, dv, total, record) {
}); });
}); });
// RDLENGTH // RDLENGTH
dv.setUint16(rdLenIndex, srvLen, false); dv.setUint16(rdLenIndex, srvLen, false);
return total; return total;
}; };

View File

@ -1,8 +1,6 @@
(function (exports) { (function (exports) {
'use strict'; 'use strict';
// TODO. Not yet implemented. Do we need to include the name server and email address record properties???
// Value Meaning/Use // Value Meaning/Use
// Primary NS Variable length. The name of the Primary Master for the domain. May be a label, pointer, or any combination // Primary NS Variable length. The name of the Primary Master for the domain. May be a label, pointer, or any combination
// Admin MB Variable length. The administrator's mailbox. May be a label, pointer, or any combination // Admin MB Variable length. The administrator's mailbox. May be a label, pointer, or any combination
@ -49,7 +47,6 @@ 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;
} }
// Serial Number // Serial Number
record.sn = dv.getUint32(dv.byteLength - 20, false); record.sn = dv.getUint32(dv.byteLength - 20, false);
// Refresh Interval // Refresh Interval

View File

@ -1,6 +1,5 @@
(function (exports) { (function (exports) {
'use strict'; 'use strict';
// TODO. Not yet implemented
// SRV identifies the host(s) that will support a particular service. It // SRV identifies the host(s) that will support a particular service. It
// is a general purpose RR to discover any service. // is a general purpose RR to discover any service.

Binary file not shown.

View File

@ -1,6 +1,6 @@
{ {
"header": { "header": {
"id": 32561, "id": 52080,
"qr": 1, "qr": 1,
"opcode": 0, "opcode": 0,
"aa": 0, "aa": 0,
@ -47,7 +47,9 @@
"rdstart": 40, "rdstart": 40,
"rdlength": 38, "rdlength": 38,
"ttl": 59, "ttl": 59,
"sn": 149683348, "name_server": "ns3.google.com",
"email_addr": "dns-admin.google.com",
"sn": 150355194,
"ref": 900, "ref": 900,
"ret": 900, "ret": 900,
"ex": 1800, "ex": 1800,

Binary file not shown.

View File

@ -1,6 +1,6 @@
{ {
"header": { "header": {
"id": 32561, "id": 52080,
"qr": 0, "qr": 0,
"opcode": 0, "opcode": 0,
"aa": 0, "aa": 0,

View File

@ -1,61 +0,0 @@
{
"header": {
"id": 60816,
"qr": 1,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 1,
"res1": 0,
"res2": 0,
"res3": 0,
"rcode": 0
},
"qdcount": 1,
"ancount": 1,
"nscount": 0,
"arcount": 0,
"question": [
{
"name": "america.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 17,
"labels": [
"america",
"com"
],
"cpcount": 0
}
],
"answer": [
{
"name": "america.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 68,
"labels": [
"america",
"com"
],
"cpcount": 1,
"rdstart": 41,
"rdlength": 56,
"ttl": 3599,
"sn": 2016050200,
"ref": 28800,
"ret": 7200,
"ex": 604800,
"nx": 3600
}
],
"authority": [],
"edns_options": [],
"additional": [],
"byteLength": 97
}

View File

@ -1,19 +0,0 @@
{
"header": {
"id": 60816,
"qr": 0,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 0,
"rcode": 0
},
"question": [
{
"name": "america.com",
"typeName": "SOA",
"className": "IN"
}
]
}

View File

@ -1,61 +0,0 @@
{
"header": {
"id": 60281,
"qr": 1,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 1,
"res1": 0,
"res2": 0,
"res3": 0,
"rcode": 0
},
"qdcount": 1,
"ancount": 1,
"nscount": 0,
"arcount": 0,
"question": [
{
"name": "daplie.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 16,
"labels": [
"daplie",
"com"
],
"cpcount": 0
}
],
"answer": [
{
"name": "daplie.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 67,
"labels": [
"daplie",
"com"
],
"cpcount": 1,
"rdstart": 40,
"rdlength": 55,
"ttl": 0,
"sn": 2017020100,
"ref": 10800,
"ret": 3600,
"ex": 1209600,
"nx": 1800
}
],
"authority": [],
"edns_options": [],
"additional": [],
"byteLength": 95
}

View File

@ -1,19 +0,0 @@
{
"header": {
"id": 60281,
"qr": 0,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 0,
"rcode": 0
},
"question": [
{
"name": "daplie.com",
"typeName": "SOA",
"className": "IN"
}
]
}

View File

@ -1,62 +0,0 @@
{
"header": {
"id": 14537,
"qr": 1,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 1,
"res1": 0,
"res2": 0,
"res3": 0,
"rcode": 3
},
"qdcount": 1,
"ancount": 0,
"nscount": 1,
"arcount": 0,
"question": [
{
"name": "doesntexisit.google.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 29,
"labels": [
"doesntexisit",
"google",
"com"
],
"cpcount": 0
}
],
"answer": [],
"authority": [
{
"name": "google.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 50,
"labels": [
"google",
"com"
],
"cpcount": 1,
"rdstart": 53,
"rdlength": 38,
"ttl": 59,
"sn": 149710188,
"ref": 900,
"ret": 900,
"ex": 1800,
"nx": 60
}
],
"edns_options": [],
"additional": [],
"byteLength": 91
}

View File

@ -1,19 +0,0 @@
{
"header": {
"id": 14537,
"qr": 0,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 0,
"rcode": 0
},
"question": [
{
"name": "doesntexisit.google.com",
"typeName": "SOA",
"className": "IN"
}
]
}

View File

@ -1,61 +0,0 @@
{
"header": {
"id": 3582,
"qr": 1,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 1,
"res1": 0,
"res2": 0,
"res3": 0,
"rcode": 0
},
"qdcount": 1,
"ancount": 1,
"nscount": 0,
"arcount": 0,
"question": [
{
"name": "facebook.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 18,
"labels": [
"facebook",
"com"
],
"cpcount": 0
}
],
"answer": [
{
"name": "facebook.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 45,
"labels": [
"facebook",
"com"
],
"cpcount": 1,
"rdstart": 42,
"rdlength": 33,
"ttl": 119,
"sn": 1489109491,
"ref": 7200,
"ret": 1800,
"ex": 604800,
"nx": 120
}
],
"authority": [],
"edns_options": [],
"additional": [],
"byteLength": 75
}

View File

@ -1,19 +0,0 @@
{
"header": {
"id": 3582,
"qr": 0,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 0,
"rcode": 0
},
"question": [
{
"name": "facebook.com",
"typeName": "SOA",
"className": "IN"
}
]
}

View File

@ -1,61 +0,0 @@
{
"header": {
"id": 38325,
"qr": 1,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 1,
"res1": 0,
"res2": 0,
"res3": 0,
"rcode": 0
},
"qdcount": 1,
"ancount": 1,
"nscount": 0,
"arcount": 0,
"question": [
{
"name": "gmail.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 15,
"labels": [
"gmail",
"com"
],
"cpcount": 0
}
],
"answer": [
{
"name": "gmail.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 57,
"labels": [
"gmail",
"com"
],
"cpcount": 1,
"rdstart": 39,
"rdlength": 45,
"ttl": 59,
"sn": 149683348,
"ref": 900,
"ret": 900,
"ex": 1800,
"nx": 60
}
],
"authority": [],
"edns_options": [],
"additional": [],
"byteLength": 84
}

View File

@ -1,19 +0,0 @@
{
"header": {
"id": 38325,
"qr": 0,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 0,
"rcode": 0
},
"question": [
{
"name": "gmail.com",
"typeName": "SOA",
"className": "IN"
}
]
}

View File

@ -1,61 +0,0 @@
{
"header": {
"id": 7381,
"qr": 1,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 1,
"res1": 0,
"res2": 0,
"res3": 0,
"rcode": 0
},
"qdcount": 1,
"ancount": 1,
"nscount": 0,
"arcount": 0,
"question": [
{
"name": "khanacademy.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 21,
"labels": [
"khanacademy",
"com"
],
"cpcount": 0
}
],
"answer": [
{
"name": "khanacademy.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 84,
"labels": [
"khanacademy",
"com"
],
"cpcount": 1,
"rdstart": 45,
"rdlength": 72,
"ttl": 899,
"sn": 1,
"ref": 7200,
"ret": 900,
"ex": 1209600,
"nx": 86400
}
],
"authority": [],
"edns_options": [],
"additional": [],
"byteLength": 117
}

View File

@ -1,19 +0,0 @@
{
"header": {
"id": 7381,
"qr": 0,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 0,
"rcode": 0
},
"question": [
{
"name": "khanacademy.com",
"typeName": "SOA",
"className": "IN"
}
]
}

View File

@ -1,61 +0,0 @@
{
"header": {
"id": 11674,
"qr": 1,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 1,
"res1": 0,
"res2": 0,
"res3": 0,
"rcode": 0
},
"qdcount": 1,
"ancount": 1,
"nscount": 0,
"arcount": 0,
"question": [
{
"name": "pinterest.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 19,
"labels": [
"pinterest",
"com"
],
"cpcount": 0
}
],
"answer": [
{
"name": "pinterest.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 44,
"labels": [
"pinterest",
"com"
],
"cpcount": 1,
"rdstart": 43,
"rdlength": 32,
"ttl": 299,
"sn": 493,
"ref": 3600,
"ret": 600,
"ex": 604800,
"nx": 1800
}
],
"authority": [],
"edns_options": [],
"additional": [],
"byteLength": 75
}

View File

@ -1,19 +0,0 @@
{
"header": {
"id": 11674,
"qr": 0,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 0,
"rcode": 0
},
"question": [
{
"name": "pinterest.com",
"typeName": "SOA",
"className": "IN"
}
]
}

View File

@ -1,61 +0,0 @@
{
"header": {
"id": 21341,
"qr": 1,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 1,
"res1": 0,
"res2": 0,
"res3": 0,
"rcode": 0
},
"qdcount": 1,
"ancount": 1,
"nscount": 0,
"arcount": 0,
"question": [
{
"name": "tinder.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 16,
"labels": [
"tinder",
"com"
],
"cpcount": 0
}
],
"answer": [
{
"name": "tinder.com",
"type": 6,
"typeName": "SOA",
"class": 1,
"className": "IN",
"byteLength": 82,
"labels": [
"tinder",
"com"
],
"cpcount": 1,
"rdstart": 40,
"rdlength": 70,
"ttl": 879,
"sn": 1,
"ref": 7200,
"ret": 900,
"ex": 1209600,
"nx": 86400
}
],
"authority": [],
"edns_options": [],
"additional": [],
"byteLength": 110
}

View File

@ -1,19 +0,0 @@
{
"header": {
"id": 21341,
"qr": 0,
"opcode": 0,
"aa": 0,
"tc": 0,
"rd": 1,
"ra": 0,
"rcode": 0
},
"question": [
{
"name": "tinder.com",
"typeName": "SOA",
"className": "IN"
}
]
}