PPP - Point-to-Point Protocol¶
pcapkit.protocols.link.ppp.protocol contains
PPP,
which implements the extractor for the Point-to-Point Protocol
(PPP) [*] frame of RFC 1661, in the HDLC-like framing of
RFC 1662, whose structure is:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Address ( |
1 |
8 |
|
Control ( |
2 |
16 |
|
Protocol (one octet when compressed) |
The Address and Control fields are read where the frame opens with 0xFF 0x03,
and the Protocol field is one octet where its first octet is odd. LCP, IPCP,
IPv6CP, PAP and CHAP packets are read at header level, as
ppp.control_packet.
Added in version 1.7.0.
- class pcapkit.protocols.link.ppp.protocol.PPP(file, length=None, /, *, layer=None, protocol=None, context=None)[source]¶
-
This class implements Point-to-Point Protocol.
The frame is dispatched from
Frame.__proto__andPCAPNG.__proto__atLINKTYPE_PPPandLINKTYPE_PPP_HDLC, fromLink.__proto__at EtherType0x880B, and as the payload of a PPPoE session and an L2TPv2 data message.The Address and Control fields are read where the frame opens with
0xFF 0x03, and the Protocol field is one octet where its first octet is odd, as Address-and-Control-Field-Compression and Protocol-Field-Compression leave them (RFC 1661 Section 6). UnderLINKTYPE_PPP_HDLCa frame not opening with0xFF 0x03is Cisco HDLC (RFC 1547 Section 4.3.1), which is refused.A protocol number the
ControlPacketregistry holds a layout for – LCP, IPCP, IPv6CP, PAP and CHAP – is read as a control packet at header level, its Code, Identifier and Length, and the rest of the frame is the next layer asRaw. Any other protocol number dispatches the next layer, through the protocols registered in theself.__proto__attribute:Index
Protocol
Added in version 1.7.0.
Defaults
- __proto__: DefaultDict[int | Protocol, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, see
self._decode_next_layer&self._import_next_layer. Keyed by PPP protocol number rather than by EtherType, so this class keeps a registry of its own instead of sharingLink.__proto__; an entry is registered withregister_ppp().
- __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.
- __control__: DefaultDict[Protocol | int, str | tuple[Callable[[Protocol, ControlPacket], ControlPacket], Callable[[Protocol, ControlPacket | Mapping[str, Any]], ControlPacket]]]¶
Protocol number to control packet method mapping, see
read()andmake(). Astrvalue names the methods_read_control_${name}and_make_control_${name}, any other value is a(parser, constructor)pair; either works on the layout theControlPacketregistry holds for the protocol number, and one with no layout there is carried as the next layer instead. An entry is registered withregister_control()andregister_ppp_control().
Properties
Methods
- read(length=None, *, alias=None, **kwargs)[source]¶
Read Point-to-Point Protocol.
Structure of PPP frame [RFC 1661][RFC 1662]:
+----------+----------+----------+-------------+---------+ | Flag | Address | Control | Protocol | Padding | | 01111110 | 11111111 | 00000011 | 8/16 bits | * | +----------+----------+----------+-------------+---------+
The Flag sequence and the Frame Check Sequence are not captured.
- Parameters:
- Return type:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If the frame does not open with the Address and Control fields under
LINKTYPE_PPP_HDLC, or a control packet’s Length is below its fixed fields.
- make(*, protocol=Protocol.Internet_Protocol_version_4, acfc=False, pfc=False, control_packet=None, payload=b'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
acfc (
bool) – Whether the Address and Control fields are left out, under Address-and-Control-Field-Compression.pfc (
bool) – Whether the Protocol field is one octet, under Protocol-Field-Compression.control_packet (
ControlPacket|Mapping[str,Any] |None) – Control packet, given as itscode,identifieranddataand optionally itslength, for a protocol number theControlPacketregistry holds a layout for.payload (
bytes|ProtocolBase|Schema) – Payload data.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
protocolis a name, or does not fit its field; if its first octet is odd in two octets, or even in one, since the frame would read back with the other width; ifcontrol_packetis missing for a protocol number with a layout, or given for one without; if a field of it does not fit; or if, withacfc, the frame would open with0xFF 0x03.
- classmethod register(code, protocol)[source]¶
Register a new protocol class for a PPP protocol number.
Notes
The fully qualified class name of the new protocol class should be
{protocol.module}.{protocol.name}.- Parameters:
code (
Protocol) – PPP protocol numberprotocol (
ModuleDescriptor[ProtocolBase] |Type[ProtocolBase]) – module descriptor or aProtocolBasesubclass
Important
This overrides
Link.registerbecauseself.__proto__is keyed by PPP protocol number 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 protocol number 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).
- classmethod register_control(code, meth)[source]¶
Register a control packet parser.
- Parameters:
code (
Protocol) – PPP protocol number.meth (
str|tuple[Callable[[Protocol,ControlPacket],ControlPacket],Callable[[Protocol,ControlPacket|Mapping[str,Any]],ControlPacket]]) – Method name, or a(parser, constructor)pair of callables, to parse and construct its control packets; see__control__.
- Warns:
RegistryWarning– If a different entry is already registered forcode; it is overwritten. Handing back the entry already stored, or one equal to it, is a silent no-op, so an override can be undone.
Data Models
Utilities
- _lookup_control(protocol)[source]¶
Look up the parser and constructor of a protocol number’s control packets.
- Parameters:
protocol (
Protocol) – PPP protocol number- Return type:
tuple[Callable[[Protocol,ControlPacket],ControlPacket],Callable[[Protocol,ControlPacket|Mapping[str,Any]],ControlPacket]]- Returns:
What
__control__holds forprotocol, as callables.- Raises:
ProtocolError – If
__control__names a method the class does not have.
- _read_control_header(protocol, packet)[source]¶
Read a control packet at header level.
- Parameters:
protocol (
Protocol) – PPP protocol numberpacket (
ControlHeader) – parsed control packet
- Return type:
- Returns:
Its Code, Identifier, Length and data.
- _make_control_header(protocol, packet)[source]¶
Make a control packet at header level.
- Parameters:
protocol (
Protocol) – PPP protocol numberpacket (
ControlPacket|Mapping[str,Any]) – Itscode,identifieranddata, and optionally itslength, by default that of the fixed fields and the data.
- Return type:
- Returns:
The control packet, in the layout the
ControlPacketregistry holds forprotocol.- Raises:
ProtocolError – If a field does not fit, or
lengthis short of the fixed fields and the data.
Header Schemas¶
- class pcapkit.protocols.link.ppp.schema.PPP(test=NO_VALUE, address=NO_VALUE, control=NO_VALUE, pfc=NO_VALUE, protocol=NO_VALUE, cp_test=NO_VALUE, control_packet=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for PPP frames.
- test: int = <ForwardMatchField test>¶
First two octets, matched forward,
0xFF03opening the Address and Control fields of HDLC-like framing (RFC 1662 Section 3.1).
- address: int = <ConditionalField address>¶
Address field, absent under Address-and-Control-Field-Compression.
- control: int = <ConditionalField control>¶
Control field, absent under Address-and-Control-Field-Compression.
- cp_test: ControlTest = <ConditionalField cp_test>¶
Fixed fields of the control packet, matched forward.
- control_packet: ControlPacket = <ConditionalField control_packet>¶
Control packet, for a protocol number
ControlPacketregisters.
- class pcapkit.protocols.link.ppp.schema.ControlPacket(*args, **kwargs)[source]¶
Bases:
EnumSchema[Protocol]Header schema for the control packets PPP carries, by the protocol number naming them.
A protocol number with no layout registered here is carried as the next layer rather than read as a control packet.
- class pcapkit.protocols.link.ppp.schema.ControlHeader(code=NO_VALUE, identifier=NO_VALUE, length=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
ControlPacketHeader schema for a control packet read at header level.
LCP and the NCPs (RFC 1661 Section 5), PAP (RFC 1334 Section 2.2) and CHAP (RFC 1994 Section 4) open their packets with the same fixed fields; what follows them is kept as octets.
Type Stubs¶
Auxiliary Functions¶
- pcapkit.protocols.link.ppp.schema.ppp_protocol_selector(pkt)[source]¶
Selector function for
PPP.protocolfield.- Parameters:
- Return type:
- Returns:
A one-octet field where the first octet of the Protocol field is odd, as Protocol-Field-Compression leaves it (RFC 1661 Section 6.5); otherwise a two-octet one.
- pcapkit.protocols.link.ppp.schema.ppp_is_control(pkt)[source]¶
Whether the Protocol field names a control packet
ControlPackethas a layout for.- Parameters:
- Return type:
- Returns:
Whether
PPP.control_packetis present.
- pcapkit.protocols.link.ppp.schema.ppp_control_selector(pkt)[source]¶
Selector function for
PPP.control_packetfield.
Data Models¶
- class pcapkit.protocols.link.ppp.data.PPP(address, control, protocol, pfc, control_packet)[source]¶
Bases:
ProtocolData model for PPP frames.
- control_packet: ControlPacket | None¶
Control packet, for a protocol number whose packets are read at header level;
Noneotherwise.
- class pcapkit.protocols.link.ppp.data.ControlPacket(code, identifier, length, data)[source]¶
Bases:
DataData model for a PPP control packet, read at header level.
Footnotes