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 |
|
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.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: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).
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 aboolfor a field wider than one bit – raiseProtocolError, rather than writing a different value or raising another exception (#2614).The Source Route and Type 2 makers raise it for
reservedoctets that are not four, rather than padding or cutting them (#2676).Each enumeration field of
make(),nextandtype, takes a member or anintcode, resolved with the enumeration’sget; a name, abool, or a code that does not fit in one octet raisesProtocolError, 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_namespaceandtype_reversedarguments ofmake(); resolve a name withresolve_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
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.
- 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:
- Return type:
- 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:
dst (
IPv6Address|str|int|bytes|None) – Destination address.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(seeparse_ip_address()) anddatais adictor a data model;dstis not read for any otherdata.ProtocolError – If
nextortypeis a name, abool, or a member or code that does not fit in one octet; ifdataisbytesthat do not parse as the routing data oftype, or is of none of the accepted types; or ifseg_left, orhdr_ext_lenor theHdr Ext Lencomputed fromdata, does not fit in one octet.
Changed in version 1.5.0: Takes
hdr_ext_lenahead ofpayload(#1457), which shifts a positionalpayload.
- 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]]) – NameXof the_read_data_type_Xand_make_data_type_Xmethods, or a(parser, constructor)pair of callables, see__routing__.
- Warns:
RegistryWarning– If a different entry is already registered forcode; 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).
- __post_init__(file=None, length=None, *, extension=False, **kwargs)[source]¶
Post initialisation hook.
- Overloads:
- 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 (#505).See also
For construction arguments, please refer to
self.make.
- 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_length()is 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.
- Raises:
ProtocolError – If
Hdr Ext Lenis 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 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.
- Raises:
ProtocolError – If
Hdr Ext Len,Pad,CmprIandCmprEdo 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:
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**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed route data schema.
- Raises:
ProtocolError – If
reservedis 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:
- Returns:
Constructed route data schema.
- Raises:
ProtocolError – If
reservedis 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 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(seeparse_ip_address()).ProtocolError – If
ipis empty, orreserveddoes not fit in its twenty bits.
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:
SchemaHeader schema for IPv6-Route packet.
- data: RoutingType = <SwitchField data>¶
Routing data.
- 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:
RoutingTypeHeader schema for IPv6-Route unknown type routing data.
- class pcapkit.protocols.internet.ipv6_route.schema.SourceRoute(reserved=NO_VALUE, ip=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
RoutingTypeHeader schema for IPv6-Route source route routing data.
- 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:
RoutingTypeHeader schema for IPv6-Route type 2 routing data.
- 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:
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 each as a “4-bit unsigned integer”, the high and low nibble of one octet. With
pad–Pad(4 bits) andReserved(20 bits) – they form the 32-bit word that section draws; the split falls on the octet boundary betweenCmprEandPad.
- ip: list[IPv6Address | bytes]¶
Addresses (SRH prefix compression decoded).
Type Stubs¶
Auxiliary Functions¶
- pcapkit.protocols.internet.ipv6_route.schema.ipv6_route_data_selector(pkt)[source]¶
Selector function for
IPv6_Route.datafield.- Parameters:
- Return type:
- Returns:
A
SchemaFieldwrappedRoutingTypeinstance based onIPv6_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 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.
- 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_leftplus the type-specific data computed byipv6_route_data_length(), i.e.4 + (4 + 8 * hdr_ext_len)– a different quantity fromipv6_route_data_length()itself (8 + 8 * hdr_ext_lenhere vs.4 + 8 * hdr_ext_lenthere), not a duplicate of it. It is what each_read_data_type_*inpcapkit.protocols.internet.ipv6_route.protocolreports back as the parsed route data’s own.length, whichread()then subtracts from the outer packet length to find the next layer’s length. Its inverse is the(length - 8) // 8that_make_data()passes back ashdr_ext_len;_make_hdr_ext_len()invertsipv6_route_data_length()instead.
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:
ProtocolData model for IPv6-Route protocol.
- class pcapkit.protocols.internet.ipv6_route.data.UnknownType(next, length, type, seg_left, data)[source]¶
Bases:
IPv6_RouteData model for IPv6-Route unknown type.
- class pcapkit.protocols.internet.ipv6_route.data.SourceRoute(next, length, type, seg_left, reserved, ip)[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.internet.ipv6_route.data.Type2(next, length, type, seg_left, reserved, ip)[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.internet.ipv6_route.data.RPL(next, length, type, seg_left, cmpr_i, cmpr_e, pad, reserved, ip, padding)[source]¶
Bases:
IPv6_RouteData model for RPL Source data type.
- ip: tuple[IPv6Address | bytes, ...]¶
Addresses.
Footnotes