IPv6 Options - Shared Option Helpers

pcapkit.protocols.internet.ipv6_ext.schema contains the field helpers shared by the option schemas of schema (HOPOPT) and schema (IPv6-Opts), since both headers carry the same IPv6 options [*]. A helper that reports an error takes the header’s name as prefix, and a selector takes the header’s option schemas. Each header module binds them in a function of the same name, which is what its fields use.

Auxiliary Functions

pcapkit.protocols.internet.ipv6_ext.schema.rpl_opt_sub_tlv_len(pkt)[source]

Return RPL option sub-TLV length.

Parameters:

pkt (dict[str, Any]) – RPL option unpacked schema.

Return type:

int

Returns:

RPL option sub-TLV length, i.e. Opt Data Len less the four octets of the fixed fields. An Opt Data Len below 4 gives 0, and the reader then rejects the option.

pcapkit.protocols.internet.ipv6_ext.schema.mpl_opt_seed_id_len(pkt, *, prefix)[source]

Return MPL Seed-ID length.

Parameters:
  • pkt (dict[str, Any]) – MPL option unpacked schema.

  • prefix (str) – Name of the extension header, leading the error message.

Return type:

int

Returns:

MPL Seed-ID length.

Raises:

FieldValueError – If flags.type is not a defined Seed-ID type.

pcapkit.protocols.internet.ipv6_ext.schema.pad_opt_data_len(pkt)[source]

Return the length of the padding data of a padding option.

Parameters:

pkt (dict[str, Any]) – Padding option unpacked schema.

Return type:

int

Returns:

Number of padding octets carried after the option header, i.e. the value of the Opt Data Len field of a PadN option, and zero for a Pad1 option, which carries no such field.

Note

A Pad1 option is a single octet with neither an Opt Data Len field nor any option data (see RFC 8200 Section 4.2), which is why the option’s len field is declared as a ConditionalField and is skipped for it. A skipped conditional field is recorded in the packet data as NO_VALUE, rather than being left out of it, so the test this function makes has to be on the value and not on the presence of the key: pkt.get('len', 0) on its own hands that NoValueType straight to PaddingField, where it becomes an unusable struct template and surfaces much later as an opaque struct.error, which is how a Pad1 option would fail to parse.

pcapkit.protocols.internet.ipv6_ext.schema.calipso_pad_len(pkt, *, prefix)[source]

Return CALIPSO option padding length.

Parameters:
  • pkt (dict[str, Any]) – CALIPSO option unpacked schema.

  • prefix (str) – Name of the extension header, leading the error message.

Return type:

int

Returns:

CALIPSO option padding length, or zero if the data ends before Opt Data Len, which leaves the option to the short read.

Raises:

ProtocolError – If Opt Data Len on the wire is too short to hold the fixed header and the compartment bitmap declared by cmpt_len, which would otherwise underflow the padding length below zero.

Changed in version 1.6.0: A length the data ends before is left to the short read, and one too short raises ProtocolError rather than FieldValueError (#2727).

pcapkit.protocols.internet.ipv6_ext.schema.mpl_opt_pad_len(pkt, *, prefix)[source]

Return MPL option padding length.

Parameters:
  • pkt (dict[str, Any]) – MPL option unpacked schema.

  • prefix (str) – Name of the extension header, leading the error message.

Return type:

int

Returns:

MPL option padding length, or zero if the data ends before Opt Data Len, which leaves the option to the short read.

Raises:

ProtocolError – If Opt Data Len on the wire is too short to hold the fixed header and the Seed-ID declared by flags.type, which would otherwise underflow the padding length below zero.

Changed in version 1.6.0: A length the data ends before is left to the short read, and one too short raises ProtocolError rather than FieldValueError (#2727).

pcapkit.protocols.internet.ipv6_ext.schema.smf_dpd_data_selector(pkt, *, prefix, base)[source]

Selector function for the data field of an SMF_DPD option.

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

  • prefix (str) – Name of the extension header, leading the error message.

  • base (EnumMeta) – The header’s SMFDPDOption schema, whose registry maps the DPD mode to the schema that reads the option.

Return type:

FieldBase

Returns:

The field for the option data, chosen by the DPD mode.

  • If mode is 0, returns a SchemaField wrapped SMFIdentificationBasedDPDOption instance.

  • If mode is 1, returns a SchemaField wrapped SMFHashBasedDPDOption instance.

Raises:

Note

The field is sized Opt Data Len + 2 rather than Opt Data Len. Opt Data Len counts only what follows the option header [RFC 8200 Section 4.2], while both schemas this may return inherit the option’s type and len fields and so parse those two octets themselves. Sizing the field at Opt Data Len would hand them an area two octets short of the option they read, which OptionField would then mis-count against the option area.

Where the data ends before Opt Data Len, the forward match reads it as zero, and the option is the short read of the schema chosen by the mode bit, likewise zero.

Changed in version 1.6.0: A length the data ends before is left to the short read, and a zero on the wire raises ProtocolError rather than FieldValueError (#2727).

pcapkit.protocols.internet.ipv6_ext.schema.smf_i_dpd_tid_selector(pkt, *, prefix)[source]

Selector function for the tid field of an SMF I-DPD option.

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

  • prefix (str) – Name of the extension header, leading the error message.

Return type:

FieldBase

Returns:

The field for the TaggerId, chosen by its type.

Raises:

FieldValueError – If tid_len does not match the length of the NULL, IPv4 or IPv6 TaggerID type.

pcapkit.protocols.internet.ipv6_ext.schema.smf_i_dpd_id_len(pkt, *, prefix)[source]

Return SMF I-DPD identifier length.

Parameters:
  • pkt (dict[str, Any]) – SMF identification-based DPD option unpacked schema.

  • prefix (str) – Name of the extension header, leading the error message.

Return type:

int

Returns:

SMF I-DPD identifier length, or zero if the data ends before Opt Data Len, which leaves the option to the short read.

Raises:

ProtocolError – If Opt Data Len on the wire is too short to hold the TaggerID it declares, which would otherwise underflow the identifier length below zero.

Changed in version 1.6.0: A length the data ends before is left to the short read, and one too short raises ProtocolError rather than FieldValueError (#2727).

pcapkit.protocols.internet.ipv6_ext.schema.quick_start_data_selector(pkt, *, base, unassigned)[source]

Selector function for the data field of a Quick_Start option.

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

  • base (EnumMeta) – The header’s QuickStartOption schema, whose registry maps the QS function to the schema that reads the option.

  • unassigned (Type[Schema]) – The header’s UnassignedOption schema.

Return type:

FieldBase

Returns:

The field for the option data, chosen by the QS function.

  • If func is 0, returns a SchemaField wrapped QuickStartRequestOption instance.

  • If func is 8, returns a SchemaField wrapped QuickStartReportOption instance.

  • Otherwise, returns a SchemaField wrapped unassigned instance, sized by the option’s own Opt Data Len.

Footnotes