Skip to content

Commit 1b77faf

Browse files
committed
RFC correctness improvements
- feat(packet): encode name compression pointers (RFC 1035 §4.1.4) - feat(server/udp): negotiated UDP payload size with TC=1 on oversize - feat(server/tcp): pipeline support (RFC 7766 §6.2.1.1) - feat(packet): EDNS extended RCODE supported - fix(packet): EDNS default UDP payload size raised to 4096 - fix(packet): clamps TTLs to 2³¹−1 - fix(packet): Label and name length validation (RFC 1035 §2.3.4) - fix(server/doh): accepts any (or absent) Accept header (RFC 8484 §4.1) - fix(server/doh): DoH POST requires Content-Type: application/dns-message - feat(server/doh): DoH responses include TTL-derived Cache-Control - fix(packet): Packet.Header.toBuffer writes Z=0 (RFC 1035 §4.1.1)
1 parent 7d09d6d commit 1b77faf

8 files changed

Lines changed: 791 additions & 117 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
44

55
### Unreleased
66

7+
- feat(packet): encode name compression pointers (RFC 1035 §4.1.4)
8+
- feat(server/udp): negotiated UDP payload size with TC=1 on oversize
9+
- feat(server/tcp): pipeline support (RFC 7766 §6.2.1.1)
10+
- feat(packet): EDNS extended RCODE supported
11+
- fix(packet): EDNS default UDP payload size raised to 4096
12+
- fix(packet): clamps TTLs to 2³¹−1
13+
- fix(packet): Label and name length validation (RFC 1035 §2.3.4)
14+
- fix(server/doh): accepts any (or absent) Accept header (RFC 8484 §4.1)
15+
- fix(server/doh): DoH POST requires Content-Type: application/dns-message
16+
- feat(server/doh): DoH responses include TTL-derived Cache-Control
17+
- fix(packet): Packet.Header.toBuffer writes Z=0 (RFC 1035 §4.1.1)
18+
719
### [2.3.0] - 2026-05-25
820

921
- fix(packet): IPv6 `::` compression for leading-zero address #123
@@ -57,5 +69,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
5769
- fix(packet): ensure compressed IPv6 is valid #70
5870
- doc(README): correct `server.listen` options
5971

72+
[2.3.0]: https://github.com/lsongdev/node-dns/releases/tag/v2.3.0
6073
[2.2.0]: https://github.com/lsongdev/node-dns/releases/tag/v2.2.0
6174
[2.2.1]: https://github.com/lsongdev/node-dns/releases/tag/v2.2.1

lib/writer.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ BufferWriter.prototype.writeBuffer = function(b) {
2525
this.buffer = this.buffer.concat(b.buffer);
2626
};
2727

28+
// Current write position, in bits.
29+
BufferWriter.prototype.bitLength = function() {
30+
return this.buffer.length;
31+
};
32+
33+
// Current write position, in bytes. Defined when DNS encoding has stayed on
34+
// byte boundaries (it always does at the points we expose this).
35+
BufferWriter.prototype.byteLength = function() {
36+
return this.buffer.length / 8;
37+
};
38+
39+
// Overwrite `size` bits at `bitOffset` with `value`. Used to back-fill
40+
// placeholders (e.g. RDLENGTH) once the field's contents have been written.
41+
BufferWriter.prototype.patch = function(bitOffset, value, size) {
42+
for (let i = 0; i < size; i++) {
43+
this.buffer[bitOffset + i] = (value & Math.pow(2, size - i - 1)) ? 1 : 0;
44+
}
45+
};
46+
2847
/**
2948
* [toBuffer description]
3049
* @return {[type]} [description]

0 commit comments

Comments
 (0)