@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/KNXnetIP.js
CHANGED
|
@@ -65,9 +65,10 @@ class KNXnetIP extends BaseHeader_1.BaseHeader {
|
|
|
65
65
|
properties: {
|
|
66
66
|
//Header Length — the size of this header in octets, 0x06 for the current KNXnet/IP spec.
|
|
67
67
|
//Kept as a plain clamped byte (honored verbatim) so a crafted frame still round-trips.
|
|
68
|
-
|
|
68
|
+
//Defaults 0x06 and 0x10 here and below: the signature match() requires.
|
|
69
|
+
headerLength: { ...this.fieldUInt('headerLength', 0, 1, 'Header Length'), default: 0x06 },
|
|
69
70
|
//Protocol Version — 0x10 (1.0) for the current spec. Kept verbatim.
|
|
70
|
-
protocolVersion: this.fieldUInt('protocolVersion', 1, 1, 'Protocol Version'),
|
|
71
|
+
protocolVersion: { ...this.fieldUInt('protocolVersion', 1, 1, 'Protocol Version'), default: 0x10 },
|
|
71
72
|
//Service Type Identifier (e.g. 0x0201 SEARCH_REQUEST, 0x0420 TUNNELLING_REQUEST). Kept as a
|
|
72
73
|
//plain clamped uint16 (NOT an Ajv enum) so any non-standard / crafted service type decoded
|
|
73
74
|
//from the wire still re-encodes without being rejected — decode never fails, encode faithful.
|
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/LACP.js
CHANGED
|
@@ -44,7 +44,8 @@ class LACP extends BaseHeader_1.BaseHeader {
|
|
|
44
44
|
type: 'object',
|
|
45
45
|
summary: 'LACP v${version} ${tlvs.length} TLVs',
|
|
46
46
|
properties: {
|
|
47
|
-
|
|
47
|
+
//Default 1: the Slow Protocols subtype of LACP, and what match() requires.
|
|
48
|
+
subtype: { ...this.fieldUInt('subtype', 0, 1, 'Subtype'), default: 1 },
|
|
48
49
|
version: this.fieldUInt('version', 1, 1, 'Version'),
|
|
49
50
|
tlvs: {
|
|
50
51
|
type: 'array',
|
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/LDP.js
CHANGED
|
@@ -62,8 +62,8 @@ class LDP extends BaseHeader_1.BaseHeader {
|
|
|
62
62
|
type: 'object',
|
|
63
63
|
summary: 'LDP lsr=${lsrId}:${labelSpace}',
|
|
64
64
|
properties: {
|
|
65
|
-
//Version of the LDP protocol; RFC 5036 defines version 1.
|
|
66
|
-
version: this.fieldUInt('version', 0, 2, 'Version'),
|
|
65
|
+
//Version of the LDP protocol; RFC 5036 defines version 1. Default 1: what match() requires.
|
|
66
|
+
version: { ...this.fieldUInt('version', 0, 2, 'Version'), default: 1 },
|
|
67
67
|
pduLength: {
|
|
68
68
|
type: 'integer',
|
|
69
69
|
autoCalculated: true,
|
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/MQTT.js
CHANGED
|
@@ -80,12 +80,14 @@ class MQTT extends BaseHeader_1.BaseHeader {
|
|
|
80
80
|
type: 'object',
|
|
81
81
|
summary: 'MQTT type=${messageType}',
|
|
82
82
|
properties: {
|
|
83
|
-
//First byte, high nibble (bits 7-4): the Control Packet type.
|
|
83
|
+
//First byte, high nibble (bits 7-4): the Control Packet type. Default 12 (PINGREQ, complete
|
|
84
|
+
//without a payload): match() rejects the reserved type 0.
|
|
84
85
|
messageType: {
|
|
85
86
|
type: 'integer',
|
|
86
87
|
label: 'Message Type',
|
|
87
88
|
minimum: 0,
|
|
88
89
|
maximum: 15,
|
|
90
|
+
default: 12,
|
|
89
91
|
decode: function () {
|
|
90
92
|
this.instance.messageType.setValue(this.readBits(0, 1, 0, 4));
|
|
91
93
|
},
|
|
@@ -45,7 +45,8 @@ class MarkerProtocol extends BaseHeader_1.BaseHeader {
|
|
|
45
45
|
type: 'object',
|
|
46
46
|
summary: 'Marker v${version} ${tlvs.length} TLVs',
|
|
47
47
|
properties: {
|
|
48
|
-
|
|
48
|
+
//Default 2: the Slow Protocols subtype of the Marker Protocol, and what match() requires.
|
|
49
|
+
subtype: { ...this.fieldUInt('subtype', 0, 1, 'Subtype'), default: 2 },
|
|
49
50
|
version: this.fieldUInt('version', 1, 1, 'Version'),
|
|
50
51
|
tlvs: {
|
|
51
52
|
type: 'array',
|
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'),
|
|
@@ -85,7 +85,8 @@ class NetFlowV5 extends BaseHeader_1.BaseHeader {
|
|
|
85
85
|
type: 'object',
|
|
86
86
|
summary: 'NetFlow v5 ${count} flows',
|
|
87
87
|
properties: {
|
|
88
|
-
|
|
88
|
+
//Default 5: the NetFlow v5 version, and what match() requires.
|
|
89
|
+
version: { ...this.fieldUInt('version', 0, 2, 'Version'), default: 5 },
|
|
89
90
|
count: {
|
|
90
91
|
type: 'integer',
|
|
91
92
|
autoCalculated: true,
|
package/dist/headers/OPCUA.js
CHANGED
|
@@ -51,9 +51,11 @@ class OPCUA extends BaseHeader_1.BaseHeader {
|
|
|
51
51
|
//3-byte ASCII message type (HEL/ACK/ERR/OPN/MSG/CLO/RHE/RHF). Kept as a string; encode
|
|
52
52
|
//writes exactly 3 bytes (a decoded value is always 3 chars; a crafted value is truncated
|
|
53
53
|
//or zero-padded to 3) so a well-formed message round-trips byte-for-byte.
|
|
54
|
+
//Default HEL (Hello, the first message of a connection): match() requires a known type.
|
|
54
55
|
messageType: {
|
|
55
56
|
type: 'string',
|
|
56
57
|
label: 'Message Type',
|
|
58
|
+
default: 'HEL',
|
|
57
59
|
minLength: 3,
|
|
58
60
|
maxLength: 3,
|
|
59
61
|
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.ASCII,
|
|
@@ -71,9 +73,11 @@ class OPCUA extends BaseHeader_1.BaseHeader {
|
|
|
71
73
|
},
|
|
72
74
|
//1-byte ASCII chunk / IsFinal indicator (F/C/A). Kept as a string; encode writes exactly
|
|
73
75
|
//1 byte.
|
|
76
|
+
//Default F (final chunk): match() requires a known chunk type.
|
|
74
77
|
chunk: {
|
|
75
78
|
type: 'string',
|
|
76
79
|
label: 'Chunk',
|
|
80
|
+
default: 'F',
|
|
77
81
|
minLength: 1,
|
|
78
82
|
maxLength: 1,
|
|
79
83
|
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.ASCII,
|
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
|
|
@@ -16,8 +16,8 @@ import { DemuxProducer } from '../types/DemuxProducer';
|
|
|
16
16
|
* Neighbors list (4-octet Router IDs from offset 44 onward). For all other types the payload is kept
|
|
17
17
|
* verbatim as `rawBody` hex from offset 24. Both are bounded by min(Packet Length, the bytes the IP layer
|
|
18
18
|
* below actually made available) and never below the 24-octet header, so a lying length field can't read
|
|
19
|
-
* past the real IP payload. match() fires on IPv4 protocol 89 or IPv6 Next Header 89 with
|
|
20
|
-
* header present.
|
|
19
|
+
* past the real IP payload. match() fires on IPv4 protocol 89 or IPv6 Next Header 89 with Version 2 and a
|
|
20
|
+
* full common header present; Version 3 on the same protocol number is OSPFv3, a separate header.
|
|
21
21
|
*/
|
|
22
22
|
export declare class OSPF extends BaseHeader {
|
|
23
23
|
#private;
|
package/dist/headers/OSPF.js
CHANGED
|
@@ -6,14 +6,17 @@ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
|
6
6
|
const BufferToIP_1 = require("../helper/BufferToIP");
|
|
7
7
|
const IPToBuffer_1 = require("../helper/IPToBuffer");
|
|
8
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");
|
|
9
12
|
/**
|
|
10
13
|
* OSPF — Open Shortest Path First (OSPFv2, RFC 2328), carried directly on IP as protocol 89. This codec
|
|
11
14
|
* decodes the 24-octet common header: an 8-bit Version (`version`, offset 0), an 8-bit Message Type
|
|
12
15
|
* (`type`, offset 1; 1 Hello, 2 Database Description, 3 LS Request, 4 LS Update, 5 LS Ack), a 16-bit
|
|
13
16
|
* Packet Length (`packetLength`, offset 2), the Source Router ID (`routerId`, IPv4, offset 4), the Area
|
|
14
|
-
* ID (`areaId`, IPv4, offset 8), a 16-bit Checksum (`checksum`, offset 12,
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
+
* ID (`areaId`, IPv4, offset 8), a 16-bit Checksum (`checksum`, offset 12), a 16-bit Auth Type (`auType`,
|
|
18
|
+
* offset 14) and the 8-octet Authentication field (`auth`, hex, offset 16). Packet Length and Checksum
|
|
19
|
+
* are computed on encode when left out and written as given otherwise.
|
|
17
20
|
*
|
|
18
21
|
* For a Hello (type 1) the body is decoded field-by-field: Network Mask (offset 24), 16-bit Hello Interval
|
|
19
22
|
* (offset 28), 8-bit Options (offset 30), 8-bit Router Priority (offset 31), 32-bit Router Dead Interval
|
|
@@ -21,8 +24,8 @@ const BufferToHex_1 = require("../helper/BufferToHex");
|
|
|
21
24
|
* Neighbors list (4-octet Router IDs from offset 44 onward). For all other types the payload is kept
|
|
22
25
|
* verbatim as `rawBody` hex from offset 24. Both are bounded by min(Packet Length, the bytes the IP layer
|
|
23
26
|
* below actually made available) and never below the 24-octet header, so a lying length field can't read
|
|
24
|
-
* past the real IP payload. match() fires on IPv4 protocol 89 or IPv6 Next Header 89 with
|
|
25
|
-
* header present.
|
|
27
|
+
* past the real IP payload. match() fires on IPv4 protocol 89 or IPv6 Next Header 89 with Version 2 and a
|
|
28
|
+
* full common header present; Version 3 on the same protocol number is OSPFv3, a separate header.
|
|
26
29
|
*/
|
|
27
30
|
class OSPF extends BaseHeader_1.BaseHeader {
|
|
28
31
|
constructor() {
|
|
@@ -69,6 +72,19 @@ class OSPF extends BaseHeader_1.BaseHeader {
|
|
|
69
72
|
end = 24;
|
|
70
73
|
return end;
|
|
71
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* The OSPFv2 checksum (RFC 2328 §A.3.1): the Internet checksum of the whole packet except the 64-bit
|
|
77
|
+
* Authentication field (bytes 16-23). With cryptographic authentication (AuType 2) the checksum is
|
|
78
|
+
* not calculated and is 0 (§D.4.3). Called once every field is written, with the checksum still zero.
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
#calculateChecksum() {
|
|
82
|
+
const auType = this.instance.auType.getValue(0);
|
|
83
|
+
if (auType === 2)
|
|
84
|
+
return 0;
|
|
85
|
+
const packet = this.packet.subarray(this.startPos, this.endPos);
|
|
86
|
+
return (0, Checksum_1.InternetChecksum)(packet.subarray(0, 16), packet.subarray(24));
|
|
87
|
+
}
|
|
72
88
|
static #schemaCache;
|
|
73
89
|
//Class-cached SCHEMA (field closures are plain functions taking dynamic `this` via .call(this)).
|
|
74
90
|
get SCHEMA() {
|
|
@@ -80,9 +96,52 @@ class OSPF extends BaseHeader_1.BaseHeader {
|
|
|
80
96
|
summary: 'OSPF type=${type} rid=${routerId}',
|
|
81
97
|
properties: {
|
|
82
98
|
//==== Common header (24 bytes, RFC 2328 §A.3.1) ====
|
|
83
|
-
|
|
99
|
+
//Default 2, what match() requires. Version 3 is still written in the OSPFv2 layout given
|
|
100
|
+
//here, with a warning: OSPFv3 (RFC 5340) has its own header and checksum, see OSPFv3.
|
|
101
|
+
version: {
|
|
102
|
+
type: 'integer',
|
|
103
|
+
label: 'Version',
|
|
104
|
+
minimum: 0,
|
|
105
|
+
maximum: 255,
|
|
106
|
+
default: 2,
|
|
107
|
+
decode: function () {
|
|
108
|
+
this.instance.version.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1)));
|
|
109
|
+
},
|
|
110
|
+
encode: function () {
|
|
111
|
+
const version = this.instance.version.getValue(2);
|
|
112
|
+
this.instance.version.setValue(version);
|
|
113
|
+
this.writeBytes(0, (0, NumberToBuffer_1.UInt8ToBuffer)(version));
|
|
114
|
+
if (version === 3)
|
|
115
|
+
this.recordError(this.instance.version.getPath(), 'Version 3 is OSPFv3, whose header and checksum differ from OSPFv2: encode it as \'ospfv3\'. This layer writes the OSPFv2 layout');
|
|
116
|
+
}
|
|
117
|
+
},
|
|
84
118
|
type: this.fieldUInt('type', 1, 1, 'Message Type'),
|
|
85
|
-
|
|
119
|
+
//The whole OSPF packet including this header; left out, the bytes actually written, filled
|
|
120
|
+
//once every field is encoded (before the checksum); a given value is written as given.
|
|
121
|
+
packetLength: {
|
|
122
|
+
type: 'integer',
|
|
123
|
+
autoCalculated: true,
|
|
124
|
+
label: 'Packet Length',
|
|
125
|
+
minimum: 0,
|
|
126
|
+
maximum: 65535,
|
|
127
|
+
decode: function () {
|
|
128
|
+
this.instance.packetLength.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
|
|
129
|
+
},
|
|
130
|
+
encode: function () {
|
|
131
|
+
if (!this.isLeftOut(this.instance.packetLength)) {
|
|
132
|
+
const packetLength = this.instance.packetLength.getValue(0);
|
|
133
|
+
this.instance.packetLength.setValue(packetLength);
|
|
134
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(packetLength));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this.instance.packetLength.setValue(0);
|
|
138
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
139
|
+
this.addPostSelfEncodeHandler(() => {
|
|
140
|
+
this.instance.packetLength.setValue(this.length);
|
|
141
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(this.length));
|
|
142
|
+
}, 1);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
86
145
|
routerId: {
|
|
87
146
|
type: 'string',
|
|
88
147
|
label: 'Source Router ID',
|
|
@@ -113,9 +172,33 @@ class OSPF extends BaseHeader_1.BaseHeader {
|
|
|
113
172
|
this.writeBytes(8, (0, IPToBuffer_1.IPv4ToBuffer)(areaId));
|
|
114
173
|
}
|
|
115
174
|
},
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
checksum:
|
|
175
|
+
//Left out, computed after the Packet Length once every field is written
|
|
176
|
+
//(#calculateChecksum); a given value is written as given.
|
|
177
|
+
checksum: {
|
|
178
|
+
type: 'integer',
|
|
179
|
+
autoCalculated: true,
|
|
180
|
+
label: 'Checksum',
|
|
181
|
+
minimum: 0,
|
|
182
|
+
maximum: 65535,
|
|
183
|
+
decode: function () {
|
|
184
|
+
this.instance.checksum.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(12, 2)));
|
|
185
|
+
},
|
|
186
|
+
encode: function () {
|
|
187
|
+
if (!this.isLeftOut(this.instance.checksum)) {
|
|
188
|
+
const checksum = this.instance.checksum.getValue(0);
|
|
189
|
+
this.instance.checksum.setValue(checksum);
|
|
190
|
+
this.writeBytes(12, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
this.instance.checksum.setValue(0);
|
|
194
|
+
this.writeBytes(12, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
195
|
+
this.addPostSelfEncodeHandler(() => {
|
|
196
|
+
const checksum = this.#calculateChecksum();
|
|
197
|
+
this.instance.checksum.setValue(checksum);
|
|
198
|
+
this.writeBytes(12, (0, NumberToBuffer_1.UInt16ToBuffer)(checksum));
|
|
199
|
+
}, 2);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
119
202
|
auType: this.fieldUInt('auType', 14, 2, 'Auth Type'),
|
|
120
203
|
auth: {
|
|
121
204
|
type: 'string',
|
|
@@ -354,12 +437,15 @@ class OSPF extends BaseHeader_1.BaseHeader {
|
|
|
354
437
|
return false;
|
|
355
438
|
//OSPF sits directly on IP (protocol 89). Accept the demux value from either the IPv4
|
|
356
439
|
//protocol field or the IPv6 next-header field, and require at least a full 24-byte common
|
|
357
|
-
//header of IP payload to be present.
|
|
440
|
+
//header of IP payload to be present. Version 2 only: version 3 on protocol 89 is the separate
|
|
441
|
+
//OSPFv3 header.
|
|
358
442
|
const protocol = this.prevCodecModule.instance.protocol.getValue(0);
|
|
359
443
|
const nextHeader = this.prevCodecModule.instance.nxt.getValue(0);
|
|
360
444
|
if (protocol !== 89 && nextHeader !== 89)
|
|
361
445
|
return false;
|
|
362
|
-
|
|
446
|
+
if (this.#available() < 24)
|
|
447
|
+
return false;
|
|
448
|
+
return this.readBytes(0, 1, true)[0] === 2;
|
|
363
449
|
}
|
|
364
450
|
}
|
|
365
451
|
exports.OSPF = OSPF;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
|
|
2
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
3
|
+
import { DemuxProducer } from '../types/DemuxProducer';
|
|
4
|
+
/**
|
|
5
|
+
* OSPFv3 — Open Shortest Path First for IPv6 (RFC 5340), carried on IPv6 as Next Header 89 (the same
|
|
6
|
+
* protocol number as OSPFv2, told apart by the Version octet). This codec decodes the 16-octet common
|
|
7
|
+
* header (RFC 5340 §A.3.1): an 8-bit Version (`version`, offset 0, 3), an 8-bit Message Type (`type`,
|
|
8
|
+
* offset 1; 1 Hello, 2 Database Description, 3 LS Request, 4 LS Update, 5 LS Ack), a 16-bit Packet Length
|
|
9
|
+
* (`packetLength`, offset 2), the Router ID (`routerId`, offset 4) and Area ID (`areaId`, offset 8) in
|
|
10
|
+
* dotted-quad form, a 16-bit Checksum (`checksum`, offset 12), an 8-bit Instance ID (`instanceId`, offset
|
|
11
|
+
* 14) and a Reserved octet (`reserved`, hex, offset 15). Unlike OSPFv2 there is no authentication in the
|
|
12
|
+
* header (RFC 4552 IPsec, or the RFC 7166 trailer after the packet, does that job). Packet Length and
|
|
13
|
+
* Checksum are computed on encode when left out and written as given otherwise; the checksum is the
|
|
14
|
+
* Internet checksum of the whole packet with the IPv6 pseudo-header prepended, its Upper-Layer Packet
|
|
15
|
+
* Length being the Packet Length field (§A.3.1).
|
|
16
|
+
*
|
|
17
|
+
* For a Hello (type 1, §A.3.2) the body is decoded field by field: Interface ID (offset 16), Router
|
|
18
|
+
* Priority (offset 20), the 24-bit Options (offset 21; V6 0x01, E 0x02, MC 0x04, N 0x08, R 0x10, DC 0x20,
|
|
19
|
+
* AF 0x100, L 0x200, AT 0x400), Hello Interval and Router Dead Interval (16 bits each, offsets 24 and 26),
|
|
20
|
+
* Designated and Backup Designated Router IDs (offsets 28 and 32), then the Router IDs of the neighbours
|
|
21
|
+
* (4 octets each from offset 36). Built from defaults, a Hello carries priority 1, Options V6|E|R, hello
|
|
22
|
+
* interval 10 and dead interval 40. For all other types the body is kept verbatim as `rawBody` hex from
|
|
23
|
+
* offset 16. Both are bounded by min(Packet Length, the end of the IPv6 payload) and never below the
|
|
24
|
+
* 16-octet header, so a lying length can't read past the real IP payload. match() fires on Next Header
|
|
25
|
+
* 89 with an IPv6 layer beneath (directly, or behind AH / an extension header), Version 3 and a full
|
|
26
|
+
* common header present.
|
|
27
|
+
*/
|
|
28
|
+
export declare class OSPFv3 extends BaseHeader {
|
|
29
|
+
#private;
|
|
30
|
+
get SCHEMA(): ProtocolJSONSchema;
|
|
31
|
+
readonly id: string;
|
|
32
|
+
readonly matchKeys: string[];
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly nickname: string;
|
|
35
|
+
readonly demuxProducers: DemuxProducer[];
|
|
36
|
+
match(): boolean;
|
|
37
|
+
}
|