Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pcapkit/protocols/internet/ipv4.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,8 @@ def _read_opt_sec(self, schema: 'Schema_SECOption', *, options: 'Option') -> 'Da
warn(f'{self.alias}: [OptNo {schema.type}] invalid format: remaining data', ProtocolWarning)

if schema.data[-1] & 0x01 == 1:
warn(f'{self.alias}: [OptNo {schema.type}] invalid format: field termination indicator not set', ProtocolWarning)
warn(f'{self.alias}: [OptNo {schema.type}] invalid format: '
f'field termination indicator set on the final octet: {schema.data[-1]!r}', ProtocolWarning)
termination = tuple(bool(byte & 0x01) for byte in schema.data)
else:
flags = []
Expand Down
8 changes: 6 additions & 2 deletions tests/protocols/internet/test_ipv4_roundtrip_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ def test_sec_termination_indicator_follows_rfc_1108(self) -> None:
option = self.parse(header('8204ab90')).info.options[OptionNumber.SEC]
self.assertEqual(option.flags, (ProtectionAuthority.GENSER, ProtectionAuthority.NSA))

# The low-order bit set on the final octet promises another octet.
with self.assertWarnsRegex(ProtocolWarning, 'field termination indicator not set'):
# The low-order bit set on the final octet promises another octet, and
# the warning names the bit that is set rather than one that is not
# (#2295). ``0x91`` is 145.
with self.assertWarns(ProtocolWarning) as caught:
self.parse(header('8204ab91'))
self.assertEqual(str(caught.warning), 'IPv4: [OptNo 130] invalid format: '
'field termination indicator set on the final octet: 145')

def test_timestamp_keeps_the_high_order_bit(self) -> None:
from pcapkit.const.ipv4.option_number import OptionNumber
Expand Down
6 changes: 3 additions & 3 deletions tests/protocols/internet/test_ipv4_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ def test_ipv4_make_opt_sec_sets_the_field_termination_indicator(self) -> None:
:rfc:`1108` section 2.4(a) makes the low-order bit of each protection
authority octet a *field termination indicator*: ``1`` means another
octet follows, ``0`` means this is the last. ``_read_opt_sec`` enforces
it, warning ``field termination indicator not set`` when the final octet
has it set. The writer and the reader agree with each other (#537) and
with the RFC (#1321).
it, warning ``field termination indicator set on the final octet`` when
the final octet has it set. The writer and the reader agree with each
other (#537) and with the RFC (#1321).

The round trip is asserted through a real datagram and with warnings
promoted to errors, because a disagreement's only symptom is a warning.
Expand Down
Loading