Skip to content

fix(l2tpv2): correct the Type enum and L bit against RFC 2661 (#1175) - #1183

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1175-l2tp-type-enum
Oct 7, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1175-l2tp-type-enum

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner
  • Searched for similar pull requests
  • Followed the coding style (pylint/mypy/isort run on the touched pcapkit/ files with the Makefile flags; no new findings)
  • make test passes, and a test case covers the change (per-module only, see below; not the full suite)
  • Added a changelog entry under docs/source/changelog/ and regenerated CHANGELOG.md, if the change is user-visible — N/A, added centrally

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

Closes #1175. Breaking: public Enum_Type values swap to Data = 0, Control = 1 (RFC 2661 §3.1). The const is regenerated from the fixed vendor table.

  • make() sets L on a control message and defaults total_length to header + payload. A new length_flag keyword, which _make_data fills in, keeps a control message captured without L byte-exact. A total_length the caller passes is written as given (documented, not checked), like UDP after design(protocols): should from_data keep declared lengths on truncated captures? #1155, so a rebuild of a snaplen-truncated capture keeps the declared length.
  • The offset pad is recorded as info.padding and goes back through make().
probe before after
int(Type.Data), int(Type.Control) 1 0 0 1
L2TPv2(tunnel_id=1, session_id=2) 800200010002 (T=1) 000200010002
make(type=Control, ns=0, nr=1, …) 0802… (L=0) c802000c…
pad rebuild …0003010203ff03 …0003000000ff03 byte-exact

Tests: new tests/protocols/link/test_l2tpv2_type_unit.py passes 8. With the source fix reverted, 6 fail. The 2 guards were proved by mutation: dropping length_flag from _make_data fails the guard and 6 cases in test_l2tpv2_length_roundtrip_unit. test_link_unit 24 passed, after one fixture edit giving its dummy flags len=True. tests/project 389 passed, 1 skipped. run_unittest_leg.py protocols --exclude protocols/internet reports 850 tests, 0 failures.

- vendor/l2tp/type.py: Data = 0, Control = 1, per RFC 2661 §3.1; the
  const is regenerated from it. BREAKING: Enum_Type values swap.
- L2TPv2.make(): a control message sets L and defaults total_length to
  the real header-plus-payload length; a new length_flag keyword, fed by
  _make_data, keeps a captured control message without L byte-exact.
  An explicit total_length is written as given, as UDP does (#1155).
- The offset pad is recorded as info.padding and passed back to make(),
  so from_data no longer zeroes it.

Closes #1175
@JarryShaw JarryShaw added breaking Breaks public-facing behaviour or API (apply alongside the type label) const Regenerated IANA or vendor constant tables; members keep their numeric values fix Pull requests that fix a defect (fix: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 7, 2026
@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 7, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review verdict on 53f2d0fc1: GOOD TO GO (ran on Sonnet; author Opus). Labelled review: good-to-go. Two design points are held for the maintainer on #1175; neither blocks the merge.

  • Enum: RFC 2661 §3.1 confirms Data=0 and Control=1. The vendor generator, re-run, produces a const file byte-identical to the committed one. Nothing else in the codebase uses the numeric values.

  • Round trips: byte-exact for:

    • ZLB;
    • control messages with and without S/L;
    • offset pads, which main zero-fills;
    • data messages with sequence numbers;
    • an over-declared length.

    The capture sweep is vacuous because no fixture holds L2TP, so this evidence is synthetic.

  • Tests: 6 of the 8 new tests fail without the fix. The ordering leg protocols (rest) ran 850 tests with 0 failures and 0 errors. The test_link_unit change is a legitimate fixture fix: the dummy lacked flags.len.

  • breaking: the label is correct, and the breakage is wider than the PR body lists:

    • parsed flags.type flips for the same bytes;
    • the default make() emits T=0;
    • a control message without total_length gains L and a Length field;
    • info and dumpkit output gain a padding key;
    • make() gains length_flag and padding.

    The changelog entry will carry all of these.

  • Out of scope: §3.1 also requires S=1 on control messages, and make() does not enforce it.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Coverage: 88.89% (unit tier, Python 3.14, 53f2d0fc1, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18757 1034 2342 845 90.24%
pcapkit/corekit 1878 91 580 22 94.34%
pcapkit/dumpkit 142 0 42 0 100.00%
pcapkit/foundation 2442 102 852 39 94.38%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 15714 188 3980 163 98.19%
pcapkit/toolkit 487 65 144 1 85.42%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2359 1006 158 42.84%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit 8047380 into main Oct 7, 2026
43 checks passed
@JarryShaw
JarryShaw deleted the fix/1175-l2tp-type-enum branch October 7, 2026 13:58
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 7, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaks public-facing behaviour or API (apply alongside the type label) const Regenerated IANA or vendor constant tables; members keep their numeric values fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(l2tp): the Type enum is inverted against RFC 2661, and make() omits L on control messages

1 participant