Repository navigation
feat(link): add GRE dissector for IPGRE/IP6GRE on LINUX_SLL/SLL2 - #2508
Conversation
Part of #2460. - Add pcapkit.protocols.link.gre.GRE, dissecting the RFC 2784 base header (C/Reserved0/Ver/Protocol Type, plus optional Checksum/Reserved1) and the RFC 2890 Key/Sequence Number extensions, gated by the C/K/S flag bits. - Wire LinuxSLL/LinuxSLL1/LinuxSLL2 to dispatch both ARPHRD_IPGRE and ARPHRD_IP6GRE to this one class -- same GRE framing either way, the "IP"/"IP6" distinction being only which outer IP version the tunnel carries. - Protocol Type dispatches onward as an EtherType through the shared Link.__proto__ registry (as VLAN/Ethernet do), so GRE keeps no registry of its own, unlike FRAD's NLPID-keyed one. - Register in all 8 places; add docs page and changelog entry. Build and tests: pylint 10.00/10, mypy clean on touched files; new tests/protocols/link/test_gre_unit.py (17 passed/42 subtests); tests/protocols/link/ (170 passed/922 subtests); tests/project/ full run (2132 passed, 80 skipped, 10619 subtests, 0 failed).
|
Cross-review (Sonnet) at |
|
Coverage: 94.48% (unit tier, Python 3.15,
Per-file detail: the |
# Conflicts: # CHANGELOG.md # docs/source/changelog/1.6.0.rst # docs/source/pcapkit/protocols/link/index.rst # pcapkit/__init__.py # pcapkit/all.py # pcapkit/protocols/__init__.py # pcapkit/protocols/data/__init__.py # pcapkit/protocols/data/link/__init__.py # pcapkit/protocols/link/__init__.py # pcapkit/protocols/link/linux_sll.py # pcapkit/protocols/schema/__init__.py # pcapkit/protocols/schema/link/__init__.py # tests/protocols/link/test_linux_sll1_unit.py # tests/protocols/link/test_linux_sll2_unit.py Co-authored-by: JarryShaw <15666417+JarryShaw@users.noreply.github.com>
# Conflicts: # CHANGELOG.md # docs/source/changelog/1.6.0.rst # pcapkit/__init__.py # pcapkit/all.py # pcapkit/protocols/__init__.py # pcapkit/protocols/link/__init__.py # pcapkit/protocols/link/linux_sll.py # tests/protocols/link/test_linux_sll1_unit.py # tests/protocols/link/test_linux_sll2_unit.py Co-authored-by: JarryShaw <15666417+JarryShaw@users.noreply.github.com>
Part of #2460.
What
LinuxSLL/LinuxSLL1/LinuxSLL2fell back toRawfor theIPGRE(778)and
IP6GRE(823)arphrd_typevalues. This addspcapkit.protocols.link.gre.GRE, dissecting the Generic RoutingEncapsulation base header (RFC 2784) plus the optional Key and Sequence
Number extensions (RFC 2890), and wires
LinuxSLL's shared_import_next_layerto dispatch bothARPHRD_IPGREandARPHRD_IP6GREto this one class.
Why one class, two bindings
IPGREandIP6GREboth land on the same GRE header — the "IP" vs "IP6" inthe
arphrd_typename is about which IP version the Linux kernel's GREtunnel interface carries on its outer layer (i.e. which
arphrd_typefired), not a different GRE header shape. The GRE framing itself is
identical either way, so this is one dissector bound at two
arphrd_typevalues, exactly as #2460 scoped it.
What the dissector covers
The base header (RFC 2784 §2.1): a
C/Reserved0/Verflags-and-versionword, then a 16-bit Protocol Type (an EtherType). When
Cis set, aChecksum/Reserved1 pair follows (§2.5-2.6). RFC 2890 §2 carves
K(KeyPresent) and
S(Sequence Number Present) out of Reserved0, each gatingits own 4-octet field — so the header is 4, 8, 12 or 16 octets depending on
which of
C/K/Sare set.The Protocol Type field dispatches onward as an EtherType through
Link.__proto__, the same family registry Ethernet, VLAN and LinuxSLLalready share — exactly as
VLANresolves its owntypefield. UnlikeFRAD(keyed by NLPID, not an EtherType),GREtherefore keeps no registryof its own.
A nonzero Version Number (RFC 2637's "Enhanced GRE"/PPTP, version 1, a
different and incompatible header layout) is refused rather than misread.
Not implemented: per-family interpretation of the Key/Sequence Number
values — recorded but not interpreted further, since their meaning is a
matter for the tunnel endpoints, not something a passive dissector can
resolve from the header alone.
Registration
Registered in all 8 places:
pcapkit/__init__.py,pcapkit/all.py,pcapkit/protocols/__init__.py,pcapkit/protocols/data/__init__.py,pcapkit/protocols/data/link/__init__.py,pcapkit/protocols/link/__init__.py,pcapkit/protocols/schema/__init__.py,pcapkit/protocols/schema/link/__init__.py.Tests
tests/protocols/link/test_gre_unit.py(new): 17 tests / 42 subtests —base header dispatch (IPv4/IPv6), each optional field individually and
together (longest 16-octet form), reserved-bit round trips, the nonzero-
version refusal,
make()/read()round trips, andmake()validation.test_linux_sll1_unit.py/test_linux_sll2_unit.py: movedIPGRE/IP6GREout of the "kept raw" sweep, added an explicit GRE-dispatch test to each.
test_short_read_roundtrip_unit.py: a GRE case (longest form, all threeoptional fields) added to the cut-at-every-offset sweep.
tests/project/test_rfc_constants_one_home_1739_unit.py: four entriesadded for literals that collide with homed constants by value but mean
something unrelated (GRE's own header-length/field-width/bit-span
literals), following the FRAD/Netlink precedent.
Counts: new test file 17 passed / 42 subtests;
tests/protocols/link/170 passed / 922 subtests;
tests/protocols/test_short_read_roundtrip_unit.py9 passed / 1390 subtests;
tests/project/full run 2132 passed, 80 skipped,10619 subtests, 0 failed. pylint 10.00/10 and mypy clean on every
touched/new
pcapkit/file (verified: 110 pre-existingpcapkit/vendor/mypy errors are identical on bare
main, unrelated to this change).Changelog & docs
Entry in
docs/source/changelog/1.6.0.rst,CHANGELOG.mdregenerated(
util/changelog_md.py --checkclean), new docs pagedocs/source/pcapkit/protocols/link/gre.rstindexed in the link-layertoctree.
Scope
Two of #2460's five
arphrd_typefollow-ups remain:IEEE80211_RADIOTAP(#2502) and
FRAD(#2499, already its own PR).NETLINKhas its own PR,#2507. This PR does not close #2460.