Skip to content

fix(ipv6-opts): rebuild every MPL seed-id kind from its parsed value (#1185) - #1187

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1185-mpl-seed-rebuild
Oct 7, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1185-mpl-seed-rebuild

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Please follow the guide below

  • Searched for similar pull requests
  • Followed the coding style (make pylint, make mypy, make isort) — ran pylint/mypy/isort with the Makefile flags on the changed files only; no new findings
  • make test passes, and a test case covers the change — the modules listed below only, not the full suite
  • Added a changelog entry — N/A, added centrally

What is the purpose of your pull request?

Tick the commit type your subject line carries.

  • fix — corrects a defect
  • feat — adds a feature
  • perf — changes performance, not behaviour
  • refactor — changes neither behaviour nor performance
  • test — tests only
  • docs — documentation only
  • ci — workflows or build tooling
  • release — bumps the version or rolls up a distribution
  • chore — anything else

Description of your pull request and other information

Closes #1185. _make_opt_mpl (HOPOPT and IPv6_Opts) now takes S from the parsed seed_type (or a new seed_type keyword), and infers it only when neither is given. For S=0 the seed is the IPv6 source address and is not written. Before, inferring from bit_length() raised on that IPv6Address, and a 64/128-bit seed with a small value was rebuilt as S=1. A missing or oversized seed raises ProtocolError. The MPLOption.seed_id annotation now includes IPv6Address.

Probe (from_data on every HOPOPT/IPv6_Opts layer in examples/captures/*): before, 2 of 28 raise AttributeError (options-ipv6.pcap frames 9 (HOPOPT) and 23 (IPv6_Opts) by info.number, in a capture regenerated from this PR's base 20438e3ec). After, 0 of 28 raise, and both frames rebuild byte-exactly.

Tests: new tests/protocols/internet/test_mpl_seed_rebuild_unit.py covers S=0–3 byte-exact rebuild, S=0 inside IPv6 and the rejection cases. Without the fix: 12 failed, 4 passed (16 subtests in total). With the fix: 4 passed, 18 subtests passed. test_option_roundtrip_unit 6 passed (no MPL EXPECTED_FAILURES entries), test_ipv6_ext_unit 30 passed, test_ipv6_extension_runtime 3 passed, test_option_coverage_runtime 3 passed, test_declared_length_roundtrip_runtime 6 passed, tests/project 389 passed / 1 skipped. util/run_unittest_leg.py protocols/internet: 476 tests, 0 failures, 0 errors.

@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 7, 2026
@JarryShaw JarryShaw added 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
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Coverage: 88.89% (unit tier, Python 3.14, e828f35ac, 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 15731 190 3998 165 98.17%
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

Copy link
Copy Markdown
Owner Author

Cross-review verdict on 4fc32b635: NEEDS CHANGES (ran on Sonnet; author Opus). One wrong citation; the code is good. Labelled review: needs-changes.

  • Change needed: the new test's module docstring cites :rfc:7731#section-2.1``. The S field is defined in RFC 7731 §6.1 (MPL Option). I confirmed this against the RFC text.
  • Confirmed:
    • Seed types per S: None or IPv6Address for S=0, int for S=1–3.
    • Every S rebuilds byte-exactly, standalone and inside IPv6, for both classes, including small S=2/3 seeds.
    • seed_type follows the module's *_default/_namespace/_reversed pattern, and out-of-range values raise ProtocolError.
    • The HOPOPT and IPv6_Opts copies behave identically.
    • Without the fix, 12 tests fail.
    • The protocols/internet leg runs 476 tests, 0F/0E.
  • Captures: both MPL frames in options-ipv6.pcap now rebuild as 11006d0200000000. Their numbers depend on the indexing: 8 and 21 by info.number, against the body's New distribution [0.13.1] #9/Fixed minor bugs in Makefile #23. The 28-layer total across all captures was not re-run.
  • Out of scope: _make_opt_smf_dpd rebuilds H-DPD as I-DPD. Filed as fix(ipv6-opts): _make_opt_smf_dpd overwrites the parsed DPD mode, so H-DPD rebuilds as I-DPD #1190, blocked on this PR.
  • Nit: seed_type=1 with an IPv6Address seed raises with a misleading "too large" message.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 7, 2026
…1185)

_make_opt_mpl inferred the S field from seed.bit_length(). With S=0 the
reader stores the IPv6 source address as the seed, so rebuilding raised
AttributeError; and a 64- or 128-bit seed with a small value was rebuilt
with a narrower S, changing the octets.

- take S from the parsed seed_type, or a new seed_type keyword, and infer
  it only when neither is given (an IPv6Address seed means S=0)
- reject a missing seed or one wider than its S allows with ProtocolError
- widen the MPLOption.seed_id annotation to include IPv6Address
- same change in HOPOPT and IPv6_Opts

Adds tests/protocols/internet/test_mpl_seed_rebuild_unit.py.
@JarryShaw
JarryShaw force-pushed the fix/1185-mpl-seed-rebuild branch from 4fc32b6 to e828f35 Compare October 7, 2026 05:21
@JarryShaw JarryShaw added review: running A cross-review is in flight against the current head - no verdict yet and removed review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Oct 7, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review verdict on e828f35ac: GOOD TO GO (ran on Sonnet; author Opus). Labelled review: good-to-go.

  • Interdiff from 4fc32b635: exactly the requested one-line fix. The test docstring now cites 7731#section-6.1. I re-ran git diff 4fc32b635 e828f35ac myself.
  • Tests: the new test module passes on the new head.
  • Frame numbers: the PR body's info.number 9 (HOPOPT) and 23 (IPv6_Opts) are correct. The reviewer's earlier 8/21 came from a stale copied capture; the regenerated one has 28 HOPOPT/IPv6_Opts layers, none raising, and both MPL layers rebuild as 11006d0200000000.
  • Unchanged from round 1: every other check carries over, since the source files are identical.

@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
JarryShaw merged commit 5fd2f22 into main Oct 7, 2026
40 checks passed
@JarryShaw
JarryShaw deleted the fix/1185-mpl-seed-rebuild branch October 7, 2026 13:59
@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

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(ipv6-opts): _make_opt_mpl calls bit_length() on an IPv6Address seed

1 participant