@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.
Files changed (136) hide show
  1. package/CHANGELOG.md +324 -0
  2. package/README.md +31 -7
  3. package/README.zh-CN.md +28 -7
  4. package/dist/Codec.d.ts +4 -3
  5. package/dist/Codec.js +48 -6
  6. package/dist/PacketHeaders.d.ts +2 -0
  7. package/dist/PacketHeaders.js +8 -4
  8. package/dist/abstracts/BaseHeader.d.ts +43 -0
  9. package/dist/abstracts/BaseHeader.js +75 -0
  10. package/dist/headers/AH.js +3 -2
  11. package/dist/headers/ARP.d.ts +3 -1
  12. package/dist/headers/ARP.js +8 -1
  13. package/dist/headers/BACnetIP.js +2 -1
  14. package/dist/headers/BFD.d.ts +2 -1
  15. package/dist/headers/BFD.js +30 -4
  16. package/dist/headers/BGP.js +8 -3
  17. package/dist/headers/Babel.js +1 -1
  18. package/dist/headers/C37118.d.ts +3 -2
  19. package/dist/headers/C37118.js +34 -15
  20. package/dist/headers/CDP.d.ts +3 -3
  21. package/dist/headers/CDP.js +46 -10
  22. package/dist/headers/CMS.js +25 -10
  23. package/dist/headers/COTP.js +2 -3
  24. package/dist/headers/CoAP.js +20 -2
  25. package/dist/headers/Codesys.js +3 -2
  26. package/dist/headers/DCCP.d.ts +3 -2
  27. package/dist/headers/DCCP.js +60 -8
  28. package/dist/headers/DHCP.js +2 -1
  29. package/dist/headers/DNP3.d.ts +12 -5
  30. package/dist/headers/DNP3.js +153 -18
  31. package/dist/headers/DTLS.js +5 -3
  32. package/dist/headers/Diameter.js +2 -1
  33. package/dist/headers/EIGRP.d.ts +3 -2
  34. package/dist/headers/EIGRP.js +31 -5
  35. package/dist/headers/Elasticsearch.js +3 -2
  36. package/dist/headers/EthernetII.d.ts +1 -0
  37. package/dist/headers/EthernetII.js +4 -0
  38. package/dist/headers/GELF.js +1 -0
  39. package/dist/headers/GENEVE.js +1 -0
  40. package/dist/headers/GRE.js +1 -0
  41. package/dist/headers/GTPv2C.js +1 -0
  42. package/dist/headers/Goose.d.ts +31 -7
  43. package/dist/headers/Goose.js +413 -172
  44. package/dist/headers/HARTIP.js +2 -2
  45. package/dist/headers/HSR.js +1 -0
  46. package/dist/headers/HTTP2.js +1 -0
  47. package/dist/headers/ICMP.js +2 -1
  48. package/dist/headers/ICMPv6.js +10 -16
  49. package/dist/headers/IEC104_I_Frame.d.ts +28 -0
  50. package/dist/headers/IEC104_I_Frame.js +434 -319
  51. package/dist/headers/IEC104_S_Frame.js +22 -4
  52. package/dist/headers/IEC104_U_Frame.js +24 -4
  53. package/dist/headers/IEC61850SampledValues.d.ts +1 -0
  54. package/dist/headers/IEC61850SampledValues.js +20 -5
  55. package/dist/headers/IGMP.d.ts +8 -7
  56. package/dist/headers/IGMP.js +57 -19
  57. package/dist/headers/IPFIX.js +3 -2
  58. package/dist/headers/IPv4.d.ts +1 -0
  59. package/dist/headers/IPv4.js +32 -23
  60. package/dist/headers/IPv6.d.ts +1 -0
  61. package/dist/headers/IPv6.js +10 -1
  62. package/dist/headers/IPv6HopByHopOptions.js +11 -1
  63. package/dist/headers/ISAKMP.js +1 -0
  64. package/dist/headers/KNXnetIP.js +3 -2
  65. package/dist/headers/Kerberos.js +1 -0
  66. package/dist/headers/L2TP.js +1 -0
  67. package/dist/headers/LACP.js +2 -1
  68. package/dist/headers/LDAP.js +1 -1
  69. package/dist/headers/LDP.js +2 -2
  70. package/dist/headers/LLC.js +1 -0
  71. package/dist/headers/MQTT.js +3 -1
  72. package/dist/headers/MarkerProtocol.js +2 -1
  73. package/dist/headers/NHRP.d.ts +1 -1
  74. package/dist/headers/NHRP.js +29 -4
  75. package/dist/headers/NetFlowV5.js +2 -1
  76. package/dist/headers/OPCUA.js +4 -0
  77. package/dist/headers/OSPF.d.ts +5 -5
  78. package/dist/headers/OSPF.js +98 -12
  79. package/dist/headers/OSPFv3.d.ts +37 -0
  80. package/dist/headers/OSPFv3.js +314 -0
  81. package/dist/headers/PIM.d.ts +3 -3
  82. package/dist/headers/PIM.js +55 -6
  83. package/dist/headers/PPPoEDiscovery.js +2 -0
  84. package/dist/headers/PPTP.js +2 -2
  85. package/dist/headers/PTP.js +5 -1
  86. package/dist/headers/QUIC.js +8 -3
  87. package/dist/headers/RDP.js +2 -0
  88. package/dist/headers/RGoose.js +4 -1
  89. package/dist/headers/RIP.js +3 -2
  90. package/dist/headers/RIPng.js +3 -2
  91. package/dist/headers/RSVP.d.ts +3 -3
  92. package/dist/headers/RSVP.js +56 -42
  93. package/dist/headers/RTCP.js +4 -2
  94. package/dist/headers/RTP.js +3 -2
  95. package/dist/headers/SCTP.d.ts +2 -2
  96. package/dist/headers/SCTP.js +29 -5
  97. package/dist/headers/SFlow.js +4 -2
  98. package/dist/headers/SLMP.js +2 -1
  99. package/dist/headers/SLP.js +2 -1
  100. package/dist/headers/SLPv1.js +2 -1
  101. package/dist/headers/SMB1.js +3 -2
  102. package/dist/headers/SMB2.js +3 -2
  103. package/dist/headers/SNAP.js +2 -2
  104. package/dist/headers/SNMP.js +2 -2
  105. package/dist/headers/STUN.js +3 -2
  106. package/dist/headers/SercosIII.d.ts +3 -2
  107. package/dist/headers/SercosIII.js +41 -5
  108. package/dist/headers/TCP.js +13 -58
  109. package/dist/headers/TLS_Alert.js +20 -2
  110. package/dist/headers/TLS_ApplicationData.d.ts +3 -3
  111. package/dist/headers/TLS_ApplicationData.js +25 -6
  112. package/dist/headers/TLS_ChangeCipherSpec.d.ts +2 -2
  113. package/dist/headers/TLS_ChangeCipherSpec.js +24 -4
  114. package/dist/headers/TLS_Handshake.d.ts +6 -0
  115. package/dist/headers/TLS_Handshake.js +67 -9
  116. package/dist/headers/TLS_Heartbeat.d.ts +4 -3
  117. package/dist/headers/TLS_Heartbeat.js +40 -7
  118. package/dist/headers/TPKT.js +1 -1
  119. package/dist/headers/TacacsPlus.js +3 -1
  120. package/dist/headers/Trailer.d.ts +30 -0
  121. package/dist/headers/Trailer.js +63 -0
  122. package/dist/headers/UDP.js +17 -61
  123. package/dist/headers/VLAN_802dot1Q.d.ts +1 -0
  124. package/dist/headers/VLAN_802dot1Q.js +4 -0
  125. package/dist/headers/VRRP.d.ts +2 -1
  126. package/dist/headers/VRRP.js +45 -9
  127. package/dist/headers/WakeOnLAN.js +2 -1
  128. package/dist/headers/WireGuard.js +3 -2
  129. package/dist/headers/Zabbix.js +2 -2
  130. package/dist/helper/Checksum.d.ts +15 -0
  131. package/dist/helper/Checksum.js +56 -0
  132. package/dist/helper/Crc.d.ts +18 -0
  133. package/dist/helper/Crc.js +58 -0
  134. package/dist/lib/BERElement.d.ts +51 -0
  135. package/dist/lib/BERElement.js +125 -0
  136. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -3,6 +3,330 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.2.0](https://github.com/myq1991/netkitty/compare/@netkitty/codec@2.1.0...@netkitty/codec@2.2.0) (2026-11-27)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **codec:** compute DNP3 data-block CRCs from a new userData field ([fcbf954](https://github.com/myq1991/netkitty/commit/fcbf9546c7f854eb1139b4f7bb227ac400d0721a))
12
+ * **codec:** count the IEC 104 information objects from IOA when left out ([d89d78c](https://github.com/myq1991/netkitty/commit/d89d78c5129fc84bc40444354e6b295bae205416))
13
+ * **codec:** default the IEC 104 U-frame and S-frame control field to its format ([c768977](https://github.com/myq1991/netkitty/commit/c768977c0fb972916f728ae64aa0dcd2b32145d1))
14
+ * **codec:** default the signature fields match() checks ([cd44c7b](https://github.com/myq1991/netkitty/commit/cd44c7b6a75f0db58d4c7bbd4f9b46ee378d8a0b))
15
+ * **codec:** keep a GOOSE or SV PDU with malformed BER as raw ([9ae2cda](https://github.com/myq1991/netkitty/commit/9ae2cda5a44c59327f571addbe3b02275710e511))
16
+ * **codec:** keep a tls-handshake Hello cut short by the capture as raw ([2bc0671](https://github.com/myq1991/netkitty/commit/2bc0671f54fb20bb9f6d5b4272f2480ac3f9d363))
17
+ * **codec:** keep a wrong-size IPv6 Hop-by-Hop option as a Custom item ([1c57d2a](https://github.com/myq1991/netkitty/commit/1c57d2a65b7697532bb80cacc9a872fa8a48e603))
18
+ * **codec:** keep bytes past a GOOSE or SV Length as a trailer layer ([3aa7d81](https://github.com/myq1991/netkitty/commit/3aa7d814d9153e1399abf4a05a8463e0a68639bc))
19
+ * **codec:** keep bytes past an IP or 802.3 length as a trailer layer ([b6bc47d](https://github.com/myq1991/netkitty/commit/b6bc47d2e013df5eaab2867c9a8f4ac4292620bb))
20
+ * **codec:** keep the Ethernet padding after an ARP packet as a trailer ([fe4eca6](https://github.com/myq1991/netkitty/commit/fe4eca62305d7b54b211f25acb7e84ddf1f06468))
21
+ * **codec:** lay out IEC 104 elements as IEC 60870-5-101 defines them ([8eb7a5d](https://github.com/myq1991/netkitty/commit/8eb7a5dec85eeed824dd969eaec2cf4425c74534))
22
+ * **codec:** mark every node of the GOOSE encoding hints hidden ([935644e](https://github.com/myq1991/netkitty/commit/935644e7f07892c28dac9d4763822c84728886a3))
23
+ * **codec:** re-encode GOOSE with the BER lengths and INTEGER widths it was captured with ([2f6ac64](https://github.com/myq1991/netkitty/commit/2f6ac643556f8a781eaaf02ea3ff4d777b32e740))
24
+ * **codec:** report IOA items of an unknown IEC 104 type id instead of failing ([ff8d7c9](https://github.com/myq1991/netkitty/commit/ff8d7c920346b6943b7ca0d554a5d95a3a7c2228))
25
+ * **codec:** write a tls-handshake body that matches its handshake type ([0415333](https://github.com/myq1991/netkitty/commit/0415333215a85c3425838e5e4634c203b7db717b))
26
+
27
+
28
+ ### Features
29
+
30
+ * **codec:** add OSPFv3 (RFC 5340) as its own header ([fc9a756](https://github.com/myq1991/netkitty/commit/fc9a756dcb594b3cbbc4881b028f76a6ec2f7bef))
31
+
32
+
33
+ ### Upgrade note
34
+
35
+ Decoded trees change shape: bytes past a layer's own length (Ethernet padding) come back as a `trailer`
36
+ layer instead of inside the innermost layer or a trailing `raw`; DNP3 frames whose block CRCs check decode
37
+ as `userData` instead of `payload`; OSPF version 3 decodes as the new `ospfv3`; GOOSE trees carry hidden
38
+ `encoding` hints and malformed GOOSE / SV PDUs decode as `raw`; IEC 104 types 40, 107 and 120–127 read
39
+ their elements at the offsets IEC 60870-5-101 defines.
40
+
41
+ Encode output changes where fields are left out: signature fields that match() checks now have schema
42
+ defaults (a saved template without `rtp.version` now sends 2; a U-frame from `{}` is STARTDT act). Some
43
+ input no longer validates: IEC 104 `NOS` above 255 and the old type-127 `{NOF, SCQ}` shape. Subclasses of
44
+ `Goose` that override its protected BER helpers break. Read "Behaviour changes" below before upgrading.
45
+
46
+ ### Behaviour changes (check before upgrading)
47
+
48
+ #### Ethernet padding is a `trailer` layer
49
+ - IPv4 bounds its payload by Total Length, IPv6 by Payload Length, Ethernet / 802.1Q by the 802.3
50
+ length, GOOSE and Sampled Values by their Length, and an Ethernet/IPv4 ARP packet ends after its 28
51
+ octets. Bytes past that end become a new
52
+ `trailer` layer (`{data: '<hex>'}`, `protocol: false`) at the
53
+ end of the layer list. Before, they were part of the innermost layer (an ICMP echo padded to 60 octets
54
+ showed the padding in `icmp.message`, a UDP payload gained it) or a trailing `raw` layer (after
55
+ LLC / STP, ARP, GOOSE and SV). Across the local captures the trailer bytes equal tshark's
56
+ `eth.padding` + `eth.trailer` on every frame where both see one (15,366 frames).
57
+ - Padding after a TCP segment with no payload no longer decodes as an application layer: across the
58
+ local captures, padding used to decode as CMS, NBSS, COTP or a TLS record on their ports.
59
+ - A length of 0 (segmentation offload), one longer than the bytes captured, or one shorter than its own
60
+ header sets no bound: those frames decode as before. Nested IP layers each bound their own payload, so
61
+ IP in GRE can end with two trailers.
62
+ - Encode writes `trailer` bytes after every other layer and after every computed length and checksum, so
63
+ a left-out IPv4 Total Length, IPv6 Payload Length, 802.3 length or checksum no longer counts the
64
+ padding (before: Total Length 32 → 46 for a padded echo, 802.3 length 38 → 45). A layer given after a
65
+ `trailer` is written before it, with a warning.
66
+ - `allowedNextLayers()` lists `trailer` after every layer (after `raw`); `checkConsistency()` never flags
67
+ it; `summary()` skips it like `raw`.
68
+ - Custom codecs: `BaseHeader.payloadEnd()` (decode only) lets a header with its own length field set the
69
+ same bound.
70
+
71
+ #### DNP3 data blocks
72
+ - New field `userData`: the transport header + application data with the per-block CRCs removed. Left out
73
+ of nothing else, encode splits it into 16-octet blocks and appends each block's CRC-16/DNP.
74
+ - Decode emits exactly one of the two: `userData` when every block CRC checks (`userData: ''` for a frame
75
+ with no user data), otherwise the verbatim `payload` plus a `warning` per bad or truncated block.
76
+ Readers of `dnp3.payload` must read `userData` for well-formed frames.
77
+ - Encode: a non-empty `payload` is written verbatim and wins (to craft a bad CRC); `userData` given as
78
+ well is ignored with a warning. `payload: ''` counts as left out. A left-out `length` is 5 + the
79
+ user-data octets of whichever field is written.
80
+
81
+ #### OSPFv3 is its own header
82
+ - New header `ospfv3` (RFC 5340): 16-octet header with `instanceId`, Hello decoded field by field
83
+ (`interfaceId`, `routerPriority`, `options`, intervals, DR/BDR, `neighbors`), other types kept as
84
+ `rawBody`. `packetLength` and `checksum` (IPv6 pseudo-header, over Packet Length) are computed when left
85
+ out. It runs over IPv6 only; OSPFv3 over IPv4 (RFC 7949) is not supported and decodes as raw.
86
+ - `ospf` now matches version 2 only and has `version` default 2. Protocol 89 with version 3 over IPv6
87
+ decodes as `ospfv3` (it used to decode as `ospf` with the v2 layout); other versions decode as raw.
88
+ `ospf` given `version: 3` on encode still writes the v2 layout, with a warning pointing to `ospfv3`.
89
+
90
+ #### IEC 104
91
+ - `numberOfObject` is computed when left out: the number of IOA items (for SQ=1, the elements). The items
92
+ written always come from `IOA`: an explicit count that differs is written as given, every item is still
93
+ written, and a warning is recorded. Before, a left-out or 0 count dropped every item silently, and a
94
+ larger count failed with an encode error. More than 127 items: the count is clamped to 127 with a
95
+ warning.
96
+ - A U-frame built from empty data is STARTDT act (`controlField` default `07000000`, `680407000000`)
97
+ instead of `680400000000`, which re-decoded as an I-frame. An S-frame from empty data is
98
+ `680401000000` (6 octets) instead of `680101`.
99
+ - `apciType` (I / S / U) lost its numeric `minimum` / `maximum` (it is a string).
100
+
101
+ #### tls-handshake
102
+ - Only ClientHello and ServerHello build a body from fields. Every other type writes `messagedata.raw`, or
103
+ nothing when it is left out, so `{}` is an empty HelloRequest (`160303000400000000`) instead of a 6-byte
104
+ zero body. Hello fields given under another type are dropped with a warning.
105
+ - In a Hello, a left-out `random` is 32 zero octets and a left-out ServerHello `cipherSuite` /
106
+ `compressionMethod` is zeros of its size, so a Hello built from its type alone re-decodes as a Hello.
107
+ - A captured ServerHelloDone no longer gains 6 octets on re-encode.
108
+
109
+ #### GOOSE and Sampled Values
110
+ - GOOSE re-encodes with the BER length forms and INTEGER widths it was captured with. Before, a device
111
+ that writes long-form lengths or fixed 4-octet INTEGERs (timeAllowedtoLive, stNum, sqNum, confRev,
112
+ numDatSetEntries, INT32 items) got a shorter frame back: 798 of 8693 GOOSE frames in one substation
113
+ capture. Decode records only the forms that are not minimal, in a hidden `encoding` node on `goosePdu`
114
+ (`lengthOctets`, and `{lengthOctets?, width?}` per field) and on each `allData` item (`lengthOctets`,
115
+ `width` on INT items, `content` hex on FLOAT32). Encode uses a hint while the value still fits and
116
+ writes the minimal form otherwise; a tree without hints encodes exactly as before.
117
+ - FLOAT32 items decode the 4 octets after the exponent-width octet. Before, the goosePdu span was one
118
+ octet short after a long-form length, so the last item lost its final octet (0.0 decoded as
119
+ 3.85e-34, and the lost octet became a stray `raw` layer). FLOAT64 (width 11) decodes as its value with
120
+ a warning; other forms decode as 0 with an error; both, and NaN, re-emit their captured octets. -0.0
121
+ encodes as `80000000`.
122
+ - A goosePdu or savPdu whose BER cannot be walked strictly (an element that runs past its parent or
123
+ Length, octets left over, unknown, repeated or out-of-order goosePdu elements) decodes as `raw` with
124
+ the error `Malformed goosePdu, kept as raw: …` instead of partial fields that re-encoded to a different
125
+ PDU.
126
+ - GOOSE / SV `length` now bounds the PDU: a decoded tree edited to a different PDU size must leave
127
+ `length` out to have it recomputed (an explicit value is written as given).
128
+ - Subclasses of `Goose`: the protected `decodeDataTLVItem` takes `BERElement[]`, `encodeDataTLVItem`
129
+ returns `Buffer[]`, and `TLVInstance` / `TLVChild` are gone.
130
+
131
+ #### IEC 104 element layouts
132
+ - Type 32 (M_ST_TB_1) wrote the CP56Time2a minute IV flag into the high milliseconds octet, so a time
133
+ tag with milliseconds ≥ 32768 re-encoded wrong.
134
+ - Types 40, 107 and 120–126 read and write their elements as IEC 60870-5-101 defines them, so the same
135
+ bytes decode to different values (same field names): 40 M_EP_TF_1 has QDP in its own octet (11
136
+ octets, CP16Time2a at +5, CP56Time2a at +7); 107 C_TS_TA_1 has a 16-bit TSC (9 octets); file transfer
137
+ has NOF 2 octets, NOS 1 and LOF 3 (122 / 123 little-endian like the rest; 126's CP56Time2a at +9).
138
+ - Type 127 F_SC_NB_1 is QueryLog: `{address, NOF, RangeStartTime, RangeStopTime}` (two CP56Time2a). The
139
+ old `{NOF, SCQ}` input no longer validates.
140
+ - Schema: `NOS` maximum 65535 → 255 (larger input is now rejected), `LOF` maximum → 16777215, `TSC` →
141
+ 65535; type 126's `LOS` is `SOF` (Status Of File), as decode already produced.
142
+ - An unknown type id with IOA items records `Type id N has no element layout: the IOA items are not
143
+ written` (the unparsed ASDU in `raw` is still written) instead of an encode error.
144
+
145
+ #### tls-handshake cut short by the capture
146
+ - A Hello whose body runs past the captured bytes (a ClientHello split across TCP segments) decodes as
147
+ `messagedata.raw` with the error `… the body continues past the captured bytes`, so it re-encodes
148
+ byte-exact. Before, a segment that ended exactly at an extension boundary decoded as a structured Hello
149
+ and re-encode rewrote the extensions length. Cut-short Hellos that already decoded raw keep their shape;
150
+ their error text changes.
151
+
152
+ #### IPv6 Hop-by-Hop
153
+ - A fixed-size option with the wrong size decodes as a Custom item instead of a typed item that failed
154
+ encode validation.
155
+
156
+ #### Signature defaults
157
+ - Fields a header's match() checks now have schema defaults, so the header built from `{}` re-decodes as
158
+ itself: STUN / DHCP / PPTP / Zabbix magic cookies, BGP marker, Wake-on-LAN sync stream, version fields
159
+ (NetFlow 5, sFlow 5, IPFIX 10, Diameter 1, HART-IP 1, LDP 1, SLP 2 / 1, RTP 2, KNXnet/IP 06/10,
160
+ TACACS+ 0xc, RIP 2, RIPng 1, DTLS fefd, QUIC v1 with `headerForm` and `fixedBit` true — also filled
161
+ when `firstByte` is given without them), message types (R-GOOSE 0xA1, WireGuard 1, MQTT
162
+ PINGREQ, RTCP RR, OPC UA HEL, SLMP 0x5000, LACP 1, Marker 2) and Babel / Elasticsearch / CODESYS /
163
+ SMB / BACnet signatures. Only input that leaves these fields out changes; decoded trees carry them.
164
+
165
+ ### Additions
166
+ - Headers `trailer` and `ospfv3`.
167
+ - Fixtures from real captures for GOOSE (long-form lengths, fixed-width INTEGERs, a minimal device), SV
168
+ and GOOSE with trailers, IEC 104 type 32, a cut-short TLS ClientHello and a TLS ServerHelloDone.
169
+ - `BaseHeader.payloadEnd()` for custom codecs.
170
+ - Test gate: every header built from `{}` under its usual parent re-decodes as itself.
171
+
172
+ ### Known limitations
173
+ - Trailer layers are always written at the end of the packet, so a trailer that decode placed inside a
174
+ tunnel (between an inner and an outer IP datagram) moves to the end when the lengths are left out.
175
+ - An 802.3 length below 3 (shorter than an LLC header) sets no bound.
176
+ - OSPFv3 over IPv4 (RFC 7949) is not supported.
177
+ - IEC 104: C_RD_NA_1 (102) decodes and encodes a READ octet the standard does not have, so a captured read
178
+ command gains an octet on re-encode; VTI decodes unsigned (tshark reads it as signed 7-bit). Types 40,
179
+ 107 and 120–127 are checked against the standard's element sizes only (no capture has them).
180
+ - GOOSE: a goosePdu carrying an element the decoder does not know, such as the optional `security [12]`
181
+ element, or a repeated or out-of-order one, now decodes as `raw` as a whole (it still re-encodes
182
+ byte-exact, but its fields cannot be edited). Unknown allData item tags (array, binary-time, bcd, mMSString, …) are dropped; a boolean TRUE
183
+ other than `01` re-encodes as `01`; a constructed goosePdu tag other than `61` re-encodes as `61`;
184
+ GOOSE strings and SV svID / datSet decode as ASCII, so octets ≥ 0x80 lose bit 7. SV gets no encoding
185
+ hints, so a non-minimal SV length form is not kept.
186
+ - Where a given length positions what follows (QUIC connection IDs, S7comm parameter/data, Diameter AVPs,
187
+ AMQP frame end, …), an explicit length that disagrees with the data reshapes the packet the way decode
188
+ would read it.
189
+
190
+
191
+
192
+
193
+
194
+ # [2.1.0](https://github.com/myq1991/netkitty/compare/@netkitty/codec@2.0.0...@netkitty/codec@2.1.0) (2026-11-26)
195
+
196
+
197
+ ### Bug Fixes
198
+
199
+ * **codec:** annotate inferred and computed fields, declare constant fallbacks as defaults ([c7953e3](https://github.com/myq1991/netkitty/commit/c7953e3fac0ac8fa687872d044b2cd81e624ab74))
200
+ * **codec:** build the IGMPv3 query from its own fields and compute the IGMP checksum ([07bc9a7](https://github.com/myq1991/netkitty/commit/07bc9a75581fe0269ee77051de22a8d206c71bea))
201
+ * **codec:** compute auto fields only when left out, and find the IP layer for pseudo-headers ([f3b2571](https://github.com/myq1991/netkitty/commit/f3b25717506353ed47f9178dbbf760924409e88e))
202
+ * **codec:** compute PIM, EIGRP, NHRP, VRRP and OSPF checksums when left out ([5d82eda](https://github.com/myq1991/netkitty/commit/5d82eda00616f9b4abe105c2051c5248f4382a8e))
203
+ * **codec:** compute RSVP and CDP checksums, write their explicit lengths as given ([3f0c6fa](https://github.com/myq1991/netkitty/commit/3f0c6faa7a609d00a503331f2da76906bcfd0fe5))
204
+ * **codec:** compute the BFD, CMS, CoAP and IEC 104 lengths when left out ([59be323](https://github.com/myq1991/netkitty/commit/59be32306a0d40e21e7162ef5c9105603230fd4c))
205
+ * **codec:** compute the SCTP CRC32c and the DCCP checksum when left out ([58311cb](https://github.com/myq1991/netkitty/commit/58311cbfb951786e87fa2e218fce39074786ed5d))
206
+ * **codec:** compute the Sercos III, DNP3 and C37.118 checks when left out ([a73343b](https://github.com/myq1991/netkitty/commit/a73343b68a4e6db4bba0aab3bbb72cfe8ab51824))
207
+ * **codec:** compute TLS record lengths when left out ([2183575](https://github.com/myq1991/netkitty/commit/21835752dc1140808dc9f0e1b1a5c74d60b5ca11))
208
+ * **codec:** leave the IPv4 pseudo-header out of the VRRP v3 checksum (RFC 9568) ([3a0487e](https://github.com/myq1991/netkitty/commit/3a0487e64fa54cb4284cd4c87d3d2dc0ac50b990))
209
+ * **codec:** let every decoded IEC 104 I-frame tree pass encode validation ([abac0b8](https://github.com/myq1991/netkitty/commit/abac0b886971274d531c3b2e83c285282d8770d2))
210
+ * **codec:** zero-fill a DCCP header up to the Data Offset computed for it ([a521722](https://github.com/myq1991/netkitty/commit/a521722ab35c654935a4f58962ddb71f76ee01e7))
211
+
212
+
213
+ ### Upgrade note
214
+
215
+ Encode now computes a length, count or checksum only when the field is left out: a caller that passes
216
+ `0` to mean "compute it" (as `ipv4.checksum: 0` / `udp.length: 0` used to allow) must leave the field
217
+ out instead. Read "Behaviour changes" below before upgrading.
218
+
219
+ ### Behaviour changes (check before upgrading)
220
+
221
+ #### An explicit value is never recomputed
222
+ - An `autoCalculated` field is computed only when it is **left out** of the input. Any value you give,
223
+ **0 included**, is written as given. Before, many fields treated 0 as "compute": `ipv4.hdrLen` /
224
+ `length` / `checksum`, `ipv6.plen`, `ipv6-hopopt.len`, `tcp.hdrLen` / `checksum`, `udp.length` /
225
+ `checksum`, `icmp.checksum`, `icmpv6.checksum`, `ah.payloadLen`, `tpkt.length`, `cotp.li`,
226
+ `stun.messageLength`, `ipfix.length`, `goose.length`, `sv.length`. Code that passes `0` to mean
227
+ "calculate it" now sends 0; leave the field out instead.
228
+ - On an integer field, `null` is coerced to 0 (so it counts as a given 0) and `''` fails validation. On
229
+ a hex string field, `''` and `null` count as left out.
230
+ - A captured UDP datagram with checksum 0 ("no checksum", RFC 768) now re-encodes to its own bytes
231
+ (it used to get a computed checksum).
232
+ - `bgp.length` minimum 19 → 0 and `ptp.messageLength` minimum 34 → 0: a shorter value is written as given
233
+ with a warning (`Length should be at least 19` / `Message length should be at least 34`) instead of
234
+ failing validation.
235
+
236
+ #### encode() no longer changes its input
237
+ - `encode()` validates a deep copy (`structuredClone`, Node.js 17+) of each input, so Ajv defaults
238
+ (`tpkt.version`, `cotp.pduType`, …) and type coercion (`'102'` → `102`) no longer appear in the objects
239
+ you passed. Code that read defaults back from its own input after encoding must read the decoded
240
+ result instead.
241
+
242
+ #### Checksums over the right IP layer
243
+ - TCP, UDP and ICMPv6 take their pseudo-header from the nearest IPv4/IPv6 layer beneath, so a checksum
244
+ behind AH or an IPv6 extension header is now correct (it was 0 behind AH). With no IP layer beneath, a
245
+ warning is recorded (`Cannot compute … checksum: no IP layer beneath …`). ICMPv6 inside an
246
+ IPv6-in-IPv6 tunnel now uses the inner header.
247
+
248
+ #### Newly computed fields (when left out; all now `autoCalculated`)
249
+ Before, each of these was written as 0 when left out.
250
+ - Internet checksums: `igmp.checksum` (the IGMP message), `pim.checksum` (whole message; a Register
251
+ covers its first 8 bytes; over IPv6 with the pseudo-header, next header 103), `eigrp.checksum`,
252
+ `rsvp.checksum`, `nhrp.checksum`, `vrrp.checksum` (v2 and v3 over IPv4 over the message, RFC 9568;
253
+ v3 over IPv6 with the pseudo-header, protocol 112), `ospf.checksum` (OSPFv2: the packet without the
254
+ 64-bit authentication field; 0 for cryptographic authentication, RFC 2328 D.4.3), `dccp.checksum`
255
+ (pseudo-header protocol 33, header, and the data CsCov selects), `cdp.checksum` (the Internet checksum
256
+ as Cisco computes it for an odd length, matching Wireshark).
257
+ - CRCs: `sctp.checksum` (CRC32c over the packet, least significant byte first), `sercos3.crc32`
258
+ (CRC-32 over the Ethernet header and Sercos bytes 0–1, little-endian; needs an Ethernet layer
259
+ directly beneath, else 0 with an error), `dnp3.headerCrc` (CRC-16/DNP over octets 0–7),
260
+ `c37118.chk` (CRC-16/CCITT-FALSE over the frame before CHK).
261
+ - Lengths: `ospf.packetLength`, `bfd.length` (24 + authentication section), `cms.frameLength` (bytes
262
+ after the 4-byte header), `dnp3.length` (5 + user-data octets, excluding block CRCs), `coap.tokenLength`,
263
+ `length` of tls-alert / tls-appdata / tls-ccsp / tls-handshake / tls-heartbeat (this record only),
264
+ `tls-handshake.handshakeLength`, `tls-heartbeat.payloadLength`, `apduLength` of IEC 104 I, S and U
265
+ frames.
266
+ - `c37118.framesize` left out now counts the 2-byte CHK when CHK is also left out (it added 0).
267
+
268
+ #### Other encode changes in these protocols
269
+ - IGMPv3 Query: its body is emitted from its own fields (type 0x11 with any of `resvSQRV`,
270
+ `qqic`, `numSources`, `sources` given), not from the IP Total Length, so a left-out `ipv4.length` no
271
+ longer drops the sources. A type 0x11 message with no v3 field is an 8-byte v2 query, whatever the IP
272
+ length says.
273
+ - `rsvp.length` is written as given (below 8 is flagged; it used to be raised to 8); left out it is
274
+ the bytes actually written, not the sum of the object lengths. `rsvp.objects[].length` and
275
+ `cdp.tlvs[].length` given as 0 are written as 0 (they were recomputed).
276
+ - DCCP with `dataOffset` left out: the header is zero-filled up to the computed Data Offset (a crafted
277
+ header that was not a multiple of 4 octets grows to the next one).
278
+ - IEC 104 I-frame with `apduLength` left out: information objects are spaced by the size of the first
279
+ object written (they were spaced by the given APDU length).
280
+ - A left-out TLS `appData` or heartbeat `payloadMessage` writes nothing (it wrote one 0x00 octet).
281
+ - Layers built from empty data (plus the discriminator `allowedNextLayers` gives) now re-decode as
282
+ themselves: dnp3, coap, c37118, every tls-* record, IEC 104 I and S frames.
283
+
284
+ #### Schema representation (`CODEC_SCHEMAS`)
285
+ - `autoCalculated: true` added to the demux fields encode infers from the next layer
286
+ (`eth` / `vlan` / `hsr` / `snap` `etherType`, `gre` / `geneve` `protocolType`, `ipv4.protocol`,
287
+ `ipv6.nxt`, `ipv6-hopopt.nxt`, `ah.nxt`), to `snap.oui` (derived from `ouiProtocol`) and to
288
+ `rdp.length` (always 8 for the Negotiation structure).
289
+ - `default` added where encode already fell back to a protocol constant, so editors can show it:
290
+ `ipv4.version` 4, `ipv6.version` 6, `ipv4.flags.df` 1, `gelf.magic` `'1e0f'`, `http2.preface` (the
291
+ connection preface), `llc.control` `'03'`, `gtpv2.flags.version` 2, `isakmp.version.major` 2,
292
+ `l2tp.flags.version` 2, `pppoe-disc.type` 1 / `version` 1, `r-session.commonHeaderId` 0x80 /
293
+ `version` 1, `rtcp.version` 2, `kerberos.msgType` 0x6a, `ldap.protocolOpTag` 0x60, `snmp.pduType`
294
+ 0xa0, `snmp.variableBindings[].valueType` 0x05, `pim.version` 2, `rsvp.version` 1, `vrrp.version` 2 /
295
+ `type` 1 / `adverInt` 1, `bfd.version` 1, `c37118.sync.version` 1, `cms.protocolType` 1. Encoded
296
+ bytes are unchanged; a field filled from its default is no longer reported as `'Not Found'`.
297
+ - Protocol signatures now have a `default`, so a layer built from empty data is recognised again:
298
+ `dnp3.start` `'0564'`, `c37118.leadIn` `'aa'`, `coap.version` 1, the TLS records' `contentType`
299
+ (21 alert, 23 appdata, 20 ccsp, 22 handshake, 24 heartbeat) and `version` `'TLS1.2'`,
300
+ `tls-ccsp.change_cipher_spec_message` `'01'`, `startByte` 104 on IEC 104 I / S / U frames.
301
+
302
+ #### IEC 104 I-frame item schemas (decoded trees now always pass encode validation)
303
+ - Item variants that disagreed with what decode fills are corrected: type 40 (M_EP_TF_1) no longer
304
+ requires SIE/SIF (type 39's fields); type 38 (M_EP_TD_1) uses `Milliseconds_16` / `Milliseconds_56`
305
+ instead of `Milliseconds`; type 70 (M_EI_NA_1) uses `COI_R` / `COI_I` instead of `COI` / `LPC`; type 101
306
+ (C_CI_NA_1) uses `RQT` instead of `RQI`. Inputs written against the old names fail validation.
307
+ - Time fields of the 21 time-tagged variants accept their full wire range (milliseconds 0–65535, minutes
308
+ 0–63, hours 0–31, day 0–31, month 0–15, year 0–127); a captured out-of-calendar time (day or month 0)
309
+ re-encodes instead of throwing.
310
+
311
+ ### Additions
312
+ - `BaseHeader` (for custom codecs): protected `isLeftOut(field)` (the left-out test every computed field
313
+ uses), `nearestIPModule()` and `ipPseudoHeader(protocol, upperLayerLength)`.
314
+
315
+ ### Known limitations
316
+ - Not computed: OSPFv3 checksums, the DNP3 per-block data CRCs (kept verbatim in `payload`), IEC 104
317
+ `numberOfObject` (not derived from the item count). tls-handshake still writes its 6-byte hello
318
+ skeleton when `messagedata` is left out. A tcp → IEC 104 U-frame built from empty data does not
319
+ re-decode as a U-frame.
320
+ - IPv4 does not bound its payload by Total Length, and Ethernet padding after an 802.3 / LLC payload
321
+ decodes as a trailing layer; a left-out length or checksum then counts the padding.
322
+ - Where a given length positions what follows (QUIC connection IDs, S7comm parameter/data, Diameter AVPs,
323
+ AMQP frame end, …), an explicit length that disagrees with the data reshapes the packet the way decode
324
+ would read it.
325
+
326
+
327
+
328
+
329
+
6
330
  # [2.0.0](https://github.com/myq1991/netkitty/compare/@netkitty/codec@1.2.1...@netkitty/codec@2.0.0) (2026-11-26)
7
331
 
8
332
 
package/README.md CHANGED
@@ -61,9 +61,13 @@ rebuilt.equals(packet) // true for a well-formed packet — decode/encode roun
61
61
 
62
62
  Build a packet from scratch by handing `encode` an array of `{id, data}` inputs in outer-to-inner
63
63
  order; any field you omit is filled from the schema's defaults, and form-string values are coerced.
64
- A parent's demux field you leave out — an EtherType (`eth`/`vlan`/`hsr`/`gre`/`geneve`/`snap`), the
65
- IPv4 `protocol`, the IPv6 `nxt` — is filled from the layer that follows (eth before LLC gets the IEEE
66
- 802.3 length instead); a value you do supply is always written as given:
64
+ Lengths, counts and checksums you leave out are computed, and a parent's demux field you leave out — an
65
+ EtherType (`eth`/`vlan`/`hsr`/`gre`/`geneve`/`snap`), the IPv4 `protocol`, the IPv6 `nxt` — is filled
66
+ from the layer that follows (eth before LLC gets the IEEE 802.3 length instead). A value you do supply,
67
+ 0 included, is always written as given, so a wrong checksum or length can be crafted on purpose. Leave a
68
+ field out to have it computed: on an integer field `null` is coerced to 0 (and written as 0) and `''`
69
+ fails validation, while on a hex field `''` and `null` count as left out. `encode` works on copies: the
70
+ input objects you pass are never changed.
67
71
 
68
72
  ```ts
69
73
  const {packet} = await codec.encode([
@@ -127,9 +131,9 @@ declaration plays four parts at once:
127
131
  projections such as HTTP `method`/`statusCode` or CMS `serviceDataDecoded`, decoded from a
128
132
  verbatim field that is the real encode authority; also values encode always derives itself). On an
129
133
  object/array it covers every descendant.
130
- - `autoCalculated: true` — encode computes the value (length, checksum, count, offset…) from the
131
- rest of the packet when it is left out (or 0 where that is the field's convention); an explicit
132
- value is still written as given. E.g. `ipv4.length`, `ipv4.checksum`, `tcp.hdrLen`.
134
+ - `autoCalculated: true` — encode computes the value (length, checksum, count, offset, or the demux
135
+ field inferred from the next layer) when it is left out; any value given, 0 included, is written
136
+ as given. E.g. `ipv4.length`, `ipv4.checksum`, `tcp.hdrLen`, `ipv4.protocol`.
133
137
  - `byteAlignment: N` — encode zero-pads the field to a multiple of N bytes, e.g. `ipv4.options`
134
138
  (4) and `tcp.options` (4).
135
139
 
@@ -167,6 +171,24 @@ heuristic matches at the current offset, then advances and recurses until the pa
167
171
  `RawData` is the forced final fallback and always matches, so unknown or malformed trailing bytes simply
168
172
  become a `raw` layer and decode can never dead-end.
169
173
 
174
+ ### Padding and trailers
175
+
176
+ IPv4 (Total Length), IPv6 (Payload Length), an Ethernet / 802.1Q 802.3 length and the GOOSE / Sampled
177
+ Values Length bound the payload they carry, and an Ethernet/IPv4 ARP packet ends after its 28 octets. Bytes past that end — Ethernet padding up to the 60-octet minimum frame, or a trailer a device
178
+ appended — are not given to the layers above; they become a `trailer` layer at the end of the list
179
+ (`{data: '<hex>'}`, `protocol: false`). A length of 0, one longer than the bytes captured, or one shorter
180
+ than its own header sets no bound. On encode, `trailer` bytes are written after every other layer and
181
+ after every computed length and checksum, so a left-out length or checksum never counts them; append
182
+ `{id: 'trailer', data: {data: '0000…'}}` to pad a frame you build.
183
+
184
+ ### Captured encodings
185
+
186
+ Where a protocol allows more than one byte form for the same value, decode keeps what the capture used
187
+ so re-encode reproduces it. GOOSE records BER length forms and INTEGER widths that are not minimal in a
188
+ hidden `encoding` node (on `goosePdu` and on each `allData` item); encode uses them while the value still
189
+ fits and falls back to the minimal form otherwise, and a tree without them encodes minimal. A GOOSE or SV
190
+ PDU whose BER cannot be walked strictly is kept as `raw` (with an error) instead of being decoded partway.
191
+
170
192
  ### The declarative shell vs. the imperative core
171
193
 
172
194
  `PROTOCOL_SCHEMA` is the schema with its closures stripped (via a `JSON.parse(JSON.stringify())`
@@ -207,7 +229,7 @@ constants, so a layer added from scratch re-opens as that layer.
207
229
 
208
230
  ## Built-in headers
209
231
 
210
- 189 protocol headers are registered by default; `raw` is the forced catch-all. Pass custom classes to `new Codec(customCodecs)` to override a built-in with the same id or add new ones.
232
+ 191 headers are registered by default: 189 protocols, `raw` (the forced catch-all) and `trailer` (bytes past a layer's own length). Pass custom classes to `new Codec(customCodecs)` to override a built-in with the same id or add new ones.
211
233
 
212
234
  | id | name |
213
235
  | ---------------- | --------------------------------------------------- |
@@ -324,6 +346,7 @@ constants, so a layer added from scratch re-opens as that layer.
324
346
  | `openflow` | OpenFlow |
325
347
  | `openvpn` | OpenVPN Protocol |
326
348
  | `ospf` | Open Shortest Path First |
349
+ | `ospfv3` | Open Shortest Path First version 3 |
327
350
  | `pcworx` | PCWorx |
328
351
  | `pgsql` | PostgreSQL Protocol |
329
352
  | `pim` | Protocol Independent Multicast |
@@ -389,6 +412,7 @@ constants, so a layer added from scratch re-opens as that layer.
389
412
  | `tls-handshake` | Transport Layer Security(Handshake Protocol) |
390
413
  | `tls-heartbeat` | Transport Layer Security(Heartbeat Protocol) |
391
414
  | `tpkt` | TPKT |
415
+ | `trailer` | Trailer |
392
416
  | `udp` | User Datagram Protocol |
393
417
  | `vlan` | 802.1Q Virtual LAN |
394
418
  | `vrrp` | Virtual Router Redundancy Protocol |
package/README.zh-CN.md CHANGED
@@ -58,9 +58,12 @@ rebuilt.equals(packet) // 对于结构完好的报文为 true —— 解码/
58
58
  ```
59
59
 
60
60
  想从零构造一个报文,只要按从外到内的顺序给 `encode` 传一组 `{id, data}` 输入即可;没填的字段会用
61
- schema 里的默认值补齐,表单传来的字符串也会被自动转换成对应类型。上一层用来区分下一层的字段如果没填
62
- (`eth`/`vlan`/`hsr`/`gre`/`geneve`/`snap` 的 EtherType、IPv4 的 `protocol`、IPv6 的 `nxt`),会按
63
- 后面那一层自动填写(eth 后面接 LLC 时填 IEEE 802.3 长度);显式填写的值总是原样写出:
61
+ schema 里的默认值补齐,表单传来的字符串也会被自动转换成对应类型。没填的长度、计数和校验和会自动计算;
62
+ 上一层用来区分下一层的字段如果没填(`eth`/`vlan`/`hsr`/`gre`/`geneve`/`snap` 的 EtherType、IPv4 的
63
+ `protocol`、IPv6 的 `nxt`),会按后面那一层自动填写(eth 后面接 LLC 时填 IEEE 802.3 长度)。显式填写的值
64
+ (包括 0)总是原样写出,所以可以有意构造错误的校验和或长度。想让某个字段自动计算,就不要传它:整数字段传
65
+ `null` 会被转换成 0 并照写,传 `''` 会校验失败;十六进制字段传 `''` 或 `null` 则等同于不填。`encode` 在
66
+ 副本上工作,不会修改传入的对象:
64
67
 
65
68
  ```ts
66
69
  const {packet} = await codec.encode([
@@ -122,9 +125,9 @@ type CodecErrorInfo = {
122
125
  - `readOnly: true`——encode 忽略该值,修改它永远不会改变编码字节(例如 HTTP `method`/`statusCode`、
123
126
  CMS `serviceDataDecoded` 这类从逐字节保留的字段解出、仅供展示的投影——真正的编码依据是那个逐字节
124
127
  字段;以及 encode 总是自行推导的值)。标在对象/数组上时覆盖其全部子孙字段。
125
- - `autoCalculated: true`——输入缺省该字段(或按该字段约定给 0)时,encode 会根据报文其余部分自动
126
- 计算(长度、校验和、计数、偏移等);显式给出的值仍按原样写入。例如 `ipv4.length`、`ipv4.checksum`、
127
- `tcp.hdrLen`。
128
+ - `autoCalculated: true`——输入缺省该字段时,encode 会自动计算(长度、校验和、计数、偏移,或按下一层
129
+ 推断的分发字段);给出的任何值(包括 0)都按原样写入。例如 `ipv4.length`、`ipv4.checksum`、
130
+ `tcp.hdrLen`、`ipv4.protocol`。
128
131
  - `byteAlignment: N`——encode 会用 0 把该字段补齐到 N 字节的整数倍,例如 `ipv4.options`(4)、
129
132
  `tcp.options`(4)。
130
133
 
@@ -158,6 +161,22 @@ try {
158
161
  递归,直到把报文消费完。`RawData` 是被强制放在最后的兜底项,且永远匹配成功,所以无法识别或畸形的尾部
159
162
  字节会直接变成一层 `raw`,解码绝不会走进死胡同。
160
163
 
164
+ ### 填充与尾部数据
165
+
166
+ IPv4(Total Length)、IPv6(Payload Length)、Ethernet / 802.1Q 的 802.3 长度以及 GOOSE / SV 的 Length
167
+ 会限定各自所承载载荷的范围,Ethernet/IPv4 的 ARP 报文在 28 字节处结束。超出这个范围的字节(补齐到 60 字节最小帧的以太网填充,或设备附加的尾部数据)不会交给上层,而是在层
168
+ 列表末尾单独成为一层 `trailer`(`{data: '<hex>'}`,`protocol: false`)。长度为 0、比实际抓到的字节还长、
169
+ 或者比自身头部还短时,不做限定。编码时 `trailer` 的字节在其他所有层、以及所有自动计算的长度和校验和之后
170
+ 才写入,所以不填的长度和校验和不会把它算进去;自己构造报文时追加 `{id: 'trailer', data: {data: '0000…'}}`
171
+ 即可补齐填充。
172
+
173
+ ### 保留抓包里的编码形式
174
+
175
+ 同一个值在协议里有多种字节写法时,解码会记下抓包实际用的那种,重新编码时照样写出。GOOSE 会把非最简的
176
+ BER 长度形式和 INTEGER 宽度记在隐藏的 `encoding` 节点里(`goosePdu` 和每个 `allData` 项上都有);编码时
177
+ 只要值还放得下就沿用,放不下就退回最简形式;不带这些节点的树按最简形式编码。BER 无法严格解析的 GOOSE / SV
178
+ PDU 整体保留为 `raw`(并记一条错误),不再解一半。
179
+
161
180
  ### 声明式外壳与命令式内核
162
181
 
163
182
  `PROTOCOL_SCHEMA` 是剥离了闭包之后的 schema(通过 `JSON.parse(JSON.stringify())` 往返——JSON 序列化
@@ -192,7 +211,7 @@ ISO-Session 后的 MMS、RTPS、BitTorrent)也会列出——协议头用 `heuri
192
211
 
193
212
  ## 内置协议头
194
213
 
195
- 默认注册了 189 个协议头(`raw` 是强制兜底)。向 `new Codec(customCodecs)` 传入自定义类可覆盖同 id 的内置头或新增协议头。
214
+ 默认注册了 191 个头:189 个协议,加上 `raw`(强制兜底)和 `trailer`(超出该层自身长度的字节)。向 `new Codec(customCodecs)` 传入自定义类可覆盖同 id 的内置头或新增协议头。
196
215
 
197
216
  | id | name |
198
217
  | ---------------- | --------------------------------------------------- |
@@ -309,6 +328,7 @@ ISO-Session 后的 MMS、RTPS、BitTorrent)也会列出——协议头用 `heuri
309
328
  | `openflow` | OpenFlow |
310
329
  | `openvpn` | OpenVPN Protocol |
311
330
  | `ospf` | Open Shortest Path First |
331
+ | `ospfv3` | Open Shortest Path First version 3 |
312
332
  | `pcworx` | PCWorx |
313
333
  | `pgsql` | PostgreSQL Protocol |
314
334
  | `pim` | Protocol Independent Multicast |
@@ -374,6 +394,7 @@ ISO-Session 后的 MMS、RTPS、BitTorrent)也会列出——协议头用 `heuri
374
394
  | `tls-handshake` | Transport Layer Security(Handshake Protocol) |
375
395
  | `tls-heartbeat` | Transport Layer Security(Heartbeat Protocol) |
376
396
  | `tpkt` | TPKT |
397
+ | `trailer` | Trailer |
377
398
  | `udp` | User Datagram Protocol |
378
399
  | `vlan` | 802.1Q Virtual LAN |
379
400
  | `vrrp` | Virtual Router Redundancy Protocol |
package/dist/Codec.d.ts CHANGED
@@ -90,7 +90,8 @@ export declare class Codec {
90
90
  * may follow `parentLayerId`, each tagged with the {field,value} to set on the parent so decode
91
91
  * would route to it. Derived by reversing the dispatch table over the parent's producer fields,
92
92
  * plus the content-heuristic children that declare this parent in `heuristicParents` (listed with a
93
- * null discriminator). RawData is always appended as the custom/fallback layer that may follow anything.
93
+ * null discriminator). RawData (the custom/fallback layer) and Trailer (padding written after every
94
+ * other layer) are always appended: either may follow anything.
94
95
  * @param parentLayerId
95
96
  */
96
97
  allowedNextLayers(parentLayerId: string): NextLayer[];
@@ -111,7 +112,7 @@ export declare class Codec {
111
112
  * actually follows (e.g. eth.etherType says IPv6 but the next layer is IPv4). This is advisory
112
113
  * only — encode never blocks on it, since a deliberately-inconsistent packet is a valid crafted
113
114
  * packet. Only demux-based relationships are checked; content-heuristic children (TLS/IEC104) are
114
- * not flagged. RawData may follow anything and is never flagged.
115
+ * not flagged. RawData and Trailer may follow anything and are never flagged.
115
116
  * @param decoded
116
117
  */
117
118
  checkConsistency(decoded: CodecDecodeResult[]): ConsistencyIssue[];
@@ -127,7 +128,7 @@ export declare class Codec {
127
128
  * One-line human summary of a decoded packet (Wireshark's Info column). The innermost layer that
128
129
  * declares a `summary` template in its schema wins (the most specific layer describes the packet);
129
130
  * the template's ${dotted.field} placeholders are filled from that layer's decoded data. Falls back
130
- * to the innermost non-raw layer's name when no template is declared. Read-only projection.
131
+ * to the innermost layer that is neither raw nor a trailer when no template is declared. Read-only projection.
131
132
  * @param decoded
132
133
  */
133
134
  summary(decoded: CodecDecodeResult[]): string;