Skip to content

Commit b2e92bd

Browse files
authored
docs(protocols): sixth whole-repo pass over internet (#1103) (#2208)
Correct the HOPOPT and IPv6-Opts padding arithmetic: a well-formed options area is 2 octets short of a multiple of 8, not 6, and the counterfactuals in make and _make_pad_options now match the floor division make uses. Drop the bug-report 'are affected' from the R1_COUNTER width comment.
1 parent a4c6711 commit b2e92bd

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎pcapkit/protocols/internet/hopopt.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ def make(self,
376376
# NOTE: No options is not the same as no options area. The header is at
377377
# least 8 octets, 2 of them the fixed part, so the remaining 6 must be
378378
# padding options. Passing the empty list through the same path produces
379-
# them; returning ``[], 0`` would declare an 8-octet header and emit 2.
379+
# them; returning ``[], 0`` would emit the 2 fixed octets alone, under a
380+
# ``Hdr Ext Len`` that ``(0 - 6) // 8`` makes ``-1``.
380381
options_value, total_length = self._make_hopopt_options(
381382
options if options is not None else [])
382383

@@ -1349,8 +1350,8 @@ def _make_pad_options(self, offset: 'int') -> 'tuple[list[Schema_PadOption], int
13491350
the alignment is computed from ``offset`` rather than from the
13501351
length of the option just emitted. Aligning each option to 8 octets
13511352
on its own leaves the options area a multiple of 8, whereas
1352-
:meth:`read` sizes it as ``hdr_ext_len * 8 + 6``, six short of a
1353-
multiple of 8; the header would declare 6 octets more than it
1353+
:meth:`read` sizes it as ``hdr_ext_len * 8 + 6``, two short of a
1354+
multiple of 8; the header would declare 2 octets fewer than it
13541355
carried.
13551356
13561357
A ``PadN`` option spends two octets on its own type and
@@ -1391,7 +1392,7 @@ def _make_hopopt_options(self, options: 'list[Schema_Option | tuple[Enum_Option,
13911392
The returned length is that of the options area alone, the value
13921393
:meth:`make` derives the ``Hdr Ext Len`` field from. Since the two
13931394
octets of the fixed header precede it, an options area is well
1394-
formed only when it is 6 octets short of a multiple of 8 --
1395+
formed only when it is 2 octets short of a multiple of 8 --
13951396
including when it holds no real options at all, in which case it is
13961397
6 octets of pure padding rather than empty.
13971398

‎pcapkit/protocols/internet/ipv6_opts.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ def make(self,
368368
# NOTE: No options is not the same as no options area. The header is at
369369
# least 8 octets, 2 of them the fixed part, so the remaining 6 must be
370370
# padding options. Passing the empty list through the same path produces
371-
# them; returning ``[], 0`` would declare an 8-octet header and emit 2.
371+
# them; returning ``[], 0`` would emit the 2 fixed octets alone, under a
372+
# ``Hdr Ext Len`` that ``(0 - 6) // 8`` makes ``-1``.
372373
options_value, total_length = self._make_ipv6_opts(
373374
options if options is not None else [])
374375

@@ -1338,8 +1339,8 @@ def _make_pad_options(self, offset: 'int') -> 'tuple[list[Schema_PadOption], int
13381339
length of the option that has just been emitted. Aligning each
13391340
option to 8 octets on its own leaves the options area a multiple of
13401341
8 octets long, whereas :meth:`read` sizes it as
1341-
``hdr_ext_len * 8 + 6`` -- six short of a multiple of 8 -- so the
1342-
header would declare 6 octets more than it carried.
1342+
``hdr_ext_len * 8 + 6`` -- two short of a multiple of 8 -- so the
1343+
header would declare 2 octets fewer than it carried.
13431344
13441345
A ``PadN`` option spends two octets on its own type and
13451346
``Opt Data Len`` fields before any padding data, so occupying
@@ -1379,7 +1380,7 @@ def _make_ipv6_opts(self, options: 'list[Schema_Option | tuple[Enum_Option, dict
13791380
The returned length is that of the options area alone, the value
13801381
:meth:`make` derives the ``Hdr Ext Len`` field from. Since the two
13811382
octets of the fixed header precede it, an options area is well
1382-
formed only when it is 6 octets short of a multiple of 8 --
1383+
formed only when it is 2 octets short of a multiple of 8 --
13831384
including when it holds no real options at all, in which case it is
13841385
6 octets of pure padding rather than empty.
13851386

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ class R1CounterParameter(Parameter, code=[Enum_Parameter.R1_Counter,
591591
#: order", so the width is stated twice and inferred from neither.
592592
#: :rfc:`5201#section-5.2.3` gives the same 4 + 8 layout, so there is no
593593
#: version under which four octets is right, and both codes that reach this
594-
#: class -- ``R1_Counter`` (128, HIPv1) and ``R1_COUNTER`` (129) -- are
595-
#: affected. With the four ``reserved`` octets the contents are 12 octets,
594+
#: class -- ``R1_Counter`` (128, HIPv1) and ``R1_COUNTER`` (129) -- take
595+
#: the eight. With the four ``reserved`` octets the contents are 12 octets,
596596
#: which :rfc:`7401` Section 5.2.1's arithmetic pads to a 16-octet record.
597597
counter: 'int' = UInt64Field()
598598
#: Padding.

0 commit comments

Comments
 (0)