L2TPv2 - Layer Two Tunnelling Protocol version 2

pcapkit.protocols.link.l2tpv2 contains L2TPv2 only, which implements extractor for the Layer Two Tunnelling Protocol version 2 (L2TPv2) [*] as specified by RFC 2661 – a 16-bit tunnel ID and a 16-bit session ID, with the version nibble reading 2. It is dispatched from UDP.__proto__ at port 1701. Its structure is described as below:

Octets

Bits

Name

Description

0

0

l2tp.flags

Flags and Version Info

0

0

l2tp.flags.type

Type (control / data)

0

1

l2tp.flags.len

Length

0

2

Reserved (must be zero x00)

0

4

l2tp.flags.seq

Sequence

0

5

Reserved (must be zero x00)

0

6

l2tp.flags.offset

Offset

0

7

l2tp.flags.prio

Priority

1

8

Reserved (must be zero x00)

1

12

l2tp.version

Version (2)

2

16

l2tp.length

Length (optional by len)

4

32

l2tp.tunnelid

Tunnel ID

6

48

l2tp.sessionid

Session ID

8

64

l2tp.ns

Sequence Number (optional by seq)

10

80

l2tp.nr

Next Sequence Number (optional by seq)

12

96

l2tp.offset

Offset Size (optional by offset)

Note

The parsed datagram appears under l2tp, not l2tpv2: info_name is declared on the version-agnostic base so that a consumer finds the data at the same key whichever version was on the wire. The version is reported by alias instead.

IANA protocol number 115 (L2TP) is deliberately left unbound. It references RFC 3931, i.e. L2TPv3, whose session and control message headers are a different shape – so the binding waits on an L2TPv3 class rather than on this one. See pcapkit.protocols.link.l2tp.

class pcapkit.protocols.link.l2tpv2.L2TPv2(file=None, length=None, **kwargs)[source]

Bases: L2TP[L2TP, L2TP]

This class implements Layer Two Tunnelling Protocol version 2.

The protocol is dispatched from UDP.__proto__ at port 1701.

Note

IANA protocol number 115 (L2TP) is deliberately left unbound. It references RFC 3931, i.e. L2TPv3, whose session and control message headers are a different shape – so the binding waits on an L2TPv3 class rather than on this one.

As with OSPF, the class subclasses Link and so reports layer == 'Link' even though it is carried inside UDP. That is a pre-existing classification, kept because moving the module would change its public import path.

property name: Literal['Layer 2 Tunnelling Protocol version 2']

Name of current protocol.

property alias: Literal['L2TPv2']

Acronym of current protocol.

property version: Literal[2]

Version of current protocol.

Always 2: RFC 2661 fixes the version nibble, and a datagram carrying any other value is a different protocol reached through a different class. c.f. L2TP.

property length: int

Header length of current protocol.

property type: Literal['control', 'data']

L2TP type.

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['L2TP'], Literal['L2TPv2']]

Returns:

Index ID of the protocol – the canonical family name first, then this version’s own label, as HTTPv1.id does. Element zero is what callers treat as canonical, so both protocol='L2TP' and protocol='L2TPv2' select this class.

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

Read Layer Two Tunnelling Protocol.

Structure of L2TP header [RFC 2661]:

 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|T|L|x|x|S|x|O|P|x|x|x|x|  Ver  |          Length (opt)         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Tunnel ID           |           Session ID          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|             Ns (opt)          |             Nr (opt)          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      Offset Size (opt)        |    Offset pad... (opt)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

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

Return type:

L2TP

Returns:

Parsed packet data.

make(version=2, type=<Type.Data: 1>, type_default=None, type_namespace=None, type_reversed=False, priority=False, length=None, tunnel_id=0, session_id=0, ns=None, nr=None, offset=None, payload=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
Return type:

L2TP

Returns:

Constructed packet data.

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (L2TP) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

classmethod __index__()[source]

Numeral registry index of the protocol.

Raises:

UnsupportedCall – This protocol has no registry entry.

Note

L2TPv2 is reached through UDP port 1701, and a port is not an __index__ value anywhere in this package – every non-raising __index__ returns a TransType, EtherType or LinkType, and Application.__index__ raises for exactly this reason. So there is no index to return here. L2TPv3 will be the first class in this family with one, IANA protocol number 115.

Return type:

NoReturn

Header Schemas

class pcapkit.protocols.schema.link.l2tp.L2TP(*args: _VT, **kwargs: _VT)[source]

Bases: Schema

Header schema for L2TP packet.

flags: FlagsType = <BitField flags>

Flags and version of L2TP packet.

length: int = <ConditionalField length>

Length of L2TP packet.

tunnel_id: int = <UInt16Field tunnel_id>

Tunnel ID of L2TP packet.

session_id: int = <UInt16Field session_id>

Session ID of L2TP packet.

ns: int = <ConditionalField ns>

Sequence number of L2TP packet.

nr: int = <ConditionalField nr>

Next sequence number of L2TP packet.

offset: int = <ConditionalField offset>

Offset size of L2TP packet.

padding: bytes = <ConditionalField padding>

Padding of L2TP packet.

payload: bytes = <PayloadField payload>

Payload of L2TP packet.

Type Stubs

class pcapkit.protocols.schema.link.l2tp.FlagsType[source]

Bases: TypedDict

Flags of L2TP packet.

type: int

Type of L2TP packet.

len: int

Length of L2TP packet.

seq: int

Sequence number of L2TP packet.

offset: int

Offset size of L2TP packet.

prio: int

Priority of L2TP packet.

version: Literal[2]

Version of L2TP packet.

Data Models

class pcapkit.protocols.data.link.l2tp.L2TP(*args: VT, **kwargs: VT)[source]

Bases: Protocol

Data model for L2TP packet.

flags: Flags

Flags and version info.

version: int

Version.

length: int | None

Length.

tunnelid: int

Tunnel ID.

sessionid: int

Session ID.

ns: int | None

Sequence Number.

nr: int | None

Next Sequence Number.

offset: int | None

Offset Size.

hdr_len: int

Header length.

class pcapkit.protocols.data.link.l2tp.Flags(*args: VT, **kwargs: VT)[source]

Bases: Data

Data model for L2TP flags and version info.

type: Type

Type.

len: bool

Length.

seq: bool

Sequence.

offset: bool

Offset.

prio: bool

Priority.

Footnotes