Skip to content

toolkit: pyshark layer names are Wireshark filter names, so LinkType lookup misses #840

Description

@JarryShaw

Found while applying #838's ruling to raise on an unresolvable link-layer name, and it will bite the moment #838 merges.

pcapkit/toolkit/pyshark.py:87 does Enum_LinkType.get(packet.layers[0].layer_name.upper()). pyshark's layer_name is Wireshark's protocol filter name, passed through unmodified — pyshark/packet/layers/base.py:30-31 is a bare return self._layer_name, and .upper() appears only in __repr__. For a PDML capture the name comes straight from <proto name> (pyshark/tshark/output_parser/tshark_xml.py:93, XmlLayer(proto)).

Three pieces of local evidence that these are filter names, not protocol titles:

  • pyshark's Packet.__getattr__ matches layer.layer_name.lower() == item.lower(), documented as "For instance: pkt.ip", and consts.TRANSPORT_LAYERS = ['UDP', 'TCP'].
  • pcapkit's own pyshark toolkit relies on exactly that: packet.ip, packet.ipv6, packet.tcp, packet.frame_info.
  • The test double in tests/toolkit/test_pyshark_unit.py names its layers 'frame', 'ip', 'tcp', 'ipv6' — all real filter names — and then 'ethernet', which is not one. Wireshark's is eth (hence eth.src, eth.dst, and the fake's own src= field).

So layers[0].layer_name.upper() is 'ETH' for an ordinary Ethernet capture, and 'ETH' is not a LinkType member — 'ETHERNET' is. Once #838 removes the fallback, every Ethernet capture traced through this toolkit raises instead of one odd case.

Fix: map pyshark/Wireshark filter names to LinkType (at least eth → ETHERNET, ip → IPV4, ipv6 → IPV6, null/loop → NULL, raw → RAW) rather than upper-casing a display name and hoping it matches. Same question applies to pcapkit/toolkit/scapy.py:324, where (Ether()/IP()/TCP()).name.upper() happens to be 'ETHERNET' and does resolve — so scapy is correct today by coincidence of naming, not by design.

Caveat, stated plainly: there is no tshark on this host, so the eth spelling is derived from pyshark's source, its documented idiom, and the test double's own internal inconsistency — not from live PDML.

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

    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)fixPull requests that fix a defect (fix: subject prefix)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions