IPv6 - Internet Protocol version 6¶
pcapkit.protocols.internet.ipv6 contains
IPv6 only,
which implements extractor for Internet Protocol
version 6 (IPv6) [*], whose structure is described
as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Version ( |
0 |
4 |
|
Traffic Class |
1 |
12 |
|
Flow Label |
4 |
32 |
|
Payload Length (header excludes) |
6 |
48 |
|
Next Header |
7 |
56 |
|
Hop Limit |
8 |
64 |
|
Source Address |
24 |
192 |
|
Destination Address |
- class pcapkit.protocols.internet.ipv6.IPv6(file=None, length=None, **kwargs)[source]¶
-
This class implements Internet Protocol version 6.
Changed in version 1.5.0:
A Shim6 header, which has no dedicated parser, and a header in
__generic_ext_codes__whose dedicated parser raises are parsed byIPv6_Ext, so the rest of the chain is still walked (#891).A rebuild from
from_data()keeps the Payload Length a truncated capture declares (#1155), and the octets past it astrailer(#1209).Next Header codes 253 and 254 are parsed and rebuilt once (#1231), and a cut extension header chain rebuilds byte for byte (#1471, #1473).
- property src: IPv6Address¶
Source IP address.
- property dst: IPv6Address¶
Destination IP address.
- property extension_headers: OrderedMultiDict[ExtensionHeader, ProtocolBase]¶
IPv6 extension header records.
- read(length=None, *, __packet__=None, **kwargs)[source]¶
Read Internet Protocol version 6 (IPv6).
Structure of IPv6 header [RFC 8200]:
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Version| Traffic Class | Flow Label | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Payload Length | Next Header | Hop Limit | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + + | | + Source Address + | | + + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + + | | + Destination Address + | | + + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Parameters:
- Return type:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If the version is not 6, or if the packet is one of the errors RFC 2675 Section 3 has a receiver detect (see
jumbogram_error()).
- make(traffic_class=0, flow_label=0, next=<TransType.UDP: 17>, next_default=None, next_namespace=None, next_reversed=False, hop_limit=64, src='::1', dst='::', payload_length=None, payload=b'', trailer=b'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
traffic_class (
int) – Traffic class.flow_label (
int) – Flow label.next (
TransType|IntEnum|IntEnum|str|int) – Next header.next_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[IntEnum] |None) – Namespace of next header.next_reversed (
bool) – Whether to reverse the namespace of next header.hop_limit (
int) – Hop limit.src (
IPv6Address|str|bytes|int) – Source IP address.dst (
IPv6Address|str|bytes|int) – Destination IP address.payload_length (
int|None) – Length of the payload, extension headers included; computed from the payload when omitted, and zero (a jumbogram) if that exceeds 65,535 octets or the payload starts with a Hop-by-Hop Options header carrying a Jumbo Payload option.payload (
bytes|ProtocolBase|Schema) – Payload data.trailer (
bytes) – Octets after the packet, outside the Payload Length, such as link-layer padding; written as is.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- _decode_next_layer(ipv6, proto=None, length=None, *, packet=None)[source]¶
Decode next layer extractor.
- Parameters:
- Return type:
- Returns:
Current protocol with next layer extracted.
- Raises:
ProtocolError – If the walk reaches a Fragment header in a packet carrying a Jumbo Payload option, an error by RFC 2675 Section 3 (#1687).
- _import_next_layer(proto, length=None, *, packet=None, version=4, extension=False, payload=None)[source]¶
Import next layer extractor.
- Parameters:
proto (
int) – next layer protocol indexpacket (
dict[str,Any] |None) – packet info (passed fromself.unpack)version (
Literal[4,6]) – IP protocol versionextension (
bool) – if is extension headerpayload (
bytes|None) – payload from packet. If not provided, will extract fromself.__header__.get_payload
- Return type:
- Returns:
Instance of next layer.
Notes
If the dedicated parser for a code in
__generic_ext_codes__raises, this substitutesIPv6_Extfor it rather than letting the exception reach thebeholder()decorating this method, which would substitute plainRaw– andRawhas nonextfield, so it could not continue_decode_next_layer()’s walk. Every other exception – including one raised byIPv6_Extitself, or byESP’s own dedicated parser – still reachesbeholderunchanged, giving a plainRawfor that one layer.253and254have no dedicated parser, so they reach plainRawwith no exception involved;_decode_next_layer()stops its walk structurally on any layer whose info carries nonextattribute,Rawincluded.ESP’s info always carries anext(None, since RFC 4303 encrypts the real value), so neither this substitution nor that structural check engages for it, and the walk ends after it – see__generic_ext_codes__’s docstring for the full distinction.The upper layer past a walk cut at
EXTENSION_HEADER_LIMITis the next extension header, and is kept raw with oneProtocolWarning, as inInternet._import_next_layer(#1604).
- __generic_ext_codes__¶
Extension header codes with a dedicated parser class in this package whose layout follows RFC 6564 Section 4’s generic
next+Hdr Ext Lenformat (see the module docstring ofpcapkit.protocols.internet.ipv6_extfor the exception table). When that dedicated parser raises,_import_next_layer()substitutesIPv6_Extinstead of letting the genericbeholder()fall back to plainRaw, which has nonextfield and so cannot continue the walk in_decode_next_layer().Three groups are deliberately absent:
Shim6has no dedicated parser class in this package, so there is no “own parser” for it to raise from. It reachesIPv6_Extby direct registration (see the bottom ofpcapkit.protocols.internet.ipv6_ext), which already produces exactly this class.ESPdoes have a dedicated, registered parser (ESP). It is excluded because RFC 4303 places the real Next Header byte inside the encrypted trailer, so its own info always carries anextattribute, just one that isNonewhenever the payload could not be decrypted – which, with no key material available to a generic parse, is always. The_decode_next_layer()walk still ends there, one iteration later, becauseNonefailsExtensionHeader’s constructor at the top of the loop – the ordinary end-of-chain path, unrelated to the structural check this set exists for.253and254have no dedicated parser at all, so they resolve to plainRaw, whose info has nonextattribute; the structural check in_decode_next_layer()catches these. A next-header byte that is not in the extension-header registry at all (e.g.147) fails the same constructor at the top of the loop, like any unrecognised upper-layer protocol code.
_decode_next_layer()’s walk stops cleanly at whichever of these (or any other IANA code this package has not implemented) it meets, and keeps this layer’s own header intact.
Protocol Constants¶
- pcapkit.protocols.internet.ipv6.IPV6_HEADER_LEN = 40¶
Length of the fixed IPv6 header, i.e. the offset of the first extension header, RFC 8200 Section 3. The one home of this value (#1739); it is fixed by the RFC, so it is never configurable.
Added in version 1.5.0.
- pcapkit.protocols.internet.ipv6.IPV6_NEXT_HEADER_OFFSET = 6¶
Offset of the Next Header field within the fixed IPv6 header, RFC 8200 Section 3. The one home of this value (#1739).
Added in version 1.5.0.
Header Schemas¶
- pcapkit.protocols.schema.internet.ipv6.IP_MAX_LENGTH = 65535¶
IPv4’s Total Length, the header included (RFC 791 Section 3.1), and IPv6’s Payload Length, the fixed header excluded (RFC 8200 Section 3) – so a longer IPv6 payload is a jumbogram, whose Jumbo Payload Length must exceed it (RFC 2675 Section 2). The one home of this value (#1739), here so that the schema’s jumbogram check and the protocol modules read the same one; it is fixed by the RFCs, so it is never configurable.
Added in version 1.5.0.
- Type:
The most octets a 16-bit IP length field declares
- class pcapkit.protocols.schema.internet.ipv6.IPv6(*args: _VT, **kwargs: _VT)[source]¶
Bases:
SchemaHeader schema for IPv6 packet.
- hextet: IPv6Hextet = <BitField hextet>¶
Version, traffic class and flow label.
The
BitFieldnamespace maps each subfield to a(start_bit, length_in_bits)pair, not to(start_bit, end_bit). Per RFC 8200 Section 3 the first 32 bits of the IPv6 header are Version (bits 0-3), Traffic Class (bits 4-11) and Flow Label (bits 12-31), so the flow label starts at bit 12 – reading it as(8, 20)would overlap the low nibble of the traffic class and drop the low nibble of the label.
- src: IPv6Address = <IPv6AddressField src>¶
Source address.
- dst: IPv6Address = <IPv6AddressField dst>¶
Destination address.
- trailer: bytes = <PayloadField trailer>¶
Octets captured past the Payload Length (or a jumbogram’s Jumbo Payload Length, see
post_process()), such as Ethernet minimum-frame padding, c.f.IPv4.trailer.
- post_process(packet)[source]¶
Revise
schemadata after unpacking process.A jumbogram [RFC 2675] declares a Payload Length of zero and carries its real length in a Jumbo Payload option instead, so the
payloadfield reads nothing and every octet lands intrailer. Whenjumbo_payload_length()finds that option, the two are split again at the Jumbo Payload Length, and only the octets beyond it stay intrailer. The octets themselves are untouched, so the packed header is unchanged.
Type Stubs¶
Auxiliary Functions¶
- pcapkit.protocols.schema.internet.ipv6.jumbo_payload_length(next, data)[source]¶
Find the Jumbo Payload Length of an IPv6 packet [RFC 2675].
The Jumbo Payload option is only honoured in a Hop-by-Hop Options header that immediately follows the IPv6 header, as RFC 2675 Section 2 and RFC 8200 Section 4.1 place it there; one anywhere else is left to the extension header that carries it.
- pcapkit.protocols.schema.internet.ipv6.jumbogram_error(length, next, data, fragment=None)[source]¶
Name the error RFC 2675 Section 3 has a receiver detect in an IPv6 packet, if any.
The four errors that section lists for a node that understands the Jumbo Payload option, each a packet the default engine rejects (#1687):
a Payload Length of zero, a Next Header of Hop-by-Hop Options, and no Jumbo Payload option;
a non-zero Payload Length and a Jumbo Payload option;
a Jumbo Payload option whose Jumbo Payload Length is below 65,536;
a Jumbo Payload option and a Fragment header.
The option counts only where
jumbo_payload_length()finds it.- Parameters:
length (
int) – Payload Length of the IPv6 header.next (
int) – Next Header of the IPv6 header.data (
bytes) – Octets following the IPv6 header, as captured.fragment (
Callable[[],bool] |None) – Tells whether the extension header chain, as the default engine walks it, has a Fragment header; called only for a packet carrying the option, so a caller walks the chain only for those.
- Return type:
- Returns:
The error, or
Noneif the packet makes none of them.
Data Models¶
- class pcapkit.protocols.data.internet.ipv6.IPv6(*args: Any, **kwargs: Any)[source]¶
Bases:
ProtocolData model for Internet Protocol version 6.
Important
Due to the reserved keyword conflict, please use
from_dict()to create an instance of this data model.- src: IPv6Address¶
Source address.
- dst: IPv6Address¶
Destination address.
Footnotes