netkitty 0.0.14 → 0.0.16
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/.idea/inspectionProfiles/Project_Default.xml +1 -1
- package/dist/NetKitty.d.ts +12 -0
- package/dist/NetKitty.d.ts.map +1 -1
- package/dist/NetKitty.js +74 -1
- package/dist/lib/codec/Codec.d.ts.map +1 -1
- package/dist/lib/codec/Codec.js +8 -0
- package/dist/lib/codec/abstracts/BaseHeader.d.ts +2 -1
- package/dist/lib/codec/abstracts/BaseHeader.d.ts.map +1 -1
- package/dist/lib/codec/abstracts/BaseHeader.js +19 -10
- package/dist/lib/codec/headers/Goose.d.ts.map +1 -1
- package/dist/lib/codec/headers/Goose.js +26 -8
- package/dist/lib/codec/headers/ICMP.d.ts +15 -0
- package/dist/lib/codec/headers/ICMP.d.ts.map +1 -0
- package/dist/lib/codec/headers/ICMP.js +147 -0
- package/dist/lib/codec/headers/ICMPv6.d.ts +15 -0
- package/dist/lib/codec/headers/ICMPv6.d.ts.map +1 -0
- package/dist/lib/codec/headers/ICMPv6.js +128 -0
- package/dist/lib/codec/headers/IPv6.d.ts +10 -0
- package/dist/lib/codec/headers/IPv6.d.ts.map +1 -0
- package/dist/lib/codec/headers/IPv6.js +177 -0
- package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts +71 -0
- package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts.map +1 -0
- package/dist/lib/codec/headers/IPv6HopByHopOptions.js +497 -0
- package/dist/lib/codec/headers/TCP.d.ts.map +1 -1
- package/dist/lib/codec/headers/TCP.js +1 -0
- package/dist/tests/units/Codec.spec.js +19 -21
- package/package.json +1 -1
- package/src/NetKitty.ts +61 -0
- package/src/lib/codec/Codec.ts +8 -0
- package/src/lib/codec/abstracts/BaseHeader.ts +17 -9
- package/src/lib/codec/headers/Goose.ts +21 -9
- package/src/lib/codec/headers/ICMP.ts +151 -0
- package/src/lib/codec/headers/ICMPv6.ts +128 -0
- package/src/lib/codec/headers/IPv6.ts +176 -0
- package/src/lib/codec/headers/IPv6HopByHopOptions.ts +532 -0
- package/src/lib/codec/headers/TCP.ts +1 -0
- package/src/tests/units/Codec.spec.ts +21 -21
- package/src/tests/units/ReadPCAP.spec.ts +1 -2
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
|
|
2
|
+
import {BaseHeader} from '../abstracts/BaseHeader'
|
|
3
|
+
import {BufferToUInt8} from '../lib/BufferToNumber'
|
|
4
|
+
import {UInt16ToBuffer, UInt32ToBuffer, UInt64ToBuffer, UInt8ToBuffer} from '../lib/NumberToBuffer'
|
|
5
|
+
import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
|
|
6
|
+
import TLV from 'node-tlv'
|
|
7
|
+
import {HexToUInt16, HexToUInt32, HexToUInt64, HexToUInt8} from '../lib/HexToNumber'
|
|
8
|
+
|
|
9
|
+
//Type=1 PadN
|
|
10
|
+
//Type=4 Tunnel Encapsulation Limit
|
|
11
|
+
//Type=5 Router Alert
|
|
12
|
+
//Type=7 CALIPSO
|
|
13
|
+
//Type=8 SMF_DPD
|
|
14
|
+
//Type=11 MPL Option
|
|
15
|
+
//Type=12 ILNP Nonce
|
|
16
|
+
//Type=13 Line-Identification Option
|
|
17
|
+
//Type=30 IPv6 DFF Header
|
|
18
|
+
//Type=138 Endpoint Identification
|
|
19
|
+
|
|
20
|
+
enum Type {
|
|
21
|
+
PadN = 'PadN',
|
|
22
|
+
Tunnel_Encapsulation_Limit = 'Tunnel-Encapsulation-Limit',
|
|
23
|
+
Router_Alert = 'Router-Alert',
|
|
24
|
+
CALIPSO = 'CALIPSO',
|
|
25
|
+
SMF_DPD = 'SMF_DPD',
|
|
26
|
+
MPL_Option = 'MPL-Option',
|
|
27
|
+
ILNP_Nonce = 'ILNP-Nonce',
|
|
28
|
+
Line_Identification_Option = 'Line-Identification-Option',
|
|
29
|
+
IPv6_DFF_Header = 'IPv6-DFF-Header',
|
|
30
|
+
Endpoint_Identification = 'Endpoint-Identification'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type PadN = {
|
|
34
|
+
type: Type.PadN
|
|
35
|
+
n: number
|
|
36
|
+
}
|
|
37
|
+
type Tunnel_Encapsulation_Limit = {
|
|
38
|
+
type: Type.Tunnel_Encapsulation_Limit
|
|
39
|
+
limit: number
|
|
40
|
+
}
|
|
41
|
+
type Router_Alert = {
|
|
42
|
+
type: Type.Router_Alert
|
|
43
|
+
alert: string
|
|
44
|
+
}
|
|
45
|
+
type CALIPSO = {
|
|
46
|
+
type: Type.CALIPSO
|
|
47
|
+
tag: string
|
|
48
|
+
}
|
|
49
|
+
type SMF_DPD = {
|
|
50
|
+
type: Type.SMF_DPD
|
|
51
|
+
hash: string
|
|
52
|
+
}
|
|
53
|
+
type MPL_Option = {
|
|
54
|
+
type: Type.MPL_Option
|
|
55
|
+
value: string
|
|
56
|
+
}
|
|
57
|
+
type ILNP_Nonce = {
|
|
58
|
+
type: Type.ILNP_Nonce
|
|
59
|
+
nonce: string
|
|
60
|
+
}
|
|
61
|
+
type Line_Identification_Option = {
|
|
62
|
+
type: Type.Line_Identification_Option
|
|
63
|
+
id: string
|
|
64
|
+
}
|
|
65
|
+
type IPv6_DFF_Header = {
|
|
66
|
+
type: Type.IPv6_DFF_Header
|
|
67
|
+
message: string
|
|
68
|
+
}
|
|
69
|
+
type Endpoint_Identification = {
|
|
70
|
+
type: Type.Endpoint_Identification
|
|
71
|
+
id: string
|
|
72
|
+
}
|
|
73
|
+
type Custom = {
|
|
74
|
+
type: number
|
|
75
|
+
data: string
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export class IPv6HopByHopOptions extends BaseHeader {
|
|
79
|
+
|
|
80
|
+
protected itemTLVs: TLV[]
|
|
81
|
+
|
|
82
|
+
protected items: (
|
|
83
|
+
PadN |
|
|
84
|
+
Tunnel_Encapsulation_Limit |
|
|
85
|
+
Router_Alert |
|
|
86
|
+
CALIPSO |
|
|
87
|
+
SMF_DPD |
|
|
88
|
+
MPL_Option |
|
|
89
|
+
ILNP_Nonce |
|
|
90
|
+
Line_Identification_Option |
|
|
91
|
+
IPv6_DFF_Header |
|
|
92
|
+
Endpoint_Identification |
|
|
93
|
+
Custom
|
|
94
|
+
)[] = []
|
|
95
|
+
|
|
96
|
+
public SCHEMA: ProtocolJSONSchema = {
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties: {
|
|
99
|
+
nxt: {
|
|
100
|
+
type: 'integer',
|
|
101
|
+
label: 'Next Header',
|
|
102
|
+
minimum: 0,
|
|
103
|
+
maximum: 255,
|
|
104
|
+
decode: (): void => {
|
|
105
|
+
this.instance.nxt.setValue(BufferToUInt8(this.readBytes(0, 1)))
|
|
106
|
+
},
|
|
107
|
+
encode: (): void => {
|
|
108
|
+
const nxt: number = this.instance.nxt.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
109
|
+
this.instance.nxt.setValue(nxt)
|
|
110
|
+
this.writeBytes(0, UInt8ToBuffer(nxt))
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
len: {
|
|
114
|
+
type: 'integer',
|
|
115
|
+
label: 'Length',
|
|
116
|
+
minimum: 0,
|
|
117
|
+
maximum: 255,
|
|
118
|
+
decode: (): void => {
|
|
119
|
+
this.instance.len.setValue(BufferToUInt8(this.readBytes(1, 1)))
|
|
120
|
+
},
|
|
121
|
+
encode: (): void => {
|
|
122
|
+
const len: number = this.instance.len.getValue(0)
|
|
123
|
+
this.instance.len.setValue(len)
|
|
124
|
+
this.writeBytes(1, UInt8ToBuffer(len))
|
|
125
|
+
if (!len) {
|
|
126
|
+
this.addPostSelfEncodeHandler((): void => {
|
|
127
|
+
let rawLength: number = 0
|
|
128
|
+
this.itemTLVs
|
|
129
|
+
.map(tlv => Buffer.from(tlv.getTLV(), 'hex').length)
|
|
130
|
+
.forEach(itemLength => rawLength += itemLength)
|
|
131
|
+
const calcLength: number = Math.floor(rawLength / 8)
|
|
132
|
+
this.instance.len.setValue(calcLength)
|
|
133
|
+
this.writeBytes(1, UInt8ToBuffer(calcLength))
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
items: {
|
|
139
|
+
type: 'array',
|
|
140
|
+
label: 'Option Items',
|
|
141
|
+
items: {
|
|
142
|
+
anyOf: [
|
|
143
|
+
//Type=1 PadN
|
|
144
|
+
{
|
|
145
|
+
type: 'object',
|
|
146
|
+
label: 'PadN',
|
|
147
|
+
properties: {
|
|
148
|
+
type: {
|
|
149
|
+
type: 'string',
|
|
150
|
+
label: 'Type',
|
|
151
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
152
|
+
enum: [Type.PadN]
|
|
153
|
+
},
|
|
154
|
+
n: {
|
|
155
|
+
type: 'integer',
|
|
156
|
+
label: 'N'
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
//Type=4 Tunnel Encapsulation Limit
|
|
161
|
+
{
|
|
162
|
+
type: 'object',
|
|
163
|
+
label: 'Tunnel Encapsulation Limit',
|
|
164
|
+
properties: {
|
|
165
|
+
type: {
|
|
166
|
+
type: 'string',
|
|
167
|
+
label: 'Type',
|
|
168
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
169
|
+
enum: [Type.Tunnel_Encapsulation_Limit]
|
|
170
|
+
},
|
|
171
|
+
limit: {
|
|
172
|
+
type: 'integer',
|
|
173
|
+
label: 'Limit',
|
|
174
|
+
minimum: 1,
|
|
175
|
+
maximum: 255
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
//Type=5 Router Alert
|
|
180
|
+
{
|
|
181
|
+
type: 'object',
|
|
182
|
+
label: 'Router Alert',
|
|
183
|
+
properties: {
|
|
184
|
+
type: {
|
|
185
|
+
type: 'string',
|
|
186
|
+
label: 'Type',
|
|
187
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
188
|
+
enum: [Type.Router_Alert]
|
|
189
|
+
},
|
|
190
|
+
alert: {
|
|
191
|
+
type: 'string',
|
|
192
|
+
label: 'Router Alert',
|
|
193
|
+
contentEncoding: StringContentEncodingEnum.HEX,
|
|
194
|
+
minLength: 4,
|
|
195
|
+
maxLength: 4
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
//Type=7 CALIPSO
|
|
200
|
+
{
|
|
201
|
+
type: 'object',
|
|
202
|
+
label: 'CALIPSO',
|
|
203
|
+
properties: {
|
|
204
|
+
type: {
|
|
205
|
+
type: 'string',
|
|
206
|
+
label: 'Type',
|
|
207
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
208
|
+
enum: [Type.CALIPSO]
|
|
209
|
+
},
|
|
210
|
+
tag: {
|
|
211
|
+
type: 'string',
|
|
212
|
+
label: 'Tag',
|
|
213
|
+
contentEncoding: StringContentEncodingEnum.HEX,
|
|
214
|
+
minLength: 16,
|
|
215
|
+
maxLength: 16
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
//Type=8 SMF_DPD
|
|
220
|
+
{
|
|
221
|
+
type: 'object',
|
|
222
|
+
label: 'SMF_DPD',
|
|
223
|
+
properties: {
|
|
224
|
+
type: {
|
|
225
|
+
type: 'string',
|
|
226
|
+
label: 'Type',
|
|
227
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
228
|
+
enum: [Type.SMF_DPD]
|
|
229
|
+
},
|
|
230
|
+
hash: {
|
|
231
|
+
type: 'string',
|
|
232
|
+
label: 'Hash',
|
|
233
|
+
contentEncoding: StringContentEncodingEnum.UTF8
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
//Type=11 MPL Option
|
|
238
|
+
{
|
|
239
|
+
type: 'object',
|
|
240
|
+
label: 'MPL Option',
|
|
241
|
+
properties: {
|
|
242
|
+
type: {
|
|
243
|
+
type: 'string',
|
|
244
|
+
label: 'Type',
|
|
245
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
246
|
+
enum: [Type.MPL_Option]
|
|
247
|
+
},
|
|
248
|
+
value: {
|
|
249
|
+
type: 'string',
|
|
250
|
+
label: 'Value',
|
|
251
|
+
contentEncoding: StringContentEncodingEnum.HEX
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
//Type=12 ILNP Nonce
|
|
256
|
+
{
|
|
257
|
+
type: 'object',
|
|
258
|
+
label: 'ILNP Nonce',
|
|
259
|
+
properties: {
|
|
260
|
+
type: {
|
|
261
|
+
type: 'string',
|
|
262
|
+
label: 'Type',
|
|
263
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
264
|
+
enum: [Type.ILNP_Nonce]
|
|
265
|
+
},
|
|
266
|
+
nonce: {
|
|
267
|
+
type: 'string',
|
|
268
|
+
label: 'Nonce',
|
|
269
|
+
minLength: 12,
|
|
270
|
+
maxLength: 12,
|
|
271
|
+
contentEncoding: StringContentEncodingEnum.HEX
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
//Type=13 Line-Identification Option
|
|
276
|
+
{
|
|
277
|
+
type: 'object',
|
|
278
|
+
label: 'Line-Identification Option',
|
|
279
|
+
properties: {
|
|
280
|
+
type: {
|
|
281
|
+
type: 'string',
|
|
282
|
+
label: 'Type',
|
|
283
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
284
|
+
enum: [Type.Line_Identification_Option]
|
|
285
|
+
},
|
|
286
|
+
id: {
|
|
287
|
+
type: 'string',
|
|
288
|
+
label: 'Identity',
|
|
289
|
+
minLength: 8,
|
|
290
|
+
maxLength: 8,
|
|
291
|
+
contentEncoding: StringContentEncodingEnum.HEX
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
//Type=30 IPv6 DFF Header
|
|
296
|
+
{
|
|
297
|
+
type: 'object',
|
|
298
|
+
label: 'IPv6 DFF Header',
|
|
299
|
+
properties: {
|
|
300
|
+
type: {
|
|
301
|
+
type: 'string',
|
|
302
|
+
label: 'Type',
|
|
303
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
304
|
+
enum: [Type.IPv6_DFF_Header]
|
|
305
|
+
},
|
|
306
|
+
message: {
|
|
307
|
+
type: 'string',
|
|
308
|
+
label: 'Message',
|
|
309
|
+
contentEncoding: StringContentEncodingEnum.HEX
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
//Type=138 Endpoint Identification
|
|
314
|
+
{
|
|
315
|
+
type: 'object',
|
|
316
|
+
label: 'Endpoint Identification',
|
|
317
|
+
properties: {
|
|
318
|
+
type: {
|
|
319
|
+
type: 'string',
|
|
320
|
+
label: 'Type',
|
|
321
|
+
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
322
|
+
enum: [Type.Endpoint_Identification]
|
|
323
|
+
},
|
|
324
|
+
id: {
|
|
325
|
+
type: 'string',
|
|
326
|
+
label: 'Identity',
|
|
327
|
+
minLength: 32,
|
|
328
|
+
maxLength: 32,
|
|
329
|
+
contentEncoding: StringContentEncodingEnum.HEX
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
//Custom
|
|
334
|
+
{
|
|
335
|
+
type: 'object',
|
|
336
|
+
label: 'Custom',
|
|
337
|
+
properties: {
|
|
338
|
+
type: {
|
|
339
|
+
type: 'integer',
|
|
340
|
+
label: 'Type'
|
|
341
|
+
},
|
|
342
|
+
data: {
|
|
343
|
+
type: 'string',
|
|
344
|
+
label: 'Data',
|
|
345
|
+
contentEncoding: StringContentEncodingEnum.HEX
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
]
|
|
350
|
+
},
|
|
351
|
+
decode: (): void => {
|
|
352
|
+
let length: number = this.instance.len.getValue(0) * 8 + 7
|
|
353
|
+
while (!this.itemTLVs) {
|
|
354
|
+
try {
|
|
355
|
+
const itemTLVs: TLV[] = TLV.parseList(this.readBytes(2, length, true))
|
|
356
|
+
const joinedHex: string = itemTLVs.map(value => value.getTLV()).join('')
|
|
357
|
+
if (this.readBytes(2, length, true).toString('hex').padStart(length * 2, '0').toUpperCase() !== joinedHex.toUpperCase()) {
|
|
358
|
+
length -= 1
|
|
359
|
+
if (!length) break
|
|
360
|
+
continue
|
|
361
|
+
}
|
|
362
|
+
this.itemTLVs = TLV.parseList(this.readBytes(2, length))
|
|
363
|
+
} catch (e) {
|
|
364
|
+
length -= 1
|
|
365
|
+
if (!length) break
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
this.itemTLVs.forEach((itemTLV: TLV): void => {
|
|
369
|
+
switch (itemTLV.getTag('number')) {
|
|
370
|
+
case 0x01: {
|
|
371
|
+
this.items.push({
|
|
372
|
+
type: Type.PadN,
|
|
373
|
+
n: itemTLV.getLength('number')
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
break
|
|
377
|
+
case 0x04: {
|
|
378
|
+
this.items.push({
|
|
379
|
+
type: Type.Tunnel_Encapsulation_Limit,
|
|
380
|
+
limit: HexToUInt8(itemTLV.getValue('hex'))
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
break
|
|
384
|
+
case 0x05: {
|
|
385
|
+
this.items.push({
|
|
386
|
+
type: Type.Router_Alert,
|
|
387
|
+
alert: itemTLV.getValue('hex')
|
|
388
|
+
})
|
|
389
|
+
}
|
|
390
|
+
break
|
|
391
|
+
case 0x07: {
|
|
392
|
+
this.items.push({
|
|
393
|
+
type: Type.CALIPSO,
|
|
394
|
+
tag: itemTLV.getValue('hex')
|
|
395
|
+
})
|
|
396
|
+
}
|
|
397
|
+
break
|
|
398
|
+
case 0x08: {
|
|
399
|
+
this.items.push({
|
|
400
|
+
type: Type.SMF_DPD,
|
|
401
|
+
hash: itemTLV.getValue('hex')
|
|
402
|
+
})
|
|
403
|
+
}
|
|
404
|
+
break
|
|
405
|
+
case 0x0B: {
|
|
406
|
+
this.items.push({
|
|
407
|
+
type: Type.MPL_Option,
|
|
408
|
+
value: itemTLV.getValue('hex')
|
|
409
|
+
})
|
|
410
|
+
}
|
|
411
|
+
break
|
|
412
|
+
case 0x0C: {
|
|
413
|
+
this.items.push({
|
|
414
|
+
type: Type.ILNP_Nonce,
|
|
415
|
+
nonce: itemTLV.getValue('hex')
|
|
416
|
+
})
|
|
417
|
+
}
|
|
418
|
+
break
|
|
419
|
+
case 0x0D: {
|
|
420
|
+
this.items.push({
|
|
421
|
+
type: Type.Line_Identification_Option,
|
|
422
|
+
id: itemTLV.getValue('hex')
|
|
423
|
+
})
|
|
424
|
+
}
|
|
425
|
+
break
|
|
426
|
+
case 0x1E: {
|
|
427
|
+
this.items.push({
|
|
428
|
+
type: Type.IPv6_DFF_Header,
|
|
429
|
+
message: itemTLV.getValue('hex')
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
break
|
|
433
|
+
case 0x8A: {
|
|
434
|
+
this.items.push({
|
|
435
|
+
type: Type.Endpoint_Identification,
|
|
436
|
+
id: itemTLV.getValue('hex')
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
break
|
|
440
|
+
default: {
|
|
441
|
+
this.items.push({
|
|
442
|
+
type: itemTLV.getTag('number'),
|
|
443
|
+
data: itemTLV.getValue('hex')
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
})
|
|
448
|
+
this.instance.items.setValue(this.items.length ? this.items : [])
|
|
449
|
+
},
|
|
450
|
+
encode: (): void => {
|
|
451
|
+
this.items = this.instance.items.getValue([])
|
|
452
|
+
this.itemTLVs = []
|
|
453
|
+
this.items.forEach(item => {
|
|
454
|
+
switch (item.type) {
|
|
455
|
+
case Type.PadN: {
|
|
456
|
+
const typedItem: PadN = {...item}
|
|
457
|
+
this.itemTLVs.push(new TLV(0x01, Buffer.alloc(typedItem.n, 0)))
|
|
458
|
+
}
|
|
459
|
+
break
|
|
460
|
+
case Type.Tunnel_Encapsulation_Limit: {
|
|
461
|
+
const typedItem: Tunnel_Encapsulation_Limit = {...item}
|
|
462
|
+
this.itemTLVs.push(new TLV(0x04, UInt8ToBuffer(typedItem.limit)))
|
|
463
|
+
}
|
|
464
|
+
break
|
|
465
|
+
case Type.Router_Alert: {
|
|
466
|
+
const typedItem: Router_Alert = {...item}
|
|
467
|
+
this.itemTLVs.push(new TLV(0x05, UInt16ToBuffer(HexToUInt16(typedItem.alert))))
|
|
468
|
+
}
|
|
469
|
+
break
|
|
470
|
+
case Type.CALIPSO: {
|
|
471
|
+
const typedItem: CALIPSO = {...item}
|
|
472
|
+
this.itemTLVs.push(new TLV(0x07, UInt64ToBuffer(HexToUInt64(typedItem.tag))))
|
|
473
|
+
}
|
|
474
|
+
break
|
|
475
|
+
case Type.SMF_DPD: {
|
|
476
|
+
const typedItem: SMF_DPD = {...item}
|
|
477
|
+
this.itemTLVs.push(new TLV(0x08, Buffer.from(typedItem.hash, 'hex')))
|
|
478
|
+
}
|
|
479
|
+
break
|
|
480
|
+
case Type.MPL_Option: {
|
|
481
|
+
const typedItem: MPL_Option = {...item}
|
|
482
|
+
this.itemTLVs.push(new TLV(0x0B, Buffer.from(typedItem.value, 'hex')))
|
|
483
|
+
}
|
|
484
|
+
break
|
|
485
|
+
case Type.ILNP_Nonce: {
|
|
486
|
+
const typedItem: ILNP_Nonce = {...item}
|
|
487
|
+
this.itemTLVs.push(new TLV(0x0C, Buffer.from(typedItem.nonce.padStart(12, '0'), 'hex')))
|
|
488
|
+
}
|
|
489
|
+
break
|
|
490
|
+
case Type.Line_Identification_Option: {
|
|
491
|
+
const typedItem: Line_Identification_Option = {...item}
|
|
492
|
+
this.itemTLVs.push(new TLV(0x0D, UInt32ToBuffer(HexToUInt32(typedItem.id))))
|
|
493
|
+
}
|
|
494
|
+
break
|
|
495
|
+
case Type.IPv6_DFF_Header: {
|
|
496
|
+
const typedItem: IPv6_DFF_Header = {...item}
|
|
497
|
+
this.itemTLVs.push(new TLV(0x1E, Buffer.from(typedItem.message, 'hex')))
|
|
498
|
+
}
|
|
499
|
+
break
|
|
500
|
+
case Type.Endpoint_Identification: {
|
|
501
|
+
const typedItem: Endpoint_Identification = {...item}
|
|
502
|
+
this.itemTLVs.push(new TLV(0x0C, Buffer.from(typedItem.id.padStart(32, '0'), 'hex')))
|
|
503
|
+
}
|
|
504
|
+
break
|
|
505
|
+
default: {
|
|
506
|
+
if (typeof item.type !== 'number') return
|
|
507
|
+
const customItem: Custom = {...item}
|
|
508
|
+
this.itemTLVs.push(new TLV(customItem.type, Buffer.from(customItem.data, 'hex')))
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
})
|
|
512
|
+
const itemsBuffer: Buffer = Buffer.from(this.itemTLVs.map(value => value.getTLV()).join(''), 'hex')
|
|
513
|
+
this.writeBytes(2, itemsBuffer)
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
public id: string = 'ipv6-hopopt'
|
|
520
|
+
|
|
521
|
+
public name: string = 'IPv6 Hop-by-Hop Option'
|
|
522
|
+
|
|
523
|
+
public nickname: string = 'HopOpt'
|
|
524
|
+
|
|
525
|
+
public readonly isProtocol: boolean = false
|
|
526
|
+
|
|
527
|
+
public match(): boolean {
|
|
528
|
+
if (!this.prevCodecModule || this.prevCodecModule.id !== 'ipv6') return false
|
|
529
|
+
return this.prevCodecModule.instance.nxt.getValue() === 0x00
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
}
|
|
@@ -7,15 +7,15 @@ async function DecodeAndEncode(packet: string): Promise<void> {
|
|
|
7
7
|
console.log('packetBuffer:', packetBuffer.toString('hex'))
|
|
8
8
|
const codec = new Codec()
|
|
9
9
|
const decodeResult = await codec.decode(packetBuffer)
|
|
10
|
-
console.log(JSON.stringify(decodeResult, null, 2))
|
|
11
|
-
for (let i = 0; i <
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
// console.log(JSON.stringify(decodeResult, null, 2))
|
|
11
|
+
// for (let i = 0; i < 100000; i++) {
|
|
12
|
+
// const encodeResult = await codec.encode(decodeResult)
|
|
13
|
+
// }
|
|
14
|
+
const encodeResult = await codec.encode(decodeResult)
|
|
15
|
+
console.log('encodeResult:', encodeResult.packet.toString('hex'))
|
|
16
|
+
console.log('packetBuffer===encodeResult', packetBuffer.toString('hex') === encodeResult.packet.toString('hex'))
|
|
17
|
+
const decodeResult1 = await codec.decode(encodeResult.packet)
|
|
18
|
+
console.log(JSON.stringify(decodeResult1, null, 2))
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
async function GOOSE_Codec(packet: string): Promise<void> {
|
|
@@ -30,6 +30,10 @@ async function IPv4_Codec(packet: string): Promise<void> {
|
|
|
30
30
|
await DecodeAndEncode(packet)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
async function IPv6_Codec(packet: string): Promise<void> {
|
|
34
|
+
await DecodeAndEncode(packet)
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
async function ARP_Codec(packet: string): Promise<void> {
|
|
34
38
|
await DecodeAndEncode(packet)
|
|
35
39
|
}
|
|
@@ -45,6 +49,7 @@ async function UDP_Codec(packet: string): Promise<void> {
|
|
|
45
49
|
(async (): Promise<void> => {
|
|
46
50
|
// console.time('GOOSE')
|
|
47
51
|
// await GOOSE_Codec('AaD0CC93AKD0CC93iLgAAQCRAAAAAGGBhoAaR0VEZXZpY2VGNjUwL0xMTjAkR08kZ2NiMDGBAwCcQIIYR0VEZXZpY2VGNjUwL0xMTjAkR09PU0UxgwtGNjUwX0dPT1NFMYQIOG6780IXKAqFAQGGAQuHAQCIAQGJAQCKAQirIIMBAIQDAwAAgwEAhAMDAACDAQCEAwMAAIMBAIQDAwAA')
|
|
52
|
+
// await GOOSE_Codec('AQzNAQNVABAAAANVgQAABoi4A1UAlgAAAABhgYuAGlBMMTEwMVBJR08wMS9MTE4wJEdPJGdvY2IwgQInEIIZUEwxMTAxUElHTzAxL0xMTjAkZHNHT09TRYMXUEwxMTAxUElHTzAxL0xMTjAuZ28AA1AAAA///wAApdAQcA==')
|
|
48
53
|
// console.timeEnd('GOOSE')
|
|
49
54
|
//
|
|
50
55
|
// console.time('IEC61850SampleValues')
|
|
@@ -54,7 +59,8 @@ async function UDP_Codec(packet: string): Promise<void> {
|
|
|
54
59
|
// await IPv4_Codec('AQBeAAD7RvyxjrRvCABFAABDFi9AAP8Rwg7AqAHI4AAA+61EFOkALwQ6AAAAAAABAAAAAAAACl9seXJhLW1kbnMEX3VkcAVsb2NhbAAADIAB')
|
|
55
60
|
console.time('IPv4')
|
|
56
61
|
// await IPv4_Codec('AAAAAAAAAAAAAAAACABLAABseDcAAEABdS1/AAABfwAAAYYWAAAAAgIQAAIAAAACAAQABQAGAO8AAAAAKVCMCgABkk2uRRMODAAICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc=')
|
|
57
|
-
await IPv4_Codec('AAABAAABAAECAwQFgQAHAQgARQAD73UOAAD//cCqwFUBAsAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoikeAWYiHtu0w+Ilen5pPcowdgE=')
|
|
63
|
+
await IPv4_Codec('jrqXwYfpMsUZ/NE3CABFAABU9jEAAEABAIjAqAGewKgBAQgAVeFhQwAAZ+gRVAAC3JkICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc=')
|
|
58
64
|
console.timeEnd('IPv4')
|
|
59
65
|
//
|
|
60
66
|
// console.time('ARP')
|
|
@@ -71,16 +77,10 @@ async function UDP_Codec(packet: string): Promise<void> {
|
|
|
71
77
|
// await UDP_Codec('////////CAAnzP1BCABFAAD/uTJAAEAR+6XAqAHGwKgB/wCKAIoA62oQEQp9csCoAcYAigDVAAAgRkFGRUZEQ0FDQUNBQ0FDQUNBQ0FDQUNBQ0FDQUNBQUEAIEZIRVBGQ0VMRUhGQ0VQRkZGQUNBQ0FDQUNBQ0FDQUJOAP9TTUIlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQAAOwAAAAAAAAAAAAAAAAAAAAAAAAA7AFYAAwABAAEAAgBMAFxNQUlMU0xPVFxCUk9XU0UAAe2A/AoAUFRTAAAAAAAAAAAAAAAAAAYBA5qBAA8BVapwdHMgc2VydmVyIChTYW1iYSwgVWJ1bnR1KQA=')
|
|
72
78
|
// console.timeEnd('UDP')
|
|
73
79
|
|
|
80
|
+
// console.time('IPv6')
|
|
81
|
+
// await IPv6_Codec('xAI6RAAAxAA6RAAAht1gAAAAADw6QP6AAAAAAAAAxgA6//5EAAD+gAAAAAAAAMYCOv/+RAAAgQDIrxOKAAEBAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0')
|
|
82
|
+
// await IPv6_Codec('MzMAAAAWxAI6RAAAht1uAAAAACQAAf6AAAAAAAAAxgI6//5EAAD/AgAAAAAAAAAAAAAAAAAWOgAFAgAAAQCPAHDCAAAAAQQAAAD/AgAAAAAAAAAAAAAAAAAC')
|
|
83
|
+
// console.timeEnd('IPv6')
|
|
84
|
+
|
|
74
85
|
|
|
75
|
-
// const fobj = new FlexibleObject({
|
|
76
|
-
// cc1: true
|
|
77
|
-
// })
|
|
78
|
-
// fobj.cc2.bb3.setValue(true)
|
|
79
|
-
//
|
|
80
|
-
// fobj.c1.b1.ccc1.setValue('1')
|
|
81
|
-
// fobj.c1.b1.ccc2.setValue(2)
|
|
82
|
-
// fobj.c1.b1.ccc3.setValue(true)
|
|
83
|
-
// // console.log(fobj.cc2.bb4.getValue(), fobj.cc2.bb4.isUndefined())
|
|
84
|
-
// console.log(JSON.stringify(fobj.getValue(), null, 2))
|
|
85
|
-
// console.log(fobj.c1.b1.ccc4.hhh6.getPath())
|
|
86
86
|
})()
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {PcapReader} from '../../lib/pcap/PcapReader'
|
|
2
|
-
import path from 'node:path'
|
|
3
2
|
|
|
4
3
|
(async (): Promise<void> => {
|
|
5
4
|
// const reader = new PcapReader({filename: path.resolve(__dirname, '../../../test.pcap'), watch: false})
|
|
@@ -9,6 +8,6 @@ import path from 'node:path'
|
|
|
9
8
|
console.log(pcapPacketInfo.index)
|
|
10
9
|
}).once('done', () => {
|
|
11
10
|
console.log('done!')
|
|
12
|
-
}).once('error',console.error)
|
|
11
|
+
}).once('error', console.error)
|
|
13
12
|
await reader.start()
|
|
14
13
|
})()
|