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 |
|
Type |
1 |
8 |
|
Code |
2 |
16 |
|
Checksum |
4 |
32 |
|
Message Body |
- class pcapkit.protocols.internet.icmpv6.ICMPv6(file=None, length=None, **kwargs)[source]¶
-
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:Type
Data Parser
Data Constructor
Destination Unreachable
Packet Too Big
Time Exceeded
Parameter Problem
Echo Request / Echo Reply
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 thepseudoit is given or by the enclosing IPv6 layer, and verified by that layer underCHECKSUM_VERIFY(#2470).- classmethod register_type(code, meth)[source]¶
Register a message body parser.
- Parameters:
- Warns:
RegistryWarning– If a different entry is already registered forcode; 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 + | |
- make(type=Type.Echo_Request, code=0, checksum=None, body=b'\x00\x00\x00\x00', pseudo=None, **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
code (
int) – ICMPv6 code; meaning is entirelytype-dependent.checksum (
bytes|None) – Checksum; ifNoneandCHECKSUM_COMPUTEis on, computed overpseudo(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.bytesis parsed againsttype’s own schema; adictor aICMPv6data model is handed to that type’s own constructor method (see__type__); any otherICMPv6Typeis 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:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
typeis a name, abool, or a member or code that does not fit in one octet; ifbodyisbytesthat do not parse as the message body oftype, or is of none of the accepted types; or ifchecksumis not two octets.
- _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().
- _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 schemaheader (
ICMPv6) – parsed ICMPv6 header schemalength (
int) – total length of the current ICMPv6 message
- Return type:
- 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 schemaheader (
ICMPv6) – parsed ICMPv6 header schemalength (
int) – total length of the current ICMPv6 message
- Return type:
- 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 schemaheader (
ICMPv6) – parsed ICMPv6 header schemalength (
int) – total length of the current ICMPv6 message
- Return type:
- 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 schemaheader (
ICMPv6) – parsed ICMPv6 header schemalength (
int) – total length of the current ICMPv6 message
- Return type:
- 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 + | |
- _make_data_type_none(type, message=None, *, data=b'', **kwargs)[source]¶
Make ICMPv6 message of unknown type.
- _make_data_type_destination_unreachable(type, message=None, *, unused=b'\x00\x00\x00\x00', data=b'', **kwargs)[source]¶
Make ICMPv6 Destination Unreachable message.
- Parameters:
- Return type:
- Returns:
Constructed message body schema.
- Raises:
ProtocolError – If
unusedis 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:
- Return type:
- 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:
- Return type:
- Returns:
Constructed message body schema.
- Raises:
ProtocolError – If
unusedis not four octets.
- _make_data_type_parameter_problem(type, message=None, *, pointer=0, data=b'', **kwargs)[source]¶
Make ICMPv6 Parameter Problem message.
- Parameters:
- Return type:
- 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:
- Return type:
- 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
strvalue names the methods_read_data_type_${name}and_make_data_type_${name}, falling back to_read_data_type_none/_make_data_type_nonewhen they do not exist; any other value is a(parser, constructor)pair of callables.
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:
SchemaHeader schema for ICMPv6 packet.
- 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:
ICMPv6TypeHeader schema for ICMPv6 message of unknown type.
- class pcapkit.protocols.schema.internet.icmpv6.DestinationUnreachable(unused=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
ICMPv6TypeHeader schema for ICMPv6 Destination Unreachable message.
- class pcapkit.protocols.schema.internet.icmpv6.PacketTooBig(mtu=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
ICMPv6TypeHeader schema for ICMPv6 Packet Too Big message.
- class pcapkit.protocols.schema.internet.icmpv6.TimeExceeded(unused=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
ICMPv6TypeHeader schema for ICMPv6 Time Exceeded message.
- class pcapkit.protocols.schema.internet.icmpv6.ParameterProblem(pointer=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
ICMPv6TypeHeader schema for ICMPv6 Parameter Problem message.
- class pcapkit.protocols.schema.internet.icmpv6.Echo(id=NO_VALUE, seq=NO_VALUE, data=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
ICMPv6TypeHeader schema for ICMPv6 Echo Request/Reply message.
Auxiliary Functions¶
- pcapkit.protocols.schema.internet.icmpv6.icmpv6_data_selector(pkt)[source]¶
Selector function for
ICMPv6.datafield.- Parameters:
- Return type:
- Returns:
A
SchemaFieldwrappedICMPv6Typeinstance based onICMPv6.type.
Data Models¶
- class pcapkit.protocols.data.internet.icmpv6.ICMPv6(*args, **kwargs)[source]¶
Bases:
ProtocolData 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.- code: int¶
ICMPv6 code. Left untyped as a bare
inthere because its meaning is entirelytype-dependent; each subclass below documents which registry (if any) its owncodevalues are drawn from.
- length: int¶
Message length, in octets, header included. ICMPv6 messages carry no length field of their own – this is simply how many octets
ICMPv6.readwas 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 underCHECKSUM_VERIFY.
- class pcapkit.protocols.data.internet.icmpv6.Unknown(type, code, checksum, length, data)[source]¶
Bases:
ICMPv6Data model for ICMPv6 packet of unknown type.
codecarries nopcapkit.constregistry for a type this package does not recognise, so it is read as a bareint.
- class pcapkit.protocols.data.internet.icmpv6.DestinationUnreachable(type, code, checksum, length, unused, data)[source]¶
Bases:
ICMPv6Data 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:
ICMPv6Data model for ICMPv6 Packet Too Big message (type 2).
codeis always0(RFC 4443 Section 3.2), so it is read as a bareintrather than typed against a registry of one member.- 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:
ICMPv6Data 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:
ICMPv6Data 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:
ICMPv6Data model for ICMPv6 Echo Request/Reply message (types 128 and 129).
codeis always0for both types (RFC 4443 Section 4.1, RFC 4443 Section 4.2), so it is read as a bareintrather than typed against a registry of one member.
Footnotes