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

ppp.address

Address (0xFF, optional)

1

8

ppp.control

Control (0x03, optional)

2

16

ppp.protocol

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]

Bases: Link[PPP, PPP]

This class implements Point-to-Point Protocol.

The frame is dispatched from Frame.__proto__ and PCAPNG.__proto__ at LINKTYPE_PPP and LINKTYPE_PPP_HDLC, from Link.__proto__ at EtherType 0x880B, 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). Under LINKTYPE_PPP_HDLC a frame not opening with 0xFF 0x03 is Cisco HDLC (RFC 1547 Section 4.3.1), which is refused.

A protocol number the ControlPacket registry 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 as Raw. Any other protocol number dispatches the next layer, through the protocols registered in the self.__proto__ attribute:

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 sharing Link.__proto__; an entry is registered with register_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() and make(). A str value names the methods _read_control_${name} and _make_control_${name}, any other value is a (parser, constructor) pair; either works on the layout the ControlPacket registry holds for the protocol number, and one with no layout there is carried as the next layer instead. An entry is registered with register_control() and register_ppp_control().

Properties

property name: Literal['Point-to-Point Protocol']

Name of current protocol.

property length: int

Header length of current protocol, a control packet included.

property protocol: Protocol

Protocol number of next layer protocol.

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:
  • length (int | None) – Length of packet data.

  • alias (int | None) – Code the frame was dispatched under, as Frame and PCAPNG pass the link type.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

PPP

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:
  • protocol (Protocol | int) – Protocol field.

  • 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 its code, identifier and data and optionally its length, for a protocol number the ControlPacket registry holds a layout for.

  • payload (bytes | ProtocolBase | Schema) – Payload data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

PPP

Returns:

Constructed packet data.

Raises:

ProtocolError – If protocol is 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; if control_packet is missing for a protocol number with a layout, or given for one without; if a field of it does not fit; or if, with acfc, the frame would open with 0xFF 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:

Important

This overrides Link.register because self.__proto__ is keyed by PPP protocol number rather than by EtherType (#2511).

Raises:

pcapkit.utilities.exceptions.RegistryError – If protocol is not a class, or not a ProtocolBase subclass.

Warns:

pcapkit.utilities.warnings.RegistryWarning – If this protocol number is already registered and the incumbent differs from the replacement; the message names both. See Protocol.register for the guard, and for the shipped descriptor a restore puts back (#1504).

classmethod register_control(code, meth)[source]

Register a control packet parser.

Parameters:
Warns:

RegistryWarning – If a different entry is already registered for code; 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

classmethod __index__()[source]

Numeral registry index of the protocol.

Return type:

LinkType

Returns:

Numeral registry index of the protocol in tcpdump link-layer header types. LINKTYPE_PPP_HDLC (50) and EtherType 0x880B are dispatched here as well.

Utilities

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (PPP) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

_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 for protocol, 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:
Return type:

ControlPacket

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 number

  • packet (ControlPacket | Mapping[str, Any]) – Its code, identifier and data, and optionally its length, by default that of the fixed fields and the data.

Return type:

ControlPacket

Returns:

The control packet, in the layout the ControlPacket registry holds for protocol.

Raises:

ProtocolError – If a field does not fit, or length is 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: Schema

Header schema for PPP frames.

test: int = <ForwardMatchField test>

First two octets, matched forward, 0xFF03 opening 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.

pfc: int = <ForwardMatchField pfc>

First octet of the Protocol field, matched forward.

protocol: Protocol = <SwitchField protocol>

Protocol field.

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 ControlPacket registers.

payload: bytes = <PayloadField payload>

Payload.

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: ControlPacket

Header 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.

code: int = <UInt8Field code>

Code.

identifier: int = <UInt8Field identifier>

Identifier.

length: int = <UInt16Field length>

Length, of the fixed fields and the data.

data: bytes = <BytesField data>

Data.

Type Stubs

class pcapkit.protocols.link.ppp.schema.ControlTest[source]

Bases: TypedDict

Fixed fields of a control packet, matched forward.

code: int

Code.

identifier: int

Identifier.

length: int

Length.

Auxiliary Functions

pcapkit.protocols.link.ppp.schema.ppp_protocol_selector(pkt)[source]

Selector function for PPP.protocol field.

Parameters:

pkt (dict[str, Any]) – Packet data.

Return type:

FieldBase

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 ControlPacket has a layout for.

Parameters:

pkt (dict[str, Any]) – Packet data.

Return type:

bool

Returns:

Whether PPP.control_packet is present.

pcapkit.protocols.link.ppp.schema.ppp_control_selector(pkt)[source]

Selector function for PPP.control_packet field.

Parameters:

pkt (dict[str, Any]) – Packet data.

Return type:

FieldBase

Returns:

The layout ControlPacket registers for the Protocol field, at the control packet’s own Length, or at its fixed fields where that Length is below them, which PPP.read then refuses.

Data Models

class pcapkit.protocols.link.ppp.data.PPP(address, control, protocol, pfc, control_packet)[source]

Bases: Protocol

Data model for PPP frames.

address: int | None

Address field, None under Address-and-Control-Field-Compression.

control: int | None

Control field, None under Address-and-Control-Field-Compression.

protocol: Protocol

Protocol field.

pfc: bool

Whether the Protocol field is one octet, under Protocol-Field-Compression.

control_packet: ControlPacket | None

Control packet, for a protocol number whose packets are read at header level; None otherwise.

class pcapkit.protocols.link.ppp.data.ControlPacket(code, identifier, length, data)[source]

Bases: Data

Data model for a PPP control packet, read at header level.

code: int

Code.

identifier: int

Identifier.

length: int

Length, of the fixed fields and the data.

data: bytes

Data, the options or message the code carries.

Footnotes