IPv6-Route - Routing Header for IPv6

pcapkit.protocols.internet.ipv6_route contains IPv6_Route only, which implements extractor for Routing Header for IPv6 (IPv6-Route) [*], whose structure is described as below:

Octets

Bits

Name

Description

0

0

route.next

Next Header

1

8

route.length

Header Extensive Length

2

16

route.type

Routing Type

3

24

route.seg_left

Segments Left

4

32

route.data

Type-Specific Data

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

Bases: Internet[IPv6_Route, IPv6_Route]

This class implements Routing Header for IPv6.

This class currently supports parsing of the following Routing Header for IPv6 routing data types, which are registered in the self.__routing__ attribute:

property name: Literal['Routing Header for IPv6']

Name of current protocol.

property alias: Literal['IPv6-Route']

Acronym of corresponding protocol.

property length: int

Header length of current protocol.

property payload: ProtocolBase | NoReturn

Payload of current instance.

Raises:

UnsupportedCall – if the protocol is used as an IPv6 extension header

Return type:

pcapkit.protocols.protocol.Protocol

property protocol: str | None | NoReturn

Name of next layer protocol (if any).

Raises:

UnsupportedCall – if the protocol is used as an IPv6 extension header

property protochain: ProtoChain | NoReturn

Protocol chain of current instance.

Raises:

UnsupportedCall – if the protocol is used as an IPv6 extension header

classmethod register_routing(code, meth)[source]

Register an routing data parser.

Parameters:
read(length=None, *, extension=False, **kwargs)[source]

Read Routing Header for IPv6.

Structure of IPv6-Route header [RFC 8200][RFC 5095]:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Header  |  Hdr Ext Len  |  Routing Type | Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                       type-specific data                      .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

  • extension (bool) – If the packet is used as an IPv6 extension header.

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

Return type:

IPv6_Route

Returns:

Parsed packet data.

make(dst=None, next=<TransType.UDP: 17>, next_default=None, next_namespace=None, next_reversed=False, type=<Routing.Source_Route: 0>, type_default=None, type_namespace=None, type_reversed=False, seg_left=0, data=b'\\x00\\x00\\x00\\x00', payload=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
Return type:

IPv6_Route

Returns:

Constructed packet data.

Raises:

FieldValueError – If dst is a bool (c.f. parse_ip_address()).

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (IPv6_Route) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

static _make_hdr_ext_len(data_length)[source]

Compute Hdr Ext Len for a type-specific data payload of data_length octets.

Per RFC 8200 Section 4.4, Hdr Ext Len is “the length of the Routing header in 8-octet units, not including the first 8 octets”. The routing header’s fixed part (next/length/ type/seg_left) is 4 octets, so the total on-the-wire header is 4 + data_length octets; equating that to 8 + 8 * hdr_ext_len and solving gives hdr_ext_len = (data_length - 4) / 8. ipv6_route_data_length in pcapkit.protocols.schema.internet.ipv6_route is this expression’s inverse, used on the read side.

This is the only place Hdr Ext Len is computed on the write side: make() used to compute it twice, once per branch, in two different (and both wrong) units – that duplication, not either expression individually, is what let the two drift and is why there is one helper now rather than two call sites. Do NOT “simplify” the - 4 / / 8 away: the units either side of it differ (octets vs. 8-octet units), and dropping the offset silently reinterprets the field, which is exactly the defect #487 fixed (compare the * 8 unit bug behind #483 in the scapy adapter).

Parameters:

data_length (int) – packed length, in octets, of the type-specific data (i.e. len(data_val.pack()) for a Schema-based payload, or the padded raw bytes length for the unknown/raw-bytes case).

Return type:

int

Returns:

The Hdr Ext Len field value.

_read_data_type_none(schema, *, header)[source]

Read IPv6-Route unknown type data.

Structure of IPv6-Route unknown type data [RFC 8200][RFC 5095]:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Header  |  Hdr Ext Len  |  Routing Type | Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                       type-specific data                      .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • schema (UnknownType) – parsed routing data schema

  • header (IPv6_Route) – parsed IPv6-Route header schema

Return type:

UnknownType

Returns:

Parsed route data.

_read_data_type_src(schema, *, header)[source]

Read IPv6-Route Source Route data.

Structure of IPv6-Route Source Route data [RFC 5095]:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Header  |  Hdr Ext Len  | Routing Type=0| Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            Reserved                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                           Address[1]                          +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                           Address[2]                          +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
.                               .                               .
.                               .                               .
.                               .                               .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                           Address[n]                          +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • schema (SourceRoute) – parsed routing data schema

  • header (IPv6_Route) – parsed IPv6-Route header schema

Return type:

SourceRoute

Returns:

Parsed route data.

_read_data_type_2(schema, *, header)[source]

Read IPv6-Route Type 2 data.

Structure of IPv6-Route Type 2 data [RFC 6275]:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Header  | Hdr Ext Len=2 | Routing Type=2|Segments Left=1|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            Reserved                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
+                                                               +
|                                                               |
+                         Home Address                          +
|                                                               |
+                                                               +
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • schema (Type2) – parsed routing data schema

  • header (IPv6_Route) – parsed IPv6-Route header schema

Return type:

Type2

Returns:

Parsed route data.

Raises:

ProtocolError – If Hdr Ext Len is NOT 2.

_read_data_type_rpl(schema, *, header)[source]

Read IPv6-Route RPL Source data.

Structure of IPv6-Route RPL Source data [RFC 6554]:

 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Header  |  Hdr Ext Len  | Routing Type  | Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| CmprI | CmprE |  Pad  |               Reserved                |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
.                                                               .
.                        Addresses[1..n]                        .
.                                                               .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • schema (RPL) – parsed routing data schema

  • header (IPv6_Route) – parsed IPv6-Route header schema

Return type:

RPL

Returns:

Parsed route data.

_make_data_type_none(type, route=None, *, dst=None, data=b'\\x00\\x00\\x00\\x00', **kwargs)[source]

Make IPv6-Route unknown type data.

Parameters:
Return type:

UnknownType

Returns:

Constructed route data schema.

_make_data_type_src(type, route=None, *, dst=None, ip=None, **kwargs)[source]

Make IPv6-Route Source Route data.

Parameters:
Return type:

SourceRoute

Returns:

Constructed route data schema.

_make_data_type_2(type, route=None, *, dst=None, ip='::', **kwargs)[source]

Make IPv6-Route Type 2 data.

Parameters:
Return type:

Type2

Returns:

Constructed route data schema.

_make_data_type_rpl(type, route=None, *, dst=None, ip=None, **kwargs)[source]

Make IPv6-Route RPL Source data.

Parameters:
Return type:

RPL

Returns:

Constructed route data schema.

Raises:

FieldValueError – If an entry of ip is a bool (c.f. parse_ip_address()).

__routing__: DefaultDict[Routing | int, str | tuple[Callable[[RoutingType, IPv6_Route], IPv6_Route], Callable[[Routing, IPv6_Route | None, IPv6Address | None, Any], RoutingType]]]

Type code to method mapping. Method names are expected to be referred to the class by _read_data_type_${name} and/or _make_data_type_${name}, and if such name not found, the value should then be a method that can parse the routing type by itself.

Type:

DefaultDict[Enum_Routing, str | tuple[TypeParser, TypeConstructor]]

__post_init__(file=None, length=None, *, extension=False, **kwargs)[source]

Post initialisation hook.

Overloads:
  • self, file (IO[bytes] | bytes), length (Optional[int]), extension (bool), src_ip (Optional[IPv6Address]), dst_ip (Optional[IPv6Address]), kwargs (Any) → None

  • self, kwargs (Any) → None

Parameters:
  • file (IO[bytes] | bytes | None) – Source packet stream.

  • length (int | None) – Length of packet data.

  • extension (bool) – If the protocol is used as an IPv6 extension header.

  • src_ip – source IP address

  • dst_ip – destination IP address

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

See also

For construction argument, please refer to self.make.

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.ipv6_route.IPv6_Route(*args: _VT, **kwargs: _VT)[source]

Bases: Schema

Header schema for IPv6-Route packet.

next: TransType = <EnumField next>

Next header.

length: int = <UInt8Field length>

Header extension length.

type: Routing = <EnumField type>

Routing type.

seg_left: int = <UInt8Field seg_left>

Segments left.

data: RoutingType = <SwitchField data>

Routing data.

payload: bytes = <PayloadField payload>

Payload.

class pcapkit.protocols.schema.internet.ipv6_route.RoutingType(dict_=None, **kwargs)[source]

Bases: EnumSchema[Routing]

Header schema for IPv6-Route type-specific routing data.

class pcapkit.protocols.schema.internet.ipv6_route.UnknownType(*args: _VT, **kwargs: _VT)[source]

Bases: RoutingType

Header schema for IPv6-Route unknown type routing data.

data: bytes = <BytesField data>

Type-specific data.

class pcapkit.protocols.schema.internet.ipv6_route.SourceRoute(*args: _VT, **kwargs: _VT)[source]

Bases: RoutingType

Header schema for IPv6-Route source route routing data.

reserved: bytes = <PaddingField reserved>

Reserved.

ip: list[IPv6Address] = <ListField ip>

Addresses.

class pcapkit.protocols.schema.internet.ipv6_route.Type2(*args: _VT, **kwargs: _VT)[source]

Bases: RoutingType

Header schema for IPv6-Route type 2 routing data.

reserved: bytes = <PaddingField reserved>

Reserved.

ip: IPv6Address = <IPv6AddressField ip>

Addresses.

class pcapkit.protocols.schema.internet.ipv6_route.RPL(*args: _VT, **kwargs: _VT)[source]

Bases: RoutingType

Header schema for IPv6-Route RPL routing data.

cmpr: CmprInfo = <BitField cmpr>

CmprI and CmprE – two 4-bit counts sharing one octet.

NOTE: RFC 6554 Section 3 gives CmprI and CmprE as “4-bit unsigned integer”, i.e. the high and low nibble of a single octet, so they cannot be two UInt8Field as they were before #564. Together with pad below – Pad (4 bits) plus Reserved (20 bits) – this is the one 32-bit word the diagram in RFC 6554 Section 3 draws, and the same word IPv6_Route._read_data_type_rpl’s own docstring already drew correctly. The split between the two fields falls on the octet boundary between CmprE and Pad, so neither straddles an octet.

pad: PadInfo = <BitField pad>

Padding length and reserved.

addresses: bytes = <ListField addresses>

Addresses.

padding: bytes = <PaddingField padding>

Padding.

post_process(packet)[source]

Revise schema data after unpacking process.

Parameters:

packet (dict[str, Any]) – Unpacked data.

Return type:

Schema

Returns:

Revised schema.

ip: list[IPv6Address | bytes]

Addresses (SRH prefix compression decoded).

Type Stubs

class pcapkit.protocols.schema.internet.ipv6_route.CmprInfo[source]

Bases: TypedDict

Prefix-compression counts, two nibbles of a single octet.

class pcapkit.protocols.schema.internet.ipv6_route.PadInfo[source]

Bases: TypedDict

Padding length and reserved.

Auxiliary Functions

pcapkit.protocols.schema.internet.ipv6_route.ipv6_route_data_selector(pkt)[source]

Selector function for IPv6_Route.data field.

Parameters:

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

Return type:

FieldBase

Returns:

A SchemaField wrapped RoutingType instance based on IPv6_Route.type.

pcapkit.protocols.schema.internet.ipv6_route.ipv6_route_data_length(hdr_ext_len)[source]

Length, in octets, of the IPv6-Route type-specific data for a given Hdr Ext Len.

Per RFC 8200 Section 4.4, Hdr Ext Len is “the length of the Routing header in 8-octet units, not including the first 8 octets” – i.e. the total on-the-wire header is 8 + 8 * hdr_ext_len octets. Of that, the 4 octets of next/length/type/seg_left are not part of the type-specific data, so the data itself – what ipv6_route_data_selector() hands to the nested RoutingType schema – is 4 + 8 * hdr_ext_len octets. This is the single place that arithmetic is done on the read side; see _make_hdr_ext_len() for its inverse on the write side. Do NOT drop the 4 +: that turns the field back into raw octets and is the exact defect #487 fixed.

Parameters:

hdr_ext_len (int) – raw Hdr Ext Len field value, as read off the wire.

Return type:

int

Returns:

Length, in octets, of the type-specific data.

Data Models

class pcapkit.protocols.data.internet.ipv6_route.IPv6_Route(dict_=None, **kwargs)[source]

Bases: Protocol

Data model for IPv6-Route protocol.

next: TransType

Next header.

length: int

Header extension length.

type: Routing

Routing type.

seg_left: int

Segments left.

class pcapkit.protocols.data.internet.ipv6_route.UnknownType(*args: VT, **kwargs: VT)[source]

Bases: IPv6_Route

Data model for IPv6-Route unknown type.

data: bytes

Data.

class pcapkit.protocols.data.internet.ipv6_route.SourceRoute(*args: VT, **kwargs: VT)[source]

Bases: IPv6_Route

Data model for IPv6-Route Source Route data type.

ip: tuple[IPv6Address, ...]

Source addresses.

class pcapkit.protocols.data.internet.ipv6_route.Type2(*args: VT, **kwargs: VT)[source]

Bases: IPv6_Route

Data model for IPv6-Route Type 2 data type.

ip: IPv6Address

Address.

class pcapkit.protocols.data.internet.ipv6_route.RPL(*args: VT, **kwargs: VT)[source]

Bases: IPv6_Route

Data model for RPL Source data type.

cmpr_i: int

CmprI.

cmpr_e: int

CmprE.

pad: int

Pad.

ip: tuple[IPv6Address | bytes, ...]

Addresses.

Footnotes