PPPoE - PPP over Ethernet

pcapkit.protocols.link.pppoe.protocol contains PPPoE, which implements the extractor for PPP over Ethernet (PPPoE) [*] of RFC 2516, whose structure is:

Octets

Bits

Name

Description

0

0

pppoe.version

Version (1)

0

4

pppoe.type

Type (1)

1

8

pppoe.code

Code

2

16

pppoe.session_id

Session ID

4

32

pppoe.length

Length of the payload

6

48

pppoe.tags

Tags (discovery stage)

The Code tells the stages apart: a discovery packet carries tags and no next layer, and a session packet a PPP frame.

Added in version 1.7.0.

class pcapkit.protocols.link.pppoe.protocol.PPPoE(file, length=None, /, *, layer=None, protocol=None, context=None)[source]

Bases: Link[PPPoE, PPPoE]

This class implements PPP over Ethernet.

The packet is dispatched from Link.__proto__ at EtherType 0x8863, the discovery stage, and 0x8864, the session stage, and from Frame.__proto__ and PCAPNG.__proto__ at LINKTYPE_PPP_ETHER. Which stage a packet is in is read from its Code, PPP_Session_Stage being the session stage’s (RFC 2516 Section 6), since LINKTYPE_PPP_ETHER carries no EtherType to tell.

A discovery packet carries its tags and no next layer. A session packet carries a PPP frame, dispatched as Link.__proto__ dispatches EtherType 0x880B. The octets past the Length field are kept as trailer.

Added in version 1.7.0.

Properties

property name: Literal['PPP over Ethernet']

Name of current protocol.

property length: int

Header length of current protocol, the tags included.

property code: Code

Code of current packet.

Methods

read(length=None, **kwargs)[source]

Read PPP over Ethernet.

Structure of PPPoE header [RFC 2516]:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  VER  | TYPE  |      CODE     |          SESSION_ID           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            LENGTH             |           payload             ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

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

Return type:

PPPoE

Returns:

Parsed packet data.

Raises:

ProtocolError – If the version or the type is not 1, or the Length of a discovery packet ends inside a tag. Parsed on its own, a version and type the cut left as zero are the short read’s (#2880).

make(*, code=Code.PPP_Session_Stage, session_id=0, payload_length=None, tags=None, payload=b'', trailer=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
  • code (Code | int) – Code; the session stage’s, or a discovery packet’s.

  • session_id (int) – Session ID.

  • payload_length (int | None) – Length field; the length of the payload or of the tags when None, which it has to be when given, but in a rebuild of a cut packet.

  • tags (Iterable[Tag | Mapping[str, Any] | tuple[Tag | int, bytes]] | None) – Tags of a discovery packet, each a (type, value) pair or a mapping of its type, value and optionally length, which has to be that of the value.

  • payload (bytes | ProtocolBase | Schema) – Payload data, a PPP frame in the session stage.

  • trailer (bytes) – Octets after the packet, outside the Length field; written as is.

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

Return type:

PPPoE

Returns:

Constructed packet data.

Raises:

ProtocolError – If code is a name, or a code its field cannot carry; if tags is given in the session stage, or payload in the discovery stage; if tags is no iterable of tags, or a tag has no type or value, a type that does not fit, a value that is not bytes or a length other than its value’s; or if payload_length is not the length of what follows the header.

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. EtherTypes 0x8863 and 0x8864 are dispatched here as well.

Utilities

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (PPPoE) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

_make_tag(tag)[source]

Make a discovery tag.

Parameters:

tag (Tag | Mapping[str, Any] | tuple[Tag | int, bytes]) – A (type, value) pair, or a mapping of the tag’s type, value and optionally length, by default that of the value.

Return type:

Tag

Returns:

The tag.

Raises:

ProtocolError – If tag is neither, or has no type or value; if the type does not fit, or the value is not bytes; or if the length is not the value’s.

Header Schemas

class pcapkit.protocols.link.pppoe.schema.PPPoE(info=NO_VALUE, code=NO_VALUE, session_id=NO_VALUE, length=NO_VALUE, tags=NO_VALUE, payload=NO_VALUE, trailer=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for PPPoE packets.

info: VersionType = <BitField info>

Version and type.

code: Code = <EnumField code>

Code.

session_id: int = <UInt16Field session_id>

Session ID.

length: int = <UInt16Field length>

Length of the payload.

tags: list[Tag] = <ConditionalField tags>

Tags, in the discovery stage.

payload: bytes = <PayloadField payload>

Payload, in the session stage.

trailer: bytes = <PayloadField trailer>

Octets captured past the Length field, see L2TP.trailer.

class pcapkit.protocols.link.pppoe.schema.Tag(type=NO_VALUE, length=NO_VALUE, value=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for PPPoE discovery tags.

type: Tag = <EnumField type>

Tag type.

length: int = <UInt16Field length>

Tag length.

value: bytes = <BytesField value>

Tag value.

Type Stubs

class pcapkit.protocols.link.pppoe.schema.VersionType[source]

Bases: TypedDict

Version and type of PPPoE packet.

ver: int

Version.

type: int

Type.

Auxiliary Functions

pcapkit.protocols.link.pppoe.schema.pppoe_payload_length(pkt)[source]

Length of the PPPoE.payload field.

Parameters:

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

Return type:

int

Returns:

The Length field in the session stage, whose payload is a PPP frame; 0 in the discovery stage, whose payload is its tags.

Data Models

class pcapkit.protocols.link.pppoe.data.PPPoE(version, type, code, session_id, length, tags)[source]

Bases: Protocol

Data model for PPPoE packets.

version: int

Version.

type: int

Type.

code: Code

Code, PPP_Session_Stage in the session stage and a discovery packet’s otherwise.

session_id: int

Session ID.

length: int

Length of the payload.

tags: tuple[Tag, ...] | None

Tags of a discovery packet; None in the session stage.

class pcapkit.protocols.link.pppoe.data.Tag(type, length, value)[source]

Bases: Data

Data model for PPPoE discovery tags.

type: Tag

Tag type.

length: int

Tag length.

value: bytes

Tag value.

Footnotes