IPv6-Route - Routing Header for IPv6

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

Octets

Bits

Name

Description

0

0

route.next

Next Header

1

8

route.length

Header Extension 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.protocol.IPv6_Route(file=None, length=None, **kwargs)[source]

Bases: IPv6_Ext[IPv6_Route, IPv6_Route]

This class implements Routing Header for IPv6.

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

Changed in version 1.3.4: length, and the length field of the parsed data model, is the header’s size in octets rather than the raw Hdr Ext Len value (#218).

Changed in version 1.5.0:

  • Hdr Ext Len is in 8-octet units both on read and on build (#487).

  • The RPL fixed area is sized at 4 octets, per RFC 6554 (#564).

  • A bool given as an address raises FieldValueError (#540).

  • make() takes data as bytes for every routing type (#1236), and an RPL source route rebuilds byte for byte, its address compression and a truncated address list included (#1456, #1457).

  • A rebuild keeps the reserved bits of an RPL source route (#1235), and the reserved octets of a Source Route or Type 2 header and the Pad octets of an RPL one as captured (#1223).

Changed in version 1.6.0:

  • make() and the RPL source route maker, given a value a fixed-width field cannot carry – negative, too wide, or a bool for a field wider than one bit – raise ProtocolError, rather than writing a different value or raising another exception (#2614).

  • The Source Route and Type 2 makers raise it for reserved octets that are not four, rather than padding or cutting them (#2676).

  • Each enumeration field of make(), next and type, takes a member or an int code, resolved with the enumeration’s get; a name, a bool, or a code that does not fit in one octet raises ProtocolError, rather than resolving against an enumeration inferred from the caller’s frame or writing a different value (#2594).

Removed in version 1.6.0: The next_default, next_namespace, next_reversed, type_default, type_namespace and type_reversed arguments of make(); resolve a name with resolve_index() first (#2594).

__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. 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.

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

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

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, type=Routing.Source_Route, seg_left=0, data=b'\x00\x00\x00\x00', hdr_ext_len=None, payload=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
Return type:

IPv6_Route

Returns:

Constructed packet data.

Raises:
  • FieldValueError – If dst is a bool (see parse_ip_address()) and data is a dict or a data model; dst is not read for any other data.

  • ProtocolError – If next or type is a name, a bool, or a member or code that does not fit in one octet; if data is bytes that do not parse as the routing data of type, or is of none of the accepted types; or if seg_left, or hdr_ext_len or the Hdr Ext Len computed from data, does not fit in one octet.

Changed in version 1.5.0: Takes hdr_ext_len ahead of payload (#1457), which shifts a positional payload.

classmethod register_routing(code, meth)[source]

Register a routing data parser.

Parameters:
Warns:

RegistryWarning – If a different entry is already registered for code; it is overwritten. Handing back the entry already stored, or one equal to it, is a silent no-op. The entry code shipped with is accepted like any other, so an override can be undone (#1362, #1363).

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['IPv6_Route']]

Returns:

Index ID of the protocol.

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

Post initialisation hook.

Overloads:
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.

Note

src_ip and dst_ip are declared only in the @overload stub above, which types them as optional keyword parameters. The runtime accepts them through **kwargs without defaulting them. The discrepancy with the implementation signature is deliberate (#505).

See also

For construction arguments, 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.

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 fixed part (next/length/type/seg_left) is 4 octets, so the on-the-wire header is 4 + data_length octets; equating that to 8 + 8 * hdr_ext_len gives hdr_ext_len = (data_length - 4) / 8. ipv6_route_data_length() is the inverse, used on the read side.

This is the only place Hdr Ext Len is computed on the write side: separate per-branch copies in make() drift apart, so keep one helper. Do NOT “simplify” the - 4 / / 8 away: the units either side differ (octets vs. 8-octet units), and dropping the offset silently reinterprets the field.

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.

Raises:

ProtocolError – If Hdr Ext Len is odd.

_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.

Raises:

ProtocolError – If Hdr Ext Len, Pad, CmprI and CmprE do not give a whole number of addresses, at least one (RFC 6554 Section 4.2).

_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, reserved=b'\x00\x00\x00\x00', **kwargs)[source]

Make IPv6-Route Source Route data.

Parameters:
Return type:

SourceRoute

Returns:

Constructed route data schema.

Raises:

ProtocolError – If reserved is not four octets.

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

Make IPv6-Route Type 2 data.

Parameters:
Return type:

Type2

Returns:

Constructed route data schema.

Raises:

ProtocolError – If reserved is not four octets.

_make_data_type_rpl(type, route=None, *, dst=None, ip=None, reserved=0, padding=b'', **kwargs)[source]

Make IPv6-Route RPL Source data.

Parameters:
  • type (Routing) – routing type

  • route (RPL | None) – route data

  • dst (IPv6Address | None) – destination IPv6 address

  • ip (list[bytes | str | int | IPv6Address] | None) – list of IPv6 addresses

  • reserved (int) – reserved bits after Pad

  • padding (bytes) – the Pad octets after the addresses, truncated or zero-filled to Pad octets

  • **kwargs (Any) – arbitrary keyword arguments

Return type:

RPL

Returns:

Constructed route data schema.

Raises:

Header Schemas

Removed in version 1.6.0: pcapkit.protocols.schema.internet.ipv6_route, with no alias: the module moved here (#2534).

class pcapkit.protocols.internet.ipv6_route.schema.IPv6_Route(next=NO_VALUE, length=NO_VALUE, type=NO_VALUE, seg_left=NO_VALUE, data=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[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.internet.ipv6_route.schema.RoutingType(*args, **kwargs)[source]

Bases: EnumSchema[Routing]

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

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

Bases: RoutingType

Header schema for IPv6-Route unknown type routing data.

data: bytes = <BytesField data>

Type-specific data.

class pcapkit.protocols.internet.ipv6_route.schema.SourceRoute(reserved=NO_VALUE, ip=NO_VALUE, *, __packet__=None, **kwargs)[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.internet.ipv6_route.schema.Type2(reserved=NO_VALUE, ip=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: RoutingType

Header schema for IPv6-Route type 2 routing data.

reserved: bytes = <PaddingField reserved>

Reserved.

ip: IPv6Address = <IPv6AddressField ip>

Home address.

class pcapkit.protocols.internet.ipv6_route.schema.RPL(cmpr=NO_VALUE, pad=NO_VALUE, addresses=NO_VALUE, padding=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: RoutingType

Header schema for IPv6-Route RPL routing data.

Removed in version 1.5.0: cmpr_i and cmpr_e, which are the keys of cmpr (#1456).

cmpr: CmprInfo = <BitField cmpr>

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

NOTE: RFC 6554 Section 3 gives each as a “4-bit unsigned integer”, the high and low nibble of one octet. With pad – Pad (4 bits) and Reserved (20 bits) – they form the 32-bit word that section draws; the split falls on the octet boundary between CmprE and Pad.

pad: PadInfo = <BitField pad>

Padding length and reserved.

addresses: bytes = <ListField addresses>

Addresses.

padding: bytes = <PaddingField padding>

Padding.

classmethod pre_unpack(packet)[source]

Prepare packet data for unpacking process.

Parameters:

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

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.internet.ipv6_route.schema.CmprInfo[source]

Bases: TypedDict

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

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

Bases: TypedDict

Padding length and reserved.

Auxiliary Functions

pcapkit.protocols.internet.ipv6_route.schema.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.internet.ipv6_route.schema.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. Dropping the 4 + would leave the data length 4 octets short.

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.

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

Total length, in octets, of the on-the-wire IPv6-Route header for a given Hdr Ext Len.

This is the fixed 4 octets of next/length/type/seg_left plus the type-specific data computed by ipv6_route_data_length(), i.e. 4 + (4 + 8 * hdr_ext_len) – a different quantity from ipv6_route_data_length() itself (8 + 8 * hdr_ext_len here vs. 4 + 8 * hdr_ext_len there), not a duplicate of it. It is what each _read_data_type_* in pcapkit.protocols.internet.ipv6_route.protocol reports back as the parsed route data’s own .length, which read() then subtracts from the outer packet length to find the next layer’s length. Its inverse is the (length - 8) // 8 that _make_data() passes back as hdr_ext_len; _make_hdr_ext_len() inverts ipv6_route_data_length() instead.

Parameters:

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

Return type:

int

Returns:

Total length, in octets, of the on-the-wire IPv6-Route header.

Data Models

Removed in version 1.6.0: pcapkit.protocols.data.internet.ipv6_route, with no alias: the module moved here (#2534).

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

Bases: Protocol

Data model for IPv6-Route protocol.

next: TransType

Next header.

length: int

Header length, in octets, decoded from Hdr Ext Len.

type: Routing

Routing type.

seg_left: int

Segments left.

class pcapkit.protocols.internet.ipv6_route.data.UnknownType(next, length, type, seg_left, data)[source]

Bases: IPv6_Route

Data model for IPv6-Route unknown type.

data: bytes

Data.

class pcapkit.protocols.internet.ipv6_route.data.SourceRoute(next, length, type, seg_left, reserved, ip)[source]

Bases: IPv6_Route

Data model for IPv6-Route Source Route data type.

Changed in version 1.5.0: New required field reserved (#1223).

reserved: bytes

The four reserved octets, as captured.

ip: tuple[IPv6Address, ...]

Source addresses.

class pcapkit.protocols.internet.ipv6_route.data.Type2(next, length, type, seg_left, reserved, ip)[source]

Bases: IPv6_Route

Data model for IPv6-Route Type 2 data type.

Changed in version 1.5.0: New required field reserved (#1223).

reserved: bytes

The four reserved octets, as captured.

ip: IPv6Address

Address.

class pcapkit.protocols.internet.ipv6_route.data.RPL(next, length, type, seg_left, cmpr_i, cmpr_e, pad, reserved, ip, padding)[source]

Bases: IPv6_Route

Data model for RPL Source data type.

Changed in version 1.5.0: New required fields reserved (#1235) and padding (#1223).

cmpr_i: int

CmprI.

cmpr_e: int

CmprE.

pad: int

Pad.

reserved: int

Reserved bits, carried verbatim so that a rebuild reproduces them.

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

Addresses.

padding: bytes

The Pad octets after the addresses, as captured.

Footnotes