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 |
|
Next Header |
1 |
8 |
|
Header Extension Length |
2 |
16 |
|
Routing Type |
3 |
24 |
|
Segments Left |
4 |
32 |
|
Type-Specific Data |
- class pcapkit.protocols.internet.ipv6_route.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:Routing Code
Data Parser
Data Constructor
Changed in version 1.3.4:
length, and thelengthfield 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
boolgiven as an address raisesFieldValueError(#540).make()takesdataasbytesfor 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
Padoctets of an RPL one as captured (#1223).
- property payload: ProtocolBase | NoReturn¶
Payload of current instance.
- Raises:
UnsupportedCall – if the protocol is used as an IPv6 extension header
- Return type:
- 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 a routing data parser.
- Parameters:
code (
Routing) – IPv6-Route data type code.meth (
str|tuple[Callable[[RoutingType,IPv6_Route],IPv6_Route],Callable[[Routing,IPv6_Route|None,IPv6Address|None,Any],RoutingType]]) – Method name or callable to parse and/or construct the data.
- 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 entrycodeshipped with is accepted like any other, so an override can be undone (#1362, #1363).
- 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:
- Return type:
- 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', hdr_ext_len=None, payload=b'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
dst (
IPv6Address|str|int|bytes|None) – Destination address.next (
TransType|IntEnum|IntEnum|str|int) – Next header type.next_default (
int|None) – Default value of next header type.next_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[IntEnum] |None) – Namespace of next header type.next_reversed (
bool) – If the namespace of next header type is reversed.type (
Routing|IntEnum|IntEnum|str|int) – Routing type.type_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[IntEnum] |None) – Namespace of routing type.type_reversed (
bool) – If the namespace of routing type is reversed.seg_left (
int) – Segments left.data (
bytes|IPv6_Route|RoutingType|dict[str,Any]) – Routing data.hdr_ext_len (
int|None) –Hdr Ext Lenfield value; computed fromdatawhen omitted.payload (
ProtocolBase|Schema|bytes) – Payload of current instance.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
FieldValueError – If
dstis abool(c.f.parse_ip_address()).
- classmethod _make_data(data)[source]¶
Create key-value pairs from
datafor protocol construction.- Parameters:
data (
IPv6_Route) – protocol data- Return type:
- Returns:
Key-value pairs for protocol construction.
- static _make_hdr_ext_len(data_length)[source]¶
Compute
Hdr Ext Lenfor a type-specific data payload ofdata_lengthoctets.Per RFC 8200 Section 4.4,
Hdr Ext Lenis 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 is4 + data_lengthoctets; equating that to8 + 8 * hdr_ext_lengiveshdr_ext_len = (data_length - 4) / 8.ipv6_route_data_lengthinpcapkit.protocols.schema.internet.ipv6_routeis the inverse, used on the read side.This is the only place
Hdr Ext Lenis computed on the write side: separate per-branch copies inmake()drift apart, so keep one helper. Do NOT “simplify” the- 4// 8away: the units either side differ (octets vs. 8-octet units), and dropping the offset silently reinterprets the field.
- _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 schemaheader (
IPv6_Route) – parsed IPv6-Route header schema
- Return type:
- 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 schemaheader (
IPv6_Route) – parsed IPv6-Route header schema
- Return type:
- 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 schemaheader (
IPv6_Route) – parsed IPv6-Route header schema
- Return type:
- Returns:
Parsed route data.
- Raises:
ProtocolError – If
Hdr Ext Lenis NOT2.
- _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 schemaheader (
IPv6_Route) – parsed IPv6-Route header schema
- Return type:
- 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:
type (
Routing) – routing typeroute (
UnknownType|None) – route datadst (
IPv6Address|None) – destination IPv6 address**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- 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:
type (
Routing) – routing typeroute (
SourceRoute|None) – route datadst (
IPv6Address|None) – destination IPv6 addressip (
list[bytes|str|int|IPv6Address] |None) – list of IPv6 addressesreserved (
bytes) – the four reserved octets, truncated or zero-filled to four octets**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed route data schema.
- _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:
- Returns:
Constructed route data schema.
- _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 typedst (
IPv6Address|None) – destination IPv6 addressip (
list[bytes|str|int|IPv6Address] |None) – list of IPv6 addressesreserved (
int) – reserved bits afterPadpadding (
bytes) – thePadoctets after the addresses, truncated or zero-filled toPadoctets**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed route data schema.
- Raises:
FieldValueError – If an entry of
ipis abool(c.f.parse_ip_address()).ProtocolError – If
ipis empty.
- __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
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.
- __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:
Note
src_ipanddst_ipare declared only in the@overloadstub above, which types them as optional keyword parameters. The runtime accepts them through**kwargswithout defaulting them. The discrepancy with the implementation signature is deliberate (GitHub issue #505).See also
For construction argument, please refer to
self.make.
Header Schemas¶
- class pcapkit.protocols.schema.internet.ipv6_route.IPv6_Route(*args: _VT, **kwargs: _VT)[source]¶
Bases:
SchemaHeader schema for IPv6-Route packet.
- data: RoutingType = <SwitchField data>¶
Routing data.
- 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:
RoutingTypeHeader schema for IPv6-Route unknown type routing data.
- class pcapkit.protocols.schema.internet.ipv6_route.SourceRoute(*args: _VT, **kwargs: _VT)[source]¶
Bases:
RoutingTypeHeader schema for IPv6-Route source route routing data.
- ip: list[IPv6Address] = <ListField ip>¶
Addresses.
- class pcapkit.protocols.schema.internet.ipv6_route.Type2(*args: _VT, **kwargs: _VT)[source]¶
Bases:
RoutingTypeHeader schema for IPv6-Route type 2 routing data.
- ip: IPv6Address = <IPv6AddressField ip>¶
Home address.
- class pcapkit.protocols.schema.internet.ipv6_route.RPL(*args: _VT, **kwargs: _VT)[source]¶
Bases:
RoutingTypeHeader 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
CmprIandCmprEas “4-bit unsigned integer”, i.e. the high and low nibble of a single octet, so they cannot be twoUInt8Field(one octet each). Together withpadbelow –Pad(4 bits) plusReserved(20 bits) – this is the one 32-bit word the diagram in RFC 6554 Section 3 draws, and the same wordIPv6_Route._read_data_type_rpl’s own docstring draws. The split between the two fields falls on the octet boundary betweenCmprEandPad, so neither straddles an octet.
- ip: list[IPv6Address | bytes]¶
Addresses (SRH prefix compression decoded).
Type Stubs¶
Auxiliary Functions¶
- pcapkit.protocols.schema.internet.ipv6_route.ipv6_route_data_selector(pkt)[source]¶
Selector function for
IPv6_Route.datafield.- Parameters:
- Return type:
- Returns:
A
SchemaFieldwrappedRoutingTypeinstance based onIPv6_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 Lenis “the length of the Routing header in 8-octet units, not including the first 8 octets” – i.e. the total on-the-wire header is8 + 8 * hdr_ext_lenoctets. Of that, the 4 octets ofnext/length/type/seg_leftare not part of the type-specific data, so the data itself – whatipv6_route_data_selector()hands to the nestedRoutingTypeschema – is4 + 8 * hdr_ext_lenoctets. 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 the4 +would leave the data length 4 octets short.
Data Models¶
- class pcapkit.protocols.data.internet.ipv6_route.IPv6_Route(dict_=None, **kwargs)[source]¶
Bases:
ProtocolData model for IPv6-Route protocol.
- class pcapkit.protocols.data.internet.ipv6_route.UnknownType(*args: VT, **kwargs: VT)[source]¶
Bases:
IPv6_RouteData model for IPv6-Route unknown type.
- class pcapkit.protocols.data.internet.ipv6_route.SourceRoute(*args: VT, **kwargs: VT)[source]¶
Bases:
IPv6_RouteData model for IPv6-Route Source Route data type.
Changed in version 1.5.0: New required field
reserved(#1223).- ip: tuple[IPv6Address, ...]¶
Source addresses.
- class pcapkit.protocols.data.internet.ipv6_route.Type2(*args: VT, **kwargs: VT)[source]¶
Bases:
IPv6_RouteData model for IPv6-Route Type 2 data type.
Changed in version 1.5.0: New required field
reserved(#1223).- ip: IPv6Address¶
Address.
- class pcapkit.protocols.data.internet.ipv6_route.RPL(*args: VT, **kwargs: VT)[source]¶
Bases:
IPv6_RouteData model for RPL Source data type.
- ip: tuple[IPv6Address | bytes, ...]¶
Addresses.
Footnotes