Checksums¶
pcapkit.protocols.misc.checksum contains the pseudo-header that
upper-layer checksums cover,
IP_Pseudo. What the
one’s-complement checksums share, such as
ChecksumStatus, is in
pcapkit.corekit.checksum.internet.
IP Pseudo-Header¶
pcapkit.protocols.misc.checksum.ip_pseudo contains
IP_Pseudo,
which implements the pseudo-header of the IP protocol family
that the upper-layer checksums cover, and pseudo_header() and
verify_upper(), through which the IP layers use it. The
pseudo-header’s structure is described as below:
IPv4 (RFC 793 Section 3.1, RFC 768):
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Source Address |
4 |
32 |
|
Destination Address |
8 |
64 |
|
Reserved |
9 |
72 |
|
Protocol |
10 |
80 |
|
Upper-Layer Packet Length |
IPv6 (RFC 8200 Section 8.1):
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Source Address |
16 |
128 |
|
Destination Address |
32 |
256 |
|
Upper-Layer Packet Length |
36 |
288 |
|
Reserved |
39 |
312 |
|
Next Header |
A checksum over the IP pseudo-header is verified and computed by the enclosing
IPv4 or
IPv6 layer, which builds the
IP_Pseudo, rather than by
the upper layer reaching back to its parent. So an upper layer constructed
alone, or behind another header such as an IPv6 extension header or an
Authentication Header, has its checksum computed only if given the pseudo
to compute it over, and one parsed alone records no outcome. The sum itself is
in pcapkit.corekit.checksum.internet.
- class pcapkit.protocols.misc.checksum.ip_pseudo.IP_Pseudo(file=None, length=None, **kwargs)[source]¶
Bases:
ProtocolBase[IP_Pseudo,IP_Pseudo]This class implements the IP pseudo-header.
It is not a layer on the wire: it is built from the enclosing
IPv4orIPv6layer, or from explicit values, and itsdatais the octets an upper-layer checksum covers ahead of that layer’s own. The layout follows the IP version of the source address, or the length of the octets parsed.Added in version 1.6.0.
- property src: IPv4Address | IPv6Address¶
Source address.
- property dst: IPv4Address | IPv6Address¶
Destination address.
- read(length=None, **kwargs)[source]¶
Read IP pseudo-header.
Structure of the IPv4 pseudo-header [RFC 793]:
+--------+--------+--------+--------+ | Source Address | +--------+--------+--------+--------+ | Destination Address | +--------+--------+--------+--------+ | zero | PTCL | TCP Length | +--------+--------+--------+--------+
Structure of the IPv6 pseudo-header [RFC 8200]:
+--------+--------+--------+--------+ | | + + | | + Source Address + | | + + | | +--------+--------+--------+--------+ | | + + | | + Destination Address + | | + + | | +--------+--------+--------+--------+ | Upper-Layer Packet Length | +--------+--------+--------+--------+ | zero | Next | +--------+--------+--------+--------+
- make(ip=None, src=None, dst=None, protocol=None, upper_length=None, zero=b'', **kwargs)[source]¶
Make (construct) packet data.
Values not given are read from
ip.srcis a Home Address option’s address (RFC 6275 Section 11.3.1);dstis the final destination of a Routing header with segments left, or of a source route (RFC 791) not yet exhausted;protocolandupper_lengthlie past the extension headers, a UDP upper layer giving its Length field (RFC 768) and a jumbogram its Jumbo Payload Length (RFC 2675). Valuesiplacks are to be given: an unparsed Routing destination (RFC 8754), a fragment’s length, or an upper layer behind an unparsed header such as ESP.- Parameters:
ip (
IPv4|IPv6|None) – Parsed or constructed IP layer enclosing the upper layer.src (
bytes|str|int|IPv4Address|IPv6Address|None) – Source address; its IP version selects the layout.dst (
bytes|str|int|IPv4Address|IPv6Address|None) – Destination address, of the same IP version assrc.protocol (
TransType|int|None) – Upper-layer protocol number.upper_length (
int|None) – Upper-layer packet length, header included.zero (
bytes) – Reserved octets, one for IPv4 and three for IPv6; empty for zeros.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
ipis neither IPv4 nor IPv6, a value is given by neither the arguments norip, a header ofipis malformed or not parsed,protocolis a name, abool, or a member or code the 8-bit protocol field cannot carry, orzerois neither empty nor the layout’s width.FieldValueError – If
srcordstis not a valid address, they differ in IP version, orupper_lengthdoes not fit the layout’s length field.
- _source(ip)[source]¶
Read the pseudo-header source address from an IP layer.
- Parameters:
- Return type:
- Returns:
The address of a Home Address option (RFC 6275 Section 11.3.1) if any, the source address otherwise.
- Raises:
ProtocolError – If a Destination Options header is not parsed, however deep in the chain.
- _destination(ip)[source]¶
Read the pseudo-header destination address from an IP layer.
- Parameters:
- Return type:
- Returns:
The last address still to be visited of a source route (RFC 791) not yet exhausted, or of a Routing header with segments left; the destination address otherwise.
- Raises:
ProtocolError – If a source route or Routing header is not parsed, or a Routing header with segments left has no parsed last address.
- _upper_protocol(ip)[source]¶
Read the upper-layer protocol from an IP layer.
- Parameters:
- Return type:
- Returns:
The protocol past the extension headers.
- Raises:
ProtocolError – If the walk ended at an unparsed header: none, or an IPv6 extension header that was not walked, as past the header limit, or a truncated Routing or Fragment header.
- _upper_length(ip, *, from_layer=True)[source]¶
Read the upper-layer packet length from an IP layer.
- Parameters:
- Return type:
- Returns:
The Length field of a UDP header that is present, else the length past the IP header and extension headers.
- Raises:
ProtocolError – If
ipis a fragment, ends at an unparsed header, or has a zero Payload Length and no Jumbo Payload option.
- __post_init__(file=None, length=None, **kwargs)[source]¶
Post initialisation hook.
- Overloads:
- Parameters:
- Raises:
ProtocolError – If the octets parsed are not
lengthlong, or not 12 (IPv4) or 40 (IPv6) long.
See also
For construction arguments, please refer to
make().
- classmethod __index__()[source]¶
Numeral registry index of the protocol.
- Raises:
UnsupportedCall – This protocol has no registry entry.
- Return type:
- pcapkit.protocols.misc.checksum.ip_pseudo.pseudo_header(pseudo, length)[source]¶
Octets of
pseudowithlengthas its upper-layer length.- Parameters:
- Return type:
- Returns:
pseudo.data, made anew if it carries another length.- Raises:
FieldValueError – If
lengthdoes not fit the length field.
- pcapkit.protocols.misc.checksum.ip_pseudo.verify_upper(ip)[source]¶
Verify the checksum of the upper layer
ipcarries over its pseudo-header.The upper layer is the payload of
ip, past any Authentication Header of IPv4. It is verified if it defines_verify_pseudo_checksum, against theIP_Pseudoofip, or againstNoneif that cannot be derived or names another protocol.
Header Schemas¶
- pcapkit.protocols.schema.misc.checksum.ip_pseudo.IPV4_PSEUDO_LEN = 12¶
Length of the IPv4 pseudo-header, RFC 793 Section 3.1 – source, destination, zero, protocol and length.
Added in version 1.6.0.
- pcapkit.protocols.schema.misc.checksum.ip_pseudo.IPV6_PSEUDO_LEN = 40¶
Length of the IPv6 pseudo-header, RFC 8200 Section 8.1 – source, destination, length, zero and next header.
Added in version 1.6.0.
- class pcapkit.protocols.schema.misc.checksum.ip_pseudo.IP_Pseudo(src=NO_VALUE, dst=NO_VALUE, ipv6_len=NO_VALUE, zero=NO_VALUE, protocol=NO_VALUE, ipv4_len=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for the IP pseudo-header.
The layout follows the source address: RFC 793 Section 3.1 for IPv4, whose length is
ipv4_len, and RFC 8200 Section 8.1 for IPv6, whose length isipv6_len.Added in version 1.6.0.
- src: IPv4Address | IPv6Address = <SwitchField src>¶
Source address.
- dst: IPv4Address | IPv6Address = <SwitchField dst>¶
Destination address.
Auxiliary Functions¶
- pcapkit.protocols.schema.misc.checksum.ip_pseudo.is_ipv6(packet)[source]¶
Tell whether
packetholds an IPv6 pseudo-header.- Parameters:
- Returns:
by the version of the source address once it is known, by the octets to unpack before that.
- Return type:
Added in version 1.6.0.
- pcapkit.protocols.schema.misc.checksum.ip_pseudo.ip_pseudo_address_selector(packet)[source]¶
Selector function for
IP_Pseudo.srcandIP_Pseudo.dst.- Parameters:
- Return type:
- Returns:
An
IPv6AddressFieldfor the IPv6 layout, anIPv4AddressFieldotherwise.
Added in version 1.6.0.
- pcapkit.protocols.schema.misc.checksum.ip_pseudo.ip_pseudo_zero_selector(packet)[source]¶
Selector function for
IP_Pseudo.zero.- Parameters:
- Return type:
- Returns:
A
PaddingFieldof three octets for the IPv6 layout, of one octet otherwise.
Added in version 1.6.0.
Data Models¶
- class pcapkit.protocols.data.misc.checksum.ip_pseudo.IP_Pseudo(version, src, dst, protocol, len, zero)[source]¶
Bases:
ProtocolData model for the IP pseudo-header.
Added in version 1.6.0.
- src: IPv4Address | IPv6Address¶
Source address.
- dst: IPv4Address | IPv6Address¶
Destination address.