@netkitty/codec 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CHANGELOG.md +249 -0
  2. package/README.md +30 -1
  3. package/README.zh-CN.md +26 -1
  4. package/dist/Codec.d.ts +25 -7
  5. package/dist/Codec.js +151 -18
  6. package/dist/PacketHeaders.d.ts +2 -0
  7. package/dist/PacketHeaders.js +8 -4
  8. package/dist/abstracts/BaseHeader.d.ts +34 -0
  9. package/dist/abstracts/BaseHeader.js +43 -0
  10. package/dist/headers/ARP.d.ts +3 -1
  11. package/dist/headers/ARP.js +8 -1
  12. package/dist/headers/BACnetIP.js +2 -1
  13. package/dist/headers/BGP.js +3 -2
  14. package/dist/headers/Babel.js +1 -1
  15. package/dist/headers/Codesys.js +3 -2
  16. package/dist/headers/DHCP.js +2 -1
  17. package/dist/headers/DNP3.d.ts +12 -7
  18. package/dist/headers/DNP3.js +98 -18
  19. package/dist/headers/DTLS.js +5 -3
  20. package/dist/headers/Diameter.js +2 -1
  21. package/dist/headers/Elasticsearch.js +3 -2
  22. package/dist/headers/EthernetII.d.ts +1 -0
  23. package/dist/headers/EthernetII.js +3 -0
  24. package/dist/headers/Goose.d.ts +31 -7
  25. package/dist/headers/Goose.js +409 -168
  26. package/dist/headers/HARTIP.js +2 -2
  27. package/dist/headers/ICMP.d.ts +1 -0
  28. package/dist/headers/ICMP.js +9 -1
  29. package/dist/headers/ICMPv6.d.ts +1 -0
  30. package/dist/headers/ICMPv6.js +1 -0
  31. package/dist/headers/IEC104_I_Frame.d.ts +28 -0
  32. package/dist/headers/IEC104_I_Frame.js +246 -160
  33. package/dist/headers/IEC104_S_Frame.js +3 -3
  34. package/dist/headers/IEC104_U_Frame.js +5 -3
  35. package/dist/headers/IEC61850SampledValues.d.ts +1 -0
  36. package/dist/headers/IEC61850SampledValues.js +16 -1
  37. package/dist/headers/IPFIX.js +2 -1
  38. package/dist/headers/IPv4.d.ts +1 -0
  39. package/dist/headers/IPv4.js +6 -0
  40. package/dist/headers/IPv6.d.ts +1 -0
  41. package/dist/headers/IPv6.js +6 -0
  42. package/dist/headers/IPv6HopByHopOptions.d.ts +2 -0
  43. package/dist/headers/IPv6HopByHopOptions.js +11 -0
  44. package/dist/headers/KNXnetIP.js +3 -2
  45. package/dist/headers/LACP.js +2 -1
  46. package/dist/headers/LDP.js +2 -2
  47. package/dist/headers/MQTT.js +3 -1
  48. package/dist/headers/MarkerProtocol.js +2 -1
  49. package/dist/headers/NHRP.js +7 -15
  50. package/dist/headers/NetFlowV5.js +2 -1
  51. package/dist/headers/OPCUA.js +4 -0
  52. package/dist/headers/OSPF.d.ts +2 -2
  53. package/dist/headers/OSPF.js +32 -20
  54. package/dist/headers/OSPFv3.d.ts +38 -0
  55. package/dist/headers/OSPFv3.js +316 -0
  56. package/dist/headers/PPTP.js +2 -2
  57. package/dist/headers/QUIC.js +8 -3
  58. package/dist/headers/RGoose.js +2 -1
  59. package/dist/headers/RIP.js +3 -2
  60. package/dist/headers/RIPng.js +3 -2
  61. package/dist/headers/RTCP.js +3 -2
  62. package/dist/headers/RTP.js +3 -2
  63. package/dist/headers/SFlow.js +4 -2
  64. package/dist/headers/SLMP.js +2 -1
  65. package/dist/headers/SLP.js +2 -1
  66. package/dist/headers/SLPv1.js +2 -1
  67. package/dist/headers/SMB1.js +3 -2
  68. package/dist/headers/SMB2.js +3 -2
  69. package/dist/headers/STUN.js +2 -1
  70. package/dist/headers/TLS_Handshake.d.ts +6 -0
  71. package/dist/headers/TLS_Handshake.js +28 -3
  72. package/dist/headers/TacacsPlus.js +3 -1
  73. package/dist/headers/Trailer.d.ts +30 -0
  74. package/dist/headers/Trailer.js +63 -0
  75. package/dist/headers/VLAN_802dot1Q.d.ts +1 -0
  76. package/dist/headers/VLAN_802dot1Q.js +3 -0
  77. package/dist/headers/WakeOnLAN.js +2 -1
  78. package/dist/headers/WireGuard.js +3 -2
  79. package/dist/headers/Zabbix.js +2 -2
  80. package/dist/lib/BERElement.d.ts +51 -0
  81. package/dist/lib/BERElement.js +125 -0
  82. package/dist/types/LayerGraph.d.ts +10 -5
  83. package/package.json +2 -2
@@ -61,8 +61,8 @@ class HARTIP extends BaseHeader_1.BaseHeader {
61
61
  summary: 'HART-IP type=${messageType} id=${messageId} seq=${sequenceNumber}',
62
62
  properties: {
63
63
  //Protocol version — 1 for the current HART-IP specification. Kept verbatim so a crafted
64
- //message with any version still round-trips.
65
- version: this.fieldUInt('version', 0, 1, 'Version'),
64
+ //message with any version still round-trips. Default 1: what match() requires.
65
+ version: { ...this.fieldUInt('version', 0, 1, 'Version'), default: 1 },
66
66
  //0 Request, 1 Response, 2 Publish/Notify, 3 NAK. Kept as a plain clamped byte (not an Ajv
67
67
  //enum) so any non-conformant / crafted value decoded from the wire still re-encodes
68
68
  //without throwing — decode never fails and encode is a faithful executor.
@@ -9,6 +9,7 @@ export declare class ICMP extends BaseHeader {
9
9
  SCHEMA: ProtocolJSONSchema;
10
10
  id: string;
11
11
  readonly matchKeys: string[];
12
+ readonly ipVersions: number[];
12
13
  name: string;
13
14
  nickname: string;
14
15
  match(): boolean;
@@ -107,6 +107,8 @@ class ICMP extends BaseHeader_1.BaseHeader {
107
107
  };
108
108
  this.id = 'icmp';
109
109
  this.matchKeys = ['ipproto:1'];
110
+ //ICMP is for IPv4 (ICMPv6 is a separate protocol, 58).
111
+ this.ipVersions = [4];
110
112
  this.name = 'Internet Control Message Protocol';
111
113
  this.nickname = 'ICMP';
112
114
  }
@@ -144,7 +146,13 @@ class ICMP extends BaseHeader_1.BaseHeader {
144
146
  match() {
145
147
  if (!this.prevCodecModule)
146
148
  return false;
147
- return this.prevCodecModule.instance.protocol.getValue() === 0x01;
149
+ //Protocol 1 from the IPv4 header itself, or Next Header 1 from AH after an IPv4 header.
150
+ if (this.prevCodecModule.instance.protocol.getValue() === 0x01)
151
+ return true;
152
+ if (this.prevCodecModule.instance.nxt.getValue() !== 0x01)
153
+ return false;
154
+ const ip = this.nearestIPModule();
155
+ return !!ip && ip.id === 'ipv4';
148
156
  }
149
157
  }
150
158
  exports.ICMP = ICMP;
@@ -9,6 +9,7 @@ export declare class ICMPv6 extends BaseHeader {
9
9
  SCHEMA: ProtocolJSONSchema;
10
10
  id: string;
11
11
  readonly matchKeys: string[];
12
+ readonly ipVersions: number[];
12
13
  name: string;
13
14
  nickname: string;
14
15
  match(): boolean;
@@ -79,6 +79,7 @@ class ICMPv6 extends BaseHeader_1.BaseHeader {
79
79
  };
80
80
  this.id = 'icmpv6';
81
81
  this.matchKeys = ['ipproto:58'];
82
+ this.ipVersions = [6];
82
83
  this.name = 'Internet Control Message Protocol v6';
83
84
  this.nickname = 'ICMPv6';
84
85
  }
@@ -1,5 +1,18 @@
1
1
  import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
2
2
  import { BaseHeader } from '../abstracts/BaseHeader';
3
+ /** The fields of a CP56Time2a time tag, as the time-tagged IOA items carry them. */
4
+ type CP56Time2a = {
5
+ Milliseconds: number;
6
+ Minutes: number;
7
+ GEN: number;
8
+ MIN_IV: number;
9
+ Hours: number;
10
+ SU: number;
11
+ Day: number;
12
+ DOW: number;
13
+ Month: number;
14
+ Year: number;
15
+ };
3
16
  export declare class IEC104_I_Frame extends BaseHeader {
4
17
  /**
5
18
  * True when decode preserved an unparsed ASDU (unknown/unsupported type id) and no
@@ -7,12 +20,26 @@ export declare class IEC104_I_Frame extends BaseHeader {
7
20
  * supplying structured IOA turns this false and encode rebuilds from fields.
8
21
  */
9
22
  protected asduRawFallbackActive(): boolean;
23
+ /**
24
+ * The number of IOA items encode writes: one per information object (SQ=0) or element (SQ=1).
25
+ */
26
+ protected ioaItemCount(): number;
10
27
  /**
11
28
  * Write an information object's 3-octet address. SQ=0 frames carry a per-object address; SQ=1
12
29
  * frames carry a single base address (before the first element) with the rest implied by
13
30
  * incrementing, so only object 1 writes it.
14
31
  */
15
32
  protected writeIOAAddress(offset: number, buffer: Buffer, i: number): void;
33
+ /**
34
+ * Read a 7-octet CP56Time2a (IEC 60870-5-4, IEC 60870-5-101 7.2.6.18) at `offset`: milliseconds (2
35
+ * octets, little-endian), minutes with GEN and IV in bits 7 and 8, hours with SU in bit 8, day of month
36
+ * with day of week in bits 6-8, month, year.
37
+ */
38
+ protected readCP56Time2a(offset: number): CP56Time2a;
39
+ /**
40
+ * Write a 7-octet CP56Time2a at `offset`, the inverse of readCP56Time2a.
41
+ */
42
+ protected writeCP56Time2a(offset: number, time: CP56Time2a): void;
16
43
  SCHEMA: ProtocolJSONSchema;
17
44
  id: string;
18
45
  readonly matchKeys: string[];
@@ -21,3 +48,4 @@ export declare class IEC104_I_Frame extends BaseHeader {
21
48
  nickname: string;
22
49
  match(): boolean;
23
50
  }
51
+ export {};