Skip to content

fix(application)!: read OSPFv3 with its own 16-octet header (#3105) - #3107

Merged
JarryShaw merged 1 commit into
mainfrom
fix/3105-ospfv3-header
Nov 27, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/3105-ospfv3-header

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Please follow the guide below

  • Put an x into every box [ ] that applies to your pull request (like this: [x])

  • Use the Preview tab to see how your pull request will look

  • Searched for similar pull requests

  • Followed the coding style (make pylint, make mypy, make isort)

  • make test passes, and a test case covers the change

  • Described the user-visible change below and left its changelog entry to the maintainer, keeping docs/source/changelog/ and CHANGELOG.md out of the diff, if the change is user-visible: N/A — centralised

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

  • Also tick if it regenerates constant or registry tables, members keeping their numeric values (the const label)


Description of your pull request and other information

Closes #3105. Merge only after the 1.8.0 release finishes: Create Release is running on main, and a push mid-chain breaks it.

flowchart TD
    IP["IPv4 / IPv6, protocol 89"] --> OSPF["OSPF (abstract base)"]
    OSPF -->|"Version 1"| V1["OSPFv1, RFC 1131: 24 octets"]
    OSPF -->|"Version 2"| V2["OSPFv2, RFC 2328: 24 octets"]
    OSPF -->|"Version 3"| V3["OSPFv3, RFC 5340: 16 octets"]
    OSPF -->|"any other"| RAW["Raw behind IP; ProtocolError parsed directly"]
Loading
  • OSPF(octets), OSPF.from_fields(version=…) and OSPF.from_data give the member, as L2TP and IGMP do (refactor(protocols): every versioned family base dispatches on read and make (IGMP, IP, ICMP, L2TP, LinuxSLL) #2574); fields without version, and a version with no member (each RFC requires its own, RFC 1131/2328 §8.2, RFC 5340 §4.2.2), are refused. Behind IP, OSPF._dispatch leaves such a packet Raw, as IGMP's hook does.
  • Breaking: ospf.schema/ospf.data (with ospf_auth_data_selector), the Schema_*/Data_* aliases and the base's read/make/length move to the members, with no alias. OSPFv3 info has instance_id/reserved, not autype/auth. OSPFv2 octets and info match main.
  • OSPFv1 reads RFC 1131 A.2 (OSPFv2's layout), with its own pcapkit.const.ospfv1 registries for the AuType (0, 1) and packet types (1–5) RFC 1131 defines, generated from DATA crawlers as pcapkit.const.sslv2 is. It keeps Authentication raw and checks its checksum.
  • protocol-family-grouping.rst records the ruling next to Member Shapes, and lists OSPF among the dispatching bases.
  • The new test_ospf_family_3105_unit fails 22 of its 23 tests on main (the scapy fixture check passes by design); its refusal, OSPFv1-registry and 1.8.0-info tests (4) fail on the previous head 26a6b413d.

Tests (3.14, -n 4, after make samples): tests/protocols 3875 passed, 4 skipped; tests/project, tests/const and tests/vendor 3129 passed, 88 skipped.

@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 26, 2026
@JarryShaw JarryShaw added bug Issues reporting a defect (set by the bug report template; a default, not an assessment) breaking Breaks public-facing behaviour or API (apply alongside the type label) review: running A cross-review is in flight against the current head - no verdict yet labels Nov 26, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.8 milestone Nov 26, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at f54b4bf4c (Sonnet cross-review).

  • Design: OSPF has no member classes. protocol-family-grouping.rst's "Member Shapes" table allows "one parser, dynamic alias", the shape ARP, TLS and DTLS use, and OSPF.alias is already OSPFv{version}. The per-instance __schema__ is a new idiom but doesn't leak: parsing v3 then v2, and v2 then v3, gives the right type each time.
  • Correctness: the scapy Hello parses with a 16-octet header and its body starts at octet 16. A non-zero Instance ID and cuts of 1 to 16 octets all rebuild byte-exact. OSPFv2, and the version 0, 1, 4 and 255 cases, are identical to main.
  • Tests: the new tests fail on main. Reverting the schema switch fails 40 of them. tests/project passes (2469).
  • Your call, non-blocking: say so if you'd rather have OSPFv2/OSPFv3 members under a dispatching base. I'd keep one class: it matches the existing dynamic-alias protocols.

@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 Nov 26, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

NEEDS CHANGES per your design ruling. Versions that differ significantly get separate classes under a shared base. One class is fine only when a version is a field change plus extra features, and explicit classes are generally better for both parsing and construction.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment and removed review: good-to-go Cross-review at the current head says ready; CI state is separate labels Nov 26, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Adding OSPFv1 as well, per your follow-up: version 1 existed (RFC 1131, obsoleted by RFC 1247), so the family is OSPF → OSPFv1, OSPFv2, OSPFv3. The worker is checking the v1 header against RFC 1131 itself instead of assuming it matches v2. Today, version 1 reads as v2.

@JarryShaw
JarryShaw force-pushed the fix/3105-ospfv3-header branch from f54b4bf to 26a6b41 Compare November 27, 2026 00:35
@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 Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Coverage: 94.71% (unit tier, Python 3.15, 345ba5c9a, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 108 4 20 2 95.31%
pcapkit/const 21713 213 3086 186 98.31%
pcapkit/corekit 3059 83 1004 40 96.73%
pcapkit/dumpkit 423 3 148 5 98.60%
pcapkit/foundation 3755 24 1208 26 98.99%
pcapkit/interface 103 4 34 3 94.89%
pcapkit/protocols 25771 158 6760 129 99.11%
pcapkit/toolkit 963 26 344 8 96.63%
pcapkit/utilities 591 7 162 5 98.41%
pcapkit/vendor 6141 2317 1400 242 58.98%

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

@JarryShaw

Copy link
Copy Markdown
Owner Author

NEEDS CHANGES at 26a6b413d (Sonnet re-review). The family structure holds: parsing and building through OSPF give the right member, nothing leaks across instances, and OSPFv2 is byte- and info-identical to main. OSPFv1 matches RFC 1131 A.2, and routing 3 to v2 fails 42 tests. Two calls are yours:

  1. Versions with no member (0, 4–255) are currently read as OSPFv2. That contradicts the conventions page ("no member is a default") and all three RFCs ("must specify protocol version N"). (A) refuse them: OSPF(bytes) raises, and dispatch hands the payload on as Raw, as IGMP does. (B) keep OSPFv2 as the default and rewrite the page's rule. Recommend (A).
  2. Removing Schema_OSPF, Data_OSPF and the two CryptographicAuthentication names with no alias, all public since at least 1.6.2, is a break inside 1.8.1. (A) accept it, as the moved-name rule and this fix's ! already imply. (B) keep aliases until 1.9.0. Recommend (A).

Also to fix:

  • The #: NOTE: on OSPF.info_name runs to 3 lines; trim it to 2.
  • The versionremoved text also needs ospf_auth_data_selector and the base's former read, make and length.
  • The 1744 pin comments say 1.7.x; those names shipped by 1.6.2.
  • OSPFv1 should name only the AuType values RFC 1131 defines (0 and 1).

The worker is applying (A) and (A) meanwhile.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment needs: decision Waiting on the maintainer to decide — not blocked by other work and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 27, 2026
@JarryShaw JarryShaw moved this from In review to Needs decision in PyPCAPKit Nov 27, 2026
OSPF read every version with OSPFv2's 24-octet header, though RFC 5340
A.3.1 gives OSPFv3 16 octets with an Instance ID and no authentication.

* OSPF becomes the abstract base of a versioned family: OSPFv1 (RFC 1131),
  OSPFv2 (RFC 2328) and OSPFv3 (RFC 5340), each a package with its own
  schema and data model. The base picks the member by the Version octet
  on parse, by version= on build, and by the data's version in from_data;
  any other version is refused, and left Raw behind IP protocol 89.
* OSPFv2 keeps 1.8.0's octets and info; OSPFv1 names RFC 1131's AuType and
  packet types in a new pcapkit.const.ospfv1, keeps its Authentication raw
  and checks its checksum; OSPFv3 hands the body on at octet 16.
* ospf.schema and ospf.data move to ospfv2, with no alias; the members are
  registered and exported.
* protocol-family-grouping.rst records the ruling: versions that differ
  significantly are separate members under a shared base.
* Tests: test_ospf_family_3105_unit, the edge table's v1 and v3 cases,
  and the OSPF pins moved to the members.
@JarryShaw
JarryShaw force-pushed the fix/3105-ospfv3-header branch from 26a6b41 to 345ba5c Compare November 27, 2026 01:29
@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 Nov 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 345ba5c9a (Sonnet re-review of round 3). This head implements recommendation (A) for both questions above, which still need your answer.

  • Refusal: OSPF(bytes) and OSPF.from_fields raise ProtocolError for versions 0, 4 and 255. Behind IPv4 and IPv6 protocol 89, those versions are handed on as Raw through a new OSPF._dispatch, shaped like IGMP's. Every case rebuilds byte-exact. If _dispatch routes unknown versions to v2, the refusal test fails.
  • OSPFv1 registries: they follow the SSLv2 precedent of a hand-maintained DATA table. Only RFC 1131's values are named: AuType 0 and 1, and packet types 1–5. The census and docs are pinned, not weakened. The versionremoved list is complete, and the exception paragraph is gone.
  • Tests: OSPF, const and vendor pass 714, tests/protocols/application passes 705, and tests/project passes 2469.

@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 Nov 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Take both recommendations

@JarryShaw

Copy link
Copy Markdown
Owner Author

Taking both, and 345ba5c9a already implements them. Versions with no member are refused: directly they raise, and behind IP protocol 89 they're handed on as Raw. The old Schema_OSPF, Data_OSPF and CryptographicAuthentication names are removed in 1.8.1 with no alias, noted as versionremoved. Nothing left to change; I'll post ready once CI is green.

@JarryShaw JarryShaw removed the needs: decision Waiting on the maintainer to decide — not blocked by other work label Nov 27, 2026
@JarryShaw JarryShaw moved this from Needs decision to In review in PyPCAPKit Nov 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Ready to merge at 345ba5c9a. Required checks pass, Coverage and the KTLO legs pass, and no KTLO or experimental leg warns. GraalPy, the experimental leg, is still running. The branch is behind main (strict ruleset), so merge through the bypass. Once it lands, I open the 1.8.1 changelog PR and then the bump.

@JarryShaw
JarryShaw merged commit af5c0be into main Nov 27, 2026
76 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 27, 2026
@JarryShaw
JarryShaw deleted the fix/3105-ospfv3-header branch November 27, 2026 03:02
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 27, 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) bug Issues reporting a defect (set by the bug report template; a default, not an assessment)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(application)!: read OSPFv3 with its own 16-octet header at IPv6 next header 89

1 participant