@netkitty/codec 2.0.0 → 2.2.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 +324 -0
- package/README.md +31 -7
- package/README.zh-CN.md +28 -7
- package/dist/Codec.d.ts +4 -3
- package/dist/Codec.js +48 -6
- package/dist/PacketHeaders.d.ts +2 -0
- package/dist/PacketHeaders.js +8 -4
- package/dist/abstracts/BaseHeader.d.ts +43 -0
- package/dist/abstracts/BaseHeader.js +75 -0
- package/dist/headers/AH.js +3 -2
- 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/BFD.d.ts +2 -1
- package/dist/headers/BFD.js +30 -4
- package/dist/headers/BGP.js +8 -3
- package/dist/headers/Babel.js +1 -1
- package/dist/headers/C37118.d.ts +3 -2
- package/dist/headers/C37118.js +34 -15
- package/dist/headers/CDP.d.ts +3 -3
- package/dist/headers/CDP.js +46 -10
- package/dist/headers/CMS.js +25 -10
- package/dist/headers/COTP.js +2 -3
- package/dist/headers/CoAP.js +20 -2
- package/dist/headers/Codesys.js +3 -2
- package/dist/headers/DCCP.d.ts +3 -2
- package/dist/headers/DCCP.js +60 -8
- package/dist/headers/DHCP.js +2 -1
- package/dist/headers/DNP3.d.ts +12 -5
- package/dist/headers/DNP3.js +153 -18
- package/dist/headers/DTLS.js +5 -3
- package/dist/headers/Diameter.js +2 -1
- package/dist/headers/EIGRP.d.ts +3 -2
- package/dist/headers/EIGRP.js +31 -5
- package/dist/headers/Elasticsearch.js +3 -2
- package/dist/headers/EthernetII.d.ts +1 -0
- package/dist/headers/EthernetII.js +4 -0
- package/dist/headers/GELF.js +1 -0
- package/dist/headers/GENEVE.js +1 -0
- package/dist/headers/GRE.js +1 -0
- package/dist/headers/GTPv2C.js +1 -0
- package/dist/headers/Goose.d.ts +31 -7
- package/dist/headers/Goose.js +413 -172
- package/dist/headers/HARTIP.js +2 -2
- package/dist/headers/HSR.js +1 -0
- package/dist/headers/HTTP2.js +1 -0
- package/dist/headers/ICMP.js +2 -1
- package/dist/headers/ICMPv6.js +10 -16
- package/dist/headers/IEC104_I_Frame.d.ts +28 -0
- package/dist/headers/IEC104_I_Frame.js +434 -319
- package/dist/headers/IEC104_S_Frame.js +22 -4
- package/dist/headers/IEC104_U_Frame.js +24 -4
- package/dist/headers/IEC61850SampledValues.d.ts +1 -0
- package/dist/headers/IEC61850SampledValues.js +20 -5
- package/dist/headers/IGMP.d.ts +8 -7
- package/dist/headers/IGMP.js +57 -19
- package/dist/headers/IPFIX.js +3 -2
- package/dist/headers/IPv4.d.ts +1 -0
- package/dist/headers/IPv4.js +32 -23
- package/dist/headers/IPv6.d.ts +1 -0
- package/dist/headers/IPv6.js +10 -1
- package/dist/headers/IPv6HopByHopOptions.js +11 -1
- package/dist/headers/ISAKMP.js +1 -0
- package/dist/headers/KNXnetIP.js +3 -2
- package/dist/headers/Kerberos.js +1 -0
- package/dist/headers/L2TP.js +1 -0
- package/dist/headers/LACP.js +2 -1
- package/dist/headers/LDAP.js +1 -1
- package/dist/headers/LDP.js +2 -2
- package/dist/headers/LLC.js +1 -0
- package/dist/headers/MQTT.js +3 -1
- package/dist/headers/MarkerProtocol.js +2 -1
- package/dist/headers/NHRP.d.ts +1 -1
- package/dist/headers/NHRP.js +29 -4
- package/dist/headers/NetFlowV5.js +2 -1
- package/dist/headers/OPCUA.js +4 -0
- package/dist/headers/OSPF.d.ts +5 -5
- package/dist/headers/OSPF.js +98 -12
- package/dist/headers/OSPFv3.d.ts +37 -0
- package/dist/headers/OSPFv3.js +314 -0
- package/dist/headers/PIM.d.ts +3 -3
- package/dist/headers/PIM.js +55 -6
- package/dist/headers/PPPoEDiscovery.js +2 -0
- package/dist/headers/PPTP.js +2 -2
- package/dist/headers/PTP.js +5 -1
- package/dist/headers/QUIC.js +8 -3
- package/dist/headers/RDP.js +2 -0
- package/dist/headers/RGoose.js +4 -1
- package/dist/headers/RIP.js +3 -2
- package/dist/headers/RIPng.js +3 -2
- package/dist/headers/RSVP.d.ts +3 -3
- package/dist/headers/RSVP.js +56 -42
- package/dist/headers/RTCP.js +4 -2
- package/dist/headers/RTP.js +3 -2
- package/dist/headers/SCTP.d.ts +2 -2
- package/dist/headers/SCTP.js +29 -5
- 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/SNAP.js +2 -2
- package/dist/headers/SNMP.js +2 -2
- package/dist/headers/STUN.js +3 -2
- package/dist/headers/SercosIII.d.ts +3 -2
- package/dist/headers/SercosIII.js +41 -5
- package/dist/headers/TCP.js +13 -58
- package/dist/headers/TLS_Alert.js +20 -2
- package/dist/headers/TLS_ApplicationData.d.ts +3 -3
- package/dist/headers/TLS_ApplicationData.js +25 -6
- package/dist/headers/TLS_ChangeCipherSpec.d.ts +2 -2
- package/dist/headers/TLS_ChangeCipherSpec.js +24 -4
- package/dist/headers/TLS_Handshake.d.ts +6 -0
- package/dist/headers/TLS_Handshake.js +67 -9
- package/dist/headers/TLS_Heartbeat.d.ts +4 -3
- package/dist/headers/TLS_Heartbeat.js +40 -7
- package/dist/headers/TPKT.js +1 -1
- 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/UDP.js +17 -61
- package/dist/headers/VLAN_802dot1Q.d.ts +1 -0
- package/dist/headers/VLAN_802dot1Q.js +4 -0
- package/dist/headers/VRRP.d.ts +2 -1
- package/dist/headers/VRRP.js +45 -9
- package/dist/headers/WakeOnLAN.js +2 -1
- package/dist/headers/WireGuard.js +3 -2
- package/dist/headers/Zabbix.js +2 -2
- package/dist/helper/Checksum.d.ts +15 -0
- package/dist/helper/Checksum.js +56 -0
- package/dist/helper/Crc.d.ts +18 -0
- package/dist/helper/Crc.js +58 -0
- package/dist/lib/BERElement.d.ts +51 -0
- package/dist/lib/BERElement.js +125 -0
- package/package.json +2 -2
package/dist/headers/DNP3.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.DNP3 = void 0;
|
|
4
5
|
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
5
6
|
const BufferToHex_1 = require("../helper/BufferToHex");
|
|
6
7
|
const HexToBuffer_1 = require("../helper/HexToBuffer");
|
|
7
8
|
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
9
|
+
const BufferToNumber_1 = require("../helper/BufferToNumber");
|
|
10
|
+
const NumberToBuffer_1 = require("../helper/NumberToBuffer");
|
|
11
|
+
const Crc_1 = require("../helper/Crc");
|
|
8
12
|
/**
|
|
9
13
|
* DNP3 — Distributed Network Protocol 3 (IEEE 1815), a SCADA protocol common in electric/water
|
|
10
14
|
* utilities, on TCP/UDP port 20000. Each frame begins with a 10-byte Data Link Layer header: the start
|
|
@@ -13,11 +17,18 @@ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
|
13
17
|
* Source address, and a header CRC. The user data that follows is carried in blocks of up to 16 octets
|
|
14
18
|
* each with its own trailing 2-byte CRC.
|
|
15
19
|
*
|
|
16
|
-
* This codec decodes the link header structurally and
|
|
17
|
-
*
|
|
18
|
-
* the transport/application layer is a cross-frame
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* This codec decodes the link header structurally and carries the data-block region in one of two hex
|
|
21
|
+
* fields. `userData` is the user data with the block CRCs removed (transport header + application data,
|
|
22
|
+
* not decoded further: reassembling the transport/application layer is a cross-frame concern); `payload`
|
|
23
|
+
* is the region verbatim, block CRCs included. Decode emits exactly one of them: `userData` when the
|
|
24
|
+
* region is complete and every block CRC verifies, otherwise `payload` plus a warning naming each bad or
|
|
25
|
+
* truncated block. On encode a given `payload` wins and is written as given (how a frame with a wrong
|
|
26
|
+
* block CRC is crafted; a `userData` given alongside it is ignored with a warning); otherwise `userData`
|
|
27
|
+
* is split into 16-octet blocks, each followed by its CRC-16/DNP, low octet first. Length and the header
|
|
28
|
+
* CRC are written as given; left out, Length counts the user data octets (the block CRCs excluded) and
|
|
29
|
+
* the header CRC is computed (CRC-16/DNP over the first 8 octets). A frame round-trips byte-for-byte
|
|
30
|
+
* either way; the frame's extent is derived from the Length field so a pipelined/trailing frame is left
|
|
31
|
+
* to RawData.
|
|
21
32
|
*/
|
|
22
33
|
class DNP3 extends BaseHeader_1.BaseHeader {
|
|
23
34
|
constructor() {
|
|
@@ -26,12 +37,12 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
26
37
|
this.name = 'Distributed Network Protocol 3';
|
|
27
38
|
this.nickname = 'DNP3';
|
|
28
39
|
this.matchKeys = ['tcpport:20000', 'udpport:20000'];
|
|
29
|
-
//A leaf header — the transport/application layers require
|
|
40
|
+
//A leaf header — the transport/application layers require reassembly across frames.
|
|
30
41
|
this.demuxProducers = [];
|
|
31
42
|
}
|
|
32
43
|
static #schemaCache;
|
|
33
44
|
get SCHEMA() {
|
|
34
|
-
return (
|
|
45
|
+
return (_a.#schemaCache ??= _a.#buildSchema());
|
|
35
46
|
}
|
|
36
47
|
/** A single bit of the Control octet (byte 3, bit 0 = MSB). */
|
|
37
48
|
static #flagBit(name, bitOffset, label) {
|
|
@@ -56,13 +67,92 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
56
67
|
const blocks = Math.ceil(userData / 16);
|
|
57
68
|
return 10 + userData + blocks * 2;
|
|
58
69
|
}
|
|
70
|
+
/** The user data octets a data-block region of `payloadOctets` carries: every block is up to 16 data
|
|
71
|
+
* octets followed by their 2-octet CRC. A trailing block too short to hold a data octet and its CRC
|
|
72
|
+
* (malformed) contributes none. */
|
|
73
|
+
static #userDataOctets(payloadOctets) {
|
|
74
|
+
const rest = payloadOctets % 18;
|
|
75
|
+
return Math.floor(payloadOctets / 18) * 16 + (rest > 2 ? rest - 2 : 0);
|
|
76
|
+
}
|
|
77
|
+
/** A block CRC-16/DNP as it goes on the wire, low octet first. */
|
|
78
|
+
static #blockCrc(data) {
|
|
79
|
+
const crc = (0, Crc_1.Crc16Dnp)(data);
|
|
80
|
+
return Buffer.from([crc & 0xff, (crc >> 8) & 0xff]);
|
|
81
|
+
}
|
|
82
|
+
/** `userData` split into 16-octet blocks, each followed by its CRC. */
|
|
83
|
+
static #toDataBlocks(userData) {
|
|
84
|
+
const blocks = [];
|
|
85
|
+
for (let offset = 0; offset < userData.length; offset += 16) {
|
|
86
|
+
const data = userData.subarray(offset, offset + 16);
|
|
87
|
+
blocks.push(data, _a.#blockCrc(data));
|
|
88
|
+
}
|
|
89
|
+
return Buffer.concat(blocks);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Read the data-block region (bounded by the Length-derived frame extent and the captured bytes) and
|
|
93
|
+
* de-block it along the block sizes the Length field implies. `faults` names every block whose CRC
|
|
94
|
+
* does not verify and a block the capture cuts short; `userData` (the data octets, CRCs removed) is
|
|
95
|
+
* only meaningful when there are none.
|
|
96
|
+
*/
|
|
97
|
+
#dataBlocks() {
|
|
98
|
+
const frameLength = this.#frameLength();
|
|
99
|
+
const remaining = this.packet.length - this.startPos;
|
|
100
|
+
const end = frameLength > remaining ? remaining : frameLength;
|
|
101
|
+
const region = end > 10 ? this.readBytes(10, end - 10) : Buffer.alloc(0);
|
|
102
|
+
const data = [];
|
|
103
|
+
const faults = [];
|
|
104
|
+
let offset = 0;
|
|
105
|
+
for (let block = 1; offset < frameLength - 10; block++) {
|
|
106
|
+
const size = Math.min(18, frameLength - 10 - offset);
|
|
107
|
+
if (offset + size > region.length) {
|
|
108
|
+
faults.push(`Data block ${block} is truncated: ${region.length - offset} of ${size} octets`);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
const blockData = region.subarray(offset, offset + size - 2);
|
|
112
|
+
const crc = (0, BufferToHex_1.BufferToHex)(region.subarray(offset + size - 2, offset + size));
|
|
113
|
+
const expected = (0, BufferToHex_1.BufferToHex)(_a.#blockCrc(blockData));
|
|
114
|
+
if (crc !== expected)
|
|
115
|
+
faults.push(`Data block ${block} CRC ${crc} does not match the computed ${expected}`);
|
|
116
|
+
data.push(blockData);
|
|
117
|
+
offset += size;
|
|
118
|
+
}
|
|
119
|
+
return { region: region, userData: Buffer.concat(data), faults: faults };
|
|
120
|
+
}
|
|
59
121
|
static #buildSchema() {
|
|
60
122
|
return {
|
|
61
123
|
type: 'object',
|
|
62
124
|
summary: 'DNP3 func=${control.functionCode} ${source}->${destination}',
|
|
63
125
|
properties: {
|
|
64
|
-
|
|
65
|
-
|
|
126
|
+
//Default 0x0564: the start octets every DNP3 frame begins with, and what match() requires.
|
|
127
|
+
start: { ...this.fieldHex('start', 0, 2, 'Start'), default: '0564' },
|
|
128
|
+
//Octets from Control through the user data, the block CRCs excluded: 5 + user data octets,
|
|
129
|
+
//counted from whichever of payload / userData is written.
|
|
130
|
+
length: {
|
|
131
|
+
type: 'integer',
|
|
132
|
+
autoCalculated: true,
|
|
133
|
+
label: 'Length',
|
|
134
|
+
minimum: 0,
|
|
135
|
+
maximum: 255,
|
|
136
|
+
decode: function () {
|
|
137
|
+
this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(2, 1)));
|
|
138
|
+
},
|
|
139
|
+
encode: function () {
|
|
140
|
+
if (!this.isLeftOut(this.instance.length)) {
|
|
141
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.length.getValue(0)));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const userDataOctets = this.isLeftOut(this.instance.payload)
|
|
145
|
+
? (0, HexToBuffer_1.HexToBuffer)(this.instance.userData.getValue('')).length
|
|
146
|
+
: _a.#userDataOctets((0, HexToBuffer_1.HexToBuffer)(this.instance.payload.getValue('')).length);
|
|
147
|
+
let length = 5 + userDataOctets;
|
|
148
|
+
if (length > 255) {
|
|
149
|
+
this.recordError(this.instance.length.getPath(), 'Maximum value is 255');
|
|
150
|
+
length = 255;
|
|
151
|
+
}
|
|
152
|
+
this.instance.length.setValue(length);
|
|
153
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt8ToBuffer)(length));
|
|
154
|
+
}
|
|
155
|
+
},
|
|
66
156
|
//Control octet (byte 3, MSB first): DIR / PRM / FCB / FCV(or DFC) / Function Code(4 bits).
|
|
67
157
|
control: {
|
|
68
158
|
type: 'object',
|
|
@@ -111,20 +201,64 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
111
201
|
this.writeBytes(6, Buffer.from([value & 0xff, (value >> 8) & 0xff]));
|
|
112
202
|
}
|
|
113
203
|
},
|
|
114
|
-
//Header CRC over the preceding 8 octets,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
204
|
+
//Header CRC: CRC-16/DNP over the preceding 8 octets (start through source), low octet first.
|
|
205
|
+
//Those octets are all written when this runs, so a left-out CRC is computed right here.
|
|
206
|
+
headerCrc: {
|
|
207
|
+
type: 'string',
|
|
208
|
+
autoCalculated: true,
|
|
209
|
+
label: 'Header CRC',
|
|
210
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
211
|
+
decode: function () {
|
|
212
|
+
this.instance.headerCrc.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(8, 2)));
|
|
213
|
+
},
|
|
214
|
+
encode: function () {
|
|
215
|
+
if (!this.isLeftOut(this.instance.headerCrc)) {
|
|
216
|
+
this.writeBytes(8, (0, HexToBuffer_1.HexToBuffer)(this.instance.headerCrc.getValue()));
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const crc = (0, Crc_1.Crc16Dnp)(this.readBytes(0, 8));
|
|
220
|
+
const crcBuffer = Buffer.from([crc & 0xff, (crc >> 8) & 0xff]);
|
|
221
|
+
this.instance.headerCrc.setValue((0, BufferToHex_1.BufferToHex)(crcBuffer));
|
|
222
|
+
this.writeBytes(8, crcBuffer);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
//The user data (transport header + application data) with the block CRCs removed. Decoded
|
|
226
|
+
//when the data-block region is complete and every block CRC verifies; encoded into 16-octet
|
|
227
|
+
//blocks, each followed by its CRC, unless a payload is given.
|
|
228
|
+
userData: {
|
|
229
|
+
type: 'string',
|
|
230
|
+
label: 'User Data',
|
|
231
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
232
|
+
decode: function () {
|
|
233
|
+
const blocks = this.#dataBlocks();
|
|
234
|
+
if (!blocks.faults.length)
|
|
235
|
+
this.instance.userData.setValue((0, BufferToHex_1.BufferToHex)(blocks.userData));
|
|
236
|
+
},
|
|
237
|
+
encode: function () {
|
|
238
|
+
if (this.isLeftOut(this.instance.userData))
|
|
239
|
+
return;
|
|
240
|
+
if (!this.isLeftOut(this.instance.payload)) {
|
|
241
|
+
this.recordError(this.instance.userData.getPath(), 'Ignored: payload is given and is written verbatim instead');
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
this.writeBytes(10, _a.#toDataBlocks((0, HexToBuffer_1.HexToBuffer)(this.instance.userData.getValue(''))));
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
//The data-block region verbatim: transport header + application data + per-block CRCs.
|
|
248
|
+
//Decoded instead of userData when a block CRC is wrong or the capture cuts a block short;
|
|
249
|
+
//given on encode, it is written as given. Bounded by the Length-derived frame extent so a
|
|
250
|
+
//pipelined/trailing frame is left to raw.
|
|
118
251
|
payload: {
|
|
119
252
|
type: 'string',
|
|
120
253
|
label: 'Payload',
|
|
121
254
|
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
122
255
|
decode: function () {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
256
|
+
if (!this.instance.userData.isUndefined())
|
|
257
|
+
return;
|
|
258
|
+
const blocks = this.#dataBlocks();
|
|
259
|
+
this.instance.payload.setValue((0, BufferToHex_1.BufferToHex)(blocks.region));
|
|
260
|
+
for (const fault of blocks.faults)
|
|
261
|
+
this.recordError(this.instance.payload.getPath(), `${fault}; the data blocks are kept verbatim as payload`, 'warning');
|
|
128
262
|
},
|
|
129
263
|
encode: function () {
|
|
130
264
|
const payload = this.instance.payload.getValue('');
|
|
@@ -148,3 +282,4 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
148
282
|
}
|
|
149
283
|
}
|
|
150
284
|
exports.DNP3 = DNP3;
|
|
285
|
+
_a = DNP3;
|
package/dist/headers/DTLS.js
CHANGED
|
@@ -64,11 +64,13 @@ class DTLS extends BaseHeader_1.BaseHeader {
|
|
|
64
64
|
summary: 'DTLS type=${contentType} len=${length}',
|
|
65
65
|
properties: {
|
|
66
66
|
//ContentType (20 change_cipher_spec, 21 alert, 22 handshake, 23 application_data,
|
|
67
|
-
//24 heartbeat). Kept as an integer — the record header is otherwise opaque here.
|
|
68
|
-
|
|
67
|
+
//24 heartbeat). Kept as an integer — the record header is otherwise opaque here. Default
|
|
68
|
+
//22 (handshake): match() requires a type in 20..25.
|
|
69
|
+
contentType: { ...this.fieldUInt('contentType', 0, 1, 'Content Type'), default: 22 },
|
|
69
70
|
//Version — 0xfeff DTLS 1.0 / 0xfefd DTLS 1.2. Stored as a lower-case hex string so any
|
|
70
71
|
//value round-trips verbatim (the match gate restricts real selection to feff/fefd).
|
|
71
|
-
|
|
72
|
+
//Default fefd (DTLS 1.2).
|
|
73
|
+
version: { ...this.fieldHex('version', 1, 2, 'Version'), default: 'fefd' },
|
|
72
74
|
epoch: this.fieldUInt('epoch', 3, 2, 'Epoch'),
|
|
73
75
|
//48-bit per-epoch sequence number, kept verbatim as hex (exceeds the 32-bit fieldUInt path).
|
|
74
76
|
sequenceNumber: this.fieldHex('sequenceNumber', 5, 6, 'Sequence Number'),
|
package/dist/headers/Diameter.js
CHANGED
|
@@ -65,7 +65,8 @@ class Diameter extends BaseHeader_1.BaseHeader {
|
|
|
65
65
|
type: 'object',
|
|
66
66
|
summary: 'Diameter cmd=${commandCode}',
|
|
67
67
|
properties: {
|
|
68
|
-
|
|
68
|
+
//Default 1: the only Diameter version (RFC 6733 §3), and what match() requires.
|
|
69
|
+
version: { ...this.fieldUInt('version', 0, 1, 'Version'), default: 1 },
|
|
69
70
|
messageLength: {
|
|
70
71
|
type: 'integer',
|
|
71
72
|
autoCalculated: true,
|
package/dist/headers/EIGRP.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ import { DemuxProducer } from '../types/DemuxProducer';
|
|
|
13
13
|
* OSPF #available) — a lying Length near the end never reads into a trailing FCS/padding. TLV values are
|
|
14
14
|
* kept verbatim as hex (per-TLV route/parameter bodies are opaque here), so every TLV round-trips
|
|
15
15
|
* byte-for-byte; the Length is honored when supplied (a crafted TLV may lie) else derived from the value
|
|
16
|
-
* byte count. The Checksum is
|
|
17
|
-
* well-formed packet round-trips byte-for-byte. Leaf header —
|
|
16
|
+
* byte count. The Checksum is computed over the whole EIGRP packet when left out (no pseudo-header, over
|
|
17
|
+
* IPv4 or IPv6), else written as given. A well-formed packet round-trips byte-for-byte. Leaf header —
|
|
18
|
+
* TLV sub-structures are not sub-decoded.
|
|
18
19
|
*/
|
|
19
20
|
export declare class EIGRP extends BaseHeader {
|
|
20
21
|
#private;
|
package/dist/headers/EIGRP.js
CHANGED
|
@@ -6,6 +6,7 @@ const BufferToHex_1 = require("../helper/BufferToHex");
|
|
|
6
6
|
const HexToBuffer_1 = require("../helper/HexToBuffer");
|
|
7
7
|
const BufferToNumber_1 = require("../helper/BufferToNumber");
|
|
8
8
|
const NumberToBuffer_1 = require("../helper/NumberToBuffer");
|
|
9
|
+
const Checksum_1 = require("../helper/Checksum");
|
|
9
10
|
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
10
11
|
/**
|
|
11
12
|
* EIGRP — Enhanced Interior Gateway Routing Protocol (Cisco), carried directly over IP as protocol 88.
|
|
@@ -19,8 +20,9 @@ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
|
19
20
|
* OSPF #available) — a lying Length near the end never reads into a trailing FCS/padding. TLV values are
|
|
20
21
|
* kept verbatim as hex (per-TLV route/parameter bodies are opaque here), so every TLV round-trips
|
|
21
22
|
* byte-for-byte; the Length is honored when supplied (a crafted TLV may lie) else derived from the value
|
|
22
|
-
* byte count. The Checksum is
|
|
23
|
-
* well-formed packet round-trips byte-for-byte. Leaf header —
|
|
23
|
+
* byte count. The Checksum is computed over the whole EIGRP packet when left out (no pseudo-header, over
|
|
24
|
+
* IPv4 or IPv6), else written as given. A well-formed packet round-trips byte-for-byte. Leaf header —
|
|
25
|
+
* TLV sub-structures are not sub-decoded.
|
|
24
26
|
*/
|
|
25
27
|
class EIGRP extends BaseHeader_1.BaseHeader {
|
|
26
28
|
constructor() {
|
|
@@ -66,9 +68,33 @@ class EIGRP extends BaseHeader_1.BaseHeader {
|
|
|
66
68
|
//==== Fixed 20-byte header ====
|
|
67
69
|
version: this.fieldUInt('version', 0, 1, 'Version'),
|
|
68
70
|
opcode: this.fieldUInt('opcode', 1, 1, 'Opcode'),
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
checksum:
|
|
71
|
+
//Internet checksum over the whole EIGRP packet (header + TLVs, checksum field zeroed),
|
|
72
|
+
//computed once every field is written when left out; a given value is written as given.
|
|
73
|
+
checksum: {
|
|
74
|
+
type: 'integer',
|
|
75
|
+
autoCalculated: true,
|
|
76
|
+
label: 'Checksum',
|
|
77
|
+
minimum: 0,
|
|
78
|
+
maximum: 65535,
|
|
79
|
+
decode: function () {
|
|
80
|
+
this.instance.checksum.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
|
|
81
|
+
},
|
|
82
|
+
encode: function () {
|
|
83
|
+
if (!this.isLeftOut(this.instance.checksum)) {
|
|
84
|
+
const checksum = this.instance.checksum.getValue(0);
|
|
85
|
+
this.instance.checksum.setValue(checksum);
|
|
86
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this.instance.checksum.setValue(0);
|
|
90
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
91
|
+
this.addPostSelfEncodeHandler(() => {
|
|
92
|
+
const checksum = (0, Checksum_1.InternetChecksum)(this.packet.subarray(this.startPos, this.endPos));
|
|
93
|
+
this.instance.checksum.setValue(checksum);
|
|
94
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
},
|
|
72
98
|
flags: this.fieldUInt('flags', 4, 4, 'Flags'),
|
|
73
99
|
sequence: this.fieldUInt('sequence', 8, 4, 'Sequence'),
|
|
74
100
|
ack: this.fieldUInt('ack', 12, 4, 'Acknowledge'),
|
|
@@ -43,8 +43,9 @@ class Elasticsearch extends BaseHeader_1.BaseHeader {
|
|
|
43
43
|
type: 'object',
|
|
44
44
|
summary: 'Elasticsearch reqId=${requestId} len=${messageLength}',
|
|
45
45
|
properties: {
|
|
46
|
-
//The 'ES' magic (0x4553) — kept verbatim as hex so any prefix still round-trips.
|
|
47
|
-
|
|
46
|
+
//The 'ES' magic (0x4553) — kept verbatim as hex so any prefix still round-trips. Default
|
|
47
|
+
//'ES': what match() requires.
|
|
48
|
+
magic: { ...this.fieldHex('magic', 0, 2, 'Magic'), default: '4553' },
|
|
48
49
|
messageLength: {
|
|
49
50
|
type: 'integer',
|
|
50
51
|
autoCalculated: true,
|
|
@@ -79,6 +79,7 @@ class EthernetII extends BaseHeader_1.BaseHeader {
|
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
etherType: {
|
|
82
|
+
autoCalculated: true,
|
|
82
83
|
type: 'string',
|
|
83
84
|
minLength: 4,
|
|
84
85
|
maxLength: 4,
|
|
@@ -100,6 +101,9 @@ class EthernetII extends BaseHeader_1.BaseHeader {
|
|
|
100
101
|
}
|
|
101
102
|
};
|
|
102
103
|
}
|
|
104
|
+
payloadEnd() {
|
|
105
|
+
return this.ieee802dot3PayloadEnd(this.instance.etherType);
|
|
106
|
+
}
|
|
103
107
|
match() {
|
|
104
108
|
//Fewer bytes than the 14-octet header cannot be reproduced by these fields (encode always writes
|
|
105
109
|
//a whole header): leave them to raw so they round-trip byte-exact.
|
package/dist/headers/GELF.js
CHANGED
|
@@ -104,6 +104,7 @@ class GELF extends BaseHeader_1.BaseHeader {
|
|
|
104
104
|
//when the form is chunked; otherwise it stays unset so it neither decodes phantom values
|
|
105
105
|
//nor writes bytes for the gzip/uncompressed forms.
|
|
106
106
|
magic: {
|
|
107
|
+
default: '1e0f',
|
|
107
108
|
type: 'string',
|
|
108
109
|
label: 'Magic',
|
|
109
110
|
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
package/dist/headers/GENEVE.js
CHANGED
|
@@ -86,6 +86,7 @@ class GENEVE extends BaseHeader_1.BaseHeader {
|
|
|
86
86
|
//Protocol Type is the EtherType of the inner frame — stored as a lowercase hex string
|
|
87
87
|
//(like eth.etherType) so it can drive the `ethertype` demux dimension to the inner codec.
|
|
88
88
|
protocolType: {
|
|
89
|
+
autoCalculated: true,
|
|
89
90
|
type: 'string', label: 'Protocol Type', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
90
91
|
decode: function () { this.instance.protocolType.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(2, 2))); },
|
|
91
92
|
encode: function () {
|
package/dist/headers/GRE.js
CHANGED
|
@@ -109,6 +109,7 @@ class GRE extends BaseHeader_1.BaseHeader {
|
|
|
109
109
|
//Protocol Type is the EtherType of the inner frame — stored as a lowercase hex string
|
|
110
110
|
//(like eth.etherType) so it can drive the `ethertype` demux dimension to the inner codec.
|
|
111
111
|
protocolType: {
|
|
112
|
+
autoCalculated: true,
|
|
112
113
|
type: 'string', label: 'Protocol Type', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
113
114
|
decode: function () { this.instance.protocolType.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(2, 2))); },
|
|
114
115
|
encode: function () {
|
package/dist/headers/GTPv2C.js
CHANGED
package/dist/headers/Goose.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
|
|
2
2
|
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
3
|
-
import
|
|
3
|
+
import { BERElement } from '../lib/BERElement';
|
|
4
4
|
declare enum ItemDataType {
|
|
5
5
|
Boolean = "Boolean",
|
|
6
6
|
INT8 = "INT8",
|
|
@@ -78,10 +78,21 @@ type StructureDataItem = {
|
|
|
78
78
|
dataType: ItemDataType.Structure;
|
|
79
79
|
value: DataItem[];
|
|
80
80
|
};
|
|
81
|
-
|
|
81
|
+
/**
|
|
82
|
+
* How a goosePdu element was encoded on the wire, where that differs from the form encode writes by
|
|
83
|
+
* default (the minimal BER length, the minimal INTEGER content). Decode records it only for such
|
|
84
|
+
* elements, so a tree without it encodes exactly as before; encode follows it while the value fits.
|
|
85
|
+
*/
|
|
86
|
+
type ElementEncoding = {
|
|
87
|
+
lengthOctets?: number;
|
|
88
|
+
width?: number;
|
|
89
|
+
content?: string;
|
|
90
|
+
};
|
|
91
|
+
type DataItem = (BooleanDataItem | INT8DataItem | INT16DataItem | INT32DataItem | INT64DataItem | INT8UDataItem | INT16UDataItem | INT32UDataItem | FLOAT32DataItem | CODEDENUMDataItem | OCTETSTRINGDataItem | VISIBLESTRINGDataItem | TimeStampDataItem | QualityDataItem | StructureDataItem) & {
|
|
92
|
+
encoding?: ElementEncoding;
|
|
93
|
+
};
|
|
82
94
|
export declare class Goose extends BaseHeader {
|
|
83
|
-
|
|
84
|
-
protected TLVChild: TLV[];
|
|
95
|
+
#private;
|
|
85
96
|
/**
|
|
86
97
|
* True when at least one structured goosePdu field decoded/was supplied. Used to
|
|
87
98
|
* decide whether the raw-passthrough fallback applies.
|
|
@@ -96,10 +107,11 @@ export declare class Goose extends BaseHeader {
|
|
|
96
107
|
SCHEMA: ProtocolJSONSchema;
|
|
97
108
|
/**
|
|
98
109
|
* Decode data TLV items
|
|
99
|
-
* @param
|
|
110
|
+
* @param dataElements
|
|
111
|
+
* @param path
|
|
100
112
|
* @protected
|
|
101
113
|
*/
|
|
102
|
-
protected decodeDataTLVItem(
|
|
114
|
+
protected decodeDataTLVItem(dataElements: BERElement[], path: string): DataItem[];
|
|
103
115
|
/**
|
|
104
116
|
* Decode a BIT STRING (tag 0x84) data item
|
|
105
117
|
* CODED-ENUM is 2 octets and Quality 3 octets (the leading unused-bits octet included in the
|
|
@@ -130,16 +142,28 @@ export declare class Goose extends BaseHeader {
|
|
|
130
142
|
* @protected
|
|
131
143
|
*/
|
|
132
144
|
protected decodeUnsignedIntegerItem(value: Buffer, path: string): DataItem;
|
|
145
|
+
/**
|
|
146
|
+
* Decode a FLOATING-POINT (tag 0x87) data item
|
|
147
|
+
* The first content octet is the exponent width, not part of the number: IEC 61850-8-1 encodes a
|
|
148
|
+
* FLOAT32 as 08 followed by the 4 octets of an IEEE 754 single. A FLOAT64 (exponent width 11, 8
|
|
149
|
+
* octets) keeps its value; other forms read as 0. Either way the item re-encodes as captured until
|
|
150
|
+
* its value changes.
|
|
151
|
+
* @param value
|
|
152
|
+
* @param path
|
|
153
|
+
* @protected
|
|
154
|
+
*/
|
|
155
|
+
protected decodeFloatingPointItem(value: Buffer, path: string): DataItem;
|
|
133
156
|
/**
|
|
134
157
|
* Encode data TLV items
|
|
135
158
|
* @param dataItems
|
|
136
159
|
* @protected
|
|
137
160
|
*/
|
|
138
|
-
protected encodeDataTLVItem(dataItems: DataItem[]):
|
|
161
|
+
protected encodeDataTLVItem(dataItems: DataItem[]): Buffer[];
|
|
139
162
|
readonly id: string;
|
|
140
163
|
readonly matchKeys: string[];
|
|
141
164
|
readonly name: string;
|
|
142
165
|
readonly nickname: string;
|
|
143
166
|
match(): boolean;
|
|
167
|
+
payloadEnd(): number | undefined;
|
|
144
168
|
}
|
|
145
169
|
export {};
|