Skip to content

fix(esp): the extension= keyword is accepted, stored and never read #895

Description

@JarryShaw

Describe the bug

ESP accepts an extension= keyword, stores it, and then never reads it. Extension mode is dead code for that one protocol.

pcapkit/protocols/internet/esp.py:1276 assigns self._extf = extension, and no line anywhere in the file reads self._extf. Contrast pcapkit/protocols/internet/ah.py, its sibling under IPsec, which reads it three times (:75, :87, :99) to guard name, protochain and payload, and assigns it at :233.

Counted across the eight implemented IPv6 extension headers:

                _extf   UnsupportedCall   if extension: return
HOPOPT            4            7                   1
IPv6_Route        4            7                   1
IPv6_Opts         4            7                   1
IPv6_Frag         4            7                   1
MH                4            7                   1
HIP               4            7                   1
AH                4            7                   1
ESP               1            0                   0

ESP is the only outlier on all three markers: it has no UnsupportedCall guard properties and no if extension: return short-circuit in read.

Reproduction

Not run against a capture — read from source at origin/main. ESP.read declares extension: 'bool' = False at :996-997 and __post_init__ at :1259-1260, so ESP(..., extension=True) is accepted; :1276 records it; nothing consumes it. The parse therefore behaves identically whether extension is True or False.

Expected behavior

One of two things, and which is a design decision rather than a mechanical fix:

  • ESP should support extension mode — then it needs the three UnsupportedCall guard properties and the if extension: return short-circuit its seven siblings have, and _extf becomes load-bearing.
  • ESP should not — then extension= should be removed from read and __post_init__ rather than accepted and silently discarded, and :1276 deleted.

Accepting a keyword that changes nothing is the worst of the three, because a caller cannot tell it had no effect.

System information

Source-only; no library version involved. Read at origin/main.

Additional context

Found while measuring the IPv6_Ext shared-base proposal on #891, where it decides whether ESP joins that base. Noted there in #891 so the refactor is not silently made to carry this fix: giving ESP the base would supply the missing guards as a side effect, turning a behaviour-preserving refactor into a behaviour change. This issue exists so that question gets answered on its own merits.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfixPull requests that fix a defect (fix: subject prefix)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions