LinuxSLL - Linux “Cooked” Capture Encapsulation Family¶
pcapkit.protocols.link.linux_sll.protocol contains
LinuxSLL only, the base class of the
Linux “cooked” capture encapsulation family:
The versions differ in field order and width, so each parses its own header.
The base holds what they share: the next-layer dispatch, and link-layer address
validation. It has no registry index, so its __index__ raises. Parsing octets
through the base, or building it from fields, gives the version its
version keyword names, which a version checks as its own on both paths
(#2840), and is refused without it, since the link type rather than the
header names the version. Its
from_data() gives the version
whose data model it is handed (#2574).
Added in version 1.6.0.
- class pcapkit.protocols.link.linux_sll.protocol.LinuxSLL[_PT: Data, _ST: Schema](file, length=None, /, *, version=None, layer=None, protocol=None, context=None)[source]¶
Bases:
Link[_PT,_ST],Generic[_PT,_ST]Base class of the Linux “cooked” capture encapsulation family.
The versions differ in field order and width, so this base holds only the next-layer dispatch they share. See Selecting a Version for the labels that select a version.
This class supports parsing of the following protocols, which are registered in the
self.__proto__attribute, keyed byarphrd_type:Index
Protocol
Every other
arphrd_typereadsprotocol_typeas an EtherType and dispatches it throughLink.__proto__, as an Ethernet frame does.It dispatches where the version is known, never giving an instance of this class (#2574).
versionnames the member, from octets or from fields, and nothing else does: the header carries no version of its own, and no field picks a member, so either is refused without it.from_data()gives the member whose data model it is handed, and refuses adict. See__new__().Defaults
- __proto__: DefaultDict[int | ARPHRD, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, keyed by the
arphrd_typevalues whoseprotocol_typeis not an EtherType, per tcpdump.org’s LINUX_SLL and LINUX_SLL2 pages.
- __proto_key__: ClassVar[tuple[Type[EnumRegistry], bool]]¶
What
__proto__is keyed by, declared asLink.__proto_key__is.
Methods
- classmethod register(code, protocol)[source]¶
Register a new protocol class for an
arphrd_type.Notes
The fully qualified class name of the new protocol class should be
{protocol.module}.{protocol.name}.- Parameters:
protocol (
ModuleDescriptor[ProtocolBase] |Type[ProtocolBase]) – module descriptor or aProtocolBasesubclass
Important
This overrides
Link.registerbecauseself.__proto__is keyed byarphrd_typerather than by EtherType. A registeredarphrd_typedispatches through it, and itsprotocol_typeis not read as an EtherType.- Raises:
pcapkit.utilities.exceptions.RegistryError – If
protocolis not a class, or not aProtocolBasesubclass.- Warns:
pcapkit.utilities.warnings.RegistryWarning– If thisarphrd_typeis already registered and the incumbent differs from the replacement; seeProtocol.registerfor the guard, and for the shipped descriptor a restore puts back (#1504).
- classmethod from_data(data, /, **kwargs)[source]¶
Create protocol instance from data.
- Parameters:
**kwargs (
Any) – AsProtocol.from_data.
- Return type:
- Returns:
Protocol instance; on this class, an instance of the member whose data model
datais.- Raises:
ProtocolError – If
datais neither member’s data model, on this class. Adictis refused: it carries no version, and no key picks a member.
Data Models
- classmethod __index__()[source]¶
Numeral registry index of the protocol.
- Raises:
UnsupportedCall – The family base has no registry entry; nothing dispatches to it, only to its members.
- Return type:
- __init__(file=NO_VALUE, length=None, /, *, version=None, layer=None, protocol=None, context=None, **fields)[source]¶
Parse a protocol instance from its octets, or construct one from its fields.
- Overloads:
file (
IO[bytes] |bytes), length (int|None) =..., /, *, version (Literal[1,2] |None) =..., layer (str|None) =..., protocol (str|ProtocolBase|Type[ProtocolBase] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =...→None*, version (
Literal[1,2] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =..., **fields (Any) →None
- Parameters:
file (
IO[bytes] |bytes|NoValueType) – Source packet stream; omitted to construct.version (
Literal[1,2] |None) – Version of the header,1or2: the member__new__()picks, which must be this class’s own.layer (
str|None) – AsProtocol.__init__.protocol (
str|ProtocolBase|Type[ProtocolBase] |None) – AsProtocol.__init__.context (
ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) – AsProtocol.__init__.**fields (
Any) – AsProtocol.__init__.
- Raises:
ProtocolError – If
versionnames neither member, or is not this class’s own version: that of the member it is or derives from, which a subclass outside the members does not have.
Changed in version 1.8.0:
versionis checked against the member, asfrom_fields()checks it, rather than handed on (#2840).
- static __new__(cls, file=NO_VALUE, length=None, /, **kwargs)[source]¶
Create the member a parse or a construction of this class describes.
The
versionkeyword names the member, and nothing else does: the header carries no version of its own. That member’s__init__then runs with the same arguments. A subclass of this class is created as itself.- Parameters:
- Return type:
- Returns:
An uninitialised instance of the member.
- Raises:
ProtocolError – If
versionis missing, or names neither member: the link type names the version,LINUX_SLL(113) orLINUX_SLL2(276).
Utilities
- _import_next_layer(proto, length=None, *, packet=None)[source]¶
Import next layer extractor.
- Parameters:
- Returns:
the class
self.__proto__registers forarphrd_typewhen it has a key for it, and otherwise the classLink.__proto__registers forprotoas an EtherType. Where parsing stops at this layer, either path keeps the payloadRaw, and aRawrecordsprotoeither way.- Return type:
Note
self.__proto__holds thearphrd_typekeys, so the EtherType path namesLink.__proto__itself rather than reaching it throughsuper(), asFRAD._import_next_layerdoes for a SNAP EtherType.
- classmethod _construction_member(fields)[source]¶
The member
from_fields(),from_data()and a call given no file construct.On this class, the member
versionnames; on another, the class itself, of whichversionmust name the member it is or derives from.versionis taken out offields, asmake()does not read it.- Parameters:
- Return type:
- Returns:
The member, or the class itself.
- Raises:
ProtocolError – If, on this class,
versionis missing; if it names neither member; or if it is not the class’s own version, which a subclass outside the members does not have.
Added in version 1.8.0.
Auxiliary Functions¶
- pcapkit.protocols.link.linux_sll.protocol._resolve_next_layer_proto(registry, arphrd_type, protocol_type)[source]¶
Resolve the next-layer dispatch key of either version.
- Parameters:
registry (
DefaultDict[int,Any]) – Thearphrd_typeregistry, i.e.LinuxSLL.__proto__.arphrd_type (
int) – ARP hardware type of the interface the packet was seen on.protocol_type (
int) – Protocol (internet layer), as parsed off the wire.
- Return type:
- Returns:
protocol_typeitself ifarphrd_typeis a key ofregistry; otherwise the valueEthernetstores for the sametype.
- pcapkit.protocols.link.linux_sll.protocol._validate_link_addr(alias, link_addr, link_addr_length, *, max_length)[source]¶
Validate and pad the link-layer address for
make()of either version.- Parameters:
alias (
str) – Acronym of the calling protocol, for the error message.link_addr (
bytes|bytearray) – Link-layer address, at most 8 octets.link_addr_length (
int|None) – Length in use, by defaultlen(link_addr); may exceed 8, e.g. 20 for InfiniBand, of which the header keeps 8.max_length (
int) – Maximum of the wire field holding the length.
- Return type:
- Returns:
link_addrpadded withNULoctets to 8, and the length.- Raises:
ProtocolError – If
link_addrexceeds 8 octets, or the length is outside0tomax_length.
Auxiliary Constants¶
Hardware Types¶
The arphrd_type keys of LinuxSLL.__proto__ are named by
ARPHRD.
Selecting a Version¶
The family name selects either version, and each version’s own name selects that
version only, as IPv4 and
IPv6 do under
IP. 'LinuxSLL' is in both versions;
'LinuxSLL1' in a v2 layer is False. String == does not expand a
key, so v1 == 'LinuxSLL' is False while 'LinuxSLL' in v1 is True.