chimney, cleanup, OPT parsing
This commit is contained in:
parent
8643e6e3c7
commit
bd433a8ddf
|
@ -32,6 +32,42 @@ pdns.unpackHeader = function (i) {
|
||||||
|
|
||||||
pdns._unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
pdns._unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS;
|
||||||
|
|
||||||
|
pdns.unpackOpt = function (ab, rec) {
|
||||||
|
var dv;
|
||||||
|
|
||||||
|
// https://tools.ietf.org/html/rfc6891#section-6
|
||||||
|
console.log('OPT is not yet supported');
|
||||||
|
if ('undefined' !== typeof packet.edns_version) {
|
||||||
|
console.warn("More that one OPT, should respond with FORMERR, but not implmentede");
|
||||||
|
}
|
||||||
|
if (packet.name) {
|
||||||
|
console.warn("name '" + packet.name + "' should not exist for type OPT 0x29 41");
|
||||||
|
}
|
||||||
|
packet.payload = rec.class;
|
||||||
|
// TODO index into the correct place in the ArrayBuffer
|
||||||
|
dv = new DataView(new ArrayBuffer(4));
|
||||||
|
// rec.ttl is actually 1 (extended_rcode), 1 (edns_version), 2:1 (DO), 2:7 (Z)
|
||||||
|
dv.setUint32(0, packet.ttl);
|
||||||
|
// is xrcode this edns_options?
|
||||||
|
packet.xrcode = '0x' + dv.getUint8(0, false).toString(16);
|
||||||
|
if ('0x0' === packet.xrcode) {
|
||||||
|
// use 4-bit rcode instead of 12-bit rcode
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// shift xrcode up by 4 bits (8 bits + 4 trailing 0s)
|
||||||
|
// OR with existing rcode (now 12-bits total)
|
||||||
|
console.warn('extended_rcode not supported yet');
|
||||||
|
}
|
||||||
|
packet.edns_version = dv.getUint8(1, false);
|
||||||
|
packet.do = dv.getUint8(2, false) & 0x8000; // 1000 0000
|
||||||
|
packet.z = dv.getUint16(2, false) & 0x7FFF; // 0111 1111
|
||||||
|
/*
|
||||||
|
"edns_options": [],
|
||||||
|
"payload": 4096,
|
||||||
|
"edns_version": 0,
|
||||||
|
"do": 0
|
||||||
|
*/
|
||||||
|
};
|
||||||
pdns.unpack = function (ab) {
|
pdns.unpack = function (ab) {
|
||||||
if (ab.buffer) {
|
if (ab.buffer) {
|
||||||
ab = ab.buffer;
|
ab = ab.buffer;
|
||||||
|
@ -175,7 +211,6 @@ pdns.unpack = function (ab) {
|
||||||
packet.header.id = id;
|
packet.header.id = id;
|
||||||
|
|
||||||
|
|
||||||
console.log('qdcount', packet.qdcount);
|
|
||||||
packet.question = [];
|
packet.question = [];
|
||||||
for (i = 0; i < packet.qdcount; i += 1) {
|
for (i = 0; i < packet.qdcount; i += 1) {
|
||||||
rec = unpackQuestion(ab, dv, ui8, total);
|
rec = unpackQuestion(ab, dv, ui8, total);
|
||||||
|
@ -183,7 +218,6 @@ pdns.unpack = function (ab) {
|
||||||
packet.question.push(rec);
|
packet.question.push(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('ancount', packet.ancount);
|
|
||||||
packet.answer = [];
|
packet.answer = [];
|
||||||
for (i = 0; i < packet.ancount; i += 1) {
|
for (i = 0; i < packet.ancount; i += 1) {
|
||||||
rec = unpackAnswer(ab, dv, ui8, total);
|
rec = unpackAnswer(ab, dv, ui8, total);
|
||||||
|
@ -191,7 +225,6 @@ pdns.unpack = function (ab) {
|
||||||
packet.answer.push(rec);
|
packet.answer.push(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('nscount', packet.nscount);
|
|
||||||
packet.authority = [];
|
packet.authority = [];
|
||||||
for (i = 0; i < packet.nscount; i += 1) {
|
for (i = 0; i < packet.nscount; i += 1) {
|
||||||
rec = unpackAnswer(ab, dv, ui8, total);
|
rec = unpackAnswer(ab, dv, ui8, total);
|
||||||
|
@ -199,11 +232,15 @@ pdns.unpack = function (ab) {
|
||||||
packet.authority.push(rec);
|
packet.authority.push(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('arcount', packet.arcount);
|
|
||||||
packet.additional = [];
|
packet.additional = [];
|
||||||
for (i = 0; i < packet.arcount; i += 1) {
|
for (i = 0; i < packet.arcount; i += 1) {
|
||||||
rec = unpackAnswer(ab, dv, ui8, total);
|
rec = unpackAnswer(ab, dv, ui8, total);
|
||||||
total += rec.byteLength;
|
total += rec.byteLength;
|
||||||
|
if (0x29 === rec.type) {
|
||||||
|
// OPT 41 (0x29)
|
||||||
|
pdns.unpackOpt(ab, rec);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
packet.additional.push(rec);
|
packet.additional.push(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(function (exports) {
|
(function (exports) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Used to provide the ability to associate some arbitrary and unformatted text
|
// Used to provide the ability to associate some arbitrary and unformatted text
|
||||||
// with a host or other name, such as a human readable information about a server
|
// with a host or other name, such as a human readable information about a server
|
||||||
// network, data center, and other accounting information.
|
// network, data center, and other accounting information.
|
||||||
|
|
||||||
|
@ -9,26 +9,10 @@ var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js'
|
||||||
|
|
||||||
exports.DNS_TYPE_TXT = function (ab, packet, record) {
|
exports.DNS_TYPE_TXT = function (ab, packet, record) {
|
||||||
|
|
||||||
|
var labels = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
|
||||||
|
record.data = [ labels.name ];
|
||||||
|
|
||||||
var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength);
|
|
||||||
console.log(rdataAb);
|
|
||||||
var dv = new DataView(rdataAb);
|
|
||||||
// var d = '';
|
|
||||||
// var string = '';
|
|
||||||
// for (var i = 0; i < dv.byteLength; i+= 1){
|
|
||||||
|
|
||||||
// d = dv.getUint8(i, false);
|
|
||||||
// string = String.fromCharCode(d);
|
|
||||||
// console.log("data at: " + i + " is: " + string);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
record.data = [ unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name ];
|
|
||||||
|
|
||||||
var l = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
|
|
||||||
|
|
||||||
console.log("labels: " + JSON.stringify(l));
|
|
||||||
return record;
|
return record;
|
||||||
};
|
};
|
||||||
|
|
||||||
}('undefined' !== typeof window ? window : exports));
|
}('undefined' !== typeof window ? window : exports));
|
||||||
|
|
|
@ -11,6 +11,7 @@ var types = exports.DNS_TYPES = {
|
||||||
, TXT: 0x10 // 16
|
, TXT: 0x10 // 16
|
||||||
, AAAA: 0x1c // 28
|
, AAAA: 0x1c // 28
|
||||||
, SRV: 0x21 // 33
|
, SRV: 0x21 // 33
|
||||||
|
, OPT: 0x29 // 41
|
||||||
, ANY: 0xff // 255
|
, ANY: 0xff // 255
|
||||||
};
|
};
|
||||||
// and in reverse
|
// and in reverse
|
||||||
|
@ -18,4 +19,4 @@ Object.keys(types).forEach(function (key) {
|
||||||
types[types[key]] = key;
|
types[types[key]] = key;
|
||||||
});
|
});
|
||||||
|
|
||||||
}('undefined' !== typeof window ? window : exports));
|
}('undefined' !== typeof window ? window : exports));
|
||||||
|
|
|
@ -78,12 +78,12 @@
|
||||||
try {
|
try {
|
||||||
deepLike(expected, result);
|
deepLike(expected, result);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
console.log('');
|
||||||
console.log('[RESULT]');
|
console.log('[RESULT]');
|
||||||
console.log(JSON.stringify(result, null, 2));
|
console.log(JSON.stringify(result, null, 2));
|
||||||
console.error('[FAIL]', name);
|
console.error('[FAIL]', name);
|
||||||
console.error(e.stack);
|
console.error(e.stack);
|
||||||
console.log('');
|
console.log('');
|
||||||
}
|
}
|
||||||
console.log('');
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
Loading…
Reference in New Issue