Skip to content

Commit 2d8c8b5

Browse files
authored
docs(internet): seventh whole-repo pass over the internet protocols (#1103) (#2259)
Full read of every internet module, data model, schema and API page. - MH: _mh_option_length names every exception; HAck codes include 131/132. - HIP: Parameter.length, ESP_INFO reserved attribution, PUZZLE per RFC 5201 too, LOCATOR_SET padding, CERT cites RFC 8002, FROM/RELAY_* meanings. - HOPOPT/IPv6-Opts: SMF_DPD cites RFC 6621 section 6.1.1; CALIPSO and SMF units; MPL names RFC 7731; Raises/Warns sections. - IPv4/ESP: TFC padding is RFC 4303 section 2.7; Raises sections; units. - IPv6_Ext/IPv6_Route: Next Header placement per RFC 8200 section 4 (ESP's trailer); guard, alias and keyword-allowlist notes; Raises sections. - esp.rst and ipv6_ext.rst follow the corrected docstrings.
1 parent 6ceed63 commit 2d8c8b5

23 files changed

Lines changed: 188 additions & 111 deletions

File tree

‎docs/source/pcapkit/protocols/internet/esp.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ Known Limitations
256256
stateless parser cannot recover them; they are required both for the ICV
257257
computation and for the AEAD associated data. An ESN protected packet
258258
therefore fails the integrity check *cleanly* rather than being decoded.
259-
* **Traffic Flow Confidentiality (TFC) padding (§2.4) is not detected.**
259+
* **Traffic Flow Confidentiality (TFC) padding (§2.7) is not detected.**
260260
TFC padding is indistinguishable from real payload without inspecting the
261261
inner protocol's own length field, so it is handed to the next layer as
262262
part of the plaintext.

‎docs/source/pcapkit/protocols/internet/ipv6_ext.rst‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ IPv6-Ext - IPv6 Extension Header
88
only, which plays a double role. It is the shared **base class** of every
99
IPv6 extension header this package implements, supplying the
1010
``extension``-mode contract: the guards that make
11-
:attr:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext.payload`,
12-
:attr:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext.protocol` and
11+
:attr:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext.payload` and
1312
:attr:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext.protochain`
14-
unavailable on a header parsed as part of an IPv6 chain. It also implements a
13+
unavailable on a header parsed as part of an IPv6 chain. Each subclass guards
14+
its own ``protocol`` the same way; this class's
15+
:attr:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext.protocol` deliberately
16+
does not. It also implements a
1517
**generic** extractor for IPv6 extension headers [*]_, standing in whenever a
1618
header's own dedicated parser is unavailable or has failed. :rfc:`6564#section-4`
1719
requires, with an RFC 2119 **MUST**, that any IPv6 extension header defined since
@@ -157,20 +159,23 @@ left, then read only what is left. See
157159
:func:`pcapkit.protocols.schema.misc.pcapng.bounded_area` and
158160
:meth:`pcapkit.protocols.misc.pcapng.PCAPNG.read`.
159161

160-
This class follows that convention's *warning*
161-
(:class:`~pcapkit.utilities.warnings.SchemaWarning`) and deliberately diverges
162-
on the *action*. Clipping is right when the declared length only governs how
163-
much of the current object to read, since there is always a well-defined
164-
"what is left" to fall back to. Here the declared length also decides *where
165-
the next header starts*; a clipped skip distance points at whatever bytes
166-
end the buffer, which are not a header. Continuing from there would
167-
fabricate a layer and record a false entry in
162+
This class follows that convention's *warning* -- a
163+
:class:`~pcapkit.utilities.warnings.SchemaWarning`, as
164+
:func:`~pcapkit.protocols.schema.misc.pcapng.bounded_area` emits -- and
165+
deliberately diverges on the *action*. Clipping is right when the declared
166+
length only governs how much of the current object to read, since there is
167+
always a well-defined "what is left" to fall back to. Here the declared length
168+
also decides *where the next header starts*; a clipped skip distance points at
169+
whatever bytes end the buffer, which are not a header. Continuing from there
170+
would fabricate a layer and record a false entry in
168171
:class:`~pcapkit.corekit.protochain.ProtoChain`, which reads as a parsed fact
169-
rather than a guess. So :meth:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext.read` warns in the same
170-
wording as the sites above, then **stops the walk**: this instance absorbs
171-
every remaining octet and reports :data:`None` for ``next``, which the
172-
caller's loop already reads as "no more extension headers". The chain ends
173-
honestly at the bad header instead of inventing what follows it.
172+
rather than a guess. So :meth:`~pcapkit.protocols.internet.ipv6_ext.IPv6_Ext.read`
173+
warns in the same form as
174+
:func:`~pcapkit.protocols.schema.misc.pcapng.bounded_area`, then **stops the
175+
walk**: this instance absorbs every remaining octet and reports :data:`None`
176+
for ``next``, which the caller's loop already reads as "no more extension
177+
headers". The chain ends honestly at the bad header instead of inventing what
178+
follows it.
174179

175180
Header Schemas
176181
--------------

‎pcapkit/protocols/data/internet/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
# IPv6 Fragment Header
134134
from pcapkit.protocols.data.internet.ipv6_frag import IPv6_Frag
135135

136-
# IPv6 Extension Header (base + generic fallback)
136+
# IPv6 Extension Header (generic fallback)
137137
from pcapkit.protocols.data.internet.ipv6_ext import IPv6_Ext
138138

139139
# IPv6 Destination Options
@@ -424,7 +424,7 @@
424424
# IPv6 Fragment Header
425425
'IPv6_Frag',
426426

427-
# IPv6 Extension Header (base + generic fallback)
427+
# IPv6 Extension Header (generic fallback)
428428
'IPv6_Ext',
429429

430430
# IPv6 Destination Options Header

‎pcapkit/protocols/data/internet/esp.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ class ESP(Protocol):
4343
#: byte of the packet that ESP owns.
4444
length: 'int'
4545
#: Payload data exactly as transmitted -- ciphertext, prefixed by any
46-
#: cryptographic synchronisation data (IV) -- excluding the ICV.
46+
#: cryptographic synchronisation data (IV) -- excluding the ICV whenever
47+
#: :attr:`icv` holds it.
4748
payload_data: 'bytes'
48-
#: Integrity check value as transmitted; empty when absent, or when no
49-
#: Security Association was available to say how long it is.
49+
#: Integrity check value as transmitted; empty when absent, when no
50+
#: Security Association was available to say how long it is, or when the
51+
#: packet is shorter than the ICV its Security Association declares.
5052
icv: 'bytes'
5153
#: Outcome of the decryption and integrity check.
5254
status: 'ESPStatus'

‎pcapkit/protocols/data/internet/hip.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class Parameter(Data):
8787
type: 'Enum_Parameter'
8888
#: Critical flag.
8989
critical: 'bool'
90-
#: Content length.
90+
#: Parameter length, in octets -- the whole record, including ``Type``,
91+
#: ``Length`` and ``Padding`` (:rfc:`7401#section-5.2.1`).
9192
length: 'int'
9293

9394
if TYPE_CHECKING:
@@ -130,7 +131,7 @@ class HIP(Protocol):
130131
version_fixed: 'int'
131132
#: Checksum.
132133
chksum: 'bytes'
133-
#: Control
134+
#: Control.
134135
control: 'Control'
135136
#: Sender's host identity tag.
136137
shit: 'int'
@@ -416,7 +417,7 @@ class NATTraversalModeParameter(Parameter):
416417

417418
#: The two reserved octets, as captured.
418419
reserved: 'bytes'
419-
#: Mode IDs
420+
#: Mode IDs.
420421
mode_id: 'tuple[NATTraversal, ...]'
421422

422423
if TYPE_CHECKING:
@@ -718,7 +719,7 @@ class PayloadMICParameter(Parameter):
718719

719720
#: The three reserved octets, as captured.
720721
reserved: 'bytes'
721-
#: Next header
722+
#: Next header.
722723
next: 'TransType'
723724
#: Payload data.
724725
payload: 'bytes'

‎pcapkit/protocols/data/internet/hopopt.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class CALIPSOOption(Option):
137137

138138
#: CALIPSO domain of interpretation.
139139
domain: 'int'
140-
#: Compartment length.
140+
#: Compartment bitmap length, in octets: four times the ``Cmpt Length``
141+
#: field, which counts 32-bit words.
141142
cmpt_len: 'int'
142143
#: Sensitivity level.
143144
level: 'int'
@@ -166,7 +167,8 @@ class SMFIdentificationBasedDPDOption(SMFDPDOption):
166167

167168
#: TaggerID type.
168169
tid_type: 'TaggerID'
169-
#: TaggerID length.
170+
#: ``TidLen`` field as on the wire: the TaggerID length in octets minus
171+
#: one, or ``0`` when there is no TaggerID [:rfc:`6621#section-6.1.1`].
170172
tid_len: 'int'
171173
#: TaggerID.
172174
tid: 'Optional[bytes | IPv4Address | IPv6Address]'

‎pcapkit/protocols/data/internet/ipv4.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class IPv4(Protocol):
112112

113113
#: Version.
114114
version: 'Literal[4]'
115-
#: Internet header length.
115+
#: Internet header length, in octets.
116116
hdr_len: 'int'
117117
#: Type of service.
118118
tos: 'ToSField'
@@ -122,7 +122,7 @@ class IPv4(Protocol):
122122
id: 'int'
123123
#: Flags.
124124
flags: 'Flags'
125-
#: Fragment offset.
125+
#: Fragment offset, in octets.
126126
offset: 'int'
127127
#: Time to live.
128128
ttl: 'timedelta'
@@ -150,7 +150,7 @@ def __init__(self, version: 'Literal[4]', hdr_len: 'int', tos: 'ToSField', len:
150150
class OptionType(Data):
151151
"""Data model for IPv4 option type data."""
152152

153-
#: Change flag.
153+
#: Copied flag, i.e. whether the option is copied into every fragment.
154154
change: 'bool'
155155
#: Option class.
156156
#class: 'int'

‎pcapkit/protocols/data/internet/ipv6_opts.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ class CALIPSOOption(Option):
142142

143143
#: CALIPSO domain of interpretation.
144144
domain: 'int'
145-
#: Compartment length.
145+
#: Compartment bitmap length, in octets: four times the ``Cmpt Length``
146+
#: field, which counts 32-bit words.
146147
cmpt_len: 'int'
147148
#: Sensitivity level.
148149
level: 'int'
@@ -172,7 +173,8 @@ class SMFIdentificationBasedDPDOption(SMFDPDOption):
172173

173174
#: TaggerID type.
174175
tid_type: 'TaggerID'
175-
#: TaggerID length.
176+
#: ``TidLen`` field as on the wire: the TaggerID length in octets minus
177+
#: one, or ``0`` when there is no TaggerID [:rfc:`6621#section-6.1.1`].
176178
tid_len: 'int'
177179
#: TaggerID.
178180
tid: 'Optional[bytes | IPv4Address | IPv6Address]'

‎pcapkit/protocols/internet/esp.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
stateless parser cannot recover them; they are required both for the ICV
147147
computation and for the AEAD associated data. An ESN protected packet
148148
therefore fails the integrity check *cleanly* rather than being decoded.
149-
* **Traffic Flow Confidentiality (TFC) padding (§2.4) is not detected.**
149+
* **Traffic Flow Confidentiality (TFC) padding (§2.7) is not detected.**
150150
TFC padding is indistinguishable from real payload without inspecting the
151151
inner protocol's own length field, so it is handed to the next layer as
152152
part of the plaintext.
@@ -1251,8 +1251,11 @@ def make(self,
12511251
12521252
Raises:
12531253
ProtocolError: If ``encrypt`` is :data:`True` and no Security
1254-
Association is available for ``spi``, or if ``pad_len`` does
1255-
not satisfy the algorithm's alignment requirement.
1254+
Association is available for ``spi``, if ``pad_len`` is
1255+
outside ``0`` to ``255`` or does not satisfy the algorithm's
1256+
alignment requirement, or if
1257+
:meth:`SecurityAssociation.encrypt` rejects ``iv`` or cannot
1258+
run without |cryptography|_.
12561259
12571260
"""
12581261
if not encrypt:

‎pcapkit/protocols/internet/hip.py‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ def _read_param_cert(self, schema: 'Schema_CertParameter', *, version: 'int', #
17581758
options: 'Parameter') -> 'Data_CertParameter': # pylint: disable=unused-argument
17591759
"""Read HIP ``CERT`` parameter.
17601760
1761-
Structure of HIP ``CERT`` parameter [:rfc:`7401`]:
1761+
Structure of HIP ``CERT`` parameter [:rfc:`8002`]:
17621762
17631763
.. code-block:: text
17641764
@@ -3028,7 +3028,7 @@ def _read_param_relay_hmac(self, schema: 'Schema_RelayHMACParameter', version: '
30283028
30293029
Structure of HIP ``RELAY_HMAC`` parameter [:rfc:`5770`]:
30303030
3031-
.. code-block::
3031+
.. code-block:: text
30323032
30333033
0 1 2 3
30343034
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -3162,7 +3162,7 @@ def _make_param_esp_info(self, code: 'Enum_Parameter', param: 'Optional[Data_ESP
31623162
code: parameter code
31633163
param: parameter data
31643164
version: HIP protocol version
3165-
reserved: reserved octets, zero when sent (:rfc:`7402#section-5.1.1`)
3165+
reserved: reserved octets (:rfc:`7402#section-5.1.1`)
31663166
index: KEYMAT index
31673167
old_spi: old SPI
31683168
new_spi: new SPI
@@ -3355,8 +3355,9 @@ def _make_puzzle_lifetime(code: 'Enum_Parameter', version: 'int',
33553355
"""Encode a ``PUZZLE`` ``Lifetime`` octet.
33563356
33573357
:rfc:`7401#section-5.2.4` gives the puzzle lifetime as ``2^(value - 32)``
3358-
seconds -- and it is the *only* place either RFC defines that encoding, so
3359-
it applies to ``PUZZLE`` alone. ``SOLUTION``'s octet at the same offset is
3358+
seconds -- and the ``PUZZLE`` section is the only place either RFC defines
3359+
that encoding (:rfc:`5201#section-5.2.4` identically), so it applies to
3360+
``PUZZLE`` alone. ``SOLUTION``'s octet at the same offset is
33603361
``Reserved`` (:rfc:`7401#section-5.2.5`) and does not come through here.
33613362
33623363
Args:
@@ -4022,6 +4023,12 @@ def _make_param_host_id(self, code: 'Enum_Parameter', param: 'Optional[Data_Host
40224023
Returns:
40234024
HIP parameter schema.
40244025
4026+
Raises:
4027+
ProtocolError: If neither ``hi`` nor ``param`` is given and
4028+
``hi_curve`` is not an ECDSA, ECDSA_LOW or EdDSA curve, or if
4029+
``hi`` is a :class:`~pcapkit.protocols.data.internet.hip.HostIdentity`
4030+
whose ``curve`` is none of those.
4031+
40254032
"""
40264033
if param is not None:
40274034
hi = param.hi
@@ -5082,7 +5089,8 @@ def _make_param_relay_from(self, code: 'Enum_Parameter', param: 'Optional[Data_R
50825089
protocol_default: default transport protocol
50835090
protocol_namespace: transport protocol namespace
50845091
protocol_reversed: reverse transport protocol namespace
5085-
address: relay address
5092+
address: the address the relay server received the relayed
5093+
packet from (:rfc:`5770`)
50865094
reserved: the reserved octet, truncated or
50875095
zero-filled to 1 octet
50885096
**kwargs: arbitrary keyword arguments
@@ -5130,7 +5138,8 @@ def _make_param_relay_to(self, code: 'Enum_Parameter', param: 'Optional[Data_Rel
51305138
protocol_default: default transport protocol
51315139
protocol_namespace: transport protocol namespace
51325140
protocol_reversed: reverse transport protocol namespace
5133-
address: relay address
5141+
address: the address the relay server forwards the packet to
5142+
(:rfc:`5770`)
51345143
reserved: the reserved octet, truncated or
51355144
zero-filled to 1 octet
51365145
**kwargs: arbitrary keyword arguments
@@ -5247,7 +5256,8 @@ def _make_param_from(self, code: 'Enum_Parameter', param: 'Optional[Data_FromPar
52475256
code: parameter code
52485257
param: parameter data
52495258
version: HIP protocol version
5250-
address: relay address
5259+
address: the original source address of the relayed packet
5260+
(:rfc:`8004`)
52515261
**kwargs: arbitrary keyword arguments
52525262
52535263
Returns:

0 commit comments

Comments
 (0)