ICMPv6 - Internet Control Message Protocol for IPv6

pcapkit.protocols.internet.icmpv6 contains ICMPv6 only, which implements extractor for Internet Control Message Protocol for IPv6 (ICMPv6) [*], whose structure is described as below:

Octets

Bits

Name

Description

0

0

icmpv6.type

Type

1

8

icmpv6.code

Code

2

16

icmpv6.checksum

Checksum

4

32

icmpv6.data

Message Body

class pcapkit.protocols.internet.icmpv6.ICMPv6(file=None, length=None, **kwargs)[source]

Bases: ICMP[ICMPv6, ICMPv6]

This class implements Internet Control Message Protocol for IPv6.

This class parses the following ICMPv6 message types, which are registered in the self.__type__ attribute:

Any other type, including Neighbor Discovery (RFC 4861) and Multicast Listener Discovery (RFC 9777), is kept as its raw message body, see _read_data_type_none() and _make_data_type_none().

Changed in version 1.6.0: The checksum is computed when make() is given none, over the pseudo it is given or by the enclosing IPv6 layer, and verified by that layer under CHECKSUM_VERIFY (#2470).

property name: Literal['Internet Control Message Protocol for IPv6']

Name of current protocol.

property alias: Literal['ICMPv6']

Acronym of corresponding protocol.

property length: int

Header length of current protocol.

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['ICMPv6']]

Returns:

Index ID of the protocol.

classmethod register_type(code, meth)[source]

Register a message body parser.

Parameters:
Warns:

RegistryWarning – If a different entry is already registered for code; it is overwritten.

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

Read Internet Control Message Protocol for IPv6 (ICMPv6).

Structure of ICMPv6 header [RFC 4443]:

 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Type      |     Code      |          Checksum             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                         Message Body                         +
|                                                               |
Parameters:
  • length (int | None) – Length of packet data.

  • __packet__ (dict[str, Any] | None) – Optional packet data, unused.

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

Return type:

ICMPv6

Returns:

Parsed packet data.

make(type=Type.Echo_Request, code=0, checksum=None, body=b'\x00\x00\x00\x00', pseudo=None, **kwargs)[source]

Make (construct) packet data.

Parameters:
  • type (Type | int) – ICMPv6 type.

  • code (int) – ICMPv6 code; meaning is entirely type-dependent.

  • checksum (bytes | None) – Checksum; if None and CHECKSUM_COMPUTE is on, computed over pseudo (RFC 4443 Section 2.3), or left to an IPv6 layer this message is the payload of; zero otherwise.

  • body (bytes | ICMPv6 | ICMPv6Type | dict[str, Any]) – Message body. bytes is parsed against type’s own schema; a dict or a ICMPv6 data model is handed to that type’s own constructor method (see __type__); any other ICMPv6Type is used as is.

  • pseudo (IP_Pseudo | None) – Pseudo-header of the enclosing IPv6 layer; its length is replaced by this message’s own.

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

Return type:

ICMPv6

Returns:

Constructed packet data.

Raises:

ProtocolError – If type is a name, a bool, or a member or code that does not fit in one octet; if body is bytes that do not parse as the message body of type, or is of none of the accepted types; or if checksum is not two octets.

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (ICMPv6) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

_verify_pseudo_checksum(pseudo)[source]

Verify the checksum over the pseudo-header of the enclosing IP layer.

That layer calls this once parsed, see verify_upper().

Parameters:

pseudo (IP_Pseudo | None) – Pseudo-header, or None if the IP layer gives none.

_read_data_type_none(schema, *, header, length)[source]

Read ICMPv6 message of unknown type.

Parameters:
  • schema (Unknown) – parsed message body schema

  • header (ICMPv6) – parsed ICMPv6 header schema

  • length (int) – total length of the current ICMPv6 message

Return type:

Unknown

Returns:

Parsed message data.

_read_data_type_destination_unreachable(schema, *, header, length)[source]

Read ICMPv6 Destination Unreachable message.

Structure of ICMPv6 Destination Unreachable message [RFC 4443]:

 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Type      |     Code      |          Checksum             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             Unused                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    As much of invoking packet                |
|                   as will fit without the ICMPv6             |
|                   packet exceeding the minimum IPv6 MTU      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • schema (DestinationUnreachable) – parsed message body schema

  • header (ICMPv6) – parsed ICMPv6 header schema

  • length (int) – total length of the current ICMPv6 message

Return type:

DestinationUnreachable

Returns:

Parsed message data.

_read_data_type_packet_too_big(schema, *, header, length)[source]

Read ICMPv6 Packet Too Big message.

Structure of ICMPv6 Packet Too Big message [RFC 4443]:

 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Type      |     Code      |          Checksum             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             MTU                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    As much of invoking packet                |
|                   as will fit without the ICMPv6             |
|                   packet exceeding the minimum IPv6 MTU      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • schema (PacketTooBig) – parsed message body schema

  • header (ICMPv6) – parsed ICMPv6 header schema

  • length (int) – total length of the current ICMPv6 message

Return type:

PacketTooBig

Returns:

Parsed message data.

_read_data_type_time_exceeded(schema, *, header, length)[source]

Read ICMPv6 Time Exceeded message.

Structure of ICMPv6 Time Exceeded message [RFC 4443] is identical to that of _read_data_type_destination_unreachable(), but for the type code.

Parameters:
  • schema (TimeExceeded) – parsed message body schema

  • header (ICMPv6) – parsed ICMPv6 header schema

  • length (int) – total length of the current ICMPv6 message

Return type:

TimeExceeded

Returns:

Parsed message data.

_read_data_type_parameter_problem(schema, *, header, length)[source]

Read ICMPv6 Parameter Problem message.

Structure of ICMPv6 Parameter Problem message [RFC 4443]:

 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Type      |     Code      |          Checksum             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            Pointer                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    As much of invoking packet                |
|                   as will fit without the ICMPv6             |
|                   packet exceeding the minimum IPv6 MTU      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • schema (ParameterProblem) – parsed message body schema

  • header (ICMPv6) – parsed ICMPv6 header schema

  • length (int) – total length of the current ICMPv6 message

Return type:

ParameterProblem

Returns:

Parsed message data.

_read_data_type_echo(schema, *, header, length)[source]

Read ICMPv6 Echo Request/Reply message.

Structure of ICMPv6 Echo Request/Reply message [RFC 4443]:

 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Type      |     Code      |          Checksum             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Identifier          |        Sequence Number        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                             Data                              +
|                                                               |
Parameters:
  • schema (Echo) – parsed message body schema

  • header (ICMPv6) – parsed ICMPv6 header schema

  • length (int) – total length of the current ICMPv6 message

Return type:

Echo

Returns:

Parsed message data.

_make_data_type_none(type, message=None, *, data=b'', **kwargs)[source]

Make ICMPv6 message of unknown type.

Parameters:
  • type (Type) – ICMPv6 type.

  • message (Unknown | None) – message data.

  • data (bytes) – raw message body as bytes.

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

Return type:

Unknown

Returns:

Constructed message body schema.

_make_data_type_destination_unreachable(type, message=None, *, unused=b'\x00\x00\x00\x00', data=b'', **kwargs)[source]

Make ICMPv6 Destination Unreachable message.

Parameters:
  • type (Type) – ICMPv6 type.

  • message (DestinationUnreachable | None) – message data.

  • unused (bytes) – the four unused octets.

  • data (bytes) – as much of the invoking packet as fits the minimum IPv6 MTU.

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

Return type:

DestinationUnreachable

Returns:

Constructed message body schema.

Raises:

ProtocolError – If unused is not four octets.

_make_data_type_packet_too_big(type, message=None, *, mtu=0, data=b'', **kwargs)[source]

Make ICMPv6 Packet Too Big message.

Parameters:
  • type (Type) – ICMPv6 type.

  • message (PacketTooBig | None) – message data.

  • mtu (int) – MTU of the link that could not forward the invoking packet.

  • data (bytes) – as much of the invoking packet as fits the minimum IPv6 MTU.

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

Return type:

PacketTooBig

Returns:

Constructed message body schema.

_make_data_type_time_exceeded(type, message=None, *, unused=b'\x00\x00\x00\x00', data=b'', **kwargs)[source]

Make ICMPv6 Time Exceeded message.

Parameters:
  • type (Type) – ICMPv6 type.

  • message (TimeExceeded | None) – message data.

  • unused (bytes) – the four unused octets.

  • data (bytes) – as much of the invoking packet as fits the minimum IPv6 MTU.

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

Return type:

TimeExceeded

Returns:

Constructed message body schema.

Raises:

ProtocolError – If unused is not four octets.

_make_data_type_parameter_problem(type, message=None, *, pointer=0, data=b'', **kwargs)[source]

Make ICMPv6 Parameter Problem message.

Parameters:
  • type (Type) – ICMPv6 type.

  • message (ParameterProblem | None) – message data.

  • pointer (int) – pointer to the octet offset within the invoking packet where the error was detected.

  • data (bytes) – as much of the invoking packet as fits the minimum IPv6 MTU.

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

Return type:

ParameterProblem

Returns:

Constructed message body schema.

_make_data_type_echo(type, message=None, *, id=0, seq=0, data=b'', **kwargs)[source]

Make ICMPv6 Echo Request/Reply message.

Parameters:
  • type (Type) – ICMPv6 type.

  • message (Echo | None) – message data.

  • id (int) – identifier.

  • seq (int) – sequence number.

  • data (bytes) – data, echoed back verbatim by a reply to the same identifier and sequence number.

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

Return type:

Echo

Returns:

Constructed message body schema.

__type__: DefaultDict[Type | int, str | tuple[Callable[[ICMPv6Type, ICMPv6, int], ICMPv6], Callable[[Type, ICMPv6 | None, Any], ICMPv6Type]]]

Type code to method mapping. A str value names the methods _read_data_type_${name} and _make_data_type_${name}, falling back to _read_data_type_none / _make_data_type_none when they do not exist; any other value is a (parser, constructor) pair of callables.

__length_hint__()[source]

Return an estimated length for the object.

Return type:

Literal[4]

classmethod __index__()[source]

Numeral registry index of the protocol.

Return type:

TransType

Returns:

Numeral registry index of the protocol in IANA.

Header Schemas

class pcapkit.protocols.schema.internet.icmpv6.ICMPv6(type=NO_VALUE, code=NO_VALUE, checksum=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for ICMPv6 packet.

type: Type = <EnumField type>

ICMPv6 type.

code: int = <UInt8Field code>

ICMPv6 code.

checksum: bytes = <BytesField checksum>

Checksum.

data: ICMPv6Type = <SwitchField data>

Message body, selected by type.

class pcapkit.protocols.schema.internet.icmpv6.ICMPv6Type(*args, **kwargs)[source]

Bases: EnumSchema[Type]

Header schema for ICMPv6 type-specific message body.

class pcapkit.protocols.schema.internet.icmpv6.Unknown(data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: ICMPv6Type

Header schema for ICMPv6 message of unknown type.

data: bytes = <BytesField data>

Message body.

class pcapkit.protocols.schema.internet.icmpv6.DestinationUnreachable(unused=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: ICMPv6Type

Header schema for ICMPv6 Destination Unreachable message.

unused: bytes = <PaddingField unused>

Unused.

data: bytes = <BytesField data>

As much of the invoking packet as fits the minimum IPv6 MTU.

class pcapkit.protocols.schema.internet.icmpv6.PacketTooBig(mtu=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: ICMPv6Type

Header schema for ICMPv6 Packet Too Big message.

mtu: int = <UInt32Field mtu>

MTU of the link that could not forward the invoking packet.

data: bytes = <BytesField data>

As much of the invoking packet as fits the minimum IPv6 MTU.

class pcapkit.protocols.schema.internet.icmpv6.TimeExceeded(unused=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: ICMPv6Type

Header schema for ICMPv6 Time Exceeded message.

unused: bytes = <PaddingField unused>

Unused.

data: bytes = <BytesField data>

As much of the invoking packet as fits the minimum IPv6 MTU.

class pcapkit.protocols.schema.internet.icmpv6.ParameterProblem(pointer=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: ICMPv6Type

Header schema for ICMPv6 Parameter Problem message.

pointer: int = <UInt32Field pointer>

Pointer.

data: bytes = <BytesField data>

As much of the invoking packet as fits the minimum IPv6 MTU.

class pcapkit.protocols.schema.internet.icmpv6.Echo(id=NO_VALUE, seq=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: ICMPv6Type

Header schema for ICMPv6 Echo Request/Reply message.

id: int = <UInt16Field id>

Identifier.

seq: int = <UInt16Field seq>

Sequence number.

data: bytes = <BytesField data>

Data.

Auxiliary Functions

pcapkit.protocols.schema.internet.icmpv6.icmpv6_data_selector(pkt)[source]

Selector function for ICMPv6.data field.

Parameters:

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

Return type:

FieldBase

Returns:

A SchemaField wrapped ICMPv6Type instance based on ICMPv6.type.

Data Models

class pcapkit.protocols.data.internet.icmpv6.ICMPv6(*args, **kwargs)[source]

Bases: Protocol

Data model for ICMPv6 protocol.

The fields below are the only ones every ICMPv6 message shares (RFC 4443); what follows them is read entirely differently depending on type, which is why each message kind below adds its own fields rather than this base class growing a union of them all.

type: Type

ICMPv6 type.

code: int

ICMPv6 code. Left untyped as a bare int here because its meaning is entirely type-dependent; each subclass below documents which registry (if any) its own code values are drawn from.

checksum: bytes

Checksum.

length: int

Message length, in octets, header included. ICMPv6 messages carry no length field of their own – this is simply how many octets ICMPv6.read was handed, kept here so the whole message can be told apart from a truncated capture.

checksum_status: ChecksumStatus

Outcome of verifying checksum, present only when the enclosing IPv6 layer verified it under CHECKSUM_VERIFY.

class pcapkit.protocols.data.internet.icmpv6.Unknown(type, code, checksum, length, data)[source]

Bases: ICMPv6

Data model for ICMPv6 packet of unknown type.

code carries no pcapkit.const registry for a type this package does not recognise, so it is read as a bare int.

data: bytes

Message body, as captured.

class pcapkit.protocols.data.internet.icmpv6.DestinationUnreachable(type, code, checksum, length, unused, data)[source]

Bases: ICMPv6

Data model for ICMPv6 Destination Unreachable message (type 1).

unused: bytes

Unused (four octets, RFC 4443 Section 3.1), as captured.

data: bytes

As much of the invoking packet as fits the minimum IPv6 MTU, per RFC 4443 Section 3.1, as captured.

class pcapkit.protocols.data.internet.icmpv6.PacketTooBig(type, code, checksum, length, mtu, data)[source]

Bases: ICMPv6

Data model for ICMPv6 Packet Too Big message (type 2).

code is always 0 (RFC 4443 Section 3.2), so it is read as a bare int rather than typed against a registry of one member.

mtu: int

MTU of the link that could not forward the invoking packet.

data: bytes

As much of the invoking packet as fits the minimum IPv6 MTU, per RFC 4443 Section 3.2, as captured.

class pcapkit.protocols.data.internet.icmpv6.TimeExceeded(type, code, checksum, length, unused, data)[source]

Bases: ICMPv6

Data model for ICMPv6 Time Exceeded message (type 3).

unused: bytes

Unused (four octets, RFC 4443 Section 3.3), as captured.

data: bytes

As much of the invoking packet as fits the minimum IPv6 MTU, per RFC 4443 Section 3.3, as captured.

class pcapkit.protocols.data.internet.icmpv6.ParameterProblem(type, code, checksum, length, pointer, data)[source]

Bases: ICMPv6

Data model for ICMPv6 Parameter Problem message (type 4).

pointer: int

Pointer, identifying the octet offset within the invoking packet where the error was detected (RFC 4443 Section 3.4).

data: bytes

As much of the invoking packet as fits the minimum IPv6 MTU, per RFC 4443 Section 3.4, as captured.

class pcapkit.protocols.data.internet.icmpv6.Echo(type, code, checksum, length, id, seq, data)[source]

Bases: ICMPv6

Data model for ICMPv6 Echo Request/Reply message (types 128 and 129).

code is always 0 for both types (RFC 4443 Section 4.1, RFC 4443 Section 4.2), so it is read as a bare int rather than typed against a registry of one member.

id: int

Identifier.

seq: int

Sequence number.

data: bytes

Data, echoed back verbatim by a reply to the same identifier and sequence number.

Footnotes