LinuxSLL - Linux “Cooked” Capture Encapsulation Family¶
pcapkit.protocols.link.linux_sll 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. Constructing
the base gives the version its version keyword names, from octets or from
fields, 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).
- class pcapkit.protocols.link.linux_sll.LinuxSLL[_PT: Data, _ST: Schema](file=None, length=None, **kwargs)[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__().- 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.
- 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=None, length=None, *, version=None, **kwargs)[source]¶
Initialisation.
- Parameters:
version (
Literal[1,2] |None) – Version of the header,1or2: the member__new__()picks. Building from fields, it must be this class’s own. Parsing, it is handed on unread.**kwargs (
Any) – AsProtocol.__init__.
- Raises:
ProtocolError – If, building from fields,
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.
- static __new__(cls, file=None, length=None, **kwargs)[source]¶
Create the member a construction of this class describes.
The
versionkeyword names the member, on either path, and nothing else does: the header carries no version of its own, and no field picks a member. 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. Without it, octets are refused as fields are: the link type names the version,LINUX_SLL(113) orLINUX_SLL2(276).
- _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.
- __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.
Auxiliary Functions¶
- pcapkit.protocols.link.linux_sll._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._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.