LLC - Logical Link Control¶
pcapkit.protocols.link.llc.protocol contains
LLC,
which implements the extractor for the IEEE 802.2 Logical Link
Control (LLC) [*] PDU of ISO/IEC 8802-2, whose structure is:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
DSAP address, its low bit the I/G bit |
1 |
8 |
|
SSAP address, less its low bit |
1 |
15 |
|
C/R bit, the low bit of the SSAP octet |
2 |
16 |
|
Control field, one octet in the U format and two in the I and S formats |
Where the PDU comes from, and where its information field goes:
flowchart TD
ETH["Ethernet, Length/Type up to 0x05DC"] --> LLC
WLAN["802.11 data frame carrying an MSDU"] --> LLC
ATM["LINKTYPE_ATM_RFC1483"] --> LLC
LLC{"control field format"}
LLC -->|"I PDU or UI PDU"| DSAP{"LLC.\_\_proto\_\_ by DSAP"}
LLC -->|"S, or U other than UI"| RAW["Raw"]
DSAP -->|"0xAA, paired: SSAP 0xAA too"| SNAP{"SNAP, by OUI"}
DSAP -->|"paired, another SSAP"| RAW
DSAP -->|"no entry"| RAW
SNAP -->|"00-00-00: the PID as an EtherType"| LINK["Link.\_\_proto\_\_"]
SNAP -->|"any other"| RAW
Added in version 1.9.0.
- class pcapkit.protocols.link.llc.protocol.LLC(file, length=None, /, *, layer=None, protocol=None, context=None)[source]¶
-
This class implements IEEE 802.2 Logical Link Control.
The PDU is dispatched from
Ethernet, where its Length/Type field is a length, fromIEEE802_11, as the frame body of a data frame carrying an MSDU, and fromFrame.__proto__andPCAPNG.__proto__atLINKTYPE_ATM_RFC1483.The control field is one octet in the U format, whose two low bits are
11, and two in the I format, whose low bit is0, and the S format, whose two low bits are01. The information field of an I PDU or a UI PDU is the next layer, dispatched by the DSAP through the protocols registered in theself.__proto__attribute. A DSAPself.__paired__flags is dispatched only when the SSAP, less its C/R bit, is the same address, as RFC 1042 sets both to the SNAP SAP and IEEE Std 802.1D-2004 both to the Bridge Spanning Tree Protocol SAP:Index
Protocol
Paired
yes
yes
That of any other PDU, such as the XID or TEST information LLC exchanges itself, is kept as
Raw.Added in version 1.9.0.
Defaults
- __proto__: DefaultDict[int | LSAP, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, see
self._decode_next_layer&self._import_next_layer. Keyed by DSAP rather than by EtherType, so this class keeps a registry of its own instead of sharingLink.__proto__; an entry is registered withregister_lsap().
- __paired__: dict[int | LSAP, bool]¶
DSAP to paired flag mapping, read by
read(). A DSAP it flags is handed on only when the SSAP, less its C/R bit, is the same address, as the standard of the protocol at that DSAP fixes it, and one it does not hold is dispatched on alone. Written with the DSAP’s entry in__proto__byregister(), through itspairedkeyword.
- __proto_key__: ClassVar[tuple[Type[EnumRegistry], bool]]¶
The enum the protocol map is keyed by, and that a bare int is no key, as
Link.__proto_key__describes.
Properties
Methods
- read(length=None, **kwargs)[source]¶
Read IEEE 802.2 Logical Link Control.
Structure of LLC PDU [IEEE Std 802.2]:
+--------+--------+-------------+-----------------------+ | DSAP | SSAP | Control | Information | | | | 8/16 bits | | +--------+--------+-------------+-----------------------+
Each field is transmitted least significant bit first, so the I/G bit of the DSAP, the C/R bit of the SSAP and the format bits of the control field are the low bits of their octets.
- make(*, dsap=LSAP.SNAP, ssap=LSAP.SNAP, cr=False, format='U', function=None, send_seq=None, recv_seq=None, poll_final=False, reserved=None, payload=b'', **kwargs)[source]¶
Make (construct) packet data.
formatdecides which fields of the control field are carried. A field it carries and the caller leaves out is written as zeros, sofunctionisUIin the U format andRRin the S format; a field it does not carry must be left out.- Parameters:
format (
Literal['I','S','U']) – Format of the control field.function (
SupervisoryFunction|ModifierFunction|int|None) – Supervisory function in the S format, or modifier function in the U format, as the first octet of the control field masked to its bits.send_seq (
int|None) – Send sequence number, N(S), in the I format.recv_seq (
int|None) – Receive sequence number, N(R), in the I and S formats.poll_final (
bool) – Poll/final bit.reserved (
int|None) – Reserved bits 5 to 8 of the S format.payload (
bytes|ProtocolBase|Schema) – Payload data, the information field.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
dsap,ssaporfunctionis a name, or a code its field cannot carry; ifssapis a group address; ifformatis none of'I','S'and'U'; if a field is given thatformatdoes not carry; or if a value does not fit its field.
- classmethod register(code, protocol, *, paired=False)[source]¶
Register a new protocol class for a DSAP.
Notes
The fully qualified class name of the new protocol class should be
{protocol.module}.{protocol.name}.The paired flag goes with the entry. Handing back the entry
codeshipped with, as a restore does, puts back the flag it shipped with too, so that an override and its restore leave__paired__as it was; any other entry takespaired.- Parameters:
code (
LSAP) – DSAP addressprotocol (
ModuleDescriptor[ProtocolBase] |Type[ProtocolBase]) – module descriptor or aProtocolBasesubclasspaired (
bool) – Whether a PDU tocodeis handed on only when its SSAP, less the C/R bit, iscodetoo, as__paired__records it.
Important
This overrides
Link.registerbecauseself.__proto__is keyed by DSAP rather than by EtherType (#2511).- Raises:
pcapkit.utilities.exceptions.RegistryError – If
protocolis not a class, or not aProtocolBasesubclass.- Warns:
pcapkit.utilities.warnings.RegistryWarning– If this DSAP is already registered and the incumbent differs from the replacement; the message names both. SeeProtocol.registerfor the guard, and for the shipped descriptor a restore puts back (#1504).
Data Models
- __length_hint__()[source]¶
Return an estimated length for the object.
The longer form – a two-octet control field, 4 octets – per the reason
L2TPv2.__length_hint__gives for a variable-length header.- Return type:
Literal[4]
Utilities
- _make_function(function, namespace, mask)[source]¶
Make the function bits of an S-format or U-format control field.
- Parameters:
function (
SupervisoryFunction|ModifierFunction|int|None) – Function, as the first octet of the control field masked to its bits;Nonemakes zeros.namespace (
Type[SupervisoryFunction] |Type[ModifierFunction]) – Enumeration of the format’s functions.mask (
int) – Bits of the first octet the function takes.
- Return type:
- Returns:
The function bits, in place in the first octet.
- Raises:
ProtocolError – If
functionis a name, or a code with a bit outsidemaskset.
Header Schemas¶
- class pcapkit.protocols.link.llc.schema.LLC(dsap=NO_VALUE, ssap=NO_VALUE, control=NO_VALUE, control_ext=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for LLC PDUs.
Auxiliary Functions¶
Data Models¶
- class pcapkit.protocols.link.llc.data.LLC(dsap, ssap, cr, control)[source]¶
Bases:
ProtocolData model for LLC PDUs.
- class pcapkit.protocols.link.llc.data.Control(format, function, send_seq, recv_seq, poll_final, reserved)[source]¶
Bases:
DataData model for the LLC control field.
- format: Literal['I', 'S', 'U']¶
Format of the control field,
'I'(information transfer),'S'(supervisory) or'U'(unnumbered).
- function: SupervisoryFunction | ModifierFunction | None¶
Supervisory function of the S format, or modifier function of the U format;
Nonein the I format.
Footnotes