@netkitty/codec 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +249 -0
- package/README.md +30 -1
- package/README.zh-CN.md +26 -1
- package/dist/Codec.d.ts +25 -7
- package/dist/Codec.js +151 -18
- package/dist/PacketHeaders.d.ts +2 -0
- package/dist/PacketHeaders.js +8 -4
- package/dist/abstracts/BaseHeader.d.ts +34 -0
- package/dist/abstracts/BaseHeader.js +43 -0
- package/dist/headers/ARP.d.ts +3 -1
- package/dist/headers/ARP.js +8 -1
- package/dist/headers/BACnetIP.js +2 -1
- package/dist/headers/BGP.js +3 -2
- package/dist/headers/Babel.js +1 -1
- package/dist/headers/Codesys.js +3 -2
- package/dist/headers/DHCP.js +2 -1
- package/dist/headers/DNP3.d.ts +12 -7
- package/dist/headers/DNP3.js +98 -18
- package/dist/headers/DTLS.js +5 -3
- package/dist/headers/Diameter.js +2 -1
- package/dist/headers/Elasticsearch.js +3 -2
- package/dist/headers/EthernetII.d.ts +1 -0
- package/dist/headers/EthernetII.js +3 -0
- package/dist/headers/Goose.d.ts +31 -7
- package/dist/headers/Goose.js +409 -168
- package/dist/headers/HARTIP.js +2 -2
- package/dist/headers/ICMP.d.ts +1 -0
- package/dist/headers/ICMP.js +9 -1
- package/dist/headers/ICMPv6.d.ts +1 -0
- package/dist/headers/ICMPv6.js +1 -0
- package/dist/headers/IEC104_I_Frame.d.ts +28 -0
- package/dist/headers/IEC104_I_Frame.js +246 -160
- package/dist/headers/IEC104_S_Frame.js +3 -3
- package/dist/headers/IEC104_U_Frame.js +5 -3
- package/dist/headers/IEC61850SampledValues.d.ts +1 -0
- package/dist/headers/IEC61850SampledValues.js +16 -1
- package/dist/headers/IPFIX.js +2 -1
- package/dist/headers/IPv4.d.ts +1 -0
- package/dist/headers/IPv4.js +6 -0
- package/dist/headers/IPv6.d.ts +1 -0
- package/dist/headers/IPv6.js +6 -0
- package/dist/headers/IPv6HopByHopOptions.d.ts +2 -0
- package/dist/headers/IPv6HopByHopOptions.js +11 -0
- package/dist/headers/KNXnetIP.js +3 -2
- package/dist/headers/LACP.js +2 -1
- package/dist/headers/LDP.js +2 -2
- package/dist/headers/MQTT.js +3 -1
- package/dist/headers/MarkerProtocol.js +2 -1
- package/dist/headers/NHRP.js +7 -15
- package/dist/headers/NetFlowV5.js +2 -1
- package/dist/headers/OPCUA.js +4 -0
- package/dist/headers/OSPF.d.ts +2 -2
- package/dist/headers/OSPF.js +32 -20
- package/dist/headers/OSPFv3.d.ts +38 -0
- package/dist/headers/OSPFv3.js +316 -0
- package/dist/headers/PPTP.js +2 -2
- package/dist/headers/QUIC.js +8 -3
- package/dist/headers/RGoose.js +2 -1
- package/dist/headers/RIP.js +3 -2
- package/dist/headers/RIPng.js +3 -2
- package/dist/headers/RTCP.js +3 -2
- package/dist/headers/RTP.js +3 -2
- package/dist/headers/SFlow.js +4 -2
- package/dist/headers/SLMP.js +2 -1
- package/dist/headers/SLP.js +2 -1
- package/dist/headers/SLPv1.js +2 -1
- package/dist/headers/SMB1.js +3 -2
- package/dist/headers/SMB2.js +3 -2
- package/dist/headers/STUN.js +2 -1
- package/dist/headers/TLS_Handshake.d.ts +6 -0
- package/dist/headers/TLS_Handshake.js +28 -3
- package/dist/headers/TacacsPlus.js +3 -1
- package/dist/headers/Trailer.d.ts +30 -0
- package/dist/headers/Trailer.js +63 -0
- package/dist/headers/VLAN_802dot1Q.d.ts +1 -0
- package/dist/headers/VLAN_802dot1Q.js +3 -0
- package/dist/headers/WakeOnLAN.js +2 -1
- package/dist/headers/WireGuard.js +3 -2
- package/dist/headers/Zabbix.js +2 -2
- package/dist/lib/BERElement.d.ts +51 -0
- package/dist/lib/BERElement.js +125 -0
- package/dist/types/LayerGraph.d.ts +10 -5
- package/package.json +2 -2
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OSPFv3 = void 0;
|
|
4
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
5
|
+
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
6
|
+
const BufferToIP_1 = require("../helper/BufferToIP");
|
|
7
|
+
const IPToBuffer_1 = require("../helper/IPToBuffer");
|
|
8
|
+
const BufferToHex_1 = require("../helper/BufferToHex");
|
|
9
|
+
const BufferToNumber_1 = require("../helper/BufferToNumber");
|
|
10
|
+
const NumberToBuffer_1 = require("../helper/NumberToBuffer");
|
|
11
|
+
const Checksum_1 = require("../helper/Checksum");
|
|
12
|
+
/**
|
|
13
|
+
* OSPFv3 — Open Shortest Path First for IPv6 (RFC 5340), carried on IPv6 as Next Header 89 (the same
|
|
14
|
+
* protocol number as OSPFv2, told apart by the Version octet). This codec decodes the 16-octet common
|
|
15
|
+
* header (RFC 5340 §A.3.1): an 8-bit Version (`version`, offset 0, 3), an 8-bit Message Type (`type`,
|
|
16
|
+
* offset 1; 1 Hello, 2 Database Description, 3 LS Request, 4 LS Update, 5 LS Ack), a 16-bit Packet Length
|
|
17
|
+
* (`packetLength`, offset 2), the Router ID (`routerId`, offset 4) and Area ID (`areaId`, offset 8) in
|
|
18
|
+
* dotted-quad form, a 16-bit Checksum (`checksum`, offset 12), an 8-bit Instance ID (`instanceId`, offset
|
|
19
|
+
* 14) and a Reserved octet (`reserved`, hex, offset 15). Unlike OSPFv2 there is no authentication in the
|
|
20
|
+
* header (RFC 4552 IPsec, or the RFC 7166 trailer after the packet, does that job). Packet Length and
|
|
21
|
+
* Checksum are computed on encode when left out and written as given otherwise; the checksum is the
|
|
22
|
+
* Internet checksum of the whole packet with the IPv6 pseudo-header prepended, its Upper-Layer Packet
|
|
23
|
+
* Length being the Packet Length field (§A.3.1).
|
|
24
|
+
*
|
|
25
|
+
* For a Hello (type 1, §A.3.2) the body is decoded field by field: Interface ID (offset 16), Router
|
|
26
|
+
* Priority (offset 20), the 24-bit Options (offset 21; V6 0x01, E 0x02, MC 0x04, N 0x08, R 0x10, DC 0x20,
|
|
27
|
+
* AF 0x100, L 0x200, AT 0x400), Hello Interval and Router Dead Interval (16 bits each, offsets 24 and 26),
|
|
28
|
+
* Designated and Backup Designated Router IDs (offsets 28 and 32), then the Router IDs of the neighbours
|
|
29
|
+
* (4 octets each from offset 36). Built from defaults, a Hello carries priority 1, Options V6|E|R, hello
|
|
30
|
+
* interval 10 and dead interval 40. For all other types the body is kept verbatim as `rawBody` hex from
|
|
31
|
+
* offset 16. Both are bounded by min(Packet Length, the end of the IPv6 payload) and never below the
|
|
32
|
+
* 16-octet header, so a lying length can't read past the real IP payload. match() fires on Next Header
|
|
33
|
+
* 89 with an IPv6 layer beneath (directly, or behind AH / an extension header), Version 3 and a full
|
|
34
|
+
* common header present.
|
|
35
|
+
*/
|
|
36
|
+
class OSPFv3 extends BaseHeader_1.BaseHeader {
|
|
37
|
+
constructor() {
|
|
38
|
+
super(...arguments);
|
|
39
|
+
this.id = 'ospfv3';
|
|
40
|
+
this.matchKeys = ['ipproto:89'];
|
|
41
|
+
//RFC 5340 runs over IPv6; OSPFv3 over IPv4 (RFC 7949) is not supported.
|
|
42
|
+
this.ipVersions = [6];
|
|
43
|
+
this.name = 'Open Shortest Path First version 3';
|
|
44
|
+
this.nickname = 'OSPFv3';
|
|
45
|
+
//A leaf header (LSA bodies are kept as rawBody).
|
|
46
|
+
this.demuxProducers = [];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Bytes of OSPFv3 the IPv6 layer beneath says are available: up to the end of its payload (Payload
|
|
50
|
+
* Length after its 40-octet header), so AH or an extension header in between is accounted for. The
|
|
51
|
+
* captured remainder when there is no Payload Length to go by.
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
#available() {
|
|
55
|
+
let available = this.packet.length - this.startPos;
|
|
56
|
+
const ip = this.nearestIPModule();
|
|
57
|
+
if (ip && ip.id === 'ipv6') {
|
|
58
|
+
const payloadLength = ip.instance.plen.getValue(0);
|
|
59
|
+
const ipPayloadEnd = ip.startPos + ip.length + payloadLength - this.startPos;
|
|
60
|
+
if (payloadLength > 0 && ipPayloadEnd < available)
|
|
61
|
+
available = ipPayloadEnd;
|
|
62
|
+
}
|
|
63
|
+
return available < 0 ? 0 : available;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Header-relative end offset of the OSPFv3 packet body: the Packet Length field, clamped down to the
|
|
67
|
+
* bytes the IPv6 layer made available (#available). Never less than the 16-octet common header. Both
|
|
68
|
+
* the Hello neighbour list and the raw-body fallback are bounded by this.
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
#bodyEnd() {
|
|
72
|
+
let end = this.instance.packetLength.getValue(0);
|
|
73
|
+
const available = this.#available();
|
|
74
|
+
if (available < end)
|
|
75
|
+
end = available;
|
|
76
|
+
if (end < 16)
|
|
77
|
+
end = 16;
|
|
78
|
+
return end;
|
|
79
|
+
}
|
|
80
|
+
/** Whether this is a Hello (type 1), whose body is decoded field by field. */
|
|
81
|
+
#isHello() {
|
|
82
|
+
const type = this.instance.type.getValue(0);
|
|
83
|
+
return type === 1;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The OSPFv3 checksum (RFC 5340 §A.3.1): the Internet checksum of the whole packet with the IPv6
|
|
87
|
+
* pseudo-header (Next Header 89, Upper-Layer Packet Length = the Packet Length field) prepended.
|
|
88
|
+
* Called once every field is written, with the checksum still zero.
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
#calculateChecksum() {
|
|
92
|
+
const ip = this.nearestIPModule();
|
|
93
|
+
if (!ip || ip.id !== 'ipv6') {
|
|
94
|
+
this.recordError(this.instance.checksum.getPath(), 'Cannot compute OSPFv3 checksum: no IPv6 layer beneath OSPFv3');
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
const pseudoHeader = this.ipPseudoHeader(89, this.instance.packetLength.getValue(0));
|
|
98
|
+
if (!pseudoHeader) {
|
|
99
|
+
this.recordError(this.instance.checksum.getPath(), 'Cannot compute OSPFv3 checksum: the IPv6 addresses beneath are unusable');
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
return (0, Checksum_1.InternetChecksum)(pseudoHeader, this.packet.subarray(this.startPos, this.endPos));
|
|
103
|
+
}
|
|
104
|
+
static #schemaCache;
|
|
105
|
+
//Class-cached SCHEMA (field closures are plain functions taking dynamic `this` via .call(this)).
|
|
106
|
+
get SCHEMA() {
|
|
107
|
+
return (OSPFv3.#schemaCache ??= OSPFv3.#buildSchema());
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* An unsigned big-endian Hello field of `byteLength` octets at `offset`, decoded and encoded only for
|
|
111
|
+
* a Hello (type 1). Left out, it is `defaultValue` (also the schema default).
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
static #helloUInt(name, offset, byteLength, label, defaultValue) {
|
|
115
|
+
return {
|
|
116
|
+
type: 'integer',
|
|
117
|
+
label: label,
|
|
118
|
+
minimum: 0,
|
|
119
|
+
maximum: 2 ** (byteLength * 8) - 1,
|
|
120
|
+
default: defaultValue,
|
|
121
|
+
decode: function () {
|
|
122
|
+
if (!this.#isHello())
|
|
123
|
+
return;
|
|
124
|
+
this.instance.hello[name].setValue(this.readBits(offset, byteLength, 0, byteLength * 8));
|
|
125
|
+
},
|
|
126
|
+
encode: function () {
|
|
127
|
+
if (!this.#isHello())
|
|
128
|
+
return;
|
|
129
|
+
const value = this.instance.hello[name].getValue(defaultValue);
|
|
130
|
+
this.instance.hello[name].setValue(value);
|
|
131
|
+
this.writeBits(offset, byteLength, 0, byteLength * 8, value);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A Router ID of the Hello body (dotted quad) at `offset`, decoded and encoded only for a Hello
|
|
137
|
+
* (type 1). Left out, it is 0.0.0.0 (none).
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
static #helloRouterId(name, offset, label) {
|
|
141
|
+
return {
|
|
142
|
+
type: 'string',
|
|
143
|
+
label: label,
|
|
144
|
+
minLength: 7,
|
|
145
|
+
maxLength: 15,
|
|
146
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.IPv4,
|
|
147
|
+
decode: function () {
|
|
148
|
+
if (!this.#isHello())
|
|
149
|
+
return;
|
|
150
|
+
this.instance.hello[name].setValue((0, BufferToIP_1.BufferToIPv4)(this.readBytes(offset, 4)));
|
|
151
|
+
},
|
|
152
|
+
encode: function () {
|
|
153
|
+
if (!this.#isHello())
|
|
154
|
+
return;
|
|
155
|
+
const routerId = this.instance.hello[name].getValue('0.0.0.0');
|
|
156
|
+
this.instance.hello[name].setValue(routerId);
|
|
157
|
+
this.writeBytes(offset, (0, IPToBuffer_1.IPv4ToBuffer)(routerId));
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
static #buildSchema() {
|
|
162
|
+
return {
|
|
163
|
+
type: 'object',
|
|
164
|
+
summary: 'OSPFv3 type=${type} rid=${routerId}',
|
|
165
|
+
properties: {
|
|
166
|
+
//==== Common header (16 bytes, RFC 5340 §A.3.1) ====
|
|
167
|
+
//Default 3, what match() requires.
|
|
168
|
+
version: { ...this.fieldUInt('version', 0, 1, 'Version'), default: 3 },
|
|
169
|
+
type: { ...this.fieldUInt('type', 1, 1, 'Message Type'), default: 1 },
|
|
170
|
+
//The whole OSPFv3 packet including this header; left out, the bytes actually written, filled
|
|
171
|
+
//once every field is encoded (before the checksum); a given value is written as given.
|
|
172
|
+
packetLength: {
|
|
173
|
+
type: 'integer',
|
|
174
|
+
autoCalculated: true,
|
|
175
|
+
label: 'Packet Length',
|
|
176
|
+
minimum: 0,
|
|
177
|
+
maximum: 65535,
|
|
178
|
+
decode: function () {
|
|
179
|
+
this.instance.packetLength.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
|
|
180
|
+
},
|
|
181
|
+
encode: function () {
|
|
182
|
+
if (!this.isLeftOut(this.instance.packetLength)) {
|
|
183
|
+
const packetLength = this.instance.packetLength.getValue(0);
|
|
184
|
+
this.instance.packetLength.setValue(packetLength);
|
|
185
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(packetLength));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.instance.packetLength.setValue(0);
|
|
189
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
190
|
+
this.addPostSelfEncodeHandler(() => {
|
|
191
|
+
this.instance.packetLength.setValue(this.length);
|
|
192
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(this.length));
|
|
193
|
+
}, 1);
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
routerId: this.fieldIPv4('routerId', 4, 'Router ID'),
|
|
197
|
+
areaId: this.fieldIPv4('areaId', 8, 'Area ID'),
|
|
198
|
+
//Left out, computed after the Packet Length once every field is written
|
|
199
|
+
//(#calculateChecksum); a given value is written as given.
|
|
200
|
+
checksum: {
|
|
201
|
+
type: 'integer',
|
|
202
|
+
autoCalculated: true,
|
|
203
|
+
label: 'Checksum',
|
|
204
|
+
minimum: 0,
|
|
205
|
+
maximum: 65535,
|
|
206
|
+
decode: function () {
|
|
207
|
+
this.instance.checksum.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(12, 2)));
|
|
208
|
+
},
|
|
209
|
+
encode: function () {
|
|
210
|
+
if (!this.isLeftOut(this.instance.checksum)) {
|
|
211
|
+
const checksum = this.instance.checksum.getValue(0);
|
|
212
|
+
this.instance.checksum.setValue(checksum);
|
|
213
|
+
this.writeBytes(12, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
this.instance.checksum.setValue(0);
|
|
217
|
+
this.writeBytes(12, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
218
|
+
this.addPostSelfEncodeHandler(() => {
|
|
219
|
+
const checksum = this.#calculateChecksum();
|
|
220
|
+
this.instance.checksum.setValue(checksum);
|
|
221
|
+
this.writeBytes(12, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
222
|
+
}, 2);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
//Distinguishes OSPFv3 instances on one link; 0 is the base IPv6 unicast instance.
|
|
226
|
+
instanceId: { ...this.fieldUInt('instanceId', 14, 1, 'Instance ID'), default: 0 },
|
|
227
|
+
//0 on transmit; kept verbatim so a non-canonical packet still round-trips.
|
|
228
|
+
reserved: this.fieldHex('reserved', 15, 1, 'Reserved'),
|
|
229
|
+
//==== Hello body (RFC 5340 §A.3.2), decoded only for type 1 ====
|
|
230
|
+
hello: {
|
|
231
|
+
type: 'object',
|
|
232
|
+
label: 'Hello Packet',
|
|
233
|
+
properties: {
|
|
234
|
+
interfaceId: this.#helloUInt('interfaceId', 16, 4, 'Interface ID', 0),
|
|
235
|
+
routerPriority: this.#helloUInt('routerPriority', 20, 1, 'Router Priority', 1),
|
|
236
|
+
//24 bits, RFC 5340 §A.2: V6 0x01, E 0x02, MC 0x04, N 0x08, R 0x10, DC 0x20, plus
|
|
237
|
+
//AF 0x100 (RFC 5838), L 0x200 (RFC 5613), AT 0x400 (RFC 7166). Default V6|E|R.
|
|
238
|
+
options: this.#helloUInt('options', 21, 3, 'Options', 0x13),
|
|
239
|
+
helloInterval: this.#helloUInt('helloInterval', 24, 2, 'Hello Interval', 10),
|
|
240
|
+
routerDeadInterval: this.#helloUInt('routerDeadInterval', 26, 2, 'Router Dead Interval', 40),
|
|
241
|
+
designatedRouter: this.#helloRouterId('designatedRouter', 28, 'Designated Router ID'),
|
|
242
|
+
backupDesignatedRouter: this.#helloRouterId('backupDesignatedRouter', 32, 'Backup Designated Router ID'),
|
|
243
|
+
neighbors: {
|
|
244
|
+
type: 'array',
|
|
245
|
+
label: 'Neighbor IDs',
|
|
246
|
+
items: {
|
|
247
|
+
type: 'string',
|
|
248
|
+
minLength: 7,
|
|
249
|
+
maxLength: 15,
|
|
250
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.IPv4
|
|
251
|
+
},
|
|
252
|
+
//Neighbour Router IDs run from the end of the fixed Hello fields (offset 36)
|
|
253
|
+
//to the Packet Length, 4 bytes each. Bounded by #bodyEnd so a corrupt length
|
|
254
|
+
//field can't read past the IPv6 payload.
|
|
255
|
+
decode: function () {
|
|
256
|
+
if (!this.#isHello())
|
|
257
|
+
return;
|
|
258
|
+
const end = this.#bodyEnd();
|
|
259
|
+
const neighbors = [];
|
|
260
|
+
for (let offset = 36; offset + 4 <= end; offset += 4)
|
|
261
|
+
neighbors.push((0, BufferToIP_1.BufferToIPv4)(this.readBytes(offset, 4)));
|
|
262
|
+
this.instance.hello.neighbors.setValue(neighbors);
|
|
263
|
+
},
|
|
264
|
+
encode: function () {
|
|
265
|
+
if (!this.#isHello())
|
|
266
|
+
return;
|
|
267
|
+
const neighbors = this.instance.hello.neighbors.getValue([]);
|
|
268
|
+
neighbors.forEach((neighbor, i) => this.writeBytes(36 + i * 4, (0, IPToBuffer_1.IPv4ToBuffer)(neighbor)));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
//==== Raw body for types 2-5 (DD / LS Request / LS Update / LS Ack) ====
|
|
274
|
+
//Kept verbatim, byte-perfect. Bounded by #bodyEnd.
|
|
275
|
+
rawBody: {
|
|
276
|
+
type: 'string',
|
|
277
|
+
label: 'Body',
|
|
278
|
+
minLength: 0,
|
|
279
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
280
|
+
decode: function () {
|
|
281
|
+
if (this.#isHello())
|
|
282
|
+
return;
|
|
283
|
+
const end = this.#bodyEnd();
|
|
284
|
+
if (end <= 16)
|
|
285
|
+
return;
|
|
286
|
+
this.instance.rawBody.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(16, end - 16)));
|
|
287
|
+
},
|
|
288
|
+
encode: function () {
|
|
289
|
+
if (this.#isHello())
|
|
290
|
+
return;
|
|
291
|
+
if (this.instance.rawBody.isUndefined())
|
|
292
|
+
return;
|
|
293
|
+
this.writeBytes(16, Buffer.from(this.instance.rawBody.getValue(''), 'hex'));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
match() {
|
|
300
|
+
if (!this.prevCodecModule)
|
|
301
|
+
return false;
|
|
302
|
+
//OSPFv3 runs over IPv6 (RFC 5340): Next Header 89 from the IPv6 header itself or from AH / an
|
|
303
|
+
//extension header after it, with an IPv6 layer beneath. Version 3 tells it from OSPFv2, which
|
|
304
|
+
//shares the protocol number; a full 16-octet common header must be present.
|
|
305
|
+
const nextHeader = this.prevCodecModule.instance.nxt.getValue(0);
|
|
306
|
+
if (nextHeader !== 89)
|
|
307
|
+
return false;
|
|
308
|
+
const ip = this.nearestIPModule();
|
|
309
|
+
if (!ip || ip.id !== 'ipv6')
|
|
310
|
+
return false;
|
|
311
|
+
if (this.#available() < 16)
|
|
312
|
+
return false;
|
|
313
|
+
return this.readBytes(0, 1, true)[0] === 3;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
exports.OSPFv3 = OSPFv3;
|
package/dist/headers/PPTP.js
CHANGED
|
@@ -78,8 +78,8 @@ class PPTP extends BaseHeader_1.BaseHeader {
|
|
|
78
78
|
//messages, the only PDU type carried on the TCP control connection.
|
|
79
79
|
pduType: this.fieldUInt('pduType', 2, 2, 'PDU Type'),
|
|
80
80
|
//The Magic Cookie constant 0x1A2B3C4D. Kept verbatim (honored, not re-derived) so a
|
|
81
|
-
//crafted/desynced cookie still round-trips.
|
|
82
|
-
magicCookie: this.fieldHex('magicCookie', 4, 4, 'Magic Cookie'),
|
|
81
|
+
//crafted/desynced cookie still round-trips. Default 0x1A2B3C4D: what match() requires.
|
|
82
|
+
magicCookie: { ...this.fieldHex('magicCookie', 4, 4, 'Magic Cookie'), default: '1a2b3c4d' },
|
|
83
83
|
controlMessageType: this.fieldUInt('controlMessageType', 8, 2, 'Control Message Type'),
|
|
84
84
|
//Reserved (MUST be 0 per RFC 2637); preserved and re-emitted untouched.
|
|
85
85
|
reserved0: this.fieldHex('reserved0', 10, 2, 'Reserved0'),
|
package/dist/headers/QUIC.js
CHANGED
|
@@ -67,16 +67,20 @@ class QUIC extends BaseHeader_1.BaseHeader {
|
|
|
67
67
|
#tailOffset() {
|
|
68
68
|
return 7 + this.instance.dcidLength.getValue(0) + this.instance.scidLength.getValue(0);
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* A single flag bit within the first byte (bit 0 = MSB). Default set: the Header Form and Fixed Bit
|
|
72
|
+
* are both 1 in the long header match() requires.
|
|
73
|
+
*/
|
|
71
74
|
static #flagBit(name, bitOffset, label) {
|
|
72
75
|
return {
|
|
73
76
|
type: 'boolean',
|
|
74
77
|
label: label,
|
|
78
|
+
default: true,
|
|
75
79
|
decode: function () {
|
|
76
80
|
this.instance.firstByte[name].setValue(!!this.readBits(0, 1, bitOffset, 1));
|
|
77
81
|
},
|
|
78
82
|
encode: function () {
|
|
79
|
-
const value = !!this.instance.firstByte[name].getValue();
|
|
83
|
+
const value = !!this.instance.firstByte[name].getValue(true);
|
|
80
84
|
this.instance.firstByte[name].setValue(value);
|
|
81
85
|
this.writeBits(0, 1, bitOffset, 1, value ? 1 : 0);
|
|
82
86
|
}
|
|
@@ -127,7 +131,8 @@ class QUIC extends BaseHeader_1.BaseHeader {
|
|
|
127
131
|
//Version — 0x00000001 = QUIC v1 (RFC 9000), 0x6b3343cf = v2 (RFC 9369), 0xff0000xx = IETF
|
|
128
132
|
//drafts, 0x00000000 = Version Negotiation. Kept as a lower-case hex string so any value
|
|
129
133
|
//round-trips verbatim and the field is unbounded (the match gate restricts real selection).
|
|
130
|
-
|
|
134
|
+
//Default QUIC v1, a version match() accepts.
|
|
135
|
+
version: { ...this.fieldHex('version', 1, 4, 'Version'), default: '00000001' },
|
|
131
136
|
//Destination Connection ID length (0..20 per RFC 9000, but any 0..255 round-trips). Honored
|
|
132
137
|
//when supplied, else derived from the DCID bytes.
|
|
133
138
|
dcidLength: {
|
package/dist/headers/RGoose.js
CHANGED
|
@@ -106,7 +106,8 @@ class RGoose extends BaseHeader_1.BaseHeader {
|
|
|
106
106
|
type: 'object',
|
|
107
107
|
summary: 'R-GOOSE/R-SV spdu=${spduNumber} si=${si}',
|
|
108
108
|
properties: {
|
|
109
|
-
|
|
109
|
+
//Default 0xA1 (non-tunnelled GOOSE): one of the Session Identifiers match() requires.
|
|
110
|
+
si: { ...this.fieldUInt('si', 0, 1, 'Session Identifier'), default: 0xa1 },
|
|
110
111
|
li: {
|
|
111
112
|
autoCalculated: true,
|
|
112
113
|
type: 'integer', label: 'Session Header Length', minimum: 0, maximum: 255,
|
package/dist/headers/RIP.js
CHANGED
|
@@ -73,8 +73,9 @@ class RIP extends BaseHeader_1.BaseHeader {
|
|
|
73
73
|
type: 'object',
|
|
74
74
|
summary: 'RIPv2 command ${command}',
|
|
75
75
|
properties: {
|
|
76
|
-
command
|
|
77
|
-
|
|
76
|
+
//Defaults command 1 (Request) and version 2 (RIPv2): the signature match() requires.
|
|
77
|
+
command: { ...this.fieldUInt('command', 0, 1, 'Command'), default: 1 },
|
|
78
|
+
version: { ...this.fieldUInt('version', 1, 1, 'Version'), default: 2 },
|
|
78
79
|
reserved: this.fieldUInt('reserved', 2, 2, 'Reserved'),
|
|
79
80
|
entries: {
|
|
80
81
|
type: 'array',
|
package/dist/headers/RIPng.js
CHANGED
|
@@ -50,8 +50,9 @@ class RIPng extends BaseHeader_1.BaseHeader {
|
|
|
50
50
|
summary: 'RIPng cmd=${command} ${rtes.length} RTEs',
|
|
51
51
|
properties: {
|
|
52
52
|
//Fixed 4-byte header: Command (1 Request / 2 Response), Version (= 1), 2-byte reserved.
|
|
53
|
-
command
|
|
54
|
-
|
|
53
|
+
//Defaults command 1 (Request) and version 1: the signature match() requires.
|
|
54
|
+
command: { ...this.fieldUInt('command', 0, 1, 'Command'), default: 1 },
|
|
55
|
+
version: { ...this.fieldUInt('version', 1, 1, 'Version'), default: 1 },
|
|
55
56
|
//Reserved (2 bytes, must be zero per RFC 2080 but kept verbatim so a non-zero value in a
|
|
56
57
|
//crafted/non-conformant message still round-trips byte-for-byte).
|
|
57
58
|
reserved: this.fieldUInt('reserved', 2, 2, 'Reserved'),
|
package/dist/headers/RTCP.js
CHANGED
|
@@ -118,8 +118,9 @@ class RTCP extends BaseHeader_1.BaseHeader {
|
|
|
118
118
|
}
|
|
119
119
|
},
|
|
120
120
|
//Packet Type (200 SR .. 207 XR). A plain uint8 — no hard enum, so an unknown/future type
|
|
121
|
-
//still decodes and re-encodes (never-throws).
|
|
122
|
-
|
|
121
|
+
//still decodes and re-encodes (never-throws). Default 201 (Receiver Report, complete with
|
|
122
|
+
//no report blocks): match() requires a type in 200..207.
|
|
123
|
+
packetType: { ...this.fieldUInt('packetType', 1, 1, 'Packet Type'), default: 201 },
|
|
123
124
|
length: {
|
|
124
125
|
type: 'integer',
|
|
125
126
|
autoCalculated: true,
|
package/dist/headers/RTP.js
CHANGED
|
@@ -105,8 +105,9 @@ class RTP extends BaseHeader_1.BaseHeader {
|
|
|
105
105
|
type: 'object',
|
|
106
106
|
summary: 'RTP pt=${payloadType} seq=${sequenceNumber} ssrc=${ssrc}',
|
|
107
107
|
properties: {
|
|
108
|
-
//Byte 0 (MSB first): Version(0-1) Padding(2) Extension(3) CSRC Count(4-7).
|
|
109
|
-
|
|
108
|
+
//Byte 0 (MSB first): Version(0-1) Padding(2) Extension(3) CSRC Count(4-7). Default version
|
|
109
|
+
//2: the signature match() requires.
|
|
110
|
+
version: { ...this.#uintBits('version', 0, 0, 2, 'Version'), default: 2 },
|
|
110
111
|
padding: this.#flagBit('padding', 0, 2, 'Padding'),
|
|
111
112
|
extension: this.#flagBit('extension', 0, 3, 'Extension'),
|
|
112
113
|
//CSRC Count: the number of 4-byte CSRC identifiers. Honored when supplied (a crafted
|
package/dist/headers/SFlow.js
CHANGED
|
@@ -105,8 +105,10 @@ class SFlow extends BaseHeader_1.BaseHeader {
|
|
|
105
105
|
type: 'object',
|
|
106
106
|
summary: 'sFlow ${numSamples} samples',
|
|
107
107
|
properties: {
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
//Default 5: the sFlow v5 version, and what match() requires.
|
|
109
|
+
version: { ...SFlow.fieldUInt('version', 0, 4, 'Version'), default: 5 },
|
|
110
|
+
//Default 1 (IPv4): the agent address layout a left-out type is written with.
|
|
111
|
+
agentAddressType: { ...SFlow.fieldUInt('agentAddressType', 4, 4, 'Agent Address Type'), default: 1 },
|
|
110
112
|
//The only variable-length field of the fixed header: 4 bytes as a dotted quad for IPv4
|
|
111
113
|
//(type 1), 16 bytes kept verbatim as hex for IPv6 (type 2). Its length shifts every
|
|
112
114
|
//downstream offset, so all trailing fields compute their offset from #subAgentIdOffset().
|
package/dist/headers/SLMP.js
CHANGED
|
@@ -79,7 +79,8 @@ class SLMP extends BaseHeader_1.BaseHeader {
|
|
|
79
79
|
properties: {
|
|
80
80
|
//The 2-byte frame marker, kept in wire order (big-endian): 0x5000 (`50 00`) request,
|
|
81
81
|
//0xD000 (`D0 00`) response. Not little-endian — it is a fixed signature, not a value.
|
|
82
|
-
|
|
82
|
+
//Default 0x5000 (request): what match() requires.
|
|
83
|
+
subheader: { ...this.fieldUInt('subheader', 0, 2, 'Subheader'), default: 0x5000 },
|
|
83
84
|
networkNo: this.fieldUInt('networkNo', 2, 1, 'Network Number'),
|
|
84
85
|
stationNo: this.fieldUInt('stationNo', 3, 1, 'Station Number'),
|
|
85
86
|
//Request-destination Module I/O number (little-endian, e.g. 0x03FF = own station).
|
package/dist/headers/SLP.js
CHANGED
|
@@ -88,7 +88,8 @@ class SLP extends BaseHeader_1.BaseHeader {
|
|
|
88
88
|
type: 'object',
|
|
89
89
|
summary: 'SLP func=${functionId} xid=${xid}',
|
|
90
90
|
properties: {
|
|
91
|
-
|
|
91
|
+
//Default 2: the SLPv2 version, and what match() requires.
|
|
92
|
+
version: { ...this.fieldUInt('version', 0, 1, 'Version'), default: 2 },
|
|
92
93
|
functionId: this.fieldUInt('functionId', 1, 1, 'Function-ID'),
|
|
93
94
|
length: {
|
|
94
95
|
type: 'integer',
|
package/dist/headers/SLPv1.js
CHANGED
|
@@ -53,7 +53,8 @@ class SLPv1 extends BaseHeader_1.BaseHeader {
|
|
|
53
53
|
type: 'object',
|
|
54
54
|
summary: 'SLPv1 func=${functionId} xid=${xid}',
|
|
55
55
|
properties: {
|
|
56
|
-
|
|
56
|
+
//Default 1: the SLPv1 version, and what match() requires.
|
|
57
|
+
version: { ...this.fieldUInt('version', 0, 1, 'Version'), default: 1 },
|
|
57
58
|
functionId: this.fieldUInt('functionId', 1, 1, 'Function'),
|
|
58
59
|
length: {
|
|
59
60
|
type: 'integer',
|
package/dist/headers/SMB1.js
CHANGED
|
@@ -139,8 +139,9 @@ class SMB1 extends BaseHeader_1.BaseHeader {
|
|
|
139
139
|
},
|
|
140
140
|
//The 4-byte Protocol magic — 0xFF 'S' 'M' 'B' (ff534d42). Kept verbatim so a crafted magic
|
|
141
141
|
//round-trips; the match() gate enforces the real signature for selection (and separates
|
|
142
|
-
//SMB1 from SMB2's 0xFE 'S' 'M' 'B' in the same 445/139 buckets).
|
|
143
|
-
|
|
142
|
+
//SMB1 from SMB2's 0xFE 'S' 'M' 'B' in the same 445/139 buckets). Default ff534d42: what
|
|
143
|
+
//match() requires.
|
|
144
|
+
protocolId: { ...this.fieldHex('protocolId', 4, 4, 'Protocol Id'), default: 'ff534d42' },
|
|
144
145
|
//Command (MS-CIFS §2.2.2.1): 0x72 NEGOTIATE, 0x73 SESSION_SETUP_ANDX, 0x75 TREE_CONNECT_ANDX,
|
|
145
146
|
//… (kept as a plain honored uint — no enum, so an unknown/crafted opcode still round-trips).
|
|
146
147
|
command: this.fieldUInt('command', 8, 1, 'Command'),
|
package/dist/headers/SMB2.js
CHANGED
|
@@ -136,8 +136,9 @@ class SMB2 extends BaseHeader_1.BaseHeader {
|
|
|
136
136
|
}
|
|
137
137
|
},
|
|
138
138
|
//The 4-byte ProtocolId magic — 0xFE 'S' 'M' 'B' (fe534d42). Kept verbatim so a crafted
|
|
139
|
-
//magic round-trips; the match() gate enforces the real signature for selection.
|
|
140
|
-
|
|
139
|
+
//magic round-trips; the match() gate enforces the real signature for selection. Default
|
|
140
|
+
//fe534d42: what match() requires.
|
|
141
|
+
protocolId: { ...this.fieldHex('protocolId', 4, 4, 'Protocol Id'), default: 'fe534d42' },
|
|
141
142
|
//StructureSize is always 64 on the wire (MS-SMB2 §2.2.1.1); kept as an honored LE uint so a
|
|
142
143
|
//crafted value round-trips (no hard constraint that would reject a lying value on re-encode).
|
|
143
144
|
structureSize: this.#fieldUInt16LE('structureSize', 8, 'Structure Size'),
|
package/dist/headers/STUN.js
CHANGED
|
@@ -74,7 +74,8 @@ class STUN extends BaseHeader_1.BaseHeader {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
|
-
|
|
77
|
+
//Default 0x2112A442: the fixed Magic Cookie (RFC 5389 §6), and what match() requires.
|
|
78
|
+
magicCookie: { ...this.fieldHex('magicCookie', 4, 4, 'Magic Cookie'), default: '2112a442' },
|
|
78
79
|
transactionId: this.fieldHex('transactionId', 8, 12, 'Transaction ID'),
|
|
79
80
|
attributes: {
|
|
80
81
|
type: 'array',
|
|
@@ -15,6 +15,12 @@ export declare class TLS_Handshake extends BaseHeader {
|
|
|
15
15
|
* verbatim; a structured Hello (messagedata.version set) turns this false.
|
|
16
16
|
*/
|
|
17
17
|
protected messagedataRawFallbackActive(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Throw when a Hello body runs past the captured bytes: a record split across TCP segments carries
|
|
20
|
+
* only part of it here. Structured, its cut-short lists would re-encode with lengths computed from
|
|
21
|
+
* what was captured instead of the ones on the wire, so the caller keeps the body as raw.
|
|
22
|
+
*/
|
|
23
|
+
protected assertHelloBodyCaptured(end: number): void;
|
|
18
24
|
/**
|
|
19
25
|
* Structurally decode a ClientHello (handshake type 1) body starting at record offset 9.
|
|
20
26
|
* Throws on any bound overrun / trailing bytes so the caller can fall back to raw.
|
|
@@ -432,14 +432,28 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
|
|
|
432
432
|
return;
|
|
433
433
|
}
|
|
434
434
|
const handshakeType = this.instance.handshakeType.getValue();
|
|
435
|
+
//Only a ClientHello or ServerHello body is built from fields. Any other type's body is
|
|
436
|
+
//its raw bytes, empty when left out: a HelloRequest or ServerHelloDone has no body
|
|
437
|
+
//(RFC 5246 7.4.1.1, 7.4.5). Hello fields given for it are reported, not written.
|
|
438
|
+
if (handshakeType !== HandshakeType.Handshake_2 && handshakeType !== HandshakeType.Handshake_3) {
|
|
439
|
+
for (const field of ['version', 'random', 'sessionId', 'cipherSuites', 'cipherSuite', 'compressionMethods', 'compressionMethod', 'extensions']) {
|
|
440
|
+
if (!md[field].isUndefined())
|
|
441
|
+
this.recordError(md[field].getPath(), 'Only a ClientHello or ServerHello body carries this field, not written');
|
|
442
|
+
}
|
|
443
|
+
if (!this.isLeftOut(md.raw))
|
|
444
|
+
this.writeBytes(9, (0, HexToBuffer_1.HexToBuffer)(md.raw.getValue().toString()));
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
//Left out, the fixed-width Hello fields are zeros of their size (a 32-octet random, the
|
|
448
|
+
//null cipher suite and compression method), so the body still parses as a Hello.
|
|
435
449
|
const parts = [];
|
|
436
450
|
parts.push(this.tlsVersionStringToBuffer(md.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'))));
|
|
437
|
-
parts.push((0, HexToBuffer_1.HexToBuffer)(md.random.getValue(
|
|
451
|
+
parts.push(this.isLeftOut(md.random) ? Buffer.alloc(32, 0) : (0, HexToBuffer_1.HexToBuffer)(md.random.getValue()));
|
|
438
452
|
const sessionId = (0, HexToBuffer_1.HexToBuffer)(md.sessionId.getValue(''));
|
|
439
453
|
parts.push((0, NumberToBuffer_1.UInt8ToBuffer)(sessionId.length), sessionId);
|
|
440
454
|
if (handshakeType === HandshakeType.Handshake_3) {
|
|
441
|
-
parts.push((0, HexToBuffer_1.HexToBuffer)(md.cipherSuite.getValue(
|
|
442
|
-
parts.push((0, HexToBuffer_1.HexToBuffer)(md.compressionMethod.getValue(
|
|
455
|
+
parts.push(this.isLeftOut(md.cipherSuite) ? Buffer.alloc(2, 0) : (0, HexToBuffer_1.HexToBuffer)(md.cipherSuite.getValue()));
|
|
456
|
+
parts.push(this.isLeftOut(md.compressionMethod) ? Buffer.alloc(1, 0) : (0, HexToBuffer_1.HexToBuffer)(md.compressionMethod.getValue()));
|
|
443
457
|
}
|
|
444
458
|
else {
|
|
445
459
|
const cipherSuites = Buffer.concat(md.cipherSuites.getValue([]).map((code) => (0, HexToBuffer_1.HexToBuffer)(code)));
|
|
@@ -514,6 +528,15 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
|
|
|
514
528
|
return false;
|
|
515
529
|
return md.version.isUndefined();
|
|
516
530
|
}
|
|
531
|
+
/**
|
|
532
|
+
* Throw when a Hello body runs past the captured bytes: a record split across TCP segments carries
|
|
533
|
+
* only part of it here. Structured, its cut-short lists would re-encode with lengths computed from
|
|
534
|
+
* what was captured instead of the ones on the wire, so the caller keeps the body as raw.
|
|
535
|
+
*/
|
|
536
|
+
assertHelloBodyCaptured(end) {
|
|
537
|
+
if (end > this.packet.length - this.startPos)
|
|
538
|
+
throw new Error('the body continues past the captured bytes');
|
|
539
|
+
}
|
|
517
540
|
/**
|
|
518
541
|
* Structurally decode a ClientHello (handshake type 1) body starting at record offset 9.
|
|
519
542
|
* Throws on any bound overrun / trailing bytes so the caller can fall back to raw.
|
|
@@ -521,6 +544,7 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
|
|
|
521
544
|
decodeClientHello(bodyLength) {
|
|
522
545
|
let p = 9;
|
|
523
546
|
const end = 9 + bodyLength;
|
|
547
|
+
this.assertHelloBodyCaptured(end);
|
|
524
548
|
const need = (n) => {
|
|
525
549
|
if (n < 0 || p + n > end)
|
|
526
550
|
throw new Error('handshake body overrun');
|
|
@@ -584,6 +608,7 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
|
|
|
584
608
|
decodeServerHello(bodyLength) {
|
|
585
609
|
let p = 9;
|
|
586
610
|
const end = 9 + bodyLength;
|
|
611
|
+
this.assertHelloBodyCaptured(end);
|
|
587
612
|
const need = (n) => {
|
|
588
613
|
if (n < 0 || p + n > end)
|
|
589
614
|
throw new Error('handshake body overrun');
|
|
@@ -45,13 +45,15 @@ class TacacsPlus extends BaseHeader_1.BaseHeader {
|
|
|
45
45
|
type: 'object',
|
|
46
46
|
label: 'Version',
|
|
47
47
|
properties: {
|
|
48
|
+
//Default 0xc: the TACACS+ major version (RFC 8907 §4.1), and what match() requires.
|
|
48
49
|
major: {
|
|
49
50
|
type: 'integer',
|
|
50
51
|
label: 'Major Version',
|
|
51
52
|
minimum: 0,
|
|
52
53
|
maximum: 15,
|
|
54
|
+
default: 0xc,
|
|
53
55
|
decode: function () { this.instance.version.major.setValue(this.readBits(0, 1, 0, 4)); },
|
|
54
|
-
encode: function () { this.writeBits(0, 1, 0, 4, this.instance.version.major.getValue(
|
|
56
|
+
encode: function () { this.writeBits(0, 1, 0, 4, this.instance.version.major.getValue(0xc)); }
|
|
55
57
|
},
|
|
56
58
|
minor: {
|
|
57
59
|
type: 'integer',
|