@netkitty/codec 2.0.0 → 2.1.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 +136 -0
- package/README.md +10 -6
- package/README.zh-CN.md +9 -6
- package/dist/Codec.js +4 -1
- package/dist/abstracts/BaseHeader.d.ts +26 -0
- package/dist/abstracts/BaseHeader.js +53 -0
- package/dist/headers/AH.js +3 -2
- package/dist/headers/BFD.d.ts +2 -1
- package/dist/headers/BFD.js +30 -4
- package/dist/headers/BGP.js +5 -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/DCCP.d.ts +3 -2
- package/dist/headers/DCCP.js +60 -8
- package/dist/headers/DNP3.d.ts +5 -3
- package/dist/headers/DNP3.js +62 -7
- package/dist/headers/EIGRP.d.ts +3 -2
- package/dist/headers/EIGRP.js +31 -5
- package/dist/headers/EthernetII.js +1 -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.js +4 -4
- 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.js +189 -160
- package/dist/headers/IEC104_S_Frame.js +19 -1
- package/dist/headers/IEC104_U_Frame.js +19 -1
- package/dist/headers/IEC61850SampledValues.js +4 -4
- package/dist/headers/IGMP.d.ts +8 -7
- package/dist/headers/IGMP.js +57 -19
- package/dist/headers/IPFIX.js +1 -1
- package/dist/headers/IPv4.js +26 -23
- package/dist/headers/IPv6.js +4 -1
- package/dist/headers/IPv6HopByHopOptions.js +3 -1
- package/dist/headers/ISAKMP.js +1 -0
- package/dist/headers/Kerberos.js +1 -0
- package/dist/headers/L2TP.js +1 -0
- package/dist/headers/LDAP.js +1 -1
- package/dist/headers/LLC.js +1 -0
- package/dist/headers/NHRP.d.ts +1 -1
- package/dist/headers/NHRP.js +29 -4
- package/dist/headers/OSPF.d.ts +3 -3
- package/dist/headers/OSPF.js +72 -7
- 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/PTP.js +5 -1
- package/dist/headers/RDP.js +2 -0
- package/dist/headers/RGoose.js +2 -0
- package/dist/headers/RSVP.d.ts +3 -3
- package/dist/headers/RSVP.js +56 -42
- package/dist/headers/RTCP.js +1 -0
- package/dist/headers/SCTP.d.ts +2 -2
- package/dist/headers/SCTP.js +29 -5
- package/dist/headers/SNAP.js +2 -2
- package/dist/headers/SNMP.js +2 -2
- package/dist/headers/STUN.js +1 -1
- 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.js +39 -6
- 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/UDP.js +17 -61
- package/dist/headers/VLAN_802dot1Q.js +1 -0
- package/dist/headers/VRRP.d.ts +2 -1
- package/dist/headers/VRRP.js +45 -9
- 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/package.json +2 -2
|
@@ -27,11 +27,13 @@ class IEC104_S_Frame extends BaseHeader_1.BaseHeader {
|
|
|
27
27
|
this.SCHEMA = {
|
|
28
28
|
type: 'object',
|
|
29
29
|
properties: {
|
|
30
|
+
//Default 0x68: the start byte of every IEC 104 APDU, and what match() requires.
|
|
30
31
|
startByte: {
|
|
31
32
|
type: 'integer',
|
|
32
33
|
label: 'Start Byte',
|
|
33
34
|
minimum: 0,
|
|
34
35
|
maximum: 255,
|
|
36
|
+
default: 104,
|
|
35
37
|
decode: () => {
|
|
36
38
|
this.instance.startByte.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1)));
|
|
37
39
|
},
|
|
@@ -39,8 +41,11 @@ class IEC104_S_Frame extends BaseHeader_1.BaseHeader {
|
|
|
39
41
|
this.writeBytes(0, (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.startByte.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'))));
|
|
40
42
|
}
|
|
41
43
|
},
|
|
44
|
+
//The octet count after this field (the 4-octet control field). Written as given; left out,
|
|
45
|
+
//it is what this layer writes after it.
|
|
42
46
|
apduLength: {
|
|
43
47
|
type: 'integer',
|
|
48
|
+
autoCalculated: true,
|
|
44
49
|
label: 'APDU Length',
|
|
45
50
|
minimum: 0,
|
|
46
51
|
maximum: 255,
|
|
@@ -48,7 +53,20 @@ class IEC104_S_Frame extends BaseHeader_1.BaseHeader {
|
|
|
48
53
|
this.instance.apduLength.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(1, 1)));
|
|
49
54
|
},
|
|
50
55
|
encode: () => {
|
|
51
|
-
|
|
56
|
+
if (!this.isLeftOut(this.instance.apduLength)) {
|
|
57
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.apduLength.getValue(0)));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt8ToBuffer)(0));
|
|
61
|
+
this.addPostSelfEncodeHandler(() => {
|
|
62
|
+
let apduLength = this.length - 2;
|
|
63
|
+
if (apduLength > 255) {
|
|
64
|
+
this.recordError(this.instance.apduLength.getPath(), 'Maximum value is 255');
|
|
65
|
+
apduLength = 255;
|
|
66
|
+
}
|
|
67
|
+
this.instance.apduLength.setValue(apduLength);
|
|
68
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt8ToBuffer)(apduLength));
|
|
69
|
+
});
|
|
52
70
|
}
|
|
53
71
|
},
|
|
54
72
|
controlField: {
|
|
@@ -28,11 +28,13 @@ class IEC104_U_Frame extends BaseHeader_1.BaseHeader {
|
|
|
28
28
|
this.SCHEMA = {
|
|
29
29
|
type: 'object',
|
|
30
30
|
properties: {
|
|
31
|
+
//Default 0x68: the start byte of every IEC 104 APDU, and what match() requires.
|
|
31
32
|
startByte: {
|
|
32
33
|
type: 'integer',
|
|
33
34
|
label: 'Start Byte',
|
|
34
35
|
minimum: 0,
|
|
35
36
|
maximum: 255,
|
|
37
|
+
default: 104,
|
|
36
38
|
decode: () => {
|
|
37
39
|
this.instance.startByte.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1)));
|
|
38
40
|
},
|
|
@@ -40,8 +42,11 @@ class IEC104_U_Frame extends BaseHeader_1.BaseHeader {
|
|
|
40
42
|
this.writeBytes(0, (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.startByte.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'))));
|
|
41
43
|
}
|
|
42
44
|
},
|
|
45
|
+
//The octet count after this field (the 4-octet control field). Written as given; left out,
|
|
46
|
+
//it is what this layer writes after it.
|
|
43
47
|
apduLength: {
|
|
44
48
|
type: 'integer',
|
|
49
|
+
autoCalculated: true,
|
|
45
50
|
label: 'APDU Length',
|
|
46
51
|
minimum: 0,
|
|
47
52
|
maximum: 255,
|
|
@@ -49,7 +54,20 @@ class IEC104_U_Frame extends BaseHeader_1.BaseHeader {
|
|
|
49
54
|
this.instance.apduLength.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(1, 1)));
|
|
50
55
|
},
|
|
51
56
|
encode: () => {
|
|
52
|
-
|
|
57
|
+
if (!this.isLeftOut(this.instance.apduLength)) {
|
|
58
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.apduLength.getValue(0)));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt8ToBuffer)(0));
|
|
62
|
+
this.addPostSelfEncodeHandler(() => {
|
|
63
|
+
let apduLength = this.length - 2;
|
|
64
|
+
if (apduLength > 255) {
|
|
65
|
+
this.recordError(this.instance.apduLength.getPath(), 'Maximum value is 255');
|
|
66
|
+
apduLength = 255;
|
|
67
|
+
}
|
|
68
|
+
this.instance.apduLength.setValue(apduLength);
|
|
69
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt8ToBuffer)(apduLength));
|
|
70
|
+
});
|
|
53
71
|
}
|
|
54
72
|
},
|
|
55
73
|
controlField: {
|
|
@@ -42,8 +42,8 @@ class IEC61850SampledValues extends BaseHeader_1.BaseHeader {
|
|
|
42
42
|
this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
|
|
43
43
|
},
|
|
44
44
|
encode: () => {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (!this.isLeftOut(this.instance.length)) {
|
|
46
|
+
const length = this.instance.length.getValue(0);
|
|
47
47
|
this.instance.length.setValue(length);
|
|
48
48
|
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
|
|
49
49
|
}
|
|
@@ -132,7 +132,7 @@ class IEC61850SampledValues extends BaseHeader_1.BaseHeader {
|
|
|
132
132
|
//the original bytes means keeping it).
|
|
133
133
|
const rawBuffer = Buffer.from(this.instance.svPdu.raw.getValue().toString(), 'hex');
|
|
134
134
|
this.writeBytes(8, rawBuffer);
|
|
135
|
-
if (this.instance.length
|
|
135
|
+
if (!this.isLeftOut(this.instance.length))
|
|
136
136
|
return;
|
|
137
137
|
this.instance.length.setValue(8 + rawBuffer.length);
|
|
138
138
|
return;
|
|
@@ -146,7 +146,7 @@ class IEC61850SampledValues extends BaseHeader_1.BaseHeader {
|
|
|
146
146
|
* Update the length only if it is not set
|
|
147
147
|
* Update length(APPID's length + Length's length + Reserved1's length + Reserved2's length + svPdu's length)
|
|
148
148
|
*/
|
|
149
|
-
if (this.instance.length
|
|
149
|
+
if (!this.isLeftOut(this.instance.length))
|
|
150
150
|
return;
|
|
151
151
|
this.instance.length.setValue(2 + 2 + 2 + 2 + svPduBuffer.length);
|
|
152
152
|
},
|
package/dist/headers/IGMP.d.ts
CHANGED
|
@@ -8,16 +8,17 @@ import { DemuxProducer } from '../types/DemuxProducer';
|
|
|
8
8
|
*
|
|
9
9
|
* - v1/v2 (Membership Query with total length 8 / Report 0x12 / Report 0x16 / Leave 0x17): a single
|
|
10
10
|
* 4-byte Group Address (dotted-quad).
|
|
11
|
-
* - v3 Membership Query (Type 0x11 with an IP payload ≥ 12 bytes
|
|
12
|
-
* QQIC (1) + Number of Sources (2) + that many
|
|
13
|
-
* hex (bounded by the source count and the IP
|
|
11
|
+
* - v3 Membership Query (Type 0x11 with an IP payload ≥ 12 bytes; on encode, Type 0x11 with any v3
|
|
12
|
+
* field given): Group Address (4) + Resv/S/QRV (1) + QQIC (1) + Number of Sources (2) + that many
|
|
13
|
+
* 4-byte source addresses, kept verbatim as `sources` hex (bounded by the source count and the IP
|
|
14
|
+
* payload).
|
|
14
15
|
* - v3 Membership Report (Type 0x22): 2 reserved bytes + Number of Group Records (2) + the group
|
|
15
16
|
* records, kept verbatim as `records` hex (bounded by the IP payload).
|
|
16
17
|
*
|
|
17
|
-
* The Checksum is
|
|
18
|
-
* message round-trips byte-for-byte. The message is bounded by the enclosing IPv4 datagram
|
|
19
|
-
* length − IP header length) so trailing padding is left to the codec's recursion / RawData. The
|
|
20
|
-
* source
|
|
18
|
+
* The Checksum is computed over the whole IGMP message when left out, else written as given; a
|
|
19
|
+
* well-formed message round-trips byte-for-byte. The message is bounded by the enclosing IPv4 datagram
|
|
20
|
+
* (total length − IP header length) so trailing padding is left to the codec's recursion / RawData. The
|
|
21
|
+
* v3 source count is honor-else-derive; the v3 record structures are kept as bounded hex.
|
|
21
22
|
*/
|
|
22
23
|
export declare class IGMP extends BaseHeader {
|
|
23
24
|
#private;
|
package/dist/headers/IGMP.js
CHANGED
|
@@ -8,6 +8,7 @@ const BufferToIP_1 = require("../helper/BufferToIP");
|
|
|
8
8
|
const IPToBuffer_1 = require("../helper/IPToBuffer");
|
|
9
9
|
const BufferToNumber_1 = require("../helper/BufferToNumber");
|
|
10
10
|
const NumberToBuffer_1 = require("../helper/NumberToBuffer");
|
|
11
|
+
const Checksum_1 = require("../helper/Checksum");
|
|
11
12
|
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
12
13
|
/**
|
|
13
14
|
* IGMP — Internet Group Management Protocol (IGMPv2 RFC 2236, IGMPv3 RFC 3376), carried directly over
|
|
@@ -16,16 +17,17 @@ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
|
16
17
|
*
|
|
17
18
|
* - v1/v2 (Membership Query with total length 8 / Report 0x12 / Report 0x16 / Leave 0x17): a single
|
|
18
19
|
* 4-byte Group Address (dotted-quad).
|
|
19
|
-
* - v3 Membership Query (Type 0x11 with an IP payload ≥ 12 bytes
|
|
20
|
-
* QQIC (1) + Number of Sources (2) + that many
|
|
21
|
-
* hex (bounded by the source count and the IP
|
|
20
|
+
* - v3 Membership Query (Type 0x11 with an IP payload ≥ 12 bytes; on encode, Type 0x11 with any v3
|
|
21
|
+
* field given): Group Address (4) + Resv/S/QRV (1) + QQIC (1) + Number of Sources (2) + that many
|
|
22
|
+
* 4-byte source addresses, kept verbatim as `sources` hex (bounded by the source count and the IP
|
|
23
|
+
* payload).
|
|
22
24
|
* - v3 Membership Report (Type 0x22): 2 reserved bytes + Number of Group Records (2) + the group
|
|
23
25
|
* records, kept verbatim as `records` hex (bounded by the IP payload).
|
|
24
26
|
*
|
|
25
|
-
* The Checksum is
|
|
26
|
-
* message round-trips byte-for-byte. The message is bounded by the enclosing IPv4 datagram
|
|
27
|
-
* length − IP header length) so trailing padding is left to the codec's recursion / RawData. The
|
|
28
|
-
* source
|
|
27
|
+
* The Checksum is computed over the whole IGMP message when left out, else written as given; a
|
|
28
|
+
* well-formed message round-trips byte-for-byte. The message is bounded by the enclosing IPv4 datagram
|
|
29
|
+
* (total length − IP header length) so trailing padding is left to the codec's recursion / RawData. The
|
|
30
|
+
* v3 source count is honor-else-derive; the v3 record structures are kept as bounded hex.
|
|
29
31
|
*/
|
|
30
32
|
class IGMP extends BaseHeader_1.BaseHeader {
|
|
31
33
|
constructor() {
|
|
@@ -65,6 +67,18 @@ class IGMP extends BaseHeader_1.BaseHeader {
|
|
|
65
67
|
const type = this.instance.type.getValue(0);
|
|
66
68
|
return type === 0x11 && this.#available() >= 12;
|
|
67
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Encode-side counterpart of #isV3Query(): Type 0x11 with any v3 Query field given. The shape comes
|
|
72
|
+
* from the message's own fields, never from the IP length, which is not computed yet when IGMP
|
|
73
|
+
* encodes (it is filled in a post-packet handler once every layer is written).
|
|
74
|
+
*/
|
|
75
|
+
#encodesV3Query() {
|
|
76
|
+
const type = this.instance.type.getValue(0);
|
|
77
|
+
if (type !== 0x11)
|
|
78
|
+
return false;
|
|
79
|
+
return !this.isLeftOut(this.instance.resvSQRV) || !this.isLeftOut(this.instance.qqic)
|
|
80
|
+
|| !this.isLeftOut(this.instance.numSources) || !this.isLeftOut(this.instance.sources);
|
|
81
|
+
}
|
|
68
82
|
/** True when this is an IGMPv3 Membership Report (Type 0x22): reserved + group records, no group address. */
|
|
69
83
|
#isV3Report() {
|
|
70
84
|
const type = this.instance.type.getValue(0);
|
|
@@ -78,9 +92,33 @@ class IGMP extends BaseHeader_1.BaseHeader {
|
|
|
78
92
|
//==== Fixed 4-byte header (RFC 2236 §2, RFC 3376 §4) ====
|
|
79
93
|
type: this.fieldUInt('type', 0, 1, 'Type'),
|
|
80
94
|
maxRespCode: this.fieldUInt('maxRespCode', 1, 1, 'Max Resp Code'),
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
checksum:
|
|
95
|
+
//Internet checksum over the whole IGMP message (RFC 2236 §2.3, RFC 3376 §4.1.2), computed
|
|
96
|
+
//once every field is written when left out; a given value is written as given.
|
|
97
|
+
checksum: {
|
|
98
|
+
type: 'integer',
|
|
99
|
+
autoCalculated: true,
|
|
100
|
+
label: 'Checksum',
|
|
101
|
+
minimum: 0,
|
|
102
|
+
maximum: 65535,
|
|
103
|
+
decode: function () {
|
|
104
|
+
this.instance.checksum.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
|
|
105
|
+
},
|
|
106
|
+
encode: function () {
|
|
107
|
+
if (!this.isLeftOut(this.instance.checksum)) {
|
|
108
|
+
const checksum = this.instance.checksum.getValue(0);
|
|
109
|
+
this.instance.checksum.setValue(checksum);
|
|
110
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.instance.checksum.setValue(0);
|
|
114
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
115
|
+
this.addPostSelfEncodeHandler(() => {
|
|
116
|
+
const checksum = (0, Checksum_1.InternetChecksum)(this.packet.subarray(this.startPos, this.endPos));
|
|
117
|
+
this.instance.checksum.setValue(checksum);
|
|
118
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
},
|
|
84
122
|
//==== Group Address (offset 4): present for every type except the v3 Report (0x22),
|
|
85
123
|
//whose bytes 4-7 are reserved + record count instead. ====
|
|
86
124
|
groupAddress: {
|
|
@@ -102,7 +140,8 @@ class IGMP extends BaseHeader_1.BaseHeader {
|
|
|
102
140
|
this.writeBytes(4, (0, IPToBuffer_1.IPv4ToBuffer)(groupAddress));
|
|
103
141
|
}
|
|
104
142
|
},
|
|
105
|
-
//==== IGMPv3 Membership Query body (RFC 3376 §4.1), decoded only when #isV3Query()
|
|
143
|
+
//==== IGMPv3 Membership Query body (RFC 3376 §4.1), decoded only when #isV3Query() and
|
|
144
|
+
//encoded only when #encodesV3Query() ====
|
|
106
145
|
resvSQRV: {
|
|
107
146
|
type: 'integer',
|
|
108
147
|
label: 'Resv/S/QRV',
|
|
@@ -114,7 +153,7 @@ class IGMP extends BaseHeader_1.BaseHeader {
|
|
|
114
153
|
this.instance.resvSQRV.setValue(this.readBytes(8, 1)[0] ?? 0);
|
|
115
154
|
},
|
|
116
155
|
encode: function () {
|
|
117
|
-
if (!this.#
|
|
156
|
+
if (!this.#encodesV3Query())
|
|
118
157
|
return;
|
|
119
158
|
this.writeBytes(8, Buffer.from([this.instance.resvSQRV.getValue(0) & 0xff]));
|
|
120
159
|
}
|
|
@@ -130,7 +169,7 @@ class IGMP extends BaseHeader_1.BaseHeader {
|
|
|
130
169
|
this.instance.qqic.setValue(this.readBytes(9, 1)[0] ?? 0);
|
|
131
170
|
},
|
|
132
171
|
encode: function () {
|
|
133
|
-
if (!this.#
|
|
172
|
+
if (!this.#encodesV3Query())
|
|
134
173
|
return;
|
|
135
174
|
this.writeBytes(9, Buffer.from([this.instance.qqic.getValue(0) & 0xff]));
|
|
136
175
|
}
|
|
@@ -147,14 +186,13 @@ class IGMP extends BaseHeader_1.BaseHeader {
|
|
|
147
186
|
this.instance.numSources.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(10, 2)));
|
|
148
187
|
},
|
|
149
188
|
encode: function () {
|
|
150
|
-
if (!this.#
|
|
189
|
+
if (!this.#encodesV3Query())
|
|
151
190
|
return;
|
|
152
191
|
//honor-else-derive: honored when supplied (a crafted message may lie); else the
|
|
153
192
|
//number of 4-byte source addresses carried in the `sources` hex.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
: Math.floor((0, HexToBuffer_1.HexToBuffer)(this.instance.sources.getValue('')).length / 4);
|
|
193
|
+
let value = this.isLeftOut(this.instance.numSources)
|
|
194
|
+
? Math.floor((0, HexToBuffer_1.HexToBuffer)(this.instance.sources.getValue('')).length / 4)
|
|
195
|
+
: this.instance.numSources.getValue(0);
|
|
158
196
|
if (value > 65535) {
|
|
159
197
|
this.recordError(this.instance.numSources.getPath(), 'Maximum value is 65535');
|
|
160
198
|
value = 65535;
|
|
@@ -184,7 +222,7 @@ class IGMP extends BaseHeader_1.BaseHeader {
|
|
|
184
222
|
this.instance.sources.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(12, byteLength)));
|
|
185
223
|
},
|
|
186
224
|
encode: function () {
|
|
187
|
-
if (!this.#
|
|
225
|
+
if (!this.#encodesV3Query())
|
|
188
226
|
return;
|
|
189
227
|
const sources = this.instance.sources.getValue('');
|
|
190
228
|
if (sources)
|
package/dist/headers/IPFIX.js
CHANGED
|
@@ -59,7 +59,7 @@ class IPFIX extends BaseHeader_1.BaseHeader {
|
|
|
59
59
|
//honored (a crafted message may lie); otherwise a placeholder is written now and
|
|
60
60
|
//the real total is filled in after every Set has encoded (post-self-encode).
|
|
61
61
|
const messageLength = this.instance.length.getValue(0);
|
|
62
|
-
if (
|
|
62
|
+
if (!this.isLeftOut(this.instance.length)) {
|
|
63
63
|
this.instance.length.setValue(messageLength);
|
|
64
64
|
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(messageLength));
|
|
65
65
|
}
|
package/dist/headers/IPv4.js
CHANGED
|
@@ -56,6 +56,7 @@ class IPv4 extends BaseHeader_1.BaseHeader {
|
|
|
56
56
|
summary: '${sip} → ${dip}',
|
|
57
57
|
properties: {
|
|
58
58
|
version: {
|
|
59
|
+
default: 4,
|
|
59
60
|
type: 'integer',
|
|
60
61
|
label: 'Version',
|
|
61
62
|
minimum: 0,
|
|
@@ -80,24 +81,25 @@ class IPv4 extends BaseHeader_1.BaseHeader {
|
|
|
80
81
|
autoCalculated: true,
|
|
81
82
|
label: 'Header Length',
|
|
82
83
|
//The field floor (IHL 0), not the protocol minimum of 20: a decoded malformed header (IHL
|
|
83
|
-
//
|
|
84
|
+
//0–4) must re-encode. Left out means "compute"; a value below 20 is written as given, flagged.
|
|
84
85
|
minimum: 0,
|
|
85
86
|
maximum: 60,
|
|
86
87
|
decode: function () {
|
|
87
88
|
this.instance.hdrLen.setValue(this.readBits(0, 1, 4, 4) * 4);
|
|
88
89
|
},
|
|
89
90
|
encode: function () {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
if (!this.isLeftOut(this.instance.hdrLen)) {
|
|
92
|
+
const headerLength = this.instance.hdrLen.getValue(0);
|
|
93
|
+
if (headerLength < 20)
|
|
94
|
+
this.recordError(this.instance.hdrLen.getPath(), 'Header length should be at least 20');
|
|
95
|
+
this.writeBits(0, 1, 4, 4, Math.floor(headerLength / 4));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
this.writeBits(0, 1, 4, 4, 0);
|
|
99
|
+
this.addPostSelfEncodeHandler(() => {
|
|
100
|
+
this.instance.hdrLen.setValue(this.length);
|
|
101
|
+
this.writeBits(0, 1, 4, 4, Math.floor(this.length / 4));
|
|
102
|
+
}, 10);
|
|
101
103
|
}
|
|
102
104
|
},
|
|
103
105
|
dsfield: {
|
|
@@ -142,13 +144,12 @@ class IPv4 extends BaseHeader_1.BaseHeader {
|
|
|
142
144
|
this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
|
|
143
145
|
},
|
|
144
146
|
encode: function () {
|
|
145
|
-
//
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
|
|
147
|
+
//Left out: the total length is only known once every layer above is encoded
|
|
148
|
+
if (!this.isLeftOut(this.instance.length)) {
|
|
149
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0)));
|
|
149
150
|
}
|
|
150
151
|
else {
|
|
151
|
-
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(
|
|
152
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
152
153
|
this.addPostPacketEncodeHandler(() => {
|
|
153
154
|
let startCount = false;
|
|
154
155
|
let totalLength = 0;
|
|
@@ -196,6 +197,7 @@ class IPv4 extends BaseHeader_1.BaseHeader {
|
|
|
196
197
|
}
|
|
197
198
|
},
|
|
198
199
|
df: {
|
|
200
|
+
default: 1,
|
|
199
201
|
type: 'integer',
|
|
200
202
|
enum: [0, 1],
|
|
201
203
|
label: 'Don\'t fragment',
|
|
@@ -252,6 +254,7 @@ class IPv4 extends BaseHeader_1.BaseHeader {
|
|
|
252
254
|
}
|
|
253
255
|
},
|
|
254
256
|
protocol: {
|
|
257
|
+
autoCalculated: true,
|
|
255
258
|
type: 'integer',
|
|
256
259
|
label: 'Protocol',
|
|
257
260
|
minimum: 0,
|
|
@@ -275,16 +278,16 @@ class IPv4 extends BaseHeader_1.BaseHeader {
|
|
|
275
278
|
this.instance.checksum.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(10, 2)));
|
|
276
279
|
},
|
|
277
280
|
encode: function () {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
281
|
+
if (!this.isLeftOut(this.instance.checksum)) {
|
|
282
|
+
let checksum = this.instance.checksum.getValue(0);
|
|
283
|
+
checksum = checksum > 65535 ? 65535 : checksum;
|
|
284
|
+
checksum = checksum < 0 ? 0 : checksum;
|
|
282
285
|
this.instance.checksum.setValue(checksum);
|
|
283
286
|
this.writeBytes(10, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
284
287
|
}
|
|
285
288
|
else {
|
|
286
|
-
this.instance.checksum.setValue(
|
|
287
|
-
this.writeBytes(10, (0, NumberToBuffer_1.UInt16ToBuffer)(
|
|
289
|
+
this.instance.checksum.setValue(0);
|
|
290
|
+
this.writeBytes(10, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
288
291
|
this.addPostPacketEncodeHandler(() => {
|
|
289
292
|
const calcChecksum = this.calculateIPv4Checksum(this.packet.subarray(this.startPos, this.endPos));
|
|
290
293
|
this.instance.checksum.setValue(calcChecksum);
|
package/dist/headers/IPv6.js
CHANGED
|
@@ -31,6 +31,7 @@ class IPv6 extends BaseHeader_1.BaseHeader {
|
|
|
31
31
|
type: 'object',
|
|
32
32
|
properties: {
|
|
33
33
|
version: {
|
|
34
|
+
default: 6,
|
|
34
35
|
type: 'integer',
|
|
35
36
|
label: 'Version',
|
|
36
37
|
minimum: 0,
|
|
@@ -102,10 +103,11 @@ class IPv6 extends BaseHeader_1.BaseHeader {
|
|
|
102
103
|
this.instance.plen.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(4, 2)));
|
|
103
104
|
},
|
|
104
105
|
encode: () => {
|
|
106
|
+
const leftOut = this.isLeftOut(this.instance.plen);
|
|
105
107
|
const plen = this.instance.plen.getValue(0);
|
|
106
108
|
this.instance.plen.setValue(plen);
|
|
107
109
|
this.writeBytes(4, (0, NumberToBuffer_1.UInt16ToBuffer)(plen));
|
|
108
|
-
if (
|
|
110
|
+
if (leftOut) {
|
|
109
111
|
this.addPostPacketEncodeHandler(() => {
|
|
110
112
|
let startCount = false;
|
|
111
113
|
let totalLength = 0;
|
|
@@ -126,6 +128,7 @@ class IPv6 extends BaseHeader_1.BaseHeader {
|
|
|
126
128
|
}
|
|
127
129
|
},
|
|
128
130
|
nxt: {
|
|
131
|
+
autoCalculated: true,
|
|
129
132
|
type: 'integer',
|
|
130
133
|
label: 'Next Header',
|
|
131
134
|
minimum: 0,
|
|
@@ -45,6 +45,7 @@ class IPv6HopByHopOptions extends BaseHeader_1.BaseHeader {
|
|
|
45
45
|
type: 'object',
|
|
46
46
|
properties: {
|
|
47
47
|
nxt: {
|
|
48
|
+
autoCalculated: true,
|
|
48
49
|
type: 'integer',
|
|
49
50
|
label: 'Next Header',
|
|
50
51
|
minimum: 0,
|
|
@@ -68,10 +69,11 @@ class IPv6HopByHopOptions extends BaseHeader_1.BaseHeader {
|
|
|
68
69
|
this.instance.len.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(1, 1)));
|
|
69
70
|
},
|
|
70
71
|
encode: () => {
|
|
72
|
+
const leftOut = this.isLeftOut(this.instance.len);
|
|
71
73
|
const len = this.instance.len.getValue(0);
|
|
72
74
|
this.instance.len.setValue(len);
|
|
73
75
|
this.writeBytes(1, (0, NumberToBuffer_1.UInt8ToBuffer)(len));
|
|
74
|
-
if (
|
|
76
|
+
if (leftOut) {
|
|
75
77
|
this.addPostSelfEncodeHandler(() => {
|
|
76
78
|
//Total header = 2 (nxt+len) + options area, and must be an integral
|
|
77
79
|
//multiple of 8 octets (RFC 8200 §4.3). items encode already padded the
|
package/dist/headers/ISAKMP.js
CHANGED
|
@@ -67,6 +67,7 @@ class ISAKMP extends BaseHeader_1.BaseHeader {
|
|
|
67
67
|
label: 'Version',
|
|
68
68
|
properties: {
|
|
69
69
|
major: {
|
|
70
|
+
default: 2,
|
|
70
71
|
type: 'integer', label: 'Major', minimum: 0, maximum: 15,
|
|
71
72
|
decode: function () { this.instance.version.major.setValue(this.readBits(17, 1, 0, 4)); },
|
|
72
73
|
encode: function () { this.writeBits(17, 1, 0, 4, this.instance.version.major.getValue(2)); }
|
package/dist/headers/Kerberos.js
CHANGED
|
@@ -136,6 +136,7 @@ class Kerberos extends BaseHeader_1.BaseHeader {
|
|
|
136
136
|
//The message-type application tag (0x6a AS-REQ … 0x7e KRB-ERROR). It is the outer BER tag
|
|
137
137
|
//of the message, so it is decoded/re-emitted together with the BER length and body below.
|
|
138
138
|
msgType: {
|
|
139
|
+
default: 0x6a,
|
|
139
140
|
type: 'integer',
|
|
140
141
|
label: 'Message Type',
|
|
141
142
|
minimum: 0,
|
package/dist/headers/L2TP.js
CHANGED
package/dist/headers/LDAP.js
CHANGED
|
@@ -190,7 +190,7 @@ class LDAP extends BaseHeader_1.BaseHeader {
|
|
|
190
190
|
//The protocolOp CHOICE tag: 0x60 bindRequest, 0x61 bindResponse, 0x63 searchRequest,
|
|
191
191
|
//0x64 searchResultEntry, 0x65 searchResultDone, 0x66 modifyRequest, 0x67 modifyResponse,
|
|
192
192
|
//0x68 addRequest, 0x69 addResponse, 0x4a delRequest, 0x42 unbindRequest, 0x73 extendedReq …
|
|
193
|
-
protocolOpTag: { type: 'integer', label: 'Protocol Op Tag', minimum: 0, maximum: 255 },
|
|
193
|
+
protocolOpTag: { type: 'integer', label: 'Protocol Op Tag', minimum: 0, maximum: 255, default: 0x60 },
|
|
194
194
|
//The protocolOp body (op length/content + any controls) kept verbatim as hex — see decode.
|
|
195
195
|
protocolOpData: { type: 'string', label: 'Protocol Op Data', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
|
|
196
196
|
}
|
package/dist/headers/LLC.js
CHANGED
|
@@ -50,6 +50,7 @@ class LLC extends BaseHeader_1.BaseHeader {
|
|
|
50
50
|
//Supervisory). Stored as hex preserving its on-wire length so encode reproduces it exactly;
|
|
51
51
|
//because the non-dry read grows headerLength, the child layer starts at the correct offset.
|
|
52
52
|
control: {
|
|
53
|
+
default: '03',
|
|
53
54
|
type: 'string',
|
|
54
55
|
label: 'Control',
|
|
55
56
|
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
package/dist/headers/NHRP.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { DemuxProducer } from '../types/DemuxProducer';
|
|
|
16
16
|
* driven by ar$shtl and the per-entry CIE type/length octets) and carry cross-field context, so this
|
|
17
17
|
* codec keeps them verbatim as `body` hex (byte-perfect) and does not sub-decode them. Packet Length is
|
|
18
18
|
* auto-computed from the body on encode when not supplied, else honored verbatim (a crafted packet may
|
|
19
|
-
* lie); the checksum is
|
|
19
|
+
* lie); likewise the checksum is computed over the whole NHRP packet when left out. The body is
|
|
20
20
|
* bounded by both Packet Length and the enclosing IP payload, so trailing bytes are left to the codec's
|
|
21
21
|
* recursion / RawData. A well-formed packet round-trips byte-for-byte.
|
|
22
22
|
*/
|
package/dist/headers/NHRP.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
|
* NHRP — NBMA Next Hop Resolution Protocol (RFC 2332), carried directly over IP as protocol 54. Every
|
|
@@ -22,7 +23,7 @@ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
|
22
23
|
* driven by ar$shtl and the per-entry CIE type/length octets) and carry cross-field context, so this
|
|
23
24
|
* codec keeps them verbatim as `body` hex (byte-perfect) and does not sub-decode them. Packet Length is
|
|
24
25
|
* auto-computed from the body on encode when not supplied, else honored verbatim (a crafted packet may
|
|
25
|
-
* lie); the checksum is
|
|
26
|
+
* lie); likewise the checksum is computed over the whole NHRP packet when left out. The body is
|
|
26
27
|
* bounded by both Packet Length and the enclosing IP payload, so trailing bytes are left to the codec's
|
|
27
28
|
* recursion / RawData. A well-formed packet round-trips byte-for-byte.
|
|
28
29
|
*/
|
|
@@ -111,9 +112,33 @@ class NHRP extends BaseHeader_1.BaseHeader {
|
|
|
111
112
|
this.writeBytes(10, (0, NumberToBuffer_1.UInt16ToBuffer)(value));
|
|
112
113
|
}
|
|
113
114
|
},
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
checksum:
|
|
115
|
+
//Internet checksum over the whole NHRP packet from the Fixed Header on (RFC 2332 §5.2.0.1),
|
|
116
|
+
//computed once every field is written when left out; a given value is written as given.
|
|
117
|
+
checksum: {
|
|
118
|
+
type: 'integer',
|
|
119
|
+
autoCalculated: true,
|
|
120
|
+
label: 'Checksum',
|
|
121
|
+
minimum: 0,
|
|
122
|
+
maximum: 65535,
|
|
123
|
+
decode: function () {
|
|
124
|
+
this.instance.checksum.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(12, 2)));
|
|
125
|
+
},
|
|
126
|
+
encode: function () {
|
|
127
|
+
if (!this.isLeftOut(this.instance.checksum)) {
|
|
128
|
+
const checksum = this.instance.checksum.getValue(0);
|
|
129
|
+
this.instance.checksum.setValue(checksum);
|
|
130
|
+
this.writeBytes(12, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this.instance.checksum.setValue(0);
|
|
134
|
+
this.writeBytes(12, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
135
|
+
this.addPostSelfEncodeHandler(() => {
|
|
136
|
+
const checksum = (0, Checksum_1.InternetChecksum)(this.packet.subarray(this.startPos, this.endPos));
|
|
137
|
+
this.instance.checksum.setValue(checksum);
|
|
138
|
+
this.writeBytes(12, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
},
|
|
117
142
|
extensionOffset: this.fieldUInt('extensionOffset', 14, 2, 'Extension Offset'),
|
|
118
143
|
opVersion: this.fieldUInt('opVersion', 16, 1, 'Version'),
|
|
119
144
|
opType: this.fieldUInt('opType', 17, 1, 'Operation Type'),
|
package/dist/headers/OSPF.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { DemuxProducer } from '../types/DemuxProducer';
|
|
|
6
6
|
* decodes the 24-octet common header: an 8-bit Version (`version`, offset 0), an 8-bit Message Type
|
|
7
7
|
* (`type`, offset 1; 1 Hello, 2 Database Description, 3 LS Request, 4 LS Update, 5 LS Ack), a 16-bit
|
|
8
8
|
* Packet Length (`packetLength`, offset 2), the Source Router ID (`routerId`, IPv4, offset 4), the Area
|
|
9
|
-
* ID (`areaId`, IPv4, offset 8), a 16-bit Checksum (`checksum`, offset 12,
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* ID (`areaId`, IPv4, offset 8), a 16-bit Checksum (`checksum`, offset 12), a 16-bit Auth Type (`auType`,
|
|
10
|
+
* offset 14) and the 8-octet Authentication field (`auth`, hex, offset 16). Packet Length and Checksum
|
|
11
|
+
* are computed on encode when left out and written as given otherwise.
|
|
12
12
|
*
|
|
13
13
|
* For a Hello (type 1) the body is decoded field-by-field: Network Mask (offset 24), 16-bit Hello Interval
|
|
14
14
|
* (offset 28), 8-bit Options (offset 30), 8-bit Router Priority (offset 31), 32-bit Router Dead Interval
|